]> git.sur5r.net Git - openldap/blob - servers/slapd/mra.c
add new ber dump routine (behind NEW_LOGGING)
[openldap] / servers / slapd / mra.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 /* mra.c - routines for dealing with extensible matching rule assertions */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/string.h>
13 #include <ac/socket.h>
14
15 #include "slap.h"
16
17
18 void
19 mra_free(
20     MatchingRuleAssertion *mra,
21     int freeit
22 )
23 {
24         ad_free( mra->ma_desc, 1 );
25         ch_free( mra->ma_rule_text );
26         ber_bvfree( mra->ma_value );
27         if ( freeit ) {
28                 ch_free( (char *) mra );
29         }
30 }
31
32 int
33 get_mra(
34     BerElement  *ber,
35     MatchingRuleAssertion       **mra,
36         const char **text
37 )
38 {
39         int rc, tag;
40         ber_len_t length;
41         struct berval type, value, *nvalue;
42         MatchingRuleAssertion *ma;
43
44         ma = ch_malloc( sizeof( MatchingRuleAssertion ) );
45         ma->ma_rule = NULL;
46         ma->ma_rule_text = NULL;
47         ma->ma_desc = NULL;
48         ma->ma_dnattrs = 0;
49         ma->ma_value = NULL;
50
51         rc = ber_scanf( ber, "{t", &tag );
52
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";
56                 mra_free( ma, 1 );
57                 return SLAPD_DISCONNECT;
58         }
59
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";
65                         mra_free( ma, 1 );
66                         return SLAPD_DISCONNECT;
67                 }
68                 ma->ma_rule = mr_find( ma->ma_rule_text );
69
70                 rc = ber_scanf( ber, "t", &tag );
71
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";
75                         mra_free( ma, 1 );
76                         return SLAPD_DISCONNECT;
77                 }
78         }
79
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;
86                 }
87
88                 rc = slap_bv2ad( &type, &ma->ma_desc, text );
89                 ch_free( type.bv_val );
90
91                 if( rc != LDAP_SUCCESS ) {
92                         ch_free( value.bv_val );
93                         mra_free( ma, 1 );
94                         return rc;
95                 }
96
97                 rc = ber_scanf( ber, "t", &tag );
98
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";
102                         mra_free( ma, 1 );
103                         return SLAPD_DISCONNECT;
104                 }
105         }
106
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";
110                 mra_free( ma, 1 );
111                 return SLAPD_DISCONNECT;
112         }
113
114         rc = ber_scanf( ber, "o", &value );
115
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";
119                 mra_free( ma, 1 );
120                 return SLAPD_DISCONNECT;
121         }
122
123         /*
124          * OK, if no matching rule, normalize for equality, otherwise
125          * normalize for the matching rule.
126          */
127         rc = value_normalize( ma->ma_desc, SLAP_MR_EQUALITY, &value, &nvalue, text );
128         ch_free( value.bv_val );
129
130         if( rc != LDAP_SUCCESS ) {
131                 mra_free( ma, 1 );
132                 return rc;
133         }
134
135         ma->ma_value = nvalue;
136
137         tag = ber_peek_tag( ber, &length );
138
139         if ( tag == LDAP_FILTER_EXT_DNATTRS ) {
140                 rc = ber_scanf( ber, "b}", &ma->ma_dnattrs );
141         } else {
142                 rc = ber_scanf( ber, "}" );
143                 ma->ma_dnattrs = 0;
144         }
145
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";
149                 mra_free( ma, 1 );
150                 return SLAPD_DISCONNECT;
151         }
152
153         *mra = ma;
154
155         return LDAP_SUCCESS;
156 }
157