]> git.sur5r.net Git - openldap/blob - servers/slapd/mra.c
temporary variable erroneously inside #ifdef (ITS#1503)
[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         ch_free( mra->ma_rule_text );
25         ber_bvfree( mra->ma_value );
26         if ( freeit ) {
27                 ch_free( (char *) mra );
28         }
29 }
30
31 int
32 get_mra(
33     BerElement  *ber,
34     MatchingRuleAssertion       **mra,
35         const char **text
36 )
37 {
38         int rc, tag;
39         ber_len_t length;
40         struct berval type, value, *nvalue;
41         MatchingRuleAssertion *ma;
42
43         ma = ch_malloc( sizeof( MatchingRuleAssertion ) );
44         ma->ma_rule = NULL;
45         ma->ma_rule_text = NULL;
46         ma->ma_desc = NULL;
47         ma->ma_dnattrs = 0;
48         ma->ma_value = NULL;
49
50         rc = ber_scanf( ber, "{t", &tag );
51
52         if( rc == LBER_ERROR ) {
53 #ifdef NEW_LOGGING
54                 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
55                            "get_mra: ber_scanf (\"{t\") failure\n" ));
56 #else
57                 Debug( LDAP_DEBUG_ANY, "  get_mra ber_scanf\n", 0, 0, 0 );
58 #endif
59
60                 *text = "Error parsing matching rule assertion";
61                 mra_free( ma, 1 );
62                 return SLAPD_DISCONNECT;
63         }
64
65         if ( tag == LDAP_FILTER_EXT_OID ) {
66                 rc = ber_scanf( ber, "a", &ma->ma_rule_text );
67                 if ( rc == LBER_ERROR ) {
68 #ifdef NEW_LOGGING
69                         LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
70                                    "get_mra: ber_scanf(\"a\") failure.\n" ));
71 #else
72                         Debug( LDAP_DEBUG_ANY, "  get_mra ber_scanf for mr\n", 0, 0, 0 );
73 #endif
74
75                         *text = "Error parsing matching rule in matching rule assertion";
76                         mra_free( ma, 1 );
77                         return SLAPD_DISCONNECT;
78                 }
79                 ma->ma_rule = mr_find( ma->ma_rule_text );
80
81                 rc = ber_scanf( ber, "t", &tag );
82
83                 if( rc == LBER_ERROR ) {
84 #ifdef NEW_LOGGING
85                         LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
86                                    "get_mra: ber_scanf (\"t\") failure\n" ));
87 #else
88                         Debug( LDAP_DEBUG_ANY, "  get_mra ber_scanf\n", 0, 0, 0 );
89 #endif
90
91                         *text = "Error parsing matching rule assertion";
92                         mra_free( ma, 1 );
93                         return SLAPD_DISCONNECT;
94                 }
95         }
96
97         if ( tag == LDAP_FILTER_EXT_TYPE ) {
98                 rc = ber_scanf( ber, "o", &type );
99                 if ( rc == LBER_ERROR ) {
100 #ifdef NEW_LOGGING
101                         LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
102                                    "get_mra: ber_scanf (\"o\") failure.\n" ));
103 #else
104                         Debug( LDAP_DEBUG_ANY, "  get_mra ber_scanf for ad\n", 0, 0, 0 );
105 #endif
106
107                         *text = "Error parsing attribute description in matching rule assertion";
108                         return SLAPD_DISCONNECT;
109                 }
110
111                 rc = slap_bv2ad( &type, &ma->ma_desc, text );
112                 ch_free( type.bv_val );
113
114                 if( rc != LDAP_SUCCESS ) {
115                         mra_free( ma, 1 );
116                         return rc;
117                 }
118
119                 rc = ber_scanf( ber, "t", &tag );
120
121                 if( rc == LBER_ERROR ) {
122 #ifdef NEW_LOGGING
123                         LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
124                                    "get_mra: ber_scanf (\"t\") failure.\n" ));
125 #else
126                         Debug( LDAP_DEBUG_ANY, "  get_mra ber_scanf\n", 0, 0, 0 );
127 #endif
128
129                         *text = "Error parsing matching rule assertion";
130                         mra_free( ma, 1 );
131                         return SLAPD_DISCONNECT;
132                 }
133         }
134
135         if ( tag != LDAP_FILTER_EXT_VALUE ) {
136 #ifdef NEW_LOGGING
137                 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
138                            "get_mra: ber_scanf missing value\n" ));
139 #else
140                 Debug( LDAP_DEBUG_ANY, "  get_mra ber_scanf missing value\n", 0, 0, 0 );
141 #endif
142
143                 *text = "Missing value in matching rule assertion";
144                 mra_free( ma, 1 );
145                 return SLAPD_DISCONNECT;
146         }
147
148         rc = ber_scanf( ber, "o", &value );
149
150         if( rc == LBER_ERROR ) {
151 #ifdef NEW_LOGGING
152                 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
153                            "get_mra: ber_scanf (\"o\") failure.\n" ));
154 #else
155                 Debug( LDAP_DEBUG_ANY, "  get_mra ber_scanf\n", 0, 0, 0 );
156 #endif
157
158                 *text = "Error decoding value in matching rule assertion";
159                 mra_free( ma, 1 );
160                 return SLAPD_DISCONNECT;
161         }
162
163         /*
164          * OK, if no matching rule, normalize for equality, otherwise
165          * normalize for the matching rule.
166          */
167         rc = value_normalize( ma->ma_desc, SLAP_MR_EQUALITY, &value, &nvalue, text );
168         ch_free( value.bv_val );
169
170         if( rc != LDAP_SUCCESS ) {
171                 mra_free( ma, 1 );
172                 return rc;
173         }
174
175         ma->ma_value = nvalue;
176
177         tag = ber_peek_tag( ber, &length );
178
179         if ( tag == LDAP_FILTER_EXT_DNATTRS ) {
180                 rc = ber_scanf( ber, "b}", &ma->ma_dnattrs );
181         } else {
182                 rc = ber_scanf( ber, "}" );
183                 ma->ma_dnattrs = 0;
184         }
185
186         if( rc == LBER_ERROR ) {
187 #ifdef NEW_LOGGING
188                 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
189                            "get_mra: ber_scanf failure\n"));
190 #else
191                 Debug( LDAP_DEBUG_ANY, "  get_mra ber_scanf\n", 0, 0, 0 );
192 #endif
193
194                 *text = "Error decoding dnattrs matching rule assertion";
195                 mra_free( ma, 1 );
196                 return SLAPD_DISCONNECT;
197         }
198
199         *mra = ma;
200
201         return LDAP_SUCCESS;
202 }
203