]> git.sur5r.net Git - openldap/blob - servers/slapd/back-sock/config.c
d07d0cef11845103af1864e71ba2c93ca2cc51c0
[openldap] / servers / slapd / back-sock / config.c
1 /* config.c - sock backend configuration file routine */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2007-2011 The OpenLDAP Foundation.
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 Brian Candler for inclusion
18  * in OpenLDAP Software. Dynamic config support by Howard Chu.
19  */
20
21 #include "portable.h"
22
23 #include <stdio.h>
24
25 #include <ac/string.h>
26 #include <ac/socket.h>
27
28 #include "slap.h"
29 #include "config.h"
30 #include "back-sock.h"
31
32 static ConfigDriver bs_cf_gen;
33 static int sock_over_setup();
34
35 enum {
36         BS_EXT = 1
37 };
38
39 static ConfigTable bscfg[] = {
40         { "socketpath", "pathname", 2, 2, 0, ARG_STRING|ARG_OFFSET,
41                 (void *)offsetof(struct sockinfo, si_sockpath),
42                 "( OLcfgDbAt:7.1 NAME 'olcDbSocketPath' "
43                         "DESC 'Pathname for Unix domain socket' "
44                         "EQUALITY caseExactMatch "
45                         "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
46         { "extensions", "ext", 2, 0, 0, ARG_MAGIC|BS_EXT,
47                 bs_cf_gen, "( OLcfgDbAt:7.2 NAME 'olcDbSocketExtensions' "
48                         "DESC 'binddn, peername, or ssf' "
49                         "EQUALITY caseIgnoreMatch "
50                         "SYNTAX OMsDirectoryString )", NULL, NULL },
51         { NULL, NULL }
52 };
53
54 static ConfigOCs bsocs[] = {
55         { "( OLcfgDbOc:7.1 "
56                 "NAME 'olcDbSocketConfig' "
57                 "DESC 'Socket backend configuration' "
58                 "SUP olcDatabaseConfig "
59                 "MUST olcDbSocketPath "
60                 "MAY olcDbSocketExtensions )",
61                         Cft_Database, bscfg },
62         { NULL, 0, NULL }
63 };
64
65 static ConfigOCs osocs[] = {
66         { "( OLcfgOvOc:22.1 "
67                 "NAME 'olcOvSocketConfig' "
68                 "DESC 'Socket overlay configuration' "
69                 "SUP olcOverlayConfig "
70                 "MUST olcDbSocketPath "
71                 "MAY olcDbSocketExtensions )",
72                         Cft_Overlay, bscfg },
73         { NULL, 0, NULL }
74 };
75
76 static slap_verbmasks bs_exts[] = {
77         { BER_BVC("binddn"), SOCK_EXT_BINDDN },
78         { BER_BVC("peername"), SOCK_EXT_PEERNAME },
79         { BER_BVC("ssf"), SOCK_EXT_SSF },
80         { BER_BVC("connid"), SOCK_EXT_CONNID },
81         { BER_BVNULL, 0 }
82 };
83
84 static int
85 bs_cf_gen( ConfigArgs *c )
86 {
87         struct sockinfo *si;
88         int rc;
89
90         if ( c->be && c->table == Cft_Database )
91                 si = c->be->be_private;
92         else if ( c->bi )
93                 si = c->bi->bi_private;
94         else
95                 return ARG_BAD_CONF;
96
97         if ( c->op == SLAP_CONFIG_EMIT ) {
98                 switch( c->type ) {
99                 case BS_EXT:
100                         return mask_to_verbs( bs_exts, si->si_extensions, &c->rvalue_vals );
101                 }
102         } else if ( c->op == LDAP_MOD_DELETE ) {
103                 switch( c->type ) {
104                 case BS_EXT:
105                         if ( c->valx < 0 ) {
106                                 si->si_extensions = 0;
107                                 rc = 0;
108                         } else {
109                                 slap_mask_t dels = 0;
110                                 rc = verbs_to_mask( c->argc, c->argv, bs_exts, &dels );
111                                 if ( rc == 0 )
112                                         si->si_extensions ^= dels;
113                         }
114                         return rc;
115                 }
116
117         } else {
118                 switch( c->type ) {
119                 case BS_EXT:
120                         return verbs_to_mask( c->argc, c->argv, bs_exts, &si->si_extensions );
121                 }
122         }
123         return 1;
124 }
125
126 int
127 sock_back_init_cf( BackendInfo *bi )
128 {
129         int rc;
130         bi->bi_cf_ocs = bsocs;
131
132         rc = config_register_schema( bscfg, bsocs );
133         if ( !rc )
134                 rc = sock_over_setup();
135         return rc;
136 }
137
138 /* sock overlay wrapper */
139 static slap_overinst sockover;
140
141 static int sock_over_db_init( Backend *be, struct config_reply_s *cr );
142 static int sock_over_db_destroy( Backend *be, struct config_reply_s *cr );
143
144 static BI_op_bind *sockfuncs[] = {
145         sock_back_bind,
146         sock_back_unbind,
147         sock_back_search,
148         sock_back_compare,
149         sock_back_modify,
150         sock_back_modrdn,
151         sock_back_add,
152         sock_back_delete
153 };
154
155 static int sock_over_op(
156         Operation *op,
157         SlapReply *rs
158 )
159 {
160         slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
161         void *private = op->o_bd->be_private;
162         slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
163         slap_operation_t which;
164         int rc;
165
166         switch (op->o_tag) {
167         case LDAP_REQ_BIND:     which = op_bind; break;
168         case LDAP_REQ_UNBIND:   which = op_unbind; break;
169         case LDAP_REQ_SEARCH:   which = op_search; break;
170         case LDAP_REQ_COMPARE:  which = op_compare; break;
171         case LDAP_REQ_MODIFY:   which = op_modify; break;
172         case LDAP_REQ_MODRDN:   which = op_modrdn; break;
173         case LDAP_REQ_ADD:      which = op_add; break;
174         case LDAP_REQ_DELETE:   which = op_delete; break;
175         default:
176                 return SLAP_CB_CONTINUE;
177         }
178         op->o_bd->be_private = on->on_bi.bi_private;
179         cb.sc_next = op->o_callback;
180         op->o_callback = &cb;
181         rc = sockfuncs[which]( op, rs );
182         op->o_bd->be_private = private;
183         op->o_callback = cb.sc_next;
184         return rc;
185 }
186
187 static int
188 sock_over_response( Operatiion *op, SlapReply *rs )
189 {
190         slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
191         struct sockinfo *si = (struct sockinfo *)on->on_bi.bi_private;
192
193 }
194
195 static int
196 sock_over_setup()
197 {
198         int rc;
199
200         sockover.on_bi.bi_type = "sock";
201         sockover.on_bi.bi_db_init = sock_over_db_init;
202         sockover.on_bi.bi_db_destroy = sock_over_db_destroy;
203
204         sockover.on_bi.bi_op_bind = sock_over_op;
205         sockover.on_bi.bi_op_unbind = sock_over_op;
206         sockover.on_bi.bi_op_search = sock_over_op;
207         sockover.on_bi.bi_op_compare = sock_over_op;
208         sockover.on_bi.bi_op_modify = sock_over_op;
209         sockover.on_bi.bi_op_modrdn = sock_over_op;
210         sockover.on_bi.bi_op_add = sock_over_op;
211         sockover.on_bi.bi_op_delete = sock_over_op;
212         sockover.on_response = sock_over_response;
213
214         sockover.on_bi.bi_cf_ocs = osocs;
215
216         rc = config_register_schema( bscfg, osocs );
217         if ( rc ) return rc;
218
219         return overlay_register( &sockover );
220 }
221
222 static int
223 sock_over_db_init(
224     Backend     *be,
225         struct config_reply_s *cr
226 )
227 {
228         slap_overinst   *on = (slap_overinst *)be->bd_info;
229         void *private = be->be_private;
230         int rc;
231
232         be->be_private = NULL;
233         rc = sock_back_db_init( be, cr );
234         on->on_bi.bi_private = be->be_private;
235         be->be_private = private;
236         return rc;
237 }
238
239 static int
240 sock_over_db_destroy(
241     Backend     *be,
242         struct config_reply_s *cr
243 )
244 {
245         slap_overinst   *on = (slap_overinst *)be->bd_info;
246         void *private = be->be_private;
247         int rc;
248
249         be->be_private = on->on_bi.bi_private;
250         rc = sock_back_db_destroy( be, cr );
251         on->on_bi.bi_private = be->be_private;
252         be->be_private = private;
253         return rc;
254 }