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