1 /* value.c - routines for dealing with values */
4 * Copyright 1998-2003 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) SLAP_MALLOC( (nn + 1)
35 * sizeof(struct berval) );
38 LDAP_LOG( OPERATION, ERR,
39 "value_add: SLAP_MALLOC failed.\n", 0, 0, 0 );
41 Debug(LDAP_DEBUG_TRACE,
42 "value_add: SLAP_MALLOC failed.\n", 0, 0, 0 );
44 return LBER_ERROR_MEMORY;
48 for ( n = 0; (*vals)[n].bv_val != NULL; n++ ) {
51 *vals = (BerVarray) SLAP_REALLOC( (char *) *vals,
52 (n + nn + 1) * sizeof(struct berval) );
55 LDAP_LOG( OPERATION, ERR,
56 "value_add: SLAP_MALLOC failed.\n", 0, 0, 0 );
58 Debug(LDAP_DEBUG_TRACE,
59 "value_add: SLAP_MALLOC failed.\n", 0, 0, 0 );
61 return LBER_ERROR_MEMORY;
66 for ( ; addvals->bv_val; v2++, addvals++ ) {
67 ber_dupbv(v2, addvals);
68 if (v2->bv_val == NULL) break;
85 if ( *vals == NULL ) {
86 *vals = (BerVarray) SLAP_MALLOC( 2 * sizeof(struct berval) );
89 LDAP_LOG( OPERATION, ERR,
90 "value_add_one: SLAP_MALLOC failed.\n", 0, 0, 0 );
92 Debug(LDAP_DEBUG_TRACE,
93 "value_add_one: SLAP_MALLOC failed.\n", 0, 0, 0 );
95 return LBER_ERROR_MEMORY;
99 for ( n = 0; (*vals)[n].bv_val != NULL; n++ ) {
102 *vals = (BerVarray) SLAP_REALLOC( (char *) *vals,
103 (n + 2) * sizeof(struct berval) );
104 if( *vals == NULL ) {
106 LDAP_LOG( OPERATION, ERR,
107 "value_add_one: SLAP_MALLOC failed.\n", 0, 0, 0 );
109 Debug(LDAP_DEBUG_TRACE,
110 "value_add_one: SLAP_MALLOC failed.\n", 0, 0, 0 );
112 return LBER_ERROR_MEMORY;
117 ber_dupbv(v2, addval);
126 int asserted_value_validate_normalize(
127 AttributeDescription *ad,
137 /* we expect the value to be in the assertion syntax */
138 assert( !SLAP_MR_IS_VALUE_OF_ATTRIBUTE_SYNTAX(usage) );
141 *text = "inappropriate matching request";
142 return LDAP_INAPPROPRIATE_MATCHING;
145 if( !mr->smr_match ) {
146 *text = "requested matching rule not supported";
147 return LDAP_INAPPROPRIATE_MATCHING;
150 rc = (mr->smr_syntax->ssyn_validate)( mr->smr_syntax, in );
152 if( rc != LDAP_SUCCESS ) {
153 *text = "value does not conform to assertion syntax";
154 return LDAP_INVALID_SYNTAX;
157 if( mr->smr_normalize ) {
158 rc = (mr->smr_normalize)( usage,
159 ad ? ad->ad_type->sat_syntax : NULL,
162 if( rc != LDAP_SUCCESS ) {
163 *text = "unable to normalize value for matching";
164 return LDAP_INVALID_SYNTAX;
168 ber_dupbv_x( out, in, ctx );
178 AttributeDescription *ad,
181 struct berval *v1, /* stored value */
182 void *v2, /* assertion */
186 struct berval nv1 = { 0, NULL };
187 struct berval nv2 = { 0, NULL };
189 assert( mr != NULL );
191 if( !mr->smr_match ) {
192 return LDAP_INAPPROPRIATE_MATCHING;
196 rc = (mr->smr_match)( match, flags,
197 ad->ad_type->sat_syntax,
199 nv1.bv_val != NULL ? &nv1 : v1,
200 nv2.bv_val != NULL ? &nv2 : v2 );
202 if (nv1.bv_val ) free( nv1.bv_val );
203 if (nv2.bv_val ) free( nv2.bv_val );
208 AttributeDescription *ad,
216 struct berval nval = { 0, NULL };
217 MatchingRule *mr = ad->ad_type->sat_equality;
219 if( mr == NULL || !mr->smr_match ) {
220 return LDAP_INAPPROPRIATE_MATCHING;
223 assert(SLAP_IS_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH( flags ));
225 if( !SLAP_IS_MR_ASSERTED_VALUE_NORMALIZED_MATCH( flags ) &&
228 rc = (mr->smr_normalize)(
229 flags & (SLAP_MR_TYPE_MASK|SLAP_MR_SUBTYPE_MASK),
230 ad ? ad->ad_type->sat_syntax : NULL,
231 mr, val, &nval, ctx );
233 if( rc != LDAP_SUCCESS ) {
234 return LDAP_INVALID_SYNTAX;
238 for ( i = 0; vals[i].bv_val != NULL; i++ ) {
242 rc = value_match( &match, ad, mr, flags,
243 &vals[i], nval.bv_val == NULL ? val : &nval, &text );
245 if( rc == LDAP_SUCCESS && match == 0 ) {
246 sl_free( nval.bv_val, ctx );
251 sl_free( nval.bv_val, ctx );
252 return LDAP_NO_SUCH_ATTRIBUTE;