Ignore:
Timestamp:
Aug 26, 2010, 4:28:45 PM (14 years ago)
Author:
gdb
Message:
Use ap_walk_config to configure directives

The only expected change in behavior here is that directives
configured from LDAP are expected to now behave much more like ones
configured statically, since they now use the same code.  In practice,
this should not work out to a significant difference, but some
directives do seem to have a lot of code that
mod_vhost_ldap_translate_name didn't contain.  (I haven't investigated
this in-depth.)

I also removed logic to deal with r->uri[0] != '\0' && r->uri[0] !=
'/'.  I believe this is not actually relevant anymore, as the tranlate
hook no longer deals with translating to filenames itself, but I could
be mistaken.
File:
1 edited

Legend:

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

    r1604 r1605  
    400400}
    401401
     402static int reconfigure_directive(apr_pool_t *p,
     403                                 server_rec *s,
     404                                 const char *dir,
     405                                 const char *args)
     406{
     407    ap_directive_t dir_s = { .directive = dir, .args = args, .next = NULL,
     408                             .line_num = 0, .filename = "VhostLDAPConf" };
     409    return ap_process_config_tree(s, &dir_s, p, p);
     410}
     411
    402412command_rec mod_vhost_ldap_cmds[] = {
    403413    AP_INIT_TAKE1("VhostLDAPURL", mod_vhost_ldap_parse_url, NULL, RSRC_CONF,
     
    438448    server_rec *server;
    439449    const char *error;
     450    int code;
    440451    mod_vhost_ldap_request_t *reqc;
    441452    int failures = 0;
     
    444455    mod_vhost_ldap_config_t *conf =
    445456        (mod_vhost_ldap_config_t *)ap_get_module_config(r->server->module_config, &vhost_ldap_module);
    446     core_server_config *core;
    447457    util_ldap_connection_t *ldc = NULL;
    448458    int result = 0;
    449459    const char *dn = NULL;
    450     char *cgi;
    451460    const char *hostname = NULL;
    452461    int is_fallback = 0;
     
    463472        return HTTP_INTERNAL_SERVER_ERROR;
    464473    }
    465 
    466     core = core_module.create_server_config(r->pool, server);
    467     ap_set_module_config(server->module_config, &core_module, core);
    468474
    469475    reqc =
     
    536542                hostname += 2;
    537543            hostname += strcspn(hostname, ".");
    538             hostname = apr_pstrcat(r->pool, "*", hostname, NULL);
     544            hostname = apr_pstrcat(r->pool, "*", hostname, (const char *)NULL);
    539545            ap_log_rerror(APLOG_MARK, APLOG_NOTICE|APLOG_NOERRNO, 0, r,
    540546                          "[mod_vhost_ldap.c] translate: "
     
    579585        for (i = 0; attributes[i]; i++) {
    580586
     587            const char *directive;
    581588            char *val = apr_pstrdup (r->pool, vals[i]);
     589            /* These do not correspond to any real directives */
     590            if (strcasecmp (attributes[i], "apacheSuexecUid") == 0) {
     591                reqc->uid = val;
     592                continue;
     593            }
     594            else if (strcasecmp (attributes[i], "apacheSuexecGid") == 0) {
     595                reqc->gid = val;
     596                continue;
     597            }
     598
    582599            if (strcasecmp (attributes[i], "apacheServerName") == 0) {
    583600                reqc->name = val;
     601                directive = "ServerName";
    584602            }
    585603            else if (strcasecmp (attributes[i], "apacheServerAdmin") == 0) {
    586604                reqc->admin = val;
     605                directive = "ServerAdmin";
    587606            }
    588607            else if (strcasecmp (attributes[i], "apacheDocumentRoot") == 0) {
    589608                reqc->docroot = val;
     609                directive = "DocumentRoot";
    590610            }
    591611            else if (strcasecmp (attributes[i], "apacheScriptAlias") == 0) {
     612                if (val != NULL) {
     613                    /* Hack to deal with current apacheScriptAlias lagout */
     614                    if (strlen(val) > 0 && val[strlen(val) - 1] == '/')
     615                        val = apr_pstrcat(r->pool, "/cgi-bin/ ", val, (const char *)NULL);
     616                    else
     617                        val = apr_pstrcat(r->pool, "/cgi-bin/ ", val, "/", (const char *)NULL);
     618                    directive = "ScriptAlias";
     619                }
    592620                reqc->cgiroot = val;
    593621            }
    594             else if (strcasecmp (attributes[i], "apacheSuexecUid") == 0) {
    595                 reqc->uid = val;
    596             }
    597             else if (strcasecmp (attributes[i], "apacheSuexecGid") == 0) {
    598                 reqc->gid = val;
    599             }
     622
     623            if (val == NULL)
     624                continue;
     625
     626            if ((code = reconfigure_directive(r->pool, server, directive, val)) != 0)
     627                return code;
    600628        }
    601629    }
     
    618646    }
    619647
    620     cgi = NULL;
    621 
    622     if (reqc->cgiroot) {
    623         cgi = strstr(r->uri, "cgi-bin/");
    624         if (cgi && (cgi != r->uri + strspn(r->uri, "/"))) {
    625             cgi = NULL;
    626         }
    627     }
    628     if (cgi) {
    629         /* Set exact filename for CGI script */
    630         cgi = apr_pstrcat(r->pool, reqc->cgiroot, cgi + strlen("cgi-bin"), NULL);
    631         if ((cgi = ap_server_root_relative(r->pool, cgi))) {
    632           ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r,
    633                         "[mod_vhost_ldap.c]: ap_document_root is: %s",
    634                         ap_document_root(r));
    635           r->filename = cgi;
    636           r->handler = "cgi-script";
    637           apr_table_setn(r->notes, "alias-forced-type", r->handler);
    638           ret = OK;
    639         }
    640     } else if (strncmp(r->uri, "/~", 2) == 0) {
    641         /* This is a quick, dirty hack. I should be shot for taking 6.170
    642          * this term and being willing to write a quick, dirty hack. */   
     648    if (reqc->uid != NULL) {
    643649        char *username;
    644         uid_t uid = (uid_t)atoll(reqc->uid);
     650        char *userdir_val;
     651        uid_t uid = (uid_t) atoll(reqc->uid);
     652
     653        if ((code = reconfigure_directive(r->pool, server, "UserDir", USERDIR)) != 0)
     654            return code;
     655
     656        /* Deal with ~ expansion */
     657        if ((code = reconfigure_directive(r->pool, server, "UserDir", "disabled")) != 0)
     658            return code;
     659
    645660        if (apr_uid_name_get(&username, uid, r->pool) != APR_SUCCESS) {
    646661            ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r,
    647662                          "could not get username for uid %d", uid);
    648             return DECLINED;
     663            return HTTP_INTERNAL_SERVER_ERROR;
    649664        }
    650         if (strncmp(r->uri + 2, username, strlen(username)) == 0 &&
    651             (r->uri[2 + strlen(username)] == '/' ||
    652              r->uri[2 + strlen(username)] == '\0')) {
    653             char *homedir;
    654             if (apr_uid_homepath_get(&homedir, username, r->pool) != APR_SUCCESS) {
    655                 ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r,
    656                               "could not get home directory for user %s", username);
    657                 return DECLINED;
    658             }
    659             r->filename = apr_pstrcat(r->pool, homedir, "/", USERDIR, r->uri + 2 + strlen(username), NULL);
    660             ret = OK;
    661         }
    662     } else if (r->uri[0] == '/') {
    663         /* we don't set r->filename here, and let other modules do it
    664          * this allows other modules (mod_rewrite.c) to work as usual
    665          */
    666         /* r->filename = apr_pstrcat (r->pool, reqc->docroot, r->uri, NULL); */
    667     } else {
    668         /* We don't handle non-file requests here */
    669         return DECLINED;
    670     }
    671 
    672     server->server_hostname = reqc->name;
    673 
    674     if (reqc->admin) {
    675         server->server_admin = reqc->admin;
    676     }
    677 
    678     /* Stolen from server/core.c */
    679 
    680     /* Make it absolute, relative to ServerRoot */
    681     reqc->docroot = ap_server_root_relative(r->pool, reqc->docroot);
    682 
    683     if (reqc->docroot == NULL) {
    684         ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r,
    685                       "[mod_vhost_ldap.c] set_document_root: DocumentRoot must be a directory");
    686 
    687         return HTTP_INTERNAL_SERVER_ERROR;
    688     }
    689 
    690     /* TODO: ap_configtestonly && ap_docrootcheck && */
    691     if (apr_filepath_merge((char**)&core->ap_document_root, NULL, reqc->docroot,
    692                            APR_FILEPATH_TRUENAME, r->pool) != APR_SUCCESS
    693         || !ap_is_directory(r->pool, reqc->docroot)) {
    694 
    695         ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r,
    696                       "[mod_vhost_ldap.c] set_document_root: Warning: DocumentRoot [%s] does not exist",
    697                       reqc->docroot);
    698         core->ap_document_root = reqc->docroot;
     665
     666        userdir_val = apr_pstrcat(r->pool, "enabled ", username, (const char *)NULL);
     667
     668        if ((code = reconfigure_directive(r->pool, server, "UserDir", userdir_val)) != 0)
     669            return code;
    699670    }
    700671
Note: See TracChangeset for help on using the changeset viewer.