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>
23 struct berval ***vals,
24 struct berval **addvals
29 for ( nn = 0; addvals != NULL && addvals[nn] != NULL; nn++ )
32 if ( *vals == NULL ) {
33 *vals = (struct berval **) ch_malloc( (nn + 1)
34 * sizeof(struct berval *) );
38 for ( n = 0; (*vals)[n] != NULL; n++ )
40 *vals = (struct berval **) ch_realloc( (char *) *vals,
41 (n + nn + 1) * sizeof(struct berval *) );
44 for ( i = 0, j = 0; i < nn; i++ ) {
45 (*vals)[n + j] = ber_bvdup( addvals[i] );
46 if( (*vals)[n + j++] == NULL ) break;
48 (*vals)[n + j] = NULL;
56 AttributeDescription *ad,
65 switch( usage & SLAP_MR_TYPE_MASK ) {
67 case SLAP_MR_EQUALITY:
68 mr = ad->ad_type->sat_equality;
70 case SLAP_MR_ORDERING:
71 mr = ad->ad_type->sat_ordering;
74 mr = ad->ad_type->sat_substr;
79 *text = "internal error";
84 *text = "inappropriate matching request";
85 return LDAP_INAPPROPRIATE_MATCHING;
88 /* we only support equality matching of binary attributes */
89 /* This is suspect, flexible certificate matching will hit this */
90 if( slap_ad_is_binary( ad ) && usage != SLAP_MR_EQUALITY ) {
91 *text = "inappropriate binary matching";
92 return LDAP_INAPPROPRIATE_MATCHING;
95 if( mr->smr_normalize ) {
96 rc = (mr->smr_normalize)( usage,
97 ad->ad_type->sat_syntax,
100 if( rc != LDAP_SUCCESS ) {
101 *text = "unable to normalize value";
102 return LDAP_INVALID_SYNTAX;
105 } else if ( mr->smr_syntax->ssyn_normalize ) {
106 rc = (mr->smr_syntax->ssyn_normalize)(
107 ad->ad_type->sat_syntax,
110 if( rc != LDAP_SUCCESS ) {
111 *text = "unable to normalize value";
112 return LDAP_INVALID_SYNTAX;
116 ber_dupbv( out, in );
126 AttributeDescription *ad,
129 struct berval *v1, /* stored value */
130 void *v2, /* assertion */
137 if( !mr->smr_match ) {
138 return LDAP_INAPPROPRIATE_MATCHING;
141 if( ad->ad_type->sat_syntax->ssyn_normalize ) {
142 rc = ad->ad_type->sat_syntax->ssyn_normalize(
143 ad->ad_type->sat_syntax, v1, &nv1 );
145 if( rc != LDAP_SUCCESS ) {
146 return LDAP_INAPPROPRIATE_MATCHING;
150 if ( SLAP_IS_MR_VALUE_SYNTAX_NONCONVERTED_MATCH( flags ) &&
153 rc = (mr->smr_convert)( v2, &nv2 );
154 if ( rc != LDAP_SUCCESS ) {
155 return LDAP_INVALID_SYNTAX;
158 /* let smr_match know we've converted the value */
159 flags |= SLAP_MR_VALUE_SYNTAX_CONVERTED_MATCH;
162 rc = (mr->smr_match)( match, flags,
163 ad->ad_type->sat_syntax,
165 nv1.bv_val != NULL ? &nv1 : v1,
166 nv2.bv_val != NULL ? &nv2 : v2 );
175 AttributeDescription *ad,
177 struct berval **vals,
183 struct berval nval_tmp;
184 MatchingRule *mr = ad->ad_type->sat_equality;
186 if( mr == NULL || !mr->smr_match ) {
187 return LDAP_INAPPROPRIATE_MATCHING;
190 /* Take care of this here or ssyn_normalize later will hurt */
191 if ( SLAP_IS_MR_VALUE_SYNTAX_NONCONVERTED_MATCH( flags )
194 rc = (mr->smr_convert)( val, &nval );
195 if ( rc != LDAP_SUCCESS ) {
196 return LDAP_INVALID_SYNTAX;
199 /* let value_match know we've done the version */
200 flags |= SLAP_MR_VALUE_SYNTAX_CONVERTED_MATCH;
203 if( mr->smr_syntax->ssyn_normalize ) {
204 rc = mr->smr_syntax->ssyn_normalize(
205 mr->smr_syntax, nval.bv_val == NULL ? val : &nval, &nval_tmp );
209 if( rc != LDAP_SUCCESS ) {
211 return LDAP_INAPPROPRIATE_MATCHING;
215 for ( i = 0; vals[i] != NULL; i++ ) {
219 rc = value_match( &match, ad, mr, flags,
220 vals[i], nval.bv_val == NULL ? val : &nval, &text );
222 if( rc == LDAP_SUCCESS && match == 0 ) {
229 return LDAP_NO_SUCH_ATTRIBUTE;