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,
139 /* we expect the value to be in the assertion syntax */
140 assert( !SLAP_MR_IS_VALUE_OF_ATTRIBUTE_SYNTAX(usage) );
143 *text = "inappropriate matching request";
144 return LDAP_INAPPROPRIATE_MATCHING;
147 if( !mr->smr_match ) {
148 *text = "requested matching rule not supported";
149 return LDAP_INAPPROPRIATE_MATCHING;
152 if( mr->smr_syntax->ssyn_pretty ) {
153 rc = (mr->smr_syntax->ssyn_pretty)( mr->smr_syntax, in, &pval, ctx );
157 rc = (mr->smr_syntax->ssyn_validate)( mr->smr_syntax, in );
160 if( rc != LDAP_SUCCESS ) {
161 *text = "value does not conform to assertion syntax";
162 return LDAP_INVALID_SYNTAX;
165 if( mr->smr_normalize ) {
166 rc = (mr->smr_normalize)(
167 usage|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
168 ad ? ad->ad_type->sat_syntax : NULL,
171 if( pval.bv_val ) ber_memfree_x( pval.bv_val, ctx );
173 if( rc != LDAP_SUCCESS ) {
174 *text = "unable to normalize value for matching";
175 return LDAP_INVALID_SYNTAX;
178 } else if ( pval.bv_val != NULL ) {
182 ber_dupbv_x( out, in, ctx );
192 AttributeDescription *ad,
195 struct berval *v1, /* stored value */
196 void *v2, /* assertion */
200 struct berval nv1 = { 0, NULL };
201 struct berval nv2 = { 0, NULL };
203 assert( mr != NULL );
205 if( !mr->smr_match ) {
206 return LDAP_INAPPROPRIATE_MATCHING;
209 rc = (mr->smr_match)( match, flags,
210 ad->ad_type->sat_syntax,
212 nv1.bv_val != NULL ? &nv1 : v1,
213 nv2.bv_val != NULL ? &nv2 : v2 );
215 if (nv1.bv_val ) free( nv1.bv_val );
216 if (nv2.bv_val ) free( nv2.bv_val );
221 AttributeDescription *ad,
229 struct berval nval = { 0, NULL };
230 MatchingRule *mr = ad->ad_type->sat_equality;
232 if( mr == NULL || !mr->smr_match ) {
233 return LDAP_INAPPROPRIATE_MATCHING;
236 assert(SLAP_IS_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH( flags ));
238 if( !SLAP_IS_MR_ASSERTED_VALUE_NORMALIZED_MATCH( flags ) &&
241 rc = (mr->smr_normalize)(
242 flags & (SLAP_MR_TYPE_MASK|SLAP_MR_SUBTYPE_MASK|SLAP_MR_VALUE_OF_SYNTAX),
243 ad ? ad->ad_type->sat_syntax : NULL,
244 mr, val, &nval, ctx );
246 if( rc != LDAP_SUCCESS ) {
247 return LDAP_INVALID_SYNTAX;
251 for ( i = 0; vals[i].bv_val != NULL; i++ ) {
255 rc = value_match( &match, ad, mr, flags,
256 &vals[i], nval.bv_val == NULL ? val : &nval, &text );
258 if( rc == LDAP_SUCCESS && match == 0 ) {
259 sl_free( nval.bv_val, ctx );
264 sl_free( nval.bv_val, ctx );
265 return LDAP_NO_SUCH_ATTRIBUTE;