mod_userdir.c revision 6f984345bbfa9342dde1f2b7b8c35b7987d078af
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin/* ====================================================================
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * The Apache Software License, Version 1.1
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin *
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Copyright (c) 2000 The Apache Software Foundation. All rights
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * reserved.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin *
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * Redistribution and use in source and binary forms, with or without
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * modification, are permitted provided that the following conditions
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * are met:
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin *
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * 1. Redistributions of source code must retain the above copyright
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * notice, this list of conditions and the following disclaimer.
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder *
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * 2. Redistributions in binary form must reproduce the above copyright
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * notice, this list of conditions and the following disclaimer in
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * the documentation and/or other materials provided with the
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * distribution.
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin *
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * 3. The end-user documentation included with the redistribution,
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * if any, must include the following acknowledgment:
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * "This product includes software developed by the
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Apache Software Foundation (http://www.apache.org/)."
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Alternately, this acknowledgment may appear in the software itself,
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * if and wherever such third-party acknowledgments normally appear.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin *
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * 4. The names "Apache" and "Apache Software Foundation" must
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * not be used to endorse or promote products derived from this
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * software without prior written permission. For written
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * permission, please contact apache@apache.org.
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin *
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * 5. Products derived from this software may not be called "Apache",
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * nor may "Apache" appear in their name, without prior written
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * permission of the Apache Software Foundation.
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin *
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * SUCH DAMAGE.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * ====================================================================
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin *
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * This software consists of voluntary contributions made by many
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * individuals on behalf of the Apache Software Foundation. For more
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * information on the Apache Software Foundation, please see
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * <http://www.apache.org/>.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin *
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Portions of this software are based upon public domain software
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * originally written at the National Center for Supercomputing Applications,
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * University of Illinois, Urbana-Champaign.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin */
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin/*
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * mod_userdir... implement the UserDir command. Broken away from the
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Alias stuff for a couple of good and not-so-good reasons:
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin *
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * 1) It shows a real minimal working example of how to do something like
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * this.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * 2) I know people who are actually interested in changing this *particular*
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * aspect of server functionality without changing the rest of it. That's
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * what this whole modular arrangement is supposed to be good at...
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin *
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Modified by Alexei Kosut to support the following constructs
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * (server running at www.foo.com, request for /~bar/one/two.html)
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin *
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * UserDir public_html -> ~bar/public_html/one/two.html
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * UserDir /usr/web -> /usr/web/bar/one/two.html
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * UserDir /home/ * /www -> /home/bar/www/one/two.html
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * NOTE: theses ^ ^ space only added allow it to work in a comment, ignore
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * UserDir http://x/users -> (302) http://x/users/bar/one/two.html
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * UserDir http://x/ * /y -> (302) http://x/bar/y/one/two.html
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * NOTE: here also ^ ^
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder *
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * In addition, you can use multiple entries, to specify alternate
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * user directories (a la Directory Index). For example:
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin *
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * UserDir public_html /usr/web http://www.xyz.com/users
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin *
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Modified by Ken Coar to provide for the following:
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin *
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * UserDir disable[d] username ...
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * UserDir enable[d] username ...
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin *
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * If "disabled" has no other arguments, *all* ~<username> references are
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * disabled, except those explicitly turned on with the "enabled" keyword.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin */
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin#if !defined(WIN32) && !defined(OS2) && !defined(BEOS)
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin#define HAVE_UNIX_SUEXEC
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder#endif
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin#include "apr_strings.h"
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder#include "apr_user.h"
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin#include "ap_config.h"
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin#include "httpd.h"
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin#include "http_config.h"
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin#include "http_request.h"
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin#ifdef HAVE_UNIX_SUEXEC
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin#include "unixd.h" /* Contains the suexec_identity hook used on Unix */
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder#endif
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin#ifdef HAVE_UNISTD_H
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder#include <unistd.h>
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder#endif
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder#ifdef HAVE_STRINGS_H
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin#include <strings.h>
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin#endif
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin/* The default directory in user's home dir */
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin#ifndef DEFAULT_USER_DIR
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin#define DEFAULT_USER_DIR "public_html"
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin#endif
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calinmodule userdir_module;
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calintypedef struct userdir_config {
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin int globally_disabled;
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin char *userdir;
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder apr_table_t *enabled_users;
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin apr_table_t *disabled_users;
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin} userdir_config;
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin/*
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Server config for this module: global disablement flag, a list of usernames
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * ineligible for UserDir access, a list of those immune to global (but not
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * explicit) disablement, and the replacement string for all others.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin */
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calinstatic void *create_userdir_config(apr_pool_t *p, server_rec *s)
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin{
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin userdir_config
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * newcfg = (userdir_config *) apr_pcalloc(p, sizeof(userdir_config));
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin newcfg->globally_disabled = 0;
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin newcfg->userdir = DEFAULT_USER_DIR;
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin newcfg->enabled_users = apr_make_table(p, 4);
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin newcfg->disabled_users = apr_make_table(p, 4);
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin return (void *) newcfg;
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin}
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin#define O_DEFAULT 0
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin#define O_ENABLE 1
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin#define O_DISABLE 2
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calinstatic const char *set_user_dir(cmd_parms *cmd, void *dummy, const char *arg)
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin{
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin userdir_config
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * s_cfg = (userdir_config *) ap_get_module_config
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin (
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin cmd->server->module_config,
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin &userdir_module
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin );
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin char *username;
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin const char
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin *usernames = arg;
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin char *kw = ap_getword_conf(cmd->pool, &usernames);
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin apr_table_t *usertable;
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin /*
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Let's do the comparisons once.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin */
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin if ((!strcasecmp(kw, "disable")) || (!strcasecmp(kw, "disabled"))) {
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder /*
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * If there are no usernames specified, this is a global disable - we
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * need do no more at this point than record the fact.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin */
if (strlen(usernames) == 0) {
s_cfg->globally_disabled = 1;
return NULL;
}
usertable = s_cfg->disabled_users;
}
else if ((!strcasecmp(kw, "enable")) || (!strcasecmp(kw, "enabled"))) {
/*
* The "disable" keyword can stand alone or take a list of names, but
* the "enable" keyword requires the list. Whinge if it doesn't have
* it.
*/
if (strlen(usernames) == 0) {
return "UserDir \"enable\" keyword requires a list of usernames";
}
usertable = s_cfg->enabled_users;
}
else {
/*
* If the first (only?) value isn't one of our keywords, just copy
* the string to the userdir string.
*/
s_cfg->userdir = apr_pstrdup(cmd->pool, arg);
return NULL;
}
/*
* Now we just take each word in turn from the command line and add it to
* the appropriate table.
*/
while (*usernames) {
username = ap_getword_conf(cmd->pool, &usernames);
apr_table_setn(usertable, username, kw);
}
return NULL;
}
static const command_rec userdir_cmds[] = {
AP_INIT_RAW_ARGS("UserDir", set_user_dir, NULL, RSRC_CONF,
"the public subdirectory in users' home directories, or "
"'disabled', or 'disabled username username...', or "
"'enabled username username...'"),
{NULL}
};
static int translate_userdir(request_rec *r)
{
void *server_conf = r->server->module_config;
const userdir_config *s_cfg =
(userdir_config *) ap_get_module_config(server_conf, &userdir_module);
char *name = r->uri;
const char *userdirs = s_cfg->userdir;
const char *w, *dname;
char *redirect;
char *x = NULL;
apr_finfo_t statbuf;
/*
* If the URI doesn't match our basic pattern, we've nothing to do with
* it.
*/
if (
(s_cfg->userdir == NULL) ||
(name[0] != '/') ||
(name[1] != '~')
) {
return DECLINED;
}
dname = name + 2;
w = ap_getword(r->pool, &dname, '/');
/*
* The 'dname' funny business involves backing it up to capture the '/'
* delimiting the "/~user" part from the rest of the URL, in case there
* was one (the case where there wasn't being just "GET /~user HTTP/1.0",
* for which we don't want to tack on a '/' onto the filename).
*/
if (dname[-1] == '/') {
--dname;
}
/*
* If there's no username, it's not for us. Ignore . and .. as well.
*/
if (w[0] == '\0' || (w[1] == '.' && (w[2] == '\0' || (w[2] == '.' && w[3] == '\0')))) {
return DECLINED;
}
/*
* Nor if there's an username but it's in the disabled list.
*/
if (apr_table_get(s_cfg->disabled_users, w) != NULL) {
return DECLINED;
}
/*
* If there's a global interdiction on UserDirs, check to see if this
* name is one of the Blessed.
*/
if (
s_cfg->globally_disabled &&
(apr_table_get(s_cfg->enabled_users, w) == NULL)
) {
return DECLINED;
}
/*
* Special cases all checked, onward to normal substitution processing.
*/
while (*userdirs) {
const char *userdir = ap_getword_conf(r->pool, &userdirs);
char *filename = NULL;
if (ap_strchr_c(userdir, '*'))
x = ap_getword(r->pool, &userdir, '*');
if (userdir[0] == '\0' || ap_os_is_path_absolute(userdir)) {
if (x) {
#ifdef HAVE_DRIVE_LETTERS
/*
* Crummy hack. Need to figure out whether we have been
* redirected to a URL or to a file on some drive. Since I
* know of no protocols that are a single letter, ignore
* a : as the first or second character, and assume a file
* was specified
*
* XXX: Still no good for NETWARE, since : is embedded (sys:/home)
*/
if (strchr(x + 2, ':'))
#else
if (strchr(x, ':'))
#endif /* HAVE_DRIVE_LETTERS */
{
redirect = apr_pstrcat(r->pool, x, w, userdir, dname, NULL);
apr_table_setn(r->headers_out, "Location", redirect);
return HTTP_MOVED_TEMPORARILY;
}
else
filename = apr_pstrcat(r->pool, x, w, userdir, NULL);
}
else
filename = apr_pstrcat(r->pool, userdir, "/", w, NULL);
}
else if (ap_strchr_c(userdir, ':')) {
redirect = apr_pstrcat(r->pool, userdir, "/", w, dname, NULL);
apr_table_setn(r->headers_out, "Location", redirect);
return HTTP_MOVED_TEMPORARILY;
}
else {
#if APR_HAS_USER
char *homedir;
if (apr_get_home_directory(&homedir, w, r->pool) == APR_SUCCESS) {
#ifdef OS2 /* XXX should this OS/2 logic move to APR? */
/* Need to manually add user name for OS/2 */
filename = apr_pstrcat(r->pool, homedir, w, "/", userdir, NULL);
#else
filename = apr_pstrcat(r->pool, homedir, "/", userdir, NULL);
#endif
}
else {
/* XXX old code ignored this error... */
}
#else
return DECLINED;
#endif
}
/*
* Now see if it exists, or we're at the last entry. If we are at the
* last entry, then use the filename generated (if there is one)
* anyway, in the hope that some handler might handle it. This can be
* used, for example, to run a CGI script for the user.
*/
if (filename && (!*userdirs ||
apr_stat(&statbuf, filename,
APR_FINFO_NORM, r->pool) == APR_SUCCESS)) {
r->filename = apr_pstrcat(r->pool, filename, dname, NULL);
/* when statbuf contains info on r->filename we can save a syscall
* by copying it to r->finfo
*/
if (*userdirs && dname[0] == 0)
r->finfo = statbuf;
/* For use in the get_suexec_identity phase */
apr_table_setn(r->notes, "mod_userdir_user", w);
return OK;
}
}
return DECLINED;
}
#ifdef HAVE_UNIX_SUEXEC
static ap_unix_identity_t *get_suexec_id_doer(const request_rec *r)
{
const char *username = apr_table_get(r->notes, "mod_userdir_user");
struct passwd *pw = NULL;
ap_unix_identity_t *ugid = NULL;
if (username == NULL) {
return NULL;
}
if ((ugid = apr_palloc(r->pool, sizeof(ap_unix_identity_t *))) == NULL) {
return NULL;
}
ugid->uid = pw->pw_uid;
ugid->gid = pw->pw_gid;
return ugid;
}
#endif /* HAVE_UNIX_SUEXEC */
static void register_hooks(apr_pool_t *p)
{
static const char * const aszSucc[]={ "mod_alias.c",NULL };
ap_hook_translate_name(translate_userdir,NULL,aszSucc,APR_HOOK_MIDDLE);
#ifdef HAVE_UNIX_SUEXEC
ap_hook_get_suexec_identity(get_suexec_id_doer,NULL,NULL,APR_HOOK_MIDDLE);
#endif
}
module userdir_module = {
STANDARD20_MODULE_STUFF,
NULL, /* dir config creater */
NULL, /* dir merger --- default is to override */
create_userdir_config, /* server config */
NULL, /* merge server config */
userdir_cmds, /* command apr_table_t */
register_hooks /* register hooks */
};