Home | History | Annotate | Line # | Download | only in samba4
      1  1.3  christos /*	$NetBSD: pguid.c,v 1.4 2025/09/05 21:16:18 christos Exp $	*/
      2  1.1      adam 
      3  1.1      adam /* pguid.c - Parent GUID value overlay */
      4  1.2  christos /* $OpenLDAP$ */
      5  1.1      adam /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
      6  1.1      adam  *
      7  1.4  christos  * Copyright 1998-2024 The OpenLDAP Foundation.
      8  1.1      adam  * Portions Copyright 2008 Pierangelo Masarati.
      9  1.1      adam  * All rights reserved.
     10  1.1      adam  *
     11  1.1      adam  * Redistribution and use in source and binary forms, with or without
     12  1.1      adam  * modification, are permitted only as authorized by the OpenLDAP
     13  1.1      adam  * Public License.
     14  1.1      adam  *
     15  1.1      adam  * A copy of this license is available in the file LICENSE in the
     16  1.1      adam  * top-level directory of the distribution or, alternatively, at
     17  1.1      adam  * <http://www.OpenLDAP.org/license.html>.
     18  1.1      adam  */
     19  1.1      adam /* ACKNOWLEDGEMENTS:
     20  1.1      adam  * This work was initially developed by Pierangelo Masarati
     21  1.1      adam  * for inclusion in OpenLDAP Software.
     22  1.1      adam  */
     23  1.1      adam 
     24  1.2  christos #include <sys/cdefs.h>
     25  1.3  christos __RCSID("$NetBSD: pguid.c,v 1.4 2025/09/05 21:16:18 christos Exp $");
     26  1.2  christos 
     27  1.1      adam #include "portable.h"
     28  1.1      adam 
     29  1.1      adam #ifdef SLAPD_OVER_PGUID
     30  1.1      adam 
     31  1.1      adam #include <stdio.h>
     32  1.1      adam 
     33  1.1      adam #include "ac/string.h"
     34  1.1      adam #include "ac/socket.h"
     35  1.1      adam 
     36  1.1      adam #include "slap.h"
     37  1.3  christos #include "slap-config.h"
     38  1.1      adam 
     39  1.1      adam #include "lutil.h"
     40  1.1      adam 
     41  1.1      adam /*
     42  1.1      adam  * Maintain an attribute (parentUUID) that contains the value
     43  1.1      adam  * of the entryUUID of the parent entry (used by Samba4)
     44  1.1      adam  */
     45  1.1      adam 
     46  1.1      adam static AttributeDescription	*ad_parentUUID;
     47  1.1      adam 
     48  1.1      adam static slap_overinst 		pguid;
     49  1.1      adam 
     50  1.1      adam static int
     51  1.1      adam pguid_op_add( Operation *op, SlapReply *rs )
     52  1.1      adam {
     53  1.1      adam 	slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
     54  1.1      adam 
     55  1.1      adam 	struct berval pdn, pndn;
     56  1.1      adam 	Entry *e = NULL;
     57  1.1      adam 	Attribute *a;
     58  1.1      adam 	int rc;
     59  1.1      adam 
     60  1.1      adam 	/* don't care about suffix entry */
     61  1.1      adam 	if ( dn_match( &op->o_req_ndn, &op->o_bd->be_nsuffix[0] ) ) {
     62  1.1      adam 		return SLAP_CB_CONTINUE;
     63  1.1      adam 	}
     64  1.1      adam 
     65  1.1      adam 	dnParent( &op->o_req_dn, &pdn );
     66  1.1      adam 	dnParent( &op->o_req_ndn, &pndn );
     67  1.1      adam 
     68  1.1      adam 	rc = overlay_entry_get_ov( op, &pndn, NULL, slap_schema.si_ad_entryUUID, 0, &e, on );
     69  1.1      adam 	if ( rc != LDAP_SUCCESS || e == NULL ) {
     70  1.1      adam 		Debug( LDAP_DEBUG_ANY, "%s: pguid_op_add: unable to get parent entry DN=\"%s\" (%d)\n",
     71  1.1      adam 			op->o_log_prefix, pdn.bv_val, rc );
     72  1.1      adam 		return SLAP_CB_CONTINUE;
     73  1.1      adam 	}
     74  1.1      adam 
     75  1.1      adam 	a = attr_find( e->e_attrs, slap_schema.si_ad_entryUUID );
     76  1.1      adam 	if ( a == NULL ) {
     77  1.1      adam 		Debug( LDAP_DEBUG_ANY, "%s: pguid_op_add: unable to find entryUUID of parent entry DN=\"%s\" (%d)\n",
     78  1.1      adam 			op->o_log_prefix, pdn.bv_val, rc );
     79  1.1      adam 
     80  1.1      adam 	} else {
     81  1.1      adam 		assert( a->a_numvals == 1 );
     82  1.1      adam 
     83  1.1      adam 		if ( op->ora_e != NULL ) {
     84  1.1      adam 			attr_merge_one( op->ora_e, ad_parentUUID, &a->a_vals[0], a->a_nvals == a->a_vals ? NULL : &a->a_nvals[0] );
     85  1.1      adam 
     86  1.1      adam 		} else {
     87  1.1      adam 			Modifications *ml;
     88  1.1      adam 			Modifications *mod;
     89  1.1      adam 
     90  1.1      adam 			assert( op->ora_modlist != NULL );
     91  1.1      adam 
     92  1.1      adam 			for ( ml = op->ora_modlist; ml != NULL; ml = ml->sml_next ) {
     93  1.1      adam 				if ( ml->sml_mod.sm_desc == slap_schema.si_ad_entryUUID ) {
     94  1.1      adam 					break;
     95  1.1      adam 				}
     96  1.1      adam 			}
     97  1.1      adam 
     98  1.1      adam 			if ( ml == NULL ) {
     99  1.1      adam 				ml = op->ora_modlist;
    100  1.1      adam 			}
    101  1.1      adam 
    102  1.1      adam 			mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
    103  1.1      adam 			mod->sml_flags = SLAP_MOD_INTERNAL;
    104  1.1      adam 			mod->sml_op = LDAP_MOD_ADD;
    105  1.1      adam 			mod->sml_desc = ad_parentUUID;
    106  1.1      adam 			mod->sml_type = ad_parentUUID->ad_cname;
    107  1.1      adam 			mod->sml_values = ch_malloc( sizeof( struct berval ) * 2 );
    108  1.1      adam 			mod->sml_nvalues = NULL;
    109  1.1      adam 			mod->sml_numvals = 1;
    110  1.1      adam 
    111  1.1      adam 			ber_dupbv( &mod->sml_values[0], &a->a_vals[0] );
    112  1.1      adam 			BER_BVZERO( &mod->sml_values[1] );
    113  1.1      adam 
    114  1.1      adam 			mod->sml_next = ml->sml_next;
    115  1.1      adam 			ml->sml_next = mod;
    116  1.1      adam 		}
    117  1.1      adam 	}
    118  1.1      adam 
    119  1.1      adam 	if ( e != NULL ) {
    120  1.1      adam 		(void)overlay_entry_release_ov( op, e, 0, on );
    121  1.1      adam 	}
    122  1.1      adam 
    123  1.1      adam 	return SLAP_CB_CONTINUE;
    124  1.1      adam }
    125  1.1      adam 
    126  1.1      adam static int
    127  1.1      adam pguid_op_rename( Operation *op, SlapReply *rs )
    128  1.1      adam {
    129  1.1      adam 	slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
    130  1.1      adam 
    131  1.1      adam 	Entry *e = NULL;
    132  1.1      adam 	Attribute *a;
    133  1.1      adam 	int rc;
    134  1.1      adam 
    135  1.1      adam 	if ( op->orr_nnewSup == NULL ) {
    136  1.1      adam 		return SLAP_CB_CONTINUE;
    137  1.1      adam 	}
    138  1.1      adam 
    139  1.1      adam 	rc = overlay_entry_get_ov( op, op->orr_nnewSup, NULL, slap_schema.si_ad_entryUUID, 0, &e, on );
    140  1.1      adam 	if ( rc != LDAP_SUCCESS || e == NULL ) {
    141  1.1      adam 		Debug( LDAP_DEBUG_ANY, "%s: pguid_op_rename: unable to get newSuperior entry DN=\"%s\" (%d)\n",
    142  1.1      adam 			op->o_log_prefix, op->orr_newSup->bv_val, rc );
    143  1.1      adam 		return SLAP_CB_CONTINUE;
    144  1.1      adam 	}
    145  1.1      adam 
    146  1.1      adam 	a = attr_find( e->e_attrs, slap_schema.si_ad_entryUUID );
    147  1.1      adam 	if ( a == NULL ) {
    148  1.1      adam 		Debug( LDAP_DEBUG_ANY, "%s: pguid_op_rename: unable to find entryUUID of newSuperior entry DN=\"%s\" (%d)\n",
    149  1.1      adam 			op->o_log_prefix, op->orr_newSup->bv_val, rc );
    150  1.1      adam 
    151  1.1      adam 	} else {
    152  1.1      adam 		Modifications *mod;
    153  1.1      adam 
    154  1.1      adam 		assert( a->a_numvals == 1 );
    155  1.1      adam 
    156  1.1      adam 		mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
    157  1.1      adam 		mod->sml_flags = SLAP_MOD_INTERNAL;
    158  1.1      adam 		mod->sml_op = LDAP_MOD_REPLACE;
    159  1.1      adam 		mod->sml_desc = ad_parentUUID;
    160  1.1      adam 		mod->sml_type = ad_parentUUID->ad_cname;
    161  1.1      adam 		mod->sml_values = ch_malloc( sizeof( struct berval ) * 2 );
    162  1.1      adam 		mod->sml_nvalues = NULL;
    163  1.1      adam 		mod->sml_numvals = 1;
    164  1.1      adam 
    165  1.1      adam 		ber_dupbv( &mod->sml_values[0], &a->a_vals[0] );
    166  1.1      adam 		BER_BVZERO( &mod->sml_values[1] );
    167  1.1      adam 
    168  1.1      adam 		mod->sml_next = op->orr_modlist;
    169  1.1      adam 		op->orr_modlist = mod;
    170  1.1      adam 	}
    171  1.1      adam 
    172  1.1      adam 	if ( e != NULL ) {
    173  1.1      adam 		(void)overlay_entry_release_ov( op, e, 0, on );
    174  1.1      adam 	}
    175  1.1      adam 
    176  1.1      adam 	return SLAP_CB_CONTINUE;
    177  1.1      adam }
    178  1.1      adam 
    179  1.1      adam static int
    180  1.1      adam pguid_db_init(
    181  1.1      adam 	BackendDB	*be,
    182  1.1      adam 	ConfigReply	*cr)
    183  1.1      adam {
    184  1.1      adam 	if ( SLAP_ISGLOBALOVERLAY( be ) ) {
    185  1.3  christos 		Log( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
    186  1.1      adam 			"pguid_db_init: pguid cannot be used as global overlay.\n" );
    187  1.1      adam 		return 1;
    188  1.1      adam 	}
    189  1.1      adam 
    190  1.1      adam 	if ( be->be_nsuffix == NULL ) {
    191  1.3  christos 		Log( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
    192  1.1      adam 			"pguid_db_init: database must have suffix\n" );
    193  1.1      adam 		return 1;
    194  1.1      adam 	}
    195  1.1      adam 
    196  1.1      adam 	if ( BER_BVISNULL( &be->be_rootndn ) || BER_BVISEMPTY( &be->be_rootndn ) ) {
    197  1.3  christos 		Log( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
    198  1.1      adam 			"pguid_db_init: missing rootdn for database DN=\"%s\", YMMV\n",
    199  1.1      adam 			be->be_suffix[ 0 ].bv_val );
    200  1.1      adam 	}
    201  1.1      adam 
    202  1.1      adam 	return 0;
    203  1.1      adam }
    204  1.1      adam 
    205  1.1      adam typedef struct pguid_mod_t {
    206  1.1      adam 	struct berval ndn;
    207  1.1      adam 	struct berval pguid;
    208  1.1      adam 	struct pguid_mod_t *next;
    209  1.1      adam } pguid_mod_t;
    210  1.1      adam 
    211  1.1      adam typedef struct {
    212  1.1      adam 	slap_overinst *on;
    213  1.1      adam 	pguid_mod_t *mods;
    214  1.1      adam } pguid_repair_cb_t;
    215  1.1      adam 
    216  1.1      adam static int
    217  1.1      adam pguid_repair_cb( Operation *op, SlapReply *rs )
    218  1.1      adam {
    219  1.1      adam 	int rc;
    220  1.1      adam 	pguid_repair_cb_t *pcb = op->o_callback->sc_private;
    221  1.1      adam 	Entry *e = NULL;
    222  1.1      adam 	Attribute *a;
    223  1.1      adam 	struct berval pdn, pndn;
    224  1.1      adam 
    225  1.1      adam 	switch ( rs->sr_type ) {
    226  1.1      adam 	case REP_SEARCH:
    227  1.1      adam 		break;
    228  1.1      adam 
    229  1.1      adam 	case REP_SEARCHREF:
    230  1.1      adam 	case REP_RESULT:
    231  1.1      adam 		return rs->sr_err;
    232  1.1      adam 
    233  1.1      adam 	default:
    234  1.1      adam 		assert( 0 );
    235  1.1      adam 	}
    236  1.1      adam 
    237  1.1      adam 	assert( rs->sr_entry != NULL );
    238  1.1      adam 
    239  1.1      adam 	dnParent( &rs->sr_entry->e_name, &pdn );
    240  1.1      adam 	dnParent( &rs->sr_entry->e_nname, &pndn );
    241  1.1      adam 
    242  1.1      adam 	rc = overlay_entry_get_ov( op, &pndn, NULL, slap_schema.si_ad_entryUUID, 0, &e, pcb->on );
    243  1.1      adam 	if ( rc != LDAP_SUCCESS || e == NULL ) {
    244  1.1      adam 		Debug( LDAP_DEBUG_ANY, "%s: pguid_repair_cb: unable to get parent entry DN=\"%s\" (%d)\n",
    245  1.1      adam 			op->o_log_prefix, pdn.bv_val, rc );
    246  1.1      adam 		return 0;
    247  1.1      adam 	}
    248  1.1      adam 
    249  1.1      adam 	a = attr_find( e->e_attrs, slap_schema.si_ad_entryUUID );
    250  1.1      adam 	if ( a == NULL ) {
    251  1.1      adam 		Debug( LDAP_DEBUG_ANY, "%s: pguid_repair_cb: unable to find entryUUID of parent entry DN=\"%s\" (%d)\n",
    252  1.1      adam 			op->o_log_prefix, pdn.bv_val, rc );
    253  1.1      adam 
    254  1.1      adam 	} else {
    255  1.1      adam 		ber_len_t len;
    256  1.1      adam 		pguid_mod_t *mod;
    257  1.1      adam 
    258  1.1      adam 		assert( a->a_numvals == 1 );
    259  1.1      adam 
    260  1.1      adam 		len = sizeof( pguid_mod_t ) + rs->sr_entry->e_nname.bv_len + 1 + a->a_vals[0].bv_len + 1;
    261  1.1      adam 		mod = op->o_tmpalloc( len, op->o_tmpmemctx );
    262  1.1      adam 		mod->ndn.bv_len = rs->sr_entry->e_nname.bv_len;
    263  1.1      adam 		mod->ndn.bv_val = (char *)&mod[1];
    264  1.1      adam 		mod->pguid.bv_len = a->a_vals[0].bv_len;
    265  1.1      adam 		mod->pguid.bv_val = (char *)&mod->ndn.bv_val[mod->ndn.bv_len + 1];
    266  1.1      adam 		lutil_strncopy( mod->ndn.bv_val, rs->sr_entry->e_nname.bv_val, rs->sr_entry->e_nname.bv_len );
    267  1.1      adam 		lutil_strncopy( mod->pguid.bv_val, a->a_vals[0].bv_val, a->a_vals[0].bv_len );
    268  1.1      adam 
    269  1.1      adam 		mod->next = pcb->mods;
    270  1.1      adam 		pcb->mods = mod;
    271  1.1      adam 
    272  1.1      adam 		Debug( LDAP_DEBUG_TRACE, "%s: pguid_repair_cb: scheduling entry DN=\"%s\" for repair\n",
    273  1.3  christos 			op->o_log_prefix, rs->sr_entry->e_name.bv_val );
    274  1.1      adam 	}
    275  1.1      adam 
    276  1.1      adam 	if ( e != NULL ) {
    277  1.1      adam 		(void)overlay_entry_release_ov( op, e, 0, pcb->on );
    278  1.1      adam 	}
    279  1.1      adam 
    280  1.1      adam 	return 0;
    281  1.1      adam }
    282  1.1      adam 
    283  1.1      adam static int
    284  1.1      adam pguid_repair( BackendDB *be )
    285  1.1      adam {
    286  1.1      adam 	slap_overinst *on = (slap_overinst *)be->bd_info;
    287  1.1      adam 	void *ctx = ldap_pvt_thread_pool_context();
    288  1.1      adam 	Connection conn = { 0 };
    289  1.1      adam 	OperationBuffer opbuf;
    290  1.1      adam 	Operation *op;
    291  1.1      adam 	slap_callback sc = { 0 };
    292  1.1      adam 	pguid_repair_cb_t pcb = { 0 };
    293  1.1      adam 	SlapReply rs = { REP_RESULT };
    294  1.1      adam 	pguid_mod_t *pmod;
    295  1.1      adam 	int nrepaired = 0;
    296  1.1      adam 
    297  1.1      adam 	connection_fake_init2( &conn, &opbuf, ctx, 0 );
    298  1.1      adam 	op = &opbuf.ob_op;
    299  1.1      adam 
    300  1.1      adam 	op->o_tag = LDAP_REQ_SEARCH;
    301  1.1      adam 	memset( &op->oq_search, 0, sizeof( op->oq_search ) );
    302  1.1      adam 
    303  1.1      adam 	op->o_bd = select_backend( &be->be_nsuffix[ 0 ], 0 );
    304  1.1      adam 
    305  1.1      adam 	op->o_req_dn = op->o_bd->be_suffix[ 0 ];
    306  1.1      adam 	op->o_req_ndn = op->o_bd->be_nsuffix[ 0 ];
    307  1.1      adam 
    308  1.1      adam 	op->o_dn = op->o_bd->be_rootdn;
    309  1.1      adam 	op->o_ndn = op->o_bd->be_rootndn;
    310  1.1      adam 
    311  1.1      adam 	op->ors_scope = LDAP_SCOPE_SUBORDINATE;
    312  1.1      adam 	op->ors_tlimit = SLAP_NO_LIMIT;
    313  1.1      adam 	op->ors_slimit = SLAP_NO_LIMIT;
    314  1.1      adam 	op->ors_attrs = slap_anlist_no_attrs;
    315  1.1      adam 
    316  1.1      adam 	op->ors_filterstr.bv_len = STRLENOF( "(!(=*))" ) + ad_parentUUID->ad_cname.bv_len;
    317  1.1      adam 	op->ors_filterstr.bv_val = op->o_tmpalloc( op->ors_filterstr.bv_len + 1, op->o_tmpmemctx );
    318  1.1      adam 	snprintf( op->ors_filterstr.bv_val, op->ors_filterstr.bv_len + 1,
    319  1.1      adam 		"(!(%s=*))", ad_parentUUID->ad_cname.bv_val );
    320  1.1      adam 
    321  1.1      adam 	op->ors_filter = str2filter_x( op, op->ors_filterstr.bv_val );
    322  1.1      adam 	if ( op->ors_filter == NULL ) {
    323  1.1      adam 		rs.sr_err = LDAP_OTHER;
    324  1.1      adam 		goto done_search;
    325  1.1      adam 	}
    326  1.1      adam 
    327  1.1      adam 	op->o_callback = &sc;
    328  1.1      adam 	sc.sc_response = pguid_repair_cb;
    329  1.1      adam 	sc.sc_private = &pcb;
    330  1.1      adam 	pcb.on = on;
    331  1.1      adam 
    332  1.1      adam 	(void)op->o_bd->bd_info->bi_op_search( op, &rs );
    333  1.1      adam 
    334  1.1      adam 	op->o_tag = LDAP_REQ_MODIFY;
    335  1.1      adam 	sc.sc_response = slap_null_cb;
    336  1.1      adam 	sc.sc_private = NULL;
    337  1.1      adam 	memset( &op->oq_modify, 0, sizeof( req_modify_s ) );
    338  1.1      adam 
    339  1.1      adam 	for ( pmod = pcb.mods; pmod != NULL; ) {
    340  1.1      adam 		pguid_mod_t *pnext;
    341  1.1      adam 
    342  1.1      adam 		Modifications *mod;
    343  1.1      adam 		SlapReply rs2 = { REP_RESULT };
    344  1.1      adam 
    345  1.1      adam 		mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
    346  1.1      adam 		mod->sml_flags = SLAP_MOD_INTERNAL;
    347  1.1      adam 		mod->sml_op = LDAP_MOD_REPLACE;
    348  1.1      adam 		mod->sml_desc = ad_parentUUID;
    349  1.1      adam 		mod->sml_type = ad_parentUUID->ad_cname;
    350  1.1      adam 		mod->sml_values = ch_malloc( sizeof( struct berval ) * 2 );
    351  1.1      adam 		mod->sml_nvalues = NULL;
    352  1.1      adam 		mod->sml_numvals = 1;
    353  1.1      adam 		mod->sml_next = NULL;
    354  1.1      adam 
    355  1.1      adam 		ber_dupbv( &mod->sml_values[0], &pmod->pguid );
    356  1.1      adam 		BER_BVZERO( &mod->sml_values[1] );
    357  1.1      adam 
    358  1.1      adam 		op->o_req_dn = pmod->ndn;
    359  1.1      adam 		op->o_req_ndn = pmod->ndn;
    360  1.1      adam 
    361  1.1      adam 		op->orm_modlist = mod;
    362  1.1      adam 		op->o_bd->be_modify( op, &rs2 );
    363  1.1      adam 		slap_mods_free( op->orm_modlist, 1 );
    364  1.1      adam 		if ( rs2.sr_err == LDAP_SUCCESS ) {
    365  1.1      adam 			Debug( LDAP_DEBUG_TRACE, "%s: pguid_repair: entry DN=\"%s\" repaired\n",
    366  1.3  christos 				op->o_log_prefix, pmod->ndn.bv_val );
    367  1.1      adam 			nrepaired++;
    368  1.1      adam 
    369  1.1      adam 		} else {
    370  1.1      adam 			Debug( LDAP_DEBUG_ANY, "%s: pguid_repair: entry DN=\"%s\" repair failed (%d)\n",
    371  1.1      adam 				op->o_log_prefix, pmod->ndn.bv_val, rs2.sr_err );
    372  1.1      adam 		}
    373  1.1      adam 
    374  1.1      adam 		pnext = pmod->next;
    375  1.1      adam 		op->o_tmpfree( pmod, op->o_tmpmemctx );
    376  1.1      adam 		pmod = pnext;
    377  1.1      adam 	}
    378  1.1      adam 
    379  1.1      adam done_search:;
    380  1.1      adam 	op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
    381  1.1      adam 	filter_free_x( op, op->ors_filter, 1 );
    382  1.1      adam 
    383  1.3  christos 	Log( LDAP_DEBUG_STATS, LDAP_LEVEL_INFO,
    384  1.1      adam 		"pguid: repaired=%d\n", nrepaired );
    385  1.1      adam 
    386  1.1      adam 	return rs.sr_err;
    387  1.1      adam }
    388  1.1      adam 
    389  1.1      adam /* search all entries without parentUUID; "repair" them */
    390  1.1      adam static int
    391  1.1      adam pguid_db_open(
    392  1.1      adam 	BackendDB	*be,
    393  1.1      adam 	ConfigReply	*cr )
    394  1.1      adam {
    395  1.1      adam 	if ( SLAP_SINGLE_SHADOW( be ) ) {
    396  1.3  christos 		Log( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
    397  1.1      adam 			"pguid incompatible with shadow database \"%s\".\n",
    398  1.1      adam 			be->be_suffix[ 0 ].bv_val );
    399  1.1      adam 		return 1;
    400  1.1      adam 	}
    401  1.1      adam 
    402  1.1      adam 	pguid_repair( be );
    403  1.1      adam 
    404  1.1      adam 	return 0;
    405  1.1      adam }
    406  1.1      adam 
    407  1.1      adam static struct {
    408  1.1      adam 	char	*desc;
    409  1.1      adam 	AttributeDescription **adp;
    410  1.1      adam } as[] = {
    411  1.1      adam 	{ "( 1.3.6.1.4.1.4203.666.1.59 "
    412  1.1      adam 		"NAME 'parentUUID' "
    413  1.1      adam 		"DESC 'the value of the entryUUID of the parent' "
    414  1.1      adam 		"EQUALITY UUIDMatch "
    415  1.1      adam 		"ORDERING UUIDOrderingMatch "
    416  1.1      adam 		"SYNTAX 1.3.6.1.1.16.1 "
    417  1.1      adam 		"USAGE dSAOperation "
    418  1.1      adam 		"SINGLE-VALUE "
    419  1.1      adam 		"NO-USER-MODIFICATION "
    420  1.1      adam 		")",
    421  1.1      adam 		&ad_parentUUID },
    422  1.1      adam 	{ NULL }
    423  1.1      adam };
    424  1.1      adam 
    425  1.1      adam int
    426  1.1      adam pguid_initialize(void)
    427  1.1      adam {
    428  1.1      adam 	int code, i;
    429  1.1      adam 
    430  1.1      adam 	for ( i = 0; as[ i ].desc != NULL; i++ ) {
    431  1.1      adam 		code = register_at( as[ i ].desc, as[ i ].adp, 0 );
    432  1.1      adam 		if ( code ) {
    433  1.1      adam 			Debug( LDAP_DEBUG_ANY,
    434  1.1      adam 				"pguid_initialize: register_at #%d failed\n",
    435  1.3  christos 				i );
    436  1.1      adam 			return code;
    437  1.1      adam 		}
    438  1.1      adam 
    439  1.1      adam 		/* Allow Manager to set these as needed */
    440  1.1      adam 		if ( is_at_no_user_mod( (*as[ i ].adp)->ad_type ) ) {
    441  1.1      adam 			(*as[ i ].adp)->ad_type->sat_flags |=
    442  1.1      adam 				SLAP_AT_MANAGEABLE;
    443  1.1      adam 		}
    444  1.1      adam 	}
    445  1.1      adam 
    446  1.1      adam 	pguid.on_bi.bi_type = "pguid";
    447  1.1      adam 
    448  1.1      adam 	pguid.on_bi.bi_op_add = pguid_op_add;
    449  1.1      adam 	pguid.on_bi.bi_op_modrdn = pguid_op_rename;
    450  1.1      adam 
    451  1.1      adam 	pguid.on_bi.bi_db_init = pguid_db_init;
    452  1.1      adam 	pguid.on_bi.bi_db_open = pguid_db_open;
    453  1.1      adam 
    454  1.1      adam 	return overlay_register( &pguid );
    455  1.1      adam }
    456  1.1      adam 
    457  1.1      adam #if SLAPD_OVER_PGUID == SLAPD_MOD_DYNAMIC
    458  1.1      adam int
    459  1.1      adam init_module( int argc, char *argv[] )
    460  1.1      adam {
    461  1.1      adam 	return pguid_initialize();
    462  1.1      adam }
    463  1.1      adam #endif /* SLAPD_OVER_PGUID == SLAPD_MOD_DYNAMIC */
    464  1.1      adam 
    465  1.1      adam #endif /* SLAPD_OVER_PGUID */
    466