]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-monitor/init.c
tolerate that config_get_vals() returns success with no values (ITS#4341)
[openldap] / servers / slapd / back-monitor / init.c
index ce8967c3045ee82604b92cb022eea1001a43c0a0..5e3c1db925b29b0a82517cea43250058972e0715 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2001-2005 The OpenLDAP Foundation.
+ * Copyright 2001-2006 The OpenLDAP Foundation.
  * Portions Copyright 2001-2003 Pierangelo Masarati.
  * All rights reserved.
  *
@@ -261,12 +261,28 @@ typedef struct entry_limbo_t {
        struct entry_limbo_t    *el_next;
 } entry_limbo_t;
 
+int
+monitor_back_is_configured( void )
+{
+       return be_monitor != NULL;
+}
+
 int
 monitor_back_register_entry(
        Entry                   *e,
        monitor_callback_t      *cb )
 {
-       monitor_info_t  *mi = ( monitor_info_t * )be_monitor->be_private;
+       monitor_info_t  *mi;
+
+       if ( be_monitor == NULL ) {
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_back_register_entry(\"%s\"): "
+                       "monitor database not configured.\n",
+                       e->e_name.bv_val, 0, 0 );
+               return -1;
+       }
+
+       mi = ( monitor_info_t * )be_monitor->be_private;
 
        assert( mi != NULL );
        assert( e != NULL );
@@ -413,9 +429,21 @@ monitor_back_register_entry_parent(
        int                     scope,
        struct berval           *filter )
 {
-       monitor_info_t  *mi = ( monitor_info_t * )be_monitor->be_private;
+       monitor_info_t  *mi;
        struct berval   ndn = BER_BVNULL;
 
+       if ( be_monitor == NULL ) {
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_back_register_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
+                       "monitor database not configured.\n",
+                       BER_BVISNULL( base ) ? "" : base->bv_val,
+                       scope == LDAP_SCOPE_BASE ? "base" : ( scope == LDAP_SCOPE_ONELEVEL ? "one" : "subtree" ),
+                       BER_BVISNULL( filter ) ? "" : filter->bv_val );
+               return -1;
+       }
+
+       mi = ( monitor_info_t * )be_monitor->be_private;
+
        assert( mi != NULL );
        assert( e != NULL );
        assert( e->e_private == NULL );
@@ -614,7 +642,7 @@ monitor_filter2ndn(
        struct berval   *ndn )
 {
        Connection      conn = { 0 };
-       char            opbuf[OPERATION_BUFFER_SIZE];
+       OperationBuffer opbuf;
        Operation       *op;
        SlapReply       rs = { 0 };
        slap_callback   cb = { NULL, monitor_filter2ndn_cb, NULL, NULL };
@@ -626,7 +654,7 @@ monitor_filter2ndn(
                return -1;
        }
 
-       op = (Operation *)opbuf;
+       op = (Operation *) &opbuf;
        connection_fake_init( &conn, op, &conn );
 
        op->o_tag = LDAP_REQ_SEARCH;
@@ -712,8 +740,26 @@ monitor_back_register_entry_attrs(
        int                     scope,
        struct berval           *filter )
 {
-       monitor_info_t  *mi = ( monitor_info_t * )be_monitor->be_private;
+       monitor_info_t  *mi;
        struct berval   ndn = BER_BVNULL;
+       char            *fname = ( a == NULL ? "callback" : "attrs" );
+
+       if ( be_monitor == NULL ) {
+               char            buf[ SLAP_TEXT_BUFLEN ];
+
+               snprintf( buf, sizeof( buf ),
+                       "monitor_back_register_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
+                       "monitor database not configured.\n",
+                       fname,
+                       BER_BVISNULL( base ) ? "" : base->bv_val,
+                       scope == LDAP_SCOPE_BASE ? "base" : ( scope == LDAP_SCOPE_ONELEVEL ? "one" : "subtree" ),
+                       BER_BVISNULL( filter ) ? "" : filter->bv_val );
+               Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
+
+               return -1;
+       }
+
+       mi = ( monitor_info_t * )be_monitor->be_private;
 
        assert( mi != NULL );
 
@@ -731,9 +777,9 @@ monitor_back_register_entry_attrs(
        {
                /* need a filter */
                Debug( LDAP_DEBUG_ANY,
-                       "monitor_back_register_entry_*(\"\"): "
+                       "monitor_back_register_entry_%s(\"\"): "
                        "need a valid filter\n",
-                       0, 0, 0 );
+                       fname, 0, 0 );
                return -1;
        }
 
@@ -747,13 +793,18 @@ monitor_back_register_entry_attrs(
 
                if ( BER_BVISNULL( &ndn ) ) {
                        if ( monitor_filter2ndn( base, scope, filter, &ndn ) ) {
-                               /* entry does not exist */
-                               Debug( LDAP_DEBUG_ANY,
-                                       "monitor_back_register_entry_*(\"\"): "
+                               char            buf[ SLAP_TEXT_BUFLEN ];
+
+                               snprintf( buf, sizeof( buf ),
+                                       "monitor_back_register_entry_%s(\"\"): "
                                        "base=%s scope=%d filter=%s : "
                                        "unable to find entry\n",
+                                       fname,
                                        base->bv_val ? base->bv_val : "\"\"",
                                        scope, filter->bv_val );
+
+                               /* entry does not exist */
+                               Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
                                return -1;
                        }
 
@@ -763,9 +814,9 @@ monitor_back_register_entry_attrs(
                if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
                        /* entry does not exist */
                        Debug( LDAP_DEBUG_ANY,
-                               "monitor_back_register_entry_*(\"%s\"): "
+                               "monitor_back_register_entry_%s(\"%s\"): "
                                "entry does not exist\n",
-                               ndn.bv_val, 0, 0 );
+                               fname, ndn.bv_val, 0 );
                        rc = -1;
                        goto done;
                }
@@ -776,9 +827,9 @@ monitor_back_register_entry_attrs(
                if ( mp->mp_flags & MONITOR_F_VOLATILE ) {
                        /* entry is volatile; cannot append callback */
                        Debug( LDAP_DEBUG_ANY,
-                               "monitor_back_register_entry_*(\"%s\"): "
+                               "monitor_back_register_entry_%s(\"%s\"): "
                                "entry is volatile\n",
-                               e->e_name.bv_val, 0, 0 );
+                               fname, e->e_name.bv_val, 0 );
                        rc = -1;
                        goto done;
                }
@@ -790,9 +841,9 @@ monitor_back_register_entry_attrs(
                        *atp = attrs_dup( a );
                        if ( *atp == NULL ) {
                                Debug( LDAP_DEBUG_ANY,
-                                       "monitor_back_register_entry_*(\"%s\"): "
+                                       "monitor_back_register_entry_%s(\"%s\"): "
                                        "attrs_dup() failed\n",
-                                       e->e_name.bv_val, 0, 0 );
+                                       fname, e->e_name.bv_val, 0 );
                                rc = -1;
                                goto done;
                        }
@@ -919,14 +970,25 @@ int
 monitor_back_initialize(
        BackendInfo     *bi )
 {
-       monitor_subsys_t        *ms;
        static char             *controls[] = {
                LDAP_CONTROL_MANAGEDSAIT,
                NULL
        };
-       monitor_info_t          *mi = &monitor_info;
-       int                     i;
-       const char              *text;
+
+       static ConfigTable monitorcfg[] = {
+               { NULL, NULL, 0, 0, 0, ARG_IGNORED,
+                       NULL, NULL, NULL, NULL }
+       };
+
+       static ConfigOCs monitorocs[] = {
+               { "( OLcfgDbOc:4.1 "
+                       "NAME 'olcMonitorConfig' "
+                       "DESC 'Monitor backend configuration' "
+                       "SUP olcDatabaseConfig "
+                       ")",
+                               Cft_Database, monitorcfg },
+               { NULL, 0, NULL }
+       };
 
        struct m_s {
                char    *name;
@@ -1201,87 +1263,10 @@ monitor_back_initialize(
                        offsetof(monitor_info_t, mi_ad_monitorRuntimeConfig) },
                { NULL, NULL, 0, -1 }
        };
-       static ConfigTable monitorcfg[] = {
-               { NULL, NULL, 0, 0, 0, ARG_IGNORED,
-                       NULL, NULL, NULL, NULL }
-       };
-       static ConfigOCs monitorocs[] = {
-               { "( OLcfgDbOc:4.1 "
-                       "NAME 'olcMonitorConfig' "
-                       "DESC 'Monitor backend configuration' "
-                       "SUP olcDatabaseConfig "
-                       ")",
-                               Cft_Database, monitorcfg },
-               { NULL, 0, NULL }
-       };
-       int             rc;
-
-       bi->bi_controls = controls;
-
-       bi->bi_init = 0;
-       bi->bi_open = 0;
-       bi->bi_config = monitor_back_config;
-       bi->bi_close = 0;
-       bi->bi_destroy = 0;
-
-       bi->bi_db_init = monitor_back_db_init;
-       bi->bi_db_config = monitor_back_db_config;
-       bi->bi_db_open = monitor_back_db_open;
-       bi->bi_db_close = 0;
-       bi->bi_db_destroy = monitor_back_db_destroy;
-
-       bi->bi_op_bind = monitor_back_bind;
-       bi->bi_op_unbind = 0;
-       bi->bi_op_search = monitor_back_search;
-       bi->bi_op_compare = monitor_back_compare;
-       bi->bi_op_modify = monitor_back_modify;
-       bi->bi_op_modrdn = 0;
-       bi->bi_op_add = 0;
-       bi->bi_op_delete = 0;
-       bi->bi_op_abandon = 0;
-
-       bi->bi_extended = 0;
-
-       bi->bi_entry_release_rw = 0;
-       bi->bi_chk_referrals = 0;
-       bi->bi_operational = monitor_back_operational;
-
-       /*
-        * hooks for slap tools
-        */
-       bi->bi_tool_entry_open = 0;
-       bi->bi_tool_entry_close = 0;
-       bi->bi_tool_entry_first = 0;
-       bi->bi_tool_entry_next = 0;
-       bi->bi_tool_entry_get = 0;
-       bi->bi_tool_entry_put = 0;
-       bi->bi_tool_entry_reindex = 0;
-       bi->bi_tool_sync = 0;
-       bi->bi_tool_dn2id_get = 0;
-       bi->bi_tool_id2entry_get = 0;
-       bi->bi_tool_entry_modify = 0;
-
-       bi->bi_connection_init = 0;
-       bi->bi_connection_destroy = 0;
-
-       /*
-        * configuration objectClasses (fake)
-        */
-       bi->bi_cf_ocs = monitorocs;
 
-       rc = config_register_schema( monitorcfg, monitorocs );
-       if ( rc ) {
-               return rc;
-       }
-
-       /*
-        * register subsys
-        */
-       for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
-               if ( monitor_back_register_subsys( ms ) ) {
-                       return -1;
-               }
-       }
+       int                     i, rc;
+       const char              *text;
+       monitor_info_t          *mi = &monitor_info;
 
        /* schema integration */
        for ( i = 0; mat[ i ].name; i++ ) {
@@ -1372,6 +1357,66 @@ monitor_back_initialize(
                ((ObjectClass **)&(((char *)mi)[ moc[ i ].offset ]))[ 0 ] = Oc;
        }
 
+       bi->bi_controls = controls;
+
+       bi->bi_init = 0;
+       bi->bi_open = 0;
+       bi->bi_config = monitor_back_config;
+       bi->bi_close = 0;
+       bi->bi_destroy = 0;
+
+       bi->bi_db_init = monitor_back_db_init;
+#if 0
+       bi->bi_db_config = monitor_back_db_config;
+#endif
+       bi->bi_db_open = monitor_back_db_open;
+       bi->bi_db_close = 0;
+       bi->bi_db_destroy = monitor_back_db_destroy;
+
+       bi->bi_op_bind = monitor_back_bind;
+       bi->bi_op_unbind = 0;
+       bi->bi_op_search = monitor_back_search;
+       bi->bi_op_compare = monitor_back_compare;
+       bi->bi_op_modify = monitor_back_modify;
+       bi->bi_op_modrdn = 0;
+       bi->bi_op_add = 0;
+       bi->bi_op_delete = 0;
+       bi->bi_op_abandon = 0;
+
+       bi->bi_extended = 0;
+
+       bi->bi_entry_release_rw = 0;
+       bi->bi_chk_referrals = 0;
+       bi->bi_operational = monitor_back_operational;
+
+       /*
+        * hooks for slap tools
+        */
+       bi->bi_tool_entry_open = 0;
+       bi->bi_tool_entry_close = 0;
+       bi->bi_tool_entry_first = 0;
+       bi->bi_tool_entry_next = 0;
+       bi->bi_tool_entry_get = 0;
+       bi->bi_tool_entry_put = 0;
+       bi->bi_tool_entry_reindex = 0;
+       bi->bi_tool_sync = 0;
+       bi->bi_tool_dn2id_get = 0;
+       bi->bi_tool_id2entry_get = 0;
+       bi->bi_tool_entry_modify = 0;
+
+       bi->bi_connection_init = 0;
+       bi->bi_connection_destroy = 0;
+
+       /*
+        * configuration objectClasses (fake)
+        */
+       bi->bi_cf_ocs = monitorocs;
+
+       rc = config_register_schema( monitorcfg, monitorocs );
+       if ( rc ) {
+               return rc;
+       }
+
        return 0;
 }
 
@@ -1379,9 +1424,22 @@ int
 monitor_back_db_init(
        BackendDB       *be )
 {
-       int             rc;
-       struct berval   dn, ndn;
-       struct berval   bv;
+       int                     rc;
+       struct berval           dn = BER_BVC( SLAPD_MONITOR_DN ),
+                               pdn,
+                               ndn;
+       BackendDB               *be2;
+
+       monitor_subsys_t        *ms;
+
+       /*
+        * register subsys
+        */
+       for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
+               if ( monitor_back_register_subsys( ms ) ) {
+                       return -1;
+               }
+       }
 
        /*
         * database monitor can be defined once only
@@ -1396,19 +1454,15 @@ monitor_back_db_init(
        /* indicate system schema supported */
        SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR;
 
-       dn.bv_val = SLAPD_MONITOR_DN;
-       dn.bv_len = sizeof( SLAPD_MONITOR_DN ) - 1;
-
-       rc = dnNormalize( 0, NULL, NULL, &dn, &ndn, NULL );
+       rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
        if( rc != LDAP_SUCCESS ) {
                Debug( LDAP_DEBUG_ANY,
-                       "unable to normalize monitor DN \"%s\" (%d)\n",
+                       "unable to normalize/pretty monitor DN \"%s\" (%d)\n",
                        dn.bv_val, rc, 0 );
                return -1;
        }
 
-       ber_dupbv( &bv, &dn );
-       ber_bvarray_add( &be->be_suffix, &bv );
+       ber_bvarray_add( &be->be_suffix, &pdn );
        ber_bvarray_add( &be->be_nsuffix, &ndn );
 
        /* NOTE: only one monitor database is allowed,
@@ -1417,6 +1471,22 @@ monitor_back_db_init(
 
        be->be_private = &monitor_info;
 
+       be2 = select_backend( &ndn, 0, 0 );
+       if ( be2 != be ) {
+               char    *type = be2->bd_info->bi_type;
+
+               if ( overlay_is_over( be2 ) ) {
+                       slap_overinfo   *oi = (slap_overinfo *)be2->bd_info->bi_private;
+                       type = oi->oi_orig->bi_type;
+               }
+
+               Debug( LDAP_DEBUG_ANY,
+                       "\"monitor\" database serving namingContext \"%s\" "
+                       "is hidden by \"%s\" database serving namingContext \"%s\".\n",
+                       pdn.bv_val, type, be2->be_nsuffix[ 0 ].bv_val );
+               return -1;
+       }
+
        return 0;
 }
 
@@ -1426,16 +1496,21 @@ monitor_back_db_open(
 {
        monitor_info_t          *mi = (monitor_info_t *)be->be_private;
        struct monitor_subsys_t **ms;
-       Entry                   *e, **ep;
+       Entry                   *e, **ep, *root;
        monitor_entry_t         *mp;
        int                     i;
-       char                    buf[ BACKMONITOR_BUFSIZE ];
-       struct berval           bv;
+       struct berval           bv, rdn = BER_BVC(SLAPD_MONITOR_DN);
        struct tm               *tms;
 #ifdef HAVE_GMTIME_R
        struct tm               tm_buf;
 #endif
        static char             tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
+       struct berval   desc[] = {
+               BER_BVC("This subtree contains monitoring/managing objects."),
+               BER_BVC("This object contains information about this server."),
+               BER_BVC("Most of the information is held in operational"
+               " attributes, which must be explicitly requested."),
+               BER_BVNULL };
 
        assert( be_monitor != NULL );
        if ( be != be_monitor ) {
@@ -1472,35 +1547,18 @@ monitor_back_db_open(
 
        if ( BER_BVISEMPTY( &be->be_rootdn ) ) {
                BER_BVSTR( &mi->mi_creatorsName, SLAPD_ANONYMOUS );
+               BER_BVSTR( &mi->mi_ncreatorsName, SLAPD_ANONYMOUS );
        } else {
                mi->mi_creatorsName = be->be_rootdn;
+               mi->mi_ncreatorsName = be->be_rootndn;
        }
 
        /*
         * creates the "cn=Monitor" entry 
         */
-       snprintf( buf, sizeof( buf ), 
-               "dn: %s\n"
-               "objectClass: %s\n"
-               "structuralObjectClass: %s\n"
-               "cn: Monitor\n"
-               "description: This subtree contains monitoring/managing objects.\n"
-               "description: This object contains information about this server.\n"
-               "description: Most of the information is held in operational"
-               " attributeTypes, which must be explicitly requested.\n"
-               "creatorsName: %s\n"
-               "modifiersName: %s\n"
-               "createTimestamp: %s\n"
-               "modifyTimestamp: %s\n",
-               SLAPD_MONITOR_DN,
-               mi->mi_oc_monitorServer->soc_cname.bv_val,
-               mi->mi_oc_monitorServer->soc_cname.bv_val,
-               mi->mi_creatorsName.bv_val,
-               mi->mi_creatorsName.bv_val,
-               mi->mi_startTime.bv_val,
-               mi->mi_startTime.bv_val );
-
-       e = str2entry( buf );
+       e = monitor_entry_stub( NULL, NULL, &rdn, mi->mi_oc_monitorServer, mi,
+               NULL, NULL );
+
        if ( e == NULL) {
                Debug( LDAP_DEBUG_ANY,
                        "unable to create \"%s\" entry\n",
@@ -1508,6 +1566,8 @@ monitor_back_db_open(
                return( -1 );
        }
 
+       attr_merge_normalize( e, slap_schema.si_ad_description, desc, NULL );
+
        bv.bv_val = strchr( (char *) Versionstr, '$' );
        if ( bv.bv_val != NULL ) {
                char    *end;
@@ -1553,6 +1613,7 @@ monitor_back_db_open(
                        SLAPD_MONITOR_DN, 0, 0 );
                return -1;
        }
+       root = e;
 
        /*      
         * Create all the subsystem specific entries
@@ -1575,46 +1636,18 @@ monitor_back_db_open(
                        return( -1 );
                }
 
-               dn.bv_len += sizeof( SLAPD_MONITOR_DN ); /* 1 for the , */
-               dn.bv_val = ch_malloc( dn.bv_len + 1 );
-               strcpy( dn.bv_val , monitor_subsys[ i ]->mss_rdn.bv_val );
-               strcat( dn.bv_val, "," SLAPD_MONITOR_DN );
-               rc = dnPrettyNormal( NULL, &dn, &monitor_subsys[ i ]->mss_dn,
-                       &monitor_subsys[ i ]->mss_ndn, NULL );
-               free( dn.bv_val );
-               if ( rc != LDAP_SUCCESS ) {
-                       Debug( LDAP_DEBUG_ANY,
-                               "monitor DN \"%s\" is invalid\n", 
-                               dn.bv_val, 0, 0 );
-                       return( -1 );
-               }
+               e = monitor_entry_stub( &root->e_name, &root->e_nname,
+                       &monitor_subsys[ i ]->mss_rdn, mi->mi_oc_monitorContainer, mi,
+                       NULL, NULL );
 
-               snprintf( buf, sizeof( buf ),
-                               "dn: %s\n"
-                               "objectClass: %s\n"
-                               "structuralObjectClass: %s\n"
-                               "cn: %s\n"
-                               "creatorsName: %s\n"
-                               "modifiersName: %s\n"
-                               "createTimestamp: %s\n"
-                               "modifyTimestamp: %s\n",
-                               monitor_subsys[ i ]->mss_dn.bv_val,
-                               mi->mi_oc_monitorContainer->soc_cname.bv_val,
-                               mi->mi_oc_monitorContainer->soc_cname.bv_val,
-                               monitor_subsys[ i ]->mss_name,
-                               mi->mi_creatorsName.bv_val,
-                               mi->mi_creatorsName.bv_val,
-                               mi->mi_startTime.bv_val,
-                               mi->mi_startTime.bv_val );
-               
-               e = str2entry( buf );
-               
                if ( e == NULL) {
                        Debug( LDAP_DEBUG_ANY,
                                "unable to create \"%s\" entry\n", 
                                monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
                        return( -1 );
                }
+               monitor_subsys[i]->mss_dn = e->e_name;
+               monitor_subsys[i]->mss_ndn = e->e_nname;
 
                if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_desc[ 0 ] ) ) {
                        attr_merge_normalize( e, slap_schema.si_ad_description,
@@ -1744,6 +1777,7 @@ monitor_back_config(
        return SLAP_CONF_UNKNOWN;
 }
 
+#if 0
 int
 monitor_back_db_config(
        Backend     *be,
@@ -1752,15 +1786,14 @@ monitor_back_db_config(
        int         argc,
        char        **argv )
 {
-#if 0
        monitor_info_t  *mi = ( monitor_info_t * )be->be_private;
-#endif
 
        /*
         * eventually, will hold database specific configuration parameters
         */
        return SLAP_CONF_UNKNOWN;
 }
+#endif
 
 int
 monitor_back_db_destroy(