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