]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/config.c
Fix prev commit, config_obsolete
[openldap] / servers / slapd / config.c
index ca80cf65e1a3f35a6617dd3e9b61ae7c3dccdcaa..4f4f91e1af8ad0c0661a85b0c0d896acadc552dd 100644 (file)
@@ -68,7 +68,6 @@ int           global_gentlehup = 0;
 int            global_idletimeout = 0;
 char   *global_host = NULL;
 char   *global_realm = NULL;
-char           *ldap_srvtab = "";
 char           **default_passwd_hash = NULL;
 struct berval default_search_base = BER_BVNULL;
 struct berval default_search_nbase = BER_BVNULL;
@@ -319,8 +318,7 @@ int config_set_vals(ConfigTable *Conf, ConfigArgs *c) {
                return(0);
        }
        if(arg_type & ARG_OFFSET) {
-               if (c->be && (!overlay_is_over(c->be) || 
-                       ((slap_overinfo *)c->be->bd_info)->oi_orig == c->bi))
+               if (c->be && c->table == Cft_Database)
                        ptr = c->be->be_private;
                else if (c->bi)
                        ptr = c->bi->bi_private;
@@ -411,8 +409,7 @@ config_get_vals(ConfigTable *cf, ConfigArgs *c)
                if ( rc ) return rc;
        } else {
                if ( cf->arg_type & ARG_OFFSET ) {
-                       if (c->be && (!overlay_is_over(c->be) || 
-                               ((slap_overinfo *)c->be->bd_info)->oi_orig == c->bi))
+                       if (c->be && c->table == Cft_Database)
                                ptr = c->be->be_private;
                        else if ( c->bi )
                                ptr = c->bi->bi_private;
@@ -729,6 +726,7 @@ read_config_file(const char *fname, int depth, ConfigArgs *cf, ConfigTable *cft)
 
                ct = config_find_keyword( cft, c );
                if ( ct ) {
+                       c->table = Cft_Global;
                        rc = config_add_vals( ct, c );
                        if ( !rc ) continue;
 
@@ -749,6 +747,7 @@ read_config_file(const char *fname, int depth, ConfigArgs *cf, ConfigTable *cft)
                        if ( c->bi->bi_cf_ocs ) {
                                ct = config_find_keyword( c->bi->bi_cf_ocs->co_table, c );
                                if ( ct ) {
+                                       c->table = c->bi->bi_cf_ocs->co_type;
                                        rc = config_add_vals( ct, c );
                                }
                        }
@@ -773,6 +772,7 @@ read_config_file(const char *fname, int depth, ConfigArgs *cf, ConfigTable *cft)
                        if ( c->be->be_cf_ocs ) {
                                ct = config_find_keyword( c->be->be_cf_ocs->co_table, c );
                                if ( ct ) {
+                                       c->table = c->be->be_cf_ocs->co_type;
                                        rc = config_add_vals( ct, c );
                                }
                        }
@@ -998,6 +998,21 @@ static slap_verbmasks tlskey[] = {
        { BER_BVC("critical"),  SB_TLS_CRITICAL },
        { BER_BVNULL, 0 }
 };
+
+static slap_verbmasks crlkeys[] = {
+               { BER_BVC("none"),      LDAP_OPT_X_TLS_CRL_NONE },
+               { BER_BVC("peer"),      LDAP_OPT_X_TLS_CRL_PEER },
+               { BER_BVC("all"),       LDAP_OPT_X_TLS_CRL_ALL },
+               { BER_BVNULL, 0 }
+       };
+
+static slap_verbmasks vfykeys[] = {
+               { BER_BVC("never"),     LDAP_OPT_X_TLS_NEVER },
+               { BER_BVC("demand"),    LDAP_OPT_X_TLS_DEMAND },
+               { BER_BVC("try"),       LDAP_OPT_X_TLS_TRY },
+               { BER_BVC("hard"),      LDAP_OPT_X_TLS_HARD },
+               { BER_BVNULL, 0 }
+       };
 #endif
 
 static slap_verbmasks methkey[] = {
@@ -1019,6 +1034,8 @@ static slap_cf_aux_table bindkey[] = {
        { BER_BVC("uri="), offsetof(slap_bindconf, sb_uri), 'b', 1, NULL },
        { BER_BVC("version="), offsetof(slap_bindconf, sb_version), 'i', 0, versionkey },
        { BER_BVC("bindmethod="), offsetof(slap_bindconf, sb_method), 'i', 0, methkey },
+       { BER_BVC("timeout="), offsetof(slap_bindconf, sb_timeout_api), 'i', 0, NULL },
+       { BER_BVC("network-timeout="), offsetof(slap_bindconf, sb_timeout_net), 'i', 0, NULL },
        { BER_BVC("binddn="), offsetof(slap_bindconf, sb_binddn), 'b', 1, (slap_verbmasks *)dnNormalize },
        { BER_BVC("credentials="), offsetof(slap_bindconf, sb_cred), 'b', 1, NULL },
        { BER_BVC("saslmech="), offsetof(slap_bindconf, sb_saslmech), 'b', 0, NULL },
@@ -1029,9 +1046,9 @@ static slap_cf_aux_table bindkey[] = {
 #ifdef HAVE_TLS
        { BER_BVC("starttls="), offsetof(slap_bindconf, sb_tls), 'i', 0, tlskey },
 
-       /* NOTE: replace "11" with the actual index
+       /* NOTE: replace "13" with the actual index
         * of the first TLS-related line */
-#define aux_TLS (bindkey+11)   /* beginning of TLS keywords */
+#define aux_TLS (bindkey+13)   /* beginning of TLS keywords */
 
        { BER_BVC("tls_cert="), offsetof(slap_bindconf, sb_tls_cert), 's', 1, NULL },
        { BER_BVC("tls_key="), offsetof(slap_bindconf, sb_tls_key), 's', 1, NULL },
@@ -1233,14 +1250,63 @@ slap_cf_aux_table_unparse( void *src, struct berval *bv, slap_cf_aux_table *tab0
 }
 
 int
-bindconf_parse( const char *word, slap_bindconf *bc )
+slap_tls_get_config( LDAP *ld, int opt, char **val )
+{
+       slap_verbmasks *keys;
+       int i, ival;
+
+       *val = NULL;
+       switch( opt ) {
+#ifdef HAVE_TLS
+       case LDAP_OPT_X_TLS_CRLCHECK:
+               keys = crlkeys;
+               break;
+       case LDAP_OPT_X_TLS_REQUIRE_CERT:
+               keys = vfykeys;
+               break;
+#endif
+       default:
+               return -1;
+       }
+       ldap_pvt_tls_get_option( ld, opt, &ival );
+       for (i=0; !BER_BVISNULL(&keys[i].word); i++) {
+               if (keys[i].mask == ival) {
+                       *val = ch_strdup( keys[i].word.bv_val );
+                       return 0;
+               }
+       }
+       return -1;
+}
+
+int
+bindconf_tls_parse( const char *word, slap_bindconf *bc )
 {
 #ifdef HAVE_TLS
-       /* Detect TLS config changes explicitly */
        if ( slap_cf_aux_table_parse( word, bc, aux_TLS, "tls config" ) == 0 ) {
                bc->sb_tls_do_init = 1;
                return 0;
        }
+#endif
+       return -1;
+}
+
+int
+bindconf_tls_unparse( slap_bindconf *bc, struct berval *bv )
+{
+#ifdef HAVE_TLS
+       return slap_cf_aux_table_unparse( bc, bv, aux_TLS );
+#endif
+       return -1;
+}
+
+int
+bindconf_parse( const char *word, slap_bindconf *bc )
+{
+#ifdef HAVE_TLS
+       /* Detect TLS config changes explicitly */
+       if ( bindconf_tls_parse( word, bc ) == 0 ) {
+               return 0;
+       }
 #endif
        return slap_cf_aux_table_parse( word, bc, bindkey, "bind config" );
 }
@@ -1285,12 +1351,6 @@ void bindconf_free( slap_bindconf *bc ) {
                BER_BVZERO( &bc->sb_authzId );
        }
 #ifdef HAVE_TLS
-#if 0
-       if ( bc->sb_tls_ctx ) {
-               SSL_CTX_free( bc->sb_tls_ctx );
-               bc->sb_tls_ctx = NULL;
-       }
-#endif
        if ( bc->sb_tls_cert ) {
                ch_free( bc->sb_tls_cert );
                bc->sb_tls_cert = NULL;
@@ -1324,6 +1384,37 @@ void bindconf_free( slap_bindconf *bc ) {
 #endif
 }
 
+void
+bindconf_tls_defaults( slap_bindconf *bc )
+{
+#ifdef HAVE_TLS
+       if ( bc->sb_tls_do_init ) {
+               if ( !bc->sb_tls_cacert )
+                       ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CACERTFILE,
+                               &bc->sb_tls_cacert );
+               if ( !bc->sb_tls_cacertdir )
+                       ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CACERTDIR,
+                               &bc->sb_tls_cacertdir );
+               if ( !bc->sb_tls_cert )
+                       ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CERTFILE,
+                               &bc->sb_tls_cert );
+               if ( !bc->sb_tls_key )
+                       ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_KEYFILE,
+                               &bc->sb_tls_key );
+               if ( !bc->sb_tls_cipher_suite )
+                       ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CIPHER_SUITE,
+                               &bc->sb_tls_cipher_suite );
+               if ( !bc->sb_tls_reqcert )
+                       bc->sb_tls_reqcert = ch_strdup("demand");
+#ifdef HAVE_OPENSSL_CRL
+               if ( !bc->sb_tls_crlcheck )
+                       slap_tls_get_config( slap_tls_ld, LDAP_OPT_X_TLS_CRLCHECK,
+                               &bc->sb_tls_crlcheck );
+#endif
+       }
+#endif
+}
+
 #ifdef HAVE_TLS
 static struct {
        const char *key;
@@ -1386,7 +1477,7 @@ int bindconf_tls_set( slap_bindconf *bc, LDAP *ld )
                int opt = 0;
 
                if ( bc->sb_tls_ctx ) {
-                       SSL_CTX_free( bc->sb_tls_ctx );
+                       ldap_pvt_tls_ctx_free( bc->sb_tls_ctx );
                        bc->sb_tls_ctx = NULL;
                }
                rc = ldap_set_option( ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
@@ -1409,6 +1500,7 @@ slap_client_connect( LDAP **ldp, slap_bindconf *sb )
 {
        LDAP            *ld = NULL;
        int             rc;
+       struct timeval tv;
 
        /* Init connection to master */
        rc = ldap_initialize( &ld, sb->sb_uri.bv_val );
@@ -1425,6 +1517,18 @@ slap_client_connect( LDAP **ldp, slap_bindconf *sb )
                        (const void *)&sb->sb_version );
        }
 
+       if ( sb->sb_timeout_api ) {
+               tv.tv_sec = sb->sb_timeout_api;
+               tv.tv_usec = 0;
+               ldap_set_option( ld, LDAP_OPT_TIMEOUT, &tv );
+       }
+
+       if ( sb->sb_timeout_net ) {
+               tv.tv_sec = sb->sb_timeout_net;
+               tv.tv_usec = 0;
+               ldap_set_option( ld, LDAP_OPT_NETWORK_TIMEOUT, &tv );
+       }
+
 #ifdef HAVE_TLS
        if ( sb->sb_tls_do_init ) {
                rc = bindconf_tls_set( sb, ld );
@@ -1805,7 +1909,9 @@ int config_generic_wrapper( Backend *be, const char *fname, int lineno,
 
        rc = SLAP_CONF_UNKNOWN;
        ct = config_find_keyword( be->be_cf_ocs->co_table, &c );
-       if ( ct )
+       if ( ct ) {
+               c.table = be->be_cf_ocs->co_type;
                rc = config_add_vals( ct, &c );
+       }
        return rc;
 }