]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-monitor/init.c
Check errcode from dn2entry before using ei
[openldap] / servers / slapd / back-monitor / init.c
index f4bc4ed66cdf946ea03a2b4db096c3ec96a8ad88..293d543535a1f9672b6fe87f6e98ae438a25fec1 100644 (file)
@@ -1380,8 +1380,10 @@ monitor_back_db_init(
        BackendDB       *be )
 {
        int             rc;
-       struct berval   dn, ndn;
-       struct berval   bv;
+       struct berval   dn = BER_BVC( SLAPD_MONITOR_DN ),
+                       pdn,
+                       ndn;
+       BackendDB       *be2;
 
        /*
         * database monitor can be defined once only
@@ -1396,19 +1398,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 +1415,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;
 }
 
@@ -1768,6 +1782,10 @@ monitor_back_db_destroy(
 {
        monitor_info_t  *mi = ( monitor_info_t * )be->be_private;
 
+       if ( mi == NULL ) {
+               return -1;
+       }
+
        /*
         * FIXME: destroys all the data
         */
@@ -1793,6 +1811,8 @@ monitor_back_db_destroy(
        
        ldap_pvt_thread_mutex_destroy( &monitor_info.mi_cache_mutex );
 
+       be->be_private = NULL;
+
        return 0;
 }