mod_userdir.c revision 08cb74ca432a8c24e39f17dedce527e6a47b8001
/* Copyright 1999-2005 The Apache Software Foundation or its licensors, as
* applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* mod_userdir... implement the UserDir command. Broken away from the
* Alias stuff for a couple of good and not-so-good reasons:
*
* 1) It shows a real minimal working example of how to do something like
* this.
* 2) I know people who are actually interested in changing this *particular*
* aspect of server functionality without changing the rest of it. That's
* what this whole modular arrangement is supposed to be good at...
*
* Modified by Alexei Kosut to support the following constructs
*
* UserDir public_html -> ~bar/public_html/one/two.html
* NOTE: theses ^ ^ space only added allow it to work in a comment, ignore
* UserDir http://x/users -> (302) http://x/users/bar/one/two.html
* UserDir http://x/ * /y -> (302) http://x/bar/y/one/two.html
* NOTE: here also ^ ^
*
* In addition, you can use multiple entries, to specify alternate
* user directories (a la Directory Index). For example:
*
* UserDir public_html /usr/web http://www.xyz.com/users
*
* Modified by Ken Coar to provide for the following:
*
* UserDir disable[d] username ...
* UserDir enable[d] username ...
*
* If "disabled" has no other arguments, *all* ~<username> references are
* disabled, except those explicitly turned on with the "enabled" keyword.
*/
#include "apr_strings.h"
#include "apr_user.h"
#define APR_WANT_STRFUNC
#include "apr_want.h"
#include <unistd.h>
#endif
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_request.h"
#define HAVE_UNIX_SUEXEC
#endif
#ifdef HAVE_UNIX_SUEXEC
#include "unixd.h" /* Contains the suexec_identity hook used on Unix */
#endif
/* The default directory in user's home dir */
#ifndef DEFAULT_USER_DIR
#define DEFAULT_USER_DIR "public_html"
#endif
typedef struct {
int globally_disabled;
char *userdir;
/*
* Server config for this module: global disablement flag, a list of usernames
* ineligible for UserDir access, a list of those immune to global (but not
* explicit) disablement, and the replacement string for all others.
*/
{
newcfg->globally_disabled = 0;
return newcfg;
}
#define O_DEFAULT 0
#define O_ENABLE 1
#define O_DISABLE 2
{
char *username;
/* Since we are a raw argument, it is possible for us to be called with
* zero arguments. So that we aren't ambiguous, flat out reject this.
*/
if (*kw == '\0') {
return "UserDir requires an argument.";
}
/*
* Let's do the comparisons once.
*/
/*
* If there are no usernames specified, this is a global disable - we
* need do no more at this point than record the fact.
*/
return NULL;
}
}
/*
* 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.
*/
return "UserDir \"enable\" keyword requires a list of usernames";
}
}
else {
/*
* If the first (only?) value isn't one of our keywords, just copy
* the string to the userdir string.
*/
return NULL;
}
/*
* Now we just take each word in turn from the command line and add it to
* the appropriate table.
*/
while (*usernames) {
}
return NULL;
}
static const command_rec userdir_cmds[] = {
"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)
{
const userdir_config *s_cfg;
const char *userdirs;
const char *w, *dname;
char *redirect;
/*
* If the URI doesn't match our basic pattern, we've nothing to do with
* it.
*/
return DECLINED;
}
return DECLINED;
}
/*
* 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).
*/
--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.
*/
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
return DECLINED;
}
/*
* Special cases all checked, onward to normal substitution processing.
*/
while (*userdirs) {
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
*/
#else
#endif /* HAVE_DRIVE_LETTERS */
{
return HTTP_MOVED_TEMPORARILY;
}
else
}
else
}
else if (x && ap_strchr_c(x, ':')) {
return HTTP_MOVED_TEMPORARILY;
}
else {
#if APR_HAS_USER
char *homedir;
}
#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.
*/
r->pool)) == APR_SUCCESS
|| rv == APR_INCOMPLETE))) {
/* XXX: Does this walk us around FollowSymLink rules?
* When statbuf contains info on r->filename we can save a syscall
* by copying it to r->finfo
*/
/* For use in the get_suexec_identity phase */
return OK;
}
}
return DECLINED;
}
#ifdef HAVE_UNIX_SUEXEC
{
#if APR_HAS_USER
return NULL;
}
return NULL;
}
return NULL;
}
#endif
return ugid;
}
#endif /* HAVE_UNIX_SUEXEC */
static void register_hooks(apr_pool_t *p)
{
#ifdef HAVE_UNIX_SUEXEC
#endif
}
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 */
};