]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-monitor/init.c
Reworked recent backend API changes, now using a separate struct,
[openldap] / servers / slapd / back-monitor / init.c
index b37a21b43f211d6d311d8667f8e7e7201383baf7..951a28631f7dc73a178533546779c725762ba606 100644 (file)
@@ -52,6 +52,10 @@ static const monitor_extra_t monitor_extra = {
        monitor_back_get_subsys_by_dn,
 
        monitor_back_register_subsys,
+       monitor_back_register_backend,
+       monitor_back_register_database,
+       monitor_back_register_overlay_info,
+       monitor_back_register_overlay,
        monitor_back_register_entry,
        monitor_back_register_entry_parent,
        monitor_back_register_entry_attrs,
@@ -221,6 +225,12 @@ static struct monitor_subsys_t known_monitor_subsys[] = {
                }, { NULL }
 };
 
+int
+monitor_subsys_is_opened( void )
+{
+       return monitor_subsys_opened;
+}
+
 int
 monitor_back_register_subsys(
        monitor_subsys_t        *ms )
@@ -245,7 +255,7 @@ monitor_back_register_subsys(
        /* if a subsystem is registered __AFTER__ subsystem 
         * initialization (depending on the sequence the databases
         * are listed in slapd.conf), init it */
-       if ( monitor_subsys_opened ) {
+       if ( monitor_subsys_is_opened() ) {
 
                /* FIXME: this should only be possible
                 * if be_monitor is already initialized */
@@ -265,11 +275,20 @@ enum {
        LIMBO_ENTRY,
        LIMBO_ENTRY_PARENT,
        LIMBO_ATTRS,
-       LIMBO_CB
+       LIMBO_CB,
+       LIMBO_BACKEND,
+       LIMBO_DATABASE,
+       LIMBO_OVERLAY_INFO,
+       LIMBO_OVERLAY,
+
+       LIMBO_LAST
 };
 
 typedef struct entry_limbo_t {
        int                     el_type;
+       BackendInfo             *el_bi;
+       BackendDB               *el_be;
+       slap_overinst           *el_on;
        Entry                   *el_e;
        Attribute               *el_a;
        struct berval           el_ndn;
@@ -288,6 +307,83 @@ monitor_back_is_configured( void )
        return be_monitor != NULL;
 }
 
+int
+monitor_back_register_backend(
+       BackendInfo             *bi )
+{
+       return -1;
+}
+
+int
+monitor_back_register_overlay_info(
+       slap_overinst           *on )
+{
+       return -1;
+}
+
+int
+monitor_back_register_overlay(
+       BackendDB               *be )
+{
+       return -1;
+}
+
+int
+monitor_back_register_backend_limbo(
+       BackendInfo             *bi )
+{
+       return -1;
+}
+
+int
+monitor_back_register_database_limbo(
+       BackendDB               *be )
+{
+       entry_limbo_t   **elpp, el = { 0 };
+       monitor_info_t  *mi;
+
+       if ( be_monitor == NULL ) {
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_back_register_database_limbo: "
+                       "monitor database not configured.\n",
+                       0, 0, 0 );
+               return -1;
+       }
+
+       mi = ( monitor_info_t * )be_monitor->be_private;
+
+
+       el.el_type = LIMBO_DATABASE;
+
+       el.el_be = be;
+       
+       for ( elpp = &mi->mi_entry_limbo;
+                       *elpp;
+                       elpp = &(*elpp)->el_next )
+               /* go to last */;
+
+       *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
+
+       el.el_next = NULL;
+       **elpp = el;
+
+       return 0;
+}
+
+int
+monitor_back_register_overlay_info_limbo(
+       slap_overinst           *on )
+{
+       return -1;
+}
+
+int
+monitor_back_register_overlay_limbo(
+       BackendDB               *be )
+{
+       return -1;
+}
+
 int
 monitor_back_register_entry(
        Entry                   *e,
@@ -311,7 +407,7 @@ monitor_back_register_entry(
        assert( e != NULL );
        assert( e->e_private == NULL );
        
-       if ( monitor_subsys_opened ) {
+       if ( monitor_subsys_is_opened() ) {
                Entry           *e_parent = NULL,
                                *e_new = NULL,
                                **ep = NULL;
@@ -433,7 +529,7 @@ done:;
                el.el_mss = mss;
                el.el_flags = flags;
 
-               for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
+               for ( elpp = &mi->mi_entry_limbo;
                                *elpp;
                                elpp = &(*elpp)->el_next )
                        /* go to last */;
@@ -490,7 +586,7 @@ monitor_back_register_entry_parent(
                return -1;
        }
 
-       if ( monitor_subsys_opened ) {
+       if ( monitor_subsys_is_opened() ) {
                Entry           *e_parent = NULL,
                                *e_new = NULL,
                                **ep = NULL;
@@ -647,7 +743,7 @@ done:;
                el.el_mss = mss;
                el.el_flags = flags;
 
-               for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
+               for ( elpp = &mi->mi_entry_limbo;
                                *elpp;
                                elpp = &(*elpp)->el_next )
                        /* go to last */;
@@ -717,12 +813,18 @@ monitor_search2ndn(
                return -1;
        }
 
-       op = (Operation *) &opbuf;
        thrctx = ldap_pvt_thread_pool_context();
-       connection_fake_init( &conn, op, thrctx );
+       connection_fake_init( &conn, &opbuf, thrctx );
+       op = &opbuf.ob_op;
 
        op->o_tag = LDAP_REQ_SEARCH;
 
+       /* use global malloc for now */
+       if ( op->o_tmpmemctx ) {
+               op->o_tmpmemctx = NULL;
+       }
+       op->o_tmpmfuncs = &ch_mfuncs;
+
        op->o_bd = be_monitor;
        if ( nbase == NULL || BER_BVISNULL( nbase ) ) {
                ber_dupbv_x( &op->o_req_dn, &op->o_bd->be_suffix[ 0 ],
@@ -769,12 +871,12 @@ cleanup:;
        if ( !BER_BVISNULL( &op->ors_filterstr ) ) {
                op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
        }
-       if ( !BER_BVISNULL( &op->o_req_ndn ) ) {
-               op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
-       }
        if ( !BER_BVISNULL( &op->o_req_dn ) ) {
                op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
        }
+       if ( !BER_BVISNULL( &op->o_req_ndn ) ) {
+               op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
+       }
 
        if ( rc != 0 ) {
                return rc;
@@ -852,7 +954,7 @@ monitor_back_register_entry_attrs(
                return -1;
        }
 
-       if ( monitor_subsys_opened ) {
+       if ( monitor_subsys_is_opened() ) {
                Entry                   *e = NULL;
                Attribute               **atp = NULL;
                monitor_entry_t         *mp = NULL;
@@ -974,7 +1076,7 @@ done:;
                el.el_a = attrs_dup( a );
                el.el_cb = cb;
 
-               for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
+               for ( elpp = &mi->mi_entry_limbo;
                                *elpp;
                                elpp = &(*elpp)->el_next )
                        /* go to last */;
@@ -1052,7 +1154,7 @@ monitor_back_unregister_entry(
 
        assert( mi != NULL );
 
-       if ( monitor_subsys_opened ) {
+       if ( monitor_subsys_is_opened() ) {
                Entry                   *e = NULL;
                monitor_entry_t         *mp = NULL;
                monitor_callback_t      *cb = NULL;
@@ -1087,7 +1189,7 @@ monitor_back_unregister_entry(
        } else {
                entry_limbo_t   **elpp;
 
-               for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
+               for ( elpp = &mi->mi_entry_limbo;
                        *elpp;
                        elpp = &(*elpp)->el_next )
                {
@@ -1165,7 +1267,7 @@ monitor_back_unregister_entry_parent(
                return -1;
        }
 
-       if ( monitor_subsys_opened ) {
+       if ( monitor_subsys_is_opened() ) {
                Entry                   *e = NULL;
                monitor_entry_t         *mp = NULL;
 
@@ -1218,7 +1320,7 @@ monitor_back_unregister_entry_parent(
        } else {
                entry_limbo_t   **elpp;
 
-               for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
+               for ( elpp = &mi->mi_entry_limbo;
                        *elpp;
                        elpp = &(*elpp)->el_next )
                {
@@ -1320,7 +1422,7 @@ monitor_back_unregister_entry_attrs(
                return -1;
        }
 
-       if ( monitor_subsys_opened ) {
+       if ( monitor_subsys_is_opened() ) {
                Entry                   *e = NULL;
                monitor_entry_t         *mp = NULL;
                int                     freeit = 0;
@@ -1394,14 +1496,12 @@ monitor_back_unregister_entry_attrs(
                        ber_memfree( ndn.bv_val );
                }
 
-               if ( e ) {
-                       monitor_cache_release( mi, e );
-               }
+               monitor_cache_release( mi, e );
 
        } else {
                entry_limbo_t   **elpp;
 
-               for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
+               for ( elpp = &mi->mi_entry_limbo;
                        *elpp;
                        elpp = &(*elpp)->el_next )
                {
@@ -1950,7 +2050,8 @@ monitor_back_initialize(
 
 int
 monitor_back_db_init(
-       BackendDB       *be )
+       BackendDB       *be,
+       ConfigReply     *c)
 {
        int                     rc;
        struct berval           dn = BER_BVC( SLAPD_MONITOR_DN ),
@@ -1961,23 +2062,24 @@ monitor_back_db_init(
        monitor_subsys_t        *ms;
 
        /*
-        * register subsys
+        * database monitor can be defined once only
         */
-       for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
-               if ( monitor_back_register_subsys( ms ) ) {
-                       return -1;
+       if ( be_monitor != NULL ) {
+               if (c) {
+                       snprintf(c->msg, sizeof(c->msg),"only one monitor database allowed");
                }
+               return( -1 );
        }
+       be_monitor = be;
 
        /*
-        * database monitor can be defined once only
+        * register subsys
         */
-       if ( be_monitor != NULL ) {
-               Debug( LDAP_DEBUG_ANY,
-                       "only one monitor database is allowed\n", 0, 0, 0 );
-               return( -1 );
+       for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
+               if ( monitor_back_register_subsys( ms ) ) {
+                       return -1;
+               }
        }
-       be_monitor = be;
 
        /* indicate system schema supported */
        SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR;
@@ -1999,7 +2101,7 @@ monitor_back_db_init(
 
        be->be_private = &monitor_info;
 
-       be2 = select_backend( &ndn, 0, 0 );
+       be2 = select_backend( &ndn, 0 );
        if ( be2 != be ) {
                char    *type = be2->bd_info->bi_type;
 
@@ -2008,10 +2110,12 @@ monitor_back_db_init(
                        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 );
+               if (c) {
+                       snprintf(c->msg, sizeof(c->msg),
+                                       "\"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;
        }
 
@@ -2020,7 +2124,8 @@ monitor_back_db_init(
 
 int
 monitor_back_db_open(
-       BackendDB       *be )
+       BackendDB       *be,
+       ConfigReply     *cr)
 {
        monitor_info_t          *mi = (monitor_info_t *)be->be_private;
        struct monitor_subsys_t **ms;
@@ -2040,6 +2145,8 @@ monitor_back_db_open(
                " attributes, which must be explicitly requested."),
                BER_BVNULL };
 
+       int                     retcode = 0;
+
        assert( be_monitor != NULL );
        if ( be != be_monitor ) {
                be_monitor = be;
@@ -2219,7 +2326,7 @@ monitor_back_db_open(
        monitor_subsys_opened = 1;
 
        if ( mi->mi_entry_limbo ) {
-               entry_limbo_t   *el = (entry_limbo_t *)mi->mi_entry_limbo;
+               entry_limbo_t   *el = mi->mi_entry_limbo;
 
                for ( ; el; ) {
                        entry_limbo_t   *tmp;
@@ -2265,6 +2372,22 @@ monitor_back_db_open(
                                                &el->el_filter );
                                break;
 
+                       case LIMBO_BACKEND:
+                               rc = monitor_back_register_backend( el->el_bi );
+                               break;
+
+                       case LIMBO_DATABASE:
+                               rc = monitor_back_register_database( el->el_be );
+                               break;
+
+                       case LIMBO_OVERLAY_INFO:
+                               rc = monitor_back_register_overlay_info( el->el_on );
+                               break;
+
+                       case LIMBO_OVERLAY:
+                               rc = monitor_back_register_overlay( el->el_be );
+                               break;
+
                        default:
                                assert( 0 );
                        }
@@ -2294,12 +2417,17 @@ monitor_back_db_open(
                        tmp = el;
                        el = el->el_next;
                        ch_free( tmp );
+
+                       if ( rc != 0 ) {
+                               /* try all, but report error at end */
+                               retcode = 1;
+                       }
                }
 
                mi->mi_entry_limbo = NULL;
        }
 
-       return( 0 );
+       return retcode;
 }
 
 int
@@ -2336,7 +2464,8 @@ monitor_back_db_config(
 
 int
 monitor_back_db_destroy(
-       BackendDB       *be )
+       BackendDB       *be,
+       ConfigReply     *cr)
 {
        monitor_info_t  *mi = ( monitor_info_t * )be->be_private;