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 ) {
119 rc = ber_scanf( ber, "t", &tag );
121 if( rc == LBER_ERROR ) {
123 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
124 "get_mra: ber_scanf (\"t\") failure.\n" ));
126 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
129 *text = "Error parsing matching rule assertion";
131 return SLAPD_DISCONNECT;
135 if ( tag != LDAP_FILTER_EXT_VALUE ) {
137 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
138 "get_mra: ber_scanf missing value\n" ));
140 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf missing value\n", 0, 0, 0 );
143 *text = "Missing value in matching rule assertion";
145 return SLAPD_DISCONNECT;
148 rc = ber_scanf( ber, "o", &value );
150 if( rc == LBER_ERROR ) {
152 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
153 "get_mra: ber_scanf (\"o\") failure.\n" ));
155 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
158 *text = "Error decoding value in matching rule assertion";
160 return SLAPD_DISCONNECT;
164 * OK, if no matching rule, normalize for equality, otherwise
165 * normalize for the matching rule.
167 rc = value_normalize( ma->ma_desc, SLAP_MR_EQUALITY, &value, &nvalue, text );
168 ch_free( value.bv_val );
170 if( rc != LDAP_SUCCESS ) {
175 ma->ma_value = nvalue;
177 tag = ber_peek_tag( ber, &length );
179 if ( tag == LDAP_FILTER_EXT_DNATTRS ) {
180 rc = ber_scanf( ber, "b}", &ma->ma_dnattrs );
182 rc = ber_scanf( ber, "}" );
186 if( rc == LBER_ERROR ) {
188 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
189 "get_mra: ber_scanf failure\n"));
191 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
194 *text = "Error decoding dnattrs matching rule assertion";
196 return SLAPD_DISCONNECT;