]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-monitor/log.c
more (in)sanity stuff
[openldap] / servers / slapd / back-monitor / log.c
index 23cf7faf162d404c0d0fa66b073c4ebb8b131315..6a390891d463c49949a3e2c02537464bc85c34cf 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2001-2004 The OpenLDAP Foundation.
+ * Copyright 2001-2005 The OpenLDAP Foundation.
  * Portions Copyright 2001-2003 Pierangelo Masarati.
  * All rights reserved.
  *
 #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
  */
@@ -70,22 +81,19 @@ static int replace_values( Entry *e, Modification *mod, int *newlevel );
  */
 int
 monitor_subsys_log_init(
-       BackendDB       *be,
-       monitorsubsys   *ms
-)
+       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."),
-               BER_BVNULL
-       };
+       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, &ms->mss_ndn, 
                                &e ) ) {
@@ -119,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;
@@ -148,22 +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_values, 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;
                }
 
@@ -186,6 +209,7 @@ monitor_subsys_log_modify(
                }
 
                if ( rc != LDAP_SUCCESS ) {
+                       rs->sr_err = rc;
                        break;
                }
        }
@@ -197,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;
                }
 
@@ -234,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
@@ -318,7 +347,7 @@ 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;
                }