2001-12-10 17:50:06 +08:00
|
|
|
/* log.c - deal with log subsystem */
|
|
|
|
/*
|
2003-01-04 04:20:47 +08:00
|
|
|
* Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
|
2001-12-10 17:50:06 +08:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
|
|
|
|
*
|
|
|
|
* This work has beed deveolped for the OpenLDAP Foundation
|
|
|
|
* in the hope that it may be useful to the Open Source community,
|
|
|
|
* but WITHOUT ANY WARRANTY.
|
|
|
|
*
|
|
|
|
* Permission is granted to anyone to use this software for any purpose
|
|
|
|
* on any computer system, and to alter it and redistribute it, subject
|
|
|
|
* to the following restrictions:
|
|
|
|
*
|
|
|
|
* 1. The author and SysNet s.n.c. are not responsible for the consequences
|
|
|
|
* of use of this software, no matter how awful, even if they arise from
|
|
|
|
* flaws in it.
|
|
|
|
*
|
|
|
|
* 2. The origin of this software must not be misrepresented, either by
|
|
|
|
* explicit claim or by omission. Since few users ever read sources,
|
|
|
|
* credits should appear in the documentation.
|
|
|
|
*
|
|
|
|
* 3. Altered versions must be plainly marked as such, and must not be
|
|
|
|
* misrepresented as being the original software. Since few users
|
|
|
|
* ever read sources, credits should appear in the documentation.
|
|
|
|
* SysNet s.n.c. cannot be responsible for the consequences of the
|
|
|
|
* alterations.
|
|
|
|
*
|
|
|
|
* 4. This notice may not be removed or altered.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
|
|
|
|
#include "slap.h"
|
2003-04-08 07:22:27 +08:00
|
|
|
#include <lber_pvt.h>
|
2001-12-10 17:50:06 +08:00
|
|
|
#include "lutil.h"
|
|
|
|
#include "ldif.h"
|
|
|
|
#include "back-monitor.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* log mutex
|
|
|
|
*/
|
|
|
|
ldap_pvt_thread_mutex_t monitor_log_mutex;
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
int i;
|
2003-04-08 07:22:27 +08:00
|
|
|
struct berval s;
|
|
|
|
struct berval n;
|
2001-12-10 17:50:06 +08:00
|
|
|
} int_2_level[] = {
|
2003-04-08 07:22:27 +08:00
|
|
|
{ LDAP_DEBUG_TRACE, BER_BVC("Trace"), { 0, NULL } },
|
|
|
|
{ LDAP_DEBUG_PACKETS, BER_BVC("Packets"), { 0, NULL } },
|
|
|
|
{ LDAP_DEBUG_ARGS, BER_BVC("Args"), { 0, NULL } },
|
|
|
|
{ LDAP_DEBUG_CONNS, BER_BVC("Conns"), { 0, NULL } },
|
|
|
|
{ LDAP_DEBUG_BER, BER_BVC("BER"), { 0, NULL } },
|
|
|
|
{ LDAP_DEBUG_FILTER, BER_BVC("Filter"), { 0, NULL } },
|
|
|
|
{ LDAP_DEBUG_CONFIG, BER_BVC("Config"), { 0, NULL } }, /* useless */
|
|
|
|
{ LDAP_DEBUG_ACL, BER_BVC("ACL"), { 0, NULL } },
|
|
|
|
{ LDAP_DEBUG_STATS, BER_BVC("Stats"), { 0, NULL } },
|
|
|
|
{ LDAP_DEBUG_STATS2, BER_BVC("Stats2"), { 0, NULL } },
|
|
|
|
{ LDAP_DEBUG_SHELL, BER_BVC("Shell"), { 0, NULL } },
|
|
|
|
{ LDAP_DEBUG_PARSE, BER_BVC("Parse"), { 0, NULL } },
|
|
|
|
{ LDAP_DEBUG_CACHE, BER_BVC("Cache"), { 0, NULL } },
|
|
|
|
{ LDAP_DEBUG_INDEX, BER_BVC("Index"), { 0, NULL } },
|
|
|
|
{ 0, { 0, NULL }, { 0, NULL } }
|
2001-12-10 17:50:06 +08:00
|
|
|
};
|
|
|
|
|
2003-04-08 07:22:27 +08:00
|
|
|
static int loglevel2int( struct berval *l );
|
|
|
|
static int int2loglevel( int n );
|
2001-12-10 17:50:06 +08:00
|
|
|
|
|
|
|
static int add_values( Entry *e, Modification *mod, int *newlevel );
|
|
|
|
static int delete_values( Entry *e, Modification *mod, int *newlevel );
|
|
|
|
static int replace_values( Entry *e, Modification *mod, int *newlevel );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* initializes log subentry
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
monitor_subsys_log_init(
|
|
|
|
BackendDB *be
|
|
|
|
)
|
|
|
|
{
|
|
|
|
struct monitorinfo *mi;
|
|
|
|
Entry *e;
|
|
|
|
int i;
|
2003-04-13 01:41:49 +08:00
|
|
|
struct berval desc[] = {
|
|
|
|
BER_BVC("This entry allows to set the log level runtime."),
|
|
|
|
BER_BVC("Set the attribute 'managedInfo' to the desired log levels."),
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
2001-12-10 17:50:06 +08:00
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_init( &monitor_log_mutex );
|
|
|
|
|
|
|
|
mi = ( struct monitorinfo * )be->be_private;
|
|
|
|
|
2002-01-03 02:14:29 +08:00
|
|
|
if ( monitor_cache_get( mi, &monitor_subsys[SLAPD_MONITOR_LOG].mss_ndn,
|
2001-12-10 17:50:06 +08:00
|
|
|
&e ) ) {
|
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( OPERATION, CRIT,
|
2001-12-10 17:50:06 +08:00
|
|
|
"monitor_subsys_log_init: "
|
|
|
|
"unable to get entry '%s'\n",
|
2002-07-12 04:33:24 +08:00
|
|
|
monitor_subsys[SLAPD_MONITOR_LOG].mss_ndn.bv_val, 0, 0 );
|
2001-12-10 17:50:06 +08:00
|
|
|
#else
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"monitor_subsys_log_init: "
|
|
|
|
"unable to get entry '%s'\n%s%s",
|
2002-01-03 02:14:29 +08:00
|
|
|
monitor_subsys[SLAPD_MONITOR_LOG].mss_ndn.bv_val,
|
2001-12-10 17:50:06 +08:00
|
|
|
"", "" );
|
|
|
|
#endif
|
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
|
2003-04-08 07:22:27 +08:00
|
|
|
/* initialize the debug level(s) */
|
2001-12-10 17:50:06 +08:00
|
|
|
for ( i = 0; int_2_level[ i ].i != 0; i++ ) {
|
|
|
|
|
2003-04-13 01:41:49 +08:00
|
|
|
if ( mi->ad_managedInfo->ad_type->sat_equality->smr_normalize ) {
|
2003-04-08 07:22:27 +08:00
|
|
|
int rc;
|
|
|
|
|
2003-04-13 01:41:49 +08:00
|
|
|
rc = (*mi->ad_managedInfo->ad_type->sat_equality->smr_normalize)(
|
2003-04-08 07:22:27 +08:00
|
|
|
0,
|
2003-04-13 01:41:49 +08:00
|
|
|
mi->ad_managedInfo->ad_type->sat_syntax,
|
|
|
|
mi->ad_managedInfo->ad_type->sat_equality,
|
2003-04-08 07:22:27 +08:00
|
|
|
&int_2_level[ i ].s,
|
2003-04-12 06:30:48 +08:00
|
|
|
&int_2_level[ i ].n, NULL );
|
2003-04-08 07:22:27 +08:00
|
|
|
if ( rc ) {
|
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( int_2_level[ i ].i & ldap_syslog ) {
|
2003-04-13 01:41:49 +08:00
|
|
|
attr_merge_one( e, mi->ad_managedInfo,
|
2003-04-08 07:22:27 +08:00
|
|
|
&int_2_level[ i ].s,
|
|
|
|
&int_2_level[ i ].n );
|
2001-12-10 17:50:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-13 01:41:49 +08:00
|
|
|
attr_merge( e, mi->ad_description, desc, NULL );
|
|
|
|
|
2001-12-10 17:50:06 +08:00
|
|
|
monitor_cache_release( mi, e );
|
|
|
|
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
monitor_subsys_log_modify(
|
2003-04-12 07:08:16 +08:00
|
|
|
Operation *op,
|
2003-04-12 09:17:05 +08:00
|
|
|
Entry *e
|
2001-12-10 17:50:06 +08:00
|
|
|
)
|
|
|
|
{
|
2003-04-12 08:30:47 +08:00
|
|
|
struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
|
2001-12-10 17:50:06 +08:00
|
|
|
int rc = LDAP_OTHER;
|
|
|
|
int newlevel = ldap_syslog;
|
|
|
|
Attribute *save_attrs;
|
2003-04-12 09:17:05 +08:00
|
|
|
Modifications *modlist = op->oq_modify.rs_modlist;
|
2001-12-10 17:50:06 +08:00
|
|
|
Modifications *ml;
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_lock( &monitor_log_mutex );
|
|
|
|
|
|
|
|
save_attrs = e->e_attrs;
|
|
|
|
e->e_attrs = attrs_dup( e->e_attrs );
|
|
|
|
|
|
|
|
for ( ml = modlist; ml != NULL; ml = ml->sml_next ) {
|
|
|
|
Modification *mod = &ml->sml_mod;
|
|
|
|
|
|
|
|
/*
|
2001-12-28 23:58:51 +08:00
|
|
|
* accept all operational attributes
|
2001-12-10 17:50:06 +08:00
|
|
|
*/
|
|
|
|
if ( is_at_operational( mod->sm_desc->ad_type ) ) {
|
|
|
|
( void ) attr_delete( &e->e_attrs, mod->sm_desc );
|
2003-04-09 07:30:58 +08:00
|
|
|
rc = attr_merge( e, mod->sm_desc, mod->sm_bvalues,
|
|
|
|
mod->sm_nvalues );
|
2001-12-10 17:50:06 +08:00
|
|
|
if ( rc != 0 ) {
|
|
|
|
rc = LDAP_OTHER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* only the monitor description attribute can be modified
|
|
|
|
*/
|
2003-04-13 01:41:49 +08:00
|
|
|
} else if ( mod->sm_desc != mi->ad_managedInfo) {
|
2001-12-10 17:50:06 +08:00
|
|
|
rc = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( mod->sm_op ) {
|
|
|
|
case LDAP_MOD_ADD:
|
|
|
|
rc = add_values( e, mod, &newlevel );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_MOD_DELETE:
|
|
|
|
rc = delete_values( e, mod, &newlevel );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_MOD_REPLACE:
|
|
|
|
rc = replace_values( e, mod, &newlevel );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2002-08-01 06:49:02 +08:00
|
|
|
rc = LDAP_OTHER;
|
2001-12-10 17:50:06 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set the new debug level */
|
|
|
|
if ( rc == LDAP_SUCCESS ) {
|
2003-05-15 09:19:30 +08:00
|
|
|
const char *text;
|
|
|
|
static char textbuf[ BACKMONITOR_BUFSIZE ];
|
2001-12-10 17:50:06 +08:00
|
|
|
|
|
|
|
/* check for abandon */
|
|
|
|
if ( op->o_abandon ) {
|
|
|
|
rc = SLAPD_ABANDON;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check that the entry still obeys the schema */
|
2002-01-11 04:12:25 +08:00
|
|
|
rc = entry_schema_check( be_monitor, e, save_attrs,
|
|
|
|
&text, textbuf, sizeof( textbuf ) );
|
2001-12-10 17:50:06 +08:00
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2002-04-02 22:38:57 +08:00
|
|
|
/*
|
|
|
|
* Do we need to protect this with a mutex?
|
|
|
|
*/
|
2001-12-10 17:50:06 +08:00
|
|
|
ldap_syslog = newlevel;
|
|
|
|
|
2001-12-28 23:58:51 +08:00
|
|
|
#if 0 /* debug rather than log */
|
2001-12-10 17:50:06 +08:00
|
|
|
slap_debug = newlevel;
|
|
|
|
lutil_set_debug_level( "slapd", slap_debug );
|
|
|
|
ber_set_option(NULL, LBER_OPT_DEBUG_LEVEL, &slap_debug);
|
|
|
|
ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, &slap_debug);
|
|
|
|
ldif_debug = slap_debug;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:;
|
|
|
|
if ( rc == LDAP_SUCCESS ) {
|
|
|
|
attrs_free( save_attrs );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
attrs_free( e->e_attrs );
|
|
|
|
e->e_attrs = save_attrs;
|
|
|
|
}
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_unlock( &monitor_log_mutex );
|
|
|
|
|
|
|
|
return( rc );
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-04-08 07:22:27 +08:00
|
|
|
loglevel2int( struct berval *l )
|
2001-12-10 17:50:06 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for ( i = 0; int_2_level[ i ].i != 0; i++ ) {
|
2003-04-08 07:22:27 +08:00
|
|
|
if ( l->bv_len != int_2_level[ i ].s.bv_len ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( strcasecmp( l->bv_val, int_2_level[ i ].s.bv_val ) == 0 ) {
|
2001-12-10 17:50:06 +08:00
|
|
|
return int_2_level[ i ].i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-04-08 07:22:27 +08:00
|
|
|
static int
|
2001-12-10 17:50:06 +08:00
|
|
|
int2loglevel( int n )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for ( i = 0; int_2_level[ i ].i != 0; i++ ) {
|
|
|
|
if ( int_2_level[ i ].i == n ) {
|
2003-04-08 07:22:27 +08:00
|
|
|
return i;
|
2001-12-10 17:50:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-08 07:22:27 +08:00
|
|
|
return -1;
|
2001-12-10 17:50:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
check_constraints( Modification *mod, int *newlevel )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2002-01-02 21:28:10 +08:00
|
|
|
for ( i = 0; mod->sm_bvalues && mod->sm_bvalues[i].bv_val != NULL; i++ ) {
|
2003-04-08 07:22:27 +08:00
|
|
|
int l;
|
2001-12-10 17:50:06 +08:00
|
|
|
|
2003-04-08 07:22:27 +08:00
|
|
|
l = loglevel2int( &mod->sm_bvalues[i] );
|
2001-12-10 17:50:06 +08:00
|
|
|
if ( !l ) {
|
|
|
|
return LDAP_CONSTRAINT_VIOLATION;
|
|
|
|
}
|
|
|
|
|
2003-04-08 07:22:27 +08:00
|
|
|
if ( ( l = int2loglevel( l ) ) == -1 ) {
|
|
|
|
return LDAP_OTHER;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert( int_2_level[ l ].s.bv_len
|
|
|
|
== mod->sm_bvalues[i].bv_len );
|
2001-12-10 17:50:06 +08:00
|
|
|
|
2003-04-08 07:22:27 +08:00
|
|
|
AC_MEMCPY( mod->sm_bvalues[i].bv_val,
|
|
|
|
int_2_level[ l ].s.bv_val,
|
|
|
|
int_2_level[ l ].s.bv_len );
|
|
|
|
|
|
|
|
AC_MEMCPY( mod->sm_nvalues[i].bv_val,
|
|
|
|
int_2_level[ l ].n.bv_val,
|
|
|
|
int_2_level[ l ].n.bv_len );
|
2001-12-10 17:50:06 +08:00
|
|
|
|
|
|
|
*newlevel |= l;
|
|
|
|
}
|
|
|
|
|
|
|
|
return LDAP_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
add_values( Entry *e, Modification *mod, int *newlevel )
|
|
|
|
{
|
|
|
|
Attribute *a;
|
|
|
|
int i, rc;
|
|
|
|
MatchingRule *mr = mod->sm_desc->ad_type->sat_equality;
|
|
|
|
|
|
|
|
rc = check_constraints( mod, newlevel );
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
a = attr_find( e->e_attrs, mod->sm_desc );
|
|
|
|
|
|
|
|
if ( a != NULL ) {
|
|
|
|
/* "description" SHOULD have appropriate rules ... */
|
|
|
|
if ( mr == NULL || !mr->smr_match ) {
|
|
|
|
return LDAP_INAPPROPRIATE_MATCHING;
|
|
|
|
}
|
|
|
|
|
2002-01-02 21:28:10 +08:00
|
|
|
for ( i = 0; mod->sm_bvalues[i].bv_val != NULL; i++ ) {
|
2001-12-10 17:50:06 +08:00
|
|
|
int rc;
|
|
|
|
int j;
|
|
|
|
const char *text = NULL;
|
2001-12-29 23:01:10 +08:00
|
|
|
struct berval asserted;
|
2001-12-10 17:50:06 +08:00
|
|
|
|
2003-03-01 12:14:17 +08:00
|
|
|
rc = asserted_value_validate_normalize(
|
2003-04-12 06:30:48 +08:00
|
|
|
mod->sm_desc, mr, SLAP_MR_EQUALITY,
|
|
|
|
&mod->sm_bvalues[i], &asserted, &text, NULL );
|
2001-12-10 17:50:06 +08:00
|
|
|
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2002-01-02 21:28:10 +08:00
|
|
|
for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) {
|
2001-12-10 17:50:06 +08:00
|
|
|
int match;
|
|
|
|
int rc = value_match( &match, mod->sm_desc, mr,
|
2003-02-27 09:54:43 +08:00
|
|
|
0,
|
2003-02-26 10:55:28 +08:00
|
|
|
&a->a_vals[j], &asserted, &text );
|
2001-12-10 17:50:06 +08:00
|
|
|
|
|
|
|
if ( rc == LDAP_SUCCESS && match == 0 ) {
|
2001-12-29 23:01:10 +08:00
|
|
|
free( asserted.bv_val );
|
2001-12-10 17:50:06 +08:00
|
|
|
return LDAP_TYPE_OR_VALUE_EXISTS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-29 23:01:10 +08:00
|
|
|
free( asserted.bv_val );
|
2001-12-10 17:50:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no - add them */
|
2003-04-09 07:30:58 +08:00
|
|
|
rc = attr_merge( e, mod->sm_desc, mod->sm_bvalues, mod->sm_nvalues );
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
2003-02-26 05:19:42 +08:00
|
|
|
/* this should return result of attr_mergeit */
|
2003-04-09 07:30:58 +08:00
|
|
|
return rc;
|
2001-12-10 17:50:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return LDAP_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
delete_values( Entry *e, Modification *mod, int *newlevel )
|
|
|
|
{
|
|
|
|
int i, j, k, found, rc, nl = 0;
|
|
|
|
Attribute *a;
|
2001-12-27 23:16:12 +08:00
|
|
|
MatchingRule *mr = mod->sm_desc->ad_type->sat_equality;
|
2001-12-10 17:50:06 +08:00
|
|
|
|
|
|
|
rc = check_constraints( mod, &nl );
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
*newlevel &= ~nl;
|
|
|
|
|
|
|
|
/* delete the entire attribute */
|
|
|
|
if ( mod->sm_bvalues == NULL ) {
|
|
|
|
int rc = attr_delete( &e->e_attrs, mod->sm_desc );
|
|
|
|
|
|
|
|
if ( rc ) {
|
|
|
|
rc = LDAP_NO_SUCH_ATTRIBUTE;
|
|
|
|
} else {
|
|
|
|
*newlevel = 0;
|
|
|
|
rc = LDAP_SUCCESS;
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( mr == NULL || !mr->smr_match ) {
|
|
|
|
/* disallow specific attributes from being deleted if
|
|
|
|
* no equality rule */
|
|
|
|
return LDAP_INAPPROPRIATE_MATCHING;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* delete specific values - find the attribute first */
|
|
|
|
if ( (a = attr_find( e->e_attrs, mod->sm_desc )) == NULL ) {
|
|
|
|
return( LDAP_NO_SUCH_ATTRIBUTE );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find each value to delete */
|
2002-01-02 21:28:10 +08:00
|
|
|
for ( i = 0; mod->sm_bvalues[i].bv_val != NULL; i++ ) {
|
2001-12-10 17:50:06 +08:00
|
|
|
int rc;
|
|
|
|
const char *text = NULL;
|
|
|
|
|
2001-12-29 23:01:10 +08:00
|
|
|
struct berval asserted;
|
2001-12-10 17:50:06 +08:00
|
|
|
|
2003-03-01 12:14:17 +08:00
|
|
|
rc = asserted_value_validate_normalize(
|
2003-04-12 06:30:48 +08:00
|
|
|
mod->sm_desc, mr, SLAP_MR_EQUALITY,
|
|
|
|
&mod->sm_bvalues[i], &asserted, &text, NULL );
|
2001-12-10 17:50:06 +08:00
|
|
|
|
|
|
|
if( rc != LDAP_SUCCESS ) return rc;
|
|
|
|
|
|
|
|
found = 0;
|
2002-01-02 21:28:10 +08:00
|
|
|
for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) {
|
2001-12-10 17:50:06 +08:00
|
|
|
int match;
|
|
|
|
int rc = value_match( &match, mod->sm_desc, mr,
|
2003-02-27 09:54:43 +08:00
|
|
|
0,
|
2003-02-26 10:55:28 +08:00
|
|
|
&a->a_vals[j], &asserted, &text );
|
2001-12-10 17:50:06 +08:00
|
|
|
|
|
|
|
if( rc == LDAP_SUCCESS && match != 0 ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* found a matching value */
|
|
|
|
found = 1;
|
|
|
|
|
|
|
|
/* delete it */
|
2002-01-02 21:28:10 +08:00
|
|
|
free( a->a_vals[j].bv_val );
|
|
|
|
for ( k = j + 1; a->a_vals[k].bv_val != NULL; k++ ) {
|
2001-12-10 17:50:06 +08:00
|
|
|
a->a_vals[k - 1] = a->a_vals[k];
|
|
|
|
}
|
2002-01-02 21:28:10 +08:00
|
|
|
a->a_vals[k - 1].bv_val = NULL;
|
2001-12-10 17:50:06 +08:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-12-29 23:01:10 +08:00
|
|
|
free( asserted.bv_val );
|
2001-12-10 17:50:06 +08:00
|
|
|
|
|
|
|
/* looked through them all w/o finding it */
|
|
|
|
if ( ! found ) {
|
|
|
|
return LDAP_NO_SUCH_ATTRIBUTE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if no values remain, delete the entire attribute */
|
2002-01-02 21:28:10 +08:00
|
|
|
if ( a->a_vals[0].bv_val == NULL ) {
|
2001-12-10 17:50:06 +08:00
|
|
|
/* should already be zero */
|
|
|
|
*newlevel = 0;
|
|
|
|
|
|
|
|
if ( attr_delete( &e->e_attrs, mod->sm_desc ) ) {
|
|
|
|
return LDAP_NO_SUCH_ATTRIBUTE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return LDAP_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
replace_values( Entry *e, Modification *mod, int *newlevel )
|
|
|
|
{
|
2001-12-25 10:30:01 +08:00
|
|
|
int rc;
|
2001-12-10 17:50:06 +08:00
|
|
|
|
|
|
|
*newlevel = 0;
|
|
|
|
rc = check_constraints( mod, newlevel );
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = attr_delete( &e->e_attrs, mod->sm_desc );
|
|
|
|
|
|
|
|
if ( rc != LDAP_SUCCESS && rc != LDAP_NO_SUCH_ATTRIBUTE ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2003-04-09 07:30:58 +08:00
|
|
|
if ( mod->sm_bvalues != NULL ) {
|
|
|
|
rc = attr_merge( e, mod->sm_desc, mod->sm_bvalues,
|
|
|
|
mod->sm_nvalues );
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
return rc;
|
|
|
|
}
|
2001-12-10 17:50:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return LDAP_SUCCESS;
|
|
|
|
}
|
|
|
|
|