1 /* value.c - routines for dealing with values */
4 * Copyright 1998-2000 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++ )
40 *vals = (BVarray) ch_realloc( (char *) *vals,
41 (n + nn + 1) * sizeof(struct berval) );
45 for ( ; addvals->bv_val; v2++, addvals++ ) {
46 ber_dupbv(v2, addvals);
47 if (v2->bv_val == NULL) break;
58 AttributeDescription *ad,
67 switch( usage & SLAP_MR_TYPE_MASK ) {
69 case SLAP_MR_EQUALITY:
70 mr = ad->ad_type->sat_equality;
72 case SLAP_MR_ORDERING:
73 mr = ad->ad_type->sat_ordering;
76 mr = ad->ad_type->sat_substr;
81 *text = "internal error";
86 *text = "inappropriate matching request";
87 return LDAP_INAPPROPRIATE_MATCHING;
90 /* we only support equality matching of binary attributes */
91 /* This is suspect, flexible certificate matching will hit this */
92 if( slap_ad_is_binary( ad ) && usage != SLAP_MR_EQUALITY ) {
93 *text = "inappropriate binary matching";
94 return LDAP_INAPPROPRIATE_MATCHING;
97 if( mr->smr_normalize ) {
98 rc = (mr->smr_normalize)( usage,
99 ad->ad_type->sat_syntax,
102 if( rc != LDAP_SUCCESS ) {
103 *text = "unable to normalize value";
104 return LDAP_INVALID_SYNTAX;
107 } else if ( mr->smr_syntax->ssyn_normalize ) {
108 rc = (mr->smr_syntax->ssyn_normalize)(
109 ad->ad_type->sat_syntax,
112 if( rc != LDAP_SUCCESS ) {
113 *text = "unable to normalize value";
114 return LDAP_INVALID_SYNTAX;
118 ber_dupbv( out, in );
128 AttributeDescription *ad,
131 struct berval *v1, /* stored value */
132 void *v2, /* assertion */
136 struct berval nv1 = { 0, NULL };
137 struct berval nv2 = { 0, NULL };
139 if( !mr->smr_match ) {
140 return LDAP_INAPPROPRIATE_MATCHING;
143 if( ad->ad_type->sat_syntax->ssyn_normalize ) {
144 rc = ad->ad_type->sat_syntax->ssyn_normalize(
145 ad->ad_type->sat_syntax, v1, &nv1 );
147 if( rc != LDAP_SUCCESS ) {
148 return LDAP_INAPPROPRIATE_MATCHING;
152 if ( SLAP_IS_MR_VALUE_SYNTAX_NONCONVERTED_MATCH( flags ) &&
155 rc = (mr->smr_convert)( v2, &nv2 );
156 if ( rc != LDAP_SUCCESS ) {
157 return LDAP_INVALID_SYNTAX;
160 /* let smr_match know we've converted the value */
161 flags |= SLAP_MR_VALUE_SYNTAX_CONVERTED_MATCH;
164 rc = (mr->smr_match)( match, flags,
165 ad->ad_type->sat_syntax,
167 nv1.bv_val != NULL ? &nv1 : v1,
168 nv2.bv_val != NULL ? &nv2 : v2 );
170 if (nv1.bv_val ) free( nv1.bv_val );
171 if (nv2.bv_val ) free( nv2.bv_val );
177 AttributeDescription *ad,
184 struct berval nval = { 0, NULL };
185 struct berval nval_tmp;
186 MatchingRule *mr = ad->ad_type->sat_equality;
188 if( mr == NULL || !mr->smr_match ) {
189 return LDAP_INAPPROPRIATE_MATCHING;
192 /* Take care of this here or ssyn_normalize later will hurt */
193 if ( SLAP_IS_MR_VALUE_SYNTAX_NONCONVERTED_MATCH( flags )
196 rc = (mr->smr_convert)( val, &nval );
197 if ( rc != LDAP_SUCCESS ) {
198 return LDAP_INVALID_SYNTAX;
201 /* let value_match know we've done the version */
202 flags |= SLAP_MR_VALUE_SYNTAX_CONVERTED_MATCH;
205 if( mr->smr_syntax->ssyn_normalize ) {
206 rc = mr->smr_syntax->ssyn_normalize(
207 mr->smr_syntax, nval.bv_val == NULL ? val : &nval, &nval_tmp );
211 if( rc != LDAP_SUCCESS ) {
213 return LDAP_INAPPROPRIATE_MATCHING;
217 for ( i = 0; vals[i].bv_val != NULL; i++ ) {
221 rc = value_match( &match, ad, mr, flags,
222 &vals[i], nval.bv_val == NULL ? val : &nval, &text );
224 if( rc == LDAP_SUCCESS && match == 0 ) {
231 return LDAP_NO_SUCH_ATTRIBUTE;