X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-monitor%2Flog.c;h=6a390891d463c49949a3e2c02537464bc85c34cf;hb=63e843d2003ddf20f3725ad439991e769ffc792a;hp=6b072071b27ceb62f34dd9c0d6263ef8f5cc6a36;hpb=072280600ad3957d790e190c4f4fa053e5bda31d;p=openldap
diff --git a/servers/slapd/back-monitor/log.c b/servers/slapd/back-monitor/log.c
index 6b072071b2..6a390891d4 100644
--- a/servers/slapd/back-monitor/log.c
+++ b/servers/slapd/back-monitor/log.c
@@ -1,34 +1,22 @@
/* log.c - deal with log subsystem */
-/*
- * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software .
+ *
+ * Copyright 2001-2005 The OpenLDAP Foundation.
+ * Portions Copyright 2001-2003 Pierangelo Masarati.
+ * 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
+ * .
*/
-/*
- * Copyright 2001, Pierangelo Masarati, All rights reserved.
- *
- * 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.
+/* ACKNOWLEDGEMENTS:
+ * This work was initially developed by Pierangelo Masarati for inclusion
+ * in OpenLDAP Software.
*/
#include "portable.h"
@@ -43,6 +31,17 @@
#include "ldif.h"
#include "back-monitor.h"
+static int
+monitor_subsys_log_destroy(
+ BackendDB *be,
+ monitor_subsys_t *ms );
+
+static int
+monitor_subsys_log_modify(
+ Operation *op,
+ SlapReply *rs,
+ Entry *e );
+
/*
* log mutex
*/
@@ -53,21 +52,21 @@ static struct {
struct berval s;
struct berval n;
} int_2_level[] = {
- { 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 } }
+ { LDAP_DEBUG_TRACE, BER_BVC("Trace"), BER_BVNULL },
+ { LDAP_DEBUG_PACKETS, BER_BVC("Packets"), BER_BVNULL },
+ { LDAP_DEBUG_ARGS, BER_BVC("Args"), BER_BVNULL },
+ { LDAP_DEBUG_CONNS, BER_BVC("Conns"), BER_BVNULL },
+ { LDAP_DEBUG_BER, BER_BVC("BER"), BER_BVNULL },
+ { LDAP_DEBUG_FILTER, BER_BVC("Filter"), BER_BVNULL },
+ { LDAP_DEBUG_CONFIG, BER_BVC("Config"), BER_BVNULL }, /* useless */
+ { LDAP_DEBUG_ACL, BER_BVC("ACL"), BER_BVNULL },
+ { LDAP_DEBUG_STATS, BER_BVC("Stats"), BER_BVNULL },
+ { LDAP_DEBUG_STATS2, BER_BVC("Stats2"), BER_BVNULL },
+ { LDAP_DEBUG_SHELL, BER_BVC("Shell"), BER_BVNULL },
+ { LDAP_DEBUG_PARSE, BER_BVC("Parse"), BER_BVNULL },
+ { LDAP_DEBUG_CACHE, BER_BVC("Cache"), BER_BVNULL },
+ { LDAP_DEBUG_INDEX, BER_BVC("Index"), BER_BVNULL },
+ { 0, BER_BVNULL, BER_BVNULL }
};
static int loglevel2int( struct berval *l );
@@ -82,47 +81,36 @@ static int replace_values( Entry *e, Modification *mod, int *newlevel );
*/
int
monitor_subsys_log_init(
- BackendDB *be
-)
+ BackendDB *be,
+ monitor_subsys_t *ms )
{
- struct monitorinfo *mi;
- Entry *e;
- int i;
- 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 }
- };
+ monitor_info_t *mi;
+ Entry *e;
+ int i;
+
+ ms->mss_destroy = monitor_subsys_log_destroy;
+ ms->mss_modify = monitor_subsys_log_modify;
ldap_pvt_thread_mutex_init( &monitor_log_mutex );
- mi = ( struct monitorinfo * )be->be_private;
+ mi = ( monitor_info_t * )be->be_private;
- if ( monitor_cache_get( mi, &monitor_subsys[SLAPD_MONITOR_LOG].mss_ndn,
+ if ( monitor_cache_get( mi, &ms->mss_ndn,
&e ) ) {
-#ifdef NEW_LOGGING
- LDAP_LOG( OPERATION, CRIT,
- "monitor_subsys_log_init: "
- "unable to get entry '%s'\n",
- monitor_subsys[SLAPD_MONITOR_LOG].mss_ndn.bv_val, 0, 0 );
-#else
Debug( LDAP_DEBUG_ANY,
"monitor_subsys_log_init: "
- "unable to get entry '%s'\n%s%s",
- monitor_subsys[SLAPD_MONITOR_LOG].mss_ndn.bv_val,
- "", "" );
-#endif
+ "unable to get entry \"%s\"\n",
+ ms->mss_ndn.bv_val, 0, 0 );
return( -1 );
}
/* initialize the debug level(s) */
for ( i = 0; int_2_level[ i ].i != 0; i++ ) {
-
if ( mi->mi_ad_managedInfo->ad_type->sat_equality->smr_normalize ) {
int rc;
rc = (*mi->mi_ad_managedInfo->ad_type->sat_equality->smr_normalize)(
- 0,
+ SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
mi->mi_ad_managedInfo->ad_type->sat_syntax,
mi->mi_ad_managedInfo->ad_type->sat_equality,
&int_2_level[ i ].s,
@@ -139,20 +127,34 @@ monitor_subsys_log_init(
}
}
- attr_merge( e, mi->mi_ad_description, desc, NULL );
-
monitor_cache_release( mi, e );
return( 0 );
}
-int
+static int
+monitor_subsys_log_destroy(
+ BackendDB *be,
+ monitor_subsys_t *ms )
+{
+ int i;
+
+ for ( i = 0; int_2_level[ i ].i != 0; i++ ) {
+ if ( !BER_BVISNULL( &int_2_level[ i ].n ) ) {
+ ch_free( int_2_level[ i ].n.bv_val );
+ }
+ }
+
+ return 0;
+}
+
+static int
monitor_subsys_log_modify(
Operation *op,
- Entry *e
-)
+ SlapReply *rs,
+ Entry *e )
{
- struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
+ monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
int rc = LDAP_OTHER;
int newlevel = ldap_syslog;
Attribute *save_attrs;
@@ -168,23 +170,23 @@ monitor_subsys_log_modify(
Modification *mod = &ml->sml_mod;
/*
- * accept all operational attributes
+ * accept all operational attributes;
+ * this includes modifersName and modifyTimestamp
+ * if lastmod is "on"
*/
if ( is_at_operational( mod->sm_desc->ad_type ) ) {
( void ) attr_delete( &e->e_attrs, mod->sm_desc );
- rc = attr_merge( e, mod->sm_desc, mod->sm_bvalues,
- mod->sm_nvalues );
- if ( rc != 0 ) {
- rc = LDAP_OTHER;
+ rc = rs->sr_err = attr_merge( e, mod->sm_desc, mod->sm_values, mod->sm_nvalues );
+ if ( rc != LDAP_SUCCESS ) {
break;
}
continue;
/*
- * only the monitor description attribute can be modified
+ * only the "managedInfo" attribute can be modified
*/
- } else if ( mod->sm_desc != mi->mi_ad_managedInfo) {
- rc = LDAP_UNWILLING_TO_PERFORM;
+ } else if ( mod->sm_desc != mi->mi_ad_managedInfo ) {
+ rc = rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
break;
}
@@ -207,6 +209,7 @@ monitor_subsys_log_modify(
}
if ( rc != LDAP_SUCCESS ) {
+ rs->sr_err = rc;
break;
}
}
@@ -218,15 +221,16 @@ monitor_subsys_log_modify(
/* check for abandon */
if ( op->o_abandon ) {
- rc = SLAPD_ABANDON;
+ rc = rs->sr_err = SLAPD_ABANDON;
goto cleanup;
}
/* check that the entry still obeys the schema */
- rc = entry_schema_check( be_monitor, e, save_attrs,
- &text, textbuf, sizeof( textbuf ) );
+ rc = entry_schema_check( op, e, save_attrs, 0,
+ &text, textbuf, sizeof( textbuf ) );
if ( rc != LDAP_SUCCESS ) {
+ rs->sr_err = rc;
goto cleanup;
}
@@ -255,7 +259,11 @@ cleanup:;
ldap_pvt_thread_mutex_unlock( &monitor_log_mutex );
- return( rc );
+ if ( rc == LDAP_SUCCESS ) {
+ rc = SLAP_CB_CONTINUE;
+ }
+
+ return rc;
}
static int
@@ -295,10 +303,10 @@ check_constraints( Modification *mod, int *newlevel )
{
int i;
- for ( i = 0; mod->sm_bvalues && mod->sm_bvalues[i].bv_val != NULL; i++ ) {
+ for ( i = 0; mod->sm_values && !BER_BVISNULL( &mod->sm_values[ i ] ); i++ ) {
int l;
- l = loglevel2int( &mod->sm_bvalues[i] );
+ l = loglevel2int( &mod->sm_values[ i ] );
if ( !l ) {
return LDAP_CONSTRAINT_VIOLATION;
}
@@ -308,13 +316,13 @@ check_constraints( Modification *mod, int *newlevel )
}
assert( int_2_level[ l ].s.bv_len
- == mod->sm_bvalues[i].bv_len );
+ == mod->sm_values[ i ].bv_len );
- AC_MEMCPY( mod->sm_bvalues[i].bv_val,
+ AC_MEMCPY( mod->sm_values[ 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,
+ AC_MEMCPY( mod->sm_nvalues[ i ].bv_val,
int_2_level[ l ].n.bv_val,
int_2_level[ l ].n.bv_len );
@@ -339,12 +347,12 @@ add_values( Entry *e, Modification *mod, int *newlevel )
a = attr_find( e->e_attrs, mod->sm_desc );
if ( a != NULL ) {
- /* "description" SHOULD have appropriate rules ... */
+ /* "managedInfo" SHOULD have appropriate rules ... */
if ( mr == NULL || !mr->smr_match ) {
return LDAP_INAPPROPRIATE_MATCHING;
}
- for ( i = 0; mod->sm_bvalues[i].bv_val != NULL; i++ ) {
+ for ( i = 0; !BER_BVISNULL( &mod->sm_values[ i ] ); i++ ) {
int rc;
int j;
const char *text = NULL;
@@ -352,17 +360,16 @@ add_values( Entry *e, Modification *mod, int *newlevel )
rc = asserted_value_validate_normalize(
mod->sm_desc, mr, SLAP_MR_EQUALITY,
- &mod->sm_bvalues[i], &asserted, &text, NULL );
+ &mod->sm_values[ i ], &asserted, &text, NULL );
if ( rc != LDAP_SUCCESS ) {
return rc;
}
- for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) {
+ for ( j = 0; !BER_BVISNULL( &a->a_vals[ j ] ); j++ ) {
int match;
int rc = value_match( &match, mod->sm_desc, mr,
- 0,
- &a->a_vals[j], &asserted, &text );
+ 0, &a->a_vals[ j ], &asserted, &text );
if ( rc == LDAP_SUCCESS && match == 0 ) {
free( asserted.bv_val );
@@ -375,7 +382,7 @@ add_values( Entry *e, Modification *mod, int *newlevel )
}
/* no - add them */
- rc = attr_merge( e, mod->sm_desc, mod->sm_bvalues, mod->sm_nvalues );
+ rc = attr_merge( e, mod->sm_desc, mod->sm_values, mod->sm_nvalues );
if ( rc != LDAP_SUCCESS ) {
/* this should return result of attr_mergeit */
return rc;
@@ -399,7 +406,7 @@ delete_values( Entry *e, Modification *mod, int *newlevel )
*newlevel &= ~nl;
/* delete the entire attribute */
- if ( mod->sm_bvalues == NULL ) {
+ if ( mod->sm_values == NULL ) {
int rc = attr_delete( &e->e_attrs, mod->sm_desc );
if ( rc ) {
@@ -423,7 +430,7 @@ delete_values( Entry *e, Modification *mod, int *newlevel )
}
/* find each value to delete */
- for ( i = 0; mod->sm_bvalues[i].bv_val != NULL; i++ ) {
+ for ( i = 0; !BER_BVISNULL( &mod->sm_values[ i ] ); i++ ) {
int rc;
const char *text = NULL;
@@ -431,16 +438,16 @@ delete_values( Entry *e, Modification *mod, int *newlevel )
rc = asserted_value_validate_normalize(
mod->sm_desc, mr, SLAP_MR_EQUALITY,
- &mod->sm_bvalues[i], &asserted, &text, NULL );
+ &mod->sm_values[ i ], &asserted, &text, NULL );
if( rc != LDAP_SUCCESS ) return rc;
found = 0;
- for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) {
+ for ( j = 0; !BER_BVISNULL( &a->a_vals[ j ] ); j++ ) {
int match;
int rc = value_match( &match, mod->sm_desc, mr,
0,
- &a->a_vals[j], &asserted, &text );
+ &a->a_vals[ j ], &asserted, &text );
if( rc == LDAP_SUCCESS && match != 0 ) {
continue;
@@ -450,11 +457,11 @@ delete_values( Entry *e, Modification *mod, int *newlevel )
found = 1;
/* delete it */
- free( a->a_vals[j].bv_val );
- for ( k = j + 1; a->a_vals[k].bv_val != NULL; k++ ) {
- a->a_vals[k - 1] = a->a_vals[k];
+ 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 ];
}
- a->a_vals[k - 1].bv_val = NULL;
+ BER_BVZERO( &a->a_vals[ k - 1 ] );
break;
}
@@ -468,7 +475,7 @@ delete_values( Entry *e, Modification *mod, int *newlevel )
}
/* if no values remain, delete the entire attribute */
- if ( a->a_vals[0].bv_val == NULL ) {
+ if ( BER_BVISNULL( &a->a_vals[ 0 ] ) ) {
/* should already be zero */
*newlevel = 0;
@@ -497,9 +504,8 @@ replace_values( Entry *e, Modification *mod, int *newlevel )
return rc;
}
- if ( mod->sm_bvalues != NULL ) {
- rc = attr_merge( e, mod->sm_desc, mod->sm_bvalues,
- mod->sm_nvalues );
+ if ( mod->sm_values != NULL ) {
+ rc = attr_merge( e, mod->sm_desc, mod->sm_values, mod->sm_nvalues );
if ( rc != LDAP_SUCCESS ) {
return rc;
}