mod_dir.c revision 36ef8f77bffe75d1aa327882be1b5bdbe2ff567a
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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_dir.c: handle default index files, and trailing-/ redirects
*/
#include "apr_strings.h"
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_request.h"
#include "http_protocol.h"
#include "http_log.h"
#include "http_main.h"
#include "util_script.h"
typedef enum {
SLASH_OFF = 0,
} slash_cfg;
typedef struct dir_config_struct {
const char *dflt;
#define DIR_CMD_PERMS OR_INDEXES
{
dir_config_rec *d = dummy;
const char *t, *w;
int count = 0;
if (!d->index_names) {
}
t = arg;
/* peek to see if "disabled" is first in a series of arguments */
const char *tt = t;
/* "disabled" is first, and alone */
break;
}
}
*(const char **)apr_array_push(d->index_names) = w;
count++;
}
return NULL;
}
{
dir_config_rec *d = d_;
return NULL;
}
static const command_rec dir_cmds[] =
{
DIR_CMD_PERMS, "Set a default handler"),
"a list of file names"),
"On or Off"),
{NULL}
};
{
return (void *) new;
}
{
return new;
}
static int fixup_dflt(request_rec *r)
{
const char *name_ptr;
int error_notfound = 0;
return DECLINED;
}
return DECLINED;
}
/* XXX: if FallbackResource points to something that doesn't exist,
* this may recurse until it hits the limit for internal redirects
* before returning an Internal Server Error.
*/
/* The logic of this function is basically cloned and simplified
* from fixup_dir below. See the comments there.
*/
}
return OK;
}
rr->headers_out);
}
}
if (error_notfound) {
return error_notfound;
}
/* nothing for us to do, pass on through */
return DECLINED;
}
static int fixup_dir(request_rec *r)
{
dir_config_rec *d;
char *dummy_ptr[1];
char **names_ptr;
int num_names;
int error_notfound = 0;
/* only handle requests against directories */
return DECLINED;
}
/* In case mod_mime wasn't present, and no handler was assigned. */
if (!r->handler) {
r->handler = DIR_MAGIC_TYPE;
}
/* Never tolerate path_info on dir requests */
return DECLINED;
}
&dir_module);
/* Redirect requests that are not '/' terminated */
{
char *ifile;
if (!d->do_slash) {
return DECLINED;
}
/* Only redirect non-get requests if we have no note to warn
* that this browser cannot handle redirs on non-GET requests
* (such as Microsoft's WebFolders).
*/
if ((r->method_number != M_GET)
return DECLINED;
}
}
else {
"/", NULL);
}
return HTTP_MOVED_PERMANENTLY;
}
if (d->index_names) {
}
else {
dummy_ptr[0] = AP_DEFAULT_INDEX;
num_names = 1;
}
/* XXX: Is this name_ptr considered escaped yet, or not??? */
/* Once upon a time args were handled _after_ the successful redirect.
* But that redirect might then _refuse_ the given r->args, creating
* a nasty tangle. It seems safer to consider the r->args while we
* determine if name_ptr is our viable index, and therefore set them
* up correctly on redirect.
*/
}
/* The sub request lookup is very liberal, and the core map_to_storage
* handler will almost always result in HTTP_OK as /foo/index.html
* may be /foo with PATH_INFO="/index.html", or even / with
* PATH_INFO="/foo/index.html". To get around this we insist that the
* the index be a regular filetype.
*
* Another reason is that the core handler also makes the assumption
* that if r->finfo is still NULL by the time it gets called, the
* file does not exist.
*/
return OK;
}
/* If the request returned a redirect, propagate it to the client */
rr->headers_out);
return error_notfound;
}
/* If the request returned something other than 404 (or 200),
* it means the module encountered some sort of problem. To be
* secure, we should return the error, rather than allow autoindex
* to create a (possibly unsafe) directory index.
*
* So we store the error, and if none of the listed files
* exist, we return the last error response we got, instead
* of a directory listing.
*/
}
}
if (error_notfound) {
return error_notfound;
}
/* nothing for us to do, pass on through */
return DECLINED;
}
static void register_hooks(apr_pool_t *p)
{
/* the order of these is of no consequence */
}
AP_DECLARE_MODULE(dir) = {
create_dir_config, /* create per-directory config structure */
merge_dir_configs, /* merge per-directory config structures */
NULL, /* create per-server config structure */
NULL, /* merge per-server config structures */
dir_cmds, /* command apr_table_t */
register_hooks /* register hooks */
};