Home | History | Annotate | Line # | Download | only in slapd
mr.c revision 1.1.1.9
      1  1.1.1.9  christos /*	$NetBSD: mr.c,v 1.1.1.9 2021/08/14 16:05:21 christos Exp $	*/
      2  1.1.1.2     lukem 
      3      1.1     lukem /* mr.c - routines to manage matching rule definitions */
      4  1.1.1.4      tron /* $OpenLDAP$ */
      5      1.1     lukem /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
      6      1.1     lukem  *
      7  1.1.1.9  christos  * Copyright 1998-2021 The OpenLDAP Foundation.
      8      1.1     lukem  * All rights reserved.
      9      1.1     lukem  *
     10      1.1     lukem  * Redistribution and use in source and binary forms, with or without
     11      1.1     lukem  * modification, are permitted only as authorized by the OpenLDAP
     12      1.1     lukem  * Public License.
     13      1.1     lukem  *
     14      1.1     lukem  * A copy of this license is available in the file LICENSE in the
     15      1.1     lukem  * top-level directory of the distribution or, alternatively, at
     16      1.1     lukem  * <http://www.OpenLDAP.org/license.html>.
     17      1.1     lukem  */
     18      1.1     lukem 
     19  1.1.1.5  christos #include <sys/cdefs.h>
     20  1.1.1.9  christos __RCSID("$NetBSD: mr.c,v 1.1.1.9 2021/08/14 16:05:21 christos Exp $");
     21  1.1.1.5  christos 
     22      1.1     lukem #include "portable.h"
     23      1.1     lukem 
     24      1.1     lukem #include <stdio.h>
     25      1.1     lukem 
     26      1.1     lukem #include <ac/ctype.h>
     27      1.1     lukem #include <ac/string.h>
     28      1.1     lukem #include <ac/socket.h>
     29      1.1     lukem 
     30      1.1     lukem #include "slap.h"
     31      1.1     lukem 
     32      1.1     lukem struct mindexrec {
     33      1.1     lukem 	struct berval	mir_name;
     34      1.1     lukem 	MatchingRule	*mir_mr;
     35      1.1     lukem };
     36      1.1     lukem 
     37      1.1     lukem static Avlnode	*mr_index = NULL;
     38      1.1     lukem static LDAP_SLIST_HEAD(MRList, MatchingRule) mr_list
     39      1.1     lukem 	= LDAP_SLIST_HEAD_INITIALIZER(&mr_list);
     40      1.1     lukem static LDAP_SLIST_HEAD(MRUList, MatchingRuleUse) mru_list
     41      1.1     lukem 	= LDAP_SLIST_HEAD_INITIALIZER(&mru_list);
     42      1.1     lukem 
     43      1.1     lukem static int
     44      1.1     lukem mr_index_cmp(
     45      1.1     lukem     const void	*v_mir1,
     46      1.1     lukem     const void	*v_mir2
     47      1.1     lukem )
     48      1.1     lukem {
     49      1.1     lukem 	const struct mindexrec	*mir1 = v_mir1;
     50      1.1     lukem 	const struct mindexrec	*mir2 = v_mir2;
     51      1.1     lukem 	int i = mir1->mir_name.bv_len - mir2->mir_name.bv_len;
     52      1.1     lukem 	if (i) return i;
     53      1.1     lukem 	return (strcasecmp( mir1->mir_name.bv_val, mir2->mir_name.bv_val ));
     54      1.1     lukem }
     55      1.1     lukem 
     56      1.1     lukem static int
     57      1.1     lukem mr_index_name_cmp(
     58      1.1     lukem     const void	*v_name,
     59      1.1     lukem     const void	*v_mir
     60      1.1     lukem )
     61      1.1     lukem {
     62      1.1     lukem 	const struct berval    *name = v_name;
     63      1.1     lukem 	const struct mindexrec *mir  = v_mir;
     64      1.1     lukem 	int i = name->bv_len - mir->mir_name.bv_len;
     65      1.1     lukem 	if (i) return i;
     66      1.1     lukem 	return (strncasecmp( name->bv_val, mir->mir_name.bv_val, name->bv_len ));
     67      1.1     lukem }
     68      1.1     lukem 
     69      1.1     lukem MatchingRule *
     70      1.1     lukem mr_find( const char *mrname )
     71      1.1     lukem {
     72      1.1     lukem 	struct berval bv;
     73      1.1     lukem 
     74      1.1     lukem 	bv.bv_val = (char *)mrname;
     75      1.1     lukem 	bv.bv_len = strlen( mrname );
     76      1.1     lukem 	return mr_bvfind( &bv );
     77      1.1     lukem }
     78      1.1     lukem 
     79      1.1     lukem MatchingRule *
     80      1.1     lukem mr_bvfind( struct berval *mrname )
     81      1.1     lukem {
     82      1.1     lukem 	struct mindexrec	*mir = NULL;
     83      1.1     lukem 
     84  1.1.1.9  christos 	if ( (mir = ldap_avl_find( mr_index, mrname, mr_index_name_cmp )) != NULL ) {
     85      1.1     lukem 		return( mir->mir_mr );
     86      1.1     lukem 	}
     87      1.1     lukem 	return( NULL );
     88      1.1     lukem }
     89      1.1     lukem 
     90      1.1     lukem void
     91      1.1     lukem mr_destroy( void )
     92      1.1     lukem {
     93      1.1     lukem 	MatchingRule *m;
     94      1.1     lukem 
     95  1.1.1.9  christos 	ldap_avl_free(mr_index, ldap_memfree);
     96      1.1     lukem 	while( !LDAP_SLIST_EMPTY(&mr_list) ) {
     97      1.1     lukem 		m = LDAP_SLIST_FIRST(&mr_list);
     98      1.1     lukem 		LDAP_SLIST_REMOVE_HEAD(&mr_list, smr_next);
     99      1.1     lukem 		ch_free( m->smr_str.bv_val );
    100      1.1     lukem 		ch_free( m->smr_compat_syntaxes );
    101      1.1     lukem 		ldap_matchingrule_free((LDAPMatchingRule *)m);
    102      1.1     lukem 	}
    103      1.1     lukem }
    104      1.1     lukem 
    105      1.1     lukem static int
    106      1.1     lukem mr_insert(
    107      1.1     lukem     MatchingRule	*smr,
    108      1.1     lukem     const char		**err
    109      1.1     lukem )
    110      1.1     lukem {
    111      1.1     lukem 	struct mindexrec	*mir;
    112      1.1     lukem 	char			**names;
    113      1.1     lukem 
    114      1.1     lukem 	LDAP_SLIST_NEXT( smr, smr_next ) = NULL;
    115      1.1     lukem 	LDAP_SLIST_INSERT_HEAD(&mr_list, smr, smr_next);
    116      1.1     lukem 
    117      1.1     lukem 	if ( smr->smr_oid ) {
    118      1.1     lukem 		mir = (struct mindexrec *)
    119      1.1     lukem 			ch_calloc( 1, sizeof(struct mindexrec) );
    120      1.1     lukem 		mir->mir_name.bv_val = smr->smr_oid;
    121      1.1     lukem 		mir->mir_name.bv_len = strlen( smr->smr_oid );
    122      1.1     lukem 		mir->mir_mr = smr;
    123  1.1.1.9  christos 		if ( ldap_avl_insert( &mr_index, (caddr_t) mir,
    124  1.1.1.9  christos 		                 mr_index_cmp, ldap_avl_dup_error ) ) {
    125      1.1     lukem 			*err = smr->smr_oid;
    126      1.1     lukem 			ldap_memfree(mir);
    127      1.1     lukem 			return SLAP_SCHERR_MR_DUP;
    128      1.1     lukem 		}
    129      1.1     lukem 		/* FIX: temporal consistency check */
    130      1.1     lukem 		mr_bvfind(&mir->mir_name);
    131      1.1     lukem 	}
    132      1.1     lukem 	if ( (names = smr->smr_names) ) {
    133      1.1     lukem 		while ( *names ) {
    134      1.1     lukem 			mir = (struct mindexrec *)
    135      1.1     lukem 				ch_calloc( 1, sizeof(struct mindexrec) );
    136      1.1     lukem 			mir->mir_name.bv_val = *names;
    137      1.1     lukem 			mir->mir_name.bv_len = strlen( *names );
    138      1.1     lukem 			mir->mir_mr = smr;
    139  1.1.1.9  christos 			if ( ldap_avl_insert( &mr_index, (caddr_t) mir,
    140  1.1.1.9  christos 			                 mr_index_cmp, ldap_avl_dup_error ) ) {
    141      1.1     lukem 				*err = *names;
    142      1.1     lukem 				ldap_memfree(mir);
    143      1.1     lukem 				return SLAP_SCHERR_MR_DUP;
    144      1.1     lukem 			}
    145      1.1     lukem 			/* FIX: temporal consistency check */
    146      1.1     lukem 			mr_bvfind(&mir->mir_name);
    147      1.1     lukem 			names++;
    148      1.1     lukem 		}
    149      1.1     lukem 	}
    150      1.1     lukem 	return 0;
    151      1.1     lukem }
    152      1.1     lukem 
    153      1.1     lukem int
    154      1.1     lukem mr_make_syntax_compat_with_mr(
    155      1.1     lukem 	Syntax		*syn,
    156      1.1     lukem 	MatchingRule	*mr )
    157      1.1     lukem {
    158      1.1     lukem 	int		n = 0;
    159      1.1     lukem 
    160      1.1     lukem 	assert( syn != NULL );
    161      1.1     lukem 	assert( mr != NULL );
    162      1.1     lukem 
    163      1.1     lukem 	if ( mr->smr_compat_syntaxes ) {
    164  1.1.1.9  christos 		/* count existing */
    165      1.1     lukem 		for ( n = 0;
    166      1.1     lukem 			mr->smr_compat_syntaxes[ n ];
    167      1.1     lukem 			n++ )
    168      1.1     lukem 		{
    169      1.1     lukem 			if ( mr->smr_compat_syntaxes[ n ] == syn ) {
    170      1.1     lukem 				/* already compatible; mmmmh... */
    171      1.1     lukem 				return 1;
    172      1.1     lukem 			}
    173      1.1     lukem 		}
    174      1.1     lukem 	}
    175      1.1     lukem 
    176      1.1     lukem 	mr->smr_compat_syntaxes = ch_realloc(
    177      1.1     lukem 		mr->smr_compat_syntaxes,
    178      1.1     lukem 		sizeof( Syntax * )*(n + 2) );
    179      1.1     lukem 	mr->smr_compat_syntaxes[ n ] = syn;
    180      1.1     lukem 	mr->smr_compat_syntaxes[ n + 1 ] = NULL;
    181      1.1     lukem 
    182      1.1     lukem 	return 0;
    183      1.1     lukem }
    184      1.1     lukem 
    185      1.1     lukem int
    186      1.1     lukem mr_make_syntax_compat_with_mrs(
    187      1.1     lukem 	const char *syntax,
    188      1.1     lukem 	char *const *mrs )
    189      1.1     lukem {
    190      1.1     lukem 	int	r, rc = 0;
    191      1.1     lukem 	Syntax	*syn;
    192      1.1     lukem 
    193      1.1     lukem 	assert( syntax != NULL );
    194      1.1     lukem 	assert( mrs != NULL );
    195      1.1     lukem 
    196      1.1     lukem 	syn = syn_find( syntax );
    197      1.1     lukem 	if ( syn == NULL ) {
    198      1.1     lukem 		return -1;
    199      1.1     lukem 	}
    200      1.1     lukem 
    201      1.1     lukem 	for ( r = 0; mrs[ r ] != NULL; r++ ) {
    202      1.1     lukem 		MatchingRule	*mr = mr_find( mrs[ r ] );
    203      1.1     lukem 		if ( mr == NULL ) {
    204      1.1     lukem 			/* matchingRule not found -- ignore by now */
    205      1.1     lukem 			continue;
    206      1.1     lukem 		}
    207      1.1     lukem 
    208      1.1     lukem 		rc += mr_make_syntax_compat_with_mr( syn, mr );
    209      1.1     lukem 	}
    210      1.1     lukem 
    211      1.1     lukem 	return rc;
    212      1.1     lukem }
    213      1.1     lukem 
    214      1.1     lukem int
    215      1.1     lukem mr_add(
    216      1.1     lukem     LDAPMatchingRule		*mr,
    217      1.1     lukem     slap_mrule_defs_rec	*def,
    218      1.1     lukem 	MatchingRule	*amr,
    219      1.1     lukem     const char		**err
    220      1.1     lukem )
    221      1.1     lukem {
    222      1.1     lukem 	MatchingRule	*smr;
    223      1.1     lukem 	Syntax		*syn;
    224      1.1     lukem 	Syntax		**compat_syn = NULL;
    225      1.1     lukem 	int		code;
    226      1.1     lukem 
    227      1.1     lukem 	if( def->mrd_compat_syntaxes ) {
    228      1.1     lukem 		int i;
    229      1.1     lukem 		for( i=0; def->mrd_compat_syntaxes[i]; i++ ) {
    230      1.1     lukem 			/* just count em */
    231      1.1     lukem 		}
    232      1.1     lukem 
    233      1.1     lukem 		compat_syn = ch_malloc( sizeof(Syntax *) * (i+1) );
    234      1.1     lukem 
    235      1.1     lukem 		for( i=0; def->mrd_compat_syntaxes[i]; i++ ) {
    236      1.1     lukem 			compat_syn[i] = syn_find( def->mrd_compat_syntaxes[i] );
    237      1.1     lukem 			if( compat_syn[i] == NULL ) {
    238      1.1     lukem 				ch_free( compat_syn );
    239      1.1     lukem 				return SLAP_SCHERR_SYN_NOT_FOUND;
    240      1.1     lukem 			}
    241      1.1     lukem 		}
    242      1.1     lukem 
    243      1.1     lukem 		compat_syn[i] = NULL;
    244      1.1     lukem 	}
    245      1.1     lukem 
    246      1.1     lukem 	smr = (MatchingRule *) ch_calloc( 1, sizeof(MatchingRule) );
    247      1.1     lukem 	AC_MEMCPY( &smr->smr_mrule, mr, sizeof(LDAPMatchingRule));
    248      1.1     lukem 
    249      1.1     lukem 	/*
    250      1.1     lukem 	 * note: smr_bvoid uses the same memory of smr_mrule.mr_oid;
    251      1.1     lukem 	 * smr_oidlen is #defined as smr_bvoid.bv_len
    252      1.1     lukem 	 */
    253      1.1     lukem 	smr->smr_bvoid.bv_val = smr->smr_mrule.mr_oid;
    254      1.1     lukem 	smr->smr_oidlen = strlen( mr->mr_oid );
    255      1.1     lukem 	smr->smr_usage = def->mrd_usage;
    256      1.1     lukem 	smr->smr_compat_syntaxes = compat_syn;
    257      1.1     lukem 	smr->smr_normalize = def->mrd_normalize;
    258      1.1     lukem 	smr->smr_match = def->mrd_match;
    259      1.1     lukem 	smr->smr_indexer = def->mrd_indexer;
    260      1.1     lukem 	smr->smr_filter = def->mrd_filter;
    261      1.1     lukem 	smr->smr_associated = amr;
    262      1.1     lukem 
    263      1.1     lukem 	if ( smr->smr_syntax_oid ) {
    264      1.1     lukem 		if ( (syn = syn_find(smr->smr_syntax_oid)) ) {
    265      1.1     lukem 			smr->smr_syntax = syn;
    266      1.1     lukem 		} else {
    267      1.1     lukem 			*err = smr->smr_syntax_oid;
    268      1.1     lukem 			ch_free( smr );
    269      1.1     lukem 			return SLAP_SCHERR_SYN_NOT_FOUND;
    270      1.1     lukem 		}
    271      1.1     lukem 	} else {
    272      1.1     lukem 		*err = "";
    273      1.1     lukem 		ch_free( smr );
    274      1.1     lukem 		return SLAP_SCHERR_MR_INCOMPLETE;
    275      1.1     lukem 	}
    276      1.1     lukem 	code = mr_insert(smr,err);
    277      1.1     lukem 	return code;
    278      1.1     lukem }
    279      1.1     lukem 
    280      1.1     lukem int
    281      1.1     lukem register_matching_rule(
    282      1.1     lukem 	slap_mrule_defs_rec *def )
    283      1.1     lukem {
    284      1.1     lukem 	LDAPMatchingRule *mr;
    285      1.1     lukem 	MatchingRule *amr = NULL;
    286      1.1     lukem 	int		code;
    287      1.1     lukem 	const char	*err;
    288      1.1     lukem 
    289      1.1     lukem 	if( def->mrd_usage == SLAP_MR_NONE && def->mrd_compat_syntaxes == NULL ) {
    290      1.1     lukem 		Debug( LDAP_DEBUG_ANY, "register_matching_rule: not usable %s\n",
    291  1.1.1.9  christos 		    def->mrd_desc );
    292      1.1     lukem 
    293      1.1     lukem 		return -1;
    294      1.1     lukem 	}
    295      1.1     lukem 
    296      1.1     lukem 	if( def->mrd_associated != NULL ) {
    297      1.1     lukem 		amr = mr_find( def->mrd_associated );
    298      1.1     lukem 		if( amr == NULL ) {
    299      1.1     lukem 			Debug( LDAP_DEBUG_ANY, "register_matching_rule: "
    300      1.1     lukem 				"could not locate associated matching rule %s for %s\n",
    301  1.1.1.9  christos 				def->mrd_associated, def->mrd_desc );
    302      1.1     lukem 
    303      1.1     lukem 			return -1;
    304      1.1     lukem 		}
    305      1.1     lukem 
    306      1.1     lukem 		if (( def->mrd_usage & SLAP_MR_EQUALITY ) &&
    307      1.1     lukem 			(( def->mrd_usage & SLAP_MR_SUBTYPE_MASK ) == SLAP_MR_NONE ))
    308      1.1     lukem 		{
    309      1.1     lukem 			if (( def->mrd_usage & SLAP_MR_EQUALITY ) &&
    310      1.1     lukem 				(( def->mrd_usage & SLAP_MR_SUBTYPE_MASK ) != SLAP_MR_NONE ))
    311      1.1     lukem 			{
    312      1.1     lukem 				Debug( LDAP_DEBUG_ANY, "register_matching_rule: "
    313      1.1     lukem 						"inappropriate (approx) association %s for %s\n",
    314  1.1.1.9  christos 					def->mrd_associated, def->mrd_desc );
    315      1.1     lukem 				return -1;
    316      1.1     lukem 			}
    317      1.1     lukem 
    318      1.1     lukem 		} else if (!( amr->smr_usage & SLAP_MR_EQUALITY )) {
    319      1.1     lukem 				Debug( LDAP_DEBUG_ANY, "register_matching_rule: "
    320      1.1     lukem 					"inappropriate (equalilty) association %s for %s\n",
    321  1.1.1.9  christos 					def->mrd_associated, def->mrd_desc );
    322      1.1     lukem 				return -1;
    323      1.1     lukem 		}
    324      1.1     lukem 	}
    325      1.1     lukem 
    326      1.1     lukem 	mr = ldap_str2matchingrule( def->mrd_desc, &code, &err,
    327      1.1     lukem 		LDAP_SCHEMA_ALLOW_ALL );
    328      1.1     lukem 	if ( !mr ) {
    329      1.1     lukem 		Debug( LDAP_DEBUG_ANY,
    330      1.1     lukem 			"Error in register_matching_rule: %s before %s in %s\n",
    331      1.1     lukem 		    ldap_scherr2str(code), err, def->mrd_desc );
    332      1.1     lukem 
    333      1.1     lukem 		return -1;
    334      1.1     lukem 	}
    335      1.1     lukem 
    336      1.1     lukem 
    337      1.1     lukem 	code = mr_add( mr, def, amr, &err );
    338      1.1     lukem 
    339      1.1     lukem 	ldap_memfree( mr );
    340      1.1     lukem 
    341      1.1     lukem 	if ( code ) {
    342      1.1     lukem 		Debug( LDAP_DEBUG_ANY,
    343      1.1     lukem 			"Error in register_matching_rule: %s for %s in %s\n",
    344      1.1     lukem 		    scherr2str(code), err, def->mrd_desc );
    345      1.1     lukem 
    346      1.1     lukem 		return -1;
    347      1.1     lukem 	}
    348      1.1     lukem 
    349      1.1     lukem 	return 0;
    350      1.1     lukem }
    351      1.1     lukem 
    352      1.1     lukem void
    353      1.1     lukem mru_destroy( void )
    354      1.1     lukem {
    355      1.1     lukem 	MatchingRuleUse *m;
    356      1.1     lukem 
    357      1.1     lukem 	while( !LDAP_SLIST_EMPTY(&mru_list) ) {
    358      1.1     lukem 		m = LDAP_SLIST_FIRST(&mru_list);
    359      1.1     lukem 		LDAP_SLIST_REMOVE_HEAD(&mru_list, smru_next);
    360      1.1     lukem 
    361      1.1     lukem 		if ( m->smru_str.bv_val ) {
    362      1.1     lukem 			ch_free( m->smru_str.bv_val );
    363      1.1     lukem 			m->smru_str.bv_val = NULL;
    364      1.1     lukem 		}
    365      1.1     lukem 		/* memory borrowed from m->smru_mr */
    366      1.1     lukem 		m->smru_oid = NULL;
    367      1.1     lukem 		m->smru_names = NULL;
    368      1.1     lukem 		m->smru_desc = NULL;
    369      1.1     lukem 
    370      1.1     lukem 		/* free what's left (basically smru_mruleuse.mru_applies_oids) */
    371      1.1     lukem 		ldap_matchingruleuse_free((LDAPMatchingRuleUse *)m);
    372      1.1     lukem 	}
    373      1.1     lukem }
    374      1.1     lukem 
    375      1.1     lukem int
    376      1.1     lukem matching_rule_use_init( void )
    377      1.1     lukem {
    378      1.1     lukem 	MatchingRule	*mr;
    379      1.1     lukem 	MatchingRuleUse	**mru_ptr = &LDAP_SLIST_FIRST(&mru_list);
    380      1.1     lukem 
    381  1.1.1.9  christos 	Debug( LDAP_DEBUG_TRACE, "matching_rule_use_init\n" );
    382      1.1     lukem 
    383      1.1     lukem 	LDAP_SLIST_FOREACH( mr, &mr_list, smr_next ) {
    384      1.1     lukem 		AttributeType	*at;
    385  1.1.1.2     lukem 		MatchingRuleUse	mru_storage = {{ 0 }},
    386      1.1     lukem 				*mru = &mru_storage;
    387      1.1     lukem 
    388      1.1     lukem 		char		**applies_oids = NULL;
    389      1.1     lukem 
    390      1.1     lukem 		mr->smr_mru = NULL;
    391      1.1     lukem 
    392      1.1     lukem 		/* hide rules marked as HIDE */
    393      1.1     lukem 		if ( mr->smr_usage & SLAP_MR_HIDE ) {
    394      1.1     lukem 			continue;
    395      1.1     lukem 		}
    396      1.1     lukem 
    397      1.1     lukem 		/* hide rules not marked as designed for extensibility */
    398      1.1     lukem 		/* MR_EXT means can be used any attribute type whose
    399      1.1     lukem 		 * syntax is same as the assertion syntax.
    400      1.1     lukem 		 * Another mechanism is needed where rule can be used
    401      1.1     lukem 		 * with attribute of other syntaxes.
    402      1.1     lukem 		 * Framework doesn't support this (yet).
    403      1.1     lukem 		 */
    404      1.1     lukem 
    405      1.1     lukem 		if (!( ( mr->smr_usage & SLAP_MR_EXT )
    406      1.1     lukem 			|| mr->smr_compat_syntaxes ) )
    407      1.1     lukem 		{
    408      1.1     lukem 			continue;
    409      1.1     lukem 		}
    410      1.1     lukem 
    411      1.1     lukem 		/*
    412      1.1     lukem 		 * Note: we're using the same values of the corresponding
    413      1.1     lukem 		 * MatchingRule structure; maybe we'd copy them ...
    414      1.1     lukem 		 */
    415      1.1     lukem 		mru->smru_mr = mr;
    416      1.1     lukem 		mru->smru_obsolete = mr->smr_obsolete;
    417      1.1     lukem 		mru->smru_applies_oids = NULL;
    418      1.1     lukem 		LDAP_SLIST_NEXT(mru, smru_next) = NULL;
    419      1.1     lukem 		mru->smru_oid = mr->smr_oid;
    420      1.1     lukem 		mru->smru_names = mr->smr_names;
    421      1.1     lukem 		mru->smru_desc = mr->smr_desc;
    422      1.1     lukem 
    423  1.1.1.9  christos 		Debug( LDAP_DEBUG_TRACE, "    %s (%s):\n",
    424  1.1.1.9  christos 				mru->smru_oid,
    425  1.1.1.9  christos 				mru->smru_names ? mru->smru_names[ 0 ] : "" );
    426      1.1     lukem 
    427      1.1     lukem 		at = NULL;
    428      1.1     lukem 		for ( at_start( &at ); at; at_next( &at ) ) {
    429      1.1     lukem 			if( at->sat_flags & SLAP_AT_HIDE ) continue;
    430      1.1     lukem 
    431      1.1     lukem 			if( mr_usable_with_at( mr, at )) {
    432      1.1     lukem 				ldap_charray_add( &applies_oids, at->sat_cname.bv_val );
    433      1.1     lukem 			}
    434      1.1     lukem 		}
    435      1.1     lukem 
    436      1.1     lukem 		/*
    437      1.1     lukem 		 * Note: the matchingRules that are not used
    438      1.1     lukem 		 * by any attributeType are not listed as
    439      1.1     lukem 		 * matchingRuleUse
    440      1.1     lukem 		 */
    441      1.1     lukem 		if ( applies_oids != NULL ) {
    442      1.1     lukem 			mru->smru_applies_oids = applies_oids;
    443      1.1     lukem 			{
    444      1.1     lukem 				char *str = ldap_matchingruleuse2str( &mru->smru_mruleuse );
    445  1.1.1.9  christos 				Debug( LDAP_DEBUG_TRACE, "       matchingRuleUse: %s\n", str );
    446      1.1     lukem 				ldap_memfree( str );
    447      1.1     lukem 			}
    448      1.1     lukem 
    449      1.1     lukem 			mru = (MatchingRuleUse *)ber_memalloc( sizeof( MatchingRuleUse ) );
    450      1.1     lukem 			/* call-forward from MatchingRule to MatchingRuleUse */
    451      1.1     lukem 			mr->smr_mru = mru;
    452      1.1     lukem 			/* copy static data to newly allocated struct */
    453      1.1     lukem 			*mru = mru_storage;
    454      1.1     lukem 			/* append the struct pointer to the end of the list */
    455      1.1     lukem 			*mru_ptr = mru;
    456      1.1     lukem 			/* update the list head pointer */
    457      1.1     lukem 			mru_ptr = &LDAP_SLIST_NEXT(mru,smru_next);
    458      1.1     lukem 		}
    459      1.1     lukem 	}
    460      1.1     lukem 
    461      1.1     lukem 	return( 0 );
    462      1.1     lukem }
    463      1.1     lukem 
    464      1.1     lukem int
    465      1.1     lukem mr_usable_with_at(
    466      1.1     lukem 	MatchingRule	*mr,
    467      1.1     lukem 	AttributeType	*at )
    468      1.1     lukem {
    469      1.1     lukem 	if ( ( mr->smr_usage & SLAP_MR_EXT ) && (
    470      1.1     lukem 		mr->smr_syntax == at->sat_syntax ||
    471      1.1     lukem 		mr == at->sat_equality ||
    472      1.1     lukem 		mr == at->sat_approx ||
    473      1.1     lukem 		syn_is_sup( at->sat_syntax, mr->smr_syntax ) ) )
    474      1.1     lukem 	{
    475      1.1     lukem 		return 1;
    476      1.1     lukem 	}
    477      1.1     lukem 
    478      1.1     lukem 	if ( mr->smr_compat_syntaxes ) {
    479      1.1     lukem 		int i;
    480      1.1     lukem 		for( i=0; mr->smr_compat_syntaxes[i]; i++ ) {
    481      1.1     lukem 			if( at->sat_syntax == mr->smr_compat_syntaxes[i] ) {
    482      1.1     lukem 				return 1;
    483      1.1     lukem 			}
    484      1.1     lukem 		}
    485      1.1     lukem 	}
    486      1.1     lukem 	return 0;
    487      1.1     lukem }
    488      1.1     lukem 
    489      1.1     lukem int mr_schema_info( Entry *e )
    490      1.1     lukem {
    491      1.1     lukem 	AttributeDescription *ad_matchingRules = slap_schema.si_ad_matchingRules;
    492      1.1     lukem 	MatchingRule *mr;
    493      1.1     lukem 	struct berval nval;
    494      1.1     lukem 
    495      1.1     lukem 	LDAP_SLIST_FOREACH(mr, &mr_list, smr_next ) {
    496      1.1     lukem 		if ( mr->smr_usage & SLAP_MR_HIDE ) {
    497      1.1     lukem 			/* skip hidden rules */
    498      1.1     lukem 			continue;
    499      1.1     lukem 		}
    500      1.1     lukem 
    501      1.1     lukem 		if ( ! mr->smr_match ) {
    502      1.1     lukem 			/* skip rules without matching functions */
    503      1.1     lukem 			continue;
    504      1.1     lukem 		}
    505      1.1     lukem 
    506      1.1     lukem 		if ( mr->smr_str.bv_val == NULL ) {
    507      1.1     lukem 			if ( ldap_matchingrule2bv( &mr->smr_mrule, &mr->smr_str ) == NULL ) {
    508      1.1     lukem 				return -1;
    509      1.1     lukem 			}
    510      1.1     lukem 		}
    511      1.1     lukem #if 0
    512      1.1     lukem 		Debug( LDAP_DEBUG_TRACE, "Merging mr [%lu] %s\n",
    513  1.1.1.9  christos 			mr->smr_str.bv_len, mr->smr_str.bv_val );
    514      1.1     lukem #endif
    515      1.1     lukem 
    516      1.1     lukem 		nval.bv_val = mr->smr_oid;
    517      1.1     lukem 		nval.bv_len = strlen(mr->smr_oid);
    518      1.1     lukem 		if( attr_merge_one( e, ad_matchingRules, &mr->smr_str, &nval ) ) {
    519      1.1     lukem 			return -1;
    520      1.1     lukem 		}
    521      1.1     lukem 	}
    522      1.1     lukem 	return 0;
    523      1.1     lukem }
    524      1.1     lukem 
    525      1.1     lukem int mru_schema_info( Entry *e )
    526      1.1     lukem {
    527      1.1     lukem 	AttributeDescription *ad_matchingRuleUse
    528      1.1     lukem 		= slap_schema.si_ad_matchingRuleUse;
    529      1.1     lukem 	MatchingRuleUse	*mru;
    530      1.1     lukem 	struct berval nval;
    531      1.1     lukem 
    532      1.1     lukem 	LDAP_SLIST_FOREACH( mru, &mru_list, smru_next ) {
    533      1.1     lukem 		assert( !( mru->smru_usage & SLAP_MR_HIDE ) );
    534      1.1     lukem 
    535      1.1     lukem 		if ( mru->smru_str.bv_val == NULL ) {
    536      1.1     lukem 			if ( ldap_matchingruleuse2bv( &mru->smru_mruleuse, &mru->smru_str )
    537      1.1     lukem 					== NULL ) {
    538      1.1     lukem 				return -1;
    539      1.1     lukem 			}
    540      1.1     lukem 		}
    541      1.1     lukem 
    542      1.1     lukem #if 0
    543      1.1     lukem 		Debug( LDAP_DEBUG_TRACE, "Merging mru [%lu] %s\n",
    544  1.1.1.9  christos 			mru->smru_str.bv_len, mru->smru_str.bv_val );
    545      1.1     lukem #endif
    546      1.1     lukem 
    547      1.1     lukem 		nval.bv_val = mru->smru_oid;
    548      1.1     lukem 		nval.bv_len = strlen(mru->smru_oid);
    549      1.1     lukem 		if( attr_merge_one( e, ad_matchingRuleUse, &mru->smru_str, &nval ) ) {
    550      1.1     lukem 			return -1;
    551      1.1     lukem 		}
    552      1.1     lukem 	}
    553      1.1     lukem 	return 0;
    554      1.1     lukem }
    555