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 *) );
37 for ( n = 0; (*vals)[n] != NULL; n++ )
39 *vals = (struct berval **) ch_realloc( (char *) *vals,
40 (n + nn + 1) * sizeof(struct berval *) );
43 for ( i = 0, j = 0; i < nn; i++ ) {
44 if ( addvals[i]->bv_len > 0 ) {
45 (*vals)[n + j] = ber_bvdup( addvals[i] );
46 if( (*vals)[n + j++] == NULL ) break;
49 (*vals)[n + j] = NULL;
57 AttributeDescription *ad,
66 switch( usage & SLAP_MR_TYPE_MASK ) {
68 case SLAP_MR_EQUALITY:
69 mr = ad->ad_type->sat_equality;
71 case SLAP_MR_ORDERING:
72 mr = ad->ad_type->sat_ordering;
75 mr = ad->ad_type->sat_substr;
80 *text = "internal error";
85 *text = "inappropriate matching request";
86 return LDAP_INAPPROPRIATE_MATCHING;
89 /* we only support equality matching of binary attributes */
90 /* This is suspect, flexible certificate matching will hit this */
91 if( slap_ad_is_binary( ad ) && usage != SLAP_MR_EQUALITY ) {
92 *text = "inappropriate binary matching";
93 return LDAP_INAPPROPRIATE_MATCHING;
96 if( mr->smr_normalize ) {
97 rc = (mr->smr_normalize)( usage,
98 ad->ad_type->sat_syntax,
101 if( rc != LDAP_SUCCESS ) {
102 *text = "unable to normalize value";
103 return LDAP_INVALID_SYNTAX;
106 } else if ( mr->smr_syntax->ssyn_normalize ) {
107 rc = (mr->smr_syntax->ssyn_normalize)(
108 ad->ad_type->sat_syntax,
111 if( rc != LDAP_SUCCESS ) {
112 *text = "unable to normalize value";
113 return LDAP_INVALID_SYNTAX;
117 *out = ber_bvdup( in );
127 AttributeDescription *ad,
130 struct berval *v1, /* stored value */
131 void *v2, /* assertion */
135 struct berval *nv1 = NULL;
136 struct berval *nv2 = 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 ( !(flags & SLAP_MR_VALUE_IS_IN_MR_SYNTAX) &&
154 rc = (mr->smr_convert)(v2,&nv2);
155 if ( rc != LDAP_SUCCESS ) {
156 return LDAP_INVALID_SYNTAX;
160 rc = (mr->smr_match)( match, flags,
161 ad->ad_type->sat_syntax,
163 nv1 != NULL ? nv1 : v1,
164 nv2 != NULL ? nv2 : v2 );
173 AttributeDescription *ad,
175 struct berval **vals,
180 struct berval *nval = NULL;
181 struct berval *nval_tmp = NULL;
182 MatchingRule *mr = ad->ad_type->sat_equality;
184 if( mr == NULL || !mr->smr_match ) {
185 return LDAP_INAPPROPRIATE_MATCHING;
188 /* Take care of this here or ssyn_normalize later will hurt */
189 if ( !(flags & SLAP_MR_VALUE_IS_IN_MR_SYNTAX) &&
191 rc = (mr->smr_convert)(val,&nval);
192 if ( rc != LDAP_SUCCESS ) {
193 return LDAP_INVALID_SYNTAX;
197 if( mr->smr_syntax->ssyn_normalize ) {
198 rc = mr->smr_syntax->ssyn_normalize(
199 mr->smr_syntax, nval == NULL ? val : nval, &nval_tmp );
203 if( rc != LDAP_SUCCESS ) {
205 return LDAP_INAPPROPRIATE_MATCHING;
209 for ( i = 0; vals[i] != NULL; i++ ) {
213 /* We did convert, so keep value_match from trying */
214 rc = value_match( &match, ad, mr,
215 flags & !SLAP_MR_VALUE_IS_IN_MR_SYNTAX,
216 vals[i], nval == NULL ? val : nval, &text );
218 if( rc == LDAP_SUCCESS && match == 0 ) {
225 return LDAP_NO_SUCH_ATTRIBUTE;