1 /* value.c - routines for dealing with values */
4 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 #include <ac/socket.h>
14 #include <ac/string.h>
30 for ( nn = 0; addvals != NULL && addvals[nn].bv_val != NULL; nn++ )
33 if ( *vals == NULL ) {
34 *vals = (BerVarray) ch_malloc( (nn + 1)
35 * sizeof(struct berval) );
38 for ( n = 0; (*vals)[n].bv_val != NULL; n++ ) {
41 *vals = (BerVarray) ch_realloc( (char *) *vals,
42 (n + nn + 1) * sizeof(struct berval) );
46 for ( ; addvals->bv_val; v2++, addvals++ ) {
47 ber_dupbv(v2, addvals);
48 if (v2->bv_val == NULL) break;
65 *text = "inappropriate matching request";
66 return LDAP_INAPPROPRIATE_MATCHING;
69 if( mr->smr_syntax == NULL ) {
70 *text = "no assertion syntax";
71 return LDAP_INVALID_SYNTAX;
74 if( ! mr->smr_syntax->ssyn_validate ) {
75 *text = "no syntax validator";
76 return LDAP_INVALID_SYNTAX;
79 rc = (mr->smr_syntax->ssyn_validate)( mr->smr_syntax, in );
81 if( rc != LDAP_SUCCESS ) {
82 *text = "value is invalid";
83 return LDAP_INVALID_SYNTAX;
91 AttributeDescription *ad,
100 switch( usage & SLAP_MR_TYPE_MASK ) {
102 case SLAP_MR_EQUALITY:
103 mr = ad->ad_type->sat_equality;
105 case SLAP_MR_ORDERING:
106 mr = ad->ad_type->sat_ordering;
109 mr = ad->ad_type->sat_substr;
114 *text = "internal error";
119 *text = "inappropriate matching request";
120 return LDAP_INAPPROPRIATE_MATCHING;
123 /* we only support equality matching of binary attributes */
124 /* This is suspect, flexible certificate matching will hit this */
125 if( slap_ad_is_binary( ad ) && usage != SLAP_MR_EQUALITY ) {
126 *text = "inappropriate binary matching";
127 return LDAP_INAPPROPRIATE_MATCHING;
130 if( mr->smr_normalize ) {
131 rc = (mr->smr_normalize)( usage,
132 ad->ad_type->sat_syntax,
135 if( rc != LDAP_SUCCESS ) {
136 *text = "unable to normalize value";
137 return LDAP_INVALID_SYNTAX;
140 } else if ( mr->smr_syntax->ssyn_normalize ) {
141 rc = (mr->smr_syntax->ssyn_normalize)(
142 ad->ad_type->sat_syntax,
145 if( rc != LDAP_SUCCESS ) {
146 *text = "unable to normalize value";
147 return LDAP_INVALID_SYNTAX;
151 ber_dupbv( out, in );
158 value_validate_normalize(
159 AttributeDescription *ad,
168 switch( usage & SLAP_MR_TYPE_MASK ) {
170 case SLAP_MR_EQUALITY:
171 mr = ad->ad_type->sat_equality;
173 case SLAP_MR_ORDERING:
174 mr = ad->ad_type->sat_ordering;
177 mr = ad->ad_type->sat_substr;
182 *text = "internal error";
187 *text = "inappropriate matching request";
188 return LDAP_INAPPROPRIATE_MATCHING;
191 if( mr->smr_syntax == NULL ) {
192 *text = "no assertion syntax";
193 return LDAP_INVALID_SYNTAX;
196 if( ! mr->smr_syntax->ssyn_validate ) {
197 *text = "no syntax validator";
198 return LDAP_INVALID_SYNTAX;
201 rc = (mr->smr_syntax->ssyn_validate)( mr->smr_syntax, in );
203 if( rc != LDAP_SUCCESS ) {
204 *text = "value is invalid";
205 return LDAP_INVALID_SYNTAX;
208 /* we only support equality matching of binary attributes */
209 /* This is suspect, flexible certificate matching will hit this */
210 if( slap_ad_is_binary( ad ) && usage != SLAP_MR_EQUALITY ) {
211 *text = "inappropriate binary matching";
212 return LDAP_INAPPROPRIATE_MATCHING;
215 if( mr->smr_normalize ) {
216 rc = (mr->smr_normalize)( usage,
217 ad->ad_type->sat_syntax,
220 if( rc != LDAP_SUCCESS ) {
221 *text = "unable to normalize value";
222 return LDAP_INVALID_SYNTAX;
225 } else if ( mr->smr_syntax->ssyn_normalize ) {
226 rc = (mr->smr_syntax->ssyn_normalize)(
227 ad->ad_type->sat_syntax,
230 if( rc != LDAP_SUCCESS ) {
231 *text = "unable to normalize value";
232 return LDAP_INVALID_SYNTAX;
236 ber_dupbv( out, in );
246 AttributeDescription *ad,
249 struct berval *v1, /* stored value */
250 void *v2, /* assertion */
254 struct berval nv1 = { 0, NULL };
255 struct berval nv2 = { 0, NULL };
257 if( !mr->smr_match ) {
258 return LDAP_INAPPROPRIATE_MATCHING;
261 if( ad->ad_type->sat_syntax->ssyn_normalize ) {
262 rc = ad->ad_type->sat_syntax->ssyn_normalize(
263 ad->ad_type->sat_syntax, v1, &nv1 );
265 if( rc != LDAP_SUCCESS ) {
266 return LDAP_INAPPROPRIATE_MATCHING;
270 if ( SLAP_IS_MR_VALUE_SYNTAX_NONCONVERTED_MATCH( flags ) &&
273 rc = (mr->smr_convert)( v2, &nv2 );
274 if ( rc != LDAP_SUCCESS ) {
275 return LDAP_INVALID_SYNTAX;
278 /* let smr_match know we've converted the value */
279 flags |= SLAP_MR_VALUE_SYNTAX_CONVERTED_MATCH;
282 rc = (mr->smr_match)( match, flags,
283 ad->ad_type->sat_syntax,
285 nv1.bv_val != NULL ? &nv1 : v1,
286 nv2.bv_val != NULL ? &nv2 : v2 );
288 if (nv1.bv_val ) free( nv1.bv_val );
289 if (nv2.bv_val ) free( nv2.bv_val );
295 AttributeDescription *ad,
302 struct berval nval = { 0, NULL };
303 struct berval nval_tmp;
304 MatchingRule *mr = ad->ad_type->sat_equality;
306 if( mr == NULL || !mr->smr_match ) {
307 return LDAP_INAPPROPRIATE_MATCHING;
310 /* Take care of this here or ssyn_normalize later will hurt */
311 if ( SLAP_IS_MR_VALUE_SYNTAX_NONCONVERTED_MATCH( flags )
314 rc = (mr->smr_convert)( val, &nval );
315 if ( rc != LDAP_SUCCESS ) {
316 return LDAP_INVALID_SYNTAX;
319 /* let value_match know we've done the version */
320 flags |= SLAP_MR_VALUE_SYNTAX_CONVERTED_MATCH;
323 if( mr->smr_syntax->ssyn_normalize ) {
324 rc = mr->smr_syntax->ssyn_normalize(
325 mr->smr_syntax, nval.bv_val == NULL ? val : &nval, &nval_tmp );
329 if( rc != LDAP_SUCCESS ) {
331 return LDAP_INAPPROPRIATE_MATCHING;
335 for ( i = 0; vals[i].bv_val != NULL; i++ ) {
339 rc = value_match( &match, ad, mr, flags,
340 &vals[i], nval.bv_val == NULL ? val : &nval, &text );
342 if( rc == LDAP_SUCCESS && match == 0 ) {
349 return LDAP_NO_SUCH_ATTRIBUTE;