Changeset 1588 for trunk


Ignore:
Timestamp:
Jul 17, 2010, 3:53:11 PM (14 years ago)
Author:
andersk
Message:
Update mod_vhost_ldap to 2.0.5

Now that mod_vhost_ldap upstream has taken all our patches except the
non-upstreamable one that hard-codes the /~username alias for our
vhosts, it might be a good idea to upgrade.

(Hopefully, gdb’s arbitrary-directives work will eventually provide a
good way to upstream the /~username functionality.)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/server/common/oursrc/httpdmods/mod_vhost_ldap.c

    r1463 r1588  
    3232#include "apr_version.h"
    3333#include "apr_ldap.h"
     34#include "apr_reslist.h"
    3435#include "apr_strings.h"
    35 #include "apr_reslist.h"
     36#include "apr_tables.h"
    3637#include "util_ldap.h"
     38#include "util_script.h"
    3739
    3840#if !defined(APU_HAS_LDAP) && !defined(APR_HAS_LDAP)
     
    5153#define MIN_GID 100
    5254const char USERDIR[] = "web_scripts";
     55
     56#define MAX_FAILURES 5
    5357
    5458module AP_MODULE_DECLARE_DATA vhost_ldap_module;
     
    122126{
    123127    module **m;
    124 
     128   
    125129    /* Stolen from modules/generators/mod_cgid.c */
    126130    total_modules = 0;
    127131    for (m = ap_preloaded_modules; *m != NULL; m++)
    128         total_modules++;
     132      total_modules++;
    129133
    130134    /* make sure that mod_ldap (util_ldap) is loaded */
     
    433437{
    434438    mod_vhost_ldap_request_t *reqc;
    435     apr_table_t *e;
    436439    int failures = 0;
    437440    const char **vals = NULL;
     
    439442    mod_vhost_ldap_config_t *conf =
    440443        (mod_vhost_ldap_config_t *)ap_get_module_config(r->server->module_config, &vhost_ldap_module);
    441     core_server_config * core =
    442         (core_server_config *) ap_get_module_config(r->server->module_config, &core_module);
     444    core_server_config *core =
     445        (core_server_config *)ap_get_module_config(r->server->module_config, &core_module);
    443446    util_ldap_connection_t *ldc = NULL;
    444447    int result = 0;
     
    447450    const char *hostname = NULL;
    448451    int is_fallback = 0;
     452    int sleep0 = 0;
     453    int sleep1 = 1;
     454    int sleep;
     455    struct berval hostnamebv, shostnamebv;
    449456
    450457    reqc =
     
    469476        ap_log_rerror(APLOG_MARK, APLOG_WARNING|APLOG_NOERRNO, 0, r,
    470477                      "[mod_vhost_ldap.c] translate: no conf->host - weird...?");
    471         return DECLINED;
     478        return HTTP_INTERNAL_SERVER_ERROR;
    472479    }
    473480
    474481    hostname = r->hostname;
    475482    if (hostname == NULL || hostname[0] == '\0')
    476         goto null;
     483        goto null;
    477484
    478485fallback:
    479486
    480487    ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r,
    481                    "[mod_vhost_ldap.c]: translating %s", r->uri);
    482 
    483     struct berval hostnamebv, shostnamebv;
     488                  "[mod_vhost_ldap.c]: translating hostname [%s], uri [%s]",
     489                  hostname, r->uri);
     490
    484491    ber_str2bv(hostname, 0, 0, &hostnamebv);
    485492    if (ldap_bv2escaped_filter_value(&hostnamebv, &shostnamebv) != 0)
     
    494501
    495502    /* sanity check - if server is down, retry it up to 5 times */
    496     if (result == LDAP_SERVER_DOWN) {
    497         if (failures++ <= 5) {
     503    if (AP_LDAP_IS_SERVER_DOWN(result) ||
     504        (result == LDAP_TIMEOUT) ||
     505        (result == LDAP_CONNECT_ERROR)) {
     506        sleep = sleep0 + sleep1;
     507        ap_log_rerror(APLOG_MARK, APLOG_WARNING|APLOG_NOERRNO, 0, r,
     508                      "[mod_vhost_ldap.c]: lookup failure, retry number #[%d], sleeping for [%d] seconds",
     509                      failures, sleep);
     510        if (failures++ < MAX_FAILURES) {
     511            /* Back-off exponentially */
     512            apr_sleep(apr_time_from_sec(sleep));
     513            sleep0 = sleep1;
     514            sleep1 = sleep;
    498515            goto start_over;
    499         }
    500     }
    501 
    502     if ((result == LDAP_NO_SUCH_OBJECT)) {
     516        } else {
     517            return HTTP_GATEWAY_TIME_OUT;
     518        }
     519    }
     520
     521    if (result == LDAP_NO_SUCH_OBJECT) {
    503522        if (strcmp(hostname, "*") != 0) {
    504523            if (strncmp(hostname, "*.", 2) == 0)
     
    513532        }
    514533
    515     null:
     534null:
    516535        if (conf->fallback && (is_fallback++ <= 0)) {
    517536            ap_log_rerror(APLOG_MARK, APLOG_NOTICE|APLOG_NOERRNO, 0, r,
     
    528547                      hostname);
    529548
    530         return DECLINED;
     549        return HTTP_BAD_REQUEST;
    531550    }
    532551
     
    537556                      "translate failed; virtual host %s; URI %s [%s]",
    538557                      hostname, r->uri, ldap_err2string(result));
    539         return DECLINED;
     558        return HTTP_INTERNAL_SERVER_ERROR;
    540559    }
    541560
     
    584603                      "[mod_vhost_ldap.c] translate: "
    585604                      "translate failed; ServerName or DocumentRoot not defined");
    586         return DECLINED;
     605        return HTTP_INTERNAL_SERVER_ERROR;
    587606    }
    588607
    589608    cgi = NULL;
    590  
     609
    591610#if 0
    592611    if (reqc->cgiroot) {
     
    597616    }
    598617    if (cgi) {
    599         r->filename = apr_pstrcat (r->pool, reqc->cgiroot, cgi + strlen("cgi-bin"), NULL);
    600         r->handler = "cgi-script";
    601         apr_table_setn(r->notes, "alias-forced-type", r->handler);
     618        /* Set exact filename for CGI script */
     619        cgi = apr_pstrcat(r->pool, reqc->cgiroot, cgi + strlen("cgi-bin"), NULL);
     620        if ((cgi = ap_server_root_relative(r->pool, cgi))) {
     621          ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r,
     622                        "[mod_vhost_ldap.c]: ap_document_root is: %s",
     623                        ap_document_root(r));
     624          r->filename = cgi;
     625          r->handler = "cgi-script";
     626          apr_table_setn(r->notes, "alias-forced-type", r->handler);
     627        }
    602628#endif
    603629    /* This is a quick, dirty hack. I should be shot for taking 6.170
     
    624650        }
    625651    } else if (r->uri[0] == '/') {
    626         r->filename = apr_pstrcat (r->pool, reqc->docroot, r->uri, NULL);
     652        /* we don't set r->filename here, and let other modules do it
     653         * this allows other modules (mod_rewrite.c) to work as usual
     654         */
     655        /* r->filename = apr_pstrcat (r->pool, reqc->docroot, r->uri, NULL); */
    627656    } else {
     657        /* We don't handle non-file requests here */
    628658        return DECLINED;
    629659    }
    630660
    631     if ((r->server = apr_pmemdup(r->pool, r->server,
    632                                  sizeof(*r->server))) == NULL)
     661    if ((r->server = apr_pmemdup(r->pool, r->server, sizeof(*r->server))) == NULL) {
     662        ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r,
     663                      "[mod_vhost_ldap.c] translate: "
     664                      "translate failed; Unable to copy r->server structure");
    633665        return HTTP_INTERNAL_SERVER_ERROR;
     666    }
    634667
    635668    r->server->server_hostname = reqc->name;
     
    639672    }
    640673
    641     // set environment variables
    642     e = r->subprocess_env;
    643     apr_table_addn (e, "SERVER_ROOT", reqc->docroot);
    644 
    645     if ((r->server->module_config =
    646          apr_pmemdup(r->pool, r->server->module_config,
    647                      sizeof(void *) *
    648                      (total_modules + DYNAMIC_MODULE_LIMIT))) == NULL)
    649         return HTTP_INTERNAL_SERVER_ERROR;
    650 
    651     if ((core = apr_pmemdup(r->pool, core, sizeof(*core))) == NULL)
    652         return HTTP_INTERNAL_SERVER_ERROR;
     674    if ((r->server->module_config = apr_pmemdup(r->pool, r->server->module_config,
     675                                                sizeof(void *) *
     676                                                (total_modules + DYNAMIC_MODULE_LIMIT))) == NULL) {
     677        ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r,
     678                      "[mod_vhost_ldap.c] translate: "
     679                      "translate failed; Unable to copy r->server->module_config structure");
     680        return HTTP_INTERNAL_SERVER_ERROR;
     681    }
     682
     683    if ((core = apr_pmemdup(r->pool, core, sizeof(*core))) == NULL) {
     684        ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r,
     685                      "[mod_vhost_ldap.c] translate: "
     686                      "translate failed; Unable to copy r->core structure");
     687        return HTTP_INTERNAL_SERVER_ERROR;
     688    }
    653689    ap_set_module_config(r->server->module_config, &core_module, core);
    654690
    655     core->ap_document_root = reqc->docroot;
    656 
    657     ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r,
    658                   "[mod_vhost_ldap.c]: translated to %s", r->filename);
    659 
    660     return OK;
     691    /* Stolen from server/core.c */
     692
     693    /* Make it absolute, relative to ServerRoot */
     694    reqc->docroot = ap_server_root_relative(r->pool, reqc->docroot);
     695
     696    if (reqc->docroot == NULL) {
     697        ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r,
     698                      "[mod_vhost_ldap.c] set_document_root: DocumentRoot must be a directory");
     699
     700        return HTTP_INTERNAL_SERVER_ERROR;
     701    }
     702
     703    /* TODO: ap_configtestonly && ap_docrootcheck && */
     704    if (apr_filepath_merge((char**)&core->ap_document_root, NULL, reqc->docroot,
     705                           APR_FILEPATH_TRUENAME, r->pool) != APR_SUCCESS
     706        || !ap_is_directory(r->pool, reqc->docroot)) {
     707
     708        ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r,
     709                      "[mod_vhost_ldap.c] set_document_root: Warning: DocumentRoot [%s] does not exist",
     710                      reqc->docroot);
     711        core->ap_document_root = reqc->docroot;
     712    }
     713
     714    /* Hack to allow post-processing by other modules (mod_rewrite, mod_alias) */
     715    return DECLINED;
    661716}
    662717
     
    706761mod_vhost_ldap_register_hooks (apr_pool_t * p)
    707762{
     763
     764    /*
     765     * Run before mod_rewrite
     766     */
     767    static const char * const aszRewrite[]={ "mod_rewrite.c", NULL };
     768
    708769    ap_hook_post_config(mod_vhost_ldap_post_config, NULL, NULL, APR_HOOK_MIDDLE);
    709     ap_hook_translate_name(mod_vhost_ldap_translate_name, NULL, NULL, APR_HOOK_MIDDLE);
     770    ap_hook_translate_name(mod_vhost_ldap_translate_name, NULL, aszRewrite, APR_HOOK_FIRST);
    710771#ifdef HAVE_UNIX_SUEXEC
    711772    ap_hook_get_suexec_identity(mod_vhost_ldap_get_suexec_id_doer, NULL, NULL, APR_HOOK_MIDDLE);
Note: See TracChangeset for help on using the changeset viewer.