]> git.sur5r.net Git - openldap/commitdiff
Disable databases & overlays (experimental)
authorHoward Chu <hyc@openldap.org>
Tue, 28 May 2013 20:09:44 +0000 (13:09 -0700)
committerHoward Chu <hyc@openldap.org>
Tue, 28 May 2013 20:09:44 +0000 (13:09 -0700)
Do not use. backend/overlay code needs to be fixed accordingly.
In particular, code which currently frees configuration in _db_close()
must be changed to free only in _db_destroy().

After restructuring, it must be possible to call _db_close()/_db_open()
multiple times in succession without requiring _db_config() in between.

servers/slapd/backend.c
servers/slapd/backover.c
servers/slapd/bconfig.c
servers/slapd/slap.h

index de82ffa493b30186af82b9303d41d8175252f0cd..2893b92dfcb8d1880ab01afce910279450d37eac 100644 (file)
@@ -264,6 +264,9 @@ int backend_startup(Backend *be)
        }
 
        if(be != NULL) {
+               /* silent noop if disabled */
+               if ( SLAP_DBDISABLED( be ))
+                       return 0;
                if ( be->bd_info->bi_open ) {
                        rc = be->bd_info->bi_open( be->bd_info );
                        if ( rc != 0 ) {
@@ -315,6 +318,8 @@ int backend_startup(Backend *be)
        i = -1;
        LDAP_STAILQ_FOREACH(be, &backendDB, be_next) {
                i++;
+               if ( SLAP_DBDISABLED( be ))
+                       continue;
                if ( be->be_suffix == NULL ) {
                        Debug( LDAP_DEBUG_ANY,
                                "backend_startup: warning, database %d (%s) "
@@ -372,6 +377,8 @@ int backend_shutdown( Backend *be )
 
        /* close each backend database */
        LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
+               if ( SLAP_DBDISABLED( be ))
+                       continue;
                if ( be->bd_info->bi_db_close ) {
                        be->bd_info->bi_db_close( be, NULL );
                }
@@ -666,7 +673,7 @@ select_backend(
        Backend         *be;
 
        LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
-               if ( be->be_nsuffix == NULL || SLAP_DBHIDDEN( be )) {
+               if ( be->be_nsuffix == NULL || SLAP_DBHIDDEN( be ) || SLAP_DBDISABLED( be )) {
                        continue;
                }
 
index 2109d429c26871de5c6316fe36a330e5eca995f6..02dc5125cbba412a0a532b6bbd6138b30a392d75 100644 (file)
@@ -150,6 +150,8 @@ over_db_open(
        }
 
        for (; on && rc == 0; on=on->on_next) {
+               if ( on->on_bi.bi_flags & SLAPO_BFLAG_DISABLED )
+                       continue;
                db.bd_info = &on->on_bi;
                if ( db.bd_info->bi_db_open ) {
                        rc = db.bd_info->bi_db_open( &db, cr );
@@ -171,6 +173,8 @@ over_db_close(
        int rc = 0;
 
        for (; on && rc == 0; on=on->on_next) {
+               if ( on->on_bi.bi_flags & SLAPO_BFLAG_DISABLED )
+                       continue;
                be->bd_info = &on->on_bi;
                if ( be->bd_info->bi_db_close ) {
                        rc = be->bd_info->bi_db_close( be, cr );
@@ -203,6 +207,8 @@ over_db_destroy(
        }
 
        for (; on && rc == 0; on=on->on_next) {
+               if ( on->on_bi.bi_flags & SLAPO_BFLAG_DISABLED )
+                       continue;
                be->bd_info = &on->on_bi;
                if ( be->bd_info->bi_db_destroy ) {
                        rc = be->bd_info->bi_db_destroy( be, cr );
@@ -232,6 +238,8 @@ over_back_response ( Operation *op, SlapReply *rs )
        db.be_flags |= SLAP_DBFLAG_OVERLAY;
        op->o_bd = &db;
        for (; on; on=on->on_next ) {
+               if ( on->on_bi.bi_flags & SLAPO_BFLAG_DISABLED )
+                       continue;
                if ( on->on_response ) {
                        db.bd_info = (BackendInfo *)on;
                        rc = on->on_response( op, rs );
@@ -277,6 +285,8 @@ over_access_allowed(
        on = oi->oi_list;
 
        for ( ; on; on = on->on_next ) {
+               if ( on->on_bi.bi_flags & SLAPO_BFLAG_DISABLED )
+                       continue;
                if ( on->on_bi.bi_access_allowed ) {
                        /* NOTE: do not copy the structure until required */
                        if ( !SLAP_ISOVERLAY( op->o_bd ) ) {
@@ -338,6 +348,8 @@ overlay_entry_get_ov(
        int rc = SLAP_CB_CONTINUE;
 
        for ( ; on; on = on->on_next ) {
+               if ( on->on_bi.bi_flags & SLAPO_BFLAG_DISABLED )
+                       continue;
                if ( on->on_bi.bi_entry_get_rw ) {
                        /* NOTE: do not copy the structure until required */
                        if ( !SLAP_ISOVERLAY( op->o_bd ) ) {
@@ -409,6 +421,8 @@ overlay_entry_release_ov(
        int rc = SLAP_CB_CONTINUE;
 
        for ( ; on; on = on->on_next ) {
+               if ( on->on_bi.bi_flags & SLAPO_BFLAG_DISABLED )
+                       continue;
                if ( on->on_bi.bi_entry_release_rw ) {
                        /* NOTE: do not copy the structure until required */
                        if ( !SLAP_ISOVERLAY( op->o_bd ) ) {
@@ -487,6 +501,8 @@ over_acl_group(
        on = oi->oi_list;
 
        for ( ; on; on = on->on_next ) {
+               if ( on->on_bi.bi_flags & SLAPO_BFLAG_DISABLED )
+                       continue;
                if ( on->on_bi.bi_acl_group ) {
                        /* NOTE: do not copy the structure until required */
                        if ( !SLAP_ISOVERLAY( op->o_bd ) ) {
@@ -556,6 +572,8 @@ over_acl_attribute(
        on = oi->oi_list;
 
        for ( ; on; on = on->on_next ) {
+               if ( on->on_bi.bi_flags & SLAPO_BFLAG_DISABLED )
+                       continue;
                if ( on->on_bi.bi_acl_attribute ) {
                        /* NOTE: do not copy the structure until required */
                        if ( !SLAP_ISOVERLAY( op->o_bd ) ) {
@@ -655,6 +673,8 @@ int overlay_op_walk(
        int rc = SLAP_CB_CONTINUE;
 
        for (; on; on=on->on_next ) {
+               if ( on->on_bi.bi_flags & SLAPO_BFLAG_DISABLED )
+                       continue;
                func = &on->on_bi.bi_op_bind;
                if ( func[which] ) {
                        op->o_bd->bd_info = (BackendInfo *)on;
@@ -849,6 +869,8 @@ over_connection_func(
        }
 
        for ( ; on; on = on->on_next ) {
+               if ( on->on_bi.bi_flags & SLAPO_BFLAG_DISABLED )
+                       continue;
                func = &on->on_bi.bi_connection_init;
                if ( func[ which ] ) {
                        bd->bd_info = (BackendInfo *)on;
index 38d4bbea42a40c0589670992a7d9184738006740..4e1f1b531f788e6e39f5a3d055f315161bd3ef27 100644 (file)
@@ -197,6 +197,7 @@ enum {
        CFG_SYNC_SUBENTRY,
        CFG_LTHREADS,
        CFG_IX_HASH64,
+       CFG_DISABLED,
 
        CFG_LAST
 };
@@ -364,6 +365,9 @@ static ConfigTable config_back_cf_table[] = {
        { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
                &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
                        "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
+       { "disabled", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_DISABLED,
+               &config_generic, "( OLcfgDbAt:0.21 NAME 'olcDisabled' "
+                       "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
        { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
                &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
                        "EQUALITY caseIgnoreMatch "
@@ -865,7 +869,7 @@ static ConfigOCs cf_ocs[] = {
                "DESC 'OpenLDAP Database-specific options' "
                "SUP olcConfig STRUCTURAL "
                "MUST olcDatabase "
-               "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
+               "MAY ( olcDisabled $ olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
                 "olcAddContentAcl $ olcLastMod $ olcLimits $ "
                 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
                 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
@@ -878,7 +882,8 @@ static ConfigOCs cf_ocs[] = {
                "NAME 'olcOverlayConfig' "
                "DESC 'OpenLDAP Overlay-specific options' "
                "SUP olcConfig STRUCTURAL "
-               "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
+               "MUST olcOverlay "
+               "MAY olcDisabled )", Cft_Overlay, NULL, cfAddOverlay },
        { "( OLcfgGlOc:6 "
                "NAME 'olcIncludeFile' "
                "DESC 'OpenLDAP configuration include file' "
@@ -1043,6 +1048,23 @@ config_generic(ConfigArgs *c) {
                case CFG_DEPTH:
                        c->value_int = c->be->be_max_deref_depth;
                        break;
+               case CFG_DISABLED:
+                       if ( c->bi ) {
+                               /* overlay */
+                               if ( c->bi->bi_flags & SLAPO_BFLAG_DISABLED ) {
+                                       c->value_int = 1;
+                               } else {
+                                       rc = 1;
+                               }
+                       } else {
+                               /* database */
+                               if ( SLAP_DBDISABLED( c->be )) {
+                                       c->value_int = 1;
+                               } else {
+                                       rc = 1;
+                               }
+                       }
+                       break;
                case CFG_HIDDEN:
                        if ( SLAP_DBHIDDEN( c->be )) {
                                c->value_int = 1;
@@ -1385,6 +1407,21 @@ config_generic(ConfigArgs *c) {
                        c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
                        break;
 
+               case CFG_DISABLED:
+                       if ( c->bi ) {
+                               c->bi->bi_flags &= ~SLAP_DBFLAG_DISABLED;
+                               if ( c->bi->bi_db_open ) {
+                                       BackendInfo *bi_orig = c->be->bd_info;
+                                       c->be->bd_info = c->bi;
+                                       rc = c->bi->bi_db_open( c->be, &c->reply );
+                                       c->be->bd_info = bi_orig;
+                               }
+                       } else {
+                               c->be->be_flags &= ~SLAP_DBFLAG_DISABLED;
+                               rc = backend_startup_one( c->be, &c->reply );
+                       }
+                       break;
+
                case CFG_IX_HASH64:
                        slap_hash64( 0 );
                        break;
@@ -2129,6 +2166,29 @@ sortval_reject:
                                SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
                        break;
 
+               case CFG_DISABLED:
+                       if ( c->bi ) {
+                               if (c->value_int) {
+                                       if ( c->bi->bi_db_close ) {
+                                               BackendInfo *bi_orig = c->be->bd_info;
+                                               c->be->bd_info = c->bi;
+                                               c->bi->bi_db_close( c->be, &c->reply );
+                                               c->be->bd_info = bi_orig;
+                                       }
+                                       c->bi->bi_flags |= SLAPO_BFLAG_DISABLED;
+                               } else {
+                                       c->bi->bi_flags &= ~SLAPO_BFLAG_DISABLED;
+                               }
+                       } else {
+                               if (c->value_int) {
+                                       backend_shutdown( c->be );
+                                       SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_DISABLED;
+                               } else {
+                                       SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_DISABLED;
+                               }
+                       }
+                       break;
+
                case CFG_HIDDEN:
                        if (c->value_int)
                                SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
index 294ac3dc1ea6be72d41046f7df7aceb761026aa6..09c1854f88ab535d30c35f4942f114d3aed249ec 100644 (file)
@@ -1854,11 +1854,13 @@ struct BackendDB {
 #define SLAP_DBFLAG_ACL_ADD            0x20000U /* check attr ACLs on adds */
 #define SLAP_DBFLAG_SYNC_SUBENTRY      0x40000U /* use subentry for context */
 #define SLAP_DBFLAG_MULTI_SHADOW       0x80000U /* uses mirrorMode/multi-master */
+#define SLAP_DBFLAG_DISABLED   0x100000U
        slap_mask_t     be_flags;
 #define SLAP_DBFLAGS(be)                       ((be)->be_flags)
 #define SLAP_NOLASTMOD(be)                     (SLAP_DBFLAGS(be) & SLAP_DBFLAG_NOLASTMOD)
 #define SLAP_LASTMOD(be)                       (!SLAP_NOLASTMOD(be))
 #define SLAP_DBHIDDEN(be)                      (SLAP_DBFLAGS(be) & SLAP_DBFLAG_HIDDEN)
+#define SLAP_DBDISABLED(be)                    (SLAP_DBFLAGS(be) & SLAP_DBFLAG_DISABLED)
 #define SLAP_DB_ONE_SUFFIX(be)         (SLAP_DBFLAGS(be) & SLAP_DBFLAG_ONE_SUFFIX)
 #define SLAP_ISOVERLAY(be)                     (SLAP_DBFLAGS(be) & SLAP_DBFLAG_OVERLAY)
 #define SLAP_ISGLOBALOVERLAY(be)               (SLAP_DBFLAGS(be) & SLAP_DBFLAG_GLOBAL_OVERLAY)
@@ -2318,6 +2320,7 @@ struct BackendInfo {
 #define        SLAPO_BFLAG_SINGLE              0x01000000U
 #define        SLAPO_BFLAG_DBONLY              0x02000000U
 #define        SLAPO_BFLAG_GLOBONLY            0x04000000U
+#define        SLAPO_BFLAG_DISABLED            0x08000000U
 #define        SLAPO_BFLAG_MASK                0xFF000000U
 
 #define SLAP_BFLAGS(be)                ((be)->bd_info->bi_flags)
@@ -2336,6 +2339,7 @@ struct BackendInfo {
 #define SLAPO_SINGLE(be)       (SLAP_BFLAGS(be) & SLAPO_BFLAG_SINGLE)
 #define SLAPO_DBONLY(be)       (SLAP_BFLAGS(be) & SLAPO_BFLAG_DBONLY)
 #define SLAPO_GLOBONLY(be)     (SLAP_BFLAGS(be) & SLAPO_BFLAG_GLOBONLY)
+#define SLAPO_DISABLED(be)     (SLAP_BFLAGS(be) & SLAPO_BFLAG_DISABLED)
 
        char    **bi_controls;          /* supported controls */
        char    bi_ctrls[SLAP_MAX_CIDS + 1];