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_rule_text.bv_val );
25 ch_free( mra->ma_value.bv_val );
27 ch_free( (char *) mra );
34 MatchingRuleAssertion **mra,
40 struct berval type, value;
41 MatchingRuleAssertion *ma;
43 ma = ch_malloc( sizeof( MatchingRuleAssertion ) );
45 ma->ma_rule_text.bv_val = NULL;
46 ma->ma_rule_text.bv_len = 0;
49 ma->ma_value.bv_val = NULL;
51 rc = ber_scanf( ber, "{t", &tag );
53 if( rc == LBER_ERROR ) {
55 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
56 "get_mra: ber_scanf (\"{t\") failure\n" ));
58 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
61 *text = "Error parsing matching rule assertion";
63 return SLAPD_DISCONNECT;
66 if ( tag == LDAP_FILTER_EXT_OID ) {
67 rc = ber_scanf( ber, "o", &ma->ma_rule_text );
68 if ( rc == LBER_ERROR ) {
70 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
71 "get_mra: ber_scanf(\"o\") failure.\n" ));
73 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf for mr\n", 0, 0, 0 );
76 *text = "Error parsing matching rule in matching rule assertion";
78 return SLAPD_DISCONNECT;
80 ma->ma_rule = mr_bvfind( &ma->ma_rule_text );
82 rc = ber_scanf( ber, "t", &tag );
84 if( rc == LBER_ERROR ) {
86 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
87 "get_mra: ber_scanf (\"t\") failure\n" ));
89 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
92 *text = "Error parsing matching rule assertion";
94 return SLAPD_DISCONNECT;
98 if ( tag == LDAP_FILTER_EXT_TYPE ) {
99 rc = ber_scanf( ber, "o", &type );
100 if ( rc == LBER_ERROR ) {
102 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
103 "get_mra: ber_scanf (\"o\") failure.\n" ));
105 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf for ad\n", 0, 0, 0 );
108 *text = "Error parsing attribute description in matching rule assertion";
109 return SLAPD_DISCONNECT;
112 rc = slap_bv2ad( &type, &ma->ma_desc, text );
113 ch_free( type.bv_val );
115 if( rc != LDAP_SUCCESS ) {
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, &ma->ma_value, text );
169 ch_free( value.bv_val );
171 if( rc != LDAP_SUCCESS ) {
176 tag = ber_peek_tag( ber, &length );
178 if ( tag == LDAP_FILTER_EXT_DNATTRS ) {
179 rc = ber_scanf( ber, "b}", &ma->ma_dnattrs );
181 rc = ber_scanf( ber, "}" );
185 if( rc == LBER_ERROR ) {
187 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
188 "get_mra: ber_scanf failure\n"));
190 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
193 *text = "Error decoding dnattrs matching rule assertion";
195 return SLAPD_DISCONNECT;