1998-08-09 08:43:13 +08:00
|
|
|
/* value.c - routines for dealing with values */
|
1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
1999-08-07 07:07:46 +08:00
|
|
|
/*
|
2003-01-04 04:20:47 +08:00
|
|
|
* Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
|
1999-08-07 07:07:46 +08:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#include <ac/ctype.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/time.h>
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <sys/stat.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include "slap.h"
|
|
|
|
|
2000-05-18 04:08:13 +08:00
|
|
|
int
|
|
|
|
value_add(
|
2002-01-14 09:43:17 +08:00
|
|
|
BerVarray *vals,
|
|
|
|
BerVarray addvals
|
2000-05-18 04:08:13 +08:00
|
|
|
)
|
|
|
|
{
|
2002-01-03 01:02:30 +08:00
|
|
|
int n, nn;
|
2002-01-14 09:43:17 +08:00
|
|
|
BerVarray v2;
|
2000-05-18 04:08:13 +08:00
|
|
|
|
2002-01-02 19:00:36 +08:00
|
|
|
for ( nn = 0; addvals != NULL && addvals[nn].bv_val != NULL; nn++ )
|
2000-05-18 04:08:13 +08:00
|
|
|
; /* NULL */
|
|
|
|
|
|
|
|
if ( *vals == NULL ) {
|
2002-11-02 02:59:52 +08:00
|
|
|
*vals = (BerVarray) SLAP_MALLOC( (nn + 1)
|
2002-01-02 19:00:36 +08:00
|
|
|
* sizeof(struct berval) );
|
2002-11-02 02:59:52 +08:00
|
|
|
if( *vals == NULL ) {
|
|
|
|
#ifdef NEW_LOGGING
|
|
|
|
LDAP_LOG( OPERATION, ERR,
|
|
|
|
"value_add: SLAP_MALLOC failed.\n", 0, 0, 0 );
|
|
|
|
#else
|
|
|
|
Debug(LDAP_DEBUG_TRACE,
|
|
|
|
"value_add: SLAP_MALLOC failed.\n", 0, 0, 0 );
|
|
|
|
#endif
|
|
|
|
return LBER_ERROR_MEMORY;
|
|
|
|
}
|
2000-05-18 04:08:13 +08:00
|
|
|
n = 0;
|
|
|
|
} else {
|
2002-01-03 01:02:30 +08:00
|
|
|
for ( n = 0; (*vals)[n].bv_val != NULL; n++ ) {
|
|
|
|
; /* Empty */
|
|
|
|
}
|
2002-11-02 02:59:52 +08:00
|
|
|
*vals = (BerVarray) SLAP_REALLOC( (char *) *vals,
|
2002-01-02 19:00:36 +08:00
|
|
|
(n + nn + 1) * sizeof(struct berval) );
|
2002-11-02 02:59:52 +08:00
|
|
|
if( *vals == NULL ) {
|
|
|
|
#ifdef NEW_LOGGING
|
|
|
|
LDAP_LOG( OPERATION, ERR,
|
|
|
|
"value_add: SLAP_MALLOC failed.\n", 0, 0, 0 );
|
|
|
|
#else
|
|
|
|
Debug(LDAP_DEBUG_TRACE,
|
|
|
|
"value_add: SLAP_MALLOC failed.\n", 0, 0, 0 );
|
|
|
|
#endif
|
|
|
|
return LBER_ERROR_MEMORY;
|
|
|
|
}
|
2000-05-18 04:08:13 +08:00
|
|
|
}
|
|
|
|
|
2002-01-02 19:00:36 +08:00
|
|
|
v2 = *vals + n;
|
|
|
|
for ( ; addvals->bv_val; v2++, addvals++ ) {
|
|
|
|
ber_dupbv(v2, addvals);
|
|
|
|
if (v2->bv_val == NULL) break;
|
2000-05-18 04:08:13 +08:00
|
|
|
}
|
2002-01-02 19:00:36 +08:00
|
|
|
v2->bv_val = NULL;
|
|
|
|
v2->bv_len = 0;
|
2000-05-18 04:08:13 +08:00
|
|
|
|
2002-08-23 16:49:19 +08:00
|
|
|
return LDAP_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
value_add_one(
|
|
|
|
BerVarray *vals,
|
|
|
|
struct berval *addval
|
|
|
|
)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
BerVarray v2;
|
|
|
|
|
|
|
|
if ( *vals == NULL ) {
|
2002-11-02 02:59:52 +08:00
|
|
|
*vals = (BerVarray) SLAP_MALLOC( 2 * sizeof(struct berval) );
|
|
|
|
if( *vals == NULL ) {
|
|
|
|
#ifdef NEW_LOGGING
|
|
|
|
LDAP_LOG( OPERATION, ERR,
|
|
|
|
"value_add_one: SLAP_MALLOC failed.\n", 0, 0, 0 );
|
|
|
|
#else
|
|
|
|
Debug(LDAP_DEBUG_TRACE,
|
|
|
|
"value_add_one: SLAP_MALLOC failed.\n", 0, 0, 0 );
|
|
|
|
#endif
|
|
|
|
return LBER_ERROR_MEMORY;
|
|
|
|
}
|
2002-08-23 16:49:19 +08:00
|
|
|
n = 0;
|
|
|
|
} else {
|
|
|
|
for ( n = 0; (*vals)[n].bv_val != NULL; n++ ) {
|
|
|
|
; /* Empty */
|
|
|
|
}
|
2002-11-02 02:59:52 +08:00
|
|
|
*vals = (BerVarray) SLAP_REALLOC( (char *) *vals,
|
2002-08-23 16:49:19 +08:00
|
|
|
(n + 2) * sizeof(struct berval) );
|
2002-11-02 02:59:52 +08:00
|
|
|
if( *vals == NULL ) {
|
|
|
|
#ifdef NEW_LOGGING
|
|
|
|
LDAP_LOG( OPERATION, ERR,
|
|
|
|
"value_add_one: SLAP_MALLOC failed.\n", 0, 0, 0 );
|
|
|
|
#else
|
|
|
|
Debug(LDAP_DEBUG_TRACE,
|
|
|
|
"value_add_one: SLAP_MALLOC failed.\n", 0, 0, 0 );
|
|
|
|
#endif
|
|
|
|
return LBER_ERROR_MEMORY;
|
|
|
|
}
|
2002-08-23 16:49:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
v2 = *vals + n;
|
|
|
|
ber_dupbv(v2, addval);
|
|
|
|
|
|
|
|
v2++;
|
|
|
|
v2->bv_val = NULL;
|
|
|
|
v2->bv_len = 0;
|
|
|
|
|
2000-05-29 07:51:39 +08:00
|
|
|
return LDAP_SUCCESS;
|
2000-05-18 04:08:13 +08:00
|
|
|
}
|
|
|
|
|
2003-02-27 09:54:43 +08:00
|
|
|
int asserted_value_validate_normalize(
|
|
|
|
AttributeDescription *ad,
|
|
|
|
MatchingRule *mr,
|
|
|
|
unsigned usage,
|
|
|
|
struct berval *in,
|
|
|
|
struct berval *out,
|
|
|
|
const char ** text )
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* we expect the value to be in the assertion syntax */
|
|
|
|
assert( !SLAP_MR_IS_VALUE_OF_ATTRIBUTE_SYNTAX(usage) );
|
|
|
|
|
|
|
|
if( mr == NULL ) {
|
|
|
|
*text = "inappropriate matching request";
|
|
|
|
return LDAP_INAPPROPRIATE_MATCHING;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !mr->smr_match ) {
|
|
|
|
*text = "requested matching rule not supported";
|
|
|
|
return LDAP_INAPPROPRIATE_MATCHING;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = (mr->smr_syntax->ssyn_validate)( mr->smr_syntax, in );
|
|
|
|
|
|
|
|
if( rc != LDAP_SUCCESS ) {
|
|
|
|
*text = "value does not conform to assertion syntax";
|
|
|
|
return LDAP_INVALID_SYNTAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( mr->smr_normalize ) {
|
|
|
|
rc = (mr->smr_normalize)( usage,
|
|
|
|
ad ? ad->ad_type->sat_syntax : NULL,
|
|
|
|
mr, in, out );
|
|
|
|
|
|
|
|
if( rc != LDAP_SUCCESS ) {
|
|
|
|
*text = "unable to normalize value for matching";
|
|
|
|
return LDAP_INVALID_SYNTAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
ber_dupbv( out, in );
|
|
|
|
}
|
2003-03-17 08:27:33 +08:00
|
|
|
|
|
|
|
return LDAP_SUCCESS;
|
2003-02-27 09:54:43 +08:00
|
|
|
}
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2000-05-22 06:46:51 +08:00
|
|
|
int
|
|
|
|
value_match(
|
2000-05-25 02:49:30 +08:00
|
|
|
int *match,
|
2000-05-22 06:46:51 +08:00
|
|
|
AttributeDescription *ad,
|
|
|
|
MatchingRule *mr,
|
2000-06-26 13:13:41 +08:00
|
|
|
unsigned flags,
|
2000-05-28 05:41:04 +08:00
|
|
|
struct berval *v1, /* stored value */
|
|
|
|
void *v2, /* assertion */
|
2000-05-22 11:46:57 +08:00
|
|
|
const char ** text )
|
2000-05-22 06:46:51 +08:00
|
|
|
{
|
2000-05-25 02:49:30 +08:00
|
|
|
int rc;
|
2001-12-30 08:14:45 +08:00
|
|
|
struct berval nv1 = { 0, NULL };
|
|
|
|
struct berval nv2 = { 0, NULL };
|
2000-05-25 04:21:46 +08:00
|
|
|
|
2002-11-26 02:37:04 +08:00
|
|
|
assert( mr != NULL );
|
|
|
|
|
|
|
|
if( !mr->smr_match ) {
|
2000-05-29 11:44:06 +08:00
|
|
|
return LDAP_INAPPROPRIATE_MATCHING;
|
|
|
|
}
|
|
|
|
|
2001-10-23 04:03:30 +08:00
|
|
|
|
2000-06-26 13:13:41 +08:00
|
|
|
rc = (mr->smr_match)( match, flags,
|
2000-05-25 02:49:30 +08:00
|
|
|
ad->ad_type->sat_syntax,
|
2000-05-25 04:21:46 +08:00
|
|
|
mr,
|
2001-12-29 23:01:10 +08:00
|
|
|
nv1.bv_val != NULL ? &nv1 : v1,
|
|
|
|
nv2.bv_val != NULL ? &nv2 : v2 );
|
2000-05-25 02:49:30 +08:00
|
|
|
|
2001-12-30 08:14:45 +08:00
|
|
|
if (nv1.bv_val ) free( nv1.bv_val );
|
|
|
|
if (nv2.bv_val ) free( nv2.bv_val );
|
2000-05-25 02:49:30 +08:00
|
|
|
return rc;
|
2000-05-22 06:46:51 +08:00
|
|
|
}
|
2000-05-25 02:49:30 +08:00
|
|
|
|
2001-10-23 17:43:20 +08:00
|
|
|
int value_find_ex(
|
2000-05-22 06:46:51 +08:00
|
|
|
AttributeDescription *ad,
|
2001-10-23 17:43:20 +08:00
|
|
|
unsigned flags,
|
2002-01-14 09:43:17 +08:00
|
|
|
BerVarray vals,
|
2000-05-29 00:36:34 +08:00
|
|
|
struct berval *val )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
int i;
|
2000-05-29 11:44:06 +08:00
|
|
|
int rc;
|
2001-12-30 08:38:44 +08:00
|
|
|
struct berval nval = { 0, NULL };
|
2000-05-29 00:36:34 +08:00
|
|
|
MatchingRule *mr = ad->ad_type->sat_equality;
|
|
|
|
|
2000-05-29 07:51:39 +08:00
|
|
|
if( mr == NULL || !mr->smr_match ) {
|
2000-05-29 00:36:34 +08:00
|
|
|
return LDAP_INAPPROPRIATE_MATCHING;
|
|
|
|
}
|
2000-05-29 11:44:06 +08:00
|
|
|
|
2003-02-27 09:54:43 +08:00
|
|
|
assert(SLAP_IS_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH( flags ));
|
|
|
|
|
|
|
|
if( !SLAP_IS_MR_ASSERTED_VALUE_NORMALIZED_MATCH( flags ) &&
|
|
|
|
mr->smr_normalize )
|
|
|
|
{
|
|
|
|
rc = (mr->smr_normalize)(
|
|
|
|
flags & SLAP_MR_TYPE_MASK|SLAP_MR_SUBTYPE_MASK,
|
|
|
|
ad ? ad->ad_type->sat_syntax : NULL,
|
|
|
|
mr, val, &nval );
|
|
|
|
|
|
|
|
if( rc != LDAP_SUCCESS ) {
|
|
|
|
return LDAP_INVALID_SYNTAX;
|
|
|
|
}
|
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2002-01-02 19:00:36 +08:00
|
|
|
for ( i = 0; vals[i].bv_val != NULL; i++ ) {
|
2000-05-25 02:49:30 +08:00
|
|
|
int match;
|
2000-05-29 00:36:34 +08:00
|
|
|
const char *text;
|
2000-05-29 11:44:06 +08:00
|
|
|
|
2001-11-28 05:59:56 +08:00
|
|
|
rc = value_match( &match, ad, mr, flags,
|
2002-01-02 19:00:36 +08:00
|
|
|
&vals[i], nval.bv_val == NULL ? val : &nval, &text );
|
2000-05-25 02:49:30 +08:00
|
|
|
|
2000-06-20 04:53:56 +08:00
|
|
|
if( rc == LDAP_SUCCESS && match == 0 ) {
|
2001-12-29 23:01:10 +08:00
|
|
|
free( nval.bv_val );
|
2000-05-22 06:46:51 +08:00
|
|
|
return LDAP_SUCCESS;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-29 23:01:10 +08:00
|
|
|
free( nval.bv_val );
|
2000-05-22 06:46:51 +08:00
|
|
|
return LDAP_NO_SUCH_ATTRIBUTE;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|