3 * Copyright 1998-2003 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 /* op->o_tmpfree( mra->ma_value.bv_val, op->o_tmpmemctx ); */
25 ch_free( mra->ma_value.bv_val );
27 op->o_tmpfree( (char *) mra, op->o_tmpmemctx );
35 MatchingRuleAssertion **mra,
42 struct berval type = { 0, NULL };
43 struct berval value = { 0, NULL };
44 struct berval rule_text = { 0, NULL };
45 MatchingRuleAssertion ma;
47 memset( &ma, 0, sizeof ma);
49 rtag = ber_scanf( ber, "{t" /*"}"*/, &tag );
51 if( rtag == LBER_ERROR ) {
53 LDAP_LOG( OPERATION, ERR,
54 "get_mra: ber_scanf (\"{t\") failure\n", 0, 0, 0 );
56 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
59 *text = "Error parsing matching rule assertion";
60 return SLAPD_DISCONNECT;
63 if ( tag == LDAP_FILTER_EXT_OID ) {
64 rtag = ber_scanf( ber, "m", &rule_text );
65 if ( rtag == LBER_ERROR ) {
67 LDAP_LOG( OPERATION, ERR,
68 "get_mra: ber_scanf(\"o\") failure.\n", 0, 0, 0 );
70 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf for mr\n", 0, 0, 0 );
73 *text = "Error parsing matching rule in matching rule assertion";
74 return SLAPD_DISCONNECT;
77 rtag = ber_scanf( ber, "t", &tag );
78 if( rtag == LBER_ERROR ) {
80 LDAP_LOG( OPERATION, ERR,
81 "get_mra: ber_scanf (\"t\") failure\n", 0, 0, 0 );
83 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
86 *text = "Error parsing matching rule assertion";
87 return SLAPD_DISCONNECT;
91 if ( tag == LDAP_FILTER_EXT_TYPE ) {
92 rtag = ber_scanf( ber, "m", &type );
93 if ( rtag == LBER_ERROR ) {
95 LDAP_LOG( OPERATION, ERR,
96 "get_mra: ber_scanf (\"o\") failure.\n", 0, 0, 0 );
98 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf for ad\n", 0, 0, 0 );
101 *text = "Error parsing attribute description in matching rule assertion";
102 return SLAPD_DISCONNECT;
105 rtag = ber_scanf( ber, "t", &tag );
106 if( rtag == LBER_ERROR ) {
108 LDAP_LOG( OPERATION, ERR,
109 "get_mra: ber_scanf (\"t\") failure.\n", 0, 0, 0 );
111 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
114 *text = "Error parsing matching rule assertion";
115 return SLAPD_DISCONNECT;
119 if ( tag != LDAP_FILTER_EXT_VALUE ) {
121 LDAP_LOG( OPERATION, ERR,
122 "get_mra: ber_scanf missing value\n", 0, 0, 0 );
124 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf missing value\n", 0, 0, 0 );
127 *text = "Missing value in matching rule assertion";
128 return SLAPD_DISCONNECT;
131 rtag = ber_scanf( ber, "m", &value );
133 if( rtag == LBER_ERROR ) {
135 LDAP_LOG( OPERATION, ERR,
136 "get_mra: ber_scanf (\"o\") failure.\n", 0, 0, 0 );
138 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
141 *text = "Error decoding value in matching rule assertion";
142 return SLAPD_DISCONNECT;
145 tag = ber_peek_tag( ber, &length );
147 if ( tag == LDAP_FILTER_EXT_DNATTRS ) {
148 rtag = ber_scanf( ber, /*"{"*/ "b}", &ma.ma_dnattrs );
150 rtag = ber_scanf( ber, /*"{"*/ "}" );
153 if( rtag == LBER_ERROR ) {
155 LDAP_LOG( OPERATION, ERR, "get_mra: ber_scanf failure\n", 0, 0, 0);
157 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
160 *text = "Error decoding dnattrs matching rule assertion";
161 return SLAPD_DISCONNECT;
164 if( type.bv_val != NULL ) {
165 rc = slap_bv2ad( &type, &ma.ma_desc, text );
166 if( rc != LDAP_SUCCESS ) {
171 if( rule_text.bv_val != NULL ) {
172 ma.ma_rule = mr_bvfind( &rule_text );
173 if( ma.ma_rule == NULL ) {
174 *text = "matching rule not recognized";
175 return LDAP_INAPPROPRIATE_MATCHING;
179 if ( ma.ma_rule == NULL ) {
181 * Need either type or rule ...
183 if ( ma.ma_desc == NULL ) {
184 *text = "no matching rule or type";
185 return LDAP_INAPPROPRIATE_MATCHING;
188 if ( ma.ma_desc->ad_type->sat_equality != NULL &&
189 ma.ma_desc->ad_type->sat_equality->smr_usage & SLAP_MR_EXT )
191 /* no matching rule was provided, use the attribute's
192 equality rule if it supports extensible matching. */
193 ma.ma_rule = ma.ma_desc->ad_type->sat_equality;
196 *text = "no appropriate rule to use for type";
197 return LDAP_INAPPROPRIATE_MATCHING;
201 if ( ma.ma_desc != NULL ) {
202 if( !mr_usable_with_at( ma.ma_rule, ma.ma_desc->ad_type ) ) {
203 *text = "matching rule use with this attribute not appropriate";
204 return LDAP_INAPPROPRIATE_MATCHING;
210 * Normalize per matching rule
212 rc = asserted_value_validate_normalize( ma.ma_desc,
214 SLAP_MR_EXT|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
215 &value, &ma.ma_value, text, op->o_tmpmemctx );
217 if( rc != LDAP_SUCCESS ) {
222 /* Append rule_text to end of struct */
223 if (rule_text.bv_val) length += rule_text.bv_len + 1;
224 *mra = op->o_tmpalloc( length, op->o_tmpmemctx );
226 if (rule_text.bv_val) {
227 (*mra)->ma_rule_text.bv_len = rule_text.bv_len;
228 (*mra)->ma_rule_text.bv_val = (char *)(*mra+1);
229 AC_MEMCPY((*mra)->ma_rule_text.bv_val, rule_text.bv_val,