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 = (BVarray) ch_malloc( (nn + 1)
35 * sizeof(struct berval) );
38 for ( n = 0; (*vals)[n].bv_val != NULL; n++ ) {
41 *vals = (BVarray) 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;
59 AttributeDescription *ad,
68 switch( usage & SLAP_MR_TYPE_MASK ) {
70 case SLAP_MR_EQUALITY:
71 mr = ad->ad_type->sat_equality;
73 case SLAP_MR_ORDERING:
74 mr = ad->ad_type->sat_ordering;
77 mr = ad->ad_type->sat_substr;
82 *text = "internal error";
87 *text = "inappropriate matching request";
88 return LDAP_INAPPROPRIATE_MATCHING;
91 /* we only support equality matching of binary attributes */
92 /* This is suspect, flexible certificate matching will hit this */
93 if( slap_ad_is_binary( ad ) && usage != SLAP_MR_EQUALITY ) {
94 *text = "inappropriate binary matching";
95 return LDAP_INAPPROPRIATE_MATCHING;
98 if( mr->smr_normalize ) {
99 rc = (mr->smr_normalize)( usage,
100 ad->ad_type->sat_syntax,
103 if( rc != LDAP_SUCCESS ) {
104 *text = "unable to normalize value";
105 return LDAP_INVALID_SYNTAX;
108 } else if ( mr->smr_syntax->ssyn_normalize ) {
109 rc = (mr->smr_syntax->ssyn_normalize)(
110 ad->ad_type->sat_syntax,
113 if( rc != LDAP_SUCCESS ) {
114 *text = "unable to normalize value";
115 return LDAP_INVALID_SYNTAX;
119 ber_dupbv( out, in );
129 AttributeDescription *ad,
132 struct berval *v1, /* stored value */
133 void *v2, /* assertion */
137 struct berval nv1 = { 0, NULL };
138 struct berval nv2 = { 0, NULL };
140 if( !mr->smr_match ) {
141 return LDAP_INAPPROPRIATE_MATCHING;
144 if( ad->ad_type->sat_syntax->ssyn_normalize ) {
145 rc = ad->ad_type->sat_syntax->ssyn_normalize(
146 ad->ad_type->sat_syntax, v1, &nv1 );
148 if( rc != LDAP_SUCCESS ) {
149 return LDAP_INAPPROPRIATE_MATCHING;
153 if ( SLAP_IS_MR_VALUE_SYNTAX_NONCONVERTED_MATCH( flags ) &&
156 rc = (mr->smr_convert)( v2, &nv2 );
157 if ( rc != LDAP_SUCCESS ) {
158 return LDAP_INVALID_SYNTAX;
161 /* let smr_match know we've converted the value */
162 flags |= SLAP_MR_VALUE_SYNTAX_CONVERTED_MATCH;
165 rc = (mr->smr_match)( match, flags,
166 ad->ad_type->sat_syntax,
168 nv1.bv_val != NULL ? &nv1 : v1,
169 nv2.bv_val != NULL ? &nv2 : v2 );
171 if (nv1.bv_val ) free( nv1.bv_val );
172 if (nv2.bv_val ) free( nv2.bv_val );
178 AttributeDescription *ad,
185 struct berval nval = { 0, NULL };
186 struct berval nval_tmp;
187 MatchingRule *mr = ad->ad_type->sat_equality;
189 if( mr == NULL || !mr->smr_match ) {
190 return LDAP_INAPPROPRIATE_MATCHING;
193 /* Take care of this here or ssyn_normalize later will hurt */
194 if ( SLAP_IS_MR_VALUE_SYNTAX_NONCONVERTED_MATCH( flags )
197 rc = (mr->smr_convert)( val, &nval );
198 if ( rc != LDAP_SUCCESS ) {
199 return LDAP_INVALID_SYNTAX;
202 /* let value_match know we've done the version */
203 flags |= SLAP_MR_VALUE_SYNTAX_CONVERTED_MATCH;
206 if( mr->smr_syntax->ssyn_normalize ) {
207 rc = mr->smr_syntax->ssyn_normalize(
208 mr->smr_syntax, nval.bv_val == NULL ? val : &nval, &nval_tmp );
212 if( rc != LDAP_SUCCESS ) {
214 return LDAP_INAPPROPRIATE_MATCHING;
218 for ( i = 0; vals[i].bv_val != NULL; i++ ) {
222 rc = value_match( &match, ad, mr, flags,
223 &vals[i], nval.bv_val == NULL ? val : &nval, &text );
225 if( rc == LDAP_SUCCESS && match == 0 ) {
232 return LDAP_NO_SUCH_ATTRIBUTE;