]> git.sur5r.net Git - openldap/blob - servers/slapd/back-relay/init.c
Reworked recent backend API changes, now using a separate struct,
[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-2007 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 "config.h"
28 #include "back-relay.h"
29
30 int
31 relay_back_initialize( BackendInfo *bi )
32 {
33         bi->bi_init = 0;
34         bi->bi_open = 0;
35         bi->bi_config = 0;
36         bi->bi_close = 0;
37         bi->bi_destroy = 0;
38
39         bi->bi_db_init = relay_back_db_init;
40         bi->bi_db_config = relay_back_db_config;
41         bi->bi_db_open = relay_back_db_open;
42 #if 0
43         bi->bi_db_close =relay_back_db_close;
44 #endif
45         bi->bi_db_destroy = relay_back_db_destroy;
46
47         bi->bi_op_bind = relay_back_op_bind;
48         bi->bi_op_unbind = relay_back_op_unbind;
49         bi->bi_op_search = relay_back_op_search;
50         bi->bi_op_compare = relay_back_op_compare;
51         bi->bi_op_modify = relay_back_op_modify;
52         bi->bi_op_modrdn = relay_back_op_modrdn;
53         bi->bi_op_add = relay_back_op_add;
54         bi->bi_op_delete = relay_back_op_delete;
55         bi->bi_op_abandon = relay_back_op_abandon;
56         bi->bi_op_cancel = relay_back_op_cancel;
57         bi->bi_extended = relay_back_op_extended;
58         bi->bi_entry_release_rw = relay_back_entry_release_rw;
59         bi->bi_entry_get_rw = relay_back_entry_get_rw;
60 #if 0   /* see comment in op.c */
61         bi->bi_chk_referrals = relay_back_chk_referrals;
62 #endif
63         bi->bi_operational = relay_back_operational;
64         bi->bi_has_subordinates = relay_back_has_subordinates;
65
66         bi->bi_connection_init = relay_back_connection_init;
67         bi->bi_connection_destroy = relay_back_connection_destroy;
68
69         return 0;
70 }
71
72 int
73 relay_back_db_init( Backend *be, ConfigReply *cr)
74 {
75         relay_back_info         *ri;
76
77         be->be_private = NULL;
78
79         ri = (relay_back_info *)ch_calloc( 1, sizeof( relay_back_info ) );
80         if ( ri == NULL ) {
81                 return -1;
82         }
83
84         ri->ri_bd = NULL;
85         BER_BVZERO( &ri->ri_realsuffix );
86         ri->ri_massage = 0;
87
88         be->be_private = (void *)ri;
89
90         return 0;
91 }
92
93 int
94 relay_back_db_open( Backend *be, ConfigReply *cr )
95 {
96         relay_back_info         *ri = (relay_back_info *)be->be_private;
97
98         assert( ri != NULL );
99
100         if ( !BER_BVISNULL( &ri->ri_realsuffix ) ) {
101                 ri->ri_bd = select_backend( &ri->ri_realsuffix, 1 );
102
103                 /* must be there: it was during config! */
104                 assert( ri->ri_bd != NULL );
105
106                 /* inherit controls */
107                 AC_MEMCPY( be->be_ctrls, ri->ri_bd->be_ctrls, sizeof( be->be_ctrls ) );
108
109         } else {
110                 /* inherit all? */
111                 AC_MEMCPY( be->be_ctrls, frontendDB->be_ctrls, sizeof( be->be_ctrls ) );
112         }
113
114         return 0;
115 }
116
117 int
118 relay_back_db_close( Backend *be, ConfigReply *cr )
119 {
120         return 0;
121 }
122
123 int
124 relay_back_db_destroy( Backend *be, ConfigReply *cr)
125 {
126         relay_back_info         *ri = (relay_back_info *)be->be_private;
127
128         if ( ri ) {
129                 if ( !BER_BVISNULL( &ri->ri_realsuffix ) ) {
130                         ch_free( ri->ri_realsuffix.bv_val );
131                 }
132                 ch_free( ri );
133         }
134
135         return 0;
136 }
137
138 #if SLAPD_RELAY == SLAPD_MOD_DYNAMIC
139
140 /* conditionally define the init_module() function */
141 SLAP_BACKEND_INIT_MODULE( relay )
142
143 #endif /* SLAPD_RELAY == SLAPD_MOD_DYNAMIC */
144