Home | History | Annotate | Line # | Download | only in samba4
rdnval.c revision 1.2
      1 /*	$NetBSD: rdnval.c,v 1.2 2020/08/11 13:15:36 christos Exp $	*/
      2 
      3 /* rdnval.c - RDN value overlay */
      4 /* $OpenLDAP$ */
      5 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
      6  *
      7  * Copyright 1998-2020 The OpenLDAP Foundation.
      8  * Portions Copyright 2008 Pierangelo Masarati.
      9  * All rights reserved.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted only as authorized by the OpenLDAP
     13  * Public License.
     14  *
     15  * A copy of this license is available in the file LICENSE in the
     16  * top-level directory of the distribution or, alternatively, at
     17  * <http://www.OpenLDAP.org/license.html>.
     18  */
     19 /* ACKNOWLEDGEMENTS:
     20  * This work was initially developed by Pierangelo Masarati
     21  * for inclusion in OpenLDAP Software.
     22  */
     23 
     24 #include <sys/cdefs.h>
     25 __RCSID("$NetBSD: rdnval.c,v 1.2 2020/08/11 13:15:36 christos Exp $");
     26 
     27 #include "portable.h"
     28 
     29 #ifdef SLAPD_OVER_RDNVAL
     30 
     31 #include <stdio.h>
     32 
     33 #include "ac/string.h"
     34 #include "ac/socket.h"
     35 
     36 #include "slap.h"
     37 #include "config.h"
     38 
     39 #include "lutil.h"
     40 
     41 /*
     42  * Maintain an attribute (rdnValue) that contains the values of each AVA
     43  * that builds up the RDN of an entry.  This is required for interoperation
     44  * with Samba4.  It mimics the "name" attribute provided by Active Directory.
     45  * The naming attributes must be directoryString-valued, or compatible.
     46  * For example, IA5String values are cast into directoryString unless
     47  * consisting of the empty string ("").
     48  */
     49 
     50 static AttributeDescription	*ad_rdnValue;
     51 static Syntax			*syn_IA5String;
     52 
     53 static slap_overinst 		rdnval;
     54 
     55 static int
     56 rdnval_is_valid( AttributeDescription *desc, struct berval *value )
     57 {
     58 	if ( desc->ad_type->sat_syntax == slap_schema.si_syn_directoryString ) {
     59 		return 1;
     60 	}
     61 
     62 	if ( desc->ad_type->sat_syntax == syn_IA5String
     63 		&& !BER_BVISEMPTY( value ) )
     64 	{
     65 		return 1;
     66 	}
     67 
     68 	return 0;
     69 }
     70 
     71 static int
     72 rdnval_unique_check_cb( Operation *op, SlapReply *rs )
     73 {
     74 	if ( rs->sr_type == REP_SEARCH ) {
     75 		int *p = (int *)op->o_callback->sc_private;
     76 		(*p)++;
     77 	}
     78 
     79 	return 0;
     80 }
     81 
     82 static int
     83 rdnval_unique_check( Operation *op, BerVarray vals )
     84 {
     85 	slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
     86 
     87 	BackendDB db = *op->o_bd;
     88 	Operation op2 = *op;
     89 	SlapReply rs2 = { 0 };
     90 	int i;
     91 	BerVarray fvals;
     92 	char *ptr;
     93 	int gotit = 0;
     94 	slap_callback cb = { 0 };
     95 
     96 	/* short-circuit attempts to add suffix entry */
     97 	if ( op->o_tag == LDAP_REQ_ADD
     98 		&& be_issuffix( op->o_bd, &op->o_req_ndn ) )
     99 	{
    100 		return LDAP_SUCCESS;
    101 	}
    102 
    103 	op2.o_bd = &db;
    104 	op2.o_bd->bd_info = (BackendInfo *)on->on_info;
    105 	op2.o_tag = LDAP_REQ_SEARCH;
    106 	op2.o_dn = op->o_bd->be_rootdn;
    107 	op2.o_ndn = op->o_bd->be_rootndn;
    108 	op2.o_callback = &cb;
    109 	cb.sc_response = rdnval_unique_check_cb;
    110 	cb.sc_private = (void *)&gotit;
    111 
    112 	dnParent( &op->o_req_ndn, &op2.o_req_dn );
    113 	op2.o_req_ndn = op2.o_req_dn;
    114 
    115 	op2.ors_limit = NULL;
    116 	op2.ors_slimit = 1;
    117 	op2.ors_tlimit = SLAP_NO_LIMIT;
    118 	op2.ors_attrs = slap_anlist_no_attrs;
    119 	op2.ors_attrsonly = 1;
    120 	op2.ors_deref = LDAP_DEREF_NEVER;
    121 	op2.ors_scope = LDAP_SCOPE_ONELEVEL;
    122 
    123 	for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ )
    124 		/* just count */ ;
    125 
    126 	fvals = op->o_tmpcalloc( sizeof( struct berval ), i + 1,
    127 		op->o_tmpmemctx );
    128 
    129 	op2.ors_filterstr.bv_len = 0;
    130 	if ( i > 1 ) {
    131 		op2.ors_filterstr.bv_len = STRLENOF( "(&)" );
    132 	}
    133 
    134 	for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
    135 		ldap_bv2escaped_filter_value_x( &vals[ i ], &fvals[ i ],
    136 			1, op->o_tmpmemctx );
    137 		op2.ors_filterstr.bv_len += ad_rdnValue->ad_cname.bv_len
    138 			+ fvals[ i ].bv_len + STRLENOF( "(=)" );
    139 	}
    140 
    141 	op2.ors_filterstr.bv_val = op->o_tmpalloc( op2.ors_filterstr.bv_len + 1, op->o_tmpmemctx );
    142 
    143 	ptr = op2.ors_filterstr.bv_val;
    144 	if ( i > 1 ) {
    145 		ptr = lutil_strcopy( ptr, "(&" );
    146 	}
    147 	for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
    148 		*ptr++ = '(';
    149 		ptr = lutil_strncopy( ptr, ad_rdnValue->ad_cname.bv_val, ad_rdnValue->ad_cname.bv_len );
    150 		*ptr++ = '=';
    151 		ptr = lutil_strncopy( ptr, fvals[ i ].bv_val, fvals[ i ].bv_len );
    152 		*ptr++ = ')';
    153 	}
    154 
    155 	if ( i > 1 ) {
    156 		*ptr++ = ')';
    157 	}
    158 	*ptr = '\0';
    159 
    160 	assert( ptr == op2.ors_filterstr.bv_val + op2.ors_filterstr.bv_len );
    161 	op2.ors_filter = str2filter_x( op, op2.ors_filterstr.bv_val );
    162 	assert( op2.ors_filter != NULL );
    163 
    164 	(void)op2.o_bd->be_search( &op2, &rs2 );
    165 
    166 	filter_free_x( op, op2.ors_filter, 1 );
    167 	op->o_tmpfree( op2.ors_filterstr.bv_val, op->o_tmpmemctx );
    168 	for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
    169 		if ( vals[ i ].bv_val != fvals[ i ].bv_val ) {
    170 			op->o_tmpfree( fvals[ i ].bv_val, op->o_tmpmemctx );
    171 		}
    172 	}
    173 	op->o_tmpfree( fvals, op->o_tmpmemctx );
    174 
    175 	if ( rs2.sr_err != LDAP_SUCCESS || gotit > 0 ) {
    176 		return LDAP_CONSTRAINT_VIOLATION;
    177 	}
    178 
    179 	return LDAP_SUCCESS;
    180 }
    181 
    182 static int
    183 rdnval_rdn2vals(
    184 	Operation *op,
    185 	SlapReply *rs,
    186 	struct berval *dn,
    187 	struct berval *ndn,
    188 	BerVarray *valsp,
    189 	BerVarray *nvalsp,
    190 	int *numvalsp )
    191 {
    192 	LDAPRDN rdn = NULL, nrdn = NULL;
    193 	int nAVA, i;
    194 
    195 	assert( *valsp == NULL );
    196 	assert( *nvalsp == NULL );
    197 
    198 	*numvalsp = 0;
    199 
    200 	if ( ldap_bv2rdn_x( dn, &rdn, (char **)&rs->sr_text,
    201 		LDAP_DN_FORMAT_LDAP, op->o_tmpmemctx ) )
    202 	{
    203 		Debug( LDAP_DEBUG_TRACE,
    204 			"%s rdnval: can't figure out "
    205 			"type(s)/value(s) of rdn DN=\"%s\"\n",
    206 			op->o_log_prefix, dn->bv_val, 0 );
    207 		rs->sr_err = LDAP_INVALID_DN_SYNTAX;
    208 		rs->sr_text = "unknown type(s) used in RDN";
    209 
    210 		goto done;
    211 	}
    212 
    213 	if ( ldap_bv2rdn_x( ndn, &nrdn,
    214 		(char **)&rs->sr_text, LDAP_DN_FORMAT_LDAP, op->o_tmpmemctx ) )
    215 	{
    216 		Debug( LDAP_DEBUG_TRACE,
    217 			"%s rdnval: can't figure out "
    218 			"type(s)/value(s) of normalized rdn DN=\"%s\"\n",
    219 			op->o_log_prefix, ndn->bv_val, 0 );
    220 		rs->sr_err = LDAP_INVALID_DN_SYNTAX;
    221 		rs->sr_text = "unknown type(s) used in RDN";
    222 
    223 		goto done;
    224 	}
    225 
    226 	for ( nAVA = 0; rdn[ nAVA ]; nAVA++ )
    227 		/* count'em */ ;
    228 
    229 	/* NOTE: we assume rdn and nrdn contain the same AVAs! */
    230 
    231 	*valsp = SLAP_CALLOC( sizeof( struct berval ), nAVA + 1 );
    232 	*nvalsp = SLAP_CALLOC( sizeof( struct berval ), nAVA + 1 );
    233 
    234 	/* Add new attribute values to the entry */
    235 	for ( i = 0; rdn[ i ]; i++ ) {
    236 		AttributeDescription	*desc = NULL;
    237 
    238 		rs->sr_err = slap_bv2ad( &rdn[ i ]->la_attr,
    239 			&desc, &rs->sr_text );
    240 
    241 		if ( rs->sr_err != LDAP_SUCCESS ) {
    242 			Debug( LDAP_DEBUG_TRACE,
    243 				"%s rdnval: %s: %s\n",
    244 				op->o_log_prefix,
    245 				rs->sr_text,
    246 				rdn[ i ]->la_attr.bv_val );
    247 			goto done;
    248 		}
    249 
    250 		if ( !rdnval_is_valid( desc, &rdn[ i ]->la_value ) ) {
    251 			Debug( LDAP_DEBUG_TRACE,
    252 				"%s rdnval: syntax of naming attribute '%s' "
    253 				"not compatible with directoryString",
    254 				op->o_log_prefix, rdn[ i ]->la_attr.bv_val, 0 );
    255 			continue;
    256 		}
    257 
    258 		if ( value_find_ex( desc,
    259 				SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
    260 					SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
    261 				*nvalsp,
    262 				&nrdn[ i ]->la_value,
    263 				op->o_tmpmemctx )
    264 			== LDAP_NO_SUCH_ATTRIBUTE )
    265 		{
    266 			ber_dupbv( &(*valsp)[ *numvalsp ], &rdn[ i ]->la_value );
    267 			ber_dupbv( &(*nvalsp)[ *numvalsp ], &nrdn[ i ]->la_value );
    268 
    269 			(*numvalsp)++;
    270 		}
    271 	}
    272 
    273 	if ( rdnval_unique_check( op, *valsp ) != LDAP_SUCCESS ) {
    274 		rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
    275 		rs->sr_text = "rdnValue not unique within siblings";
    276 		goto done;
    277 	}
    278 
    279 done:;
    280 	if ( rdn != NULL ) {
    281 		ldap_rdnfree_x( rdn, op->o_tmpmemctx );
    282 	}
    283 
    284 	if ( nrdn != NULL ) {
    285 		ldap_rdnfree_x( nrdn, op->o_tmpmemctx );
    286 	}
    287 
    288 	if ( rs->sr_err != LDAP_SUCCESS ) {
    289 		if ( *valsp != NULL ) {
    290 			ber_bvarray_free( *valsp );
    291 			ber_bvarray_free( *nvalsp );
    292 			*valsp = NULL;
    293 			*nvalsp = NULL;
    294 			*numvalsp = 0;
    295 		}
    296 	}
    297 
    298 	return rs->sr_err;
    299 }
    300 
    301 static int
    302 rdnval_op_add( Operation *op, SlapReply *rs )
    303 {
    304 	Attribute *a, **ap;
    305 	int numvals = 0;
    306 	BerVarray vals = NULL, nvals = NULL;
    307 	int rc;
    308 
    309 	/* NOTE: should we accept an entry still in mods format? */
    310 	assert( op->ora_e != NULL );
    311 
    312 	if ( BER_BVISEMPTY( &op->ora_e->e_nname ) ) {
    313 		return SLAP_CB_CONTINUE;
    314 	}
    315 
    316 	a = attr_find( op->ora_e->e_attrs, ad_rdnValue );
    317 	if ( a != NULL ) {
    318 		/* TODO: check consistency? */
    319 		return SLAP_CB_CONTINUE;
    320 	}
    321 
    322 	rc = rdnval_rdn2vals( op, rs, &op->ora_e->e_name, &op->ora_e->e_nname,
    323 		&vals, &nvals, &numvals );
    324 	if ( rc != LDAP_SUCCESS ) {
    325 		send_ldap_result( op, rs );
    326 	}
    327 
    328 	a = attr_alloc( ad_rdnValue );
    329 
    330 	a->a_vals = vals;
    331 	a->a_nvals = nvals;
    332 	a->a_numvals = numvals;
    333 
    334 	for ( ap = &op->ora_e->e_attrs; *ap != NULL; ap = &(*ap)->a_next )
    335 		/* goto tail */ ;
    336 
    337 	*ap = a;
    338 
    339 	return SLAP_CB_CONTINUE;
    340 }
    341 
    342 static int
    343 rdnval_op_rename( Operation *op, SlapReply *rs )
    344 {
    345 	Modifications *ml, **mlp;
    346 	int numvals = 0;
    347 	BerVarray vals = NULL, nvals = NULL;
    348 	struct berval old;
    349 	int rc;
    350 
    351 	dnRdn( &op->o_req_ndn, &old );
    352 	if ( dn_match( &old, &op->orr_nnewrdn ) ) {
    353 		return SLAP_CB_CONTINUE;
    354 	}
    355 
    356 	rc = rdnval_rdn2vals( op, rs, &op->orr_newrdn, &op->orr_nnewrdn,
    357 		&vals, &nvals, &numvals );
    358 	if ( rc != LDAP_SUCCESS ) {
    359 		send_ldap_result( op, rs );
    360 	}
    361 
    362 	ml = SLAP_CALLOC( sizeof( Modifications ), 1 );
    363 	ml->sml_values = vals;
    364 	ml->sml_nvalues = nvals;
    365 
    366 	ml->sml_numvals = numvals;
    367 
    368 	ml->sml_op = LDAP_MOD_REPLACE;
    369 	ml->sml_flags = SLAP_MOD_INTERNAL;
    370 	ml->sml_desc = ad_rdnValue;
    371 	ml->sml_type = ad_rdnValue->ad_cname;
    372 
    373 	for ( mlp = &op->orr_modlist; *mlp != NULL; mlp = &(*mlp)->sml_next )
    374 		/* goto tail */ ;
    375 
    376 	*mlp = ml;
    377 
    378 	return SLAP_CB_CONTINUE;
    379 }
    380 
    381 static int
    382 rdnval_db_init(
    383 	BackendDB	*be,
    384 	ConfigReply	*cr)
    385 {
    386 	if ( SLAP_ISGLOBALOVERLAY( be ) ) {
    387 		Log0( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
    388 			"rdnval_db_init: rdnval cannot be used as global overlay.\n" );
    389 		return 1;
    390 	}
    391 
    392 	if ( be->be_nsuffix == NULL ) {
    393 		Log0( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
    394 			"rdnval_db_init: database must have suffix\n" );
    395 		return 1;
    396 	}
    397 
    398 	if ( BER_BVISNULL( &be->be_rootndn ) || BER_BVISEMPTY( &be->be_rootndn ) ) {
    399 		Log1( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
    400 			"rdnval_db_init: missing rootdn for database DN=\"%s\", YMMV\n",
    401 			be->be_suffix[ 0 ].bv_val );
    402 	}
    403 
    404 	return 0;
    405 }
    406 
    407 typedef struct rdnval_mod_t {
    408 	struct berval ndn;
    409 	BerVarray vals;
    410 	BerVarray nvals;
    411 	int numvals;
    412 	struct rdnval_mod_t *next;
    413 } rdnval_mod_t;
    414 
    415 typedef struct {
    416 	BackendDB *bd;
    417 	rdnval_mod_t *mods;
    418 } rdnval_repair_cb_t;
    419 
    420 static int
    421 rdnval_repair_cb( Operation *op, SlapReply *rs )
    422 {
    423 	int rc;
    424 	rdnval_repair_cb_t *rcb = op->o_callback->sc_private;
    425 	rdnval_mod_t *mod;
    426 	BerVarray vals = NULL, nvals = NULL;
    427 	int numvals = 0;
    428 	ber_len_t len;
    429 	BackendDB *save_bd = op->o_bd;
    430 
    431 	switch ( rs->sr_type ) {
    432 	case REP_SEARCH:
    433 		break;
    434 
    435 	case REP_SEARCHREF:
    436 	case REP_RESULT:
    437 		return rs->sr_err;
    438 
    439 	default:
    440 		assert( 0 );
    441 	}
    442 
    443 	assert( rs->sr_entry != NULL );
    444 
    445 	op->o_bd = rcb->bd;
    446 	rc = rdnval_rdn2vals( op, rs, &rs->sr_entry->e_name, &rs->sr_entry->e_nname,
    447 		&vals, &nvals, &numvals );
    448 	op->o_bd = save_bd;
    449 	if ( rc != LDAP_SUCCESS ) {
    450 		return 0;
    451 	}
    452 
    453 	len = sizeof( rdnval_mod_t ) + rs->sr_entry->e_nname.bv_len + 1;
    454 	mod = op->o_tmpalloc( len, op->o_tmpmemctx );
    455 	mod->ndn.bv_len = rs->sr_entry->e_nname.bv_len;
    456 	mod->ndn.bv_val = (char *)&mod[1];
    457 	lutil_strncopy( mod->ndn.bv_val, rs->sr_entry->e_nname.bv_val, rs->sr_entry->e_nname.bv_len );
    458 	mod->vals = vals;
    459 	mod->nvals = nvals;
    460 	mod->numvals = numvals;
    461 
    462 	mod->next = rcb->mods;
    463 	rcb->mods = mod;
    464 
    465 	Debug( LDAP_DEBUG_TRACE, "%s: rdnval_repair_cb: scheduling entry DN=\"%s\" for repair\n",
    466 		op->o_log_prefix, rs->sr_entry->e_name.bv_val, 0 );
    467 
    468 	return 0;
    469 }
    470 
    471 static int
    472 rdnval_repair( BackendDB *be )
    473 {
    474 	slap_overinst *on = (slap_overinst *)be->bd_info;
    475 	void *ctx = ldap_pvt_thread_pool_context();
    476 	Connection conn = { 0 };
    477 	OperationBuffer opbuf;
    478 	Operation *op;
    479 	BackendDB db;
    480 	slap_callback sc = { 0 };
    481 	rdnval_repair_cb_t rcb = { 0 };
    482 	SlapReply rs = { REP_RESULT };
    483 	rdnval_mod_t *rmod;
    484 	int nrepaired = 0;
    485 
    486 	connection_fake_init2( &conn, &opbuf, ctx, 0 );
    487 	op = &opbuf.ob_op;
    488 
    489 	op->o_tag = LDAP_REQ_SEARCH;
    490 	memset( &op->oq_search, 0, sizeof( op->oq_search ) );
    491 
    492 	assert( !BER_BVISNULL( &be->be_nsuffix[ 0 ] ) );
    493 
    494 	op->o_bd = select_backend( &be->be_nsuffix[ 0 ], 0 );
    495 	assert( op->o_bd != NULL );
    496 	assert( op->o_bd->be_nsuffix != NULL );
    497 
    498 	op->o_req_dn = op->o_bd->be_suffix[ 0 ];
    499 	op->o_req_ndn = op->o_bd->be_nsuffix[ 0 ];
    500 
    501 	op->o_dn = op->o_bd->be_rootdn;
    502 	op->o_ndn = op->o_bd->be_rootndn;
    503 
    504 	op->ors_scope = LDAP_SCOPE_SUBTREE;
    505 	op->ors_tlimit = SLAP_NO_LIMIT;
    506 	op->ors_slimit = SLAP_NO_LIMIT;
    507 	op->ors_attrs = slap_anlist_no_attrs;
    508 
    509 	op->ors_filterstr.bv_len = STRLENOF( "(!(=*))" ) + ad_rdnValue->ad_cname.bv_len;
    510 	op->ors_filterstr.bv_val = op->o_tmpalloc( op->ors_filterstr.bv_len + 1, op->o_tmpmemctx );
    511 	snprintf( op->ors_filterstr.bv_val, op->ors_filterstr.bv_len + 1,
    512 		"(!(%s=*))", ad_rdnValue->ad_cname.bv_val );
    513 
    514 	op->ors_filter = str2filter_x( op, op->ors_filterstr.bv_val );
    515 	if ( op->ors_filter == NULL ) {
    516 		rs.sr_err = LDAP_OTHER;
    517 		goto done_search;
    518 	}
    519 
    520 	op->o_callback = &sc;
    521 	sc.sc_response = rdnval_repair_cb;
    522 	sc.sc_private = &rcb;
    523 	rcb.bd = &db;
    524 	db = *be;
    525 	db.bd_info = (BackendInfo *)on;
    526 
    527 	(void)op->o_bd->bd_info->bi_op_search( op, &rs );
    528 
    529 	op->o_tag = LDAP_REQ_MODIFY;
    530 	sc.sc_response = slap_null_cb;
    531 	sc.sc_private = NULL;
    532 	memset( &op->oq_modify, 0, sizeof( req_modify_s ) );
    533 
    534 	for ( rmod = rcb.mods; rmod != NULL; ) {
    535 		rdnval_mod_t *rnext;
    536 
    537 		Modifications *mod;
    538 		SlapReply rs2 = { REP_RESULT };
    539 
    540 		mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
    541 		mod->sml_flags = SLAP_MOD_INTERNAL;
    542 		mod->sml_op = LDAP_MOD_REPLACE;
    543 		mod->sml_desc = ad_rdnValue;
    544 		mod->sml_type = ad_rdnValue->ad_cname;
    545 		mod->sml_values = rmod->vals;
    546 		mod->sml_nvalues = rmod->nvals;
    547 		mod->sml_numvals = rmod->numvals;
    548 		mod->sml_next = NULL;
    549 
    550 		op->o_req_dn = rmod->ndn;
    551 		op->o_req_ndn = rmod->ndn;
    552 
    553 		op->orm_modlist = mod;
    554 
    555 		op->o_bd->be_modify( op, &rs2 );
    556 
    557 		slap_mods_free( op->orm_modlist, 1 );
    558 		if ( rs2.sr_err == LDAP_SUCCESS ) {
    559 			Debug( LDAP_DEBUG_TRACE, "%s: rdnval_repair: entry DN=\"%s\" repaired\n",
    560 				op->o_log_prefix, rmod->ndn.bv_val, 0 );
    561 			nrepaired++;
    562 
    563 		} else {
    564 			Debug( LDAP_DEBUG_ANY, "%s: rdnval_repair: entry DN=\"%s\" repair failed (%d)\n",
    565 				op->o_log_prefix, rmod->ndn.bv_val, rs2.sr_err );
    566 		}
    567 
    568 		rnext = rmod->next;
    569 		op->o_tmpfree( rmod, op->o_tmpmemctx );
    570 		rmod = rnext;
    571 	}
    572 
    573 done_search:;
    574 	op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
    575 	filter_free_x( op, op->ors_filter, 1 );
    576 
    577 	Log1( LDAP_DEBUG_STATS, LDAP_LEVEL_INFO,
    578 		"rdnval: repaired=%d\n", nrepaired );
    579 
    580 	return 0;
    581 }
    582 
    583 /* search all entries without parentUUID; "repair" them */
    584 static int
    585 rdnval_db_open(
    586 	BackendDB	*be,
    587 	ConfigReply	*cr )
    588 {
    589 	if ( SLAP_SINGLE_SHADOW( be ) ) {
    590 		Log1( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
    591 			"rdnval incompatible with shadow database \"%s\".\n",
    592 			be->be_suffix[ 0 ].bv_val );
    593 		return 1;
    594 	}
    595 
    596 	return rdnval_repair( be );
    597 }
    598 
    599 static struct {
    600 	char	*desc;
    601 	AttributeDescription **adp;
    602 } as[] = {
    603 	{ "( 1.3.6.1.4.1.4203.666.1.58 "
    604 		"NAME 'rdnValue' "
    605 		"DESC 'the value of the naming attributes' "
    606 		"SYNTAX '1.3.6.1.4.1.1466.115.121.1.15' "
    607 		"EQUALITY caseIgnoreMatch "
    608 		"USAGE dSAOperation "
    609 		"NO-USER-MODIFICATION "
    610 		")",
    611 		&ad_rdnValue },
    612 	{ NULL }
    613 };
    614 
    615 int
    616 rdnval_initialize(void)
    617 {
    618 	int code, i;
    619 
    620 	for ( i = 0; as[ i ].desc != NULL; i++ ) {
    621 		code = register_at( as[ i ].desc, as[ i ].adp, 0 );
    622 		if ( code ) {
    623 			Debug( LDAP_DEBUG_ANY,
    624 				"rdnval_initialize: register_at #%d failed\n",
    625 				i, 0, 0 );
    626 			return code;
    627 		}
    628 
    629 		/* Allow Manager to set these as needed */
    630 		if ( is_at_no_user_mod( (*as[ i ].adp)->ad_type ) ) {
    631 			(*as[ i ].adp)->ad_type->sat_flags |=
    632 				SLAP_AT_MANAGEABLE;
    633 		}
    634 	}
    635 
    636 	syn_IA5String = syn_find( "1.3.6.1.4.1.1466.115.121.1.26" );
    637 	if ( syn_IA5String == NULL ) {
    638 		Debug( LDAP_DEBUG_ANY,
    639 			"rdnval_initialize: unable to find syntax '1.3.6.1.4.1.1466.115.121.1.26' (IA5String)\n",
    640 			0, 0, 0 );
    641 		return LDAP_OTHER;
    642 	}
    643 
    644 	rdnval.on_bi.bi_type = "rdnval";
    645 
    646 	rdnval.on_bi.bi_op_add = rdnval_op_add;
    647 	rdnval.on_bi.bi_op_modrdn = rdnval_op_rename;
    648 
    649 	rdnval.on_bi.bi_db_init = rdnval_db_init;
    650 	rdnval.on_bi.bi_db_open = rdnval_db_open;
    651 
    652 	return overlay_register( &rdnval );
    653 }
    654 
    655 #if SLAPD_OVER_RDNVAL == SLAPD_MOD_DYNAMIC
    656 int
    657 init_module( int argc, char *argv[] )
    658 {
    659 	return rdnval_initialize();
    660 }
    661 #endif /* SLAPD_OVER_RDNVAL == SLAPD_MOD_DYNAMIC */
    662 
    663 #endif /* SLAPD_OVER_RDNVAL */
    664