]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-monitor/init.c
fix NOOP return code (ITS#4563; I'll check and confirm it later; NOOP support might...
[openldap] / servers / slapd / back-monitor / init.c
index 5292bc85b61c5205e7db09ba6e73df5f18fcbf84..264b70c5c7ebeaddb433fa30b15d6b6d955bb8c4 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.
  *
@@ -860,7 +860,7 @@ monitor_back_register_entry_attrs(
 
 done:;
                if ( rc ) {
-                       if ( *atp ) {
+                       if ( atp && *atp ) {
                                attrs_free( *atp );
                                *atp = NULL;
                        }
@@ -1285,6 +1285,7 @@ monitor_back_initialize(
                }
 
                if ( at->at_oid == NULL ) {
+                       ldap_attributetype_free(at);
                        Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
                                "null OID for attributeType \"%s\"\n",
                                mat[ i ].name, 0, 0 );
@@ -1293,6 +1294,7 @@ monitor_back_initialize(
 
                code = at_add(at, 0, NULL, &err);
                if ( code ) {
+                       ldap_attributetype_free(at);
                        Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
                                "%s in attributeType \"%s\"\n",
                                scherr2str(code), mat[ i ].name, 0 );
@@ -1328,6 +1330,7 @@ monitor_back_initialize(
                }
 
                if ( oc->oc_oid == NULL ) {
+                       ldap_objectclass_free(oc);
                        Debug( LDAP_DEBUG_ANY,
                                "objectclass \"%s\" has no OID\n" ,
                                moc[ i ].name, 0, 0 );
@@ -1336,12 +1339,12 @@ monitor_back_initialize(
 
                code = oc_add(oc, 0, NULL, &err);
                if ( code ) {
+                       ldap_objectclass_free(oc);
                        Debug( LDAP_DEBUG_ANY,
                                "objectclass \"%s\": %s \"%s\"\n" ,
                                moc[ i ].name, scherr2str(code), err );
                        return -1;
                }
-
                ldap_memfree(oc);
 
                Oc = oc_find( moc[ i ].name );
@@ -1496,16 +1499,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 ) {
@@ -1542,35 +1550,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"
-               " attributes, 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",
@@ -1578,6 +1569,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;
@@ -1623,6 +1616,7 @@ monitor_back_db_open(
                        SLAPD_MONITOR_DN, 0, 0 );
                return -1;
        }
+       root = e;
 
        /*      
         * Create all the subsystem specific entries
@@ -1645,46 +1639,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,
@@ -1860,14 +1826,6 @@ monitor_back_db_destroy(
                        if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_rdn ) ) {
                                ch_free( monitor_subsys[ i ]->mss_rdn.bv_val );
                        }
-
-                       if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_dn ) ) {
-                               ch_free( monitor_subsys[ i ]->mss_dn.bv_val );
-                       }
-
-                       if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_ndn ) ) {
-                               ch_free( monitor_subsys[ i ]->mss_ndn.bv_val );
-                       }
                }
 
                ch_free( monitor_subsys );