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 ) {
54 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
55 *text = "Error parsing matching rule assertion";
57 return SLAPD_DISCONNECT;
60 if ( tag == LDAP_FILTER_EXT_OID ) {
61 rc = ber_scanf( ber, "a", &ma->ma_rule_text );
62 if ( rc == LBER_ERROR ) {
63 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf for mr\n", 0, 0, 0 );
64 *text = "Error parsing matching rule in matching rule assertion";
66 return SLAPD_DISCONNECT;
68 ma->ma_rule = mr_find( ma->ma_rule_text );
70 rc = ber_scanf( ber, "t", &tag );
72 if( rc == LBER_ERROR ) {
73 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
74 *text = "Error parsing matching rule assertion";
76 return SLAPD_DISCONNECT;
80 if ( tag == LDAP_FILTER_EXT_TYPE ) {
81 rc = ber_scanf( ber, "o", &type );
82 if ( rc == LBER_ERROR ) {
83 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf for ad\n", 0, 0, 0 );
84 *text = "Error parsing attribute description in matching rule assertion";
85 return SLAPD_DISCONNECT;
88 rc = slap_bv2ad( &type, &ma->ma_desc, text );
89 ch_free( type.bv_val );
91 if( rc != LDAP_SUCCESS ) {
92 ch_free( value.bv_val );
97 rc = ber_scanf( ber, "t", &tag );
99 if( rc == LBER_ERROR ) {
100 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
101 *text = "Error parsing matching rule assertion";
103 return SLAPD_DISCONNECT;
107 if ( tag != LDAP_FILTER_EXT_VALUE ) {
108 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf missing value\n", 0, 0, 0 );
109 *text = "Missing value in matching rule assertion";
111 return SLAPD_DISCONNECT;
114 rc = ber_scanf( ber, "o", &value );
116 if( rc == LBER_ERROR ) {
117 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
118 *text = "Error decoding value in matching rule assertion";
120 return SLAPD_DISCONNECT;
124 * OK, if no matching rule, normalize for equality, otherwise
125 * normalize for the matching rule.
127 rc = value_normalize( ma->ma_desc, SLAP_MR_EQUALITY, &value, &nvalue, text );
128 ch_free( value.bv_val );
130 if( rc != LDAP_SUCCESS ) {
135 ma->ma_value = nvalue;
137 tag = ber_peek_tag( ber, &length );
139 if ( tag == LDAP_FILTER_EXT_DNATTRS ) {
140 rc = ber_scanf( ber, "b}", &ma->ma_dnattrs );
142 rc = ber_scanf( ber, "}" );
146 if( rc == LBER_ERROR ) {
147 Debug( LDAP_DEBUG_ANY, " get_mra ber_scanf\n", 0, 0, 0 );
148 *text = "Error decoding dnattrs matching rule assertion";
150 return SLAPD_DISCONNECT;