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 );
161 AttributeDescription *ad,
164 struct berval *v1, /* stored value */
165 void *v2, /* assertion */
169 struct berval nv1 = { 0, NULL };
170 struct berval nv2 = { 0, NULL };
172 if( !mr->smr_match ) {
173 return LDAP_INAPPROPRIATE_MATCHING;
176 if( ad->ad_type->sat_syntax->ssyn_normalize ) {
177 rc = ad->ad_type->sat_syntax->ssyn_normalize(
178 ad->ad_type->sat_syntax, v1, &nv1 );
180 if( rc != LDAP_SUCCESS ) {
181 return LDAP_INAPPROPRIATE_MATCHING;
185 if ( SLAP_IS_MR_VALUE_SYNTAX_NONCONVERTED_MATCH( flags ) &&
188 rc = (mr->smr_convert)( v2, &nv2 );
189 if ( rc != LDAP_SUCCESS ) {
190 return LDAP_INVALID_SYNTAX;
193 /* let smr_match know we've converted the value */
194 flags |= SLAP_MR_VALUE_SYNTAX_CONVERTED_MATCH;
197 rc = (mr->smr_match)( match, flags,
198 ad->ad_type->sat_syntax,
200 nv1.bv_val != NULL ? &nv1 : v1,
201 nv2.bv_val != NULL ? &nv2 : v2 );
203 if (nv1.bv_val ) free( nv1.bv_val );
204 if (nv2.bv_val ) free( nv2.bv_val );
210 AttributeDescription *ad,
217 struct berval nval = { 0, NULL };
218 struct berval nval_tmp;
219 MatchingRule *mr = ad->ad_type->sat_equality;
221 if( mr == NULL || !mr->smr_match ) {
222 return LDAP_INAPPROPRIATE_MATCHING;
225 /* Take care of this here or ssyn_normalize later will hurt */
226 if ( SLAP_IS_MR_VALUE_SYNTAX_NONCONVERTED_MATCH( flags )
229 rc = (mr->smr_convert)( val, &nval );
230 if ( rc != LDAP_SUCCESS ) {
231 return LDAP_INVALID_SYNTAX;
234 /* let value_match know we've done the version */
235 flags |= SLAP_MR_VALUE_SYNTAX_CONVERTED_MATCH;
238 if( mr->smr_syntax->ssyn_normalize ) {
239 rc = mr->smr_syntax->ssyn_normalize(
240 mr->smr_syntax, nval.bv_val == NULL ? val : &nval, &nval_tmp );
244 if( rc != LDAP_SUCCESS ) {
246 return LDAP_INAPPROPRIATE_MATCHING;
250 for ( i = 0; vals[i].bv_val != NULL; i++ ) {
254 rc = value_match( &match, ad, mr, flags,
255 &vals[i], nval.bv_val == NULL ? val : &nval, &text );
257 if( rc == LDAP_SUCCESS && match == 0 ) {
264 return LDAP_NO_SUCH_ATTRIBUTE;