]> git.sur5r.net Git - openldap/blob - servers/slapd/back-relay/init.c
ACIs almost entirely factored out of slapd
[openldap] / servers / slapd / back-relay / init.c
1 /* init.c - initialize relay backend */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 2004-2005 The OpenLDAP Foundation.
5  * Portions Copyright 2004 Pierangelo Masarati.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 /* ACKNOWLEDGEMENTS:
17  * This work was initially developed by Pierangelo Masarati for inclusion
18  * in OpenLDAP Software.
19  */
20
21 #include "portable.h"
22
23 #include <stdio.h>
24 #include <ac/string.h>
25
26 #include "slap.h"
27 #include "back-relay.h"
28
29 int
30 relay_back_initialize( BackendInfo *bi )
31 {
32         bi->bi_init = 0;
33         bi->bi_open = 0;
34         bi->bi_config = 0;
35         bi->bi_close = 0;
36         bi->bi_destroy = 0;
37
38         bi->bi_db_init = relay_back_db_init;
39         bi->bi_db_config = relay_back_db_config;
40         bi->bi_db_open = relay_back_db_open;
41 #if 0
42         bi->bi_db_close =relay_back_db_close;
43 #endif
44         bi->bi_db_destroy = relay_back_db_destroy;
45
46         bi->bi_op_bind = relay_back_op_bind;
47         bi->bi_op_unbind = relay_back_op_unbind;
48         bi->bi_op_search = relay_back_op_search;
49         bi->bi_op_compare = relay_back_op_compare;
50         bi->bi_op_modify = relay_back_op_modify;
51         bi->bi_op_modrdn = relay_back_op_modrdn;
52         bi->bi_op_add = relay_back_op_add;
53         bi->bi_op_delete = relay_back_op_delete;
54         bi->bi_op_abandon = relay_back_op_abandon;
55         bi->bi_op_cancel = relay_back_op_cancel;
56         bi->bi_extended = relay_back_op_extended;
57         bi->bi_entry_release_rw = relay_back_entry_release_rw;
58         bi->bi_entry_get_rw = relay_back_entry_get_rw;
59 #if 0   /* see comment in op.c */
60         bi->bi_chk_referrals = relay_back_chk_referrals;
61 #endif
62         bi->bi_operational = relay_back_operational;
63         bi->bi_has_subordinates = relay_back_has_subordinates;
64
65         bi->bi_connection_init = relay_back_connection_init;
66         bi->bi_connection_destroy = relay_back_connection_destroy;
67
68         return 0;
69 }
70
71 int
72 relay_back_db_init( Backend *be )
73 {
74         relay_back_info         *ri;
75
76         be->be_private = NULL;
77
78         ri = (relay_back_info *)ch_calloc( 1, sizeof( relay_back_info ) );
79         if ( ri == NULL ) {
80                 return -1;
81         }
82
83         ri->ri_bd = NULL;
84         BER_BVZERO( &ri->ri_realsuffix );
85         ri->ri_massage = 0;
86
87         be->be_private = (void *)ri;
88
89         return 0;
90 }
91
92 int
93 relay_back_db_open( Backend *be )
94 {
95         relay_back_info         *ri = (relay_back_info *)be->be_private;
96
97         assert( ri != NULL );
98
99         if ( !BER_BVISNULL( &ri->ri_realsuffix ) ) {
100                 ri->ri_bd = select_backend( &ri->ri_realsuffix, 0, 1 );
101
102                 /* must be there: it was during config! */
103                 assert( ri->ri_bd != NULL );
104
105                 /* inherit controls */
106                 AC_MEMCPY( be->be_ctrls, ri->ri_bd->be_ctrls, sizeof( be->be_ctrls ) );
107
108         } else {
109                 /* inherit all? */
110                 AC_MEMCPY( be->be_ctrls, frontendDB->be_ctrls, sizeof( be->be_ctrls ) );
111         }
112
113         return 0;
114 }
115
116 int
117 relay_back_db_close( Backend *be )
118 {
119         return 0;
120 }
121
122 int
123 relay_back_db_destroy( Backend *be )
124 {
125         relay_back_info         *ri = (relay_back_info *)be->be_private;
126
127         if ( ri ) {
128                 if ( !BER_BVISNULL( &ri->ri_realsuffix ) ) {
129                         ch_free( ri->ri_realsuffix.bv_val );
130                 }
131                 ch_free( ri );
132         }
133
134         return 0;
135 }
136
137 #if SLAPD_RELAY == SLAPD_MOD_DYNAMIC
138
139 /* conditionally define the init_module() function */
140 SLAP_BACKEND_INIT_MODULE( relay )
141
142 #endif /* SLAPD_RELAY == SLAPD_MOD_DYNAMIC */
143