]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-monitor/database.c
address ITS#4332; might remove dynamicObject counting
[openldap] / servers / slapd / back-monitor / database.c
index 267042d8ee21a16cf2dda0fbb8951efa09ccc5fb..a5485577e6d2be974bd523034db1c403d0c0f1ed 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.
  *
@@ -45,6 +45,9 @@ static int monitor_back_add_plugin( monitor_info_t *mi, Backend *be, Entry *e );
 #if 0 && defined(SLAPD_LDBM) 
 #include "../back-ldbm/back-ldbm.h"
 #endif /* defined(SLAPD_LDBM) */
+#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
@@ -54,6 +57,12 @@ static int monitor_back_add_plugin( monitor_info_t *mi, Backend *be, Entry *e );
 #define PATH_MAX       4095
 #endif /* ! PATH_MAX */
 
+static int
+monitor_subsys_database_modify(
+       Operation       *op,
+       SlapReply       *rs,
+       Entry           *e );
+
 static struct restricted_ops_t {
        struct berval   op;
        unsigned int    tag;
@@ -129,6 +138,8 @@ monitor_subsys_database_init(
 
        assert( be != NULL );
 
+       ms->mss_modify = monitor_subsys_database_modify;
+
        mi = ( monitor_info_t * )be->be_private;
 
        ms_backend = monitor_back_get_subsys( SLAPD_MONITOR_BACKEND_NAME );
@@ -175,6 +186,7 @@ monitor_subsys_database_init(
                slap_overinfo   *oi = NULL;
                BackendInfo     *bi, *bi2;
                Entry           *e;
+               struct berval bv;
 
                i++;
 
@@ -190,32 +202,12 @@ monitor_subsys_database_init(
                        continue;
                }
 
-               snprintf( buf, sizeof( buf ),
-                               "dn: cn=Database %d,%s\n"
-                               "objectClass: %s\n"
-                               "structuralObjectClass: %s\n"
-                               "cn: Database %d\n"
-                               "%s: %s\n"
-                               "%s: %s\n"
-                               "creatorsName: %s\n"
-                               "modifiersName: %s\n"
-                               "createTimestamp: %s\n"
-                               "modifyTimestamp: %s\n",
-                               i,
-                                       ms->mss_dn.bv_val,
-                               mi->mi_oc_monitoredObject->soc_cname.bv_val,
-                               mi->mi_oc_monitoredObject->soc_cname.bv_val,
-                               i,
-                               mi->mi_ad_monitoredInfo->ad_cname.bv_val,
-                                       bi->bi_type,
-                               mi->mi_ad_monitorIsShadow->ad_cname.bv_val,
-                                       SLAP_SHADOW( be ) ? slap_true_bv.bv_val : slap_false_bv.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 );
+               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 ( e == NULL ) {
                        Debug( LDAP_DEBUG_ANY,
                                "monitor_subsys_database_init: "
@@ -223,7 +215,13 @@ monitor_subsys_database_init(
                                i, ms->mss_dn.bv_val, 0 );
                        return( -1 );
                }
-               
+
+               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 );
+
                if ( SLAP_MONITOR( be ) ) {
                        attr_merge( e, slap_schema.si_ad_monitorContext,
                                        be->be_suffix, be->be_nsuffix );
@@ -247,6 +245,11 @@ monitor_subsys_database_init(
                (void)init_readOnly( mi, e, be->be_restrictops );
                (void)init_restrictedOperation( mi, e, be->be_restrictops );
 
+               if ( SLAP_SHADOW( be ) && be->be_update_refs ) {
+                       attr_merge_normalize( e, mi->mi_ad_monitorUpdateRef,
+                                       be->be_update_refs, NULL );
+               }
+
                if ( oi != NULL ) {
                        slap_overinst   *on = oi->oi_list,
                                        *on1 = on;
@@ -275,7 +278,7 @@ monitor_subsys_database_init(
                                                break;
                                        }
                                }
-                               assert( on2 );
+                               assert( on2 != NULL );
 
                                snprintf( buf, sizeof( buf ), 
                                        "cn=Overlay %d,%s", 
@@ -287,34 +290,19 @@ monitor_subsys_database_init(
                        }
                }
 
+
+               if ( 0 ) {
+                       assert( 0 );
+
 #if defined(SLAPD_BDB) || defined(SLAPD_HDB) 
-               if ( strcmp( bi->bi_type, "bdb" ) == 0
+               } 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' };
-                       char            *fname = NULL;
-
-                       if ( strcmp( bi->bi_type, "bdb" ) == 0
-                                       || strcmp( bi->bi_type, "hdb" ) == 0 )
-                       {
-                               struct bdb_info *bdb = (struct bdb_info *) be->be_private;
-
-                               fname = bdb->bi_dbenv_home;
-#if 0
-                       } else if ( strcmp( bi->bi_type, "ldbm" ) == 0 ) {
-                               struct ldbminfo *ldbm = (struct ldbminfo *) be->be_private;
-
-                               /* FIXME: there's a conflict
-                                * between back-bdb.h and back.ldbm.h;
-                                * anyway, this code will be moved
-                                * to the backends as soon as the
-                                * issue with filtering on namingContexts
-                                * is fixed */
-                               fname = ldbm->li_directory;
-#endif
-                       }
+                       struct bdb_info *bdb = (struct bdb_info *) be->be_private;
+                       char            *fname = bdb->bi_dbenv_home;
 
                        len = strlen( fname );
                        if ( fname[ 0 ] != '/' ) {
@@ -350,22 +338,60 @@ monitor_subsys_database_init(
                                        &bv, NULL );
 
                        ch_free( bv.bv_val );
-               }
-#endif /* defined(SLAPD_LDAP) || defined(SLAPD_HDB) */
 
+#endif /* defined(SLAPD_BDB) || defined(SLAPD_HDB) */
 #if defined(SLAPD_LDAP) 
-               if ( strcmp( bi->bi_type, "ldap" ) == 0 ) {
-                       struct ldapinfo         *li =
-                               (struct ldapinfo *)be->be_private;
-                       struct berval           bv;
+               } 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, " " );
 
-                       ber_str2bv( li->url, 0, 0, &bv );
+                       if ( urls != NULL ) {
+                               int             u;
+
+                               for ( u = 0; urls[ u ] != NULL; u++ ) {
+                                       struct berval   bv;
+
+                                       ber_str2bv( urls[ u ], 0, 0, &bv );
+
+                                       attr_merge_normalize_one( e,
+                                               slap_schema.si_ad_labeledURI,
+                                               &bv, NULL );
+                               }
+
+                               ldap_charray_free( urls );
+                       }
+#endif
 
-                       attr_merge_normalize_one( e,
-                                       slap_schema.si_ad_labeledURI,
-                                       &bv, NULL );
-               }
 #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;
+
+                       for ( t = 0; t < mi->mi_ntargets; t++ ) {
+                               char            **urls = ldap_str2charray( mi->mi_targets[ t ].mt_uri, " " );
+
+                               if ( urls != NULL ) {
+                                       int             u;
+
+                                       for ( u = 0; urls[ u ] != NULL; u++ ) {
+                                               struct berval   bv;
+
+                                               ber_str2bv( urls[ u ], 0, 0, &bv );
+
+                                               attr_merge_normalize_one( e,
+                                                       slap_schema.si_ad_labeledURI,
+                                                       &bv, NULL );
+                                       }
+                                       ldap_charray_free( urls );
+                               }
+                       }
+#endif /* defined(SLAPD_META) */
+               }
 
                j = -1;
                LDAP_STAILQ_FOREACH( bi2, &backendInfo, bi_next ) {
@@ -424,35 +450,14 @@ monitor_subsys_database_init(
                                                break;
                                        }
                                }
-                               assert( on2 );
-
-                               snprintf( buf, sizeof( buf ),
-                                               "dn: cn=Overlay %d,cn=Database %d,%s\n"
-                                               "objectClass: %s\n"
-                                               "structuralObjectClass: %s\n"
-                                               "cn: Overlay %d\n"
-                                               "%s: %s\n"
-                                               "seeAlso: cn=Overlay %d,%s\n"
-                                               "creatorsName: %s\n"
-                                               "modifiersName: %s\n"
-                                               "createTimestamp: %s\n"
-                                               "modifyTimestamp: %s\n",
-                                               o,
-                                               i,
-                                               ms->mss_dn.bv_val,
-                                               mi->mi_oc_monitoredObject->soc_cname.bv_val,
-                                               mi->mi_oc_monitoredObject->soc_cname.bv_val,
-                                               o,
-                                               mi->mi_ad_monitoredInfo->ad_cname.bv_val,
-                                               on->on_bi.bi_type,
-                                               j,
-                                               ms_overlay->mss_dn.bv_val,
-                                               mi->mi_creatorsName.bv_val,
-                                               mi->mi_creatorsName.bv_val,
-                                               mi->mi_startTime.bv_val,
-                                               mi->mi_startTime.bv_val );
-                               
-                               e_overlay = str2entry( buf );
+                               assert( on2 != NULL );
+
+                               bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Overlay %d", o );
+                               bv.bv_val = buf;
+
+                               e_overlay = monitor_entry_stub( &e->e_name, &e->e_nname, &bv,
+                                       mi->mi_oc_monitoredObject, mi, NULL, NULL );
+
                                if ( e_overlay == NULL ) {
                                        Debug( LDAP_DEBUG_ANY,
                                                "monitor_subsys_database_init: "
@@ -461,6 +466,14 @@ monitor_subsys_database_init(
                                                o, i, ms->mss_dn.bv_val );
                                        return( -1 );
                                }
+                               ber_str2bv( on->on_bi.bi_type, 0, 0, &bv );
+                               attr_merge_one( e, mi->mi_ad_monitoredInfo, &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, slap_schema.si_ad_seeAlso,
+                                       &bv, NULL );
 
                                mp_overlay = monitor_entrypriv_create();
                                if ( mp_overlay == NULL ) {
@@ -540,12 +553,11 @@ value_mask( BerVarray v, slap_mask_t cur, slap_mask_t *delta )
        return LDAP_SUCCESS;
 }
 
-int
+static int
 monitor_subsys_database_modify(
        Operation       *op,
        SlapReply       *rs,
-       Entry           *e
-)
+       Entry           *e )
 {
        monitor_info_t  *mi = (monitor_info_t *)op->o_bd->be_private;
        int             rc = LDAP_OTHER;