| 1 |
/* null.c - the null backend */ |
| 2 |
/* $OpenLDAP$ */ |
| 3 |
/* This work is part of OpenLDAP Software <http://www.openldap.org/>. |
| 4 |
* |
| 5 |
* Copyright 2002-2024 The OpenLDAP Foundation. |
| 6 |
* All rights reserved. |
| 7 |
* |
| 8 |
* Redistribution and use in source and binary forms, with or without |
| 9 |
* modification, are permitted only as authorized by the OpenLDAP |
| 10 |
* Public License. |
| 11 |
* |
| 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>. |
| 15 |
*/ |
| 16 |
/* ACKNOWLEDGEMENTS: |
| 17 |
* This work was originally developed by Hallvard Furuseth for inclusion |
| 18 |
* in OpenLDAP Software. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "portable.h" |
| 22 |
|
| 23 |
#include <stdio.h> |
| 24 |
#include <ac/string.h> |
| 25 |
|
| 26 |
#include "slap.h" |
| 27 |
#include "slap-config.h" |
| 28 |
|
| 29 |
typedef struct null_info { |
| 30 |
int ni_bind_allowed; |
| 31 |
int ni_dosearch; |
| 32 |
ID ni_nextid; |
| 33 |
Entry *ni_entry; |
| 34 |
} null_info; |
| 35 |
|
| 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 |
"EQUALITY booleanMatch " |
| 42 |
"SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL }, |
| 43 |
{ "dosearch", "true|FALSE", 1, 2, 0, ARG_ON_OFF|ARG_OFFSET, |
| 44 |
(void *)offsetof(null_info, ni_dosearch), |
| 45 |
"( OLcfgDbAt:8.2 NAME 'olcDbDoSearch' " |
| 46 |
"DESC 'Return an entry on searches' " |
| 47 |
"EQUALITY booleanMatch " |
| 48 |
"SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL }, |
| 49 |
{ NULL, NULL, 0, 0, 0, ARG_IGNORED, |
| 50 |
NULL, NULL, NULL, NULL } |
| 51 |
}; |
| 52 |
|
| 53 |
static ConfigOCs nullocs[] = { |
| 54 |
{ "( OLcfgDbOc:8.1 " |
| 55 |
"NAME 'olcNullConfig' " |
| 56 |
"DESC 'Null backend configuration' " |
| 57 |
"SUP olcDatabaseConfig " |
| 58 |
"MAY ( olcDbBindAllowed $ olcDbDoSearch ) )", |
| 59 |
Cft_Database, nullcfg }, |
| 60 |
{ NULL, 0, NULL } |
| 61 |
}; |
| 62 |
|
| 63 |
|
| 64 |
static int |
| 65 |
null_back_db_open( BackendDB *be, ConfigReply *cr ) |
| 66 |
{ |
| 67 |
struct null_info *ni = (struct null_info *) be->be_private; |
| 68 |
struct berval bv[2]; |
| 69 |
AttributeDescription *ad = NULL; |
| 70 |
const char *text; |
| 71 |
Entry *e; |
| 72 |
|
| 73 |
if ( ni->ni_dosearch ) { |
| 74 |
e = entry_alloc(); |
| 75 |
ber_dupbv( &e->e_name, &be->be_suffix[0] ); |
| 76 |
ber_dupbv( &e->e_nname, &be->be_nsuffix[0] ); |
| 77 |
|
| 78 |
dnRdn( &e->e_nname, &bv[0] ); |
| 79 |
bv[1].bv_val = strchr(bv[0].bv_val, '=') + 1; |
| 80 |
bv[1].bv_len = bv[0].bv_len - (bv[1].bv_val - |
| 81 |
bv[0].bv_val); |
| 82 |
bv[0].bv_len -= bv[1].bv_len + 1; |
| 83 |
slap_bv2ad( &bv[0], &ad, &text ); |
| 84 |
attr_merge_one( e, ad, &bv[1], NULL ); |
| 85 |
|
| 86 |
ber_str2bv("extensibleObject", 0, 0, &bv[0]); |
| 87 |
attr_merge_one( e, slap_schema.si_ad_objectClass, &bv[0], NULL); |
| 88 |
ni->ni_entry = e; |
| 89 |
} |
| 90 |
return 0; |
| 91 |
} |
| 92 |
|
| 93 |
/* LDAP operations */ |
| 94 |
|
| 95 |
static int |
| 96 |
null_back_bind( Operation *op, SlapReply *rs ) |
| 97 |
{ |
| 98 |
struct null_info *ni = (struct null_info *) op->o_bd->be_private; |
| 99 |
|
| 100 |
if ( ni->ni_bind_allowed || be_isroot_pw( op ) ) { |
| 101 |
/* front end will send result on success (0) */ |
| 102 |
return LDAP_SUCCESS; |
| 103 |
} |
| 104 |
|
| 105 |
rs->sr_err = LDAP_INVALID_CREDENTIALS; |
| 106 |
send_ldap_result( op, rs ); |
| 107 |
|
| 108 |
return rs->sr_err; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
static int |
| 113 |
null_back_respond( Operation *op, SlapReply *rs, int rc ) |
| 114 |
{ |
| 115 |
LDAPControl ctrl[SLAP_MAX_RESPONSE_CONTROLS], *ctrls[SLAP_MAX_RESPONSE_CONTROLS]; |
| 116 |
int c = 0; |
| 117 |
|
| 118 |
BerElementBuffer ps_berbuf; |
| 119 |
BerElement *ps_ber = NULL; |
| 120 |
LDAPControl **preread_ctrl = NULL, |
| 121 |
**postread_ctrl = NULL; |
| 122 |
|
| 123 |
rs->sr_err = LDAP_OTHER; |
| 124 |
|
| 125 |
/* this comes first, as in case of assertion failure |
| 126 |
* any further processing must stop */ |
| 127 |
if ( get_assert( op ) ) { |
| 128 |
rs->sr_err = LDAP_ASSERTION_FAILED; |
| 129 |
goto respond; |
| 130 |
} |
| 131 |
|
| 132 |
if ( op->o_preread ) { |
| 133 |
Entry e = { 0 }; |
| 134 |
|
| 135 |
switch ( op->o_tag ) { |
| 136 |
case LDAP_REQ_MODIFY: |
| 137 |
case LDAP_REQ_RENAME: |
| 138 |
case LDAP_REQ_DELETE: |
| 139 |
e.e_name = op->o_req_dn; |
| 140 |
e.e_nname = op->o_req_ndn; |
| 141 |
|
| 142 |
preread_ctrl = &ctrls[c]; |
| 143 |
*preread_ctrl = NULL; |
| 144 |
|
| 145 |
if ( slap_read_controls( op, rs, &e, |
| 146 |
&slap_pre_read_bv, preread_ctrl ) ) |
| 147 |
{ |
| 148 |
preread_ctrl = NULL; |
| 149 |
|
| 150 |
Debug( LDAP_DEBUG_TRACE, |
| 151 |
"<=- null_back_respond: pre-read " |
| 152 |
"failed!\n" ); |
| 153 |
|
| 154 |
if ( op->o_preread & SLAP_CONTROL_CRITICAL ) { |
| 155 |
/* FIXME: is it correct to abort |
| 156 |
* operation if control fails? */ |
| 157 |
goto respond; |
| 158 |
} |
| 159 |
|
| 160 |
} else { |
| 161 |
c++; |
| 162 |
} |
| 163 |
break; |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
if ( op->o_postread ) { |
| 168 |
Entry e = { 0 }; |
| 169 |
|
| 170 |
switch ( op->o_tag ) { |
| 171 |
case LDAP_REQ_ADD: |
| 172 |
case LDAP_REQ_MODIFY: |
| 173 |
case LDAP_REQ_RENAME: |
| 174 |
if ( op->o_tag == LDAP_REQ_ADD ) { |
| 175 |
e.e_name = op->ora_e->e_name; |
| 176 |
e.e_nname = op->ora_e->e_nname; |
| 177 |
|
| 178 |
} else { |
| 179 |
e.e_name = op->o_req_dn; |
| 180 |
e.e_nname = op->o_req_ndn; |
| 181 |
} |
| 182 |
|
| 183 |
postread_ctrl = &ctrls[c]; |
| 184 |
*postread_ctrl = NULL; |
| 185 |
|
| 186 |
if ( slap_read_controls( op, rs, &e, |
| 187 |
&slap_post_read_bv, postread_ctrl ) ) |
| 188 |
{ |
| 189 |
postread_ctrl = NULL; |
| 190 |
|
| 191 |
Debug( LDAP_DEBUG_TRACE, |
| 192 |
"<=- null_back_respond: post-read " |
| 193 |
"failed!\n" ); |
| 194 |
|
| 195 |
if ( op->o_postread & SLAP_CONTROL_CRITICAL ) { |
| 196 |
/* FIXME: is it correct to abort |
| 197 |
* operation if control fails? */ |
| 198 |
goto respond; |
| 199 |
} |
| 200 |
|
| 201 |
} else { |
| 202 |
c++; |
| 203 |
} |
| 204 |
break; |
| 205 |
} |
| 206 |
} |
| 207 |
|
| 208 |
if ( op->o_noop ) { |
| 209 |
switch ( op->o_tag ) { |
| 210 |
case LDAP_REQ_ADD: |
| 211 |
case LDAP_REQ_MODIFY: |
| 212 |
case LDAP_REQ_RENAME: |
| 213 |
case LDAP_REQ_DELETE: |
| 214 |
case LDAP_REQ_EXTENDED: |
| 215 |
rc = LDAP_X_NO_OPERATION; |
| 216 |
break; |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
if ( get_pagedresults( op ) > SLAP_CONTROL_IGNORED ) { |
| 221 |
struct berval cookie = BER_BVC( "" ); |
| 222 |
|
| 223 |
/* should not be here... */ |
| 224 |
assert( op->o_tag == LDAP_REQ_SEARCH ); |
| 225 |
|
| 226 |
ctrl[c].ldctl_oid = LDAP_CONTROL_PAGEDRESULTS; |
| 227 |
ctrl[c].ldctl_iscritical = 0; |
| 228 |
|
| 229 |
ps_ber = (BerElement *)&ps_berbuf; |
| 230 |
ber_init2( ps_ber, NULL, LBER_USE_DER ); |
| 231 |
|
| 232 |
/* return size of 0 -- no estimate */ |
| 233 |
ber_printf( ps_ber, "{iO}", 0, &cookie ); |
| 234 |
|
| 235 |
if ( ber_flatten2( ps_ber, &ctrl[c].ldctl_value, 0 ) == -1 ) { |
| 236 |
goto done; |
| 237 |
} |
| 238 |
|
| 239 |
ctrls[c] = &ctrl[c]; |
| 240 |
c++; |
| 241 |
} |
| 242 |
|
| 243 |
/* terminate controls array */ |
| 244 |
ctrls[c] = NULL; |
| 245 |
rs->sr_ctrls = ctrls; |
| 246 |
rs->sr_err = rc; |
| 247 |
|
| 248 |
respond:; |
| 249 |
send_ldap_result( op, rs ); |
| 250 |
rs->sr_ctrls = NULL; |
| 251 |
|
| 252 |
done:; |
| 253 |
if ( ps_ber != NULL ) { |
| 254 |
(void) ber_free_buf( ps_ber ); |
| 255 |
} |
| 256 |
|
| 257 |
if( preread_ctrl != NULL && (*preread_ctrl) != NULL ) { |
| 258 |
slap_sl_free( (*preread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx ); |
| 259 |
slap_sl_free( *preread_ctrl, op->o_tmpmemctx ); |
| 260 |
} |
| 261 |
|
| 262 |
if( postread_ctrl != NULL && (*postread_ctrl) != NULL ) { |
| 263 |
slap_sl_free( (*postread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx ); |
| 264 |
slap_sl_free( *postread_ctrl, op->o_tmpmemctx ); |
| 265 |
} |
| 266 |
|
| 267 |
return rs->sr_err; |
| 268 |
} |
| 269 |
|
| 270 |
/* add, delete, modify, modrdn, search */ |
| 271 |
static int |
| 272 |
null_back_success( Operation *op, SlapReply *rs ) |
| 273 |
{ |
| 274 |
return null_back_respond( op, rs, LDAP_SUCCESS ); |
| 275 |
} |
| 276 |
|
| 277 |
/* compare */ |
| 278 |
static int |
| 279 |
null_back_false( Operation *op, SlapReply *rs ) |
| 280 |
{ |
| 281 |
return null_back_respond( op, rs, LDAP_COMPARE_FALSE ); |
| 282 |
} |
| 283 |
|
| 284 |
static int |
| 285 |
null_back_search( Operation *op, SlapReply *rs ) |
| 286 |
{ |
| 287 |
struct null_info *ni = (struct null_info *) op->o_bd->be_private; |
| 288 |
|
| 289 |
if ( ni->ni_entry ) { |
| 290 |
rs->sr_entry = ni->ni_entry; |
| 291 |
rs->sr_flags = 0; |
| 292 |
|
| 293 |
rs->sr_attrs = op->ors_attrs; |
| 294 |
rs->sr_operational_attrs = NULL; |
| 295 |
send_search_entry( op, rs ); |
| 296 |
} |
| 297 |
return null_back_respond( op, rs, LDAP_SUCCESS ); |
| 298 |
} |
| 299 |
|
| 300 |
/* for overlays */ |
| 301 |
static int |
| 302 |
null_back_entry_get( |
| 303 |
Operation *op, |
| 304 |
struct berval *ndn, |
| 305 |
ObjectClass *oc, |
| 306 |
AttributeDescription *at, |
| 307 |
int rw, |
| 308 |
Entry **ent ) |
| 309 |
{ |
| 310 |
/* don't admit the object isn't there */ |
| 311 |
return oc || at ? LDAP_NO_SUCH_ATTRIBUTE : LDAP_BUSY; |
| 312 |
} |
| 313 |
|
| 314 |
static int |
| 315 |
null_back_entry_release( |
| 316 |
Operation *op, |
| 317 |
Entry *e, |
| 318 |
int rw ) |
| 319 |
{ |
| 320 |
/* we reuse our entry, don't free it */ |
| 321 |
return 0; |
| 322 |
} |
| 323 |
|
| 324 |
/* Slap tools */ |
| 325 |
|
| 326 |
static int |
| 327 |
null_tool_entry_open( BackendDB *be, int mode ) |
| 328 |
{ |
| 329 |
return 0; |
| 330 |
} |
| 331 |
|
| 332 |
static int |
| 333 |
null_tool_entry_close( BackendDB *be ) |
| 334 |
{ |
| 335 |
assert( be != NULL ); |
| 336 |
return 0; |
| 337 |
} |
| 338 |
|
| 339 |
static ID |
| 340 |
null_tool_entry_first_x( BackendDB *be, struct berval *base, int scope, Filter *f ) |
| 341 |
{ |
| 342 |
return NOID; |
| 343 |
} |
| 344 |
|
| 345 |
static ID |
| 346 |
null_tool_entry_next( BackendDB *be ) |
| 347 |
{ |
| 348 |
return NOID; |
| 349 |
} |
| 350 |
|
| 351 |
static Entry * |
| 352 |
null_tool_entry_get( BackendDB *be, ID id ) |
| 353 |
{ |
| 354 |
assert( slapMode & SLAP_TOOL_MODE ); |
| 355 |
return NULL; |
| 356 |
} |
| 357 |
|
| 358 |
static ID |
| 359 |
null_tool_entry_put( BackendDB *be, Entry *e, struct berval *text ) |
| 360 |
{ |
| 361 |
assert( slapMode & SLAP_TOOL_MODE ); |
| 362 |
assert( text != NULL ); |
| 363 |
assert( text->bv_val != NULL ); |
| 364 |
assert( text->bv_val[0] == '\0' ); /* overconservative? */ |
| 365 |
|
| 366 |
e->e_id = ((struct null_info *) be->be_private)->ni_nextid++; |
| 367 |
return e->e_id; |
| 368 |
} |
| 369 |
|
| 370 |
|
| 371 |
/* Setup */ |
| 372 |
|
| 373 |
static int |
| 374 |
null_back_db_init( BackendDB *be, ConfigReply *cr ) |
| 375 |
{ |
| 376 |
struct null_info *ni = ch_calloc( 1, sizeof(struct null_info) ); |
| 377 |
ni->ni_bind_allowed = 0; |
| 378 |
ni->ni_nextid = 1; |
| 379 |
be->be_private = ni; |
| 380 |
be->be_cf_ocs = be->bd_info->bi_cf_ocs; |
| 381 |
return 0; |
| 382 |
} |
| 383 |
|
| 384 |
static int |
| 385 |
null_back_db_destroy( Backend *be, ConfigReply *cr ) |
| 386 |
{ |
| 387 |
struct null_info *ni = be->be_private; |
| 388 |
|
| 389 |
if ( ni->ni_entry ) { |
| 390 |
entry_free( ni->ni_entry ); |
| 391 |
ni->ni_entry = NULL; |
| 392 |
} |
| 393 |
free( be->be_private ); |
| 394 |
return 0; |
| 395 |
} |
| 396 |
|
| 397 |
|
| 398 |
int |
| 399 |
null_back_initialize( BackendInfo *bi ) |
| 400 |
{ |
| 401 |
static char *controls[] = { |
| 402 |
LDAP_CONTROL_ASSERT, |
| 403 |
LDAP_CONTROL_MANAGEDSAIT, |
| 404 |
LDAP_CONTROL_NOOP, |
| 405 |
LDAP_CONTROL_PAGEDRESULTS, |
| 406 |
LDAP_CONTROL_SUBENTRIES, |
| 407 |
LDAP_CONTROL_PRE_READ, |
| 408 |
LDAP_CONTROL_POST_READ, |
| 409 |
LDAP_CONTROL_X_PERMISSIVE_MODIFY, |
| 410 |
NULL |
| 411 |
}; |
| 412 |
|
| 413 |
Debug( LDAP_DEBUG_TRACE, |
| 414 |
"null_back_initialize: initialize null backend\n" ); |
| 415 |
|
| 416 |
bi->bi_flags |= |
| 417 |
SLAP_BFLAG_INCREMENT | |
| 418 |
SLAP_BFLAG_SUBENTRIES | |
| 419 |
SLAP_BFLAG_ALIASES | |
| 420 |
SLAP_BFLAG_REFERRALS; |
| 421 |
|
| 422 |
bi->bi_controls = controls; |
| 423 |
|
| 424 |
bi->bi_open = 0; |
| 425 |
bi->bi_close = 0; |
| 426 |
bi->bi_config = 0; |
| 427 |
bi->bi_destroy = 0; |
| 428 |
|
| 429 |
bi->bi_db_init = null_back_db_init; |
| 430 |
bi->bi_db_config = config_generic_wrapper; |
| 431 |
bi->bi_db_open = null_back_db_open; |
| 432 |
bi->bi_db_close = 0; |
| 433 |
bi->bi_db_destroy = null_back_db_destroy; |
| 434 |
|
| 435 |
bi->bi_op_bind = null_back_bind; |
| 436 |
bi->bi_op_unbind = 0; |
| 437 |
bi->bi_op_search = null_back_search; |
| 438 |
bi->bi_op_compare = null_back_false; |
| 439 |
bi->bi_op_modify = null_back_success; |
| 440 |
bi->bi_op_modrdn = null_back_success; |
| 441 |
bi->bi_op_add = null_back_success; |
| 442 |
bi->bi_op_delete = null_back_success; |
| 443 |
bi->bi_op_abandon = 0; |
| 444 |
|
| 445 |
bi->bi_extended = 0; |
| 446 |
|
| 447 |
bi->bi_chk_referrals = 0; |
| 448 |
|
| 449 |
bi->bi_connection_init = 0; |
| 450 |
bi->bi_connection_destroy = 0; |
| 451 |
|
| 452 |
bi->bi_entry_get_rw = null_back_entry_get; |
| 453 |
bi->bi_entry_release_rw = null_back_entry_release; |
| 454 |
|
| 455 |
bi->bi_tool_entry_open = null_tool_entry_open; |
| 456 |
bi->bi_tool_entry_close = null_tool_entry_close; |
| 457 |
bi->bi_tool_entry_first = backend_tool_entry_first; |
| 458 |
bi->bi_tool_entry_first_x = null_tool_entry_first_x; |
| 459 |
bi->bi_tool_entry_next = null_tool_entry_next; |
| 460 |
bi->bi_tool_entry_get = null_tool_entry_get; |
| 461 |
bi->bi_tool_entry_put = null_tool_entry_put; |
| 462 |
|
| 463 |
bi->bi_cf_ocs = nullocs; |
| 464 |
return config_register_schema( nullcfg, nullocs ); |
| 465 |
} |
| 466 |
|
| 467 |
#if SLAPD_NULL == SLAPD_MOD_DYNAMIC |
| 468 |
|
| 469 |
/* conditionally define the init_module() function */ |
| 470 |
SLAP_BACKEND_INIT_MODULE( null ) |
| 471 |
|
| 472 |
#endif /* SLAPD_NULL == SLAPD_MOD_DYNAMIC */ |