1 /* retcode.c - customizable response for client testing purposes */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005 The OpenLDAP Foundation.
6 * Portions Copyright 2005 Pierangelo Masarati <ando@sys-net.it>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
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>.
18 * This work was initially developed by Pierangelo Masarati for inclusion
19 * in OpenLDAP Software.
24 #ifdef SLAPD_OVER_RETCODE
28 #include <ac/unistd.h>
29 #include <ac/string.h>
31 #include <ac/socket.h>
36 static slap_overinst retcode;
38 static AttributeDescription *ad_errCode;
39 static AttributeDescription *ad_errText;
40 static AttributeDescription *ad_errOp;
41 static AttributeDescription *ad_errSleepTime;
42 static ObjectClass *oc_errAbsObject;
43 static ObjectClass *oc_errObject;
44 static ObjectClass *oc_errAuxObject;
46 typedef enum retcode_op_e {
47 SN_DG_OP_NONE = 0x0000,
48 SN_DG_OP_ADD = 0x0001,
49 SN_DG_OP_BIND = 0x0002,
50 SN_DG_OP_COMPARE = 0x0004,
51 SN_DG_OP_DELETE = 0x0008,
52 SN_DG_OP_MODIFY = 0x0010,
53 SN_DG_OP_RENAME = 0x0020,
54 SN_DG_OP_SEARCH = 0x0040,
55 SN_DG_EXTENDED = 0x0080,
56 SN_DG_OP_AUTH = SN_DG_OP_BIND,
57 SN_DG_OP_READ = (SN_DG_OP_COMPARE|SN_DG_OP_SEARCH),
58 SN_DG_OP_WRITE = (SN_DG_OP_ADD|SN_DG_OP_DELETE|SN_DG_OP_MODIFY|SN_DG_OP_RENAME),
59 SN_DG_OP_ALL = (SN_DG_OP_AUTH|SN_DG_OP_READ|SN_DG_OP_WRITE|SN_DG_EXTENDED)
62 typedef struct retcode_item_t {
64 struct berval rdi_ndn;
65 struct berval rdi_text;
71 struct retcode_item_t *rdi_next;
74 typedef struct retcode_t {
76 struct berval rd_npdn;
78 retcode_item_t *rd_item;
81 #define RETCODE_FNONE 0x00
82 #define RETCODE_FINDIR 0x01
83 #define RETCODE_FSTOP 0x02
84 #define RETCODE_INDIR( rd ) ( (rd)->rd_flags & RETCODE_FINDIR )
88 retcode_entry_response( Operation *op, SlapReply *rs, Entry *e );
91 retcode_cleanup_cb( Operation *op, SlapReply *rs )
93 rs->sr_matched = NULL;
96 if ( rs->sr_ref != NULL ) {
97 ber_bvarray_free( rs->sr_ref );
101 ch_free( op->o_callback );
102 op->o_callback = NULL;
104 return SLAP_CB_CONTINUE;
108 retcode_send_onelevel( Operation *op, SlapReply *rs )
110 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
111 retcode_t *rd = (retcode_t *)on->on_bi.bi_private;
115 for ( rdi = rd->rd_item; rdi != NULL; rdi = rdi->rdi_next ) {
118 if ( op->o_abandon ) {
119 return rs->sr_err = SLAPD_ABANDON;
122 rs->sr_err = test_filter( op, &rdi->rdi_e, op->ors_filter );
123 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
124 if ( op->ors_slimit == rs->sr_nentries ) {
125 rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
130 rs->sr_attrs = op->ors_attrs;
131 rs->sr_operational_attrs = NULL;
134 rs->sr_err = LDAP_SUCCESS;
135 rs->sr_entry = &rdi->rdi_e;
137 rc = send_search_entry( op, rs );
140 case 0: /* entry sent ok */
142 case 1: /* entry not sent */
144 case -1: /* connection closed */
146 rs->sr_err = LDAP_OTHER;
150 rs->sr_err = LDAP_SUCCESS;
155 send_ldap_result( op, rs );
161 retcode_op_add( Operation *op, SlapReply *rs )
163 return retcode_entry_response( op, rs, op->ora_e );
166 typedef struct retcode_cb_t {
172 retcode_cb_response( Operation *op, SlapReply *rs )
174 retcode_cb_t *rdc = (retcode_cb_t *)op->o_callback->sc_private;
176 if ( rs->sr_type == REP_SEARCH ) {
177 ber_tag_t o_tag = op->o_tag;
180 op->o_tag = rdc->rdc_tag;
181 rc = retcode_entry_response( op, rs, rs->sr_entry );
187 if ( rs->sr_err == LDAP_SUCCESS ) {
188 if ( ! ( rdc->rdc_flags & RETCODE_FSTOP ) ) {
189 rdc->rdc_flags = SLAP_CB_CONTINUE;
194 return SLAP_CB_CONTINUE;
198 retcode_op_internal( Operation *op, SlapReply *rs )
200 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
203 SlapReply rs2 = { 0 };
204 BackendDB db = *op->o_bd;
205 slap_callback sc = { 0 };
210 op2.o_tag = LDAP_REQ_SEARCH;
211 op2.ors_scope = LDAP_SCOPE_BASE;
212 op2.ors_deref = LDAP_DEREF_NEVER;
213 op2.ors_tlimit = SLAP_NO_LIMIT;
214 op2.ors_slimit = SLAP_NO_LIMIT;
215 op2.ors_limit = NULL;
216 op2.ors_attrsonly = 0;
217 op2.ors_attrs = slap_anlist_all_attributes;
219 ber_str2bv_x( "(objectClass=errAbsObject)",
220 STRLENOF( "(objectClass=errAbsObject)" ),
221 1, &op2.ors_filterstr, op2.o_tmpmemctx );
222 op2.ors_filter = str2filter_x( &op2, op2.ors_filterstr.bv_val );
224 db.bd_info = on->on_info->oi_orig;
227 rdc.rdc_flags = RETCODE_FINDIR;
228 if ( op->o_tag == LDAP_REQ_SEARCH && op->ors_scope == LDAP_SCOPE_BASE ) {
229 rdc.rdc_flags |= RETCODE_FSTOP;
231 rdc.rdc_tag = op->o_tag;
232 sc.sc_response = retcode_cb_response;
233 sc.sc_private = &rdc;
234 op2.o_callback = ≻
236 rc = op2.o_bd->be_search( &op2, &rs2 );
238 filter_free_x( &op2, op2.ors_filter );
239 ber_memfree_x( op2.ors_filterstr.bv_val, op2.o_tmpmemctx );
241 if ( rdc.rdc_flags == SLAP_CB_CONTINUE ) {
242 return SLAP_CB_CONTINUE;
249 retcode_op_func( Operation *op, SlapReply *rs )
251 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
252 retcode_t *rd = (retcode_t *)on->on_bi.bi_private;
255 struct berval nrdn, npdn;
257 slap_callback *cb = NULL;
259 if ( !dnIsSuffix( &op->o_req_ndn, &rd->rd_npdn ) ) {
260 if ( RETCODE_INDIR( rd ) ) {
261 switch ( op->o_tag ) {
263 return retcode_op_add( op, rs );
266 if ( be_isroot_pw( op ) ) {
267 return SLAP_CB_CONTINUE;
271 case LDAP_REQ_MODIFY:
272 case LDAP_REQ_DELETE:
273 case LDAP_REQ_MODRDN:
274 case LDAP_REQ_COMPARE:
275 case LDAP_REQ_SEARCH:
276 return retcode_op_internal( op, rs );
280 return SLAP_CB_CONTINUE;
283 if ( op->o_tag == LDAP_REQ_SEARCH
284 && op->ors_scope != LDAP_SCOPE_BASE
285 && op->o_req_ndn.bv_len == rd->rd_npdn.bv_len )
287 return retcode_send_onelevel( op, rs );
290 dnParent( &op->o_req_ndn, &npdn );
291 if ( npdn.bv_len != rd->rd_npdn.bv_len ) {
292 rs->sr_err = LDAP_NO_SUCH_OBJECT;
293 rs->sr_matched = rd->rd_pdn.bv_val;
294 send_ldap_result( op, rs );
295 rs->sr_matched = NULL;
299 dnRdn( &op->o_req_ndn, &nrdn );
301 for ( rdi = rd->rd_item; rdi != NULL; rdi = rdi->rdi_next ) {
302 struct berval rdi_nrdn;
304 dnRdn( &rdi->rdi_ndn, &rdi_nrdn );
305 if ( dn_match( &nrdn, &rdi_nrdn ) ) {
310 if ( rdi != NULL && rdi->rdi_mask != SN_DG_OP_ALL ) {
311 retcode_op_e o_tag = SN_DG_OP_NONE;
313 switch ( op->o_tag ) {
315 o_tag = SN_DG_OP_ADD;
319 o_tag = SN_DG_OP_BIND;
322 case LDAP_REQ_COMPARE:
323 o_tag = SN_DG_OP_COMPARE;
326 case LDAP_REQ_DELETE:
327 o_tag = SN_DG_OP_DELETE;
330 case LDAP_REQ_MODIFY:
331 o_tag = SN_DG_OP_MODIFY;
334 case LDAP_REQ_MODRDN:
335 o_tag = SN_DG_OP_RENAME;
338 case LDAP_REQ_SEARCH:
339 o_tag = SN_DG_OP_SEARCH;
342 case LDAP_REQ_EXTENDED:
343 o_tag = SN_DG_EXTENDED;
347 /* Should not happen */
351 if ( !( o_tag & rdi->rdi_mask ) ) {
352 return SLAP_CB_CONTINUE;
357 rs->sr_matched = rd->rd_pdn.bv_val;
358 rs->sr_err = LDAP_NO_SUCH_OBJECT;
359 rs->sr_text = "retcode not found";
362 rs->sr_err = rdi->rdi_err;
363 rs->sr_text = rdi->rdi_text.bv_val;
365 /* FIXME: we only honor the rdi_ref field in case rdi_err
366 * is LDAP_REFERRAL otherwise send_ldap_result() bails out */
367 if ( rs->sr_err == LDAP_REFERRAL ) {
370 if ( rdi->rdi_ref != NULL ) {
373 ref = default_referral;
377 rs->sr_ref = referral_rewrite( ref,
378 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
381 rs->sr_err = LDAP_OTHER;
382 rs->sr_text = "bad referral object";
386 if ( rdi->rdi_sleeptime > 0 ) {
387 sleep( rdi->rdi_sleeptime );
391 switch ( op->o_tag ) {
392 case LDAP_REQ_EXTENDED:
396 cb = ( slap_callback * )ch_malloc( sizeof( slap_callback ) );
397 memset( cb, 0, sizeof( slap_callback ) );
398 cb->sc_cleanup = retcode_cleanup_cb;
403 send_ldap_result( op, rs );
404 if ( rs->sr_ref != NULL ) {
405 ber_bvarray_free( rs->sr_ref );
407 rs->sr_matched = NULL;
416 retcode_op2str( ber_tag_t op, struct berval *bv )
420 BER_BVSTR( bv, "bind" );
423 BER_BVSTR( bv, "add" );
425 case LDAP_REQ_DELETE:
426 BER_BVSTR( bv, "delete" );
428 case LDAP_REQ_MODRDN:
429 BER_BVSTR( bv, "modrdn" );
431 case LDAP_REQ_MODIFY:
432 BER_BVSTR( bv, "modify" );
434 case LDAP_REQ_COMPARE:
435 BER_BVSTR( bv, "compare" );
437 case LDAP_REQ_SEARCH:
438 BER_BVSTR( bv, "search" );
440 case LDAP_REQ_EXTENDED:
441 BER_BVSTR( bv, "extended" );
448 retcode_entry_response( Operation *op, SlapReply *rs, Entry *e )
450 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
456 if ( get_manageDSAit( op ) ) {
457 return SLAP_CB_CONTINUE;
460 if ( !is_entry_objectclass( e, oc_errAbsObject, 0 ) ) {
461 return SLAP_CB_CONTINUE;
465 a = attr_find( e->e_attrs, ad_errOp );
469 struct berval bv = BER_BVNULL;
471 (void)retcode_op2str( op->o_tag, &bv );
473 if ( BER_BVISNULL( &bv ) ) {
474 return SLAP_CB_CONTINUE;
477 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ ) {
478 if ( bvmatch( &a->a_nvals[ i ], &bv ) ) {
485 return SLAP_CB_CONTINUE;
490 a = attr_find( e->e_attrs, ad_errCode );
492 return SLAP_CB_CONTINUE;
494 err = strtol( a->a_nvals[ 0 ].bv_val, &next, 0 );
495 if ( next == a->a_nvals[ 0 ].bv_val || next[ 0 ] != '\0' ) {
496 return SLAP_CB_CONTINUE;
501 a = attr_find( e->e_attrs, ad_errSleepTime );
505 sleepTime = strtoul( a->a_nvals[ 0 ].bv_val, &next, 0 );
506 if ( next != a->a_nvals[ 0 ].bv_val && next[ 0 ] == '\0' ) {
511 if ( rs->sr_err != LDAP_SUCCESS ) {
512 BackendDB db = *op->o_bd;
513 void *o_callback = op->o_callback;
516 a = attr_find( e->e_attrs, ad_errText );
518 rs->sr_text = a->a_vals[ 0 ].bv_val;
521 db.bd_info = on->on_info->oi_orig;
523 op->o_callback = NULL;
526 if ( rs->sr_err == LDAP_REFERRAL ) {
527 BerVarray refs = default_referral;
529 a = attr_find( e->e_attrs, slap_schema.si_ad_ref );
533 rs->sr_ref = referral_rewrite( refs,
534 NULL, &op->o_req_dn, op->oq_search.rs_scope );
536 send_search_reference( op, rs );
537 ber_bvarray_free( rs->sr_ref );
541 send_ldap_result( op, rs );
545 op->o_callback = o_callback;
548 if ( rs->sr_err != LDAP_SUCCESS ) {
553 return SLAP_CB_CONTINUE;
557 retcode_response( Operation *op, SlapReply *rs )
559 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
560 retcode_t *rd = (retcode_t *)on->on_bi.bi_private;
562 if ( rs->sr_type != REP_SEARCH || !RETCODE_INDIR( rd ) ) {
563 return SLAP_CB_CONTINUE;
566 return retcode_entry_response( op, rs, rs->sr_entry );
570 retcode_db_init( BackendDB *be )
572 slap_overinst *on = (slap_overinst *)be->bd_info;
575 rd = (retcode_t *)ch_malloc( sizeof( retcode_t ) );
576 memset( rd, 0, sizeof( retcode_t ) );
578 on->on_bi.bi_private = (void *)rd;
591 slap_overinst *on = (slap_overinst *)be->bd_info;
592 retcode_t *rd = (retcode_t *)on->on_bi.bi_private;
594 char *argv0 = argv[ 0 ] + STRLENOF( "retcode-" );
596 if ( strncasecmp( argv[ 0 ], "retcode-", STRLENOF( "retcode-" ) ) != 0 ) {
597 return SLAP_CONF_UNKNOWN;
600 if ( strcasecmp( argv0, "parent" ) == 0 ) {
605 fprintf( stderr, "%s: line %d: retcode: "
606 "\"retcode-parent <DN>\": missing <DN>\n",
611 if ( !BER_BVISNULL( &rd->rd_pdn ) ) {
612 fprintf( stderr, "%s: line %d: retcode: "
613 "parent already defined.\n", fname, lineno );
617 ber_str2bv( argv[ 1 ], 0, 0, &dn );
619 rc = dnPrettyNormal( NULL, &dn, &rd->rd_pdn, &rd->rd_npdn, NULL );
620 if ( rc != LDAP_SUCCESS ) {
621 fprintf( stderr, "%s: line %d: retcode: "
622 "unable to normalize parent DN \"%s\": %d\n",
623 fname, lineno, argv[ 1 ], rc );
627 } else if ( strcasecmp( argv0, "item" ) == 0 ) {
628 retcode_item_t rdi = { BER_BVNULL }, **rdip;
629 struct berval bv, rdn, nrdn;
634 fprintf( stderr, "%s: line %d: retcode: "
635 "\"retcode-item <RDN> <retcode> [<text>]\": "
641 ber_str2bv( argv[ 1 ], 0, 0, &bv );
643 rc = dnPrettyNormal( NULL, &bv, &rdn, &nrdn, NULL );
644 if ( rc != LDAP_SUCCESS ) {
645 fprintf( stderr, "%s: line %d: retcode: "
646 "unable to normalize RDN \"%s\": %d\n",
647 fname, lineno, argv[ 1 ], rc );
651 if ( !dnIsOneLevelRDN( &nrdn ) ) {
652 fprintf( stderr, "%s: line %d: retcode: "
653 "value \"%s\" is not a RDN\n",
654 fname, lineno, argv[ 1 ] );
658 if ( BER_BVISNULL( &rd->rd_npdn ) ) {
659 /* FIXME: we use the database suffix */
660 if ( be->be_nsuffix == NULL ) {
661 fprintf( stderr, "%s: line %d: retcode: "
662 "either \"retcode-parent\" "
663 "or \"suffix\" must be defined.\n",
668 ber_dupbv( &rd->rd_pdn, &be->be_suffix[ 0 ] );
669 ber_dupbv( &rd->rd_npdn, &be->be_nsuffix[ 0 ] );
672 build_new_dn( &rdi.rdi_dn, &rd->rd_pdn, &rdn, NULL );
673 build_new_dn( &rdi.rdi_ndn, &rd->rd_npdn, &nrdn, NULL );
675 ch_free( rdn.bv_val );
676 ch_free( nrdn.bv_val );
678 rdi.rdi_err = strtol( argv[ 2 ], &next, 0 );
679 if ( next == argv[ 2 ] || next[ 0 ] != '\0' ) {
680 fprintf( stderr, "%s: line %d: retcode: "
681 "unable to parse return code \"%s\"\n",
682 fname, lineno, argv[ 2 ] );
686 rdi.rdi_mask = SN_DG_OP_ALL;
691 for ( i = 3; i < argc; i++ ) {
692 if ( strncasecmp( argv[ i ], "op=", STRLENOF( "op=" ) ) == 0 )
697 ops = ldap_str2charray( &argv[ i ][ STRLENOF( "op=" ) ], "," );
698 assert( ops != NULL );
700 rdi.rdi_mask = SN_DG_OP_NONE;
702 for ( j = 0; ops[ j ] != NULL; j++ ) {
703 if ( strcasecmp( ops[ j ], "add" ) == 0 ) {
704 rdi.rdi_mask |= SN_DG_OP_ADD;
706 } else if ( strcasecmp( ops[ j ], "bind" ) == 0 ) {
707 rdi.rdi_mask |= SN_DG_OP_BIND;
709 } else if ( strcasecmp( ops[ j ], "compare" ) == 0 ) {
710 rdi.rdi_mask |= SN_DG_OP_COMPARE;
712 } else if ( strcasecmp( ops[ j ], "add" ) == 0 ) {
713 rdi.rdi_mask |= SN_DG_OP_DELETE;
715 } else if ( strcasecmp( ops[ j ], "modify" ) == 0 ) {
716 rdi.rdi_mask |= SN_DG_OP_MODIFY;
718 } else if ( strcasecmp( ops[ j ], "rename" ) == 0 ) {
719 rdi.rdi_mask |= SN_DG_OP_RENAME;
721 } else if ( strcasecmp( ops[ j ], "search" ) == 0 ) {
722 rdi.rdi_mask |= SN_DG_OP_SEARCH;
724 } else if ( strcasecmp( ops[ j ], "extended" ) == 0 ) {
725 rdi.rdi_mask |= SN_DG_EXTENDED;
727 } else if ( strcasecmp( ops[ j ], "auth" ) == 0 ) {
728 rdi.rdi_mask |= SN_DG_OP_AUTH;
730 } else if ( strcasecmp( ops[ j ], "read" ) == 0 ) {
731 rdi.rdi_mask |= SN_DG_OP_READ;
733 } else if ( strcasecmp( ops[ j ], "write" ) == 0 ) {
734 rdi.rdi_mask |= SN_DG_OP_WRITE;
736 } else if ( strcasecmp( ops[ j ], "all" ) == 0 ) {
737 rdi.rdi_mask |= SN_DG_OP_ALL;
740 fprintf( stderr, "retcode: unknown op \"%s\"\n",
746 ldap_charray_free( ops );
748 } else if ( strncasecmp( argv[ i ], "text=", STRLENOF( "text=" ) ) == 0 )
750 if ( !BER_BVISNULL( &rdi.rdi_text ) ) {
751 fprintf( stderr, "%s: line %d: retcode: "
752 "\"text\" already provided.\n",
756 ber_str2bv( &argv[ i ][ STRLENOF( "text=" ) ], 0, 1, &rdi.rdi_text );
758 } else if ( strncasecmp( argv[ i ], "ref=", STRLENOF( "ref=" ) ) == 0 )
763 if ( rdi.rdi_ref != NULL ) {
764 fprintf( stderr, "%s: line %d: retcode: "
765 "\"ref\" already provided.\n",
770 if ( rdi.rdi_err != LDAP_REFERRAL ) {
771 fprintf( stderr, "%s: line %d: retcode: "
772 "providing \"ref\"\n"
773 "\talong with a non-referral "
774 "resultCode may cause slapd failures\n"
775 "\trelated to internal checks.\n",
779 refs = ldap_str2charray( &argv[ i ][ STRLENOF( "ref=" ) ], " " );
780 assert( refs != NULL );
782 for ( j = 0; refs[ j ] != NULL; j++ ) {
785 ber_str2bv( refs[ j ], 0, 1, &bv );
786 ber_bvarray_add( &rdi.rdi_ref, &bv );
789 ldap_charray_free( refs );
791 } else if ( strncasecmp( argv[ i ], "sleeptime=", STRLENOF( "sleeptime=" ) ) == 0 )
794 if ( rdi.rdi_sleeptime != 0 ) {
795 fprintf( stderr, "%s: line %d: retcode: "
796 "\"sleeptime\" already provided.\n",
801 rdi.rdi_sleeptime = strtol( &argv[ i ][ STRLENOF( "sleeptime=" ) ], &next, 10 );
802 if ( next == argv[ i ] || next[ 0 ] != '\0' ) {
803 fprintf( stderr, "%s: line %d: retcode: "
804 "unable to parse \"sleeptime=%s\".\n",
805 fname, lineno, &argv[ i ][ STRLENOF( "sleeptime=" ) ] );
810 fprintf( stderr, "%s: line %d: retcode: "
811 "unknown option \"%s\".\n",
812 fname, lineno, argv[ i ] );
818 for ( rdip = &rd->rd_item; *rdip; rdip = &(*rdip)->rdi_next )
822 *rdip = ( retcode_item_t * )ch_malloc( sizeof( retcode_item_t ) );
825 } else if ( strcasecmp( argv0, "indir" ) == 0 ) {
826 rd->rd_flags |= RETCODE_FINDIR;
829 return SLAP_CONF_UNKNOWN;
836 retcode_db_open( BackendDB *be )
838 slap_overinst *on = (slap_overinst *)be->bd_info;
839 retcode_t *rd = (retcode_t *)on->on_bi.bi_private;
843 for ( rdi = rd->rd_item; rdi; rdi = rdi->rdi_next ) {
847 struct berval val[ 3 ];
848 char buf[ SLAP_TEXT_BUFLEN ];
851 rdi->rdi_e.e_name = rdi->rdi_dn;
852 rdi->rdi_e.e_nname = rdi->rdi_ndn;
855 val[ 0 ] = oc_errObject->soc_cname;
856 val[ 1 ] = slap_schema.si_oc_extensibleObject->soc_cname;
857 BER_BVZERO( &val[ 2 ] );
859 attr_merge( &rdi->rdi_e, slap_schema.si_ad_objectClass, val, NULL );
862 rc = ldap_bv2rdn( &rdi->rdi_dn, &rdn, (char **) &p,
863 LDAP_DN_FORMAT_LDAP );
865 assert( rc == LDAP_SUCCESS );
867 for ( j = 0; rdn[ j ]; j++ ) {
868 LDAPAVA *ava = rdn[ j ];
869 AttributeDescription *ad = NULL;
872 rc = slap_bv2ad( &ava->la_attr, &ad, &text );
873 assert( rc == LDAP_SUCCESS );
875 attr_merge_normalize_one( &rdi->rdi_e, ad,
876 &ava->la_value, NULL );
882 snprintf( buf, sizeof( buf ), "%d", rdi->rdi_err );
883 ber_str2bv( buf, 0, 0, &val[ 0 ] );
885 attr_merge_one( &rdi->rdi_e, ad_errCode, &val[ 0 ], NULL );
887 if ( rdi->rdi_ref != NULL ) {
888 attr_merge_normalize( &rdi->rdi_e, slap_schema.si_ad_ref,
889 rdi->rdi_ref, NULL );
893 if ( !BER_BVISNULL( &rdi->rdi_text ) ) {
894 val[ 0 ] = rdi->rdi_text;
896 attr_merge_normalize_one( &rdi->rdi_e, ad_errText, &val[ 0 ], NULL );
900 if ( rdi->rdi_sleeptime > 0 ) {
901 snprintf( buf, sizeof( buf ), "%d", rdi->rdi_sleeptime );
902 ber_str2bv( buf, 0, 0, &val[ 0 ] );
904 attr_merge_one( &rdi->rdi_e, ad_errSleepTime, &val[ 0 ], NULL );
908 if ( rdi->rdi_mask & SN_DG_OP_ADD ) {
909 BER_BVSTR( &val[ 0 ], "add" );
910 attr_merge_normalize_one( &rdi->rdi_e, ad_errOp, &val[ 0 ], NULL );
913 if ( rdi->rdi_mask & SN_DG_OP_BIND ) {
914 BER_BVSTR( &val[ 0 ], "bind" );
915 attr_merge_normalize_one( &rdi->rdi_e, ad_errOp, &val[ 0 ], NULL );
918 if ( rdi->rdi_mask & SN_DG_OP_COMPARE ) {
919 BER_BVSTR( &val[ 0 ], "compare" );
920 attr_merge_normalize_one( &rdi->rdi_e, ad_errOp, &val[ 0 ], NULL );
923 if ( rdi->rdi_mask & SN_DG_OP_DELETE ) {
924 BER_BVSTR( &val[ 0 ], "delete" );
925 attr_merge_normalize_one( &rdi->rdi_e, ad_errOp, &val[ 0 ], NULL );
928 if ( rdi->rdi_mask & SN_DG_EXTENDED ) {
929 BER_BVSTR( &val[ 0 ], "extended" );
930 attr_merge_normalize_one( &rdi->rdi_e, ad_errOp, &val[ 0 ], NULL );
933 if ( rdi->rdi_mask & SN_DG_OP_MODIFY ) {
934 BER_BVSTR( &val[ 0 ], "modify" );
935 attr_merge_normalize_one( &rdi->rdi_e, ad_errOp, &val[ 0 ], NULL );
938 if ( rdi->rdi_mask & SN_DG_OP_RENAME ) {
939 BER_BVSTR( &val[ 0 ], "rename" );
940 attr_merge_normalize_one( &rdi->rdi_e, ad_errOp, &val[ 0 ], NULL );
943 if ( rdi->rdi_mask & SN_DG_OP_SEARCH ) {
944 BER_BVSTR( &val[ 0 ], "search" );
945 attr_merge_normalize_one( &rdi->rdi_e, ad_errOp, &val[ 0 ], NULL );
953 retcode_db_destroy( BackendDB *be )
955 slap_overinst *on = (slap_overinst *)be->bd_info;
956 retcode_t *rd = (retcode_t *)on->on_bi.bi_private;
959 retcode_item_t *rdi, *next;
961 for ( rdi = rd->rd_item; rdi != NULL; rdi = next ) {
962 ber_memfree( rdi->rdi_dn.bv_val );
963 ber_memfree( rdi->rdi_ndn.bv_val );
965 if ( !BER_BVISNULL( &rdi->rdi_text ) ) {
966 ber_memfree( rdi->rdi_text.bv_val );
969 BER_BVZERO( &rdi->rdi_e.e_name );
970 BER_BVZERO( &rdi->rdi_e.e_nname );
972 entry_clean( &rdi->rdi_e );
974 next = rdi->rdi_next;
985 #if SLAPD_OVER_RETCODE == SLAPD_MOD_DYNAMIC
987 #endif /* SLAPD_OVER_RETCODE == SLAPD_MOD_DYNAMIC */
997 AttributeDescription **ad;
999 { "errCode", "( 1.3.6.1.4.1.4203.666.11.4.1.1 "
1000 "NAME ( 'errCode' ) "
1001 "DESC 'LDAP error code' "
1002 "EQUALITY integerMatch "
1003 "ORDERING integerOrderingMatch "
1004 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
1007 { "errOp", "( 1.3.6.1.4.1.4203.666.11.4.1.2 "
1009 "DESC 'Operations the errObject applies to' "
1010 "EQUALITY caseIgnoreMatch "
1011 "SUBSTR caseIgnoreSubstringsMatch "
1012 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1014 { "errText", "( 1.3.6.1.4.1.4203.666.11.4.1.3 "
1015 "NAME ( 'errText' ) "
1016 "DESC 'LDAP error textual description' "
1017 "EQUALITY caseIgnoreMatch "
1018 "SUBSTR caseIgnoreSubstringsMatch "
1019 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
1022 { "errSleepTime", "( 1.3.6.1.4.1.4203.666.11.4.1.4 "
1023 "NAME ( 'errSleepTime' ) "
1024 "DESC 'Time to wait before returning the error' "
1025 "EQUALITY integerMatch "
1026 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
1037 { "errAbsObject", "( 1.3.6.1.4.1.4203.666.11.4.3.0 "
1038 "NAME ( 'errAbsObject' ) "
1049 { "errObject", "( 1.3.6.1.4.1.4203.666.11.4.3.1 "
1050 "NAME ( 'errObject' ) "
1051 "SUP errAbsObject STRUCTURAL "
1054 { "errAuxObject", "( 1.3.6.1.4.1.4203.666.11.4.3.2 "
1055 "NAME ( 'errAuxObject' ) "
1056 "SUP errAbsObject AUXILIARY "
1063 for ( i = 0; retcode_at[ i ].name != NULL; i++ ) {
1064 LDAPAttributeType *at;
1066 at = ldap_str2attributetype( retcode_at[ i ].desc,
1067 &code, &err, LDAP_SCHEMA_ALLOW_ALL );
1069 fprintf( stderr, "retcode: "
1070 "AttributeType load failed: %s %s\n",
1071 ldap_scherr2str( code ), err );
1075 #if LDAP_VENDOR_VERSION_MINOR == X || LDAP_VENDOR_VERSION_MINOR > 2
1076 code = at_add( at, 0, NULL, &err );
1078 code = at_add( at, &err );
1081 if ( code != LDAP_SUCCESS ) {
1082 fprintf( stderr, "retcode: "
1083 "AttributeType load failed: %s %s\n",
1084 scherr2str( code ), err );
1088 code = slap_str2ad( retcode_at[ i ].name,
1089 retcode_at[ i ].ad, &err );
1090 if ( code != LDAP_SUCCESS ) {
1091 fprintf( stderr, "retcode: unable to find "
1092 "AttributeDescription \"%s\": %d (%s)\n",
1093 retcode_at[ i ].name, code, err );
1098 for ( i = 0; retcode_oc[ i ].name != NULL; i++ ) {
1099 LDAPObjectClass *oc;
1101 oc = ldap_str2objectclass( retcode_oc[ i ].desc,
1102 &code, &err, LDAP_SCHEMA_ALLOW_ALL );
1104 fprintf( stderr, "retcode: "
1105 "ObjectClass load failed: %s %s\n",
1106 ldap_scherr2str( code ), err );
1110 #if LDAP_VENDOR_VERSION_MINOR == X || LDAP_VENDOR_VERSION_MINOR > 2
1111 code = oc_add( oc, 0, NULL, &err );
1113 code = oc_add( oc, &err );
1116 if ( code != LDAP_SUCCESS ) {
1117 fprintf( stderr, "retcode: "
1118 "ObjectClass load failed: %s %s\n",
1119 scherr2str( code ), err );
1123 *retcode_oc[ i ].oc = oc_find( retcode_oc[ i ].name );
1124 if ( *retcode_oc[ i ].oc == NULL ) {
1125 fprintf( stderr, "retcode: unable to find "
1126 "objectClass \"%s\"\n",
1127 retcode_oc[ i ].name );
1132 retcode.on_bi.bi_type = "retcode";
1134 retcode.on_bi.bi_db_init = retcode_db_init;
1135 retcode.on_bi.bi_db_config = retcode_db_config;
1136 retcode.on_bi.bi_db_open = retcode_db_open;
1137 retcode.on_bi.bi_db_destroy = retcode_db_destroy;
1139 retcode.on_bi.bi_op_add = retcode_op_func;
1140 retcode.on_bi.bi_op_bind = retcode_op_func;
1141 retcode.on_bi.bi_op_compare = retcode_op_func;
1142 retcode.on_bi.bi_op_delete = retcode_op_func;
1143 retcode.on_bi.bi_op_modify = retcode_op_func;
1144 retcode.on_bi.bi_op_modrdn = retcode_op_func;
1145 retcode.on_bi.bi_op_search = retcode_op_func;
1147 retcode.on_bi.bi_extended = retcode_op_func;
1149 retcode.on_response = retcode_response;
1151 return overlay_register( &retcode );
1154 #if SLAPD_OVER_RETCODE == SLAPD_MOD_DYNAMIC
1156 init_module( int argc, char *argv[] )
1158 return retcode_init();
1160 #endif /* SLAPD_OVER_RETCODE == SLAPD_MOD_DYNAMIC */
1162 #endif /* SLAPD_OVER_RETCODE */