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 #if 0 /* no longer a malloc'd string */
25 ch_free( mra->ma_rule_text.bv_val );
27 ch_free( mra->ma_value.bv_val );
29 ch_free( (char *) mra );
36 MatchingRuleAssertion **mra,
42 struct berval type, value;
43 MatchingRuleAssertion *ma;
45 ma = ch_malloc( sizeof( MatchingRuleAssertion ) );
47 ma->ma_rule_text.bv_val = NULL;
48 ma->ma_rule_text.bv_len = 0;
51 ma->ma_value.bv_val = NULL;
53 rc = ber_scanf( ber, "{t", &tag );
55 if( rc == LBER_ERROR ) {
57 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
58 "get_mra: ber_scanf (\"{t\") failure\n" ));
60 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
63 *text = "Error parsing matching rule assertion";
65 return SLAPD_DISCONNECT;
68 if ( tag == LDAP_FILTER_EXT_OID ) {
69 rc = ber_scanf( ber, "m", &ma->ma_rule_text );
70 if ( rc == LBER_ERROR ) {
72 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
73 "get_mra: ber_scanf(\"o\") failure.\n" ));
75 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf for mr\n", 0, 0, 0 );
78 *text = "Error parsing matching rule in matching rule assertion";
80 return SLAPD_DISCONNECT;
82 ma->ma_rule = mr_bvfind( &ma->ma_rule_text );
84 rc = ber_scanf( ber, "t", &tag );
86 if( rc == LBER_ERROR ) {
88 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
89 "get_mra: ber_scanf (\"t\") failure\n" ));
91 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
94 *text = "Error parsing matching rule assertion";
96 return SLAPD_DISCONNECT;
100 if ( tag == LDAP_FILTER_EXT_TYPE ) {
101 rc = ber_scanf( ber, "m", &type );
102 if ( rc == LBER_ERROR ) {
104 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
105 "get_mra: ber_scanf (\"o\") failure.\n" ));
107 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf for ad\n", 0, 0, 0 );
110 *text = "Error parsing attribute description in matching rule assertion";
111 return SLAPD_DISCONNECT;
114 rc = slap_bv2ad( &type, &ma->ma_desc, text );
116 if( rc != LDAP_SUCCESS ) {
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, "m", &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, &ma->ma_value, text );
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;