]> git.sur5r.net Git - openldap/commitdiff
new logging
authorKurt Zeilenga <kurt@openldap.org>
Sun, 28 Jul 2002 21:12:57 +0000 (21:12 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Sun, 28 Jul 2002 21:12:57 +0000 (21:12 +0000)
13 files changed:
servers/slapd/back-monitor/backend.c
servers/slapd/back-monitor/bind.c [new file with mode: 0644]
servers/slapd/back-monitor/conn.c
servers/slapd/back-monitor/database.c
servers/slapd/back-monitor/init.c
servers/slapd/back-monitor/listener.c [new file with mode: 0644]
servers/slapd/back-monitor/log.c
servers/slapd/back-monitor/modify.c [new file with mode: 0644]
servers/slapd/back-monitor/operation.c
servers/slapd/back-monitor/search.c [new file with mode: 0644]
servers/slapd/back-monitor/sent.c [new file with mode: 0644]
servers/slapd/back-monitor/thread.c [new file with mode: 0644]
servers/slapd/tools/slapadd.c

index bd65f90639b2b2df3f995200e1137b6583fe763c..d147929abe6027f6682651a4d5ecf0da48f743a0 100644 (file)
@@ -58,10 +58,10 @@ monitor_subsys_backend_init(
                                &monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn, 
                                &e_backend ) ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+               LDAP_LOG( OPERATION, CRIT,
                        "monitor_subsys_backend_init: "
                        "unable to get entry '%s'\n",
-                       monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val ));
+                       monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                        "monitor_subsys_backend_init: "
@@ -91,11 +91,10 @@ monitor_subsys_backend_init(
                e = str2entry( buf );
                if ( e == NULL ) {
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+                       LDAP_LOG( OPERATION, CRIT,
                                "monitor_subsys_backend_init: "
                                "unable to create entry 'cn=Backend %d,%s'\n",
-                               i, 
-                               monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val ));
+                               i, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0 );
 #else
                        Debug( LDAP_DEBUG_ANY,
                                "monitor_subsys_backend_init: "
@@ -124,11 +123,10 @@ monitor_subsys_backend_init(
 
                if ( monitor_cache_add( mi, e ) ) {
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+                       LDAP_LOG( OPERATION, CRIT,
                                "monitor_subsys_backend_init: "
                                "unable to add entry 'cn=Backend %d,%s'\n",
-                               i,
-                               monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val ));
+                               i, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0 );
 #else
                        Debug( LDAP_DEBUG_ANY,
                                "monitor_subsys_backend_init: "
diff --git a/servers/slapd/back-monitor/bind.c b/servers/slapd/back-monitor/bind.c
new file mode 100644 (file)
index 0000000..9c0cd46
--- /dev/null
@@ -0,0 +1,81 @@
+/* bind.c - monitor backend bind routine */
+/*
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
+ * 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 <slap.h>
+#include "back-monitor.h"
+
+/*
+ * At present, only rootdn can bind with simple bind
+ */
+
+int
+monitor_back_bind(
+       Backend         *be,
+       Connection      *conn,
+       Operation       *op,
+       struct berval   *dn,
+       struct berval   *ndn,
+       int             method,
+       struct berval   *cred,
+       struct berval   *edn
+                                   
+)
+{
+#if 0  /* not used yet */
+       struct monitorinfo      *mi = (struct monitorinfo *) be->be_private;
+#endif
+
+#ifdef NEW_LOGGING
+       LDAP_LOG( BACK_MON, ENTRY,
+               "monitor_back_bind: dn: %s.\n", dn->bv_val, 0, 0 );
+#else
+       Debug(LDAP_DEBUG_ARGS, "==> monitor_back_bind: dn: %s\n%s%s", 
+                       dn->bv_val, "", "");
+#endif
+       
+       if ( method == LDAP_AUTH_SIMPLE 
+                       && be_isroot_pw( be, conn, ndn, cred ) ) {
+               ber_dupbv( edn, be_root_dn( be ) );
+               return( 0 );
+       }
+
+       send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
+                               NULL, NULL, NULL, NULL );
+
+       return( 1 );
+}
+
index 43ba3dc4e4fe951f19601e3bac973da08adc280a..ad7ab23240e57b82b44f23f385c842e8705caad2 100644 (file)
@@ -59,10 +59,10 @@ monitor_subsys_conn_init(
        if ( monitor_cache_get( mi,
                        &monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn, &e_conn ) ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+               LDAP_LOG( OPERATION, CRIT,
                        "monitor_subsys_conn_init: "
                        "unable to get entry '%s'\n",
-                       monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val ));
+                       monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                        "monitor_subsys_conn_init: "
@@ -87,10 +87,10 @@ monitor_subsys_conn_init(
        e = str2entry( buf );
        if ( e == NULL ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+               LDAP_LOG( OPERATION, CRIT,
                        "monitor_subsys_conn_init: "
                        "unable to create entry 'cn=Total,%s'\n",
-                       monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val ));
+                       monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                        "monitor_subsys_conn_init: "
@@ -117,10 +117,10 @@ monitor_subsys_conn_init(
 
        if ( monitor_cache_add( mi, e ) ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+               LDAP_LOG( OPERATION, CRIT,
                        "monitor_subsys_conn_init: "
                        "unable to add entry 'cn=Total,%s'\n",
-                       monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val ));
+                       monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                        "monitor_subsys_conn_init: "
@@ -145,10 +145,10 @@ monitor_subsys_conn_init(
        e = str2entry( buf );
        if ( e == NULL ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+               LDAP_LOG( OPERATION, CRIT,
                        "monitor_subsys_conn_init: "
                        "unable to create entry 'cn=Current,%s'\n",
-                       monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val ));
+                       monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                        "monitor_subsys_conn_init: "
@@ -175,10 +175,10 @@ monitor_subsys_conn_init(
 
        if ( monitor_cache_add( mi, e ) ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+               LDAP_LOG( OPERATION, CRIT,
                        "monitor_subsys_conn_init: "
                        "unable to add entry 'cn=Current,%s'\n",
-                       monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val ));
+                       monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                        "monitor_subsys_conn_init: "
@@ -210,12 +210,12 @@ monitor_subsys_conn_update(
        assert( mi );
        assert( e );
        
-       if ( strncasecmp( e->e_ndn, "CN=TOTAL", 
-                               sizeof("CN=TOTAL")-1 ) == 0 ) {
+       if ( strncasecmp( e->e_ndn, "cn=total", 
+                               sizeof("cn=total")-1 ) == 0 ) {
                n = connections_nextid();
 
-       } else if ( strncasecmp( e->e_ndn, "CN=CURRENT", 
-                               sizeof("CN=CURRENT")-1 ) == 0 ) {
+       } else if ( strncasecmp( e->e_ndn, "cn=current", 
+                               sizeof("cn=current")-1 ) == 0 ) {
                Connection      *c;
                int             connindex;
 
@@ -273,12 +273,11 @@ conn_create(
 
        if ( e == NULL) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+               LDAP_LOG( OPERATION, CRIT,
                        "monitor_subsys_conn_create: "
                        "unable to create entry "
                        "'cn=" CONN_CN_PREFIX " %ld,%s' entry\n",
-                       c->c_connid, 
-                       monitor_subsys[SLAPD_MONITOR_CONN].mss_dn.bv_val ));
+                       c->c_connid, monitor_subsys[SLAPD_MONITOR_CONN].mss_dn.bv_val, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                        "monitor_subsys_conn_create: "
@@ -293,10 +292,10 @@ conn_create(
        ldap_pvt_thread_mutex_lock( &gmtime_mutex );
        
        ltm = gmtime( &c->c_starttime );
-       strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
+       lutil_gentime( buf2, sizeof(buf2), ltm );
                        
        ltm = gmtime( &c->c_activitytime );
-       strftime( buf3, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
+       lutil_gentime( buf3, sizeof(buf2), ltm );
                        
        ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
 
index 66b0b0bce4520035df9c579c5888c08ca19aa27e..2ed5225faaee3241d69aa143d380b7c9c5b03b56 100644 (file)
@@ -61,10 +61,10 @@ monitor_subsys_database_init(
                                &monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn, 
                                &e_database ) ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+               LDAP_LOG( OPERATION, CRIT,
                        "monitor_subsys_database_init: "
                        "unable to get entry '%s'\n",
-                       monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val ));
+                       monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                        "monitor_subsys_database_init: "
@@ -99,11 +99,10 @@ monitor_subsys_database_init(
                e = str2entry( buf );
                if ( e == NULL ) {
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+                       LDAP_LOG( OPERATION, CRIT,
                                "monitor_subsys_database_init: "
                                "unable to create entry 'cn=Database %d,%s'\n",
-                               i, 
-                               monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val ));
+                               i, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0 );
 #else
                        Debug( LDAP_DEBUG_ANY,
                                "monitor_subsys_database_init: "
@@ -155,11 +154,10 @@ monitor_subsys_database_init(
 
                if ( monitor_cache_add( mi, e ) ) {
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+                       LDAP_LOG( OPERATION, CRIT,
                                "monitor_subsys_database_init: "
                                "unable to add entry 'cn=Database %d,%s'\n",
-                               i, 
-                               monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val ));
+                               i, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0 );
 #else
                        Debug( LDAP_DEBUG_ANY,
                                "monitor_subsys_database_init: "
index b8637dd0d800d6c88ad4c30f6bd7cad7b5b23a26..240f64e1119801307a6734fcd20d571e14c6f990 100644 (file)
@@ -236,8 +236,8 @@ monitor_back_db_init(
         */
        if ( be_monitor ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
-                       "only one monitor backend is allowed\n" ));
+               LDAP_LOG( OPERATION, CRIT,
+                       "only one monitor backend is allowed\n" , 0, 0, 0);
 #else
                Debug( LDAP_DEBUG_ANY,
                        "only one monitor backend is allowed\n%s%s%s",
@@ -256,8 +256,8 @@ monitor_back_db_init(
        rc = dnNormalize2( NULL, &dn, &ndn );
        if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
-                       "monitor DN \"" SLAPD_MONITOR_DN "\" backend is allowed\n" ));
+               LDAP_LOG( OPERATION, CRIT,
+                       "monitor DN \"" SLAPD_MONITOR_DN "\" backend is allowed\n" , 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                        "monitor DN \"" SLAPD_MONITOR_DN "\" backend is allowed\n",
@@ -275,8 +275,8 @@ monitor_back_db_init(
 
        if ( slap_str2ad( "description", &monitor_ad_desc, &text ) ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
-                       "monitor_back_db_init: %s\n", text ));
+               LDAP_LOG( OPERATION, CRIT,
+                       "monitor_back_db_init: %s\n", text, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                        "monitor_subsys_backend_init: %s\n%s%s", 
@@ -302,9 +302,9 @@ monitor_back_db_init(
                free( dn.bv_val );
                if ( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+                       LDAP_LOG( OPERATION, CRIT,
                                "monitor RDN \"%s\" is invalid\n", 
-                               dn.bv_val ));
+                               dn.bv_val, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_ANY,
                                "monitor RDN \"%s\" is invalid\n", 
@@ -322,9 +322,9 @@ monitor_back_db_init(
                free( dn.bv_val );
                if ( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+                       LDAP_LOG( OPERATION, CRIT,
                                "monitor DN \"%s\" is invalid\n", 
-                               dn.bv_val ));
+                               dn.bv_val, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_ANY,
                                "monitor DN \"%s\" is invalid\n", 
@@ -344,9 +344,9 @@ monitor_back_db_init(
                
                if ( e == NULL) {
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+                       LDAP_LOG( OPERATION, CRIT,
                                "unable to create '%s' entry\n", 
-                               monitor_subsys[ i ].mss_dn.bv_val ));
+                               monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_ANY,
                                "unable to create '%s' entry\n", 
@@ -364,9 +364,9 @@ monitor_back_db_init(
 
                if ( monitor_cache_add( mi, e ) ) {
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+                       LDAP_LOG( OPERATION, CRIT,
                                "unable to add entry '%s' to cache\n",
-                               monitor_subsys[ i ].mss_dn.bv_val ));
+                               monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_ANY,
                                "unable to add entry '%s' to cache\n",
@@ -392,9 +392,9 @@ monitor_back_db_init(
        e = str2entry( buf );
        if ( e == NULL) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+               LDAP_LOG( OPERATION, CRIT,
                        "unable to create '%s' entry\n",
-                       SLAPD_MONITOR_DN ));
+                       SLAPD_MONITOR_DN, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                        "unable to create '%s' entry\n%s%s",
@@ -412,9 +412,9 @@ monitor_back_db_init(
        }
        if ( attr_merge( e, monitor_ad_desc, bv ) ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+               LDAP_LOG( OPERATION, CRIT,
                        "unable to add description to '%s' entry\n",
-                       SLAPD_MONITOR_DN ));
+                       SLAPD_MONITOR_DN, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                        "unable to add description to '%s' entry\n%s%s",
@@ -432,9 +432,9 @@ monitor_back_db_init(
 
        if ( monitor_cache_add( mi, e ) ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+               LDAP_LOG( OPERATION, CRIT,
                        "unable to add entry '%s' to cache\n",
-                       SLAPD_MONITOR_DN ));
+                       SLAPD_MONITOR_DN, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                        "unable to add entry '%s' to cache\n%s%s",
@@ -465,8 +465,8 @@ monitor_back_open(
        rc = dnNormalize2( NULL, &dn, &ndn );
        if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
-                       "monitor DN \"" SLAPD_MONITOR_DN "\" is invalid\n" ));
+               LDAP_LOG( OPERATION, CRIT,
+                       "monitor DN \"" SLAPD_MONITOR_DN "\" is invalid\n" , 0, 0, 0);
 #else
                Debug( LDAP_DEBUG_ANY,
                        "monitor DN \"" SLAPD_MONITOR_DN "\" is invalid\n",
@@ -480,8 +480,8 @@ monitor_back_open(
 
        if ( be == NULL ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
-                       "unable to get monitor backend\n" ));
+               LDAP_LOG( OPERATION, CRIT,
+                       "unable to get monitor backend\n" , 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                        "unable to get monitor backend\n", 0, 0, 0 );
@@ -523,8 +523,8 @@ monitor_back_db_config(
 )
 {
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "config", LDAP_LEVEL_INFO,
-               "line %d of file '%s' will be ignored\n", lineno, fname ));
+       LDAP_LOG( CONFIG, INFO,
+               "line %d of file '%s' will be ignored\n", lineno, fname, 0 );
 #else
        Debug( LDAP_DEBUG_CONFIG, 
                "line %d of file '%s' will be ignored\n%s", lineno, fname, "" );
diff --git a/servers/slapd/back-monitor/listener.c b/servers/slapd/back-monitor/listener.c
new file mode 100644 (file)
index 0000000..2f8b3b8
--- /dev/null
@@ -0,0 +1,178 @@
+/* listener.c - deals with listener subsystem */
+/*
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
+ * 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 "slap.h"
+#include "back-monitor.h"
+
+int
+monitor_subsys_listener_init(
+       BackendDB       *be
+)
+{
+       struct monitorinfo      *mi;
+       Entry                   *e, *e_listener, *e_tmp;
+       int                     i;
+       struct monitorentrypriv *mp;
+       Listener                **l;
+
+       assert( be != NULL );
+       assert( monitor_ad_desc != NULL );
+
+       mi = ( struct monitorinfo * )be->be_private;
+
+       if ( monitor_cache_get( mi, 
+                               &monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn, 
+                               &e_listener ) ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG( OPERATION, CRIT,
+                       "monitor_subsys_listener_init: "
+                       "unable to get entry '%s'\n",
+                       monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_subsys_listener_init: "
+                       "unable to get entry '%s'\n%s%s",
+                       monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 
+                       "", "" );
+#endif
+               return( -1 );
+       }
+
+       if ( ( l = slapd_get_listeners() ) == NULL ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG( OPERATION, CRIT,
+                       "monitor_subsys_listener_init: "
+                       "unable to get listeners\n", 0, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_subsys_listener_init: "
+                       "unable to get listeners\n", 0, 0, 0 );
+#endif
+               return( -1 );
+       }
+
+       e_tmp = NULL;
+       for ( i = 0; l[i]; i++ );
+       for ( ; i--; ) {
+               char            buf[1024];
+
+               snprintf( buf, sizeof( buf ),
+                               "dn: cn=Listener %d,%s\n"
+                               SLAPD_MONITOR_OBJECTCLASSES
+                               "cn: Listener %d\n"
+                               "description: %s\n"
+                               "labeledURI: %s",
+                               i,
+                               monitor_subsys[SLAPD_MONITOR_LISTENER].mss_dn.bv_val,
+                               i,
+                               l[i]->sl_name,
+
+                               l[i]->sl_url );
+               
+               e = str2entry( buf );
+               if ( e == NULL ) {
+#ifdef NEW_LOGGING
+                       LDAP_LOG( OPERATION, CRIT,
+                               "monitor_subsys_listener_init: "
+                               "unable to create entry 'cn=Listener, %d,%s'\n",
+                               i, monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 0 );
+#else
+                       Debug( LDAP_DEBUG_ANY,
+                               "monitor_subsys_listener_init: "
+                               "unable to create entry 'cn=Listener %d,%s'\n%s",
+                               i,
+                               monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val,
+                               "" );
+#endif
+                       return( -1 );
+               }
+
+#ifdef HAVE_TLS
+               if ( l[i]->sl_is_tls ) {
+                       struct berval bv[2];
+                       bv[1].bv_val = NULL;
+                       bv[0].bv_val = "TLS";
+                       bv[0].bv_len = sizeof("TLS")-1;
+                       attr_merge( e, monitor_ad_desc, bv );
+               }
+#endif /* HAVE_TLS */
+#ifdef LDAP_CONNECTIONLESS
+               if ( l[i]->sl_is_udp ) {
+                       struct berval bv[2];
+                       bv[1].bv_val = NULL;
+                       bv[0].bv_val = "UDP";
+                       bv[0].bv_len = sizeof("UDP")-1;
+                       attr_merge( e, monitor_ad_desc, bv );
+               }
+#endif /* HAVE_TLS */
+
+               mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
+               e->e_private = ( void * )mp;
+               mp->mp_next = e_tmp;
+               mp->mp_children = NULL;
+               mp->mp_info = &monitor_subsys[SLAPD_MONITOR_LISTENER];
+               mp->mp_flags = monitor_subsys[SLAPD_MONITOR_LISTENER].mss_flags
+                       | MONITOR_F_SUB;
+
+               if ( monitor_cache_add( mi, e ) ) {
+#ifdef NEW_LOGGING
+                       LDAP_LOG( OPERATION, CRIT,
+                               "monitor_subsys_listener_init: "
+                               "unable to add entry 'cn=Listener %d,%s'\n",
+                               i, monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 0 );
+#else
+                       Debug( LDAP_DEBUG_ANY,
+                               "monitor_subsys_listener_init: "
+                               "unable to add entry 'cn=Listener %d,%s'\n",
+                               i,
+                               monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val,
+                               0 );
+#endif
+                       return( -1 );
+               }
+
+               e_tmp = e;
+       }
+       
+       mp = ( struct monitorentrypriv * )e_listener->e_private;
+       mp->mp_children = e_tmp;
+
+       monitor_cache_release( mi, e_listener );
+
+       return( 0 );
+}
+
index aef5d34caaefb8190be07aeedd64e6bfac728acc..1c12104b2f80c0dcffafbbe61af6f0543128f46c 100644 (file)
@@ -95,10 +95,10 @@ monitor_subsys_log_init(
        if ( monitor_cache_get( mi, &monitor_subsys[SLAPD_MONITOR_LOG].mss_ndn, 
                                &e ) ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+               LDAP_LOG( OPERATION, CRIT,
                        "monitor_subsys_log_init: "
                        "unable to get entry '%s'\n",
-                       monitor_subsys[SLAPD_MONITOR_LOG].mss_ndn.bv_val ));
+                       monitor_subsys[SLAPD_MONITOR_LOG].mss_ndn.bv_val, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                        "monitor_subsys_log_init: "
diff --git a/servers/slapd/back-monitor/modify.c b/servers/slapd/back-monitor/modify.c
new file mode 100644 (file)
index 0000000..5cf4e29
--- /dev/null
@@ -0,0 +1,91 @@
+/* modify.c - monitor backend modify routine */
+/*
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
+ * 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 <ac/socket.h>
+
+#include "slap.h"
+#include "back-monitor.h"
+#include "proto-back-monitor.h"
+
+int
+monitor_back_modify(
+    Backend    *be,
+    Connection *conn,
+    Operation  *op,
+    struct berval      *dn,
+    struct berval      *ndn,
+    Modifications      *modlist
+)
+{
+       int             rc = 0;
+       struct monitorinfo      *mi = (struct monitorinfo *) be->be_private;
+       Entry           *matched;
+       Entry           *e;
+
+#ifdef NEW_LOGGING
+       LDAP_LOG( BACK_MON, ENTRY,
+               "monitor_back_modify: enter\n", 0, 0, 0 );
+#else
+       Debug(LDAP_DEBUG_ARGS, "monitor_back_modify:\n", 0, 0, 0);
+#endif
+
+       /* acquire and lock entry */
+       monitor_cache_dn2entry( mi, ndn, &e, &matched );
+       if ( e == NULL ) {
+               send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT,
+                               matched ? matched->e_dn : NULL,
+                               NULL, NULL, NULL );
+               if ( matched != NULL ) {
+                       monitor_cache_release( mi, matched );
+                       return( 0 );
+               }
+       }
+
+       if ( !acl_check_modlist( be, conn, op, e, modlist )) {
+               rc = LDAP_INSUFFICIENT_ACCESS;
+       } else {
+               rc = monitor_entry_modify( mi, e, modlist );
+       }
+
+       send_ldap_result( conn, op, rc, NULL, NULL, NULL, NULL );
+
+       monitor_cache_release( mi, e );
+
+       return( 0 );
+}
+
index b8a0ff4fb417004912dc69c27d1a94120de3c38f..7686bde2bbfa31162b688022e4307f6e9185930f 100644 (file)
@@ -75,10 +75,10 @@ monitor_subsys_ops_init(
        if ( monitor_cache_get( mi,
                        &monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn, &e_op ) ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+               LDAP_LOG( OPERATION, CRIT,
                        "monitor_subsys_ops_init: "
                        "unable to get entry '%s'\n",
-                       monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val ));
+                       monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                        "monitor_subsys_ops_init: "
@@ -105,11 +105,11 @@ monitor_subsys_ops_init(
        e = str2entry( buf );
        if ( e == NULL ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+               LDAP_LOG( OPERATION, CRIT,
                        "monitor_subsys_ops_init: "
                        "unable to create entry 'cn=%s,%s'\n",
                        bv_initiated.bv_val,
-                       monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val ));
+                       monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                        "monitor_subsys_ops_init: "
@@ -136,11 +136,11 @@ monitor_subsys_ops_init(
 
        if ( monitor_cache_add( mi, e ) ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+               LDAP_LOG( OPERATION, CRIT,
                        "monitor_subsys_ops_init: "
                        "unable to add entry 'cn=%s,%s'\n",
                        bv_initiated.bv_val,
-                       monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val ));
+                       monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                        "monitor_subsys_ops_init: "
@@ -172,12 +172,12 @@ monitor_subsys_ops_init(
                e = str2entry( buf );
                if ( e == NULL ) {
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+                       LDAP_LOG( OPERATION, CRIT,
                                "monitor_subsys_ops_init: "
                                "unable to create entry 'cn=%s,cn=%s,%s'\n",
                                bv_op[ i ].bv_val,
                                bv_initiated.bv_val,
-                               monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val ));
+                               monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val );
 #else
                        Debug( LDAP_DEBUG_ANY,
                                "monitor_subsys_ops_init: "
@@ -204,12 +204,12 @@ monitor_subsys_ops_init(
 
                if ( monitor_cache_add( mi, e ) ) {
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+                       LDAP_LOG( OPERATION, CRIT,
                                "monitor_subsys_ops_init: "
                                "unable to add entry 'cn=%s,cn=%s,%s'\n",
                                bv_op[ i ].bv_val,
                                bv_initiated.bv_val,
-                               monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val ));
+                               monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val );
 #else
                        Debug( LDAP_DEBUG_ANY,
                                "monitor_subsys_ops_init: "
@@ -241,11 +241,11 @@ monitor_subsys_ops_init(
        e = str2entry( buf );
        if ( e == NULL ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+               LDAP_LOG( OPERATION, CRIT,
                        "monitor_subsys_ops_init: "
                        "unable to create entry 'cn=%s,%s'\n",
                        bv_completed.bv_val,
-                       monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val ));
+                       monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                        "monitor_subsys_ops_init: "
@@ -271,11 +271,11 @@ monitor_subsys_ops_init(
 
        if ( monitor_cache_add( mi, e ) ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+               LDAP_LOG( OPERATION, CRIT,
                        "monitor_subsys_ops_init: "
                        "unable to add entry 'cn=%s,%s'\n",
                        bv_completed.bv_val,
-                       monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val ));
+                       monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                        "monitor_subsys_ops_init: "
@@ -307,12 +307,12 @@ monitor_subsys_ops_init(
                e = str2entry( buf );
                if ( e == NULL ) {
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+                       LDAP_LOG( OPERATION, CRIT,
                                "monitor_subsys_ops_init: "
                                "unable to create entry 'cn=%s,cn=%s,%s'\n",
                                bv_op[ i ].bv_val,
                                bv_completed.bv_val,
-                               monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val ));
+                               monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val );
 #else
                        Debug( LDAP_DEBUG_ANY,
                                "monitor_subsys_ops_init: "
@@ -338,12 +338,12 @@ monitor_subsys_ops_init(
 
                if ( monitor_cache_add( mi, e ) ) {
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+                       LDAP_LOG( OPERATION, CRIT,
                                "monitor_subsys_ops_init: "
                                "unable to add entry 'cn=%s,cn=%s,%s'\n",
                                bv_op[ i ].bv_val,
                                bv_completed.bv_val,
-                               monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val ));
+                               monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val );
 #else
                        Debug( LDAP_DEBUG_ANY,
                                "monitor_subsys_ops_init: "
diff --git a/servers/slapd/back-monitor/search.c b/servers/slapd/back-monitor/search.c
new file mode 100644 (file)
index 0000000..16d49e8
--- /dev/null
@@ -0,0 +1,226 @@
+/* search.c - monitor backend search function */
+/*
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
+ * 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 <ac/socket.h>
+
+#include "slap.h"
+#include "back-monitor.h"
+#include "proto-back-monitor.h"
+
+static int
+monitor_send_children(
+       Backend         *be,
+       Connection      *conn,
+       Operation       *op,
+       Filter          *filter,
+       AttributeName   *attrs,
+       int             attrsonly,
+       Entry           *e_parent,
+       int             sub,
+       int             *nentriesp
+)
+{
+       struct monitorinfo      *mi = (struct monitorinfo *) be->be_private;
+       Entry                   *e, *e_tmp, *e_ch;
+       struct monitorentrypriv *mp;
+       int                     nentries;
+       int                     rc;
+
+       mp = ( struct monitorentrypriv * )e_parent->e_private;
+       e = mp->mp_children;
+
+       e_ch = NULL;
+       if ( MONITOR_HAS_VOLATILE_CH( mp ) ) {
+               monitor_entry_create( mi, NULL, e_parent, &e_ch );
+       }
+       monitor_cache_release( mi, e_parent );
+
+       /* no volatile entries? */
+       if ( e_ch == NULL ) {
+               /* no persistent entries? return */
+               if ( e == NULL ) {
+                       return( 0 );
+               }
+       
+       /* volatile entries */
+       } else {
+               /* if no persistent, return only volatile */
+               if ( e == NULL ) {
+                       e = e_ch;
+                       monitor_cache_lock( e_ch );
+
+               /* else append persistent to volatile */
+               } else {
+                       e_tmp = e_ch;
+                       do {
+                               mp = ( struct monitorentrypriv * )e_tmp->e_private;
+                               e_tmp = mp->mp_next;
+       
+                               if ( e_tmp == NULL ) {
+                                       mp->mp_next = e;
+                                       break;
+                               }
+                       } while ( e_tmp );
+                       e = e_ch;
+               }
+       }
+
+       /* return entries */
+       for ( nentries = *nentriesp; e != NULL; ) {
+               mp = ( struct monitorentrypriv * )e->e_private;
+
+               monitor_entry_update( mi, e );
+               
+               rc = test_filter( be, conn, op, e, filter );
+               if ( rc == LDAP_COMPARE_TRUE ) {
+                       send_search_entry( be, conn, op, e, 
+                                       attrs, attrsonly, NULL );
+                       nentries++;
+               }
+
+               if ( ( mp->mp_children || MONITOR_HAS_VOLATILE_CH( mp ) )
+                               && sub ) {
+                       rc = monitor_send_children( be, conn, op, filter, 
+                                       attrs, attrsonly, 
+                                       e, sub, &nentries );
+                       if ( rc ) {
+                               return( rc );
+                       }
+               }
+
+               e_tmp = mp->mp_next;
+               if ( e_tmp != NULL ) {
+                       monitor_cache_lock( e_tmp );
+               }
+               monitor_cache_release( mi, e );
+               e = e_tmp;
+       }
+       
+       return( 0 );
+}
+
+int
+monitor_back_search(
+       Backend         *be,
+       Connection      *conn,
+       Operation       *op,
+       struct berval   *base,
+       struct berval   *nbase,
+       int             scope,
+       int             deref,
+       int             slimit,
+       int             tlimit,
+       Filter          *filter,
+       struct berval   *filterstr,
+       AttributeName   *attrs,
+       int             attrsonly 
+)
+{
+       struct monitorinfo      *mi = (struct monitorinfo *) be->be_private;
+       int             rc;
+       Entry           *e, *matched = NULL;
+       int             nentries = 0;
+
+#ifdef NEW_LOGGING
+       LDAP_LOG( BACK_MON, ENTRY,
+                  "monitor_back_search: enter\n", 0, 0, 0 );
+#else
+       Debug(LDAP_DEBUG_TRACE, "=> monitor_back_search\n%s%s%s", "", "", "");
+#endif
+
+
+       /* get entry with reader lock */
+       monitor_cache_dn2entry( mi, nbase, &e, &matched );
+       if ( e == NULL ) {
+               send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT,
+                       matched ? matched->e_dn : NULL, 
+                       NULL, NULL, NULL );
+               if ( matched ) {
+                       monitor_cache_release( mi, matched );
+               }
+
+               return( 0 );
+       }
+
+       nentries = 0;
+       switch ( scope ) {
+       case LDAP_SCOPE_BASE:
+               monitor_entry_update( mi, e );
+               rc = test_filter( be, conn, op, e, filter );
+               if ( rc == LDAP_COMPARE_TRUE ) {                        
+                       send_search_entry( be, conn, op, e, attrs, 
+                                       attrsonly, NULL );
+                       nentries = 1;
+               }
+               monitor_cache_release( mi, e );
+               break;
+
+       case LDAP_SCOPE_ONELEVEL:
+               rc = monitor_send_children( be, conn, op, filter,
+                               attrs, attrsonly,
+                               e, 0, &nentries );
+               if ( rc ) {
+                       // error
+               }               
+               
+               break;
+
+       case LDAP_SCOPE_SUBTREE:
+               monitor_entry_update( mi, e );
+               rc = test_filter( be, conn, op, e, filter );
+               if ( rc == LDAP_COMPARE_TRUE ) {
+                       send_search_entry( be, conn, op, e, attrs,
+                                       attrsonly, NULL );
+                       nentries++;
+               }
+
+               rc = monitor_send_children( be, conn, op, filter,
+                               attrs, attrsonly,
+                               e, 1, &nentries );
+               if ( rc ) {
+                       // error
+               }
+
+               break;
+       }
+       
+       send_search_result( conn, op, LDAP_SUCCESS,
+                       NULL, NULL, NULL, NULL, nentries );
+
+       return( 0 );
+}
diff --git a/servers/slapd/back-monitor/sent.c b/servers/slapd/back-monitor/sent.c
new file mode 100644 (file)
index 0000000..62c55f9
--- /dev/null
@@ -0,0 +1,361 @@
+/* sent.c - deal with data sent subsystem */
+/*
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
+ * 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 "slap.h"
+#include "back-monitor.h"
+
+int
+monitor_subsys_sent_init(
+       BackendDB               *be
+)
+{
+       struct monitorinfo      *mi;
+       
+       Entry                   *e, *e_tmp, *e_sent;
+       struct monitorentrypriv *mp;
+       char                    buf[1024];
+       struct berval           bv[2];
+
+       assert( be != NULL );
+
+       mi = ( struct monitorinfo * )be->be_private;
+
+       if ( monitor_cache_get( mi,
+                       &monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn, &e_sent ) ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG( OPERATION, CRIT,
+                       "monitor_subsys_sent_init: "
+                       "unable to get entry '%s'\n",
+                       monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_subsys_sent_init: "
+                       "unable to get entry '%s'\n%s%s",
+                       monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 
+                       "", "" );
+#endif
+               return( -1 );
+       }
+
+       e_tmp = NULL;
+
+       /*
+        * Entries
+        */
+       snprintf( buf, sizeof( buf ),
+                       "dn: cn=Entries,%s\n"
+                       SLAPD_MONITOR_OBJECTCLASSES
+                       "cn: Entries\n",
+                       monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val );
+
+       e = str2entry( buf );
+       if ( e == NULL ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG( OPERATION, CRIT,
+                       "monitor_subsys_sent_init: "
+                       "unable to create entry 'cn=Entries,%s'\n",
+                       monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_subsys_sent_init: "
+                       "unable to create entry 'cn=Entries,%s'\n%s%s",
+                       monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
+                       "", "" );
+#endif
+               return( -1 );
+       }
+       
+       bv[1].bv_val = NULL;
+       bv[0].bv_val = "0";
+       bv[0].bv_len = 1;
+       attr_merge( e, monitor_ad_desc, bv );
+       
+       mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
+       e->e_private = ( void * )mp;
+       mp->mp_next = e_tmp;
+       mp->mp_children = NULL;
+       mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
+       mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
+               | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
+
+       if ( monitor_cache_add( mi, e ) ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG( OPERATION, CRIT,
+                       "monitor_subsys_sent_init: "
+                       "unable to add entry 'cn=Entries,%s'\n",
+                       monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_subsys_sent_init: "
+                       "unable to add entry 'cn=Entries,%s'\n%s%s",
+                       monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
+                       "", "" );
+#endif
+               return( -1 );
+       }
+       
+       e_tmp = e;
+
+       /*
+        * Referrals
+        */
+       snprintf( buf, sizeof( buf ),
+                       "dn: cn=Referrals,%s\n"
+                       SLAPD_MONITOR_OBJECTCLASSES
+                       "cn: Referrals\n",
+                       monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val );
+
+       e = str2entry( buf );
+       if ( e == NULL ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG( OPERATION, CRIT,
+                       "monitor_subsys_sent_init: "
+                       "unable to create entry 'cn=Referrals,%s'\n",
+                       monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_subsys_sent_init: "
+                       "unable to create entry 'cn=Referrals,%s'\n%s%s",
+                       monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
+                       "", "" );
+#endif
+               return( -1 );
+       }
+
+       bv[0].bv_val = "0";
+       bv[0].bv_len = 1;
+       attr_merge( e, monitor_ad_desc, bv );
+       
+       mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
+       e->e_private = ( void * )mp;
+       mp->mp_next = e_tmp;
+       mp->mp_children = NULL;
+       mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
+       mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
+               | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
+
+       if ( monitor_cache_add( mi, e ) ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG( OPERATION, CRIT,
+                       "monitor_subsys_sent_init: "
+                       "unable to add entry 'cn=Referrals,%s'\n",
+                       monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_subsys_sent_init: "
+                       "unable to add entry 'cn=Referrals,%s'\n%s%s",
+                       monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
+                       "", "" );
+#endif
+               return( -1 );
+       }
+       
+       e_tmp = e;
+
+       /*
+        * PDU
+        */
+       snprintf( buf, sizeof( buf ),
+                       "dn: cn=PDU,%s\n"
+                       SLAPD_MONITOR_OBJECTCLASSES
+                       "cn: PDU\n",
+                       monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val );
+
+       e = str2entry( buf );
+       if ( e == NULL ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG( OPERATION, CRIT,
+                       "monitor_subsys_sent_init: "
+                       "unable to create entry 'cn=PDU,%s'\n",
+                       monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_subsys_sent_init: "
+                       "unable to create entry 'cn=PDU,%s'\n%s%s",
+                       monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
+                       "", "" );
+#endif
+               return( -1 );
+       }
+
+       bv[0].bv_val = "0";
+       bv[0].bv_len = 1;
+       attr_merge( e, monitor_ad_desc, bv );
+       
+       mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
+       e->e_private = ( void * )mp;
+       mp->mp_next = e_tmp;
+       mp->mp_children = NULL;
+       mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
+       mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
+               | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
+
+       if ( monitor_cache_add( mi, e ) ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG( OPERATION, CRIT,
+                       "monitor_subsys_sent_init: "
+                       "unable to add entry 'cn=PDU,%s'\n",
+                       monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_subsys_sent_init: "
+                       "unable to add entry 'cn=PDU,%s'\n%s%s",
+                       monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
+                       "", "" );
+#endif
+               return( -1 );
+       }
+       
+       e_tmp = e;
+
+       /*
+        * Bytes
+        */
+       snprintf( buf, sizeof( buf ),
+                       "dn: cn=Bytes,%s\n"
+                       SLAPD_MONITOR_OBJECTCLASSES
+                       "cn: Bytes\n",
+                       monitor_subsys[SLAPD_MONITOR_SENT].mss_dn.bv_val );
+
+       e = str2entry( buf );
+       if ( e == NULL ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG( OPERATION, CRIT,
+                       "monitor_subsys_sent_init: "
+                       "unable to create entry 'cn=Bytes,%s'\n",
+                       monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_subsys_sent_init: "
+                       "unable to create entry 'cn=Bytes,%s'\n%s%s",
+                       monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
+                       "", "" );
+#endif
+               return( -1 );
+       }
+
+       bv[0].bv_val = "0";
+       bv[0].bv_len = 1;
+       attr_merge( e, monitor_ad_desc, bv );
+       
+       mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
+       e->e_private = ( void * )mp;
+       mp->mp_next = e_tmp;
+       mp->mp_children = NULL;
+       mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
+       mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
+               | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
+
+       if ( monitor_cache_add( mi, e ) ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG( OPERATION, CRIT,
+                       "monitor_subsys_sent_init: "
+                       "unable to add entry 'cn=Bytes,%s'\n",
+                       monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_subsys_sent_init: "
+                       "unable to add entry 'cn=Bytes,%s'\n%s%s",
+                       monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn.bv_val,
+                       "", "" );
+#endif
+               return( -1 );
+       }
+       
+       e_tmp = e;
+
+       mp = ( struct monitorentrypriv * )e_sent->e_private;
+       mp->mp_children = e_tmp;
+
+       monitor_cache_release( mi, e_sent );
+
+       return( 0 );
+}
+
+int
+monitor_subsys_sent_update(
+       struct monitorinfo      *mi,
+       Entry                   *e
+)
+{
+       long            n = -1;
+
+       assert( mi );
+       assert( e );
+       
+       if ( strncasecmp( e->e_ndn, "cn=entries", 
+                               sizeof("cn=entries")-1 ) == 0 ) {
+               ldap_pvt_thread_mutex_lock(&num_sent_mutex);
+               n = num_entries_sent;
+               ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
+
+       } else if ( strncasecmp( e->e_ndn, "cn=referrals", 
+                               sizeof("cn=referrals")-1 ) == 0 ) {
+               ldap_pvt_thread_mutex_lock(&num_sent_mutex);
+               n = num_refs_sent;
+               ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
+
+       } else if ( strncasecmp( e->e_ndn, "cn=pdu", 
+                               sizeof("cn=pdu")-1 ) == 0 ) {
+               ldap_pvt_thread_mutex_lock(&num_sent_mutex);
+               n = num_pdu_sent;
+               ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
+
+       } else if ( strncasecmp( e->e_ndn, "cn=bytes", 
+                               sizeof("cn=bytes")-1 ) == 0 ) {
+               ldap_pvt_thread_mutex_lock(&num_sent_mutex);
+               n = num_bytes_sent;
+               ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
+       }
+
+       if ( n != -1 ) {
+               Attribute       *a;
+               char            buf[16];
+
+               a = attr_find( e->e_attrs, monitor_ad_desc );
+               if ( a == NULL ) {
+                       return( -1 );
+               }
+
+               snprintf( buf, sizeof( buf ), "%ld", n );
+               free( a->a_vals[ 0 ].bv_val );
+               ber_str2bv( buf, 0, 1, a->a_vals );
+       }
+
+       return( 0 );
+}
+
diff --git a/servers/slapd/back-monitor/thread.c b/servers/slapd/back-monitor/thread.c
new file mode 100644 (file)
index 0000000..112ada7
--- /dev/null
@@ -0,0 +1,121 @@
+/* thread.c - deal with thread subsystem */
+/*
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
+ * 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 "slap.h"
+#include "back-monitor.h"
+
+/*
+*  * initializes log subentry
+*   */
+int
+monitor_subsys_thread_init(
+       BackendDB       *be
+)
+{
+       struct monitorinfo      *mi;
+       Entry                   *e;
+       struct berval           bv[2];
+       static char             buf[1024];
+
+       mi = ( struct monitorinfo * )be->be_private;
+
+       if ( monitor_cache_get( mi, 
+               &monitor_subsys[SLAPD_MONITOR_THREAD].mss_ndn, &e ) )
+       {
+#ifdef NEW_LOGGING
+               LDAP_LOG( OPERATION, CRIT,
+                       "monitor_subsys_thread_init: unable to get entry '%s'\n",
+                       monitor_subsys[SLAPD_MONITOR_THREAD].mss_ndn.bv_val, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_subsys_thread_init: unable to get entry '%s'\n",
+                       monitor_subsys[SLAPD_MONITOR_THREAD].mss_ndn.bv_val, 
+                       0, 0 );
+#endif
+               return( -1 );
+       }
+
+       /* initialize the thread number */
+       snprintf( buf, sizeof( buf ), "max=%d", connection_pool_max );
+
+       bv[1].bv_val = NULL;
+       bv[0].bv_val = buf;
+       bv[0].bv_len = strlen( bv[0].bv_val );
+
+       attr_merge( e, monitor_ad_desc, bv );
+
+       monitor_cache_release( mi, e );
+
+       return( 0 );
+}
+
+int 
+monitor_subsys_thread_update( 
+       struct monitorinfo      *mi,
+       Entry                   *e
+)
+{
+       Attribute               *a;
+       struct berval           bv[2], *b = NULL;
+       char                    buf[1024];
+
+       bv[1].bv_val = NULL;
+
+       snprintf( buf, sizeof( buf ), "backload=%d", 
+                       ldap_pvt_thread_pool_backload( &connection_pool ) );
+
+       if ( ( a = attr_find( e->e_attrs, monitor_ad_desc ) ) != NULL ) {
+
+               for ( b = a->a_vals; b[0].bv_val != NULL; b++ ) {
+                       if ( strncmp( b[0].bv_val, "backload=", 
+                                       sizeof( "backload=" ) - 1 ) == 0 ) {
+                               free( b[0].bv_val );
+                               ber_str2bv( buf, 0, 1, &b[0] );
+                               break;
+                       }
+               }
+       }
+
+       if ( b == NULL || b[0].bv_val == NULL ) {
+               bv[0].bv_val = buf;
+               bv[0].bv_len = strlen( buf );
+               attr_merge( e, monitor_ad_desc, bv );
+       }
+
+       return( 0 );
+}
+
index d14114c50c0e18a60a6b5164a9b4505a28032342..771012774028b89b2c7c634084196d32b5c7cf90 100644 (file)
@@ -31,6 +31,9 @@ main( int argc, char **argv )
        char textbuf[SLAP_TEXT_BUFLEN] = { '\0' };
        size_t textlen = sizeof textbuf;
 
+#ifdef NEW_LOGGING
+       lutil_log_initialize(argc, argv );
+#endif
        slap_tool_init( "slapadd", SLAPADD, argc, argv );
 
        if( !be->be_entry_open ||