/* retcode.c - customizable response for client testing purposes */
-/* $Header$ */
+/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 2005 The OpenLDAP Foundation.
+ * Copyright 2005-2009 The OpenLDAP Foundation.
* Portions Copyright 2005 Pierangelo Masarati <ando@sys-net.it>
* All rights reserved.
*
#include <ac/socket.h>
#include "slap.h"
+#include "config.h"
#include "lutil.h"
+#include "ldif.h"
static slap_overinst retcode;
static AttributeDescription *ad_errText;
static AttributeDescription *ad_errOp;
static AttributeDescription *ad_errSleepTime;
+static AttributeDescription *ad_errMatchedDN;
+static AttributeDescription *ad_errUnsolicitedOID;
+static AttributeDescription *ad_errUnsolicitedData;
+static AttributeDescription *ad_errDisconnect;
+
+static ObjectClass *oc_errAbsObject;
static ObjectClass *oc_errObject;
+static ObjectClass *oc_errAuxObject;
typedef enum retcode_op_e {
SN_DG_OP_NONE = 0x0000,
} retcode_op_e;
typedef struct retcode_item_t {
+ struct berval rdi_line;
struct berval rdi_dn;
struct berval rdi_ndn;
struct berval rdi_text;
+ struct berval rdi_matched;
int rdi_err;
BerVarray rdi_ref;
int rdi_sleeptime;
Entry rdi_e;
slap_mask_t rdi_mask;
+ struct berval rdi_unsolicited_oid;
+ struct berval rdi_unsolicited_data;
+
+ unsigned rdi_flags;
+#define RDI_PRE_DISCONNECT (0x1U)
+#define RDI_POST_DISCONNECT (0x2U)
+
struct retcode_item_t *rdi_next;
} retcode_item_t;
struct berval rd_pdn;
struct berval rd_npdn;
+ int rd_sleep;
+
retcode_item_t *rd_item;
- unsigned rd_flags;
-#define RETCODE_FNONE 0x00
+ int rd_indir;
#define RETCODE_FINDIR 0x01
-#define RETCODE_INDIR( rd ) ( (rd)->rd_flags & RETCODE_FINDIR )
+#define RETCODE_INDIR( rd ) ( (rd)->rd_indir )
} retcode_t;
static int
-retcode_entry_response( Operation *op, SlapReply *rs, Entry *e );
+retcode_entry_response( Operation *op, SlapReply *rs, BackendInfo *bi, Entry *e );
+
+static unsigned int
+retcode_sleep( int s )
+{
+ unsigned int r = 0;
+
+ /* sleep as required */
+ if ( s < 0 ) {
+#if 0 /* use high-order bits for better randomness (Numerical Recipes in "C") */
+ r = rand() % (-s);
+#endif
+ r = ((double)(-s))*rand()/(RAND_MAX + 1.0);
+ } else if ( s > 0 ) {
+ r = (unsigned int)s;
+ }
+ if ( r ) {
+ sleep( r );
+ }
+
+ return r;
+}
static int
retcode_cleanup_cb( Operation *op, SlapReply *rs )
retcode_item_t *rdi;
for ( rdi = rd->rd_item; rdi != NULL; rdi = rdi->rdi_next ) {
- int rc;
-
if ( op->o_abandon ) {
return rs->sr_err = SLAPD_ABANDON;
}
rs->sr_err = test_filter( op, &rdi->rdi_e, op->ors_filter );
if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
- if ( op->ors_slimit == rs->sr_nentries ) {
- rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
- goto done;
- }
-
/* safe default */
rs->sr_attrs = op->ors_attrs;
rs->sr_operational_attrs = NULL;
rs->sr_err = LDAP_SUCCESS;
rs->sr_entry = &rdi->rdi_e;
- rc = send_search_entry( op, rs );
+ rs->sr_err = send_search_entry( op, rs );
+ rs->sr_entry = NULL;
- switch ( rc ) {
- case 0: /* entry sent ok */
- break;
- case 1: /* entry not sent */
- break;
- case -1: /* connection closed */
- rs->sr_entry = NULL;
+ switch ( rs->sr_err ) {
+ case LDAP_UNAVAILABLE: /* connection closed */
rs->sr_err = LDAP_OTHER;
+ /* fallthru */
+ case LDAP_SIZELIMIT_EXCEEDED:
goto done;
}
}
static int
retcode_op_add( Operation *op, SlapReply *rs )
{
- return retcode_entry_response( op, rs, op->ora_e );
+ return retcode_entry_response( op, rs, NULL, op->ora_e );
}
typedef struct retcode_cb_t {
+ BackendInfo *rdc_info;
unsigned rdc_flags;
ber_tag_t rdc_tag;
+ AttributeName *rdc_attrs;
} retcode_cb_t;
static int
{
retcode_cb_t *rdc = (retcode_cb_t *)op->o_callback->sc_private;
+ op->o_tag = rdc->rdc_tag;
if ( rs->sr_type == REP_SEARCH ) {
ber_tag_t o_tag = op->o_tag;
int rc;
- op->o_tag = rdc->rdc_tag;
- rc = retcode_entry_response( op, rs, rs->sr_entry );
+ if ( op->o_tag == LDAP_REQ_SEARCH ) {
+ rs->sr_attrs = rdc->rdc_attrs;
+ }
+ rc = retcode_entry_response( op, rs, rdc->rdc_info, rs->sr_entry );
op->o_tag = o_tag;
return rc;
}
- if ( rs->sr_err == LDAP_SUCCESS ) {
- rdc->rdc_flags = SLAP_CB_CONTINUE;
+ switch ( rs->sr_err ) {
+ case LDAP_SUCCESS:
+ case LDAP_NO_SUCH_OBJECT:
+ /* in case of noSuchObject, stop the internal search
+ * for in-directory error stuff */
+ if ( !op->o_abandon ) {
+ rdc->rdc_flags = SLAP_CB_CONTINUE;
+ }
+ return 0;
}
- return 0;
+ return SLAP_CB_CONTINUE;
}
static int
slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
Operation op2 = *op;
- SlapReply rs2 = { 0 };
BackendDB db = *op->o_bd;
slap_callback sc = { 0 };
retcode_cb_t rdc;
op2.ors_attrsonly = 0;
op2.ors_attrs = slap_anlist_all_attributes;
- ber_str2bv_x( "(objectClass=errObject)", STRLENOF( "(objectClass=errObject)" ),
+ ber_str2bv_x( "(objectClass=errAbsObject)",
+ STRLENOF( "(objectClass=errAbsObject)" ),
1, &op2.ors_filterstr, op2.o_tmpmemctx );
op2.ors_filter = str2filter_x( &op2, op2.ors_filterstr.bv_val );
+ /* errAbsObject is defined by this overlay! */
+ assert( op2.ors_filter != NULL );
+
db.bd_info = on->on_info->oi_orig;
op2.o_bd = &db;
+ rdc.rdc_info = on->on_info->oi_orig;
rdc.rdc_flags = RETCODE_FINDIR;
+ if ( op->o_tag == LDAP_REQ_SEARCH ) {
+ rdc.rdc_attrs = op->ors_attrs;
+ }
rdc.rdc_tag = op->o_tag;
sc.sc_response = retcode_cb_response;
sc.sc_private = &rdc;
op2.o_callback = ≻
- rc = op2.o_bd->be_search( &op2, &rs2 );
+ rc = op2.o_bd->be_search( &op2, rs );
+ op->o_abandon = op2.o_abandon;
- filter_free_x( &op2, op2.ors_filter );
+ filter_free_x( &op2, op2.ors_filter, 1 );
ber_memfree_x( op2.ors_filterstr.bv_val, op2.o_tmpmemctx );
if ( rdc.rdc_flags == SLAP_CB_CONTINUE ) {
slap_callback *cb = NULL;
+ /* sleep as required */
+ retcode_sleep( rd->rd_sleep );
+
if ( !dnIsSuffix( &op->o_req_ndn, &rd->rd_npdn ) ) {
if ( RETCODE_INDIR( rd ) ) {
switch ( op->o_tag ) {
case LDAP_REQ_ADD:
return retcode_op_add( op, rs );
- case LDAP_REQ_MODIFY:
case LDAP_REQ_BIND:
+ /* skip if rootdn */
+ /* FIXME: better give the db a chance? */
+ if ( be_isroot_pw( op ) ) {
+ return LDAP_SUCCESS;
+ }
+ return retcode_op_internal( op, rs );
+
+ case LDAP_REQ_SEARCH:
+ if ( op->ors_scope == LDAP_SCOPE_BASE ) {
+ rs->sr_err = retcode_op_internal( op, rs );
+ switch ( rs->sr_err ) {
+ case SLAP_CB_CONTINUE:
+ if ( rs->sr_nentries == 0 ) {
+ break;
+ }
+ rs->sr_err = LDAP_SUCCESS;
+ /* fallthru */
+
+ default:
+ send_ldap_result( op, rs );
+ break;
+ }
+ return rs->sr_err;
+ }
+ break;
+
+ case LDAP_REQ_MODIFY:
case LDAP_REQ_DELETE:
case LDAP_REQ_MODRDN:
case LDAP_REQ_COMPARE:
- case LDAP_REQ_SEARCH:
return retcode_op_internal( op, rs );
}
}
rs->sr_text = "retcode not found";
} else {
+ if ( rdi->rdi_flags & RDI_PRE_DISCONNECT ) {
+ return rs->sr_err = SLAPD_DISCONNECT;
+ }
+
rs->sr_err = rdi->rdi_err;
rs->sr_text = rdi->rdi_text.bv_val;
+ rs->sr_matched = rdi->rdi_matched.bv_val;
/* FIXME: we only honor the rdi_ref field in case rdi_err
* is LDAP_REFERRAL otherwise send_ldap_result() bails out */
if ( rdi->rdi_ref != NULL ) {
ref = rdi->rdi_ref;
-
- } else if ( default_referral != NULL ) {
+ } else {
ref = default_referral;
}
}
}
- if ( rdi->rdi_sleeptime > 0 ) {
- sleep( rdi->rdi_sleeptime );
- }
+ retcode_sleep( rdi->rdi_sleeptime );
}
switch ( op->o_tag ) {
break;
default:
- send_ldap_result( op, rs );
+ if ( rdi && !BER_BVISNULL( &rdi->rdi_unsolicited_oid ) ) {
+ ber_int_t msgid = op->o_msgid;
+
+ /* RFC 4511 unsolicited response */
+
+ op->o_msgid = 0;
+ if ( strcmp( rdi->rdi_unsolicited_oid.bv_val, "0" ) == 0 ) {
+ send_ldap_result( op, rs );
+
+ } else {
+ ber_tag_t tag = op->o_tag;
+
+ op->o_tag = LDAP_REQ_EXTENDED;
+ rs->sr_rspoid = rdi->rdi_unsolicited_oid.bv_val;
+ if ( !BER_BVISNULL( &rdi->rdi_unsolicited_data ) ) {
+ rs->sr_rspdata = &rdi->rdi_unsolicited_data;
+ }
+ send_ldap_extended( op, rs );
+ rs->sr_rspoid = NULL;
+ rs->sr_rspdata = NULL;
+ op->o_tag = tag;
+
+ }
+ op->o_msgid = msgid;
+
+ } else {
+ send_ldap_result( op, rs );
+ }
+
if ( rs->sr_ref != NULL ) {
ber_bvarray_free( rs->sr_ref );
+ rs->sr_ref = NULL;
}
rs->sr_matched = NULL;
rs->sr_text = NULL;
+
+ if ( rdi && rdi->rdi_flags & RDI_POST_DISCONNECT ) {
+ return rs->sr_err = SLAPD_DISCONNECT;
+ }
break;
}
}
static int
-retcode_entry_response( Operation *op, SlapReply *rs, Entry *e )
+retcode_entry_response( Operation *op, SlapReply *rs, BackendInfo *bi, Entry *e )
{
- slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
-
Attribute *a;
int err;
char *next;
+ int disconnect = 0;
if ( get_manageDSAit( op ) ) {
return SLAP_CB_CONTINUE;
}
- if ( !is_entry_objectclass( e, oc_errObject, 0 ) ) {
+ if ( !is_entry_objectclass_or_sub( e, oc_errAbsObject ) ) {
return SLAP_CB_CONTINUE;
}
}
}
+ /* disconnect */
+ a = attr_find( e->e_attrs, ad_errDisconnect );
+ if ( a != NULL ) {
+ if ( bvmatch( &a->a_nvals[ 0 ], &slap_true_bv ) ) {
+ return rs->sr_err = SLAPD_DISCONNECT;
+ }
+ disconnect = 1;
+ }
+
/* error code */
a = attr_find( e->e_attrs, ad_errCode );
if ( a == NULL ) {
/* sleep time */
a = attr_find( e->e_attrs, ad_errSleepTime );
- if ( a != NULL ) {
+ if ( a != NULL && a->a_nvals[ 0 ].bv_val[ 0 ] != '-' ) {
int sleepTime;
- sleepTime = strtoul( a->a_nvals[ 0 ].bv_val, &next, 0 );
- if ( next != a->a_nvals[ 0 ].bv_val && next[ 0 ] == '\0' ) {
- sleep( sleepTime );
+ if ( lutil_atoi( &sleepTime, a->a_nvals[ 0 ].bv_val ) == 0 ) {
+ retcode_sleep( sleepTime );
}
}
- if ( rs->sr_err != LDAP_SUCCESS ) {
- BackendDB db = *op->o_bd;
+ if ( rs->sr_err != LDAP_SUCCESS && !LDAP_API_ERROR( rs->sr_err )) {
+ BackendDB db = *op->o_bd,
+ *o_bd = op->o_bd;
void *o_callback = op->o_callback;
/* message text */
rs->sr_text = a->a_vals[ 0 ].bv_val;
}
- db.bd_info = on->on_info->oi_orig;
+ /* matched DN */
+ a = attr_find( e->e_attrs, ad_errMatchedDN );
+ if ( a != NULL ) {
+ rs->sr_matched = a->a_vals[ 0 ].bv_val;
+ }
+
+ if ( bi == NULL ) {
+ slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
+
+ bi = on->on_info->oi_orig;
+ }
+
+ db.bd_info = bi;
op->o_bd = &db;
op->o_callback = NULL;
rs->sr_ref = NULL;
} else {
- send_ldap_result( op, rs );
+ a = attr_find( e->e_attrs, ad_errUnsolicitedOID );
+ if ( a != NULL ) {
+ struct berval oid = BER_BVNULL,
+ data = BER_BVNULL;
+ ber_int_t msgid = op->o_msgid;
+
+ /* RFC 4511 unsolicited response */
+
+ op->o_msgid = 0;
+
+ oid = a->a_nvals[ 0 ];
+
+ a = attr_find( e->e_attrs, ad_errUnsolicitedData );
+ if ( a != NULL ) {
+ data = a->a_nvals[ 0 ];
+ }
+
+ if ( strcmp( oid.bv_val, "0" ) == 0 ) {
+ send_ldap_result( op, rs );
+
+ } else {
+ ber_tag_t tag = op->o_tag;
+
+ op->o_tag = LDAP_REQ_EXTENDED;
+ rs->sr_rspoid = oid.bv_val;
+ if ( !BER_BVISNULL( &data ) ) {
+ rs->sr_rspdata = &data;
+ }
+ send_ldap_extended( op, rs );
+ rs->sr_rspoid = NULL;
+ rs->sr_rspdata = NULL;
+ op->o_tag = tag;
+ }
+ op->o_msgid = msgid;
+
+ } else {
+ send_ldap_result( op, rs );
+ }
}
rs->sr_text = NULL;
+ rs->sr_matched = NULL;
+ op->o_bd = o_bd;
op->o_callback = o_callback;
}
-
+
if ( rs->sr_err != LDAP_SUCCESS ) {
+ if ( disconnect ) {
+ return rs->sr_err = SLAPD_DISCONNECT;
+ }
+
op->o_abandon = 1;
return rs->sr_err;
}
return SLAP_CB_CONTINUE;
}
- return retcode_entry_response( op, rs, rs->sr_entry );
+ return retcode_entry_response( op, rs, NULL, rs->sr_entry );
}
static int
-retcode_db_init( BackendDB *be )
+retcode_db_init( BackendDB *be, ConfigReply *cr )
{
slap_overinst *on = (slap_overinst *)be->bd_info;
retcode_t *rd;
+ srand( getpid() );
+
rd = (retcode_t *)ch_malloc( sizeof( retcode_t ) );
memset( rd, 0, sizeof( retcode_t ) );
return 0;
}
-static int
-retcode_db_config(
- BackendDB *be,
- const char *fname,
- int lineno,
- int argc,
- char **argv )
+static void
+retcode_item_destroy( retcode_item_t *rdi )
{
- slap_overinst *on = (slap_overinst *)be->bd_info;
- retcode_t *rd = (retcode_t *)on->on_bi.bi_private;
+ ber_memfree( rdi->rdi_line.bv_val );
- char *argv0 = argv[ 0 ] + STRLENOF( "retcode-" );
+ ber_memfree( rdi->rdi_dn.bv_val );
+ ber_memfree( rdi->rdi_ndn.bv_val );
- if ( strncasecmp( argv[ 0 ], "retcode-", STRLENOF( "retcode-" ) ) != 0 ) {
- return SLAP_CONF_UNKNOWN;
+ if ( !BER_BVISNULL( &rdi->rdi_text ) ) {
+ ber_memfree( rdi->rdi_text.bv_val );
}
- if ( strcasecmp( argv0, "parent" ) == 0 ) {
- struct berval dn;
- int rc;
+ if ( !BER_BVISNULL( &rdi->rdi_matched ) ) {
+ ber_memfree( rdi->rdi_matched.bv_val );
+ }
- if ( argc != 2 ) {
- fprintf( stderr, "%s: line %d: retcode: "
- "\"retcode-parent <DN>\": missing <DN>\n",
- fname, lineno );
- return 1;
- }
+ if ( rdi->rdi_ref ) {
+ ber_bvarray_free( rdi->rdi_ref );
+ }
- if ( !BER_BVISNULL( &rd->rd_pdn ) ) {
- fprintf( stderr, "%s: line %d: retcode: "
- "parent already defined.\n", fname, lineno );
- return 1;
+ BER_BVZERO( &rdi->rdi_e.e_name );
+ BER_BVZERO( &rdi->rdi_e.e_nname );
+
+ entry_clean( &rdi->rdi_e );
+
+ ch_free( rdi );
+}
+
+enum {
+ RC_PARENT = 1,
+ RC_ITEM
+};
+
+static ConfigDriver rc_cf_gen;
+
+static ConfigTable rccfg[] = {
+ { "retcode-parent", "dn",
+ 2, 2, 0, ARG_MAGIC|ARG_DN|RC_PARENT, rc_cf_gen,
+ "( OLcfgOvAt:20.1 NAME 'olcRetcodeParent' "
+ "DESC '' "
+ "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
+ { "retcode-item", "rdn> <retcode> <...",
+ 3, 0, 0, ARG_MAGIC|RC_ITEM, rc_cf_gen,
+ "( OLcfgOvAt:20.2 NAME 'olcRetcodeItem' "
+ "DESC '' "
+ "EQUALITY caseIgnoreMatch "
+ "SYNTAX OMsDirectoryString "
+ "X-ORDERED 'VALUES' )", NULL, NULL },
+ { "retcode-indir", "on|off",
+ 1, 2, 0, ARG_OFFSET|ARG_ON_OFF,
+ (void *)offsetof(retcode_t, rd_indir),
+ "( OLcfgOvAt:20.3 NAME 'olcRetcodeInDir' "
+ "DESC '' "
+ "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
+
+ { "retcode-sleep", "sleeptime",
+ 2, 2, 0, ARG_OFFSET|ARG_INT,
+ (void *)offsetof(retcode_t, rd_sleep),
+ "( OLcfgOvAt:20.4 NAME 'olcRetcodeSleep' "
+ "DESC '' "
+ "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
+
+ { NULL, NULL, 0, 0, 0, ARG_IGNORED }
+};
+
+static ConfigOCs rcocs[] = {
+ { "( OLcfgOvOc:20.1 "
+ "NAME 'olcRetcodeConfig' "
+ "DESC 'Retcode configuration' "
+ "SUP olcOverlayConfig "
+ "MAY ( olcRetcodeParent "
+ "$ olcRetcodeItem "
+ "$ olcRetcodeInDir "
+ "$ olcRetcodeSleep "
+ ") )",
+ Cft_Overlay, rccfg, NULL, NULL },
+ { NULL, 0, NULL }
+};
+
+static int
+rc_cf_gen( ConfigArgs *c )
+{
+ slap_overinst *on = (slap_overinst *)c->bi;
+ retcode_t *rd = (retcode_t *)on->on_bi.bi_private;
+ int rc = ARG_BAD_CONF;
+
+ if ( c->op == SLAP_CONFIG_EMIT ) {
+ switch( c->type ) {
+ case RC_PARENT:
+ if ( !BER_BVISEMPTY( &rd->rd_pdn )) {
+ rc = value_add_one( &c->rvalue_vals,
+ &rd->rd_pdn );
+ if ( rc == 0 ) {
+ rc = value_add_one( &c->rvalue_nvals,
+ &rd->rd_npdn );
+ }
+ return rc;
+ }
+ rc = 0;
+ break;
+
+ case RC_ITEM: {
+ retcode_item_t *rdi;
+ int i;
+
+ for ( rdi = rd->rd_item, i = 0; rdi; rdi = rdi->rdi_next, i++ ) {
+ char buf[4096];
+ struct berval bv;
+ char *ptr;
+
+ bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
+ bv.bv_len += rdi->rdi_line.bv_len;
+ ptr = bv.bv_val = ch_malloc( bv.bv_len + 1 );
+ ptr = lutil_strcopy( ptr, buf );
+ ptr = lutil_strncopy( ptr, rdi->rdi_line.bv_val, rdi->rdi_line.bv_len );
+ ber_bvarray_add( &c->rvalue_vals, &bv );
+ }
+ rc = 0;
+ } break;
+
+ default:
+ assert( 0 );
+ break;
}
- ber_str2bv( argv[ 1 ], 0, 0, &dn );
+ return rc;
- rc = dnPrettyNormal( NULL, &dn, &rd->rd_pdn, &rd->rd_npdn, NULL );
- if ( rc != LDAP_SUCCESS ) {
- fprintf( stderr, "%s: line %d: retcode: "
- "unable to normalize parent DN \"%s\": %d\n",
- fname, lineno, argv[ 1 ], rc );
- return 1;
+ } else if ( c->op == LDAP_MOD_DELETE ) {
+ switch( c->type ) {
+ case RC_PARENT:
+ if ( rd->rd_pdn.bv_val ) {
+ ber_memfree ( rd->rd_pdn.bv_val );
+ rc = 0;
+ }
+ if ( rd->rd_npdn.bv_val ) {
+ ber_memfree ( rd->rd_npdn.bv_val );
+ }
+ break;
+
+ case RC_ITEM:
+ if ( c->valx == -1 ) {
+ retcode_item_t *rdi, *next;
+
+ for ( rdi = rd->rd_item; rdi != NULL; rdi = next ) {
+ next = rdi->rdi_next;
+ retcode_item_destroy( rdi );
+ }
+
+ } else {
+ retcode_item_t **rdip, *rdi;
+ int i;
+
+ for ( rdip = &rd->rd_item, i = 0; i <= c->valx && *rdip; i++, rdip = &(*rdip)->rdi_next )
+ ;
+ if ( *rdip == NULL ) {
+ return 1;
+ }
+ rdi = *rdip;
+ *rdip = rdi->rdi_next;
+
+ retcode_item_destroy( rdi );
+ }
+ rc = 0;
+ break;
+
+ default:
+ assert( 0 );
+ break;
}
+ return rc; /* FIXME */
+ }
- } else if ( strcasecmp( argv0, "item" ) == 0 ) {
+ switch( c->type ) {
+ case RC_PARENT:
+ if ( rd->rd_pdn.bv_val ) {
+ ber_memfree ( rd->rd_pdn.bv_val );
+ }
+ if ( rd->rd_npdn.bv_val ) {
+ ber_memfree ( rd->rd_npdn.bv_val );
+ }
+ rd->rd_pdn = c->value_dn;
+ rd->rd_npdn = c->value_ndn;
+ rc = 0;
+ break;
+
+ case RC_ITEM: {
retcode_item_t rdi = { BER_BVNULL }, **rdip;
struct berval bv, rdn, nrdn;
- int rc;
char *next = NULL;
+ int i;
- if ( argc < 3 ) {
- fprintf( stderr, "%s: line %d: retcode: "
+ if ( c->argc < 3 ) {
+ snprintf( c->cr_msg, sizeof(c->cr_msg),
"\"retcode-item <RDN> <retcode> [<text>]\": "
- "missing args\n",
- fname, lineno, argv[ 1 ] );
- return 1;
+ "missing args" );
+ Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
+ c->log, c->cr_msg, 0 );
+ return ARG_BAD_CONF;
}
- ber_str2bv( argv[ 1 ], 0, 0, &bv );
+ ber_str2bv( c->argv[ 1 ], 0, 0, &bv );
rc = dnPrettyNormal( NULL, &bv, &rdn, &nrdn, NULL );
if ( rc != LDAP_SUCCESS ) {
- fprintf( stderr, "%s: line %d: retcode: "
- "unable to normalize RDN \"%s\": %d\n",
- fname, lineno, argv[ 1 ], rc );
- return 1;
+ snprintf( c->cr_msg, sizeof(c->cr_msg),
+ "unable to normalize RDN \"%s\": %d",
+ c->argv[ 1 ], rc );
+ Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
+ c->log, c->cr_msg, 0 );
+ return ARG_BAD_CONF;
}
if ( !dnIsOneLevelRDN( &nrdn ) ) {
- fprintf( stderr, "%s: line %d: retcode: "
- "value \"%s\" is not a RDN\n",
- fname, lineno, argv[ 1 ] );
- return 1;
+ snprintf( c->cr_msg, sizeof(c->cr_msg),
+ "value \"%s\" is not a RDN",
+ c->argv[ 1 ] );
+ Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
+ c->log, c->cr_msg, 0 );
+ return ARG_BAD_CONF;
}
if ( BER_BVISNULL( &rd->rd_npdn ) ) {
/* FIXME: we use the database suffix */
- if ( be->be_nsuffix == NULL ) {
- fprintf( stderr, "%s: line %d: retcode: "
+ if ( c->be->be_nsuffix == NULL ) {
+ snprintf( c->cr_msg, sizeof(c->cr_msg),
"either \"retcode-parent\" "
- "or \"suffix\" must be defined.\n",
- fname, lineno );
- return 1;
+ "or \"suffix\" must be defined" );
+ Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
+ c->log, c->cr_msg, 0 );
+ return ARG_BAD_CONF;
}
- ber_dupbv( &rd->rd_pdn, &be->be_suffix[ 0 ] );
- ber_dupbv( &rd->rd_npdn, &be->be_nsuffix[ 0 ] );
+ ber_dupbv( &rd->rd_pdn, &c->be->be_suffix[ 0 ] );
+ ber_dupbv( &rd->rd_npdn, &c->be->be_nsuffix[ 0 ] );
}
build_new_dn( &rdi.rdi_dn, &rd->rd_pdn, &rdn, NULL );
ch_free( rdn.bv_val );
ch_free( nrdn.bv_val );
- rdi.rdi_err = strtol( argv[ 2 ], &next, 0 );
- if ( next == argv[ 2 ] || next[ 0 ] != '\0' ) {
- fprintf( stderr, "%s: line %d: retcode: "
- "unable to parse return code \"%s\"\n",
- fname, lineno, argv[ 2 ] );
- return 1;
+ rdi.rdi_err = strtol( c->argv[ 2 ], &next, 0 );
+ if ( next == c->argv[ 2 ] || next[ 0 ] != '\0' ) {
+ snprintf( c->cr_msg, sizeof(c->cr_msg),
+ "unable to parse return code \"%s\"",
+ c->argv[ 2 ] );
+ Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
+ c->log, c->cr_msg, 0 );
+ return ARG_BAD_CONF;
}
rdi.rdi_mask = SN_DG_OP_ALL;
- if ( argc > 3 ) {
- int i;
-
- for ( i = 3; i < argc; i++ ) {
- if ( strncasecmp( argv[ i ], "op=", STRLENOF( "op=" ) ) == 0 )
+ if ( c->argc > 3 ) {
+ for ( i = 3; i < c->argc; i++ ) {
+ if ( strncasecmp( c->argv[ i ], "op=", STRLENOF( "op=" ) ) == 0 )
{
char **ops;
int j;
- ops = ldap_str2charray( &argv[ i ][ STRLENOF( "op=" ) ], "," );
+ ops = ldap_str2charray( &c->argv[ i ][ STRLENOF( "op=" ) ], "," );
assert( ops != NULL );
rdi.rdi_mask = SN_DG_OP_NONE;
} else if ( strcasecmp( ops[ j ], "compare" ) == 0 ) {
rdi.rdi_mask |= SN_DG_OP_COMPARE;
- } else if ( strcasecmp( ops[ j ], "add" ) == 0 ) {
+ } else if ( strcasecmp( ops[ j ], "delete" ) == 0 ) {
rdi.rdi_mask |= SN_DG_OP_DELETE;
} else if ( strcasecmp( ops[ j ], "modify" ) == 0 ) {
rdi.rdi_mask |= SN_DG_OP_MODIFY;
- } else if ( strcasecmp( ops[ j ], "rename" ) == 0 ) {
+ } else if ( strcasecmp( ops[ j ], "rename" ) == 0
+ || strcasecmp( ops[ j ], "modrdn" ) == 0 )
+ {
rdi.rdi_mask |= SN_DG_OP_RENAME;
} else if ( strcasecmp( ops[ j ], "search" ) == 0 ) {
rdi.rdi_mask |= SN_DG_OP_ALL;
} else {
- fprintf( stderr, "retcode: unknown op \"%s\"\n",
+ snprintf( c->cr_msg, sizeof(c->cr_msg),
+ "unknown op \"%s\"",
ops[ j ] );
- return 1;
+ ldap_charray_free( ops );
+ Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
+ c->log, c->cr_msg, 0 );
+ return ARG_BAD_CONF;
}
}
ldap_charray_free( ops );
- } else if ( strncasecmp( argv[ i ], "text=", STRLENOF( "text=" ) ) == 0 )
+ } else if ( strncasecmp( c->argv[ i ], "text=", STRLENOF( "text=" ) ) == 0 )
{
if ( !BER_BVISNULL( &rdi.rdi_text ) ) {
- fprintf( stderr, "%s: line %d: retcode: "
- "\"text\" already provided.\n",
- fname, lineno );
- return 1;
+ snprintf( c->cr_msg, sizeof(c->cr_msg),
+ "\"text\" already provided" );
+ Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
+ c->log, c->cr_msg, 0 );
+ return ARG_BAD_CONF;
+ }
+ ber_str2bv( &c->argv[ i ][ STRLENOF( "text=" ) ], 0, 1, &rdi.rdi_text );
+
+ } else if ( strncasecmp( c->argv[ i ], "matched=", STRLENOF( "matched=" ) ) == 0 )
+ {
+ struct berval dn;
+
+ if ( !BER_BVISNULL( &rdi.rdi_matched ) ) {
+ snprintf( c->cr_msg, sizeof(c->cr_msg),
+ "\"matched\" already provided" );
+ Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
+ c->log, c->cr_msg, 0 );
+ return ARG_BAD_CONF;
+ }
+ ber_str2bv( &c->argv[ i ][ STRLENOF( "matched=" ) ], 0, 0, &dn );
+ if ( dnPretty( NULL, &dn, &rdi.rdi_matched, NULL ) != LDAP_SUCCESS ) {
+ snprintf( c->cr_msg, sizeof(c->cr_msg),
+ "unable to prettify matched DN \"%s\"",
+ &c->argv[ i ][ STRLENOF( "matched=" ) ] );
+ Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
+ c->log, c->cr_msg, 0 );
+ return ARG_BAD_CONF;
}
- ber_str2bv( &argv[ i ][ STRLENOF( "text=" ) ], 0, 1, &rdi.rdi_text );
- } else if ( strncasecmp( argv[ i ], "ref=", STRLENOF( "ref=" ) ) == 0 )
+ } else if ( strncasecmp( c->argv[ i ], "ref=", STRLENOF( "ref=" ) ) == 0 )
{
char **refs;
int j;
if ( rdi.rdi_ref != NULL ) {
- fprintf( stderr, "%s: line %d: retcode: "
- "\"ref\" already provided.\n",
- fname, lineno );
- return 1;
+ snprintf( c->cr_msg, sizeof(c->cr_msg),
+ "\"ref\" already provided" );
+ Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
+ c->log, c->cr_msg, 0 );
+ return ARG_BAD_CONF;
}
if ( rdi.rdi_err != LDAP_REFERRAL ) {
- fprintf( stderr, "%s: line %d: retcode: "
- "providing \"ref\"\n"
- "\talong with a non-referral "
- "resultCode may cause slapd failures\n"
- "\trelated to internal checks.\n",
- fname, lineno );
+ snprintf( c->cr_msg, sizeof(c->cr_msg),
+ "providing \"ref\" "
+ "along with a non-referral "
+ "resultCode may cause slapd failures "
+ "related to internal checks" );
+ Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
+ c->log, c->cr_msg, 0 );
}
- refs = ldap_str2charray( &argv[ i ][ STRLENOF( "ref=" ) ], " " );
+ refs = ldap_str2charray( &c->argv[ i ][ STRLENOF( "ref=" ) ], " " );
assert( refs != NULL );
for ( j = 0; refs[ j ] != NULL; j++ ) {
ldap_charray_free( refs );
- } else if ( strncasecmp( argv[ i ], "sleeptime=", STRLENOF( "sleeptime=" ) ) == 0 )
+ } else if ( strncasecmp( c->argv[ i ], "sleeptime=", STRLENOF( "sleeptime=" ) ) == 0 )
{
- char *next;
if ( rdi.rdi_sleeptime != 0 ) {
- fprintf( stderr, "%s: line %d: retcode: "
- "\"sleeptime\" already provided.\n",
- fname, lineno );
- return 1;
+ snprintf( c->cr_msg, sizeof(c->cr_msg),
+ "\"sleeptime\" already provided" );
+ Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
+ c->log, c->cr_msg, 0 );
+ return ARG_BAD_CONF;
+ }
+
+ if ( lutil_atoi( &rdi.rdi_sleeptime, &c->argv[ i ][ STRLENOF( "sleeptime=" ) ] ) ) {
+ snprintf( c->cr_msg, sizeof(c->cr_msg),
+ "unable to parse \"sleeptime=%s\"",
+ &c->argv[ i ][ STRLENOF( "sleeptime=" ) ] );
+ Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
+ c->log, c->cr_msg, 0 );
+ return ARG_BAD_CONF;
+ }
+
+ } else if ( strncasecmp( c->argv[ i ], "unsolicited=", STRLENOF( "unsolicited=" ) ) == 0 )
+ {
+ char *data;
+
+ if ( !BER_BVISNULL( &rdi.rdi_unsolicited_oid ) ) {
+ snprintf( c->cr_msg, sizeof(c->cr_msg),
+ "\"unsolicited\" already provided" );
+ Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
+ c->log, c->cr_msg, 0 );
+ return ARG_BAD_CONF;
}
- rdi.rdi_sleeptime = strtol( &argv[ i ][ STRLENOF( "sleeptime=" ) ], &next, 10 );
- if ( next == argv[ i ] || next[ 0 ] != '\0' ) {
- fprintf( stderr, "%s: line %d: retcode: "
- "unable to parse \"sleeptime=%s\".\n",
- fname, lineno, &argv[ i ][ STRLENOF( "sleeptime=" ) ] );
- return 1;
+ data = strchr( &c->argv[ i ][ STRLENOF( "unsolicited=" ) ], ':' );
+ if ( data != NULL ) {
+ struct berval oid;
+
+ if ( ldif_parse_line2( &c->argv[ i ][ STRLENOF( "unsolicited=" ) ],
+ &oid, &rdi.rdi_unsolicited_data, NULL ) )
+ {
+ snprintf( c->cr_msg, sizeof(c->cr_msg),
+ "unable to parse \"unsolicited\"" );
+ Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
+ c->log, c->cr_msg, 0 );
+ return ARG_BAD_CONF;
+ }
+
+ ber_dupbv( &rdi.rdi_unsolicited_oid, &oid );
+
+ } else {
+ ber_str2bv( &c->argv[ i ][ STRLENOF( "unsolicited=" ) ], 0, 1,
+ &rdi.rdi_unsolicited_oid );
+ }
+
+ } else if ( strncasecmp( c->argv[ i ], "flags=", STRLENOF( "flags=" ) ) == 0 )
+ {
+ char *arg = &c->argv[ i ][ STRLENOF( "flags=" ) ];
+ if ( strcasecmp( arg, "disconnect" ) == 0 ) {
+ rdi.rdi_flags |= RDI_PRE_DISCONNECT;
+
+ } else if ( strcasecmp( arg, "pre-disconnect" ) == 0 ) {
+ rdi.rdi_flags |= RDI_PRE_DISCONNECT;
+
+ } else if ( strcasecmp( arg, "post-disconnect" ) == 0 ) {
+ rdi.rdi_flags |= RDI_POST_DISCONNECT;
+
+ } else {
+ snprintf( c->cr_msg, sizeof(c->cr_msg),
+ "unknown flag \"%s\"", arg );
+ Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
+ c->log, c->cr_msg, 0 );
+ return ARG_BAD_CONF;
}
} else {
- fprintf( stderr, "%s: line %d: retcode: "
- "unknown option \"%s\".\n",
- fname, lineno, argv[ i ] );
- return 1;
+ snprintf( c->cr_msg, sizeof(c->cr_msg),
+ "unknown option \"%s\"",
+ c->argv[ i ] );
+ Debug( LDAP_DEBUG_CONFIG, "%s: retcode: %s\n",
+ c->log, c->cr_msg, 0 );
+ return ARG_BAD_CONF;
}
}
}
+ rdi.rdi_line.bv_len = 2*(c->argc - 1) + c->argc - 2;
+ for ( i = 1; i < c->argc; i++ ) {
+ rdi.rdi_line.bv_len += strlen( c->argv[ i ] );
+ }
+ next = rdi.rdi_line.bv_val = ch_malloc( rdi.rdi_line.bv_len + 1 );
+
+ for ( i = 1; i < c->argc; i++ ) {
+ *next++ = '"';
+ next = lutil_strcopy( next, c->argv[ i ] );
+ *next++ = '"';
+ *next++ = ' ';
+ }
+ *--next = '\0';
+
for ( rdip = &rd->rd_item; *rdip; rdip = &(*rdip)->rdi_next )
/* go to last */ ;
*rdip = ( retcode_item_t * )ch_malloc( sizeof( retcode_item_t ) );
*(*rdip) = rdi;
- } else if ( strcasecmp( argv0, "indir" ) == 0 ) {
- rd->rd_flags |= RETCODE_FINDIR;
+ rc = 0;
+ } break;
- } else {
- return SLAP_CONF_UNKNOWN;
+ default:
+ rc = SLAP_CONF_UNKNOWN;
+ break;
}
- return 0;
+ return rc;
}
static int
-retcode_db_open( BackendDB *be )
+retcode_db_open( BackendDB *be, ConfigReply *cr)
{
slap_overinst *on = (slap_overinst *)be->bd_info;
retcode_t *rd = (retcode_t *)on->on_bi.bi_private;
attr_merge_normalize_one( &rdi->rdi_e, ad_errText, &val[ 0 ], NULL );
}
+ /* matched */
+ if ( !BER_BVISNULL( &rdi->rdi_matched ) ) {
+ val[ 0 ] = rdi->rdi_matched;
+
+ attr_merge_normalize_one( &rdi->rdi_e, ad_errMatchedDN, &val[ 0 ], NULL );
+ }
+
/* sleep time */
- if ( rdi->rdi_sleeptime > 0 ) {
+ if ( rdi->rdi_sleeptime ) {
snprintf( buf, sizeof( buf ), "%d", rdi->rdi_sleeptime );
ber_str2bv( buf, 0, 0, &val[ 0 ] );
}
static int
-retcode_db_destroy( BackendDB *be )
+retcode_db_destroy( BackendDB *be, ConfigReply *cr )
{
slap_overinst *on = (slap_overinst *)be->bd_info;
retcode_t *rd = (retcode_t *)on->on_bi.bi_private;
retcode_item_t *rdi, *next;
for ( rdi = rd->rd_item; rdi != NULL; rdi = next ) {
- ber_memfree( rdi->rdi_dn.bv_val );
- ber_memfree( rdi->rdi_ndn.bv_val );
-
- if ( !BER_BVISNULL( &rdi->rdi_text ) ) {
- ber_memfree( rdi->rdi_text.bv_val );
- }
-
- BER_BVZERO( &rdi->rdi_e.e_name );
- BER_BVZERO( &rdi->rdi_e.e_nname );
-
- entry_clean( &rdi->rdi_e );
-
next = rdi->rdi_next;
+ retcode_item_destroy( rdi );
+ }
+
+ if ( !BER_BVISNULL( &rd->rd_pdn ) ) {
+ ber_memfree( rd->rd_pdn.bv_val );
+ }
- ch_free( rdi );
+ if ( !BER_BVISNULL( &rd->rd_npdn ) ) {
+ ber_memfree( rd->rd_npdn.bv_val );
}
ber_memfree( rd );
static
#endif /* SLAPD_OVER_RETCODE == SLAPD_MOD_DYNAMIC */
int
-retcode_init( void )
+retcode_initialize( void )
{
int i, code;
- const char *err;
static struct {
- char *name;
char *desc;
AttributeDescription **ad;
} retcode_at[] = {
- { "errCode", "( 1.3.6.1.4.1.4203.666.11.4.1.1 "
+ { "( 1.3.6.1.4.1.4203.666.11.4.1.1 "
"NAME ( 'errCode' ) "
"DESC 'LDAP error code' "
"EQUALITY integerMatch "
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
"SINGLE-VALUE )",
&ad_errCode },
- { "errOp", "( 1.3.6.1.4.1.4203.666.11.4.1.2 "
+ { "( 1.3.6.1.4.1.4203.666.11.4.1.2 "
"NAME ( 'errOp' ) "
"DESC 'Operations the errObject applies to' "
"EQUALITY caseIgnoreMatch "
"SUBSTR caseIgnoreSubstringsMatch "
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
&ad_errOp},
- { "errText", "( 1.3.6.1.4.1.4203.666.11.4.1.3 "
+ { "( 1.3.6.1.4.1.4203.666.11.4.1.3 "
"NAME ( 'errText' ) "
"DESC 'LDAP error textual description' "
"EQUALITY caseIgnoreMatch "
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
"SINGLE-VALUE )",
&ad_errText },
- { "errSleepTime", "( 1.3.6.1.4.1.4203.666.11.4.1.4 "
+ { "( 1.3.6.1.4.1.4203.666.11.4.1.4 "
"NAME ( 'errSleepTime' ) "
"DESC 'Time to wait before returning the error' "
"EQUALITY integerMatch "
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
"SINGLE-VALUE )",
&ad_errSleepTime },
+ { "( 1.3.6.1.4.1.4203.666.11.4.1.5 "
+ "NAME ( 'errMatchedDN' ) "
+ "DESC 'Value to be returned as matched DN' "
+ "EQUALITY distinguishedNameMatch "
+ "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
+ "SINGLE-VALUE )",
+ &ad_errMatchedDN },
+ { "( 1.3.6.1.4.1.4203.666.11.4.1.6 "
+ "NAME ( 'errUnsolicitedOID' ) "
+ "DESC 'OID to be returned within unsolicited response' "
+ "EQUALITY objectIdentifierMatch "
+ "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 "
+ "SINGLE-VALUE )",
+ &ad_errUnsolicitedOID },
+ { "( 1.3.6.1.4.1.4203.666.11.4.1.7 "
+ "NAME ( 'errUnsolicitedData' ) "
+ "DESC 'Data to be returned within unsolicited response' "
+ "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 "
+ "SINGLE-VALUE )",
+ &ad_errUnsolicitedData },
+ { "( 1.3.6.1.4.1.4203.666.11.4.1.8 "
+ "NAME ( 'errDisconnect' ) "
+ "DESC 'Disconnect without notice' "
+ "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
+ "SINGLE-VALUE )",
+ &ad_errDisconnect },
{ NULL }
};
static struct {
- char *name;
char *desc;
ObjectClass **oc;
} retcode_oc[] = {
- { "errObject", "( 1.3.6.1.4.1.4203.666.11.4.3.1 "
- "NAME ( 'errObject' ) "
- "SUP top STRUCTURAL "
+ { "( 1.3.6.1.4.1.4203.666.11.4.3.0 "
+ "NAME ( 'errAbsObject' ) "
+ "SUP top ABSTRACT "
"MUST ( errCode ) "
"MAY ( "
"cn "
"$ errOp "
"$ errText "
"$ errSleepTime "
+ "$ errMatchedDN "
+ "$ errUnsolicitedOID "
+ "$ errUnsolicitedData "
+ "$ errDisconnect "
") )",
+ &oc_errAbsObject },
+ { "( 1.3.6.1.4.1.4203.666.11.4.3.1 "
+ "NAME ( 'errObject' ) "
+ "SUP errAbsObject STRUCTURAL "
+ ")",
&oc_errObject },
+ { "( 1.3.6.1.4.1.4203.666.11.4.3.2 "
+ "NAME ( 'errAuxObject' ) "
+ "SUP errAbsObject AUXILIARY "
+ ")",
+ &oc_errAuxObject },
{ NULL }
};
- for ( i = 0; retcode_at[ i ].name != NULL; i++ ) {
- LDAPAttributeType *at;
-
- at = ldap_str2attributetype( retcode_at[ i ].desc,
- &code, &err, LDAP_SCHEMA_ALLOW_ALL );
- if ( !at ) {
- fprintf( stderr, "retcode: "
- "AttributeType load failed: %s %s\n",
- ldap_scherr2str( code ), err );
+ for ( i = 0; retcode_at[ i ].desc != NULL; i++ ) {
+ code = register_at( retcode_at[ i ].desc, retcode_at[ i ].ad, 0 );
+ if ( code ) {
+ Debug( LDAP_DEBUG_ANY,
+ "retcode: register_at failed\n", 0, 0, 0 );
return code;
}
-#if LDAP_VENDOR_VERSION_MINOR == X || LDAP_VENDOR_VERSION_MINOR > 2
- code = at_add( at, 0, NULL, &err );
-#else
- code = at_add( at, &err );
-#endif
- ldap_memfree( at );
- if ( code != LDAP_SUCCESS ) {
- fprintf( stderr, "retcode: "
- "AttributeType load failed: %s %s\n",
- scherr2str( code ), err );
- return code;
- }
-
- code = slap_str2ad( retcode_at[ i ].name,
- retcode_at[ i ].ad, &err );
- if ( code != LDAP_SUCCESS ) {
- fprintf( stderr, "retcode: unable to find "
- "AttributeDescription \"%s\": %d (%s)\n",
- retcode_at[ i ].name, code, err );
- return 1;
- }
+ (*retcode_at[ i ].ad)->ad_type->sat_flags |= SLAP_AT_HIDE;
}
- for ( i = 0; retcode_oc[ i ].name != NULL; i++ ) {
- LDAPObjectClass *oc;
-
- oc = ldap_str2objectclass( retcode_oc[ i ].desc,
- &code, &err, LDAP_SCHEMA_ALLOW_ALL );
- if ( !oc ) {
- fprintf( stderr, "retcode: "
- "ObjectClass load failed: %s %s\n",
- ldap_scherr2str( code ), err );
- return code;
- }
-
-#if LDAP_VENDOR_VERSION_MINOR == X || LDAP_VENDOR_VERSION_MINOR > 2
- code = oc_add( oc, 0, NULL, &err );
-#else
- code = oc_add( oc, &err );
-#endif
- ldap_memfree(oc);
- if ( code != LDAP_SUCCESS ) {
- fprintf( stderr, "retcode: "
- "ObjectClass load failed: %s %s\n",
- scherr2str( code ), err );
+ for ( i = 0; retcode_oc[ i ].desc != NULL; i++ ) {
+ code = register_oc( retcode_oc[ i ].desc, retcode_oc[ i ].oc, 0 );
+ if ( code ) {
+ Debug( LDAP_DEBUG_ANY,
+ "retcode: register_oc failed\n", 0, 0, 0 );
return code;
}
- *retcode_oc[ i ].oc = oc_find( retcode_oc[ i ].name );
- if ( *retcode_oc[ i ].oc == NULL ) {
- fprintf( stderr, "retcode: unable to find "
- "objectClass \"%s\"\n",
- retcode_oc[ i ].name );
- return 1;
- }
+ (*retcode_oc[ i ].oc)->soc_flags |= SLAP_OC_HIDE;
}
retcode.on_bi.bi_type = "retcode";
retcode.on_bi.bi_db_init = retcode_db_init;
- retcode.on_bi.bi_db_config = retcode_db_config;
retcode.on_bi.bi_db_open = retcode_db_open;
retcode.on_bi.bi_db_destroy = retcode_db_destroy;
retcode.on_response = retcode_response;
+ retcode.on_bi.bi_cf_ocs = rcocs;
+
+ code = config_register_schema( rccfg, rcocs );
+ if ( code ) {
+ return code;
+ }
+
return overlay_register( &retcode );
}
int
init_module( int argc, char *argv[] )
{
- return retcode_init();
+ return retcode_initialize();
}
#endif /* SLAPD_OVER_RETCODE == SLAPD_MOD_DYNAMIC */