1 /* null.c - the null backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2002-2012 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>
34 static ConfigDriver null_cf_gen;
36 static ConfigTable nullcfg[] = {
37 { "bind", "true|FALSE", 1, 2, 0, ARG_ON_OFF|ARG_MAGIC,
39 "( OLcfgDbAt:8.1 NAME 'olcDbBindAllowed' "
40 "DESC 'Allow binds to this database' "
41 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
42 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
43 NULL, NULL, NULL, NULL }
46 static ConfigOCs nullocs[] = {
48 "NAME 'olcNullConfig' "
49 "DESC 'Null backend ocnfiguration' "
50 "SUP olcDatabaseConfig "
51 "MAY ( olcDbBindAllowed ) )",
52 Cft_Database, nullcfg },
60 null_back_bind( Operation *op, SlapReply *rs )
62 struct null_info *ni = (struct null_info *) op->o_bd->be_private;
64 if ( ni->ni_bind_allowed || be_isroot_pw( op ) ) {
65 /* front end will send result on success (0) */
69 rs->sr_err = LDAP_INVALID_CREDENTIALS;
70 send_ldap_result( op, rs );
77 null_back_respond( Operation *op, SlapReply *rs, int rc )
79 LDAPControl ctrl[SLAP_MAX_RESPONSE_CONTROLS], *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
82 BerElementBuffer ps_berbuf;
83 BerElement *ps_ber = NULL;
84 LDAPControl **preread_ctrl = NULL,
85 **postread_ctrl = NULL;
87 rs->sr_err = LDAP_OTHER;
89 /* this comes first, as in case of assertion failure
90 * any further processing must stop */
91 if ( get_assert( op ) ) {
92 rs->sr_err = LDAP_ASSERTION_FAILED;
96 if ( op->o_preread ) {
99 switch ( op->o_tag ) {
100 case LDAP_REQ_MODIFY:
101 case LDAP_REQ_RENAME:
102 case LDAP_REQ_DELETE:
103 e.e_name = op->o_req_dn;
104 e.e_nname = op->o_req_ndn;
106 preread_ctrl = &ctrls[c];
107 *preread_ctrl = NULL;
109 if ( slap_read_controls( op, rs, &e,
110 &slap_pre_read_bv, preread_ctrl ) )
114 Debug( LDAP_DEBUG_TRACE,
115 "<=- null_back_respond: pre-read "
116 "failed!\n", 0, 0, 0 );
118 if ( op->o_preread & SLAP_CONTROL_CRITICAL ) {
119 /* FIXME: is it correct to abort
120 * operation if control fails? */
131 if ( op->o_postread ) {
134 switch ( op->o_tag ) {
136 case LDAP_REQ_MODIFY:
137 case LDAP_REQ_RENAME:
138 if ( op->o_tag == LDAP_REQ_ADD ) {
139 e.e_name = op->ora_e->e_name;
140 e.e_nname = op->ora_e->e_nname;
143 e.e_name = op->o_req_dn;
144 e.e_nname = op->o_req_ndn;
147 postread_ctrl = &ctrls[c];
148 *postread_ctrl = NULL;
150 if ( slap_read_controls( op, rs, &e,
151 &slap_post_read_bv, postread_ctrl ) )
153 postread_ctrl = NULL;
155 Debug( LDAP_DEBUG_TRACE,
156 "<=- null_back_respond: post-read "
157 "failed!\n", 0, 0, 0 );
159 if ( op->o_postread & SLAP_CONTROL_CRITICAL ) {
160 /* FIXME: is it correct to abort
161 * operation if control fails? */
173 switch ( op->o_tag ) {
175 case LDAP_REQ_MODIFY:
176 case LDAP_REQ_RENAME:
177 case LDAP_REQ_DELETE:
178 case LDAP_REQ_EXTENDED:
179 rc = LDAP_X_NO_OPERATION;
184 if ( get_pagedresults( op ) > SLAP_CONTROL_IGNORED ) {
185 struct berval cookie = BER_BVC( "" );
187 /* should not be here... */
188 assert( op->o_tag == LDAP_REQ_SEARCH );
190 ctrl[c].ldctl_oid = LDAP_CONTROL_PAGEDRESULTS;
191 ctrl[c].ldctl_iscritical = 0;
193 ps_ber = (BerElement *)&ps_berbuf;
194 ber_init2( ps_ber, NULL, LBER_USE_DER );
196 /* return size of 0 -- no estimate */
197 ber_printf( ps_ber, "{iO}", 0, &cookie );
199 if ( ber_flatten2( ps_ber, &ctrl[c].ldctl_value, 0 ) == -1 ) {
207 /* terminate controls array */
209 rs->sr_ctrls = ctrls;
213 send_ldap_result( op, rs );
217 if ( ps_ber != NULL ) {
218 (void) ber_free_buf( ps_ber );
221 if( preread_ctrl != NULL && (*preread_ctrl) != NULL ) {
222 slap_sl_free( (*preread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
223 slap_sl_free( *preread_ctrl, op->o_tmpmemctx );
226 if( postread_ctrl != NULL && (*postread_ctrl) != NULL ) {
227 slap_sl_free( (*postread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
228 slap_sl_free( *postread_ctrl, op->o_tmpmemctx );
234 /* add, delete, modify, modrdn, search */
236 null_back_success( Operation *op, SlapReply *rs )
238 return null_back_respond( op, rs, LDAP_SUCCESS );
243 null_back_false( Operation *op, SlapReply *rs )
245 return null_back_respond( op, rs, LDAP_COMPARE_FALSE );
255 AttributeDescription *at,
259 /* don't admit the object isn't there */
260 return oc || at ? LDAP_NO_SUCH_ATTRIBUTE : LDAP_BUSY;
267 null_tool_entry_open( BackendDB *be, int mode )
273 null_tool_entry_close( BackendDB *be )
275 assert( be != NULL );
280 null_tool_entry_first_x( BackendDB *be, struct berval *base, int scope, Filter *f )
286 null_tool_entry_next( BackendDB *be )
292 null_tool_entry_get( BackendDB *be, ID id )
294 assert( slapMode & SLAP_TOOL_MODE );
299 null_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
301 assert( slapMode & SLAP_TOOL_MODE );
302 assert( text != NULL );
303 assert( text->bv_val != NULL );
304 assert( text->bv_val[0] == '\0' ); /* overconservative? */
306 e->e_id = ((struct null_info *) be->be_private)->ni_nextid++;
314 null_cf_gen( ConfigArgs *c )
316 struct null_info *ni = (struct null_info *) c->be->be_private;
318 if ( c->op == SLAP_CONFIG_EMIT ) {
319 c->value_int = ni->ni_bind_allowed;
321 } else if ( c->op == LDAP_MOD_DELETE ) {
322 ni->ni_bind_allowed = 0;
326 ni->ni_bind_allowed = c->value_int;
331 null_back_db_init( BackendDB *be, ConfigReply *cr )
333 struct null_info *ni = ch_calloc( 1, sizeof(struct null_info) );
334 ni->ni_bind_allowed = 0;
337 be->be_cf_ocs = be->bd_info->bi_cf_ocs;
342 null_back_db_destroy( Backend *be, ConfigReply *cr )
344 free( be->be_private );
350 null_back_initialize( BackendInfo *bi )
352 static char *controls[] = {
354 LDAP_CONTROL_MANAGEDSAIT,
356 LDAP_CONTROL_PAGEDRESULTS,
357 LDAP_CONTROL_SUBENTRIES,
358 LDAP_CONTROL_PRE_READ,
359 LDAP_CONTROL_POST_READ,
360 LDAP_CONTROL_X_PERMISSIVE_MODIFY,
364 Debug( LDAP_DEBUG_TRACE,
365 "null_back_initialize: initialize null backend\n", 0, 0, 0 );
368 SLAP_BFLAG_INCREMENT |
369 SLAP_BFLAG_SUBENTRIES |
371 SLAP_BFLAG_REFERRALS;
373 bi->bi_controls = controls;
380 bi->bi_db_init = null_back_db_init;
381 bi->bi_db_config = config_generic_wrapper;
384 bi->bi_db_destroy = null_back_db_destroy;
386 bi->bi_op_bind = null_back_bind;
387 bi->bi_op_unbind = 0;
388 bi->bi_op_search = null_back_success;
389 bi->bi_op_compare = null_back_false;
390 bi->bi_op_modify = null_back_success;
391 bi->bi_op_modrdn = null_back_success;
392 bi->bi_op_add = null_back_success;
393 bi->bi_op_delete = null_back_success;
394 bi->bi_op_abandon = 0;
398 bi->bi_chk_referrals = 0;
400 bi->bi_connection_init = 0;
401 bi->bi_connection_destroy = 0;
403 bi->bi_entry_get_rw = null_back_entry_get;
405 bi->bi_tool_entry_open = null_tool_entry_open;
406 bi->bi_tool_entry_close = null_tool_entry_close;
407 bi->bi_tool_entry_first = backend_tool_entry_first;
408 bi->bi_tool_entry_first_x = null_tool_entry_first_x;
409 bi->bi_tool_entry_next = null_tool_entry_next;
410 bi->bi_tool_entry_get = null_tool_entry_get;
411 bi->bi_tool_entry_put = null_tool_entry_put;
413 bi->bi_cf_ocs = nullocs;
414 return config_register_schema( nullcfg, nullocs );
417 #if SLAPD_NULL == SLAPD_MOD_DYNAMIC
419 /* conditionally define the init_module() function */
420 SLAP_BACKEND_INIT_MODULE( null )
422 #endif /* SLAPD_NULL == SLAPD_MOD_DYNAMIC */