2001-12-10 17:50:06 +08:00
|
|
|
/* log.c - deal with log subsystem */
|
2003-11-27 10:35:20 +08:00
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2011-01-05 08:42:37 +08:00
|
|
|
* Copyright 2001-2011 The OpenLDAP Foundation.
|
2003-12-09 01:41:40 +08:00
|
|
|
* Portions Copyright 2001-2003 Pierangelo Masarati.
|
2003-11-27 10:35:20 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
*/
|
|
|
|
/* ACKNOWLEDGEMENTS:
|
|
|
|
* This work was initially developed by Pierangelo Masarati for inclusion
|
|
|
|
* in OpenLDAP Software.
|
|
|
|
*/
|
2001-12-10 17:50:06 +08:00
|
|
|
|
|
|
|
#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"
|
|
|
|
|
2005-10-16 01:37:18 +08:00
|
|
|
static int
|
|
|
|
monitor_subsys_log_open(
|
2005-08-09 04:45:10 +08:00
|
|
|
BackendDB *be,
|
|
|
|
monitor_subsys_t *ms );
|
|
|
|
|
|
|
|
static int
|
|
|
|
monitor_subsys_log_modify(
|
|
|
|
Operation *op,
|
|
|
|
SlapReply *rs,
|
|
|
|
Entry *e );
|
|
|
|
|
2001-12-10 17:50:06 +08:00
|
|
|
/*
|
|
|
|
* log mutex
|
|
|
|
*/
|
|
|
|
ldap_pvt_thread_mutex_t monitor_log_mutex;
|
|
|
|
|
2005-10-16 01:37:18 +08:00
|
|
|
static int add_values( Operation *op, Entry *e, Modification *mod, int *newlevel );
|
|
|
|
static int delete_values( Operation *op, Entry *e, Modification *mod, int *newlevel );
|
|
|
|
static int replace_values( Operation *op, Entry *e, Modification *mod, int *newlevel );
|
2001-12-10 17:50:06 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* initializes log subentry
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
monitor_subsys_log_init(
|
2004-11-09 02:52:27 +08:00
|
|
|
BackendDB *be,
|
2005-04-28 05:30:35 +08:00
|
|
|
monitor_subsys_t *ms )
|
2001-12-10 17:50:06 +08:00
|
|
|
{
|
2005-10-16 01:37:18 +08:00
|
|
|
ms->mss_open = monitor_subsys_log_open;
|
2005-08-09 04:45:10 +08:00
|
|
|
ms->mss_modify = monitor_subsys_log_modify;
|
|
|
|
|
2001-12-10 17:50:06 +08:00
|
|
|
ldap_pvt_thread_mutex_init( &monitor_log_mutex );
|
|
|
|
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
2005-10-16 01:37:18 +08:00
|
|
|
/*
|
|
|
|
* opens log subentry
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
monitor_subsys_log_open(
|
2005-08-09 04:45:10 +08:00
|
|
|
BackendDB *be,
|
|
|
|
monitor_subsys_t *ms )
|
|
|
|
{
|
2005-10-16 01:37:18 +08:00
|
|
|
BerVarray bva = NULL;
|
|
|
|
|
|
|
|
if ( loglevel2bvarray( ldap_syslog, &bva ) == 0 && bva != NULL ) {
|
|
|
|
monitor_info_t *mi;
|
|
|
|
Entry *e;
|
2005-08-09 04:45:10 +08:00
|
|
|
|
2005-10-16 01:37:18 +08:00
|
|
|
mi = ( monitor_info_t * )be->be_private;
|
|
|
|
|
|
|
|
if ( monitor_cache_get( mi, &ms->mss_ndn, &e ) ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"monitor_subsys_log_init: "
|
|
|
|
"unable to get entry \"%s\"\n",
|
|
|
|
ms->mss_ndn.bv_val, 0, 0 );
|
|
|
|
ber_bvarray_free( bva );
|
|
|
|
return( -1 );
|
2005-08-09 04:45:10 +08:00
|
|
|
}
|
2005-10-16 01:37:18 +08:00
|
|
|
|
|
|
|
attr_merge_normalize( e, mi->mi_ad_managedInfo, bva, NULL );
|
|
|
|
ber_bvarray_free( bva );
|
|
|
|
|
|
|
|
monitor_cache_release( mi, e );
|
2005-08-09 04:45:10 +08:00
|
|
|
}
|
|
|
|
|
2005-10-16 01:37:18 +08:00
|
|
|
return( 0 );
|
2005-08-09 04:45:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-12-10 17:50:06 +08:00
|
|
|
monitor_subsys_log_modify(
|
2003-04-12 07:08:16 +08:00
|
|
|
Operation *op,
|
2005-04-28 05:30:35 +08:00
|
|
|
SlapReply *rs,
|
|
|
|
Entry *e )
|
2001-12-10 17:50:06 +08:00
|
|
|
{
|
2004-11-09 02:52:27 +08:00
|
|
|
monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
|
2001-12-10 17:50:06 +08:00
|
|
|
int rc = LDAP_OTHER;
|
|
|
|
int newlevel = ldap_syslog;
|
|
|
|
Attribute *save_attrs;
|
2007-08-16 17:48:53 +08:00
|
|
|
Modifications *modlist = op->orm_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;
|
|
|
|
|
|
|
|
/*
|
2005-01-18 17:48:53 +08:00
|
|
|
* accept all operational attributes;
|
|
|
|
* this includes modifersName and modifyTimestamp
|
|
|
|
* if lastmod is "on"
|
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 );
|
2005-10-16 01:37:18 +08:00
|
|
|
rc = rs->sr_err = attr_merge( e, mod->sm_desc,
|
|
|
|
mod->sm_values, mod->sm_nvalues );
|
2005-04-28 05:30:35 +08:00
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
2001-12-10 17:50:06 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
2005-04-30 04:29:59 +08:00
|
|
|
* only the "managedInfo" attribute can be modified
|
2001-12-10 17:50:06 +08:00
|
|
|
*/
|
2005-04-28 05:30:35 +08:00
|
|
|
} else if ( mod->sm_desc != mi->mi_ad_managedInfo ) {
|
|
|
|
rc = rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
|
2001-12-10 17:50:06 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( mod->sm_op ) {
|
|
|
|
case LDAP_MOD_ADD:
|
2005-10-16 01:37:18 +08:00
|
|
|
rc = add_values( op, e, mod, &newlevel );
|
2001-12-10 17:50:06 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_MOD_DELETE:
|
2005-10-16 01:37:18 +08:00
|
|
|
rc = delete_values( op, e, mod, &newlevel );
|
2001-12-10 17:50:06 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_MOD_REPLACE:
|
2005-10-16 01:37:18 +08:00
|
|
|
rc = replace_values( op, e, mod, &newlevel );
|
2001-12-10 17:50:06 +08:00
|
|
|
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 ) {
|
2005-04-28 05:30:35 +08:00
|
|
|
rs->sr_err = rc;
|
2001-12-10 17:50:06 +08:00
|
|
|
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 ) {
|
2005-04-28 05:30:35 +08:00
|
|
|
rc = rs->sr_err = SLAPD_ABANDON;
|
2001-12-10 17:50:06 +08:00
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check that the entry still obeys the schema */
|
2009-02-05 06:36:49 +08:00
|
|
|
rc = entry_schema_check( op, e, save_attrs, 0, 0, NULL,
|
2005-05-14 03:07:31 +08:00
|
|
|
&text, textbuf, sizeof( textbuf ) );
|
2001-12-10 17:50:06 +08:00
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
2005-04-28 05:30:35 +08:00
|
|
|
rs->sr_err = rc;
|
2001-12-10 17:50:06 +08:00
|
|
|
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 );
|
|
|
|
|
2005-04-28 05:30:35 +08:00
|
|
|
if ( rc == LDAP_SUCCESS ) {
|
|
|
|
rc = SLAP_CB_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
2001-12-10 17:50:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-10-16 01:37:18 +08:00
|
|
|
check_constraints( Modification *mod, int *newlevel )
|
2001-12-10 17:50:06 +08:00
|
|
|
{
|
|
|
|
int i;
|
2003-04-08 07:22:27 +08:00
|
|
|
|
2005-10-16 01:37:18 +08:00
|
|
|
if ( mod->sm_nvalues != NULL ) {
|
|
|
|
ber_bvarray_free( mod->sm_nvalues );
|
|
|
|
mod->sm_nvalues = NULL;
|
2001-12-10 17:50:06 +08:00
|
|
|
}
|
|
|
|
|
2005-10-16 01:37:18 +08:00
|
|
|
for ( i = 0; !BER_BVISNULL( &mod->sm_values[ i ] ); i++ ) {
|
2003-04-08 07:22:27 +08:00
|
|
|
int l;
|
2005-10-16 01:37:18 +08:00
|
|
|
struct berval bv;
|
|
|
|
|
|
|
|
if ( str2loglevel( mod->sm_values[ i ].bv_val, &l ) ) {
|
2001-12-10 17:50:06 +08:00
|
|
|
return LDAP_CONSTRAINT_VIOLATION;
|
|
|
|
}
|
|
|
|
|
2005-10-16 01:37:18 +08:00
|
|
|
if ( loglevel2bv( l, &bv ) ) {
|
|
|
|
return LDAP_CONSTRAINT_VIOLATION;
|
2003-04-08 07:22:27 +08:00
|
|
|
}
|
2005-10-16 01:37:18 +08:00
|
|
|
|
|
|
|
assert( bv.bv_len == mod->sm_values[ i ].bv_len );
|
2001-12-10 17:50:06 +08:00
|
|
|
|
2004-11-08 18:55:33 +08:00
|
|
|
AC_MEMCPY( mod->sm_values[ i ].bv_val,
|
2005-10-16 01:37:18 +08:00
|
|
|
bv.bv_val, bv.bv_len );
|
2001-12-10 17:50:06 +08:00
|
|
|
|
2005-10-16 01:37:18 +08:00
|
|
|
*newlevel |= l;
|
2001-12-10 17:50:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return LDAP_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-10-16 01:37:18 +08:00
|
|
|
add_values( Operation *op, Entry *e, Modification *mod, int *newlevel )
|
2001-12-10 17:50:06 +08:00
|
|
|
{
|
|
|
|
Attribute *a;
|
|
|
|
int i, rc;
|
|
|
|
MatchingRule *mr = mod->sm_desc->ad_type->sat_equality;
|
|
|
|
|
2005-10-16 01:37:18 +08:00
|
|
|
assert( mod->sm_values != NULL );
|
|
|
|
|
2001-12-10 17:50:06 +08:00
|
|
|
rc = check_constraints( mod, newlevel );
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
a = attr_find( e->e_attrs, mod->sm_desc );
|
|
|
|
|
|
|
|
if ( a != NULL ) {
|
2005-04-30 04:29:59 +08:00
|
|
|
/* "managedInfo" SHOULD have appropriate rules ... */
|
2001-12-10 17:50:06 +08:00
|
|
|
if ( mr == NULL || !mr->smr_match ) {
|
|
|
|
return LDAP_INAPPROPRIATE_MATCHING;
|
|
|
|
}
|
|
|
|
|
2004-11-08 18:55:33 +08:00
|
|
|
for ( i = 0; !BER_BVISNULL( &mod->sm_values[ i ] ); 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,
|
2005-10-16 01:37:18 +08:00
|
|
|
&mod->sm_values[ i ], &asserted, &text,
|
|
|
|
op->o_tmpmemctx );
|
2001-12-10 17:50:06 +08:00
|
|
|
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2004-11-08 18:55:33 +08:00
|
|
|
for ( j = 0; !BER_BVISNULL( &a->a_vals[ j ] ); j++ ) {
|
2001-12-10 17:50:06 +08:00
|
|
|
int match;
|
|
|
|
int rc = value_match( &match, mod->sm_desc, mr,
|
2005-10-16 01:37:18 +08:00
|
|
|
0, &a->a_nvals[ 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 */
|
2005-10-16 01:37:18 +08:00
|
|
|
rc = attr_merge_normalize( e, mod->sm_desc, mod->sm_values,
|
|
|
|
op->o_tmpmemctx );
|
2003-04-09 07:30:58 +08:00
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
return rc;
|
2001-12-10 17:50:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return LDAP_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-10-16 01:37:18 +08:00
|
|
|
delete_values( Operation *op, Entry *e, Modification *mod, int *newlevel )
|
2001-12-10 17:50:06 +08:00
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
/* delete the entire attribute */
|
2004-04-08 14:49:17 +08:00
|
|
|
if ( mod->sm_values == NULL ) {
|
2001-12-10 17:50:06 +08:00
|
|
|
int rc = attr_delete( &e->e_attrs, mod->sm_desc );
|
|
|
|
|
|
|
|
if ( rc ) {
|
|
|
|
rc = LDAP_NO_SUCH_ATTRIBUTE;
|
2005-10-15 23:43:53 +08:00
|
|
|
|
2001-12-10 17:50:06 +08:00
|
|
|
} else {
|
|
|
|
*newlevel = 0;
|
|
|
|
rc = LDAP_SUCCESS;
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2005-10-16 01:37:18 +08:00
|
|
|
rc = check_constraints( mod, &nl );
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
*newlevel &= ~nl;
|
|
|
|
|
2001-12-10 17:50:06 +08:00
|
|
|
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 */
|
2004-11-08 18:55:33 +08:00
|
|
|
for ( i = 0; !BER_BVISNULL( &mod->sm_values[ i ] ); 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,
|
2005-10-16 01:37:18 +08:00
|
|
|
&mod->sm_values[ i ], &asserted, &text,
|
|
|
|
op->o_tmpmemctx );
|
2001-12-10 17:50:06 +08:00
|
|
|
|
|
|
|
if( rc != LDAP_SUCCESS ) return rc;
|
|
|
|
|
|
|
|
found = 0;
|
2004-11-08 18:55:33 +08:00
|
|
|
for ( j = 0; !BER_BVISNULL( &a->a_vals[ j ] ); j++ ) {
|
2001-12-10 17:50:06 +08:00
|
|
|
int match;
|
|
|
|
int rc = value_match( &match, mod->sm_desc, mr,
|
2005-10-16 01:37:18 +08:00
|
|
|
0, &a->a_nvals[ 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 */
|
2005-10-16 01:37:18 +08:00
|
|
|
if ( a->a_nvals != a->a_vals ) {
|
|
|
|
free( a->a_nvals[ j ].bv_val );
|
|
|
|
for ( k = j + 1; !BER_BVISNULL( &a->a_nvals[ k ] ); k++ ) {
|
|
|
|
a->a_nvals[ k - 1 ] = a->a_nvals[ k ];
|
|
|
|
}
|
|
|
|
BER_BVZERO( &a->a_nvals[ k - 1 ] );
|
|
|
|
}
|
|
|
|
|
2004-11-08 18:55:33 +08:00
|
|
|
free( a->a_vals[ j ].bv_val );
|
|
|
|
for ( k = j + 1; !BER_BVISNULL( &a->a_vals[ k ] ); k++ ) {
|
|
|
|
a->a_vals[ k - 1 ] = a->a_vals[ k ];
|
2001-12-10 17:50:06 +08:00
|
|
|
}
|
2004-11-08 18:55:33 +08:00
|
|
|
BER_BVZERO( &a->a_vals[ k - 1 ] );
|
2008-01-09 01:02:37 +08:00
|
|
|
a->a_numvals--;
|
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 */
|
2004-11-08 18:55:33 +08:00
|
|
|
if ( BER_BVISNULL( &a->a_vals[ 0 ] ) ) {
|
2008-01-09 01:02:37 +08:00
|
|
|
assert( a->a_numvals == 0 );
|
|
|
|
|
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
|
2005-10-16 01:37:18 +08:00
|
|
|
replace_values( Operation *op, Entry *e, Modification *mod, int *newlevel )
|
2001-12-10 17:50:06 +08:00
|
|
|
{
|
2001-12-25 10:30:01 +08:00
|
|
|
int rc;
|
2001-12-10 17:50:06 +08:00
|
|
|
|
2005-10-16 01:37:18 +08:00
|
|
|
if ( mod->sm_values != NULL ) {
|
|
|
|
*newlevel = 0;
|
|
|
|
rc = check_constraints( mod, newlevel );
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
return rc;
|
|
|
|
}
|
2001-12-10 17:50:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rc = attr_delete( &e->e_attrs, mod->sm_desc );
|
|
|
|
|
|
|
|
if ( rc != LDAP_SUCCESS && rc != LDAP_NO_SUCH_ATTRIBUTE ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2004-04-08 14:49:17 +08:00
|
|
|
if ( mod->sm_values != NULL ) {
|
2005-10-16 01:37:18 +08:00
|
|
|
rc = attr_merge_normalize( e, mod->sm_desc, mod->sm_values,
|
|
|
|
op->o_tmpmemctx );
|
2003-04-09 07:30:58 +08:00
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
return rc;
|
|
|
|
}
|
2001-12-10 17:50:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return LDAP_SUCCESS;
|
|
|
|
}
|
|
|
|
|