]> git.sur5r.net Git - openldap/blob - servers/slapd/mra.c
Use defined Root DSE attributes.
[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                         ch_free( value.bv_val );
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, &nvalue, text );
169         ch_free( value.bv_val );
170
171         if( rc != LDAP_SUCCESS ) {
172                 mra_free( ma, 1 );
173                 return rc;
174         }
175
176         ma->ma_value = nvalue;
177
178         tag = ber_peek_tag( ber, &length );
179
180         if ( tag == LDAP_FILTER_EXT_DNATTRS ) {
181                 rc = ber_scanf( ber, "b}", &ma->ma_dnattrs );
182         } else {
183                 rc = ber_scanf( ber, "}" );
184                 ma->ma_dnattrs = 0;
185         }
186
187         if( rc == LBER_ERROR ) {
188 #ifdef NEW_LOGGING
189                 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
190                            "get_mra: ber_scanf failure\n"));
191 #else
192                 Debug( LDAP_DEBUG_ANY, "  get_mra ber_scanf\n", 0, 0, 0 );
193 #endif
194
195                 *text = "Error decoding dnattrs matching rule assertion";
196                 mra_free( ma, 1 );
197                 return SLAPD_DISCONNECT;
198         }
199
200         *mra = ma;
201
202         return LDAP_SUCCESS;
203 }
204