1 /* null.c - the null backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2002-2017 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 originally developed by Hallvard Furuseth for inclusion
18 * in OpenLDAP Software.
24 #include <ac/string.h>
29 typedef struct null_info {
36 static ConfigTable nullcfg[] = {
37 { "bind", "true|FALSE", 1, 2, 0, ARG_ON_OFF|ARG_OFFSET,
38 (void *)offsetof(null_info, ni_bind_allowed),
39 "( OLcfgDbAt:8.1 NAME 'olcDbBindAllowed' "
40 "DESC 'Allow binds to this database' "
41 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
42 { "dosearch", "true|FALSE", 1, 2, 0, ARG_ON_OFF|ARG_OFFSET,
43 (void *)offsetof(null_info, ni_dosearch),
44 "( OLcfgDbAt:8.2 NAME 'olcDbDoSearch' "
45 "DESC 'Return an entry on searches' "
46 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
47 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
48 NULL, NULL, NULL, NULL }
51 static ConfigOCs nullocs[] = {
53 "NAME 'olcNullConfig' "
54 "DESC 'Null backend ocnfiguration' "
55 "SUP olcDatabaseConfig "
56 "MAY ( olcDbBindAllowed $ olcDbDoSearch ) )",
57 Cft_Database, nullcfg },
63 null_back_db_open( BackendDB *be, ConfigReply *cr )
65 struct null_info *ni = (struct null_info *) be->be_private;
67 AttributeDescription *ad = NULL;
71 if ( ni->ni_dosearch ) {
73 e->e_name = be->be_suffix[0];
74 e->e_nname = be->be_nsuffix[0];
76 dnRdn( &e->e_nname, &bv[0] );
77 bv[1].bv_val = strchr(bv[0].bv_val, '=') + 1;
78 bv[1].bv_len = bv[0].bv_len - (bv[1].bv_val -
80 bv[0].bv_len -= bv[1].bv_len + 1;
81 slap_bv2ad( &bv[0], &ad, &text );
82 attr_merge_one( e, ad, &bv[1], NULL );
84 ber_str2bv("extensibleObject", 0, 0, &bv[0]);
85 attr_merge_one( e, slap_schema.si_ad_objectClass, &bv[0], NULL);
94 null_back_bind( Operation *op, SlapReply *rs )
96 struct null_info *ni = (struct null_info *) op->o_bd->be_private;
98 if ( ni->ni_bind_allowed || be_isroot_pw( op ) ) {
99 /* front end will send result on success (0) */
103 rs->sr_err = LDAP_INVALID_CREDENTIALS;
104 send_ldap_result( op, rs );
111 null_back_respond( Operation *op, SlapReply *rs, int rc )
113 LDAPControl ctrl[SLAP_MAX_RESPONSE_CONTROLS], *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
116 BerElementBuffer ps_berbuf;
117 BerElement *ps_ber = NULL;
118 LDAPControl **preread_ctrl = NULL,
119 **postread_ctrl = NULL;
121 rs->sr_err = LDAP_OTHER;
123 /* this comes first, as in case of assertion failure
124 * any further processing must stop */
125 if ( get_assert( op ) ) {
126 rs->sr_err = LDAP_ASSERTION_FAILED;
130 if ( op->o_preread ) {
133 switch ( op->o_tag ) {
134 case LDAP_REQ_MODIFY:
135 case LDAP_REQ_RENAME:
136 case LDAP_REQ_DELETE:
137 e.e_name = op->o_req_dn;
138 e.e_nname = op->o_req_ndn;
140 preread_ctrl = &ctrls[c];
141 *preread_ctrl = NULL;
143 if ( slap_read_controls( op, rs, &e,
144 &slap_pre_read_bv, preread_ctrl ) )
148 Debug( LDAP_DEBUG_TRACE,
149 "<=- null_back_respond: pre-read "
150 "failed!\n", 0, 0, 0 );
152 if ( op->o_preread & SLAP_CONTROL_CRITICAL ) {
153 /* FIXME: is it correct to abort
154 * operation if control fails? */
165 if ( op->o_postread ) {
168 switch ( op->o_tag ) {
170 case LDAP_REQ_MODIFY:
171 case LDAP_REQ_RENAME:
172 if ( op->o_tag == LDAP_REQ_ADD ) {
173 e.e_name = op->ora_e->e_name;
174 e.e_nname = op->ora_e->e_nname;
177 e.e_name = op->o_req_dn;
178 e.e_nname = op->o_req_ndn;
181 postread_ctrl = &ctrls[c];
182 *postread_ctrl = NULL;
184 if ( slap_read_controls( op, rs, &e,
185 &slap_post_read_bv, postread_ctrl ) )
187 postread_ctrl = NULL;
189 Debug( LDAP_DEBUG_TRACE,
190 "<=- null_back_respond: post-read "
191 "failed!\n", 0, 0, 0 );
193 if ( op->o_postread & SLAP_CONTROL_CRITICAL ) {
194 /* FIXME: is it correct to abort
195 * operation if control fails? */
207 switch ( op->o_tag ) {
209 case LDAP_REQ_MODIFY:
210 case LDAP_REQ_RENAME:
211 case LDAP_REQ_DELETE:
212 case LDAP_REQ_EXTENDED:
213 rc = LDAP_X_NO_OPERATION;
218 if ( get_pagedresults( op ) > SLAP_CONTROL_IGNORED ) {
219 struct berval cookie = BER_BVC( "" );
221 /* should not be here... */
222 assert( op->o_tag == LDAP_REQ_SEARCH );
224 ctrl[c].ldctl_oid = LDAP_CONTROL_PAGEDRESULTS;
225 ctrl[c].ldctl_iscritical = 0;
227 ps_ber = (BerElement *)&ps_berbuf;
228 ber_init2( ps_ber, NULL, LBER_USE_DER );
230 /* return size of 0 -- no estimate */
231 ber_printf( ps_ber, "{iO}", 0, &cookie );
233 if ( ber_flatten2( ps_ber, &ctrl[c].ldctl_value, 0 ) == -1 ) {
241 /* terminate controls array */
243 rs->sr_ctrls = ctrls;
247 send_ldap_result( op, rs );
251 if ( ps_ber != NULL ) {
252 (void) ber_free_buf( ps_ber );
255 if( preread_ctrl != NULL && (*preread_ctrl) != NULL ) {
256 slap_sl_free( (*preread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
257 slap_sl_free( *preread_ctrl, op->o_tmpmemctx );
260 if( postread_ctrl != NULL && (*postread_ctrl) != NULL ) {
261 slap_sl_free( (*postread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
262 slap_sl_free( *postread_ctrl, op->o_tmpmemctx );
268 /* add, delete, modify, modrdn, search */
270 null_back_success( Operation *op, SlapReply *rs )
272 return null_back_respond( op, rs, LDAP_SUCCESS );
277 null_back_false( Operation *op, SlapReply *rs )
279 return null_back_respond( op, rs, LDAP_COMPARE_FALSE );
283 null_back_search( Operation *op, SlapReply *rs )
285 struct null_info *ni = (struct null_info *) op->o_bd->be_private;
287 if ( ni->ni_entry ) {
288 rs->sr_entry = ni->ni_entry;
291 rs->sr_attrs = op->ors_attrs;
292 rs->sr_operational_attrs = NULL;
293 send_search_entry( op, rs );
295 return null_back_respond( op, rs, LDAP_SUCCESS );
304 AttributeDescription *at,
308 /* don't admit the object isn't there */
309 return oc || at ? LDAP_NO_SUCH_ATTRIBUTE : LDAP_BUSY;
313 null_back_entry_release(
318 /* we reuse our entry, don't free it */
325 null_tool_entry_open( BackendDB *be, int mode )
331 null_tool_entry_close( BackendDB *be )
333 assert( be != NULL );
338 null_tool_entry_first_x( BackendDB *be, struct berval *base, int scope, Filter *f )
344 null_tool_entry_next( BackendDB *be )
350 null_tool_entry_get( BackendDB *be, ID id )
352 assert( slapMode & SLAP_TOOL_MODE );
357 null_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
359 assert( slapMode & SLAP_TOOL_MODE );
360 assert( text != NULL );
361 assert( text->bv_val != NULL );
362 assert( text->bv_val[0] == '\0' ); /* overconservative? */
364 e->e_id = ((struct null_info *) be->be_private)->ni_nextid++;
372 null_back_db_init( BackendDB *be, ConfigReply *cr )
374 struct null_info *ni = ch_calloc( 1, sizeof(struct null_info) );
375 ni->ni_bind_allowed = 0;
378 be->be_cf_ocs = be->bd_info->bi_cf_ocs;
383 null_back_db_destroy( Backend *be, ConfigReply *cr )
385 struct null_info *ni = be->be_private;
387 if ( ni->ni_entry ) {
388 entry_free( ni->ni_entry );
391 free( be->be_private );
397 null_back_initialize( BackendInfo *bi )
399 static char *controls[] = {
401 LDAP_CONTROL_MANAGEDSAIT,
403 LDAP_CONTROL_PAGEDRESULTS,
404 LDAP_CONTROL_SUBENTRIES,
405 LDAP_CONTROL_PRE_READ,
406 LDAP_CONTROL_POST_READ,
407 LDAP_CONTROL_X_PERMISSIVE_MODIFY,
411 Debug( LDAP_DEBUG_TRACE,
412 "null_back_initialize: initialize null backend\n", 0, 0, 0 );
415 SLAP_BFLAG_INCREMENT |
416 SLAP_BFLAG_SUBENTRIES |
418 SLAP_BFLAG_REFERRALS;
420 bi->bi_controls = controls;
427 bi->bi_db_init = null_back_db_init;
428 bi->bi_db_config = config_generic_wrapper;
429 bi->bi_db_open = null_back_db_open;
431 bi->bi_db_destroy = null_back_db_destroy;
433 bi->bi_op_bind = null_back_bind;
434 bi->bi_op_unbind = 0;
435 bi->bi_op_search = null_back_search;
436 bi->bi_op_compare = null_back_false;
437 bi->bi_op_modify = null_back_success;
438 bi->bi_op_modrdn = null_back_success;
439 bi->bi_op_add = null_back_success;
440 bi->bi_op_delete = null_back_success;
441 bi->bi_op_abandon = 0;
445 bi->bi_chk_referrals = 0;
447 bi->bi_connection_init = 0;
448 bi->bi_connection_destroy = 0;
450 bi->bi_entry_get_rw = null_back_entry_get;
451 bi->bi_entry_release_rw = null_back_entry_release;
453 bi->bi_tool_entry_open = null_tool_entry_open;
454 bi->bi_tool_entry_close = null_tool_entry_close;
455 bi->bi_tool_entry_first = backend_tool_entry_first;
456 bi->bi_tool_entry_first_x = null_tool_entry_first_x;
457 bi->bi_tool_entry_next = null_tool_entry_next;
458 bi->bi_tool_entry_get = null_tool_entry_get;
459 bi->bi_tool_entry_put = null_tool_entry_put;
461 bi->bi_cf_ocs = nullocs;
462 return config_register_schema( nullcfg, nullocs );
465 #if SLAPD_NULL == SLAPD_MOD_DYNAMIC
467 /* conditionally define the init_module() function */
468 SLAP_BACKEND_INIT_MODULE( null )
470 #endif /* SLAPD_NULL == SLAPD_MOD_DYNAMIC */