| 1 |
/* retcode.c - customizable response for client testing purposes */ |
| 2 |
/* $OpenLDAP$ */ |
| 3 |
/* This work is part of OpenLDAP Software <http://www.openldap.org/>. |
| 4 |
* |
| 5 |
* Copyright 2005-2024 The OpenLDAP Foundation. |
| 6 |
* Portions Copyright 2005 Pierangelo Masarati <[email protected]> |
| 7 |
* All rights reserved. |
| 8 |
* |
| 9 |
* Redistribution and use in source and binary forms, with or without |
| 10 |
* modification, are permitted only as authorized by the OpenLDAP |
| 11 |
* Public License. |
| 12 |
* |
| 13 |
* A copy of this license is available in the file LICENSE in the |
| 14 |
* top-level directory of the distribution or, alternatively, at |
| 15 |
* <http://www.OpenLDAP.org/license.html>. |
| 16 |
*/ |
| 17 |
/* ACKNOWLEDGEMENTS: |
| 18 |
* This work was initially developed by Pierangelo Masarati for inclusion |
| 19 |
* in OpenLDAP Software. |
| 20 |
*/ |
| 21 |
|
| 22 |
#include "portable.h" |
| 23 |
|
| 24 |
#ifdef SLAPD_OVER_RETCODE |
| 25 |
|
| 26 |
#include <stdio.h> |
| 27 |
|
| 28 |
#include <ac/unistd.h> |
| 29 |
#include <ac/string.h> |
| 30 |
#include <ac/ctype.h> |
| 31 |
#include <ac/socket.h> |
| 32 |
|
| 33 |
#include "slap.h" |
| 34 |
#include "slap-config.h" |
| 35 |
#include "lutil.h" |
| 36 |
#include "ldif.h" |
| 37 |
|
| 38 |
static slap_overinst retcode; |
| 39 |
|
| 40 |
static AttributeDescription *ad_errCode; |
| 41 |
static AttributeDescription *ad_errText; |
| 42 |
static AttributeDescription *ad_errOp; |
| 43 |
static AttributeDescription *ad_errSleepTime; |
| 44 |
static AttributeDescription *ad_errMatchedDN; |
| 45 |
static AttributeDescription *ad_errUnsolicitedOID; |
| 46 |
static AttributeDescription *ad_errUnsolicitedData; |
| 47 |
static AttributeDescription *ad_errDisconnect; |
| 48 |
|
| 49 |
static ObjectClass *oc_errAbsObject; |
| 50 |
static ObjectClass *oc_errObject; |
| 51 |
static ObjectClass *oc_errAuxObject; |
| 52 |
|
| 53 |
typedef enum retcode_op_e { |
| 54 |
SN_DG_OP_NONE = 0x0000, |
| 55 |
SN_DG_OP_ADD = 0x0001, |
| 56 |
SN_DG_OP_BIND = 0x0002, |
| 57 |
SN_DG_OP_COMPARE = 0x0004, |
| 58 |
SN_DG_OP_DELETE = 0x0008, |
| 59 |
SN_DG_OP_MODIFY = 0x0010, |
| 60 |
SN_DG_OP_RENAME = 0x0020, |
| 61 |
SN_DG_OP_SEARCH = 0x0040, |
| 62 |
SN_DG_EXTENDED = 0x0080, |
| 63 |
SN_DG_OP_AUTH = SN_DG_OP_BIND, |
| 64 |
SN_DG_OP_READ = (SN_DG_OP_COMPARE|SN_DG_OP_SEARCH), |
| 65 |
SN_DG_OP_WRITE = (SN_DG_OP_ADD|SN_DG_OP_DELETE|SN_DG_OP_MODIFY|SN_DG_OP_RENAME), |
| 66 |
SN_DG_OP_ALL = (SN_DG_OP_AUTH|SN_DG_OP_READ|SN_DG_OP_WRITE|SN_DG_EXTENDED) |
| 67 |
} retcode_op_e; |
| 68 |
|
| 69 |
typedef struct retcode_item_t { |
| 70 |
struct berval rdi_line; |
| 71 |
struct berval rdi_dn; |
| 72 |
struct berval rdi_ndn; |
| 73 |
struct berval rdi_text; |
| 74 |
struct berval rdi_matched; |
| 75 |
int rdi_err; |
| 76 |
BerVarray rdi_ref; |
| 77 |
int rdi_sleeptime; |
| 78 |
Entry rdi_e; |
| 79 |
slap_mask_t rdi_mask; |
| 80 |
struct berval rdi_unsolicited_oid; |
| 81 |
struct berval rdi_unsolicited_data; |
| 82 |
|
| 83 |
unsigned rdi_flags; |
| 84 |
#define RDI_PRE_DISCONNECT (0x1U) |
| 85 |
#define RDI_POST_DISCONNECT (0x2U) |
| 86 |
|
| 87 |
struct retcode_item_t *rdi_next; |
| 88 |
} retcode_item_t; |
| 89 |
|
| 90 |
typedef struct retcode_t { |
| 91 |
struct berval rd_pdn; |
| 92 |
struct berval rd_npdn; |
| 93 |
|
| 94 |
int rd_sleep; |
| 95 |
|
| 96 |
retcode_item_t *rd_item; |
| 97 |
|
| 98 |
int rd_indir; |
| 99 |
#define RETCODE_FINDIR 0x01 |
| 100 |
#define RETCODE_INDIR( rd ) ( (rd)->rd_indir ) |
| 101 |
} retcode_t; |
| 102 |
|
| 103 |
static int |
| 104 |
retcode_entry_response( Operation *op, SlapReply *rs, BackendInfo *bi, Entry *e ); |
| 105 |
|
| 106 |
static unsigned int |
| 107 |
retcode_sleep( int s ) |
| 108 |
{ |
| 109 |
unsigned int r = 0; |
| 110 |
|
| 111 |
/* sleep as required */ |
| 112 |
if ( s < 0 ) { |
| 113 |
#if 0 /* use high-order bits for better randomness (Numerical Recipes in "C") */ |
| 114 |
r = rand() % (-s); |
| 115 |
#endif |
| 116 |
r = ((double)(-s))*rand()/(RAND_MAX + 1.0); |
| 117 |
} else if ( s > 0 ) { |
| 118 |
r = (unsigned int)s; |
| 119 |
} |
| 120 |
if ( r ) { |
| 121 |
sleep( r ); |
| 122 |
} |
| 123 |
|
| 124 |
return r; |
| 125 |
} |
| 126 |
|
| 127 |
static int |
| 128 |
retcode_cleanup_cb( Operation *op, SlapReply *rs ) |
| 129 |
{ |
| 130 |
rs->sr_matched = NULL; |
| 131 |
rs->sr_text = NULL; |
| 132 |
|
| 133 |
if ( rs->sr_ref != NULL ) { |
| 134 |
ber_bvarray_free( rs->sr_ref ); |
| 135 |
rs->sr_ref = NULL; |
| 136 |
} |
| 137 |
|
| 138 |
ch_free( op->o_callback ); |
| 139 |
op->o_callback = NULL; |
| 140 |
|
| 141 |
return SLAP_CB_CONTINUE; |
| 142 |
} |
| 143 |
|
| 144 |
static int |
| 145 |
retcode_send_onelevel( Operation *op, SlapReply *rs ) |
| 146 |
{ |
| 147 |
slap_overinst *on = (slap_overinst *)op->o_bd->bd_info; |
| 148 |
retcode_t *rd = (retcode_t *)on->on_bi.bi_private; |
| 149 |
|
| 150 |
retcode_item_t *rdi; |
| 151 |
|
| 152 |
for ( rdi = rd->rd_item; rdi != NULL; rdi = rdi->rdi_next ) { |
| 153 |
if ( op->o_abandon ) { |
| 154 |
return rs->sr_err = SLAPD_ABANDON; |
| 155 |
} |
| 156 |
|
| 157 |
rs->sr_err = test_filter( op, &rdi->rdi_e, op->ors_filter ); |
| 158 |
if ( rs->sr_err == LDAP_COMPARE_TRUE ) { |
| 159 |
/* safe default */ |
| 160 |
rs->sr_attrs = op->ors_attrs; |
| 161 |
rs->sr_operational_attrs = NULL; |
| 162 |
rs->sr_ctrls = NULL; |
| 163 |
rs->sr_flags = 0; |
| 164 |
rs->sr_err = LDAP_SUCCESS; |
| 165 |
rs->sr_entry = &rdi->rdi_e; |
| 166 |
|
| 167 |
rs->sr_err = send_search_entry( op, rs ); |
| 168 |
rs->sr_flags = 0; |
| 169 |
rs->sr_entry = NULL; |
| 170 |
rs->sr_attrs = NULL; |
| 171 |
|
| 172 |
switch ( rs->sr_err ) { |
| 173 |
case LDAP_UNAVAILABLE: /* connection closed */ |
| 174 |
rs->sr_err = LDAP_OTHER; |
| 175 |
/* fallthru */ |
| 176 |
case LDAP_SIZELIMIT_EXCEEDED: |
| 177 |
goto done; |
| 178 |
} |
| 179 |
} |
| 180 |
rs->sr_err = LDAP_SUCCESS; |
| 181 |
} |
| 182 |
|
| 183 |
done:; |
| 184 |
|
| 185 |
send_ldap_result( op, rs ); |
| 186 |
|
| 187 |
return rs->sr_err; |
| 188 |
} |
| 189 |
|
| 190 |
static int |
| 191 |
retcode_op_add( Operation *op, SlapReply *rs ) |
| 192 |
{ |
| 193 |
return retcode_entry_response( op, rs, NULL, op->ora_e ); |
| 194 |
} |
| 195 |
|
| 196 |
typedef struct retcode_cb_t { |
| 197 |
BackendInfo *rdc_info; |
| 198 |
unsigned rdc_flags; |
| 199 |
ber_tag_t rdc_tag; |
| 200 |
AttributeName *rdc_attrs; |
| 201 |
} retcode_cb_t; |
| 202 |
|
| 203 |
static int |
| 204 |
retcode_cb_response( Operation *op, SlapReply *rs ) |
| 205 |
{ |
| 206 |
retcode_cb_t *rdc = (retcode_cb_t *)op->o_callback->sc_private; |
| 207 |
|
| 208 |
op->o_tag = rdc->rdc_tag; |
| 209 |
if ( rs->sr_type == REP_SEARCH ) { |
| 210 |
ber_tag_t o_tag = op->o_tag; |
| 211 |
int rc; |
| 212 |
|
| 213 |
if ( op->o_tag == LDAP_REQ_SEARCH ) { |
| 214 |
rs->sr_attrs = rdc->rdc_attrs; |
| 215 |
} |
| 216 |
rc = retcode_entry_response( op, rs, rdc->rdc_info, rs->sr_entry ); |
| 217 |
op->o_tag = o_tag; |
| 218 |
|
| 219 |
return rc; |
| 220 |
} |
| 221 |
|
| 222 |
switch ( rs->sr_err ) { |
| 223 |
case LDAP_SUCCESS: |
| 224 |
case LDAP_NO_SUCH_OBJECT: |
| 225 |
/* in case of noSuchObject, stop the internal search |
| 226 |
* for in-directory error stuff */ |
| 227 |
if ( !op->o_abandon ) { |
| 228 |
rdc->rdc_flags = SLAP_CB_CONTINUE; |
| 229 |
} |
| 230 |
return 0; |
| 231 |
} |
| 232 |
|
| 233 |
return SLAP_CB_CONTINUE; |
| 234 |
} |
| 235 |
|
| 236 |
static int |
| 237 |
retcode_op_internal( Operation *op, SlapReply *rs ) |
| 238 |
{ |
| 239 |
slap_overinst *on = (slap_overinst *)op->o_bd->bd_info; |
| 240 |
|
| 241 |
Operation op2 = *op; |
| 242 |
BackendDB db = *op->o_bd; |
| 243 |
slap_callback sc = { 0 }; |
| 244 |
retcode_cb_t rdc; |
| 245 |
|
| 246 |
int rc; |
| 247 |
|
| 248 |
op2.o_tag = LDAP_REQ_SEARCH; |
| 249 |
op2.ors_scope = LDAP_SCOPE_BASE; |
| 250 |
op2.ors_deref = LDAP_DEREF_NEVER; |
| 251 |
op2.ors_tlimit = SLAP_NO_LIMIT; |
| 252 |
op2.ors_slimit = SLAP_NO_LIMIT; |
| 253 |
op2.ors_limit = NULL; |
| 254 |
op2.ors_attrsonly = 0; |
| 255 |
op2.ors_attrs = slap_anlist_all_attributes; |
| 256 |
|
| 257 |
ber_str2bv_x( "(objectClass=errAbsObject)", |
| 258 |
STRLENOF( "(objectClass=errAbsObject)" ), |
| 259 |
1, &op2.ors_filterstr, op2.o_tmpmemctx ); |
| 260 |
op2.ors_filter = str2filter_x( &op2, op2.ors_filterstr.bv_val ); |
| 261 |
|
| 262 |
/* errAbsObject is defined by this overlay! */ |
| 263 |
assert( op2.ors_filter != NULL ); |
| 264 |
|
| 265 |
db.bd_info = on->on_info->oi_orig; |
| 266 |
op2.o_bd = &db; |
| 267 |
|
| 268 |
rdc.rdc_info = on->on_info->oi_orig; |
| 269 |
rdc.rdc_flags = RETCODE_FINDIR; |
| 270 |
if ( op->o_tag == LDAP_REQ_SEARCH ) { |
| 271 |
rdc.rdc_attrs = op->ors_attrs; |
| 272 |
} |
| 273 |
rdc.rdc_tag = op->o_tag; |
| 274 |
sc.sc_response = retcode_cb_response; |
| 275 |
sc.sc_private = &rdc; |
| 276 |
op2.o_callback = ≻ |
| 277 |
|
| 278 |
rc = op2.o_bd->be_search( &op2, rs ); |
| 279 |
op->o_abandon = op2.o_abandon; |
| 280 |
|
| 281 |
filter_free_x( &op2, op2.ors_filter, 1 ); |
| 282 |
ber_memfree_x( op2.ors_filterstr.bv_val, op2.o_tmpmemctx ); |
| 283 |
|
| 284 |
if ( rdc.rdc_flags == SLAP_CB_CONTINUE ) { |
| 285 |
return SLAP_CB_CONTINUE; |
| 286 |
} |
| 287 |
|
| 288 |
return rc; |
| 289 |
} |
| 290 |
|
| 291 |
static int |
| 292 |
retcode_op_func( Operation *op, SlapReply *rs ) |
| 293 |
{ |
| 294 |
slap_overinst *on = (slap_overinst *)op->o_bd->bd_info; |
| 295 |
retcode_t *rd = (retcode_t *)on->on_bi.bi_private; |
| 296 |
|
| 297 |
retcode_item_t *rdi; |
| 298 |
struct berval nrdn, npdn; |
| 299 |
|
| 300 |
slap_callback *cb = NULL; |
| 301 |
|
| 302 |
/* sleep as required */ |
| 303 |
retcode_sleep( rd->rd_sleep ); |
| 304 |
|
| 305 |
if ( !dnIsSuffix( &op->o_req_ndn, &rd->rd_npdn ) ) { |
| 306 |
if ( RETCODE_INDIR( rd ) ) { |
| 307 |
switch ( op->o_tag ) { |
| 308 |
case LDAP_REQ_ADD: |
| 309 |
return retcode_op_add( op, rs ); |
| 310 |
|
| 311 |
case LDAP_REQ_BIND: |
| 312 |
/* skip if rootdn */ |
| 313 |
/* FIXME: better give the db a chance? */ |
| 314 |
if ( be_isroot_pw( op ) ) { |
| 315 |
return LDAP_SUCCESS; |
| 316 |
} |
| 317 |
return retcode_op_internal( op, rs ); |
| 318 |
|
| 319 |
case LDAP_REQ_SEARCH: |
| 320 |
if ( op->ors_scope == LDAP_SCOPE_BASE ) { |
| 321 |
rs->sr_err = retcode_op_internal( op, rs ); |
| 322 |
switch ( rs->sr_err ) { |
| 323 |
case SLAP_CB_CONTINUE: |
| 324 |
if ( rs->sr_nentries == 0 ) { |
| 325 |
break; |
| 326 |
} |
| 327 |
rs->sr_err = LDAP_SUCCESS; |
| 328 |
/* fallthru */ |
| 329 |
|
| 330 |
default: |
| 331 |
send_ldap_result( op, rs ); |
| 332 |
break; |
| 333 |
} |
| 334 |
return rs->sr_err; |
| 335 |
} |
| 336 |
break; |
| 337 |
|
| 338 |
case LDAP_REQ_MODIFY: |
| 339 |
case LDAP_REQ_DELETE: |
| 340 |
case LDAP_REQ_MODRDN: |
| 341 |
case LDAP_REQ_COMPARE: |
| 342 |
return retcode_op_internal( op, rs ); |
| 343 |
} |
| 344 |
} |
| 345 |
|
| 346 |
return SLAP_CB_CONTINUE; |
| 347 |
} |
| 348 |
|
| 349 |
if ( op->o_tag == LDAP_REQ_SEARCH |
| 350 |
&& op->ors_scope != LDAP_SCOPE_BASE |
| 351 |
&& op->o_req_ndn.bv_len == rd->rd_npdn.bv_len ) |
| 352 |
{ |
| 353 |
return retcode_send_onelevel( op, rs ); |
| 354 |
} |
| 355 |
|
| 356 |
dnParent( &op->o_req_ndn, &npdn ); |
| 357 |
if ( npdn.bv_len != rd->rd_npdn.bv_len ) { |
| 358 |
rs->sr_err = LDAP_NO_SUCH_OBJECT; |
| 359 |
rs->sr_matched = rd->rd_pdn.bv_val; |
| 360 |
send_ldap_result( op, rs ); |
| 361 |
rs->sr_matched = NULL; |
| 362 |
return rs->sr_err; |
| 363 |
} |
| 364 |
|
| 365 |
dnRdn( &op->o_req_ndn, &nrdn ); |
| 366 |
|
| 367 |
for ( rdi = rd->rd_item; rdi != NULL; rdi = rdi->rdi_next ) { |
| 368 |
struct berval rdi_nrdn; |
| 369 |
|
| 370 |
dnRdn( &rdi->rdi_ndn, &rdi_nrdn ); |
| 371 |
if ( dn_match( &nrdn, &rdi_nrdn ) ) { |
| 372 |
break; |
| 373 |
} |
| 374 |
} |
| 375 |
|
| 376 |
if ( rdi != NULL && rdi->rdi_mask != SN_DG_OP_ALL ) { |
| 377 |
retcode_op_e o_tag = SN_DG_OP_NONE; |
| 378 |
|
| 379 |
switch ( op->o_tag ) { |
| 380 |
case LDAP_REQ_ADD: |
| 381 |
o_tag = SN_DG_OP_ADD; |
| 382 |
break; |
| 383 |
|
| 384 |
case LDAP_REQ_BIND: |
| 385 |
o_tag = SN_DG_OP_BIND; |
| 386 |
break; |
| 387 |
|
| 388 |
case LDAP_REQ_COMPARE: |
| 389 |
o_tag = SN_DG_OP_COMPARE; |
| 390 |
break; |
| 391 |
|
| 392 |
case LDAP_REQ_DELETE: |
| 393 |
o_tag = SN_DG_OP_DELETE; |
| 394 |
break; |
| 395 |
|
| 396 |
case LDAP_REQ_MODIFY: |
| 397 |
o_tag = SN_DG_OP_MODIFY; |
| 398 |
break; |
| 399 |
|
| 400 |
case LDAP_REQ_MODRDN: |
| 401 |
o_tag = SN_DG_OP_RENAME; |
| 402 |
break; |
| 403 |
|
| 404 |
case LDAP_REQ_SEARCH: |
| 405 |
o_tag = SN_DG_OP_SEARCH; |
| 406 |
break; |
| 407 |
|
| 408 |
case LDAP_REQ_EXTENDED: |
| 409 |
o_tag = SN_DG_EXTENDED; |
| 410 |
break; |
| 411 |
|
| 412 |
default: |
| 413 |
/* Should not happen */ |
| 414 |
break; |
| 415 |
} |
| 416 |
|
| 417 |
if ( !( o_tag & rdi->rdi_mask ) ) { |
| 418 |
return SLAP_CB_CONTINUE; |
| 419 |
} |
| 420 |
} |
| 421 |
|
| 422 |
if ( rdi == NULL ) { |
| 423 |
rs->sr_matched = rd->rd_pdn.bv_val; |
| 424 |
rs->sr_err = LDAP_NO_SUCH_OBJECT; |
| 425 |
rs->sr_text = "retcode not found"; |
| 426 |
|
| 427 |
} else { |
| 428 |
if ( rdi->rdi_flags & RDI_PRE_DISCONNECT ) { |
| 429 |
return rs->sr_err = SLAPD_DISCONNECT; |
| 430 |
} |
| 431 |
|
| 432 |
rs->sr_err = rdi->rdi_err; |
| 433 |
rs->sr_text = rdi->rdi_text.bv_val; |
| 434 |
rs->sr_matched = rdi->rdi_matched.bv_val; |
| 435 |
|
| 436 |
/* FIXME: we only honor the rdi_ref field in case rdi_err |
| 437 |
* is LDAP_REFERRAL otherwise send_ldap_result() bails out */ |
| 438 |
if ( rs->sr_err == LDAP_REFERRAL ) { |
| 439 |
BerVarray ref; |
| 440 |
|
| 441 |
if ( rdi->rdi_ref != NULL ) { |
| 442 |
ref = rdi->rdi_ref; |
| 443 |
} else { |
| 444 |
ref = default_referral; |
| 445 |
} |
| 446 |
|
| 447 |
if ( ref != NULL ) { |
| 448 |
rs->sr_ref = referral_rewrite( ref, |
| 449 |
NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT ); |
| 450 |
|
| 451 |
} else { |
| 452 |
rs->sr_err = LDAP_OTHER; |
| 453 |
rs->sr_text = "bad referral object"; |
| 454 |
} |
| 455 |
} |
| 456 |
|
| 457 |
retcode_sleep( rdi->rdi_sleeptime ); |
| 458 |
} |
| 459 |
|
| 460 |
switch ( op->o_tag ) { |
| 461 |
case LDAP_REQ_EXTENDED: |
| 462 |
if ( rdi == NULL ) { |
| 463 |
break; |
| 464 |
} |
| 465 |
cb = ( slap_callback * )ch_malloc( sizeof( slap_callback ) ); |
| 466 |
memset( cb, 0, sizeof( slap_callback ) ); |
| 467 |
cb->sc_cleanup = retcode_cleanup_cb; |
| 468 |
op->o_callback = cb; |
| 469 |
break; |
| 470 |
|
| 471 |
default: |
| 472 |
if ( rdi && !BER_BVISNULL( &rdi->rdi_unsolicited_oid ) ) { |
| 473 |
ber_int_t msgid = op->o_msgid; |
| 474 |
|
| 475 |
/* RFC 4511 unsolicited response */ |
| 476 |
|
| 477 |
op->o_msgid = 0; |
| 478 |
if ( strcmp( rdi->rdi_unsolicited_oid.bv_val, "0" ) == 0 ) { |
| 479 |
send_ldap_result( op, rs ); |
| 480 |
|
| 481 |
} else { |
| 482 |
ber_tag_t tag = op->o_tag; |
| 483 |
|
| 484 |
op->o_tag = LDAP_REQ_EXTENDED; |
| 485 |
rs->sr_rspoid = rdi->rdi_unsolicited_oid.bv_val; |
| 486 |
if ( !BER_BVISNULL( &rdi->rdi_unsolicited_data ) ) { |
| 487 |
rs->sr_rspdata = &rdi->rdi_unsolicited_data; |
| 488 |
} |
| 489 |
send_ldap_extended( op, rs ); |
| 490 |
rs->sr_rspoid = NULL; |
| 491 |
rs->sr_rspdata = NULL; |
| 492 |
op->o_tag = tag; |
| 493 |
|
| 494 |
} |
| 495 |
op->o_msgid = msgid; |
| 496 |
|
| 497 |
} else { |
| 498 |
send_ldap_result( op, rs ); |
| 499 |
} |
| 500 |
|
| 501 |
if ( rs->sr_ref != NULL ) { |
| 502 |
ber_bvarray_free( rs->sr_ref ); |
| 503 |
rs->sr_ref = NULL; |
| 504 |
} |
| 505 |
rs->sr_matched = NULL; |
| 506 |
rs->sr_text = NULL; |
| 507 |
|
| 508 |
if ( rdi && rdi->rdi_flags & RDI_POST_DISCONNECT ) { |
| 509 |
return rs->sr_err = SLAPD_DISCONNECT; |
| 510 |
} |
| 511 |
break; |
| 512 |
} |
| 513 |
|
| 514 |
return rs->sr_err; |
| 515 |
} |
| 516 |
|
| 517 |
static int |
| 518 |
retcode_op2str( ber_tag_t op, struct berval *bv ) |
| 519 |
{ |
| 520 |
switch ( op ) { |
| 521 |
case LDAP_REQ_BIND: |
| 522 |
BER_BVSTR( bv, "bind" ); |
| 523 |
return 0; |
| 524 |
case LDAP_REQ_ADD: |
| 525 |
BER_BVSTR( bv, "add" ); |
| 526 |
return 0; |
| 527 |
case LDAP_REQ_DELETE: |
| 528 |
BER_BVSTR( bv, "delete" ); |
| 529 |
return 0; |
| 530 |
case LDAP_REQ_MODRDN: |
| 531 |
BER_BVSTR( bv, "modrdn" ); |
| 532 |
return 0; |
| 533 |
case LDAP_REQ_MODIFY: |
| 534 |
BER_BVSTR( bv, "modify" ); |
| 535 |
return 0; |
| 536 |
case LDAP_REQ_COMPARE: |
| 537 |
BER_BVSTR( bv, "compare" ); |
| 538 |
return 0; |
| 539 |
case LDAP_REQ_SEARCH: |
| 540 |
BER_BVSTR( bv, "search" ); |
| 541 |
return 0; |
| 542 |
case LDAP_REQ_EXTENDED: |
| 543 |
BER_BVSTR( bv, "extended" ); |
| 544 |
return 0; |
| 545 |
} |
| 546 |
return -1; |
| 547 |
} |
| 548 |
|
| 549 |
static int |
| 550 |
retcode_entry_response( Operation *op, SlapReply *rs, BackendInfo *bi, Entry *e ) |
| 551 |
{ |
| 552 |
Attribute *a; |
| 553 |
int err; |
| 554 |
char *next; |
| 555 |
int disconnect = 0; |
| 556 |
|
| 557 |
if ( get_manageDSAit( op ) ) { |
| 558 |
return SLAP_CB_CONTINUE; |
| 559 |
} |
| 560 |
|
| 561 |
if ( !is_entry_objectclass_or_sub( e, oc_errAbsObject ) ) { |
| 562 |
return SLAP_CB_CONTINUE; |
| 563 |
} |
| 564 |
|
| 565 |
/* operation */ |
| 566 |
a = attr_find( e->e_attrs, ad_errOp ); |
| 567 |
if ( a != NULL ) { |
| 568 |
int i, |
| 569 |
gotit = 0; |
| 570 |
struct berval bv = BER_BVNULL; |
| 571 |
|
| 572 |
(void)retcode_op2str( op->o_tag, &bv ); |
| 573 |
|
| 574 |
if ( BER_BVISNULL( &bv ) ) { |
| 575 |
return SLAP_CB_CONTINUE; |
| 576 |
} |
| 577 |
|
| 578 |
for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ ) { |
| 579 |
if ( bvmatch( &a->a_nvals[ i ], &bv ) ) { |
| 580 |
gotit = 1; |
| 581 |
break; |
| 582 |
} |
| 583 |
} |
| 584 |
|
| 585 |
if ( !gotit ) { |
| 586 |
return SLAP_CB_CONTINUE; |
| 587 |
} |
| 588 |
} |
| 589 |
|
| 590 |
/* disconnect */ |
| 591 |
a = attr_find( e->e_attrs, ad_errDisconnect ); |
| 592 |
if ( a != NULL ) { |
| 593 |
if ( bvmatch( &a->a_nvals[ 0 ], &slap_true_bv ) ) { |
| 594 |
return rs->sr_err = SLAPD_DISCONNECT; |
| 595 |
} |
| 596 |
disconnect = 1; |
| 597 |
} |
| 598 |
|
| 599 |
/* error code */ |
| 600 |
a = attr_find( e->e_attrs, ad_errCode ); |
| 601 |
if ( a == NULL ) { |
| 602 |
return SLAP_CB_CONTINUE; |
| 603 |
} |
| 604 |
err = strtol( a->a_nvals[ 0 ].bv_val, &next, 0 ); |
| 605 |
if ( next == a->a_nvals[ 0 ].bv_val || next[ 0 ] != '\0' ) { |
| 606 |
return SLAP_CB_CONTINUE; |
| 607 |
} |
| 608 |
rs->sr_err = err; |
| 609 |
|
| 610 |
/* sleep time */ |
| 611 |
a = attr_find( e->e_attrs, ad_errSleepTime ); |
| 612 |
if ( a != NULL && a->a_nvals[ 0 ].bv_val[ 0 ] != '-' ) { |
| 613 |
int sleepTime; |
| 614 |
|
| 615 |
if ( lutil_atoi( &sleepTime, a->a_nvals[ 0 ].bv_val ) == 0 ) { |
| 616 |
retcode_sleep( sleepTime ); |
| 617 |
} |
| 618 |
} |
| 619 |
|
| 620 |
if ( rs->sr_err != LDAP_SUCCESS && !LDAP_API_ERROR( rs->sr_err )) { |
| 621 |
BackendDB db = *op->o_bd, |
| 622 |
*o_bd = op->o_bd; |
| 623 |
void *o_callback = op->o_callback; |
| 624 |
|
| 625 |
/* message text */ |
| 626 |
a = attr_find( e->e_attrs, ad_errText ); |
| 627 |
if ( a != NULL ) { |
| 628 |
rs->sr_text = a->a_vals[ 0 ].bv_val; |
| 629 |
} |
| 630 |
|
| 631 |
/* matched DN */ |
| 632 |
a = attr_find( e->e_attrs, ad_errMatchedDN ); |
| 633 |
if ( a != NULL ) { |
| 634 |
rs->sr_matched = a->a_vals[ 0 ].bv_val; |
| 635 |
} |
| 636 |
|
| 637 |
if ( bi == NULL ) { |
| 638 |
slap_overinst *on = (slap_overinst *)op->o_bd->bd_info; |
| 639 |
|
| 640 |
bi = on->on_info->oi_orig; |
| 641 |
} |
| 642 |
|
| 643 |
db.bd_info = bi; |
| 644 |
op->o_bd = &db; |
| 645 |
op->o_callback = NULL; |
| 646 |
|
| 647 |
/* referral */ |
| 648 |
if ( rs->sr_err == LDAP_REFERRAL ) { |
| 649 |
BerVarray refs = default_referral; |
| 650 |
|
| 651 |
a = attr_find( e->e_attrs, slap_schema.si_ad_ref ); |
| 652 |
if ( a != NULL ) { |
| 653 |
refs = a->a_vals; |
| 654 |
} |
| 655 |
rs->sr_ref = referral_rewrite( refs, |
| 656 |
NULL, &op->o_req_dn, op->oq_search.rs_scope ); |
| 657 |
|
| 658 |
send_search_reference( op, rs ); |
| 659 |
ber_bvarray_free( rs->sr_ref ); |
| 660 |
rs->sr_ref = NULL; |
| 661 |
|
| 662 |
} else { |
| 663 |
a = attr_find( e->e_attrs, ad_errUnsolicitedOID ); |
| 664 |
if ( a != NULL ) { |
| 665 |
struct berval oid = BER_BVNULL, |
| 666 |
data = BER_BVNULL; |
| 667 |
ber_int_t msgid = op->o_msgid; |
| 668 |
|
| 669 |
/* RFC 4511 unsolicited response */ |
| 670 |
|
| 671 |
op->o_msgid = 0; |
| 672 |
|
| 673 |
oid = a->a_nvals[ 0 ]; |
| 674 |
|
| 675 |
a = attr_find( e->e_attrs, ad_errUnsolicitedData ); |
| 676 |
if ( a != NULL ) { |
| 677 |
data = a->a_nvals[ 0 ]; |
| 678 |
} |
| 679 |
|
| 680 |
if ( strcmp( oid.bv_val, "0" ) == 0 ) { |
| 681 |
send_ldap_result( op, rs ); |
| 682 |
|
| 683 |
} else { |
| 684 |
ber_tag_t tag = op->o_tag; |
| 685 |
|
| 686 |
op->o_tag = LDAP_REQ_EXTENDED; |
| 687 |
rs->sr_rspoid = oid.bv_val; |
| 688 |
if ( !BER_BVISNULL( &data ) ) { |
| 689 |
rs->sr_rspdata = &data; |
| 690 |
} |
| 691 |
send_ldap_extended( op, rs ); |
| 692 |
rs->sr_rspoid = NULL; |
| 693 |
rs->sr_rspdata = NULL; |
| 694 |
op->o_tag = tag; |
| 695 |
} |
| 696 |
op->o_msgid = msgid; |
| 697 |
|
| 698 |
} else { |
| 699 |
send_ldap_result( op, rs ); |
| 700 |
} |
| 701 |
} |
| 702 |
|
| 703 |
rs->sr_text = NULL; |
| 704 |
rs->sr_matched = NULL; |
| 705 |
op->o_bd = o_bd; |
| 706 |
op->o_callback = o_callback; |
| 707 |
} |
| 708 |
|
| 709 |
if ( rs->sr_err != LDAP_SUCCESS ) { |
| 710 |
if ( disconnect ) { |
| 711 |
return rs->sr_err = SLAPD_DISCONNECT; |
| 712 |
} |
| 713 |
|
| 714 |
return rs->sr_err; |
| 715 |
} |
| 716 |
|
| 717 |
return SLAP_CB_CONTINUE; |
| 718 |
} |
| 719 |
|
| 720 |
static int |
| 721 |
retcode_response( Operation *op, SlapReply *rs ) |
| 722 |
{ |
| 723 |
slap_overinst *on = (slap_overinst *)op->o_bd->bd_info; |
| 724 |
retcode_t *rd = (retcode_t *)on->on_bi.bi_private; |
| 725 |
|
| 726 |
if ( rs->sr_type != REP_SEARCH || !RETCODE_INDIR( rd ) ) { |
| 727 |
return SLAP_CB_CONTINUE; |
| 728 |
} |
| 729 |
|
| 730 |
return retcode_entry_response( op, rs, NULL, rs->sr_entry ); |
| 731 |
} |
| 732 |
|
| 733 |
static int |
| 734 |
retcode_db_init( BackendDB *be, ConfigReply *cr ) |
| 735 |
{ |
| 736 |
slap_overinst *on = (slap_overinst *)be->bd_info; |
| 737 |
retcode_t *rd; |
| 738 |
|
| 739 |
srand( getpid() ); |
| 740 |
|
| 741 |
rd = (retcode_t *)ch_malloc( sizeof( retcode_t ) ); |
| 742 |
memset( rd, 0, sizeof( retcode_t ) ); |
| 743 |
|
| 744 |
on->on_bi.bi_private = (void *)rd; |
| 745 |
|
| 746 |
return 0; |
| 747 |
} |
| 748 |
|
| 749 |
static void |
| 750 |
retcode_item_destroy( retcode_item_t *rdi ) |
| 751 |
{ |
| 752 |
ber_memfree( rdi->rdi_line.bv_val ); |
| 753 |
|
| 754 |
ber_memfree( rdi->rdi_dn.bv_val ); |
| 755 |
ber_memfree( rdi->rdi_ndn.bv_val ); |
| 756 |
|
| 757 |
if ( !BER_BVISNULL( &rdi->rdi_text ) ) { |
| 758 |
ber_memfree( rdi->rdi_text.bv_val ); |
| 759 |
} |
| 760 |
|
| 761 |
if ( !BER_BVISNULL( &rdi->rdi_matched ) ) { |
| 762 |
ber_memfree( rdi->rdi_matched.bv_val ); |
| 763 |
} |
| 764 |
|
| 765 |
if ( rdi->rdi_ref ) { |
| 766 |
ber_bvarray_free( rdi->rdi_ref ); |
| 767 |
} |
| 768 |
|
| 769 |
BER_BVZERO( &rdi->rdi_e.e_name ); |
| 770 |
BER_BVZERO( &rdi->rdi_e.e_nname ); |
| 771 |
|
| 772 |
entry_clean( &rdi->rdi_e ); |
| 773 |
|
| 774 |
if ( !BER_BVISNULL( &rdi->rdi_unsolicited_oid ) ) { |
| 775 |
ber_memfree( rdi->rdi_unsolicited_oid.bv_val ); |
| 776 |
if ( !BER_BVISNULL( &rdi->rdi_unsolicited_data ) ) |
| 777 |
ber_memfree( rdi->rdi_unsolicited_data.bv_val ); |
| 778 |
} |
| 779 |
|
| 780 |
ch_free( rdi ); |
| 781 |
} |
| 782 |
|
| 783 |
enum { |
| 784 |
RC_PARENT = 1, |
| 785 |
RC_ITEM |
| 786 |
}; |
| 787 |
|
| 788 |
static ConfigDriver rc_cf_gen; |
| 789 |
|
| 790 |
static ConfigTable rccfg[] = { |
| 791 |
{ "retcode-parent", "dn", |
| 792 |
2, 2, 0, ARG_MAGIC|ARG_DN|ARG_QUOTE|RC_PARENT, rc_cf_gen, |
| 793 |
"( OLcfgOvAt:20.1 NAME 'olcRetcodeParent' " |
| 794 |
"DESC '' " |
| 795 |
"EQUALITY distinguishedNameMatch " |
| 796 |
"SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL }, |
| 797 |
{ "retcode-item", "rdn> <retcode> <...", |
| 798 |
3, 0, 0, ARG_MAGIC|RC_ITEM, rc_cf_gen, |
| 799 |
"( OLcfgOvAt:20.2 NAME 'olcRetcodeItem' " |
| 800 |
"DESC '' " |
| 801 |
"EQUALITY caseIgnoreMatch " |
| 802 |
"SYNTAX OMsDirectoryString " |
| 803 |
"X-ORDERED 'VALUES' )", NULL, NULL }, |
| 804 |
{ "retcode-indir", "on|off", |
| 805 |
1, 2, 0, ARG_OFFSET|ARG_ON_OFF, |
| 806 |
(void *)offsetof(retcode_t, rd_indir), |
| 807 |
"( OLcfgOvAt:20.3 NAME 'olcRetcodeInDir' " |
| 808 |
"DESC '' " |
| 809 |
"EQUALITY booleanMatch " |
| 810 |
"SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL }, |
| 811 |
|
| 812 |
{ "retcode-sleep", "sleeptime", |
| 813 |
2, 2, 0, ARG_OFFSET|ARG_INT, |
| 814 |
(void *)offsetof(retcode_t, rd_sleep), |
| 815 |
"( OLcfgOvAt:20.4 NAME 'olcRetcodeSleep' " |
| 816 |
"DESC '' " |
| 817 |
"EQUALITY integerMatch " |
| 818 |
"SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL }, |
| 819 |
|
| 820 |
{ NULL, NULL, 0, 0, 0, ARG_IGNORED } |
| 821 |
}; |
| 822 |
|
| 823 |
static ConfigOCs rcocs[] = { |
| 824 |
{ "( OLcfgOvOc:20.1 " |
| 825 |
"NAME 'olcRetcodeConfig' " |
| 826 |
"DESC 'Retcode configuration' " |
| 827 |
"SUP olcOverlayConfig " |
| 828 |
"MAY ( olcRetcodeParent " |
| 829 |
"$ olcRetcodeItem " |
| 830 |
"$ olcRetcodeInDir " |
| 831 |
"$ olcRetcodeSleep " |
| 832 |
") )", |
| 833 |
Cft_Overlay, rccfg, NULL, NULL }, |
| 834 |
{ NULL, 0, NULL } |
| 835 |
}; |
| 836 |
|
| 837 |
static int |
| 838 |
rc_cf_gen( ConfigArgs *c ) |
| 839 |
{ |
| 840 |
slap_overinst *on = (slap_overinst *)c->bi; |
| 841 |
retcode_t *rd = (retcode_t *)on->on_bi.bi_private; |
| 842 |
int rc = ARG_BAD_CONF; |
| 843 |
|
| 844 |
if ( c->op == SLAP_CONFIG_EMIT ) { |
| 845 |
switch( c->type ) { |
| 846 |
case RC_PARENT: |
| 847 |
if ( !BER_BVISEMPTY( &rd->rd_pdn )) { |
| 848 |
rc = value_add_one( &c->rvalue_vals, |
| 849 |
&rd->rd_pdn ); |
| 850 |
if ( rc == 0 ) { |
| 851 |
rc = value_add_one( &c->rvalue_nvals, |
| 852 |
&rd->rd_npdn ); |
| 853 |
} |
| 854 |
return rc; |
| 855 |
} |
| 856 |
rc = 0; |
| 857 |
break; |
| 858 |
|
| 859 |
case RC_ITEM: { |
| 860 |
retcode_item_t *rdi; |
| 861 |
int i; |
| 862 |
|
| 863 |
for ( rdi = rd->rd_item, i = 0; rdi; rdi = rdi->rdi_next, i++ ) { |
| 864 |
char buf[4096]; |
| 865 |
struct berval bv; |
| 866 |
char *ptr; |
| 867 |
|
| 868 |
bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i ); |
| 869 |
bv.bv_len += rdi->rdi_line.bv_len; |
| 870 |
ptr = bv.bv_val = ch_malloc( bv.bv_len + 1 ); |
| 871 |
ptr = lutil_strcopy( ptr, buf ); |
| 872 |
ptr = lutil_strncopy( ptr, rdi->rdi_line.bv_val, rdi->rdi_line.bv_len ); |
| 873 |
ber_bvarray_add( &c->rvalue_vals, &bv ); |
| 874 |
} |
| 875 |
rc = 0; |
| 876 |
} break; |
| 877 |
|
| 878 |
default: |
| 879 |
assert( 0 ); |
| 880 |
break; |
| 881 |
} |
| 882 |
|
| 883 |
return rc; |
| 884 |
|
| 885 |
} else if ( c->op == LDAP_MOD_DELETE ) { |
| 886 |
switch( c->type ) { |
| 887 |
case RC_PARENT: |
| 888 |
if ( rd->rd_pdn.bv_val ) { |
| 889 |
ber_memfree ( rd->rd_pdn.bv_val ); |
| 890 |
rc = 0; |
| 891 |
} |
| 892 |
if ( rd->rd_npdn.bv_val ) { |
| 893 |
ber_memfree ( rd->rd_npdn.bv_val ); |
| 894 |
} |
| 895 |
break; |
| 896 |
|
| 897 |
case RC_ITEM: |
| 898 |
if ( c->valx == -1 ) { |
| 899 |
retcode_item_t *rdi, *next; |
| 900 |
|
| 901 |
for ( rdi = rd->rd_item; rdi != NULL; rdi = next ) { |
| 902 |
next = rdi->rdi_next; |
| 903 |
retcode_item_destroy( rdi ); |
| 904 |
} |
| 905 |
|
| 906 |
} else { |
| 907 |
retcode_item_t **rdip, *rdi; |
| 908 |
int i; |
| 909 |
|
| 910 |
for ( rdip = &rd->rd_item, i = 0; i <= c->valx && *rdip; i++, rdip = &(*rdip)->rdi_next ) |
| 911 |
; |
| 912 |
if ( *rdip == NULL ) { |
| 913 |
return 1; |
| 914 |
} |
| 915 |
rdi = *rdip; |
| 916 |
*rdip = rdi->rdi_next; |
| 917 |
|
| 918 |
retcode_item_destroy( rdi ); |
| 919 |
} |
| 920 |
rc = 0; |
| 921 |
break; |
| 922 |
|
| 923 |
default: |
| 924 |
assert( 0 ); |
| 925 |
break; |
| 926 |
} |
| 927 |
return rc; /* FIXME */ |
| 928 |
} |
| 929 |
|
| 930 |
switch( c->type ) { |
| 931 |
case RC_PARENT: |
| 932 |
if ( rd->rd_pdn.bv_val ) { |
| 933 |
ber_memfree ( rd->rd_pdn.bv_val ); |
| 934 |
} |
| 935 |
if ( rd->rd_npdn.bv_val ) { |
| 936 |
ber_memfree ( rd->rd_npdn.bv_val ); |
| 937 |
} |
| 938 |
rd->rd_pdn = c->value_dn; |
| 939 |
rd->rd_npdn = c->value_ndn; |
| 940 |
rc = 0; |
| 941 |
break; |
| 942 |
|
| 943 |
case RC_ITEM: { |
| 944 |
retcode_item_t rdi = { BER_BVNULL }, **rdip; |
| 945 |
struct berval bv, rdn, nrdn; |
| 946 |
char *next = NULL; |
| 947 |
int i; |
| 948 |
|
| 949 |
if ( c->argc < 3 ) { |
| 950 |
snprintf( c->cr_msg, sizeof(c->cr_msg), |
| 951 |
"\"retcode-item <RDN> <retcode> [<text>]\": " |
| 952 |
"missing args" ); |
| 953 |
Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n", |
| 954 |
c->log, c->cr_msg ); |
| 955 |
return ARG_BAD_CONF; |
| 956 |
} |
| 957 |
|
| 958 |
ber_str2bv( c->argv[ 1 ], 0, 0, &bv ); |
| 959 |
|
| 960 |
rc = dnPrettyNormal( NULL, &bv, &rdn, &nrdn, NULL ); |
| 961 |
if ( rc != LDAP_SUCCESS ) { |
| 962 |
snprintf( c->cr_msg, sizeof(c->cr_msg), |
| 963 |
"unable to normalize RDN \"%s\": %d", |
| 964 |
c->argv[ 1 ], rc ); |
| 965 |
Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n", |
| 966 |
c->log, c->cr_msg ); |
| 967 |
return ARG_BAD_CONF; |
| 968 |
} |
| 969 |
|
| 970 |
if ( !dnIsOneLevelRDN( &nrdn ) ) { |
| 971 |
snprintf( c->cr_msg, sizeof(c->cr_msg), |
| 972 |
"value \"%s\" is not a RDN", |
| 973 |
c->argv[ 1 ] ); |
| 974 |
Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n", |
| 975 |
c->log, c->cr_msg ); |
| 976 |
return ARG_BAD_CONF; |
| 977 |
} |
| 978 |
|
| 979 |
if ( BER_BVISNULL( &rd->rd_npdn ) ) { |
| 980 |
/* FIXME: we use the database suffix */ |
| 981 |
if ( c->be->be_nsuffix == NULL ) { |
| 982 |
snprintf( c->cr_msg, sizeof(c->cr_msg), |
| 983 |
"either \"retcode-parent\" " |
| 984 |
"or \"suffix\" must be defined" ); |
| 985 |
Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n", |
| 986 |
c->log, c->cr_msg ); |
| 987 |
return ARG_BAD_CONF; |
| 988 |
} |
| 989 |
|
| 990 |
ber_dupbv( &rd->rd_pdn, &c->be->be_suffix[ 0 ] ); |
| 991 |
ber_dupbv( &rd->rd_npdn, &c->be->be_nsuffix[ 0 ] ); |
| 992 |
} |
| 993 |
|
| 994 |
build_new_dn( &rdi.rdi_dn, &rd->rd_pdn, &rdn, NULL ); |
| 995 |
build_new_dn( &rdi.rdi_ndn, &rd->rd_npdn, &nrdn, NULL ); |
| 996 |
|
| 997 |
ch_free( rdn.bv_val ); |
| 998 |
ch_free( nrdn.bv_val ); |
| 999 |
|
| 1000 |
rdi.rdi_err = strtol( c->argv[ 2 ], &next, 0 ); |
| 1001 |
if ( next == c->argv[ 2 ] || next[ 0 ] != '\0' ) { |
| 1002 |
snprintf( c->cr_msg, sizeof(c->cr_msg), |
| 1003 |
"unable to parse return code \"%s\"", |
| 1004 |
c->argv[ 2 ] ); |
| 1005 |
Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n", |
| 1006 |
c->log, c->cr_msg ); |
| 1007 |
return ARG_BAD_CONF; |
| 1008 |
} |
| 1009 |
|
| 1010 |
rdi.rdi_mask = SN_DG_OP_ALL; |
| 1011 |
|
| 1012 |
if ( c->argc > 3 ) { |
| 1013 |
for ( i = 3; i < c->argc; i++ ) { |
| 1014 |
if ( strncasecmp( c->argv[ i ], "op=", STRLENOF( "op=" ) ) == 0 ) |
| 1015 |
{ |
| 1016 |
char **ops; |
| 1017 |
int j; |
| 1018 |
|
| 1019 |
ops = ldap_str2charray( &c->argv[ i ][ STRLENOF( "op=" ) ], "," ); |
| 1020 |
assert( ops != NULL ); |
| 1021 |
|
| 1022 |
rdi.rdi_mask = SN_DG_OP_NONE; |
| 1023 |
|
| 1024 |
for ( j = 0; ops[ j ] != NULL; j++ ) { |
| 1025 |
if ( strcasecmp( ops[ j ], "add" ) == 0 ) { |
| 1026 |
rdi.rdi_mask |= SN_DG_OP_ADD; |
| 1027 |
|
| 1028 |
} else if ( strcasecmp( ops[ j ], "bind" ) == 0 ) { |
| 1029 |
rdi.rdi_mask |= SN_DG_OP_BIND; |
| 1030 |
|
| 1031 |
} else if ( strcasecmp( ops[ j ], "compare" ) == 0 ) { |
| 1032 |
rdi.rdi_mask |= SN_DG_OP_COMPARE; |
| 1033 |
|
| 1034 |
} else if ( strcasecmp( ops[ j ], "delete" ) == 0 ) { |
| 1035 |
rdi.rdi_mask |= SN_DG_OP_DELETE; |
| 1036 |
|
| 1037 |
} else if ( strcasecmp( ops[ j ], "modify" ) == 0 ) { |
| 1038 |
rdi.rdi_mask |= SN_DG_OP_MODIFY; |
| 1039 |
|
| 1040 |
} else if ( strcasecmp( ops[ j ], "rename" ) == 0 |
| 1041 |
|| strcasecmp( ops[ j ], "modrdn" ) == 0 ) |
| 1042 |
{ |
| 1043 |
rdi.rdi_mask |= SN_DG_OP_RENAME; |
| 1044 |
|
| 1045 |
} else if ( strcasecmp( ops[ j ], "search" ) == 0 ) { |
| 1046 |
rdi.rdi_mask |= SN_DG_OP_SEARCH; |
| 1047 |
|
| 1048 |
} else if ( strcasecmp( ops[ j ], "extended" ) == 0 ) { |
| 1049 |
rdi.rdi_mask |= SN_DG_EXTENDED; |
| 1050 |
|
| 1051 |
} else if ( strcasecmp( ops[ j ], "auth" ) == 0 ) { |
| 1052 |
rdi.rdi_mask |= SN_DG_OP_AUTH; |
| 1053 |
|
| 1054 |
} else if ( strcasecmp( ops[ j ], "read" ) == 0 ) { |
| 1055 |
rdi.rdi_mask |= SN_DG_OP_READ; |
| 1056 |
|
| 1057 |
} else if ( strcasecmp( ops[ j ], "write" ) == 0 ) { |
| 1058 |
rdi.rdi_mask |= SN_DG_OP_WRITE; |
| 1059 |
|
| 1060 |
} else if ( strcasecmp( ops[ j ], "all" ) == 0 ) { |
| 1061 |
rdi.rdi_mask |= SN_DG_OP_ALL; |
| 1062 |
|
| 1063 |
} else { |
| 1064 |
snprintf( c->cr_msg, sizeof(c->cr_msg), |
| 1065 |
"unknown op \"%s\"", |
| 1066 |
ops[ j ] ); |
| 1067 |
ldap_charray_free( ops ); |
| 1068 |
Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n", |
| 1069 |
c->log, c->cr_msg ); |
| 1070 |
return ARG_BAD_CONF; |
| 1071 |
} |
| 1072 |
} |
| 1073 |
|
| 1074 |
ldap_charray_free( ops ); |
| 1075 |
|
| 1076 |
} else if ( strncasecmp( c->argv[ i ], "text=", STRLENOF( "text=" ) ) == 0 ) |
| 1077 |
{ |
| 1078 |
if ( !BER_BVISNULL( &rdi.rdi_text ) ) { |
| 1079 |
snprintf( c->cr_msg, sizeof(c->cr_msg), |
| 1080 |
"\"text\" already provided" ); |
| 1081 |
Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n", |
| 1082 |
c->log, c->cr_msg ); |
| 1083 |
return ARG_BAD_CONF; |
| 1084 |
} |
| 1085 |
ber_str2bv( &c->argv[ i ][ STRLENOF( "text=" ) ], 0, 1, &rdi.rdi_text ); |
| 1086 |
|
| 1087 |
} else if ( strncasecmp( c->argv[ i ], "matched=", STRLENOF( "matched=" ) ) == 0 ) |
| 1088 |
{ |
| 1089 |
struct berval dn; |
| 1090 |
|
| 1091 |
if ( !BER_BVISNULL( &rdi.rdi_matched ) ) { |
| 1092 |
snprintf( c->cr_msg, sizeof(c->cr_msg), |
| 1093 |
"\"matched\" already provided" ); |
| 1094 |
Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n", |
| 1095 |
c->log, c->cr_msg ); |
| 1096 |
return ARG_BAD_CONF; |
| 1097 |
} |
| 1098 |
ber_str2bv( &c->argv[ i ][ STRLENOF( "matched=" ) ], 0, 0, &dn ); |
| 1099 |
if ( dnPretty( NULL, &dn, &rdi.rdi_matched, NULL ) != LDAP_SUCCESS ) { |
| 1100 |
snprintf( c->cr_msg, sizeof(c->cr_msg), |
| 1101 |
"unable to prettify matched DN \"%s\"", |
| 1102 |
&c->argv[ i ][ STRLENOF( "matched=" ) ] ); |
| 1103 |
Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n", |
| 1104 |
c->log, c->cr_msg ); |
| 1105 |
return ARG_BAD_CONF; |
| 1106 |
} |
| 1107 |
|
| 1108 |
} else if ( strncasecmp( c->argv[ i ], "ref=", STRLENOF( "ref=" ) ) == 0 ) |
| 1109 |
{ |
| 1110 |
char **refs; |
| 1111 |
int j; |
| 1112 |
|
| 1113 |
if ( rdi.rdi_ref != NULL ) { |
| 1114 |
snprintf( c->cr_msg, sizeof(c->cr_msg), |
| 1115 |
"\"ref\" already provided" ); |
| 1116 |
Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n", |
| 1117 |
c->log, c->cr_msg ); |
| 1118 |
return ARG_BAD_CONF; |
| 1119 |
} |
| 1120 |
|
| 1121 |
if ( rdi.rdi_err != LDAP_REFERRAL ) { |
| 1122 |
snprintf( c->cr_msg, sizeof(c->cr_msg), |
| 1123 |
"providing \"ref\" " |
| 1124 |
"along with a non-referral " |
| 1125 |
"resultCode may cause slapd failures " |
| 1126 |
"related to internal checks" ); |
| 1127 |
Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n", |
| 1128 |
c->log, c->cr_msg ); |
| 1129 |
} |
| 1130 |
|
| 1131 |
refs = ldap_str2charray( &c->argv[ i ][ STRLENOF( "ref=" ) ], " " ); |
| 1132 |
assert( refs != NULL ); |
| 1133 |
|
| 1134 |
for ( j = 0; refs[ j ] != NULL; j++ ) { |
| 1135 |
struct berval bv; |
| 1136 |
|
| 1137 |
ber_str2bv( refs[ j ], 0, 1, &bv ); |
| 1138 |
ber_bvarray_add( &rdi.rdi_ref, &bv ); |
| 1139 |
} |
| 1140 |
|
| 1141 |
ldap_charray_free( refs ); |
| 1142 |
|
| 1143 |
} else if ( strncasecmp( c->argv[ i ], "sleeptime=", STRLENOF( "sleeptime=" ) ) == 0 ) |
| 1144 |
{ |
| 1145 |
if ( rdi.rdi_sleeptime != 0 ) { |
| 1146 |
snprintf( c->cr_msg, sizeof(c->cr_msg), |
| 1147 |
"\"sleeptime\" already provided" ); |
| 1148 |
Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n", |
| 1149 |
c->log, c->cr_msg ); |
| 1150 |
return ARG_BAD_CONF; |
| 1151 |
} |
| 1152 |
|
| 1153 |
if ( lutil_atoi( &rdi.rdi_sleeptime, &c->argv[ i ][ STRLENOF( "sleeptime=" ) ] ) ) { |
| 1154 |
snprintf( c->cr_msg, sizeof(c->cr_msg), |
| 1155 |
"unable to parse \"sleeptime=%s\"", |
| 1156 |
&c->argv[ i ][ STRLENOF( "sleeptime=" ) ] ); |
| 1157 |
Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n", |
| 1158 |
c->log, c->cr_msg ); |
| 1159 |
return ARG_BAD_CONF; |
| 1160 |
} |
| 1161 |
|
| 1162 |
} else if ( strncasecmp( c->argv[ i ], "unsolicited=", STRLENOF( "unsolicited=" ) ) == 0 ) |
| 1163 |
{ |
| 1164 |
char *data; |
| 1165 |
|
| 1166 |
if ( !BER_BVISNULL( &rdi.rdi_unsolicited_oid ) ) { |
| 1167 |
snprintf( c->cr_msg, sizeof(c->cr_msg), |
| 1168 |
"\"unsolicited\" already provided" ); |
| 1169 |
Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n", |
| 1170 |
c->log, c->cr_msg ); |
| 1171 |
return ARG_BAD_CONF; |
| 1172 |
} |
| 1173 |
|
| 1174 |
data = strchr( &c->argv[ i ][ STRLENOF( "unsolicited=" ) ], ':' ); |
| 1175 |
if ( data != NULL ) { |
| 1176 |
struct berval oid; |
| 1177 |
|
| 1178 |
if ( ldif_parse_line2( &c->argv[ i ][ STRLENOF( "unsolicited=" ) ], |
| 1179 |
&oid, &rdi.rdi_unsolicited_data, NULL ) ) |
| 1180 |
{ |
| 1181 |
snprintf( c->cr_msg, sizeof(c->cr_msg), |
| 1182 |
"unable to parse \"unsolicited\"" ); |
| 1183 |
Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n", |
| 1184 |
c->log, c->cr_msg ); |
| 1185 |
return ARG_BAD_CONF; |
| 1186 |
} |
| 1187 |
|
| 1188 |
ber_dupbv( &rdi.rdi_unsolicited_oid, &oid ); |
| 1189 |
|
| 1190 |
} else { |
| 1191 |
ber_str2bv( &c->argv[ i ][ STRLENOF( "unsolicited=" ) ], 0, 1, |
| 1192 |
&rdi.rdi_unsolicited_oid ); |
| 1193 |
} |
| 1194 |
|
| 1195 |
} else if ( strncasecmp( c->argv[ i ], "flags=", STRLENOF( "flags=" ) ) == 0 ) |
| 1196 |
{ |
| 1197 |
char *arg = &c->argv[ i ][ STRLENOF( "flags=" ) ]; |
| 1198 |
if ( strcasecmp( arg, "disconnect" ) == 0 ) { |
| 1199 |
rdi.rdi_flags |= RDI_PRE_DISCONNECT; |
| 1200 |
|
| 1201 |
} else if ( strcasecmp( arg, "pre-disconnect" ) == 0 ) { |
| 1202 |
rdi.rdi_flags |= RDI_PRE_DISCONNECT; |
| 1203 |
|
| 1204 |
} else if ( strcasecmp( arg, "post-disconnect" ) == 0 ) { |
| 1205 |
rdi.rdi_flags |= RDI_POST_DISCONNECT; |
| 1206 |
|
| 1207 |
} else { |
| 1208 |
snprintf( c->cr_msg, sizeof(c->cr_msg), |
| 1209 |
"unknown flag \"%s\"", arg ); |
| 1210 |
Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n", |
| 1211 |
c->log, c->cr_msg ); |
| 1212 |
return ARG_BAD_CONF; |
| 1213 |
} |
| 1214 |
|
| 1215 |
} else { |
| 1216 |
snprintf( c->cr_msg, sizeof(c->cr_msg), |
| 1217 |
"unknown option \"%s\"", |
| 1218 |
c->argv[ i ] ); |
| 1219 |
Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n", |
| 1220 |
c->log, c->cr_msg ); |
| 1221 |
return ARG_BAD_CONF; |
| 1222 |
} |
| 1223 |
} |
| 1224 |
} |
| 1225 |
|
| 1226 |
rdi.rdi_line.bv_len = 2*(c->argc - 1) + c->argc - 2; |
| 1227 |
for ( i = 1; i < c->argc; i++ ) { |
| 1228 |
rdi.rdi_line.bv_len += strlen( c->argv[ i ] ); |
| 1229 |
} |
| 1230 |
next = rdi.rdi_line.bv_val = ch_malloc( rdi.rdi_line.bv_len + 1 ); |
| 1231 |
|
| 1232 |
for ( i = 1; i < c->argc; i++ ) { |
| 1233 |
*next++ = '"'; |
| 1234 |
next = lutil_strcopy( next, c->argv[ i ] ); |
| 1235 |
*next++ = '"'; |
| 1236 |
*next++ = ' '; |
| 1237 |
} |
| 1238 |
*--next = '\0'; |
| 1239 |
|
| 1240 |
/* We're marked X-ORDERED 'VALUES', valx might be valid */ |
| 1241 |
for ( i = 0, rdip = &rd->rd_item; |
| 1242 |
*rdip && (c->valx < 0 || i < c->valx); |
| 1243 |
rdip = &(*rdip)->rdi_next, i++ ) |
| 1244 |
/* go to position */ ; |
| 1245 |
|
| 1246 |
|
| 1247 |
rdi.rdi_next = *rdip; |
| 1248 |
*rdip = ( retcode_item_t * )ch_malloc( sizeof( retcode_item_t ) ); |
| 1249 |
*(*rdip) = rdi; |
| 1250 |
|
| 1251 |
rc = 0; |
| 1252 |
} break; |
| 1253 |
|
| 1254 |
default: |
| 1255 |
rc = SLAP_CONF_UNKNOWN; |
| 1256 |
break; |
| 1257 |
} |
| 1258 |
|
| 1259 |
return rc; |
| 1260 |
} |
| 1261 |
|
| 1262 |
static int |
| 1263 |
retcode_db_open( BackendDB *be, ConfigReply *cr) |
| 1264 |
{ |
| 1265 |
slap_overinst *on = (slap_overinst *)be->bd_info; |
| 1266 |
retcode_t *rd = (retcode_t *)on->on_bi.bi_private; |
| 1267 |
|
| 1268 |
retcode_item_t *rdi; |
| 1269 |
|
| 1270 |
for ( rdi = rd->rd_item; rdi; rdi = rdi->rdi_next ) { |
| 1271 |
LDAPRDN rdn = NULL; |
| 1272 |
int rc, j; |
| 1273 |
char* p; |
| 1274 |
struct berval val[ 3 ]; |
| 1275 |
char buf[ SLAP_TEXT_BUFLEN ]; |
| 1276 |
|
| 1277 |
/* DN */ |
| 1278 |
rdi->rdi_e.e_name = rdi->rdi_dn; |
| 1279 |
rdi->rdi_e.e_nname = rdi->rdi_ndn; |
| 1280 |
|
| 1281 |
/* objectClass */ |
| 1282 |
val[ 0 ] = oc_errObject->soc_cname; |
| 1283 |
val[ 1 ] = slap_schema.si_oc_extensibleObject->soc_cname; |
| 1284 |
BER_BVZERO( &val[ 2 ] ); |
| 1285 |
|
| 1286 |
attr_merge( &rdi->rdi_e, slap_schema.si_ad_objectClass, val, NULL ); |
| 1287 |
|
| 1288 |
/* RDN avas */ |
| 1289 |
rc = ldap_bv2rdn( &rdi->rdi_dn, &rdn, (char **) &p, |
| 1290 |
LDAP_DN_FORMAT_LDAP ); |
| 1291 |
|
| 1292 |
assert( rc == LDAP_SUCCESS ); |
| 1293 |
|
| 1294 |
for ( j = 0; rdn[ j ]; j++ ) { |
| 1295 |
LDAPAVA *ava = rdn[ j ]; |
| 1296 |
AttributeDescription *ad = NULL; |
| 1297 |
const char *text; |
| 1298 |
|
| 1299 |
rc = slap_bv2ad( &ava->la_attr, &ad, &text ); |
| 1300 |
assert( rc == LDAP_SUCCESS ); |
| 1301 |
|
| 1302 |
attr_merge_normalize_one( &rdi->rdi_e, ad, |
| 1303 |
&ava->la_value, NULL ); |
| 1304 |
} |
| 1305 |
|
| 1306 |
ldap_rdnfree( rdn ); |
| 1307 |
|
| 1308 |
/* error code */ |
| 1309 |
snprintf( buf, sizeof( buf ), "%d", rdi->rdi_err ); |
| 1310 |
ber_str2bv( buf, 0, 0, &val[ 0 ] ); |
| 1311 |
|
| 1312 |
attr_merge_one( &rdi->rdi_e, ad_errCode, &val[ 0 ], NULL ); |
| 1313 |
|
| 1314 |
if ( rdi->rdi_ref != NULL ) { |
| 1315 |
attr_merge_normalize( &rdi->rdi_e, slap_schema.si_ad_ref, |
| 1316 |
rdi->rdi_ref, NULL ); |
| 1317 |
} |
| 1318 |
|
| 1319 |
/* text */ |
| 1320 |
if ( !BER_BVISNULL( &rdi->rdi_text ) ) { |
| 1321 |
val[ 0 ] = rdi->rdi_text; |
| 1322 |
|
| 1323 |
attr_merge_normalize_one( &rdi->rdi_e, ad_errText, &val[ 0 ], NULL ); |
| 1324 |
} |
| 1325 |
|
| 1326 |
/* matched */ |
| 1327 |
if ( !BER_BVISNULL( &rdi->rdi_matched ) ) { |
| 1328 |
val[ 0 ] = rdi->rdi_matched; |
| 1329 |
|
| 1330 |
attr_merge_normalize_one( &rdi->rdi_e, ad_errMatchedDN, &val[ 0 ], NULL ); |
| 1331 |
} |
| 1332 |
|
| 1333 |
/* sleep time */ |
| 1334 |
if ( rdi->rdi_sleeptime ) { |
| 1335 |
snprintf( buf, sizeof( buf ), "%d", rdi->rdi_sleeptime ); |
| 1336 |
ber_str2bv( buf, 0, 0, &val[ 0 ] ); |
| 1337 |
|
| 1338 |
attr_merge_one( &rdi->rdi_e, ad_errSleepTime, &val[ 0 ], NULL ); |
| 1339 |
} |
| 1340 |
|
| 1341 |
/* operations */ |
| 1342 |
if ( rdi->rdi_mask & SN_DG_OP_ADD ) { |
| 1343 |
BER_BVSTR( &val[ 0 ], "add" ); |
| 1344 |
attr_merge_normalize_one( &rdi->rdi_e, ad_errOp, &val[ 0 ], NULL ); |
| 1345 |
} |
| 1346 |
|
| 1347 |
if ( rdi->rdi_mask & SN_DG_OP_BIND ) { |
| 1348 |
BER_BVSTR( &val[ 0 ], "bind" ); |
| 1349 |
attr_merge_normalize_one( &rdi->rdi_e, ad_errOp, &val[ 0 ], NULL ); |
| 1350 |
} |
| 1351 |
|
| 1352 |
if ( rdi->rdi_mask & SN_DG_OP_COMPARE ) { |
| 1353 |
BER_BVSTR( &val[ 0 ], "compare" ); |
| 1354 |
attr_merge_normalize_one( &rdi->rdi_e, ad_errOp, &val[ 0 ], NULL ); |
| 1355 |
} |
| 1356 |
|
| 1357 |
if ( rdi->rdi_mask & SN_DG_OP_DELETE ) { |
| 1358 |
BER_BVSTR( &val[ 0 ], "delete" ); |
| 1359 |
attr_merge_normalize_one( &rdi->rdi_e, ad_errOp, &val[ 0 ], NULL ); |
| 1360 |
} |
| 1361 |
|
| 1362 |
if ( rdi->rdi_mask & SN_DG_EXTENDED ) { |
| 1363 |
BER_BVSTR( &val[ 0 ], "extended" ); |
| 1364 |
attr_merge_normalize_one( &rdi->rdi_e, ad_errOp, &val[ 0 ], NULL ); |
| 1365 |
} |
| 1366 |
|
| 1367 |
if ( rdi->rdi_mask & SN_DG_OP_MODIFY ) { |
| 1368 |
BER_BVSTR( &val[ 0 ], "modify" ); |
| 1369 |
attr_merge_normalize_one( &rdi->rdi_e, ad_errOp, &val[ 0 ], NULL ); |
| 1370 |
} |
| 1371 |
|
| 1372 |
if ( rdi->rdi_mask & SN_DG_OP_RENAME ) { |
| 1373 |
BER_BVSTR( &val[ 0 ], "rename" ); |
| 1374 |
attr_merge_normalize_one( &rdi->rdi_e, ad_errOp, &val[ 0 ], NULL ); |
| 1375 |
} |
| 1376 |
|
| 1377 |
if ( rdi->rdi_mask & SN_DG_OP_SEARCH ) { |
| 1378 |
BER_BVSTR( &val[ 0 ], "search" ); |
| 1379 |
attr_merge_normalize_one( &rdi->rdi_e, ad_errOp, &val[ 0 ], NULL ); |
| 1380 |
} |
| 1381 |
} |
| 1382 |
|
| 1383 |
return 0; |
| 1384 |
} |
| 1385 |
|
| 1386 |
static int |
| 1387 |
retcode_db_destroy( BackendDB *be, ConfigReply *cr ) |
| 1388 |
{ |
| 1389 |
slap_overinst *on = (slap_overinst *)be->bd_info; |
| 1390 |
retcode_t *rd = (retcode_t *)on->on_bi.bi_private; |
| 1391 |
|
| 1392 |
if ( rd ) { |
| 1393 |
retcode_item_t *rdi, *next; |
| 1394 |
|
| 1395 |
for ( rdi = rd->rd_item; rdi != NULL; rdi = next ) { |
| 1396 |
next = rdi->rdi_next; |
| 1397 |
retcode_item_destroy( rdi ); |
| 1398 |
} |
| 1399 |
|
| 1400 |
if ( !BER_BVISNULL( &rd->rd_pdn ) ) { |
| 1401 |
ber_memfree( rd->rd_pdn.bv_val ); |
| 1402 |
} |
| 1403 |
|
| 1404 |
if ( !BER_BVISNULL( &rd->rd_npdn ) ) { |
| 1405 |
ber_memfree( rd->rd_npdn.bv_val ); |
| 1406 |
} |
| 1407 |
|
| 1408 |
ber_memfree( rd ); |
| 1409 |
} |
| 1410 |
|
| 1411 |
return 0; |
| 1412 |
} |
| 1413 |
|
| 1414 |
#if SLAPD_OVER_RETCODE == SLAPD_MOD_DYNAMIC |
| 1415 |
static |
| 1416 |
#endif /* SLAPD_OVER_RETCODE == SLAPD_MOD_DYNAMIC */ |
| 1417 |
int |
| 1418 |
retcode_initialize( void ) |
| 1419 |
{ |
| 1420 |
int i, code; |
| 1421 |
|
| 1422 |
static struct { |
| 1423 |
char *desc; |
| 1424 |
AttributeDescription **ad; |
| 1425 |
} retcode_at[] = { |
| 1426 |
{ "( 1.3.6.1.4.1.4203.666.11.4.1.1 " |
| 1427 |
"NAME ( 'errCode' ) " |
| 1428 |
"DESC 'LDAP error code' " |
| 1429 |
"EQUALITY integerMatch " |
| 1430 |
"ORDERING integerOrderingMatch " |
| 1431 |
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 " |
| 1432 |
"SINGLE-VALUE )", |
| 1433 |
&ad_errCode }, |
| 1434 |
{ "( 1.3.6.1.4.1.4203.666.11.4.1.2 " |
| 1435 |
"NAME ( 'errOp' ) " |
| 1436 |
"DESC 'Operations the errObject applies to' " |
| 1437 |
"EQUALITY caseIgnoreMatch " |
| 1438 |
"SUBSTR caseIgnoreSubstringsMatch " |
| 1439 |
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )", |
| 1440 |
&ad_errOp}, |
| 1441 |
{ "( 1.3.6.1.4.1.4203.666.11.4.1.3 " |
| 1442 |
"NAME ( 'errText' ) " |
| 1443 |
"DESC 'LDAP error textual description' " |
| 1444 |
"EQUALITY caseIgnoreMatch " |
| 1445 |
"SUBSTR caseIgnoreSubstringsMatch " |
| 1446 |
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 " |
| 1447 |
"SINGLE-VALUE )", |
| 1448 |
&ad_errText }, |
| 1449 |
{ "( 1.3.6.1.4.1.4203.666.11.4.1.4 " |
| 1450 |
"NAME ( 'errSleepTime' ) " |
| 1451 |
"DESC 'Time to wait before returning the error' " |
| 1452 |
"EQUALITY integerMatch " |
| 1453 |
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 " |
| 1454 |
"SINGLE-VALUE )", |
| 1455 |
&ad_errSleepTime }, |
| 1456 |
{ "( 1.3.6.1.4.1.4203.666.11.4.1.5 " |
| 1457 |
"NAME ( 'errMatchedDN' ) " |
| 1458 |
"DESC 'Value to be returned as matched DN' " |
| 1459 |
"EQUALITY distinguishedNameMatch " |
| 1460 |
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 " |
| 1461 |
"SINGLE-VALUE )", |
| 1462 |
&ad_errMatchedDN }, |
| 1463 |
{ "( 1.3.6.1.4.1.4203.666.11.4.1.6 " |
| 1464 |
"NAME ( 'errUnsolicitedOID' ) " |
| 1465 |
"DESC 'OID to be returned within unsolicited response' " |
| 1466 |
"EQUALITY objectIdentifierMatch " |
| 1467 |
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 " |
| 1468 |
"SINGLE-VALUE )", |
| 1469 |
&ad_errUnsolicitedOID }, |
| 1470 |
{ "( 1.3.6.1.4.1.4203.666.11.4.1.7 " |
| 1471 |
"NAME ( 'errUnsolicitedData' ) " |
| 1472 |
"DESC 'Data to be returned within unsolicited response' " |
| 1473 |
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 " |
| 1474 |
"SINGLE-VALUE )", |
| 1475 |
&ad_errUnsolicitedData }, |
| 1476 |
{ "( 1.3.6.1.4.1.4203.666.11.4.1.8 " |
| 1477 |
"NAME ( 'errDisconnect' ) " |
| 1478 |
"DESC 'Disconnect without notice' " |
| 1479 |
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 " |
| 1480 |
"SINGLE-VALUE )", |
| 1481 |
&ad_errDisconnect }, |
| 1482 |
{ NULL } |
| 1483 |
}; |
| 1484 |
|
| 1485 |
static struct { |
| 1486 |
char *desc; |
| 1487 |
ObjectClass **oc; |
| 1488 |
} retcode_oc[] = { |
| 1489 |
{ "( 1.3.6.1.4.1.4203.666.11.4.3.0 " |
| 1490 |
"NAME ( 'errAbsObject' ) " |
| 1491 |
"SUP top ABSTRACT " |
| 1492 |
"MUST ( errCode ) " |
| 1493 |
"MAY ( " |
| 1494 |
"cn " |
| 1495 |
"$ description " |
| 1496 |
"$ errOp " |
| 1497 |
"$ errText " |
| 1498 |
"$ errSleepTime " |
| 1499 |
"$ errMatchedDN " |
| 1500 |
"$ errUnsolicitedOID " |
| 1501 |
"$ errUnsolicitedData " |
| 1502 |
"$ errDisconnect " |
| 1503 |
") )", |
| 1504 |
&oc_errAbsObject }, |
| 1505 |
{ "( 1.3.6.1.4.1.4203.666.11.4.3.1 " |
| 1506 |
"NAME ( 'errObject' ) " |
| 1507 |
"SUP errAbsObject STRUCTURAL " |
| 1508 |
")", |
| 1509 |
&oc_errObject }, |
| 1510 |
{ "( 1.3.6.1.4.1.4203.666.11.4.3.2 " |
| 1511 |
"NAME ( 'errAuxObject' ) " |
| 1512 |
"SUP errAbsObject AUXILIARY " |
| 1513 |
")", |
| 1514 |
&oc_errAuxObject }, |
| 1515 |
{ NULL } |
| 1516 |
}; |
| 1517 |
|
| 1518 |
|
| 1519 |
for ( i = 0; retcode_at[ i ].desc != NULL; i++ ) { |
| 1520 |
code = register_at( retcode_at[ i ].desc, retcode_at[ i ].ad, 0 ); |
| 1521 |
if ( code ) { |
| 1522 |
Debug( LDAP_DEBUG_ANY, |
| 1523 |
"retcode: register_at failed\n" ); |
| 1524 |
return code; |
| 1525 |
} |
| 1526 |
|
| 1527 |
(*retcode_at[ i ].ad)->ad_type->sat_flags |= SLAP_AT_HIDE; |
| 1528 |
} |
| 1529 |
|
| 1530 |
for ( i = 0; retcode_oc[ i ].desc != NULL; i++ ) { |
| 1531 |
code = register_oc( retcode_oc[ i ].desc, retcode_oc[ i ].oc, 0 ); |
| 1532 |
if ( code ) { |
| 1533 |
Debug( LDAP_DEBUG_ANY, |
| 1534 |
"retcode: register_oc failed\n" ); |
| 1535 |
return code; |
| 1536 |
} |
| 1537 |
|
| 1538 |
(*retcode_oc[ i ].oc)->soc_flags |= SLAP_OC_HIDE; |
| 1539 |
} |
| 1540 |
|
| 1541 |
retcode.on_bi.bi_type = "retcode"; |
| 1542 |
|
| 1543 |
retcode.on_bi.bi_db_init = retcode_db_init; |
| 1544 |
retcode.on_bi.bi_db_open = retcode_db_open; |
| 1545 |
retcode.on_bi.bi_db_destroy = retcode_db_destroy; |
| 1546 |
|
| 1547 |
retcode.on_bi.bi_op_add = retcode_op_func; |
| 1548 |
retcode.on_bi.bi_op_bind = retcode_op_func; |
| 1549 |
retcode.on_bi.bi_op_compare = retcode_op_func; |
| 1550 |
retcode.on_bi.bi_op_delete = retcode_op_func; |
| 1551 |
retcode.on_bi.bi_op_modify = retcode_op_func; |
| 1552 |
retcode.on_bi.bi_op_modrdn = retcode_op_func; |
| 1553 |
retcode.on_bi.bi_op_search = retcode_op_func; |
| 1554 |
|
| 1555 |
retcode.on_bi.bi_extended = retcode_op_func; |
| 1556 |
|
| 1557 |
retcode.on_response = retcode_response; |
| 1558 |
|
| 1559 |
retcode.on_bi.bi_cf_ocs = rcocs; |
| 1560 |
|
| 1561 |
code = config_register_schema( rccfg, rcocs ); |
| 1562 |
if ( code ) { |
| 1563 |
return code; |
| 1564 |
} |
| 1565 |
|
| 1566 |
return overlay_register( &retcode ); |
| 1567 |
} |
| 1568 |
|
| 1569 |
#if SLAPD_OVER_RETCODE == SLAPD_MOD_DYNAMIC |
| 1570 |
int |
| 1571 |
init_module( int argc, char *argv[] ) |
| 1572 |
{ |
| 1573 |
return retcode_initialize(); |
| 1574 |
} |
| 1575 |
#endif /* SLAPD_OVER_RETCODE == SLAPD_MOD_DYNAMIC */ |
| 1576 |
|
| 1577 |
#endif /* SLAPD_OVER_RETCODE */ |