]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-monitor/database.c
Use IANA-assigned OID for entryDN and remove hide flag.
[openldap] / servers / slapd / back-monitor / database.c
index 5d080f60fd6571a220cbae7173ae17ae25a95703..f09001ed2b0070e05e8d160f7789b91018a1563f 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2001-2006 The OpenLDAP Foundation.
+ * Copyright 2001-2007 The OpenLDAP Foundation.
  * Portions Copyright 2001-2003 Pierangelo Masarati.
  * All rights reserved.
  *
 static int monitor_back_add_plugin( monitor_info_t *mi, Backend *be, Entry *e );
 #endif /* defined(LDAP_SLAPI) */
 
-#if 0  /* moved to back-bdb/monitor.c */
-#if defined(SLAPD_BDB)
-#include "../back-bdb/back-bdb.h"
-#endif /* defined(SLAPD_BDB) */
-#if defined(SLAPD_HDB)
-#include "../back-hdb/back-bdb.h"
-#endif /* defined(SLAPD_HDB) */
-#endif
-#if defined(SLAPD_LDAP) 
-#include "../back-ldap/back-ldap.h"
-#endif /* defined(SLAPD_LDAP) */
-#if defined(SLAPD_META) 
-#include "../back-meta/back-meta.h"
-#endif /* defined(SLAPD_META) */
-
 /* for PATH_MAX on some systems (e.g. Solaris) */
 #ifdef HAVE_LIMITS_H
 #include <limits.h>
@@ -122,385 +107,424 @@ init_restrictedOperation( monitor_info_t *mi, Entry *e, slap_mask_t restrictops
        return LDAP_SUCCESS;
 }
 
-int
-monitor_subsys_database_init(
+static int
+monitor_subsys_database_init_one(
+       monitor_info_t          *mi,
        BackendDB               *be,
-       monitor_subsys_t        *ms
-)
+       monitor_subsys_t        *ms,
+       monitor_subsys_t        *ms_backend,
+       monitor_subsys_t        *ms_overlay,
+       struct berval           *rdn,
+       Entry                   *e_database,
+       Entry                   ***epp )
 {
-       monitor_info_t          *mi;
-       Entry                   *e_database, **ep;
-       int                     i;
+       char                    buf[ BACKMONITOR_BUFSIZE ];
+       int                     j;
+       slap_overinfo           *oi = NULL;
+       BackendInfo             *bi, *bi2;
+       Entry                   *e;
        monitor_entry_t         *mp;
-       monitor_subsys_t        *ms_backend,
-                               *ms_overlay;
-
-       assert( be != NULL );
-
-       ms->mss_modify = monitor_subsys_database_modify;
+       char                    *rdnval = strchr( rdn->bv_val, '=' ) + 1;
+       struct berval           bv;
 
-       mi = ( monitor_info_t * )be->be_private;
+       bi = be->bd_info;
 
-       ms_backend = monitor_back_get_subsys( SLAPD_MONITOR_BACKEND_NAME );
-       if ( ms_backend == NULL ) {
-               Debug( LDAP_DEBUG_ANY,
-                       "monitor_subsys_database_init: "
-                       "unable to get "
-                       "\"" SLAPD_MONITOR_BACKEND_NAME "\" "
-                       "subsystem\n",
-                       0, 0, 0 );
-               return -1;
+       if ( overlay_is_over( be ) ) {
+               oi = (slap_overinfo *)be->bd_info->bi_private;
+               bi = oi->oi_orig;
        }
 
-       ms_overlay = monitor_back_get_subsys( SLAPD_MONITOR_OVERLAY_NAME );
-       if ( ms_overlay == NULL ) {
-               Debug( LDAP_DEBUG_ANY,
-                       "monitor_subsys_database_init: "
-                       "unable to get "
-                       "\"" SLAPD_MONITOR_OVERLAY_NAME "\" "
-                       "subsystem\n",
-                       0, 0, 0 );
-               return -1;
+       /* Subordinates are not exposed as their own naming context */
+       if ( SLAP_GLUE_SUBORDINATE( be ) ) {
+               return 0;
        }
 
-       if ( monitor_cache_get( mi, &ms->mss_ndn, &e_database ) ) {
+       e = monitor_entry_stub( &ms->mss_dn, &ms->mss_ndn, rdn,
+               mi->mi_oc_monitoredObject, mi, NULL, NULL );
+
+       if ( e == NULL ) {
                Debug( LDAP_DEBUG_ANY,
                        "monitor_subsys_database_init: "
-                       "unable to get entry \"%s\"\n",
-                       ms->mss_ndn.bv_val, 0, 0 );
+                       "unable to create entry \"%s,%s\"\n",
+                       rdn->bv_val, ms->mss_dn.bv_val, 0 );
                return( -1 );
        }
 
-       (void)init_readOnly( mi, e_database, frontendDB->be_restrictops );
-       (void)init_restrictedOperation( mi, e_database, frontendDB->be_restrictops );
-
-       mp = ( monitor_entry_t * )e_database->e_private;
-       mp->mp_children = NULL;
-       ep = &mp->mp_children;
-
-       i = -1;
-       LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
-               char            buf[ BACKMONITOR_BUFSIZE ];
-               int             j;
-               slap_overinfo   *oi = NULL;
-               BackendInfo     *bi, *bi2;
-               Entry           *e;
-               struct berval bv;
-
-               i++;
+       ber_str2bv( bi->bi_type, 0, 0, &bv );
+       attr_merge_one( e, mi->mi_ad_monitoredInfo, &bv, NULL );
+       attr_merge_one( e, mi->mi_ad_monitorIsShadow,
+               SLAP_SHADOW( be ) ? (struct berval *)&slap_true_bv :
+                       (struct berval *)&slap_false_bv, NULL );
 
-               bi = be->bd_info;
+       if ( SLAP_MONITOR( be ) ) {
+               attr_merge( e, slap_schema.si_ad_monitorContext,
+                               be->be_suffix, be->be_nsuffix );
+               attr_merge( e_database, slap_schema.si_ad_monitorContext,
+                               be->be_suffix, be->be_nsuffix );
 
-               if ( overlay_is_over( be ) ) {
-                       oi = (slap_overinfo *)be->bd_info->bi_private;
-                       bi = oi->oi_orig;
+       } else {
+               if ( be->be_suffix == NULL ) {
+                       Debug( LDAP_DEBUG_ANY,
+                               "monitor_subsys_database_init: "
+                               "missing suffix for %s\n",
+                               rdnval, 0, 0 );
+                       return -1;
                }
+               attr_merge( e, slap_schema.si_ad_namingContexts,
+                               be->be_suffix, be->be_nsuffix );
+               attr_merge( e_database, slap_schema.si_ad_namingContexts,
+                               be->be_suffix, be->be_nsuffix );
+       }
 
-               /* Subordinates are not exposed as their own naming context */
-               if ( SLAP_GLUE_SUBORDINATE( be ) ) {
-                       continue;
-               }
+       (void)init_readOnly( mi, e, be->be_restrictops );
+       (void)init_restrictedOperation( mi, e, be->be_restrictops );
 
-               bv.bv_len = snprintf( buf, sizeof( buf ),
-                               "cn=Database %d", i );
-               bv.bv_val = buf;
-               e = monitor_entry_stub( &ms->mss_dn, &ms->mss_ndn, &bv,
-                       mi->mi_oc_monitoredObject, mi, NULL, NULL );
+       if ( SLAP_SHADOW( be ) && be->be_update_refs ) {
+               attr_merge_normalize( e, mi->mi_ad_monitorUpdateRef,
+                               be->be_update_refs, NULL );
+       }
 
-               if ( e == NULL ) {
-                       Debug( LDAP_DEBUG_ANY,
-                               "monitor_subsys_database_init: "
-                               "unable to create entry \"cn=Database %d,%s\"\n",
-                               i, ms->mss_dn.bv_val, 0 );
-                       return( -1 );
-               }
+       if ( oi != NULL ) {
+               slap_overinst   *on = oi->oi_list,
+                               *on1 = on;
 
-               ber_str2bv( bi->bi_type, 0, 0, &bv );
-               attr_merge_one( e, mi->mi_ad_monitoredInfo, &bv, NULL );
-               attr_merge_one( e, mi->mi_ad_monitorIsShadow,
-                       SLAP_SHADOW( be ) ? (struct berval *)&slap_true_bv :
-                               (struct berval *)&slap_false_bv, NULL );
+               for ( ; on; on = on->on_next ) {
+                       slap_overinst           *on2;
 
-               if ( SLAP_MONITOR( be ) ) {
-                       attr_merge( e, slap_schema.si_ad_monitorContext,
-                                       be->be_suffix, be->be_nsuffix );
-                       attr_merge( e_database, slap_schema.si_ad_monitorContext,
-                                       be->be_suffix, be->be_nsuffix );
+                       for ( on2 = on1; on2 != on; on2 = on2->on_next ) {
+                               if ( on2->on_bi.bi_type == on->on_bi.bi_type ) {
+                                       break;
+                               }
+                       }
 
-               } else {
-                       if ( be->be_suffix == NULL ) {
-                               Debug( LDAP_DEBUG_ANY,
-                                       "monitor_subsys_database_init: "
-                                       "missing suffix for database %d\n",
-                                       i, 0, 0 );
-                               return -1;
+                       if ( on2 != on ) {
+                               break;
                        }
-                       attr_merge( e, slap_schema.si_ad_namingContexts,
-                                       be->be_suffix, be->be_nsuffix );
-                       attr_merge( e_database, slap_schema.si_ad_namingContexts,
-                                       be->be_suffix, be->be_nsuffix );
-               }
+                       
+                       ber_str2bv( on->on_bi.bi_type, 0, 0, &bv );
+                       attr_merge_normalize_one( e, mi->mi_ad_monitorOverlay,
+                                       &bv, NULL );
 
-               (void)init_readOnly( mi, e, be->be_restrictops );
-               (void)init_restrictedOperation( mi, e, be->be_restrictops );
+                       /* find the overlay number, j */
+                       for ( on2 = overlay_next( NULL ), j = 0; on2; on2 = overlay_next( on2 ), j++ ) {
+                               if ( on2->on_bi.bi_type == on->on_bi.bi_type ) {
+                                       break;
+                               }
+                       }
+                       assert( on2 != NULL );
+
+                       snprintf( buf, sizeof( buf ), 
+                               "cn=Overlay %d,%s", 
+                               j, ms_overlay->mss_dn.bv_val );
+                       ber_str2bv( buf, 0, 0, &bv );
+                       attr_merge_normalize_one( e,
+                                       slap_schema.si_ad_seeAlso,
+                                       &bv, NULL );
+               }
+       }
 
-               if ( SLAP_SHADOW( be ) && be->be_update_refs ) {
-                       attr_merge_normalize( e, mi->mi_ad_monitorUpdateRef,
-                                       be->be_update_refs, NULL );
+       j = -1;
+       LDAP_STAILQ_FOREACH( bi2, &backendInfo, bi_next ) {
+               j++;
+               if ( bi2->bi_type == bi->bi_type ) {
+                       snprintf( buf, sizeof( buf ), 
+                               "cn=Backend %d,%s", 
+                               j, ms_backend->mss_dn.bv_val );
+                       bv.bv_val = buf;
+                       bv.bv_len = strlen( buf );
+                       attr_merge_normalize_one( e,
+                                       slap_schema.si_ad_seeAlso,
+                                       &bv, NULL );
+                       break;
                }
+       }
+       /* we must find it! */
+       assert( j >= 0 );
 
-               if ( oi != NULL ) {
-                       slap_overinst   *on = oi->oi_list,
-                                       *on1 = on;
+       mp = monitor_entrypriv_create();
+       if ( mp == NULL ) {
+               return -1;
+       }
+       e->e_private = ( void * )mp;
+       mp->mp_info = ms;
+       mp->mp_flags = ms->mss_flags
+               | MONITOR_F_SUB;
 
-                       for ( ; on; on = on->on_next ) {
-                               struct berval           bv;
-                               slap_overinst           *on2;
+       if ( monitor_cache_add( mi, e ) ) {
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_subsys_database_init: "
+                       "unable to add entry \"%s,%s\"\n",
+                       rdn->bv_val, ms->mss_dn.bv_val, 0 );
+               return( -1 );
+       }
 
-                               for ( on2 = on1; on2 != on; on2 = on2->on_next ) {
-                                       if ( on2->on_bi.bi_type == on->on_bi.bi_type ) {
-                                               break;
-                                       }
-                               }
+#if defined(LDAP_SLAPI)
+       monitor_back_add_plugin( mi, be, e );
+#endif /* defined(LDAP_SLAPI) */
+
+       if ( oi != NULL ) {
+               Entry           **ep_overlay = &mp->mp_children;
+               monitor_entry_t *mp_overlay;
+               slap_overinst   *on = oi->oi_list;
+               int             o;
+
+               for ( o = 0; on; o++, on = on->on_next ) {
+                       Entry                   *e_overlay;
+                       slap_overinst           *on2;
 
-                               if ( on2 != on ) {
+                       /* find the overlay number, j */
+                       for ( on2 = overlay_next( NULL ), j = 0; on2; on2 = overlay_next( on2 ), j++ ) {
+                               if ( on2->on_bi.bi_type == on->on_bi.bi_type ) {
                                        break;
                                }
-                               
-                               ber_str2bv( on->on_bi.bi_type, 0, 0, &bv );
-                               attr_merge_normalize_one( e, mi->mi_ad_monitorOverlay,
-                                               &bv, NULL );
-
-                               /* find the overlay number, j */
-                               for ( on2 = overlay_next( NULL ), j = 0; on2; on2 = overlay_next( on2 ), j++ ) {
-                                       if ( on2->on_bi.bi_type == on->on_bi.bi_type ) {
-                                               break;
-                                       }
-                               }
-                               assert( on2 != NULL );
-
-                               snprintf( buf, sizeof( buf ), 
-                                       "cn=Overlay %d,%s", 
-                                       j, ms_overlay->mss_dn.bv_val );
-                               ber_str2bv( buf, 0, 0, &bv );
-                               attr_merge_normalize_one( e,
-                                               slap_schema.si_ad_seeAlso,
-                                               &bv, NULL );
                        }
-               }
+                       assert( on2 != NULL );
 
+                       bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Overlay %d", o );
+                       bv.bv_val = buf;
 
-               if ( 0 ) {
-                       assert( 0 );
-
-#if 0 /* moved into back-bdb/monitor.c */
-#if defined(SLAPD_BDB) || defined(SLAPD_HDB) 
-               } else if ( strcmp( bi->bi_type, "bdb" ) == 0
-                               || strcmp( bi->bi_type, "hdb" ) == 0 )
-               {
-                       struct berval   bv;
-                       ber_len_t       pathlen = 0, len = 0;
-                       char            path[ PATH_MAX ] = { '\0' };
-                       struct bdb_info *bdb = (struct bdb_info *) be->be_private;
-                       char            *fname = bdb->bi_dbenv_home;
-
-                       len = strlen( fname );
-                       if ( fname[ 0 ] != '/' ) {
-                               /* get full path name */
-                               getcwd( path, sizeof( path ) );
-                               pathlen = strlen( path );
-
-                               if ( fname[ 0 ] == '.' && fname[ 1 ] == '/' ) {
-                                       fname += 2;
-                                       len -= 2;
-                               }
-                       }
+                       e_overlay = monitor_entry_stub( &e->e_name, &e->e_nname, &bv,
+                               mi->mi_oc_monitoredObject, mi, NULL, NULL );
 
-                       bv.bv_len = STRLENOF( "file://" ) + pathlen
-                               + STRLENOF( "/" ) + len;
-                       bv.bv_val = ch_malloc( bv.bv_len + STRLENOF( "/" ) + 1 );
-                       AC_MEMCPY( bv.bv_val, "file://", STRLENOF( "file://" ) );
-                       if ( pathlen ) {
-                               AC_MEMCPY( &bv.bv_val[ STRLENOF( "file://" ) ],
-                                               path, pathlen );
-                               bv.bv_val[ STRLENOF( "file://" ) + pathlen ] = '/';
-                               pathlen++;
-                       }
-                       AC_MEMCPY( &bv.bv_val[ STRLENOF( "file://" ) + pathlen ],
-                                       fname, len );
-                       if ( bv.bv_val[ bv.bv_len - 1 ] != '/' ) {
-                               bv.bv_val[ bv.bv_len ] = '/';
-                               bv.bv_len++;
+                       if ( e_overlay == NULL ) {
+                               Debug( LDAP_DEBUG_ANY,
+                                       "monitor_subsys_database_init: "
+                                       "unable to create entry "
+                                       "\"cn=Overlay %d,%s,%s\"\n",
+                                       o, rdn->bv_val, ms->mss_dn.bv_val );
+                               return( -1 );
                        }
-                       bv.bv_val[ bv.bv_len ] = '\0';
+                       ber_str2bv( on->on_bi.bi_type, 0, 0, &bv );
+                       attr_merge_one( e_overlay, mi->mi_ad_monitoredInfo, &bv, NULL );
 
-                       attr_merge_normalize_one( e, slap_schema.si_ad_labeledURI,
-                                       &bv, NULL );
+                       bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Overlay %d,%s",
+                               j, ms_overlay->mss_dn.bv_val );
+                       bv.bv_val = buf;
+                       attr_merge_normalize_one( e_overlay, slap_schema.si_ad_seeAlso,
+                               &bv, NULL );
 
-                       ch_free( bv.bv_val );
+                       if ( SLAP_MONITOR( be ) ) {
+                               attr_merge( e_overlay, slap_schema.si_ad_monitorContext,
+                                               be->be_suffix, be->be_nsuffix );
 
-#endif /* defined(SLAPD_BDB) || defined(SLAPD_HDB) */
-#endif
-#if defined(SLAPD_LDAP) 
-               } else if ( strcmp( bi->bi_type, "ldap" ) == 0 ) {
-                       ldapinfo_t      *li = (ldapinfo_t *)be->be_private;
-#if 0
-                       attr_merge_normalize( e, slap_schema.si_ad_labeledURI,
-                                       li->li_bvuri, NULL );
-#else
-                       char            **urls = ldap_str2charray( li->li_uri, " " );
+                       } else {
+                               attr_merge( e_overlay, slap_schema.si_ad_namingContexts,
+                                               be->be_suffix, be->be_nsuffix );
+                       }
 
-                       if ( urls != NULL ) {
-                               int             u;
+                       mp_overlay = monitor_entrypriv_create();
+                       if ( mp_overlay == NULL ) {
+                               return -1;
+                       }
+                       e_overlay->e_private = ( void * )mp_overlay;
+                       mp_overlay->mp_info = ms;
+                       mp_overlay->mp_flags = ms->mss_flags
+                               | MONITOR_F_SUB;
+       
+                       if ( monitor_cache_add( mi, e_overlay ) ) {
+                               Debug( LDAP_DEBUG_ANY,
+                                       "monitor_subsys_database_init: "
+                                       "unable to add entry "
+                                       "\"cn=Overlay %d,%s,%s\"\n",
+                                       o, rdn->bv_val, ms->mss_dn.bv_val );
+                               return( -1 );
+                       }
 
-                               for ( u = 0; urls[ u ] != NULL; u++ ) {
-                                       struct berval   bv;
+                       *ep_overlay = e_overlay;
+                       ep_overlay = &mp_overlay->mp_next;
+               }
+       }
 
-                                       ber_str2bv( urls[ u ], 0, 0, &bv );
+       **epp = e;
+       *epp = &mp->mp_next;
 
-                                       attr_merge_normalize_one( e,
-                                               slap_schema.si_ad_labeledURI,
-                                               &bv, NULL );
-                               }
+       return 0;
+}
 
-                               ldap_charray_free( urls );
-                       }
-#endif
+int
+monitor_back_register_database(
+       BackendDB               *be )
+{
+       monitor_info_t          *mi;
+       Entry                   *e_database, **ep;
+       int                     i, rc;
+       monitor_entry_t         *mp;
+       monitor_subsys_t        *ms_backend,
+                               *ms_database,
+                               *ms_overlay;
+       struct berval           bv;
+       char                    buf[ BACKMONITOR_BUFSIZE ];
 
-#endif /* defined(SLAPD_LDAP) */
-#if defined(SLAPD_META) 
-               } else if ( strcmp( bi->bi_type, "meta" ) == 0 ) {
-                       metainfo_t      *mi = (metainfo_t *)be->be_private;
-                       int             t;
+       assert( be_monitor != NULL );
 
-                       for ( t = 0; t < mi->mi_ntargets; t++ ) {
-                               char            **urls = ldap_str2charray( mi->mi_targets[ t ]->mt_uri, " " );
+       if ( !monitor_subsys_is_opened() ) {
+               return monitor_back_register_database_limbo( be );
+       }
+
+       mi = ( monitor_info_t * )be_monitor->be_private;
 
-                               if ( urls != NULL ) {
-                                       int             u;
+       ms_backend = monitor_back_get_subsys( SLAPD_MONITOR_BACKEND_NAME );
+       if ( ms_backend == NULL ) {
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_back_register_database: "
+                       "unable to get "
+                       "\"" SLAPD_MONITOR_BACKEND_NAME "\" "
+                       "subsystem\n",
+                       0, 0, 0 );
+               return -1;
+       }
+
+       ms_database = monitor_back_get_subsys( SLAPD_MONITOR_DATABASE_NAME );
+       if ( ms_database == NULL ) {
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_back_register_database: "
+                       "unable to get "
+                       "\"" SLAPD_MONITOR_DATABASE_NAME "\" "
+                       "subsystem\n",
+                       0, 0, 0 );
+               return -1;
+       }
 
-                                       for ( u = 0; urls[ u ] != NULL; u++ ) {
-                                               struct berval   bv;
+       ms_overlay = monitor_back_get_subsys( SLAPD_MONITOR_OVERLAY_NAME );
+       if ( ms_overlay == NULL ) {
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_back_register_database: "
+                       "unable to get "
+                       "\"" SLAPD_MONITOR_OVERLAY_NAME "\" "
+                       "subsystem\n",
+                       0, 0, 0 );
+               return -1;
+       }
 
-                                               ber_str2bv( urls[ u ], 0, 0, &bv );
+       if ( monitor_cache_get( mi, &ms_database->mss_ndn, &e_database ) ) {
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_subsys_database_init: "
+                       "unable to get entry \"%s\"\n",
+                       ms_database->mss_ndn.bv_val, 0, 0 );
+               return( -1 );
+       }
 
-                                               attr_merge_normalize_one( e,
-                                                       slap_schema.si_ad_labeledURI,
-                                                       &bv, NULL );
+       mp = ( monitor_entry_t * )e_database->e_private;
+       for ( i = -1, ep = &mp->mp_children; *ep; i++ ) {
+               Attribute       *a;
+
+               a = attr_find( (*ep)->e_attrs, slap_schema.si_ad_namingContexts );
+               if ( a ) {
+                       int             j, k;
+
+                       for ( j = 0; !BER_BVISNULL( &a->a_nvals[ j ] ); j++ ) {
+                               for ( k = 0; !BER_BVISNULL( &be->be_nsuffix[ k ] ); k++ ) {
+                                       if ( dn_match( &a->a_nvals[ j ], &be->be_nsuffix[ k ] ) ) {
+                                               rc = 0;
+                                               goto done;
                                        }
-                                       ldap_charray_free( urls );
                                }
                        }
-#endif /* defined(SLAPD_META) */
                }
 
-               j = -1;
-               LDAP_STAILQ_FOREACH( bi2, &backendInfo, bi_next ) {
-                       j++;
-                       if ( bi2->bi_type == bi->bi_type ) {
-                               struct berval           bv;
-
-                               snprintf( buf, sizeof( buf ), 
-                                       "cn=Backend %d,%s", 
-                                       j, ms_backend->mss_dn.bv_val );
-                               bv.bv_val = buf;
-                               bv.bv_len = strlen( buf );
-                               attr_merge_normalize_one( e,
-                                               slap_schema.si_ad_seeAlso,
-                                               &bv, NULL );
-                               break;
-                       }
-               }
-               /* we must find it! */
-               assert( j >= 0 );
+               mp = ( monitor_entry_t * )(*ep)->e_private;
 
-               mp = monitor_entrypriv_create();
-               if ( mp == NULL ) {
-                       return -1;
-               }
-               e->e_private = ( void * )mp;
-               mp->mp_info = ms;
-               mp->mp_flags = ms->mss_flags
-                       | MONITOR_F_SUB;
+               assert( mp != NULL );
+               ep = &mp->mp_next;
+       }
 
-               if ( monitor_cache_add( mi, e ) ) {
-                       Debug( LDAP_DEBUG_ANY,
-                               "monitor_subsys_database_init: "
-                               "unable to add entry \"cn=Database %d,%s\"\n",
-                               i, ms->mss_dn.bv_val, 0 );
-                       return( -1 );
-               }
+       bv.bv_val = buf;
+       bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Database %d", i );
+       if ( bv.bv_len >= sizeof( buf ) ) {
+               rc = -1;
+               goto done;
+       }
+       
+       rc = monitor_subsys_database_init_one( mi, be,
+               ms_database, ms_backend, ms_overlay, &bv, e_database, &ep );
+       if ( rc != 0 ) {
+               goto done;
+       }
 
-#if defined(LDAP_SLAPI)
-               monitor_back_add_plugin( mi, be, e );
-#endif /* defined(LDAP_SLAPI) */
+done:;
+       monitor_cache_release( mi, e_database );
+
+       return rc;
+}
+
+int
+monitor_subsys_database_init(
+       BackendDB               *be,
+       monitor_subsys_t        *ms )
+{
+       monitor_info_t          *mi;
+       Entry                   *e_database, **ep;
+       int                     i, rc;
+       monitor_entry_t         *mp;
+       monitor_subsys_t        *ms_backend,
+                               *ms_overlay;
+       struct berval           bv;
 
-               if ( oi != NULL ) {
-                       Entry           **ep_overlay = &mp->mp_children;
-                       monitor_entry_t *mp_overlay;
-                       slap_overinst   *on = oi->oi_list;
-                       int             o;
+       assert( be != NULL );
 
-                       for ( o = 0; on; o++, on = on->on_next ) {
-                               Entry                   *e_overlay;
-                               slap_overinst           *on2;
+       ms->mss_modify = monitor_subsys_database_modify;
 
-                               /* find the overlay number, j */
-                               for ( on2 = overlay_next( NULL ), j = 0; on2; on2 = overlay_next( on2 ), j++ ) {
-                                       if ( on2->on_bi.bi_type == on->on_bi.bi_type ) {
-                                               break;
-                                       }
-                               }
-                               assert( on2 != NULL );
+       mi = ( monitor_info_t * )be->be_private;
+
+       ms_backend = monitor_back_get_subsys( SLAPD_MONITOR_BACKEND_NAME );
+       if ( ms_backend == NULL ) {
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_subsys_database_init: "
+                       "unable to get "
+                       "\"" SLAPD_MONITOR_BACKEND_NAME "\" "
+                       "subsystem\n",
+                       0, 0, 0 );
+               return -1;
+       }
+
+       ms_overlay = monitor_back_get_subsys( SLAPD_MONITOR_OVERLAY_NAME );
+       if ( ms_overlay == NULL ) {
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_subsys_database_init: "
+                       "unable to get "
+                       "\"" SLAPD_MONITOR_OVERLAY_NAME "\" "
+                       "subsystem\n",
+                       0, 0, 0 );
+               return -1;
+       }
 
-                               bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Overlay %d", o );
-                               bv.bv_val = buf;
+       if ( monitor_cache_get( mi, &ms->mss_ndn, &e_database ) ) {
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_subsys_database_init: "
+                       "unable to get entry \"%s\"\n",
+                       ms->mss_ndn.bv_val, 0, 0 );
+               return( -1 );
+       }
 
-                               e_overlay = monitor_entry_stub( &e->e_name, &e->e_nname, &bv,
-                                       mi->mi_oc_monitoredObject, mi, NULL, NULL );
+       (void)init_readOnly( mi, e_database, frontendDB->be_restrictops );
+       (void)init_restrictedOperation( mi, e_database, frontendDB->be_restrictops );
 
-                               if ( e_overlay == NULL ) {
-                                       Debug( LDAP_DEBUG_ANY,
-                                               "monitor_subsys_database_init: "
-                                               "unable to create entry "
-                                               "\"cn=Overlay %d,cn=Database %d,%s\"\n",
-                                               o, i, ms->mss_dn.bv_val );
-                                       return( -1 );
-                               }
-                               ber_str2bv( on->on_bi.bi_type, 0, 0, &bv );
-                               attr_merge_one( e_overlay, mi->mi_ad_monitoredInfo, &bv, NULL );
+       mp = ( monitor_entry_t * )e_database->e_private;
+       mp->mp_children = NULL;
+       ep = &mp->mp_children;
 
-                               bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Overlay %d,%s",
-                                       j, ms_overlay->mss_dn.bv_val );
-                               bv.bv_val = buf;
-                               attr_merge_normalize_one( e_overlay, slap_schema.si_ad_seeAlso,
-                                       &bv, NULL );
+       BER_BVSTR( &bv, "cn=Frontend" );
+       rc = monitor_subsys_database_init_one( mi, frontendDB,
+               ms, ms_backend, ms_overlay, &bv, e_database, &ep );
+       if ( rc != 0 ) {
+               return rc;
+       }
 
-                               mp_overlay = monitor_entrypriv_create();
-                               if ( mp_overlay == NULL ) {
-                                       return -1;
-                               }
-                               e_overlay->e_private = ( void * )mp_overlay;
-                               mp_overlay->mp_info = ms;
-                               mp_overlay->mp_flags = ms->mss_flags
-                                       | MONITOR_F_SUB;
-               
-                               if ( monitor_cache_add( mi, e_overlay ) ) {
-                                       Debug( LDAP_DEBUG_ANY,
-                                               "monitor_subsys_database_init: "
-                                               "unable to add entry "
-                                               "\"cn=Overlay %d,cn=Database %d,%s\"\n",
-                                               o, i, ms->mss_dn.bv_val );
-                                       return( -1 );
-                               }
+       i = -1;
+       LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
+               char            buf[ BACKMONITOR_BUFSIZE ];
 
-                               *ep_overlay = e_overlay;
-                               ep_overlay = &mp_overlay->mp_next;
-                       }
+               bv.bv_val = buf;
+               bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Database %d", ++i );
+               if ( bv.bv_len >= sizeof( buf ) ) {
+                       return -1;
+               }
+               
+               rc = monitor_subsys_database_init_one( mi, be,
+                       ms, ms_backend, ms_overlay, &bv, e_database, &ep );
+               if ( rc != 0 ) {
+                       return rc;
                }
-
-               *ep = e;
-               ep = &mp->mp_next;
        }
        
        monitor_cache_release( mi, e_database );