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 ad_free( mra->ma_desc, 1 );
25 ch_free( mra->ma_rule_text );
26 ber_bvfree( mra->ma_value );
28 ch_free( (char *) mra );
35 MatchingRuleAssertion **mra,
41 struct berval type, value, *nvalue;
42 MatchingRuleAssertion *ma;
44 ma = ch_malloc( sizeof( MatchingRuleAssertion ) );
46 ma->ma_rule_text = 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, "a", &ma->ma_rule_text );
68 if ( rc == LBER_ERROR ) {
70 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
71 "get_mra: ber_scanf(\"a\") 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_find( 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 ) {
116 ch_free( value.bv_val );
121 rc = ber_scanf( ber, "t", &tag );
123 if( rc == LBER_ERROR ) {
125 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
126 "get_mra: ber_scanf (\"t\") failure.\n" ));
128 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
131 *text = "Error parsing matching rule assertion";
133 return SLAPD_DISCONNECT;
137 if ( tag != LDAP_FILTER_EXT_VALUE ) {
139 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
140 "get_mra: ber_scanf missing value\n" ));
142 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf missing value\n", 0, 0, 0 );
145 *text = "Missing value in matching rule assertion";
147 return SLAPD_DISCONNECT;
150 rc = ber_scanf( ber, "o", &value );
152 if( rc == LBER_ERROR ) {
154 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
155 "get_mra: ber_scanf (\"o\") failure.\n" ));
157 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
160 *text = "Error decoding value in matching rule assertion";
162 return SLAPD_DISCONNECT;
166 * OK, if no matching rule, normalize for equality, otherwise
167 * normalize for the matching rule.
169 rc = value_normalize( ma->ma_desc, SLAP_MR_EQUALITY, &value, &nvalue, text );
170 ch_free( value.bv_val );
172 if( rc != LDAP_SUCCESS ) {
177 ma->ma_value = nvalue;
179 tag = ber_peek_tag( ber, &length );
181 if ( tag == LDAP_FILTER_EXT_DNATTRS ) {
182 rc = ber_scanf( ber, "b}", &ma->ma_dnattrs );
184 rc = ber_scanf( ber, "}" );
188 if( rc == LBER_ERROR ) {
190 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
191 "get_mra: ber_scanf failure\n"));
193 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
196 *text = "Error decoding dnattrs matching rule assertion";
198 return SLAPD_DISCONNECT;