842ae4bd224140319ae7feec1872b93dfd491143fielding/* Licensed to the Apache Software Foundation (ASF) under one or more
842ae4bd224140319ae7feec1872b93dfd491143fielding * contributor license agreements. See the NOTICE file distributed with
842ae4bd224140319ae7feec1872b93dfd491143fielding * this work for additional information regarding copyright ownership.
842ae4bd224140319ae7feec1872b93dfd491143fielding * The ASF licenses this file to You under the Apache License, Version 2.0
842ae4bd224140319ae7feec1872b93dfd491143fielding * (the "License"); you may not use this file except in compliance with
842ae4bd224140319ae7feec1872b93dfd491143fielding * the License. You may obtain a copy of the License at
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * http://www.apache.org/licenses/LICENSE-2.0
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * Unless required by applicable law or agreed to in writing, software
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * distributed under the License is distributed on an "AS IS" BASIS,
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * See the License for the specific language governing permissions and
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * limitations under the License.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/*
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * mod_cern_meta.c
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * version 0.1.0
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * status beta
e8f95a682820a599fe41b22977010636be5c2717jim *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Andrew Wilson <Andrew.Wilson@cm.cf.ac.uk> 25.Jan.96
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * *** IMPORTANT ***
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * This version of mod_cern_meta.c controls Meta File behaviour on a
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * per-directory basis. Previous versions of the module defined behaviour
e8f95a682820a599fe41b22977010636be5c2717jim * on a per-server basis. The upshot is that you'll need to revisit your
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * configuration files in order to make use of the new module.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * ***
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Emulate the CERN HTTPD Meta file semantics. Meta files are HTTP
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * headers that can be output in addition to the normal range of
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * headers for each file accessed. They appear rather like the Apache
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * .asis files, and are able to provide a crude way of influencing
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * the Expires: header, as well as providing other curiosities.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * There are many ways to manage meta information, this one was
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * chosen because there is already a large number of CERN users
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * who can exploit this module. It should be noted that there are probably
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * more sensitive ways of managing the Expires: header specifically.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
e8f95a682820a599fe41b22977010636be5c2717jim * The module obeys the following directives, which can appear
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * in the server's .conf files and in .htaccess files.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
e8f95a682820a599fe41b22977010636be5c2717jim * MetaFiles <on|off>
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
e8f95a682820a599fe41b22977010636be5c2717jim * turns on|off meta file processing for any directory.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Default value is off
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * # turn on MetaFiles in this directory
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * MetaFiles on
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * MetaDir <directory name>
e8f95a682820a599fe41b22977010636be5c2717jim *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * specifies the name of the directory in which Apache can find
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * meta information files. The directory is usually a 'hidden'
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * subdirectory of the directory that contains the file being
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * accessed. eg:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
e8f95a682820a599fe41b22977010636be5c2717jim * # .meta files are in the *same* directory as the
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * # file being accessed
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * MetaDir .
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * the default is to look in a '.web' subdirectory. This is the
e8f95a682820a599fe41b22977010636be5c2717jim * same as for CERN 3.+ webservers and behaviour is the same as
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * for the directive:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * MetaDir .web
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * MetaSuffix <meta file suffix>
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * specifies the file name suffix for the file containing the
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * meta information. eg:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * # our meta files are suffixed with '.cern_meta'
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * MetaSuffix .cern_meta
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * the default is to look for files with the suffix '.meta'. This
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * behaviour is the same as for the directive:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * MetaSuffix .meta
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * When accessing the file
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * DOCUMENT_ROOT/somedir/index.html
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * this module will look for the file
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * DOCUMENT_ROOT/somedir/.web/index.html.meta
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
e8f95a682820a599fe41b22977010636be5c2717jim * and will use its contents to generate additional MIME header
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * information.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * For more information on the CERN Meta file semantics see:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * http://www.w3.org/hypertext/WWW/Daemon/User/Config/General.html#MetaDir
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Change-log:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * 29.Jan.96 pfopen/pfclose instead of fopen/fclose
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * DECLINE when real file not found, we may be checking each
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * of the index.html/index.shtml/index.htm variants and don't
e8f95a682820a599fe41b22977010636be5c2717jim * need to report missing ones as spurious errors.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * 31.Jan.96 log_error reports about a malformed .meta file, rather
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * than a script error.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * 20.Jun.96 MetaFiles <on|off> default off, added, so that module
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * can be configured per-directory. Prior to this the module
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * was running for each request anywhere on the server, naughty..
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * 29.Jun.96 All directives made per-directory.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
024cd9589e52cf11ce765dfddb5b5f0c6e421a48gstein#include "apr.h"
024cd9589e52cf11ce765dfddb5b5f0c6e421a48gstein#include "apr_strings.h"
024cd9589e52cf11ce765dfddb5b5f0c6e421a48gstein
024cd9589e52cf11ce765dfddb5b5f0c6e421a48gstein#define APR_WANT_STRFUNC
024cd9589e52cf11ce765dfddb5b5f0c6e421a48gstein#include "apr_want.h"
024cd9589e52cf11ce765dfddb5b5f0c6e421a48gstein
024cd9589e52cf11ce765dfddb5b5f0c6e421a48gstein#if APR_HAVE_SYS_TYPES_H
024cd9589e52cf11ce765dfddb5b5f0c6e421a48gstein#include <sys/types.h>
024cd9589e52cf11ce765dfddb5b5f0c6e421a48gstein#endif
024cd9589e52cf11ce765dfddb5b5f0c6e421a48gstein
9625528fcf4fa27288f3be080a1979c8ef60d7dfrbb#include "ap_config.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "httpd.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "http_config.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "util_script.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "http_log.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "http_request.h"
e9dacb49354baa7346837faad335f27caa7fe1eestoddard#include "http_protocol.h"
ff250fa78a491f4dcf3e673f122f2d9942a7411awrowe#include "apr_lib.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#define DIR_CMD_PERMS OR_INDEXES
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
66724147170b966b8ce54b0b5f9d9bcc67641b90nd#define DEFAULT_METADIR ".web"
66724147170b966b8ce54b0b5f9d9bcc67641b90nd#define DEFAULT_METASUFFIX ".meta"
66724147170b966b8ce54b0b5f9d9bcc67641b90nd#define DEFAULT_METAFILES 0
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
3d96ee83babeec32482c9082c9426340cee8c44dwrowemodule AP_MODULE_DECLARE_DATA cern_meta_module;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingtypedef struct {
ba09062ce0c7e0d6904a53aaf99896f5924b3989trawick const char *metadir;
ba09062ce0c7e0d6904a53aaf99896f5924b3989trawick const char *metasuffix;
ba09062ce0c7e0d6904a53aaf99896f5924b3989trawick int metafiles;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding} cern_meta_dir_config;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmstatic void *create_cern_meta_dir_config(apr_pool_t *p, char *dummy)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding cern_meta_dir_config *new =
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm (cern_meta_dir_config *) apr_palloc(p, sizeof(cern_meta_dir_config));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->metadir = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->metasuffix = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->metafiles = DEFAULT_METAFILES;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return new;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmstatic void *merge_cern_meta_dir_configs(apr_pool_t *p, void *basev, void *addv)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding cern_meta_dir_config *base = (cern_meta_dir_config *) basev;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding cern_meta_dir_config *add = (cern_meta_dir_config *) addv;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding cern_meta_dir_config *new =
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm (cern_meta_dir_config *) apr_palloc(p, sizeof(cern_meta_dir_config));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->metadir = add->metadir ? add->metadir : base->metadir;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->metasuffix = add->metasuffix ? add->metasuffix : base->metasuffix;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->metafiles = add->metafiles;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return new;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
ba09062ce0c7e0d6904a53aaf99896f5924b3989trawickstatic const char *set_metadir(cmd_parms *parms, void *in_dconf, const char *arg)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
ba09062ce0c7e0d6904a53aaf99896f5924b3989trawick cern_meta_dir_config *dconf = in_dconf;
ba09062ce0c7e0d6904a53aaf99896f5924b3989trawick
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding dconf->metadir = arg;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
ba09062ce0c7e0d6904a53aaf99896f5924b3989trawickstatic const char *set_metasuffix(cmd_parms *parms, void *in_dconf, const char *arg)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
ba09062ce0c7e0d6904a53aaf99896f5924b3989trawick cern_meta_dir_config *dconf = in_dconf;
ba09062ce0c7e0d6904a53aaf99896f5924b3989trawick
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding dconf->metasuffix = arg;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
ba09062ce0c7e0d6904a53aaf99896f5924b3989trawickstatic const char *set_metafiles(cmd_parms *parms, void *in_dconf, int arg)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
ba09062ce0c7e0d6904a53aaf99896f5924b3989trawick cern_meta_dir_config *dconf = in_dconf;
ba09062ce0c7e0d6904a53aaf99896f5924b3989trawick
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding dconf->metafiles = arg;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic const command_rec cern_meta_cmds[] =
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
ba09062ce0c7e0d6904a53aaf99896f5924b3989trawick AP_INIT_FLAG("MetaFiles", set_metafiles, NULL, DIR_CMD_PERMS,
ba09062ce0c7e0d6904a53aaf99896f5924b3989trawick "Limited to 'on' or 'off'"),
ba09062ce0c7e0d6904a53aaf99896f5924b3989trawick AP_INIT_TAKE1("MetaDir", set_metadir, NULL, DIR_CMD_PERMS,
ba09062ce0c7e0d6904a53aaf99896f5924b3989trawick "the name of the directory containing meta files"),
ba09062ce0c7e0d6904a53aaf99896f5924b3989trawick AP_INIT_TAKE1("MetaSuffix", set_metasuffix, NULL, DIR_CMD_PERMS,
ba09062ce0c7e0d6904a53aaf99896f5924b3989trawick "the filename suffix for meta files"),
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding {NULL}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding};
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* XXX: this is very similar to ap_scan_script_header_err_core...
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * are the differences deliberate, or just a result of bit rot?
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmstatic int scan_meta_file(request_rec *r, apr_file_t *f)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char w[MAX_STRING_LEN];
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *l;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int p;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_table_t *tmp_headers;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
066877f1a045103acfdd376d48cdd473c33f409bdougm tmp_headers = apr_table_make(r->pool, 5);
066877f1a045103acfdd376d48cdd473c33f409bdougm while (apr_file_gets(w, MAX_STRING_LEN - 1, f) == APR_SUCCESS) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
66724147170b966b8ce54b0b5f9d9bcc67641b90nd /* Delete terminal (CR?)LF */
66724147170b966b8ce54b0b5f9d9bcc67641b90nd p = strlen(w);
66724147170b966b8ce54b0b5f9d9bcc67641b90nd if (p > 0 && w[p - 1] == '\n') {
66724147170b966b8ce54b0b5f9d9bcc67641b90nd if (p > 1 && w[p - 2] == '\015')
66724147170b966b8ce54b0b5f9d9bcc67641b90nd w[p - 2] = '\0';
66724147170b966b8ce54b0b5f9d9bcc67641b90nd else
66724147170b966b8ce54b0b5f9d9bcc67641b90nd w[p - 1] = '\0';
66724147170b966b8ce54b0b5f9d9bcc67641b90nd }
66724147170b966b8ce54b0b5f9d9bcc67641b90nd
66724147170b966b8ce54b0b5f9d9bcc67641b90nd if (w[0] == '\0') {
66724147170b966b8ce54b0b5f9d9bcc67641b90nd return OK;
66724147170b966b8ce54b0b5f9d9bcc67641b90nd }
66724147170b966b8ce54b0b5f9d9bcc67641b90nd
66724147170b966b8ce54b0b5f9d9bcc67641b90nd /* if we see a bogus header don't ignore it. Shout and scream */
66724147170b966b8ce54b0b5f9d9bcc67641b90nd
66724147170b966b8ce54b0b5f9d9bcc67641b90nd if (!(l = strchr(w, ':'))) {
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01560)
66724147170b966b8ce54b0b5f9d9bcc67641b90nd "malformed header in meta file: %s", r->filename);
66724147170b966b8ce54b0b5f9d9bcc67641b90nd return HTTP_INTERNAL_SERVER_ERROR;
66724147170b966b8ce54b0b5f9d9bcc67641b90nd }
66724147170b966b8ce54b0b5f9d9bcc67641b90nd
66724147170b966b8ce54b0b5f9d9bcc67641b90nd *l++ = '\0';
75b4c883b2ef72e0104b8b206f3408dbd1d36768jailletc while (apr_isspace(*l))
66724147170b966b8ce54b0b5f9d9bcc67641b90nd ++l;
66724147170b966b8ce54b0b5f9d9bcc67641b90nd
66724147170b966b8ce54b0b5f9d9bcc67641b90nd if (!strcasecmp(w, "Content-type")) {
66724147170b966b8ce54b0b5f9d9bcc67641b90nd char *tmp;
66724147170b966b8ce54b0b5f9d9bcc67641b90nd /* Nuke trailing whitespace */
66724147170b966b8ce54b0b5f9d9bcc67641b90nd
66724147170b966b8ce54b0b5f9d9bcc67641b90nd char *endp = l + strlen(l) - 1;
66724147170b966b8ce54b0b5f9d9bcc67641b90nd while (endp > l && apr_isspace(*endp))
66724147170b966b8ce54b0b5f9d9bcc67641b90nd *endp-- = '\0';
66724147170b966b8ce54b0b5f9d9bcc67641b90nd
66724147170b966b8ce54b0b5f9d9bcc67641b90nd tmp = apr_pstrdup(r->pool, l);
66724147170b966b8ce54b0b5f9d9bcc67641b90nd ap_content_type_tolower(tmp);
66724147170b966b8ce54b0b5f9d9bcc67641b90nd ap_set_content_type(r, tmp);
66724147170b966b8ce54b0b5f9d9bcc67641b90nd }
66724147170b966b8ce54b0b5f9d9bcc67641b90nd else if (!strcasecmp(w, "Status")) {
66724147170b966b8ce54b0b5f9d9bcc67641b90nd sscanf(l, "%d", &r->status);
66724147170b966b8ce54b0b5f9d9bcc67641b90nd r->status_line = apr_pstrdup(r->pool, l);
66724147170b966b8ce54b0b5f9d9bcc67641b90nd }
66724147170b966b8ce54b0b5f9d9bcc67641b90nd else {
66724147170b966b8ce54b0b5f9d9bcc67641b90nd apr_table_set(tmp_headers, w, l);
66724147170b966b8ce54b0b5f9d9bcc67641b90nd }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
066877f1a045103acfdd376d48cdd473c33f409bdougm apr_table_overlap(r->headers_out, tmp_headers, APR_OVERLAP_TABLES_SET);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return OK;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic int add_cern_meta_data(request_rec *r)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *metafilename;
f3259946a9f26eb57f0eeb3fb0e840da809c5495stoddard char *leading_slash;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *last_slash;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *real_file;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *scrap_book;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_file_t *f = NULL;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_status_t retcode;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding cern_meta_dir_config *dconf;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int rv;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding request_rec *rr;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding dconf = ap_get_module_config(r->per_dir_config, &cern_meta_module);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!dconf->metafiles) {
66724147170b966b8ce54b0b5f9d9bcc67641b90nd return DECLINED;
4716af1325aa569053fab49fd588707d9e910faetrawick }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* if ./.web/$1.meta exists then output 'asis' */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
2d4ea77e21ef7f3707d2c27f6117cc0a36e99b83trawick if (r->finfo.filetype == APR_NOFILE) {
66724147170b966b8ce54b0b5f9d9bcc67641b90nd return DECLINED;
4716af1325aa569053fab49fd588707d9e910faetrawick }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* is this a directory? */
d9f2c22804bcbc9ad07d4ec18fbb8aa7c042dcd0bjh if (r->finfo.filetype == APR_DIR || r->uri[strlen(r->uri) - 1] == '/') {
66724147170b966b8ce54b0b5f9d9bcc67641b90nd return DECLINED;
4716af1325aa569053fab49fd588707d9e910faetrawick }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* what directory is this file in? */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm scrap_book = apr_pstrdup(r->pool, r->filename);
f3259946a9f26eb57f0eeb3fb0e840da809c5495stoddard
f3259946a9f26eb57f0eeb3fb0e840da809c5495stoddard leading_slash = strchr(scrap_book, '/');
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding last_slash = strrchr(scrap_book, '/');
f3259946a9f26eb57f0eeb3fb0e840da809c5495stoddard if ((last_slash != NULL) && (last_slash != leading_slash)) {
66724147170b966b8ce54b0b5f9d9bcc67641b90nd /* skip over last slash */
66724147170b966b8ce54b0b5f9d9bcc67641b90nd real_file = last_slash;
66724147170b966b8ce54b0b5f9d9bcc67641b90nd real_file++;
66724147170b966b8ce54b0b5f9d9bcc67641b90nd *last_slash = '\0';
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
66724147170b966b8ce54b0b5f9d9bcc67641b90nd /* no last slash, buh?! */
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01561)
66724147170b966b8ce54b0b5f9d9bcc67641b90nd "internal error in mod_cern_meta: %s", r->filename);
66724147170b966b8ce54b0b5f9d9bcc67641b90nd /* should really barf, but hey, let's be friends... */
66724147170b966b8ce54b0b5f9d9bcc67641b90nd return DECLINED;
4716af1325aa569053fab49fd588707d9e910faetrawick }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
f3259946a9f26eb57f0eeb3fb0e840da809c5495stoddard metafilename = apr_pstrcat(r->pool, scrap_book, "/",
66724147170b966b8ce54b0b5f9d9bcc67641b90nd dconf->metadir ? dconf->metadir : DEFAULT_METADIR,
66724147170b966b8ce54b0b5f9d9bcc67641b90nd "/", real_file,
66724147170b966b8ce54b0b5f9d9bcc67641b90nd dconf->metasuffix ? dconf->metasuffix : DEFAULT_METASUFFIX,
66724147170b966b8ce54b0b5f9d9bcc67641b90nd NULL);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
c5b6ab7b079b3fe0f13115786ad52dff3c0af87cwrowe /* It sucks to require this subrequest to complete, because this
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * means people must leave their meta files accessible to the world.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * A better solution might be a "safe open" feature of pfopen to avoid
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * pipes, symlinks, and crap like that.
c5b6ab7b079b3fe0f13115786ad52dff3c0af87cwrowe *
c5b6ab7b079b3fe0f13115786ad52dff3c0af87cwrowe * In fact, this doesn't suck. Because <Location > blocks are never run
c5b6ab7b079b3fe0f13115786ad52dff3c0af87cwrowe * against sub_req_lookup_file, the meta can be somewhat protected by
c5b6ab7b079b3fe0f13115786ad52dff3c0af87cwrowe * either masking it with a <Location > directive or alias, or stowing
c5b6ab7b079b3fe0f13115786ad52dff3c0af87cwrowe * the file outside of the web document tree, while providing the
c5b6ab7b079b3fe0f13115786ad52dff3c0af87cwrowe * appropriate directory blocks to allow access to it as a file.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
85bea52867bd1a8c81080ba415b5cd5b771ce5f7gstein rr = ap_sub_req_lookup_file(metafilename, r, NULL);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (rr->status != HTTP_OK) {
66724147170b966b8ce54b0b5f9d9bcc67641b90nd ap_destroy_sub_req(rr);
66724147170b966b8ce54b0b5f9d9bcc67641b90nd return DECLINED;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_destroy_sub_req(rr);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
1f78f6d87f69c241a3e903a46bae4666d17a8513trawick retcode = apr_file_open(&f, metafilename, APR_READ, APR_OS_DEFAULT, r->pool);
1465b960f95b4afba4f4221054dd09e11509bd40rbb if (retcode != APR_SUCCESS) {
66724147170b966b8ce54b0b5f9d9bcc67641b90nd if (APR_STATUS_IS_ENOENT(retcode)) {
66724147170b966b8ce54b0b5f9d9bcc67641b90nd return DECLINED;
66724147170b966b8ce54b0b5f9d9bcc67641b90nd }
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01562)
66724147170b966b8ce54b0b5f9d9bcc67641b90nd "meta file permissions deny server access: %s", metafilename);
66724147170b966b8ce54b0b5f9d9bcc67641b90nd return HTTP_FORBIDDEN;
4716af1325aa569053fab49fd588707d9e910faetrawick }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* read the headers in */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding rv = scan_meta_file(r, f);
066877f1a045103acfdd376d48cdd473c33f409bdougm apr_file_close(f);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return rv;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
73e8b26287de5c06fa470d36162e103dbac9c7e5wrowe
73e8b26287de5c06fa470d36162e103dbac9c7e5wrowestatic void register_hooks(apr_pool_t *p)
577a76180006add04a166b12f1ad130aeedeaa5estoddard{
b980ad7fdc218b4855cde9f75a747527f50c554dwrowe ap_hook_fixups(add_cern_meta_data,NULL,NULL,APR_HOOK_MIDDLE);
577a76180006add04a166b12f1ad130aeedeaa5estoddard}
73e8b26287de5c06fa470d36162e103dbac9c7e5wrowe
36ef8f77bffe75d1aa327882be1b5bdbe2ff567asfAP_DECLARE_MODULE(cern_meta) =
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
577a76180006add04a166b12f1ad130aeedeaa5estoddard STANDARD20_MODULE_STUFF,
66724147170b966b8ce54b0b5f9d9bcc67641b90nd create_cern_meta_dir_config, /* dir config creater */
66724147170b966b8ce54b0b5f9d9bcc67641b90nd merge_cern_meta_dir_configs, /* dir merger --- default is to override */
66724147170b966b8ce54b0b5f9d9bcc67641b90nd NULL, /* server config */
66724147170b966b8ce54b0b5f9d9bcc67641b90nd NULL, /* merge server configs */
66724147170b966b8ce54b0b5f9d9bcc67641b90nd cern_meta_cmds, /* command apr_table_t */
66724147170b966b8ce54b0b5f9d9bcc67641b90nd register_hooks /* register hooks */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding};