3 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 /* mra.c - routines for dealing with extensible matching rule assertions */
12 #include <ac/string.h>
13 #include <ac/socket.h>
20 MatchingRuleAssertion *mra,
24 ch_free( mra->ma_value.bv_val );
26 ch_free( (char *) mra );
33 MatchingRuleAssertion **mra,
40 struct berval type = { 0, NULL }, value;
41 MatchingRuleAssertion *ma;
43 ma = ch_malloc( sizeof( MatchingRuleAssertion ) );
45 ma->ma_rule_text.bv_len = 0;
46 ma->ma_rule_text.bv_val = NULL;
49 ma->ma_value.bv_len = 0;
50 ma->ma_value.bv_val = NULL;
52 rtag = ber_scanf( ber, "{t", &tag );
54 if( rtag == LBER_ERROR ) {
56 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
57 "get_mra: ber_scanf (\"{t\") failure\n" ));
59 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
62 *text = "Error parsing matching rule assertion";
64 return SLAPD_DISCONNECT;
67 if ( tag == LDAP_FILTER_EXT_OID ) {
68 rtag = ber_scanf( ber, "m", &ma->ma_rule_text );
69 if ( rtag == LBER_ERROR ) {
71 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
72 "get_mra: ber_scanf(\"o\") failure.\n" ));
74 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf for mr\n", 0, 0, 0 );
77 *text = "Error parsing matching rule in matching rule assertion";
79 return SLAPD_DISCONNECT;
82 rtag = ber_scanf( ber, "t", &tag );
83 if( rtag == LBER_ERROR ) {
85 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
86 "get_mra: ber_scanf (\"t\") failure\n" ));
88 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
91 *text = "Error parsing matching rule assertion";
93 return SLAPD_DISCONNECT;
97 if ( tag == LDAP_FILTER_EXT_TYPE ) {
98 rtag = ber_scanf( ber, "m", &type );
99 if ( rtag == LBER_ERROR ) {
101 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
102 "get_mra: ber_scanf (\"o\") failure.\n" ));
104 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf for ad\n", 0, 0, 0 );
107 *text = "Error parsing attribute description in matching rule assertion";
108 return SLAPD_DISCONNECT;
111 rtag = ber_scanf( ber, "t", &tag );
112 if( rtag == LBER_ERROR ) {
114 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
115 "get_mra: ber_scanf (\"t\") failure.\n" ));
117 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
120 *text = "Error parsing matching rule assertion";
122 return SLAPD_DISCONNECT;
126 if ( tag != LDAP_FILTER_EXT_VALUE ) {
128 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
129 "get_mra: ber_scanf missing value\n" ));
131 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf missing value\n", 0, 0, 0 );
134 *text = "Missing value in matching rule assertion";
136 return SLAPD_DISCONNECT;
139 rtag = ber_scanf( ber, "m", &value );
141 if( rtag == LBER_ERROR ) {
143 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
144 "get_mra: ber_scanf (\"o\") failure.\n" ));
146 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
149 *text = "Error decoding value in matching rule assertion";
151 return SLAPD_DISCONNECT;
154 tag = ber_peek_tag( ber, &length );
156 if ( tag == LDAP_FILTER_EXT_DNATTRS ) {
157 rtag = ber_scanf( ber, "b}", &ma->ma_dnattrs );
159 rtag = ber_scanf( ber, "}" );
162 if( rtag == LBER_ERROR ) {
164 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
165 "get_mra: ber_scanf failure\n"));
167 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
170 *text = "Error decoding dnattrs matching rule assertion";
172 return SLAPD_DISCONNECT;
175 if( ma->ma_dnattrs ) {
176 *text = "matching with \":dn\" not supported";
177 return LDAP_INAPPROPRIATE_MATCHING;
180 if( type.bv_val != NULL ) {
181 rc = slap_bv2ad( &type, &ma->ma_desc, text );
182 if( rc != LDAP_SUCCESS ) {
188 *text = "matching without attribute description rule not supported";
189 return LDAP_INAPPROPRIATE_MATCHING;
192 if( ma->ma_rule_text.bv_val != NULL ) {
193 ma->ma_rule = mr_bvfind( &ma->ma_rule_text );
194 if( ma->ma_rule == NULL ) {
196 *text = "matching rule not recognized";
197 return LDAP_INAPPROPRIATE_MATCHING;
201 if( ma->ma_desc != NULL &&
202 ma->ma_desc->ad_type->sat_equality != NULL &&
203 ma->ma_desc->ad_type->sat_equality->smr_usage & SLAP_MR_EXT )
205 /* no matching rule was provided, use the attribute's
206 equality rule if it supports extensible matching. */
207 ma->ma_rule = ma->ma_desc->ad_type->sat_equality;
211 return LDAP_INAPPROPRIATE_MATCHING;
214 /* check to see if the matching rule is appropriate for
215 the syntax of the attribute. This check will need
216 to be extended to support other kinds of extensible
218 if( strcmp( ma->ma_rule->smr_syntax->ssyn_oid,
219 ma->ma_desc->ad_type->sat_syntax->ssyn_oid ) != 0 )
222 return LDAP_INAPPROPRIATE_MATCHING;
226 * OK, if no matching rule, normalize for equality, otherwise
227 * normalize for the matching rule.
229 rc = value_validate_normalize( ma->ma_desc, SLAP_MR_EQUALITY,
230 &value, &ma->ma_value, text );
232 if( rc != LDAP_SUCCESS ) {