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();
34 static slap_response sock_over_response;
40 static ConfigTable bscfg[] = {
41 { "socketpath", "pathname", 2, 2, 0, ARG_STRING|ARG_OFFSET,
42 (void *)offsetof(struct sockinfo, si_sockpath),
43 "( OLcfgDbAt:7.1 NAME 'olcDbSocketPath' "
44 "DESC 'Pathname for Unix domain socket' "
45 "EQUALITY caseExactMatch "
46 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
47 { "extensions", "ext", 2, 0, 0, ARG_MAGIC|BS_EXT,
48 bs_cf_gen, "( OLcfgDbAt:7.2 NAME 'olcDbSocketExtensions' "
49 "DESC 'binddn, peername, or ssf' "
50 "EQUALITY caseIgnoreMatch "
51 "SYNTAX OMsDirectoryString )", NULL, NULL },
55 static ConfigOCs bsocs[] = {
57 "NAME 'olcDbSocketConfig' "
58 "DESC 'Socket backend configuration' "
59 "SUP olcDatabaseConfig "
60 "MUST olcDbSocketPath "
61 "MAY olcDbSocketExtensions )",
62 Cft_Database, bscfg },
66 static ConfigOCs osocs[] = {
68 "NAME 'olcOvSocketConfig' "
69 "DESC 'Socket overlay configuration' "
70 "SUP olcOverlayConfig "
71 "MUST olcDbSocketPath "
72 "MAY olcDbSocketExtensions )",
77 static slap_verbmasks bs_exts[] = {
78 { BER_BVC("binddn"), SOCK_EXT_BINDDN },
79 { BER_BVC("peername"), SOCK_EXT_PEERNAME },
80 { BER_BVC("ssf"), SOCK_EXT_SSF },
81 { BER_BVC("connid"), SOCK_EXT_CONNID },
86 bs_cf_gen( ConfigArgs *c )
91 if ( c->be && c->table == Cft_Database )
92 si = c->be->be_private;
94 si = c->bi->bi_private;
98 if ( c->op == SLAP_CONFIG_EMIT ) {
101 return mask_to_verbs( bs_exts, si->si_extensions, &c->rvalue_vals );
103 } else if ( c->op == LDAP_MOD_DELETE ) {
107 si->si_extensions = 0;
110 slap_mask_t dels = 0;
111 rc = verbs_to_mask( c->argc, c->argv, bs_exts, &dels );
113 si->si_extensions ^= dels;
121 return verbs_to_mask( c->argc, c->argv, bs_exts, &si->si_extensions );
128 sock_back_init_cf( BackendInfo *bi )
131 bi->bi_cf_ocs = bsocs;
133 rc = config_register_schema( bscfg, bsocs );
135 rc = sock_over_setup();
139 /* sock overlay wrapper */
140 static slap_overinst sockover;
142 static int sock_over_db_init( Backend *be, struct config_reply_s *cr );
143 static int sock_over_db_destroy( Backend *be, struct config_reply_s *cr );
145 static BI_op_bind *sockfuncs[] = {
156 static int sock_over_op(
161 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
162 void *private = op->o_bd->be_private;
163 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
164 slap_operation_t which;
168 case LDAP_REQ_BIND: which = op_bind; break;
169 case LDAP_REQ_UNBIND: which = op_unbind; break;
170 case LDAP_REQ_SEARCH: which = op_search; break;
171 case LDAP_REQ_COMPARE: which = op_compare; break;
172 case LDAP_REQ_MODIFY: which = op_modify; break;
173 case LDAP_REQ_MODRDN: which = op_modrdn; break;
174 case LDAP_REQ_ADD: which = op_add; break;
175 case LDAP_REQ_DELETE: which = op_delete; break;
177 return SLAP_CB_CONTINUE;
179 op->o_bd->be_private = on->on_bi.bi_private;
180 cb.sc_next = op->o_callback;
181 op->o_callback = &cb;
182 rc = sockfuncs[which]( op, rs );
183 op->o_bd->be_private = private;
184 op->o_callback = cb.sc_next;
185 return SLAP_CB_CONTINUE;
189 sock_over_response( Operation *op, SlapReply *rs )
191 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
192 struct sockinfo *si = (struct sockinfo *)on->on_bi.bi_private;
195 if ( rs->sr_type != REP_RESULT )
196 return SLAP_CB_CONTINUE;
198 if (( fp = opensock( si->si_sockpath )) == NULL )
199 return SLAP_CB_CONTINUE;
201 /* write out the result */
202 fprintf( fp, "RESULT\n" );
203 fprintf( fp, "msgid: %ld\n", (long) op->o_msgid );
204 sock_print_conn( fp, op->o_conn, si );
205 fprintf( fp, "code: %d\n", rs->sr_err );
206 if ( rs->sr_matched )
207 fprintf( fp, "matched: %s\n", rs->sr_matched );
209 fprintf( fp, "info: %s\n", rs->sr_text );
213 return SLAP_CB_CONTINUE;
221 sockover.on_bi.bi_type = "sock";
222 sockover.on_bi.bi_db_init = sock_over_db_init;
223 sockover.on_bi.bi_db_destroy = sock_over_db_destroy;
225 sockover.on_bi.bi_op_bind = sock_over_op;
226 sockover.on_bi.bi_op_unbind = sock_over_op;
227 sockover.on_bi.bi_op_search = sock_over_op;
228 sockover.on_bi.bi_op_compare = sock_over_op;
229 sockover.on_bi.bi_op_modify = sock_over_op;
230 sockover.on_bi.bi_op_modrdn = sock_over_op;
231 sockover.on_bi.bi_op_add = sock_over_op;
232 sockover.on_bi.bi_op_delete = sock_over_op;
233 sockover.on_response = sock_over_response;
235 sockover.on_bi.bi_cf_ocs = osocs;
237 rc = config_register_schema( bscfg, osocs );
240 return overlay_register( &sockover );
246 struct config_reply_s *cr
249 slap_overinst *on = (slap_overinst *)be->bd_info;
250 void *private = be->be_private;
253 be->be_private = NULL;
254 rc = sock_back_db_init( be, cr );
255 on->on_bi.bi_private = be->be_private;
256 be->be_private = private;
261 sock_over_db_destroy(
263 struct config_reply_s *cr
266 slap_overinst *on = (slap_overinst *)be->bd_info;
267 void *private = be->be_private;
270 be->be_private = on->on_bi.bi_private;
271 rc = sock_back_db_destroy( be, cr );
272 on->on_bi.bi_private = be->be_private;
273 be->be_private = private;