1 /* null.c - the null backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2002-2010 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>
38 null_back_bind( Operation *op, SlapReply *rs )
40 struct null_info *ni = (struct null_info *) op->o_bd->be_private;
42 if ( ni->ni_bind_allowed || be_isroot_pw( op ) ) {
43 /* front end will send result on success (0) */
47 rs->sr_err = LDAP_INVALID_CREDENTIALS;
48 send_ldap_result( op, rs );
55 null_back_respond( Operation *op, SlapReply *rs, int rc )
57 LDAPControl ctrl[SLAP_MAX_RESPONSE_CONTROLS], *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
60 BerElementBuffer ps_berbuf;
61 BerElement *ps_ber = NULL;
62 LDAPControl **preread_ctrl = NULL,
63 **postread_ctrl = NULL;
65 rs->sr_err = LDAP_OTHER;
67 /* this comes first, as in case of assertion failure
68 * any further processing must stop */
69 if ( get_assert( op ) ) {
70 rs->sr_err = LDAP_ASSERTION_FAILED;
74 if ( op->o_preread ) {
77 switch ( op->o_tag ) {
81 e.e_name = op->o_req_dn;
82 e.e_nname = op->o_req_ndn;
84 preread_ctrl = &ctrls[c];
87 if ( slap_read_controls( op, rs, &e,
88 &slap_pre_read_bv, preread_ctrl ) )
92 Debug( LDAP_DEBUG_TRACE,
93 "<=- null_back_respond: pre-read "
94 "failed!\n", 0, 0, 0 );
96 if ( op->o_preread & SLAP_CONTROL_CRITICAL ) {
97 /* FIXME: is it correct to abort
98 * operation if control fails? */
109 if ( op->o_postread ) {
112 switch ( op->o_tag ) {
114 case LDAP_REQ_MODIFY:
115 case LDAP_REQ_RENAME:
116 if ( op->o_tag == LDAP_REQ_ADD ) {
117 e.e_name = op->ora_e->e_name;
118 e.e_nname = op->ora_e->e_nname;
121 e.e_name = op->o_req_dn;
122 e.e_nname = op->o_req_ndn;
125 postread_ctrl = &ctrls[c];
126 *postread_ctrl = NULL;
128 if ( slap_read_controls( op, rs, &e,
129 &slap_post_read_bv, postread_ctrl ) )
131 postread_ctrl = NULL;
133 Debug( LDAP_DEBUG_TRACE,
134 "<=- null_back_respond: post-read "
135 "failed!\n", 0, 0, 0 );
137 if ( op->o_postread & SLAP_CONTROL_CRITICAL ) {
138 /* FIXME: is it correct to abort
139 * operation if control fails? */
151 switch ( op->o_tag ) {
153 case LDAP_REQ_MODIFY:
154 case LDAP_REQ_RENAME:
155 case LDAP_REQ_DELETE:
156 case LDAP_REQ_EXTENDED:
157 rc = LDAP_X_NO_OPERATION;
162 if ( get_pagedresults( op ) > SLAP_CONTROL_IGNORED ) {
163 struct berval cookie = BER_BVC( "" );
165 /* should not be here... */
166 assert( op->o_tag == LDAP_REQ_SEARCH );
168 ctrl[c].ldctl_oid = LDAP_CONTROL_PAGEDRESULTS;
169 ctrl[c].ldctl_iscritical = 0;
171 ps_ber = (BerElement *)&ps_berbuf;
172 ber_init2( ps_ber, NULL, LBER_USE_DER );
174 /* return size of 0 -- no estimate */
175 ber_printf( ps_ber, "{iO}", 0, &cookie );
177 if ( ber_flatten2( ps_ber, &ctrl[c].ldctl_value, 0 ) == -1 ) {
185 /* terminate controls array */
187 rs->sr_ctrls = ctrls;
191 send_ldap_result( op, rs );
195 if ( ps_ber != NULL ) {
196 (void) ber_free_buf( ps_ber );
199 if( preread_ctrl != NULL && (*preread_ctrl) != NULL ) {
200 slap_sl_free( (*preread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
201 slap_sl_free( *preread_ctrl, op->o_tmpmemctx );
204 if( postread_ctrl != NULL && (*postread_ctrl) != NULL ) {
205 slap_sl_free( (*postread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
206 slap_sl_free( *postread_ctrl, op->o_tmpmemctx );
212 /* add, delete, modify, modrdn, search */
214 null_back_success( Operation *op, SlapReply *rs )
216 return null_back_respond( op, rs, LDAP_SUCCESS );
221 null_back_false( Operation *op, SlapReply *rs )
223 return null_back_respond( op, rs, LDAP_COMPARE_FALSE );
233 AttributeDescription *at,
237 /* don't admit the object isn't there */
238 return oc || at ? LDAP_NO_SUCH_ATTRIBUTE : LDAP_BUSY;
245 null_tool_entry_open( BackendDB *be, int mode )
251 null_tool_entry_close( BackendDB *be )
253 assert( be != NULL );
258 null_tool_entry_next( BackendDB *be )
264 null_tool_entry_get( BackendDB *be, ID id )
266 assert( slapMode & SLAP_TOOL_MODE );
271 null_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
273 assert( slapMode & SLAP_TOOL_MODE );
274 assert( text != NULL );
275 assert( text->bv_val != NULL );
276 assert( text->bv_val[0] == '\0' ); /* overconservative? */
278 e->e_id = ((struct null_info *) be->be_private)->ni_nextid++;
293 struct null_info *ni = (struct null_info *) be->be_private;
296 fprintf( stderr, "%s: line %d: null database info is null!\n",
301 /* bind requests allowed */
302 if ( strcasecmp( argv[0], "bind" ) == 0 ) {
305 "%s: line %d: missing <on/off> in \"bind <on/off>\" line\n",
309 ni->ni_bind_allowed = strcasecmp( argv[1], "off" );
313 return SLAP_CONF_UNKNOWN;
320 null_back_db_init( BackendDB *be, ConfigReply *cr )
322 struct null_info *ni = ch_calloc( 1, sizeof(struct null_info) );
323 ni->ni_bind_allowed = 0;
330 null_back_db_destroy( Backend *be, ConfigReply *cr )
332 free( be->be_private );
338 null_back_initialize( BackendInfo *bi )
340 static char *controls[] = {
342 LDAP_CONTROL_MANAGEDSAIT,
344 LDAP_CONTROL_PAGEDRESULTS,
345 LDAP_CONTROL_SUBENTRIES,
346 LDAP_CONTROL_PRE_READ,
347 LDAP_CONTROL_POST_READ,
348 LDAP_CONTROL_X_PERMISSIVE_MODIFY,
352 Debug( LDAP_DEBUG_TRACE,
353 "null_back_initialize: initialize null backend\n", 0, 0, 0 );
356 SLAP_BFLAG_INCREMENT |
357 SLAP_BFLAG_SUBENTRIES |
359 SLAP_BFLAG_REFERRALS;
361 bi->bi_controls = controls;
368 bi->bi_db_init = null_back_db_init;
369 bi->bi_db_config = null_back_db_config;
372 bi->bi_db_destroy = null_back_db_destroy;
374 bi->bi_op_bind = null_back_bind;
375 bi->bi_op_unbind = 0;
376 bi->bi_op_search = null_back_success;
377 bi->bi_op_compare = null_back_false;
378 bi->bi_op_modify = null_back_success;
379 bi->bi_op_modrdn = null_back_success;
380 bi->bi_op_add = null_back_success;
381 bi->bi_op_delete = null_back_success;
382 bi->bi_op_abandon = 0;
386 bi->bi_chk_referrals = 0;
388 bi->bi_connection_init = 0;
389 bi->bi_connection_destroy = 0;
391 bi->bi_entry_get_rw = null_back_entry_get;
393 bi->bi_tool_entry_open = null_tool_entry_open;
394 bi->bi_tool_entry_close = null_tool_entry_close;
395 bi->bi_tool_entry_first = null_tool_entry_next;
396 bi->bi_tool_entry_next = null_tool_entry_next;
397 bi->bi_tool_entry_get = null_tool_entry_get;
398 bi->bi_tool_entry_put = null_tool_entry_put;
403 #if SLAPD_NULL == SLAPD_MOD_DYNAMIC
405 /* conditionally define the init_module() function */
406 SLAP_BACKEND_INIT_MODULE( null )
408 #endif /* SLAPD_NULL == SLAPD_MOD_DYNAMIC */