1 /* value.c - routines for dealing with values */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2004 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * Copyright (c) 1995 Regents of the University of Michigan.
18 * All rights reserved.
20 * Redistribution and use in source and binary forms are permitted
21 * provided that this notice is preserved and that due credit is given
22 * to the University of Michigan at Ann Arbor. The name of the University
23 * may not be used to endorse or promote products derived from this
24 * software without specific prior written permission. This software
25 * is provided ``as is'' without express or implied warranty.
33 #include <ac/socket.h>
34 #include <ac/string.h>
49 if ( addvals != NULL ) {
50 for ( ; !BER_BVISNULL( &addvals[nn] ); nn++ )
54 if ( *vals == NULL ) {
55 *vals = (BerVarray) SLAP_MALLOC( (nn + 1)
56 * sizeof(struct berval) );
58 Debug(LDAP_DEBUG_TRACE,
59 "value_add: SLAP_MALLOC failed.\n", 0, 0, 0 );
60 return LBER_ERROR_MEMORY;
65 for ( n = 0; !BER_BVISNULL( &(*vals)[n] ); n++ ) {
68 *vals = (BerVarray) SLAP_REALLOC( (char *) *vals,
69 (n + nn + 1) * sizeof(struct berval) );
71 Debug(LDAP_DEBUG_TRACE,
72 "value_add: SLAP_MALLOC failed.\n", 0, 0, 0 );
73 return LBER_ERROR_MEMORY;
78 for ( ; !BER_BVISNULL( addvals ); v2++, addvals++ ) {
79 ber_dupbv( v2, addvals );
80 if ( BER_BVISNULL( v2 ) ) break;
90 struct berval *addval )
95 if ( *vals == NULL ) {
96 *vals = (BerVarray) SLAP_MALLOC( 2 * sizeof(struct berval) );
98 Debug(LDAP_DEBUG_TRACE,
99 "value_add_one: SLAP_MALLOC failed.\n", 0, 0, 0 );
100 return LBER_ERROR_MEMORY;
105 for ( n = 0; !BER_BVISNULL( &(*vals)[n] ); n++ ) {
108 *vals = (BerVarray) SLAP_REALLOC( (char *) *vals,
109 (n + 2) * sizeof(struct berval) );
110 if( *vals == NULL ) {
111 Debug(LDAP_DEBUG_TRACE,
112 "value_add_one: SLAP_MALLOC failed.\n", 0, 0, 0 );
113 return LBER_ERROR_MEMORY;
118 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 */
201 assert( mr != NULL );
203 if( !mr->smr_match ) {
204 return LDAP_INAPPROPRIATE_MATCHING;
207 rc = (mr->smr_match)( match, flags,
208 ad->ad_type->sat_syntax, mr, v1, v2 );
214 AttributeDescription *ad,
222 struct berval nval = BER_BVNULL;
223 MatchingRule *mr = ad->ad_type->sat_equality;
225 if( mr == NULL || !mr->smr_match ) {
226 return LDAP_INAPPROPRIATE_MATCHING;
229 assert(SLAP_IS_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH( flags ));
231 if( !SLAP_IS_MR_ASSERTED_VALUE_NORMALIZED_MATCH( flags ) &&
234 rc = (mr->smr_normalize)(
235 flags & (SLAP_MR_TYPE_MASK|SLAP_MR_SUBTYPE_MASK|SLAP_MR_VALUE_OF_SYNTAX),
236 ad ? ad->ad_type->sat_syntax : NULL,
237 mr, val, &nval, ctx );
239 if( rc != LDAP_SUCCESS ) {
240 return LDAP_INVALID_SYNTAX;
244 for ( i = 0; vals[i].bv_val != NULL; i++ ) {
248 rc = value_match( &match, ad, mr, flags,
249 &vals[i], nval.bv_val == NULL ? val : &nval, &text );
251 if( rc == LDAP_SUCCESS && match == 0 ) {
252 slap_sl_free( nval.bv_val, ctx );
257 slap_sl_free( nval.bv_val, ctx );
258 return LDAP_NO_SUCH_ATTRIBUTE;