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