1 /* config.c - sock backend configuration file routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2007-2011 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
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>.
17 * This work was initially developed by Brian Candler for inclusion
18 * in OpenLDAP Software. Dynamic config support by Howard Chu.
25 #include <ac/string.h>
26 #include <ac/socket.h>
30 #include "back-sock.h"
32 static ConfigDriver bs_cf_gen;
33 static int sock_over_setup();
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 },
54 static ConfigOCs bsocs[] = {
56 "NAME 'olcDbSocketConfig' "
57 "DESC 'Socket backend configuration' "
58 "SUP olcDatabaseConfig "
59 "MUST olcDbSocketPath "
60 "MAY olcDbSocketExtensions )",
61 Cft_Database, bscfg },
65 static ConfigOCs osocs[] = {
67 "NAME 'olcOvSocketConfig' "
68 "DESC 'Socket overlay configuration' "
69 "SUP olcOverlayConfig "
70 "MUST olcDbSocketPath "
71 "MAY olcDbSocketExtensions )",
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 },
85 bs_cf_gen( ConfigArgs *c )
90 if ( c->be && c->table == Cft_Database )
91 si = c->be->be_private;
93 si = c->bi->bi_private;
97 if ( c->op == SLAP_CONFIG_EMIT ) {
100 return mask_to_verbs( bs_exts, si->si_extensions, &c->rvalue_vals );
102 } else if ( c->op == LDAP_MOD_DELETE ) {
106 si->si_extensions = 0;
109 slap_mask_t dels = 0;
110 rc = verbs_to_mask( c->argc, c->argv, bs_exts, &dels );
112 si->si_extensions ^= dels;
120 return verbs_to_mask( c->argc, c->argv, bs_exts, &si->si_extensions );
127 sock_back_init_cf( BackendInfo *bi )
130 bi->bi_cf_ocs = bsocs;
132 rc = config_register_schema( bscfg, bsocs );
134 rc = sock_over_setup();
138 /* sock overlay wrapper */
139 static slap_overinst sockover;
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 );
144 static BI_op_bind *sockfuncs[] = {
155 static int sock_over_op(
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;
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;
176 return SLAP_CB_CONTINUE;
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;
188 sock_over_response( Operatiion *op, SlapReply *rs )
190 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
191 struct sockinfo *si = (struct sockinfo *)on->on_bi.bi_private;
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;
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;
214 sockover.on_bi.bi_cf_ocs = osocs;
216 rc = config_register_schema( bscfg, osocs );
219 return overlay_register( &sockover );
225 struct config_reply_s *cr
228 slap_overinst *on = (slap_overinst *)be->bd_info;
229 void *private = be->be_private;
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;
240 sock_over_db_destroy(
242 struct config_reply_s *cr
245 slap_overinst *on = (slap_overinst *)be->bd_info;
246 void *private = be->be_private;
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;