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 if ( *vals == NULL ) {
66 *vals = (BerVarray) ch_malloc( 2 * sizeof(struct berval) );
69 for ( n = 0; (*vals)[n].bv_val != NULL; n++ ) {
72 *vals = (BerVarray) ch_realloc( (char *) *vals,
73 (n + 2) * sizeof(struct berval) );
77 ber_dupbv(v2, addval);
95 *text = "inappropriate matching request";
96 return LDAP_INAPPROPRIATE_MATCHING;
99 if( mr->smr_syntax == NULL ) {
100 *text = "no assertion syntax";
101 return LDAP_INVALID_SYNTAX;
104 if( ! mr->smr_syntax->ssyn_validate ) {
105 *text = "no syntax validator";
106 return LDAP_INVALID_SYNTAX;
109 rc = (mr->smr_syntax->ssyn_validate)( mr->smr_syntax, in );
111 if( rc != LDAP_SUCCESS ) {
112 *text = "value is invalid";
113 return LDAP_INVALID_SYNTAX;
121 AttributeDescription *ad,
130 switch( usage & SLAP_MR_TYPE_MASK ) {
132 case SLAP_MR_EQUALITY:
133 mr = ad->ad_type->sat_equality;
135 case SLAP_MR_ORDERING:
136 mr = ad->ad_type->sat_ordering;
139 mr = ad->ad_type->sat_substr;
144 *text = "internal error";
149 *text = "inappropriate matching request";
150 return LDAP_INAPPROPRIATE_MATCHING;
153 /* we only support equality matching of binary attributes */
154 /* This is suspect, flexible certificate matching will hit this */
155 if( slap_ad_is_binary( ad ) && usage != SLAP_MR_EQUALITY ) {
156 *text = "inappropriate binary matching";
157 return LDAP_INAPPROPRIATE_MATCHING;
160 if( mr->smr_normalize ) {
161 rc = (mr->smr_normalize)( usage,
162 ad->ad_type->sat_syntax,
165 if( rc != LDAP_SUCCESS ) {
166 *text = "unable to normalize value";
167 return LDAP_INVALID_SYNTAX;
170 } else if ( mr->smr_syntax->ssyn_normalize ) {
171 rc = (mr->smr_syntax->ssyn_normalize)(
172 ad->ad_type->sat_syntax,
175 if( rc != LDAP_SUCCESS ) {
176 *text = "unable to normalize value";
177 return LDAP_INVALID_SYNTAX;
181 ber_dupbv( out, in );
188 value_validate_normalize(
189 AttributeDescription *ad,
198 switch( usage & SLAP_MR_TYPE_MASK ) {
200 case SLAP_MR_EQUALITY:
201 mr = ad->ad_type->sat_equality;
203 case SLAP_MR_ORDERING:
204 mr = ad->ad_type->sat_ordering;
207 mr = ad->ad_type->sat_substr;
212 *text = "internal error";
217 *text = "inappropriate matching request";
218 return LDAP_INAPPROPRIATE_MATCHING;
221 if( mr->smr_syntax == NULL ) {
222 *text = "no assertion syntax";
223 return LDAP_INVALID_SYNTAX;
226 if( ! mr->smr_syntax->ssyn_validate ) {
227 *text = "no syntax validator";
228 return LDAP_INVALID_SYNTAX;
231 rc = (mr->smr_syntax->ssyn_validate)( mr->smr_syntax, in );
233 if( rc != LDAP_SUCCESS ) {
234 *text = "value is invalid";
235 return LDAP_INVALID_SYNTAX;
238 /* we only support equality matching of binary attributes */
239 /* This is suspect, flexible certificate matching will hit this */
240 if( slap_ad_is_binary( ad ) && usage != SLAP_MR_EQUALITY ) {
241 *text = "inappropriate binary matching";
242 return LDAP_INAPPROPRIATE_MATCHING;
245 if( mr->smr_normalize ) {
246 rc = (mr->smr_normalize)( usage,
247 ad->ad_type->sat_syntax,
250 if( rc != LDAP_SUCCESS ) {
251 *text = "unable to normalize value";
252 return LDAP_INVALID_SYNTAX;
255 } else if ( mr->smr_syntax->ssyn_normalize ) {
256 rc = (mr->smr_syntax->ssyn_normalize)(
257 ad->ad_type->sat_syntax,
260 if( rc != LDAP_SUCCESS ) {
261 *text = "unable to normalize value";
262 return LDAP_INVALID_SYNTAX;
266 ber_dupbv( out, in );
276 AttributeDescription *ad,
279 struct berval *v1, /* stored value */
280 void *v2, /* assertion */
284 struct berval nv1 = { 0, NULL };
285 struct berval nv2 = { 0, NULL };
287 if( !mr->smr_match ) {
288 return LDAP_INAPPROPRIATE_MATCHING;
291 if( ad->ad_type->sat_syntax->ssyn_normalize ) {
292 rc = ad->ad_type->sat_syntax->ssyn_normalize(
293 ad->ad_type->sat_syntax, v1, &nv1 );
295 if( rc != LDAP_SUCCESS ) {
296 return LDAP_INAPPROPRIATE_MATCHING;
300 if ( SLAP_IS_MR_VALUE_SYNTAX_NONCONVERTED_MATCH( flags ) &&
303 rc = (mr->smr_convert)( v2, &nv2 );
304 if ( rc != LDAP_SUCCESS ) {
305 return LDAP_INVALID_SYNTAX;
308 /* let smr_match know we've converted the value */
309 flags |= SLAP_MR_VALUE_SYNTAX_CONVERTED_MATCH;
312 rc = (mr->smr_match)( match, flags,
313 ad->ad_type->sat_syntax,
315 nv1.bv_val != NULL ? &nv1 : v1,
316 nv2.bv_val != NULL ? &nv2 : v2 );
318 if (nv1.bv_val ) free( nv1.bv_val );
319 if (nv2.bv_val ) free( nv2.bv_val );
325 AttributeDescription *ad,
332 struct berval nval = { 0, NULL };
333 MatchingRule *mr = ad->ad_type->sat_equality;
335 if( mr == NULL || !mr->smr_match ) {
336 return LDAP_INAPPROPRIATE_MATCHING;
339 /* Take care of this here or ssyn_normalize later will hurt */
340 if ( SLAP_IS_MR_VALUE_SYNTAX_NONCONVERTED_MATCH( flags )
343 rc = (mr->smr_convert)( val, &nval );
344 if ( rc != LDAP_SUCCESS ) {
345 return LDAP_INVALID_SYNTAX;
348 /* let value_match know we've done the version */
349 flags |= SLAP_MR_VALUE_SYNTAX_CONVERTED_MATCH;
352 if( mr->smr_syntax->ssyn_normalize ) {
353 struct berval nval_tmp;
355 rc = mr->smr_syntax->ssyn_normalize(
357 nval.bv_val == NULL ? val : &nval, &nval_tmp );
361 if( rc != LDAP_SUCCESS ) {
363 return LDAP_INAPPROPRIATE_MATCHING;
367 for ( i = 0; vals[i].bv_val != NULL; i++ ) {
371 rc = value_match( &match, ad, mr, flags,
372 &vals[i], nval.bv_val == NULL ? val : &nval, &text );
374 if( rc == LDAP_SUCCESS && match == 0 ) {
381 return LDAP_NO_SUCH_ATTRIBUTE;