mod_include.c revision 3633fb691373bb8b1ddc9c801ba25c367cf5e5a3
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*
* Portions of this software are based upon public domain software
* originally written at the National Center for Supercomputing Applications,
* University of Illinois, Urbana-Champaign.
*/
/*
* http_include.c: Handles the server-parsed HTML documents
*
* Original by Rob McCool; substantial fixups by David Robinson;
* incorporated into the Apache module framework by rst.
*
*/
#include "apr.h"
#include "apr_strings.h"
#include "apr_thread_proc.h"
#include "apr_hash.h"
#include "apr_user.h"
#include "apr_lib.h"
#include "apr_optional.h"
#define APR_WANT_STRFUNC
#define APR_WANT_MEMFUNC
#include "apr_want.h"
#include "ap_config.h"
#include "util_filter.h"
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_request.h"
#include "http_core.h"
#include "http_protocol.h"
#include "http_log.h"
#include "http_main.h"
#include "util_script.h"
#include "http_core.h"
#include "mod_include.h"
/* helper for Latin1 <-> entity encoding */
#include "util_ebcdic.h"
(unsigned char)ch)
#else /* APR_CHARSET_EBCDIC */
#endif /* !APR_CHARSET_EBCDIC */
/*
* +-------------------------------------------------------+
* | |
* | Debugging Macros
* | |
* +-------------------------------------------------------+
*/
#ifdef DEBUG_INCLUDE
#define MAX_DEBUG_SIZE MAX_STRING_LEN
do { \
"\"\n", NULL); \
} while(0)
do { \
} while(0)
#else
#define MAX_DEBUG_SIZE 10
#endif
/*
* +-------------------------------------------------------+
* | |
* | Types and Structures
* | |
* +-------------------------------------------------------+
*/
typedef enum {
} xbithack_t;
typedef struct {
unsigned int T[256];
unsigned int x;
} bndm_t;
typedef struct {
const char *default_error_msg;
const char *default_time_fmt;
typedef struct {
const char *default_start_tag;
const char *default_end_tag;
const char *undefined_echo;
/* main parser states */
typedef enum {
typedef struct arg_item {
char *name;
char *value;
} arg_item_t;
struct ssi_internal_ctx {
int seen_eos;
int error;
char quote; /* quote character value (or \0) */
request_rec *r;
const char *start_seq;
const char *end_seq;
char *directive; /* name of the current directive */
char *error_str_override;
char *time_str_override;
char *re_string;
};
/*
* +-------------------------------------------------------+
* | |
* | Static Module Data
* | |
* +-------------------------------------------------------+
*/
/* global module structure */
/* function handlers for include directives */
static apr_hash_t *include_handlers;
/* forward declaration of handler registry */
/* Sentinel value to store in subprocess_env for items that
*/
static const char lazy_eval_sentinel;
#define LAZY_VALUE (&lazy_eval_sentinel)
/* default values */
#define DEFAULT_START_SEQUENCE "<!--#"
#define DEFAULT_END_SEQUENCE "-->"
#define DEFAULT_ERROR_MSG "[an error occurred while processing this directive]"
#define DEFAULT_TIME_FORMAT "%A, %d-%b-%Y %H:%M:%S %Z"
#define DEFAULT_UNDEFINED_ECHO "(none)"
#ifdef XBITHACK
#define DEFAULT_XBITHACK XBITHACK_FULL
#else
#define DEFAULT_XBITHACK XBITHACK_OFF
#endif
/*
* +-------------------------------------------------------+
* | |
* | Environment/Expansion Functions
* | |
* +-------------------------------------------------------+
*/
/*
* decodes a string containing html entities or numeric character references.
* 's' is overwritten with the decoded string.
* If 's' is syntatically incorrect, then the followed fixups will be made:
* unknown entities will be left undecoded;
* references to unused numeric characters will be deleted.
* In particular, � will not be decoded, but will be deleted.
*/
/* maximum length of any ISO-LATIN-1 HTML entity name. */
#define MAXENTLEN (6)
/* The following is a shrinking transformation, therefore safe. */
static void decodehtml(char *s)
{
int val, i, j;
char *p;
const char *ents;
{
NULL, /* 0 */
NULL, /* 1 */
"lt\074gt\076", /* 2 */
"amp\046ETH\320eth\360", /* 3 */
"quot\042Auml\304Euml\313Iuml\317Ouml\326Uuml\334auml\344euml\353\
iuml\357ouml\366uuml\374yuml\377", /* 4 */
"Acirc\302Aring\305AElig\306Ecirc\312Icirc\316Ocirc\324Ucirc\333\
THORN\336szlig\337acirc\342aring\345aelig\346ecirc\352icirc\356ocirc\364\
ucirc\373thorn\376", /* 5 */
"Agrave\300Aacute\301Atilde\303Ccedil\307Egrave\310Eacute\311\
Igrave\314Iacute\315Ntilde\321Ograve\322Oacute\323Otilde\325Oslash\330\
Ugrave\331Uacute\332Yacute\335agrave\340aacute\341atilde\343ccedil\347\
egrave\350eacute\351igrave\354iacute\355ntilde\361ograve\362oacute\363\
otilde\365oslash\370ugrave\371uacute\372yacute\375" /* 6 */
};
/* Do a fast scan through the string until we find anything
* that needs more complicated handling
*/
for (; *s != '&'; s++) {
if (*s == '\0') {
return;
}
}
for (p = s; *s != '\0'; s++, p++) {
if (*s != '&') {
*p = *s;
continue;
}
/* find end of entity */
for (i = 1; s[i] != ';' && s[i] != '\0'; i++) {
continue;
}
if (s[i] == '\0') { /* treat as normal data */
*p = *s;
continue;
}
/* is it numeric ? */
if (s[1] == '#') {
}
s += i;
p--; /* no data to output */
}
else {
*p = RAW_ASCII_CHAR(val);
}
}
else {
j = i - 1;
/* wrong length */
*p = '&';
continue; /* skip it */
}
break;
}
}
if (*ents == '\0') {
*p = '&'; /* unknown */
}
else {
*p = RAW_ASCII_CHAR(((const unsigned char *) ents)[j]);
s += i;
}
}
}
*p = '\0';
}
{
apr_table_t *e = r->subprocess_env;
char *t;
}
apr_table_setn(e, "DOCUMENT_NAME", ++t);
}
else {
}
if (r->args) {
apr_table_setn(e, "QUERY_STRING_UNESCAPED",
}
}
{
char *val;
}
}
}
val = "<unknown>";
}
}
else {
}
if (val) {
}
return val;
}
const char *var)
{
const char *val;
/* Handle $0 .. $9 from the last regex evaluated.
* The choice of returning NULL strings on not-found,
* v.s. empty strings on an empty match is deliberate.
*/
return NULL;
}
else {
return NULL;
}
}
}
else {
if (val == LAZY_VALUE)
}
return val;
}
/* initial buffer size for power-of-two allocator in ap_ssi_parse_string */
#define PARSE_STRING_INITIAL_SIZE 64
/*
* Do variable substitution on strings
* (Note: If out==NULL, this function allocs a buffer for the resulting
* string from r->pool. The return value is the parsed string)
*/
{
char ch;
char *next;
char *end_out;
/* allocate an output buffer if needed */
if (!out) {
}
}
else {
}
/* leave room for nul terminator */
switch (ch) {
case '\\':
/* double the buffer size */
char *new_out;
if (new_out_size > length) {
}
}
else {
/* truncated */
*next = '\0';
return out;
}
}
if (*in == '$') {
}
else {
}
break;
case '$':
{
const char *start_of_var_name;
char *end_of_var_name; /* end of var name + 1 */
char tmp_store;
apr_size_t l;
/* guess that the expansion won't happen */
if (*in == '{') {
++in;
0, r, "Missing '}' on variable \"%s\"",
*next = '\0';
return out;
}
end_of_var_name = (char *)temp_end;
++in;
}
else {
++in;
}
end_of_var_name = (char *)temp_end;
}
/* what a pain, too bad there's no table_getn where you can
* pass a non-nul terminated string */
l = end_of_var_name - start_of_var_name;
if (l != 0) {
*end_of_var_name = '\0';
if (val) {
}
else if (leave_name) {
}
else {
/* no expansion to be done */
break;
}
}
else {
/* zero-length variable name causes just the $ to be
* copied */
l = 1;
}
/* increase the buffer size to accommodate l more chars */
char *new_out;
do {
new_out_size *= 2;
} while (new_out_size < current_length + l);
if (new_out_size > length) {
}
}
next += l;
break;
}
default:
/* double the buffer size */
char *new_out;
if (new_out_size > length) {
}
}
else {
/* truncated */
*next = '\0';
return out;
}
}
break;
}
}
*next = '\0';
return out;
}
/*
* +-------------------------------------------------------+
* | |
* | Conditional Expression Parser
* | |
* +-------------------------------------------------------+
*/
{
int regex_error;
"unable to compile pattern \"%s\"", rexp);
return -1;
}
}
return (!regex_error);
}
enum token_type {
};
struct token {
enum token_type type;
char* value;
};
{
char ch;
int next = 0;
char qs = 0;
int tkn_fnd = 0;
/* Skip leading white space */
return (char *) NULL;
}
if (!apr_isspace(ch)) {
break;
}
}
if (ch == '\0') {
return (char *) NULL;
}
switch (ch) {
case '(':
return (string);
case ')':
return (string);
case '=':
return (string);
case '!':
if (*string == '=') {
return (string + 1);
}
else {
return (string);
}
case '\'':
/* already token->type == token_string */
qs = '\'';
break;
case '/':
qs = '/';
break;
case '|':
if (*string == '|') {
return (string + 1);
}
break;
case '&':
if (*string == '&') {
return (string + 1);
}
break;
case '>':
if (*string == '=') {
return (string + 1);
}
else {
return (string);
}
case '<':
if (*string == '=') {
return (string + 1);
}
else {
return (string);
}
default:
/* already token->type == token_string */
break;
}
/* We should only be here if we are in a string */
trailing null */
if (!qs) {
}
/*
* I used the ++string throughout this section so that string
* ends up pointing to the next token and I can just return it
*/
if (ch == '\\') {
tkn_fnd = 1;
}
else {
}
}
else {
if (!qs) {
if (apr_isspace(ch)) {
tkn_fnd = 1;
}
else {
switch (ch) {
case '(':
case ')':
case '=':
case '!':
case '<':
case '>':
tkn_fnd = 1;
break;
case '|':
tkn_fnd = 1;
}
break;
case '&':
tkn_fnd = 1;
}
break;
}
if (!tkn_fnd) {
}
}
}
else {
qs = 0;
tkn_fnd = 1;
string++;
}
else {
}
}
}
if (tkn_fnd) {
break;
}
}
/* If qs is still set, we have an unmatched quote */
if (qs) {
*unmatched = 1;
next = 0;
}
return (string);
}
/* there is an implicit assumption here that expr is at most MAX_STRING_LEN-1
* characters long...
*/
{
struct parse_node {
const char *parse;
char* buffer;
int retval = 0;
apr_size_t debug_pos = 0;
*was_error = 0;
*was_unmatched = 0;
return (0);
}
/* Create Parse Tree */
while (1) {
sizeof(struct parse_node));
(char *) NULL) {
break;
}
case token_string:
#ifdef DEBUG_INCLUDE
" Token: string (%s)\n",
#endif
break;
}
case token_string:
NULL);
break;
case token_eq:
case token_ne:
case token_and:
case token_or:
case token_lbrace:
case token_not:
case token_ge:
case token_gt:
case token_le:
case token_lt:
break;
default:
"Invalid expression \"%s\" in file %s",
*was_error = 1;
return retval;
}
break;
case token_re:
#ifdef DEBUG_INCLUDE
" Token: regex (%s)\n",
#endif
break;
}
case token_eq:
case token_ne:
case token_and:
case token_or:
case token_lbrace:
case token_not:
break;
default:
"Invalid expression \"%s\" in file %s",
*was_error = 1;
return retval;
}
break;
case token_and:
case token_or:
#ifdef DEBUG_INCLUDE
#endif
"Invalid expression \"%s\" in file %s",
*was_error = 1;
return retval;
}
/* Percolate upwards */
case token_string:
case token_re:
case token_group:
case token_not:
case token_eq:
case token_ne:
case token_and:
case token_or:
case token_ge:
case token_gt:
case token_le:
case token_lt:
continue;
case token_lbrace:
break;
default:
"Invalid expression \"%s\" in file %s",
*was_error = 1;
return retval;
}
break;
}
}
else {
}
break;
case token_not:
#ifdef DEBUG_INCLUDE
sizeof(" Token: not\n"));
debug_pos += sizeof(" Token: not\n");
#endif
break;
}
/* Percolate upwards */
case token_not:
case token_eq:
case token_ne:
case token_and:
case token_or:
case token_lbrace:
case token_ge:
case token_gt:
case token_le:
case token_lt:
break;
default:
"Invalid expression \"%s\" in file %s",
*was_error = 1;
return retval;
}
}
}
else {
}
break;
case token_eq:
case token_ne:
case token_ge:
case token_gt:
case token_le:
case token_lt:
#ifdef DEBUG_INCLUDE
#endif
"Invalid expression \"%s\" in file %s",
*was_error = 1;
return retval;
}
/* Percolate upwards */
case token_string:
case token_re:
case token_group:
continue;
case token_lbrace:
case token_and:
case token_or:
break;
case token_not:
case token_eq:
case token_ne:
case token_ge:
case token_gt:
case token_le:
case token_lt:
default:
"Invalid expression \"%s\" in file %s",
*was_error = 1;
return retval;
}
break;
}
}
else {
}
break;
case token_rbrace:
#ifdef DEBUG_INCLUDE
sizeof (" Token: rbrace\n"));
debug_pos += sizeof (" Token: rbrace\n");
#endif
break;
}
}
"Unmatched ')' in \"%s\" in file %s",
*was_error = 1;
return retval;
}
break;
case token_lbrace:
#ifdef DEBUG_INCLUDE
sizeof (" Token: lbrace\n"));
debug_pos += sizeof (" Token: lbrace\n");
#endif
break;
}
/* Percolate upwards */
case token_not:
case token_eq:
case token_ne:
case token_and:
case token_or:
case token_lbrace:
case token_ge:
case token_gt:
case token_le:
case token_lt:
break;
case token_string:
case token_re:
case token_group:
default:
"Invalid expression \"%s\" in file %s",
*was_error = 1;
return retval;
}
}
}
else {
}
break;
default:
break;
}
}
/* Evaluate Parse Tree */
case token_string:
#ifdef DEBUG_INCLUDE
sizeof (" Evaluate string\n"));
debug_pos += sizeof (" Evaluate string\n");
#endif
MAX_STRING_LEN, 0);
break;
case token_re:
"No operator before regex of expr \"%s\" in file %s",
*was_error = 1;
return retval;
case token_and:
case token_or:
#ifdef DEBUG_INCLUDE
#endif
"Invalid expression \"%s\" in file %s",
*was_error = 1;
return retval;
}
case token_string:
NULL, MAX_STRING_LEN, 0);
break;
default:
continue;
}
}
case token_string:
NULL, MAX_STRING_LEN, 0);
break;
default:
continue;
}
}
#ifdef DEBUG_INCLUDE
#endif
}
else {
}
#ifdef DEBUG_INCLUDE
#endif
break;
case token_eq:
case token_ne:
#ifdef DEBUG_INCLUDE
#endif
"Invalid expression \"%s\" in file %s",
*was_error = 1;
return retval;
}
NULL, MAX_STRING_LEN, 0);
NULL, MAX_STRING_LEN, 0);
#ifdef DEBUG_INCLUDE
" Re Compare (%s) with /%s/\n",
#endif
}
else {
#ifdef DEBUG_INCLUDE
" Compare (%s) with (%s)\n",
#endif
}
}
#ifdef DEBUG_INCLUDE
#endif
break;
case token_ge:
case token_gt:
case token_le:
case token_lt:
#ifdef DEBUG_INCLUDE
#endif
"Invalid expression \"%s\" in file %s",
*was_error = 1;
return retval;
}
NULL, MAX_STRING_LEN, 0);
NULL, MAX_STRING_LEN, 0);
#ifdef DEBUG_INCLUDE
" Compare (%s) with (%s)\n",
#endif
}
}
}
}
else {
}
#ifdef DEBUG_INCLUDE
#endif
break;
case token_not:
continue;
}
}
else {
}
#ifdef DEBUG_INCLUDE
#endif
break;
case token_group:
continue;
}
}
else {
}
#ifdef DEBUG_INCLUDE
#endif
break;
case token_lbrace:
"Unmatched '(' in \"%s\" in file %s",
*was_error = 1;
return retval;
case token_rbrace:
"Unmatched ')' in \"%s\" in file %s",
*was_error = 1;
return retval;
default:
"bad token type");
*was_error = 1;
return retval;
}
}
return (retval);
}
/*
* +-------------------------------------------------------+
* | |
* | Action Handlers
* | |
* +-------------------------------------------------------+
*/
/*
* Extract the next tag name and value.
* If there are no more tags, set the tag name to NULL.
* The tag value is html decoded if dodecode is non-zero.
* The tag value may be NULL if there is no tag value..
*/
{
return;
}
}
return;
}
/* ensure that path is relative, and does not contain ".." elements
* ensentially ensure that it does not match the regex:
* (^/|(^|/)\.\.(/|$))
* XXX: Simply replace with apr_filepath_merge
*/
static int is_only_below(const char *path)
{
#ifdef HAVE_DRIVE_LETTERS
return 0;
#endif
#ifdef NETWARE
return 0;
#endif
if (path[0] == '/') {
return 0;
}
while (*path) {
int dots = 0;
++dots;
#if defined(WIN32)
/* If the name is canonical this is redundant
* but in security, redundancy is worthwhile.
* Does OS2 belong here (accepts ... for ..)?
*/
return 0;
#else
return 0;
#endif
/* Advance to either the null byte at the end of the
* string or the character right after the next slash,
* whichever comes first
*/
continue;
}
}
return 1;
}
{
int ret=0;
/* XXX: Port to apr_filepath_merge
* be safe; only files in this directory or below allowed
*/
if (!is_only_below(tag_val)) {
error_fmt = "unable to access file \"%s\" "
"in parsed file %s";
}
else {
/* note: it is okay to pass NULL for the "next filter" since
we never attempt to "run" this sub request. */
&& rv != APR_INCOMPLETE) {
error_fmt = "unable to get information about \"%s\" "
"in parsed file %s";
}
}
else {
error_fmt = "unable to lookup information about \"%s\" "
"in parsed file %s";
}
}
if (error_fmt) {
ret = -1;
}
return ret;
}
/* note: it is okay to pass NULL for the "next filter" since
we never attempt to "run" this sub request. */
return 0;
}
else {
"unable to get information about \"%s\" "
"in parsed file %s",
return -1;
}
}
else {
"unknown parameter \"%s\" to tag %s in %s",
return -1;
}
}
/*
* <!--#include virtual|file="..." [virtual|file="..."] ... -->
*/
{
request_rec *r = f->r;
? APLOG_ERR : APLOG_WARNING,
0, r, "missing argument for include element in %s",
r->filename);
}
return APR_SUCCESS;
}
return APR_SUCCESS;
}
while (1) {
char *parsed_string;
break;
}
break;
}
if (tag[0] == 'f') {
/* XXX: Port to apr_filepath_merge
* be safe; only files in this directory or below allowed
*/
if (!is_only_below(parsed_string)) {
error_fmt = "unable to include file \"%s\" in parsed file %s";
}
else {
}
}
else {
}
error_fmt = "unable to include \"%s\" in parsed file %s";
}
error_fmt = "unable to include potential exec \"%s\" in parsed "
"file %s";
}
if (!error_fmt) {
int founddupe = 0;
request_rec *p, *q;
/* try to avoid recursive includes. We do this by walking
* up the r->main list of subrequests, and at each level
* walking back through any internal redirects. At each
* step, we compare the filenames and the URIs.
*
* The filename comparison catches a recursive include
* with an ever-changing URL, eg.
* <!--#include virtual=
* "$REQUEST_URI/$QUERY_STRING?$QUERY_STRING/x" -->
* which, although they would eventually be caught because
* we have a limit on the length of files, etc., can
* recurse for a while.
*
* The URI comparison catches the case where the filename
* is changed while processing the request, so the
* current name is never the same as any previous one.
* This can happen with "DocumentRoot /foo" when you
* request "/" on the server and it includes "/".
* This only applies to modules such as mod_dir that
* (somewhat improperly) mess with r->filename outside
* of a filename translation phase.
*/
for (q = p; q; q = q->prev) {
((*q->uri == '/') &&
founddupe = 1;
break;
}
}
}
if (p) {
error_fmt = "Recursive include of \"%s\" in parsed file %s";
}
}
/* See the Kludge in includes_filter for why.
* Basically, it puts a bread crumb in here, then looks
* for the crumb later to see if its been here.
*/
if (rr) {
}
error_fmt = "unable to include \"%s\" in parsed file %s";
}
if (error_fmt) {
r->filename);
}
/* destroy the sub request */
if (rr) {
}
if (error_fmt) {
break;
}
}
return APR_SUCCESS;
}
{
request_rec *r = f->r;
while (1) {
return APR_SUCCESS;
}
conn_rec *c = r->connection;
const char *val =
get_include_var(r, ctx,
if (val) {
switch(encode) {
case E_NONE:
break;
case E_URL:
break;
case E_ENTITY:
break;
}
r->pool, c->bucket_alloc);
}
else {
c->bucket_alloc);
}
}
else {
"unknown value \"%s\" to parameter \"encoding\" of "
}
}
else {
"unknown parameter \"%s\" in tag echo of %s",
}
}
}
return APR_SUCCESS;
}
/* error and tf must point to a string with room for at
* least MAX_STRING_LEN characters
*/
{
char *parsed_string;
request_rec *r = f->r;
while (1) {
return APR_SUCCESS;
}
}
}
}
}
}
}
}
else {
"unknown parameter \"%s\" to tag config in %s",
}
}
}
return APR_SUCCESS;
}
{
char *parsed_string;
request_rec *r = f->r;
while (1) {
return APR_SUCCESS;
}
else {
/* XXX: if we *know* we're going to have to copy the
* thing off of the stack anyway, why not palloc buff
* instead of sticking it on the stack; then we can just
* use a pool bucket and skip the copy
*/
char buff[50];
}
else {
int l, x, pos = 0;
char tmp_buff[50];
for (x = 0; x < l; x++) {
if (x && (!((l - x) % 3))) {
}
}
}
r->connection->bucket_alloc);
}
else {
}
}
}
}
return APR_SUCCESS;
}
{
char *parsed_string;
request_rec *r = f->r;
while (1) {
return APR_SUCCESS;
}
else {
char *t_val;
r->connection->bucket_alloc);
}
else {
}
}
}
}
return APR_SUCCESS;
}
/* pjr - These seem to allow expr="fred" expr="joe" where joe overwrites fred. */
{
char debug_buf[MAX_DEBUG_SIZE];
request_rec *r = f->r;
ctx->if_nesting_level++;
}
else {
while (1) {
if (!tag) {
if (!expr) {
"missing expr in if statement: %s",
r->filename);
return APR_SUCCESS;
}
if (was_error) {
return APR_SUCCESS;
}
if (was_unmatched) {
}
if (expr_ret) {
}
else {
}
ctx->if_nesting_level = 0;
return APR_SUCCESS;
}
#ifdef DEBUG_INCLUDE
if (1) {
apr_size_t d_len = 0;
r->connection->bucket_alloc);
}
#endif
}
else {
"unknown parameter \"%s\" to tag if in %s", tag,
r->filename);
}
}
}
return APR_SUCCESS;
}
{
char debug_buf[MAX_DEBUG_SIZE];
request_rec *r = f->r;
if (!ctx->if_nesting_level) {
while (1) {
if (!tag) {
return APR_SUCCESS;
}
if (!expr) {
"missing expr in elif statement: %s",
r->filename);
return APR_SUCCESS;
}
if (was_error) {
return APR_SUCCESS;
}
if (was_unmatched) {
}
if (expr_ret) {
}
else {
}
return APR_SUCCESS;
}
#ifdef DEBUG_INCLUDE
if (1) {
apr_size_t d_len = 0;
r->connection->bucket_alloc);
}
#endif
}
else {
"unknown parameter \"%s\" to tag if in %s", tag,
r->filename);
}
}
}
return APR_SUCCESS;
}
{
request_rec *r = f->r;
if (!ctx->if_nesting_level) {
"else directive does not take tags in %s", r->filename);
}
return APR_SUCCESS;
}
else {
}
else {
}
return APR_SUCCESS;
}
}
return APR_SUCCESS;
}
{
request_rec *r = f->r;
if (!ctx->if_nesting_level) {
"endif directive does not take tags in %s", r->filename);
return APR_SUCCESS;
}
else {
return APR_SUCCESS;
}
}
else {
ctx->if_nesting_level--;
return APR_SUCCESS;
}
}
{
char *parsed_string;
request_rec *r = f->r;
apr_pool_t *p = r->pool;
/* we need to use the 'main' request pool to set notes as that is
* a notes lifetime
*/
while (sub) {
}
while (1) {
return APR_SUCCESS;
}
else if (!tag_val) {
return APR_SUCCESS;
}
}
"variable must precede value in set directive in %s",
r->filename);
return APR_SUCCESS;
}
apr_pstrdup(p, parsed_string));
}
else {
"Invalid tag for set directive in %s", r->filename);
return APR_SUCCESS;
}
}
}
return APR_SUCCESS;
}
{
request_rec *r = f->r;
int i;
if (val_text == LAZY_VALUE) {
}
*next++ = '=';
*next++ = '\n';
*next = 0;
r->pool,
r->connection->bucket_alloc);
}
return APR_SUCCESS;
}
else {
"printenv directive does not take tags in %s",
r->filename);
return APR_SUCCESS;
}
}
return APR_SUCCESS;
}
/*
* +-------------------------------------------------------+
* | |
* | Main Includes-Filter Engine
* | |
* +-------------------------------------------------------+
*/
/* This is an implementation of the BNDM search algorithm.
*
* Fast and Flexible String Matching by Combining Bit-parallelism and
* Suffix Automata (2001)
* Gonzalo Navarro, Mathieu Raffinot
*
*
* Initial code submitted by Sascha Schumann.
*/
/* Precompile the bndm_t data structure. */
{
unsigned int x;
memset(t->T, 0, sizeof(unsigned int) * 256);
t->pattern_len = nl;
t->T[(unsigned char) *n++] |= x;
}
t->x = x - 1;
return t;
}
/* Implements the BNDM search algorithm (as described above).
*
* h - the string to look in
* hl - length of the string to look for
* t - precompiled bndm structure against the pattern
*
* Returns the count of character that is the first match or hl if no
* match is found.
*/
{
const char *skip;
unsigned int *T, x, d;
T = t->T;
x = t->x;
nl = t->pattern_len;
while (p < he) {
skip = p;
d = x;
do {
d &= T[(unsigned char) *p--];
if (!d) {
break;
}
if ((d & 1)) {
if (p != pi) {
skip = p;
}
else {
return p - h + 1;
}
}
d >>= 1;
} while (d);
}
return hl;
}
/*
* returns the index position of the first byte of start_seq (or the len of
* the buffer as non-match)
*/
{
const char *p, *ep;
p = data; /* try partial match at the end of the buffer (below) */
}
else {
/* try fast bndm search over the buffer
* (hopefully the whole start sequence can be found in this buffer)
*/
/* wow, found it. ready. */
return index;
}
else {
/* ok, the pattern can't be found as whole in the buffer,
* check the end for a partial match
*/
}
}
do {
++p;
}
/* found a possible start_seq start */
if (p < ep) {
++p;
++p;
++pos;
}
/* partial match found. Store the info for the next round */
if (p == ep) {
return index;
}
}
/* we must try all combinations; consider (e.g.) SSIStartTag "--->"
* and a string data of "--.-" and the end of the buffer
*/
} while (p < ep);
/* no match */
return len;
}
/*
* returns the first byte *after* the partial (or final) match.
*
* If we had to trick with the start_seq start, 'release' returns the
* number of chars of the start_seq which appeared not to be part of a
* full tag and may have to be passed down the filter chain.
*/
const char *data,
{
const char *p, *ep;
*release = 0;
do {
p = data;
++p;
++pos;
}
/* full match */
return (p - data);
}
/* the whole buffer is a partial match */
if (p == ep) {
return (p - data);
}
/* No match so far, but again:
* We must try all combinations, since the start_seq is a random
* user supplied string
*
* So: look if the first char of start_seq appears somewhere within
* the current partial match. If it does, try to start a match that
* begins with this offset. (This can happen, if a strange
* start_seq like "---->" spans buffers)
*/
do {
++spos;
++*release;
++p;
++spos;
++*release;
--pos;
}
/* if a matching beginning char was found, try to match the
* remainder of the old buffer.
*/
if (pos > 1) {
apr_size_t t = 1;
++p;
++p;
++t;
}
if (t == pos) {
/* yeah, another partial match found in the *old*
* buffer, now test the *current* buffer for
* continuing match
*/
break;
}
}
} while (pos > 1);
if (pos) {
continue;
}
}
break;
} while (1); /* work hard to find a match ;-) */
/* no match at all, release all (wrongly) matched chars so far */
return 0;
}
/*
* returns the position after the directive
*/
{
const char *p = data;
case PARSE_DIRECTIVE:
while (p < ep && !apr_isspace(*p)) {
/* we have to consider the case of missing space between directive
* and end_seq (be somewhat lenient), e.g. <!--#printenv-->
*/
++p;
return (p - data);
}
++p;
}
if (p < ep) { /* found delimiter whitespace */
}
break;
case PARSE_DIRECTIVE_TAIL:
++p;
++pos;
}
/* full match, we're done */
break;
}
/* partial match, the buffer is too small to match fully */
if (p == ep) {
break;
}
/* no match. continue normal parsing */
return 0;
case PARSE_DIRECTIVE_POSTTAIL:
/* continue immediately with the next state */
case PARSE_DIRECTIVE_POSTNAME:
}
if (!intern->directive_len) {
"directive name in parsed document %s",
}
else {
/* normalize directive name */
}
}
return 0;
default:
/* get a rid of a gcc warning about unhandled enumerations */
break;
}
return (p - data);
}
/*
* find out whether the next token is (a possible) end_seq or an argument
*/
{
const char *p = data;
/* skip leading WS */
while (p < ep && apr_isspace(*p)) {
++p;
}
/* buffer doesn't consist of whitespaces only */
if (p < ep) {
}
return (p - data);
}
/*
* test the stream for end_seq. If it doesn't match at all, it must be an
* argument
*/
{
const char *p = data;
}
++p;
++pos;
}
/* bingo, full match */
return (p - data);
}
/* partial match, the buffer is too small to match fully */
if (p == ep) {
return (p - data);
}
/* no match. It must be an argument string then
* The caller should cleanup and rewind to the reparse point
*/
return 0;
}
/*
* extract name=value from the buffer
* A pcre-pattern could look (similar to):
* name\s*(?:=\s*(["'`]?)value\1(?>\s*))?
*/
{
const char *p = data;
case PARSE_ARG:
/*
* create argument structure and append it to the current list
*/
sizeof(*intern->current_arg));
}
else {
}
}
/* check whether it's a valid one. If it begins with a quote, we
* can safely assume, someone forgot the name of the argument
*/
switch (*p) {
case '"': case '\'': case '`':
"argument name for value to tag %s in %s",
return (p - data);
default:
}
/* continue immediately with next state */
case PARSE_ARG_NAME:
++p;
}
if (p < ep) {
return (p - data);
}
break;
case PARSE_ARG_POSTNAME:
"argument name for value to tag %s in %s",
}
else {
/* normalize the name */
while (*sp) {
++sp;
}
}
/* continue with next state immediately */
case PARSE_ARG_EQ:
while (p < ep && apr_isspace(*p)) {
++p;
}
if (p < ep) {
if (*p == '=') {
++p;
}
else { /* no value */
}
return (p - data);
}
break;
case PARSE_ARG_PREVAL:
while (p < ep && apr_isspace(*p)) {
++p;
}
/* buffer doesn't consist of whitespaces only */
if (p < ep) {
switch (*p) {
case '"': case '\'': case '`':
break;
default:
break;
}
return (p - data);
}
break;
case PARSE_ARG_VAL_ESC:
++p;
}
/* continue with next state immediately */
case PARSE_ARG_VAL:
for (; p < ep; ++p) {
++p;
if (p == ep) {
break;
}
--p;
}
}
++p;
break;
}
++p;
break;
}
}
return (p - data);
case PARSE_ARG_POSTVAL:
/*
* The value is still the raw input string. Finally clean it up.
*/
/* strip quote escaping \ from the string */
apr_size_t shift = 0;
char *sp;
++sp;
}
++sp;
++shift;
}
if (shift) {
}
}
}
return 0;
default:
/* get a rid of a gcc warning about unhandled enumerations */
break;
}
return len; /* partial match of something */
}
/*
* This is the main loop over the current bucket brigade.
*/
{
request_rec *r = f->r;
char *magic; /* magic pointer for sentinel use */
/* fast exit */
if (APR_BRIGADE_EMPTY(bb)) {
return APR_SUCCESS;
}
/* we may crash, since already cleaned up; hand over the responsibility
* to the next filter;-)
*/
}
/* All stuff passed along has to be put into that brigade */
/* initialization for this loop */
intern->bytes_read = 0;
intern->r = r;
/* loop over the current bucket brigade */
while (b != APR_BRIGADE_SENTINEL(bb)) {
/* handle meta buckets before reading any data */
if (APR_BUCKET_IS_METADATA(b)) {
newb = APR_BUCKET_NEXT(b);
if (APR_BUCKET_IS_EOS(b)) {
/* Hit end of stream, time for cleanup ... But wait!
* Perhaps we're not ready yet. We may have to loop one or
* two times again to finish our work. In that case, we
* just re-insert the EOS bucket to allow for an extra loop.
*
* PARSE_EXECUTE means, we've hit a directive just before the
* EOS, which is now waiting for execution.
*
* PARSE_DIRECTIVE_POSTTAIL means, we've hit a directive with
* no argument and no space between directive and end_seq
* just before the EOS. (consider <!--#printenv--> as last
* or only string within the stream). This state, however,
* just cleans up and turns itself to PARSE_EXECUTE, which
* will be passed through within the next (and actually
* last) round.
*/
}
else {
break; /* END OF STREAM */
}
}
else {
if (APR_BUCKET_IS_FLUSH(b)) {
}
b = newb;
continue;
}
}
/* enough is enough ... */
if (!APR_BRIGADE_EMPTY(pass_bb)) {
if (!APR_STATUS_IS_SUCCESS(rv)) {
return rv;
}
}
intern->bytes_read = 0;
}
/* read the current bucket data */
len = 0;
if (intern->bytes_read > 0) {
if (APR_STATUS_IS_EAGAIN(rv)) {
continue;
}
}
}
if (!APR_STATUS_IS_SUCCESS(rv)) {
return rv;
}
}
/* zero length bucket, fetch next one */
b = APR_BUCKET_NEXT(b);
continue;
}
/*
*/
/* no current tag; search for start sequence */
case PARSE_PRE_HEAD:
apr_bucket_split(b, index);
}
newb = APR_BUCKET_NEXT(b);
}
else {
}
/* now delete the start_seq stuff from the remaining bucket */
}
b = APR_BUCKET_NEXT(newb);
}
else {
b = newb;
}
break;
/* we're currently looking for the end of the start sequence */
case PARSE_HEAD:
/* check if we mismatched earlier and have to release some chars */
f->c->bucket_alloc);
}
if (index) { /* any match */
/* now delete the start_seq stuff from the remaining bucket */
apr_bucket_split(b, index);
}
newb = APR_BUCKET_NEXT(b);
b = newb;
}
break;
/* we're currently grabbing the directive name */
case PARSE_DIRECTIVE:
case PARSE_DIRECTIVE_POSTNAME:
case PARSE_DIRECTIVE_TAIL:
case PARSE_DIRECTIVE_POSTTAIL:
if (index) {
apr_bucket_split(b, index);
newb = APR_BUCKET_NEXT(b);
}
if (store) {
if (index) {
b = newb;
}
/* time for cleanup? */
}
}
else if (index) {
b = newb;
}
break;
/* skip WS and find out what comes next (arg or end_seq) */
case PARSE_PRE_ARG:
if (index) { /* skipped whitespaces */
apr_bucket_split(b, index);
}
newb = APR_BUCKET_NEXT(b);
b = newb;
}
break;
/* currently parsing name[=val] */
case PARSE_ARG:
case PARSE_ARG_NAME:
case PARSE_ARG_POSTNAME:
case PARSE_ARG_EQ:
case PARSE_ARG_PREVAL:
case PARSE_ARG_VAL:
case PARSE_ARG_VAL_ESC:
case PARSE_ARG_POSTVAL:
if (index) {
apr_bucket_split(b, index);
newb = APR_BUCKET_NEXT(b);
}
if (store) {
if (index) {
b = newb;
}
/* time for cleanup? */
}
}
else if (index) {
b = newb;
}
break;
/* try to match end_seq at current pos. */
case PARSE_TAIL:
case PARSE_TAIL_SEQ:
case PARSE_EXECUTE: /* full match */
apr_bucket_split(b, index);
newb = APR_BUCKET_NEXT(b);
b = newb;
break;
case PARSE_ARG: /* no match */
/* PARSE_ARG must reparse at the beginning */
b = APR_BRIGADE_FIRST(bb);
break;
default: /* partial match */
newb = APR_BUCKET_NEXT(b);
b = newb;
break;
}
break;
/* now execute the parsed directive, cleanup the space and
* start again with PARSE_PRE_HEAD
*/
case PARSE_EXECUTE:
/* if there was an error, it was already logged; just stop here */
}
}
else {
if (handle_func) {
if (!APR_STATUS_IS_SUCCESS(rv)) {
return rv;
}
}
else {
"unknown directive \"%s\" in parsed doc %s",
r->filename);
}
}
}
/* cleanup */
/* Oooof. Done here, start next round */
break;
} /* switch(ctx->state) */
} /* while(brigade) */
/* End of stream. Final cleanup */
f->c->bucket_alloc));
}
}
"SSI directive was not properly finished at the end "
"of parsed document %s", r->filename);
}
}
"missing closing endif directive in parsed document"
" %s", r->filename);
}
/* cleanup our temporary memory */
/* don't forget to finally insert the EOS bucket */
}
/* if something's left over, pass it along */
if (!APR_BRIGADE_EMPTY(pass_bb)) {
}
else {
rv = APR_SUCCESS;
}
return rv;
}
/*
* +-------------------------------------------------------+
* | |
* | Runtime Hooks
* | |
* +-------------------------------------------------------+
*/
static int includes_setup(ap_filter_t *f)
{
/* When our xbithack value isn't set to full or our platform isn't
* providing group-level protection bits or our group-level bits do not
* have group-execite on, we will set the no_local_copy value to 1 so
* that we will not send 304s.
*/
f->r->no_local_copy = 1;
}
return OK;
}
{
request_rec *r = f->r;
if (!(ap_allow_options(r) & OPT_INCLUDES)) {
return ap_pass_brigade(f->next, b);
}
if (!f->ctx) {
struct ssi_internal_ctx *intern;
/* create context for this filter */
/* runtime data */
if (ap_allow_options(r) & OPT_INCNOEXEC) {
}
ctx->if_nesting_level = 0;
}
/* Kludge --- for nested includes, we want to keep the subprocess
* environment of the base document (for compatibility); that means
* torquing our own last_modified date as well so that the
* LAST_MODIFIED variable gets reset to the proper value if the
* nested document resets <!--#config timefmt -->.
*/
}
else {
/* we're not a nested include, so we create an initial
* environment */
ap_add_cgi_vars(r);
}
/* Always unset the content-length. There is no way to know if
* the content will be modified at some point by send_parsed_content.
* It is very possible for us to not find any content in the first
* 9k of the file, but still have to modify the content of the file.
* If we are going to pass the file through send_parsed_content, then
* the content-length should just be unset.
*/
/* Always unset the ETag/Last-Modified fields - see RFC2616 - 13.3.4.
* We don't know if we are going to be including a file or executing
* a program which may change the Last-Modified header or make the
* content completely dynamic. Therefore, we can't support these
* headers.
* Exception: XBitHack full means we *should* set the Last-Modified field.
*/
/* Assure the platform supports Group protections */
}
else {
}
/* add QUERY stuff to env cause it ain't yet */
if (r->args) {
}
return send_parsed_content(f, b);
}
static int include_fixup(request_rec *r)
{
{
if (!r->content_type || !*r->content_type) {
ap_set_content_type(r, "text/html");
}
r->handler = "default-handler";
}
else
/* These OS's don't support xbithack. This is being worked on. */
{
return DECLINED;
}
#else
{
return DECLINED;
}
return DECLINED;
}
return DECLINED;
}
}
#endif
/* We always return declined, because the default handler actually
* serves the file. All we have to do is add the filter.
*/
return DECLINED;
}
/*
* +-------------------------------------------------------+
* | |
* | Configuration Handling
* | |
* +-------------------------------------------------------+
*/
{
return result;
}
{
return result;
}
{
}
}
}
else {
return "XBitHack must be set to Off, On, or Full";
}
return NULL;
}
const char *tag)
{
const char *p = tag;
/* be consistent. (See below in set_default_end_tag) */
while (*p) {
if (apr_isspace(*p)) {
return "SSIStartTag may not contain any whitespaces";
}
++p;
}
return NULL;
}
const char *tag)
{
const char *p = tag;
/* sanity check. The parser may fail otherwise */
while (*p) {
if (apr_isspace(*p)) {
return "SSIEndTag may not contain any whitespaces";
}
++p;
}
return NULL;
}
const char *msg)
{
return NULL;
}
const char *msg)
{
return NULL;
}
const char *fmt)
{
return NULL;
}
/*
* +-------------------------------------------------------+
* | |
* | Module Initialization and Configuration
* | |
* +-------------------------------------------------------+
*/
{
if(ssi_pfn_register) {
}
return OK;
}
static const command_rec includes_cmds[] =
{
"Off, On, or Full"),
"a string"),
"a strftime(3) formatted string"),
"SSI Start String Tag"),
"SSI End String Tag"),
"String to be displayed if an echoed variable is undefined"),
{NULL}
};
{
}
static void register_hooks(apr_pool_t *p)
{
}
{
create_includes_dir_config, /* dir config creater */
NULL, /* dir merger --- default is to override */
create_includes_server_config,/* server config */
NULL, /* merge server config */
includes_cmds, /* command apr_table_t */
register_hooks /* register hooks */
};