3 * Copyright 1998-2000 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_rule_text );
25 ber_bvfree( mra->ma_value );
27 ch_free( (char *) mra );
34 MatchingRuleAssertion **mra,
40 struct berval type, value, *nvalue;
41 MatchingRuleAssertion *ma;
43 ma = ch_malloc( sizeof( MatchingRuleAssertion ) );
45 ma->ma_rule_text = NULL;
50 rc = ber_scanf( ber, "{t", &tag );
52 if( rc == LBER_ERROR ) {
54 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
55 "get_mra: ber_scanf (\"{t\") failure\n" ));
57 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
60 *text = "Error parsing matching rule assertion";
62 return SLAPD_DISCONNECT;
65 if ( tag == LDAP_FILTER_EXT_OID ) {
66 rc = ber_scanf( ber, "a", &ma->ma_rule_text );
67 if ( rc == LBER_ERROR ) {
69 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
70 "get_mra: ber_scanf(\"a\") failure.\n" ));
72 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf for mr\n", 0, 0, 0 );
75 *text = "Error parsing matching rule in matching rule assertion";
77 return SLAPD_DISCONNECT;
79 ma->ma_rule = mr_find( ma->ma_rule_text );
81 rc = ber_scanf( ber, "t", &tag );
83 if( rc == 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 rc = ber_scanf( ber, "o", &type );
99 if ( rc == 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 rc = slap_bv2ad( &type, &ma->ma_desc, text );
112 ch_free( type.bv_val );
114 if( rc != LDAP_SUCCESS ) {
115 ch_free( value.bv_val );
120 rc = ber_scanf( ber, "t", &tag );
122 if( rc == LBER_ERROR ) {
124 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
125 "get_mra: ber_scanf (\"t\") failure.\n" ));
127 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
130 *text = "Error parsing matching rule assertion";
132 return SLAPD_DISCONNECT;
136 if ( tag != LDAP_FILTER_EXT_VALUE ) {
138 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
139 "get_mra: ber_scanf missing value\n" ));
141 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf missing value\n", 0, 0, 0 );
144 *text = "Missing value in matching rule assertion";
146 return SLAPD_DISCONNECT;
149 rc = ber_scanf( ber, "o", &value );
151 if( rc == LBER_ERROR ) {
153 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
154 "get_mra: ber_scanf (\"o\") failure.\n" ));
156 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
159 *text = "Error decoding value in matching rule assertion";
161 return SLAPD_DISCONNECT;
165 * OK, if no matching rule, normalize for equality, otherwise
166 * normalize for the matching rule.
168 rc = value_normalize( ma->ma_desc, SLAP_MR_EQUALITY, &value, &nvalue, text );
169 ch_free( value.bv_val );
171 if( rc != LDAP_SUCCESS ) {
176 ma->ma_value = nvalue;
178 tag = ber_peek_tag( ber, &length );
180 if ( tag == LDAP_FILTER_EXT_DNATTRS ) {
181 rc = ber_scanf( ber, "b}", &ma->ma_dnattrs );
183 rc = ber_scanf( ber, "}" );
187 if( rc == LBER_ERROR ) {
189 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
190 "get_mra: ber_scanf failure\n"));
192 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
195 *text = "Error decoding dnattrs matching rule assertion";
197 return SLAPD_DISCONNECT;