Mailing List Archive

New ScriptAlias fix...
This restores compatibility with the NCSA code pretty completely, by
merging ScriptAliases and regular Aliases into a single list, matching
in the order in which they occur in the config file while giving
neither absolute priority. (Note in passing --- giving ScriptAliases
absolute priority over Aliases is really no more compatible with the
old code than giving Aliases priority over ScriptAliases, and it's
liable to just give a different set of people a different set of
problems. As for "correct", I have no idea what's correct, but
staying compatible with the old code will break the fewest peoples'
setups).

In order to let mod_cgi know whether a particular URI was
ScriptAliased or not (which it needs to know for back-comabatibility
--- Options ExecCGI doesn't matter in the ScriptAliased case), it adds
a 'notes' table to the request_rec; the alias module in effect "passes
a note" to whichever other modules might care.

(I considered other ways of doing this which would have avoided adding
the 'notes' table --- e.g., faking up an "impossible" header --- but
all of them were ugly, at least as bug-prone, and likely to bite back
in the future).

diff -c ./http_protocol.c ../http_protocol.c
*** ./http_protocol.c Sat Aug 19 11:33:46 1995
--- ../http_protocol.c Sat Aug 19 12:08:48 1995
***************
*** 278,283 ****
--- 278,284 ----
r->subprocess_env = make_table (r->pool, 50);
r->headers_out = make_table (r->pool, 5);
r->err_headers_out = make_table (r->pool, 5);
+ r->notes = make_table (r->pool, 5);

r->request_config = create_request_config (r->pool);
r->per_dir_config = r->server->lookup_defaults; /* For now. */
***************
*** 336,341 ****
--- 337,343 ----
rnew->subprocess_env = copy_table (rnew->pool, r->subprocess_env);
rnew->headers_out = make_table (rnew->pool, 5);
rnew->err_headers_out = make_table (rnew->pool, 5);
+ rnew->notes = make_table (rnew->pool, 5);

rnew->main = r;
}
diff -c ./http_request.c ../http_request.c
*** ./http_request.c Sat Aug 19 11:20:24 1995
--- ../http_request.c Sat Aug 19 12:08:55 1995
***************
*** 639,644 ****
--- 639,645 ----
new->headers_out = make_table (r->pool, 5);
new->err_headers_out = r->err_headers_out;
new->subprocess_env = rename_original_env (r->pool, r->subprocess_env);
+ new->notes = make_table (r->pool, 5);

new->no_cache = r->no_cache; /* If we've already made up our minds
* about this, don't change 'em back!
diff -c ./httpd.h ../httpd.h
*** ./httpd.h Sat Aug 19 11:20:27 1995
--- ../httpd.h Sat Aug 19 11:35:42 1995
***************
*** 289,294 ****
--- 289,297 ----
* The difference between headers_out and err_headers_out is that the
* latter are printed even on error, and persist across internal redirects
* (so the headers printed for ErrorDocument handlers will have them).
+ *
+ * The 'notes' table is for notes from one module to another, with no
+ * other set purpose in mind...
*/

table *headers_in;
***************
*** 295,300 ****
--- 298,304 ----
table *headers_out;
table *err_headers_out;
table *subprocess_env;
+ table *notes;

char *content_type; /* Break these out --- we dispatch on 'em */
char *content_encoding;
diff -c ./mod_alias.c ../mod_alias.c
*** ./mod_alias.c Sat Aug 19 11:20:24 1995
--- ../mod_alias.c Sat Aug 19 12:02:47 1995
***************
*** 73,78 ****
--- 73,79 ----
typedef struct {
char *real;
char *fake;
+ char *forced_type;
} alias_entry;

typedef struct {
***************
*** 125,131 ****
/* XX r can NOT be relative to DocumentRoot here... compat bug. */

strip_slashes (f); strip_slashes(r);
! new->fake = f; new->real = r;
return NULL;
}

--- 126,132 ----
/* XX r can NOT be relative to DocumentRoot here... compat bug. */

strip_slashes (f); strip_slashes(r);
! new->fake = f; new->real = r; new->forced_type = cmd->info;
return NULL;
}

***************
*** 145,150 ****
--- 146,153 ----
command_rec alias_cmds[] = {
{ "Alias", add_alias, NULL, RSRC_CONF, TAKE2,
"a fakename and a realname"},
+ { "ScriptAlias", add_alias, CGI_MAGIC_TYPE, RSRC_CONF, TAKE2,
+ "a fakename and a realname"},
{ "Redirect", add_redirect, NULL, RSRC_CONF, TAKE2,
"a document to be redirected, then the destination URL" },
{ NULL }
***************
*** 162,167 ****
--- 165,173 ----
if(!strncmp(r->uri, p->fake, l)
&& (p->fake[l-1] == '/' || l == strlen(r->uri) || r->uri[l] == '/'))
{
+ if (p->forced_type)
+ table_set (r->notes, "alias-forced-type", p->forced_type);
+
return pstrcat(r->pool, p->real, r->uri + l, NULL);
}
}
***************
*** 192,197 ****
--- 198,211 ----
return DECLINED;
}

+ int type_forced_alias (request_rec *r)
+ {
+ char *t = table_get (r->notes, "alias-forced-type");
+ if (!t) return DECLINED;
+ r->content_type = t;
+ return OK;
+ }
+
module alias_module = {
STANDARD_MODULE_STUFF,
NULL, /* initializer */
***************
*** 205,211 ****
NULL, /* check_user_id */
NULL, /* check auth */
NULL, /* check access */
! NULL, /* type_checker */
NULL, /* fixups */
NULL /* logger */
};
--- 219,225 ----
NULL, /* check_user_id */
NULL, /* check auth */
NULL, /* check access */
! type_forced_alias, /* type_checker */
NULL, /* fixups */
NULL /* logger */
};
diff -c ./mod_cgi.c ../mod_cgi.c
*** ./mod_cgi.c Sat Aug 19 11:20:24 1995
--- ../mod_cgi.c Sat Aug 19 12:01:09 1995
***************
*** 84,164 ****
#include "http_log.h"
#include "util_script.h"

! /* ScriptAlias handling. The effects of ScriptAlias cut across
! * filename translation, file typing (if it's in a ScriptAliased
! * directory, it's a script), and permissions (ExecCGI doesn't
! * matter), so it's a bit of a pain to get right...
*/

- module cgi_module;
-
- typedef struct {
- char *real;
- char *fake;
- } alias_entry;
-
- void *cgi_server_config (pool *p, server_rec *s) {
- return make_array (p, 40, sizeof (alias_entry));
- }
-
- void *merge_cgi_server_config (pool *p, void *base, void *overrides) {
- return append_arrays (p, (array_header *)overrides, (array_header *)base);
- }
-
- char *script_alias (cmd_parms *cmd, void *dummy, char *f, char *r)
- {
- void *sconf = cmd->server->module_config;
- array_header *script_aliases =
- (array_header *)get_module_config(sconf,&cgi_module);
- alias_entry *new = (alias_entry *)push_array (script_aliases);
-
- new->fake = f; new->real = r;
- return NULL;
- }
-
- command_rec cgi_cmds[] = {
- { "ScriptAlias", script_alias, NULL, RSRC_CONF, TAKE2,
- "a fakename and a realname"},
- { NULL }
- };
-
- int translate_scriptalias (request_rec *r)
- {
- array_header *aliases =
- (array_header *)get_module_config(r->server->module_config, &cgi_module);
- alias_entry *entries = (alias_entry *)aliases->elts;
- int i;
-
- for (i = 0; i < aliases->nelts; ++i) {
- alias_entry *p = &entries[i];
- int l = strlen(p->fake);
-
- if(!strncmp(r->uri, p->fake, l)
- && (p->fake[l-1] == '/' || l == strlen(r->uri) || r->uri[l] == '/'))
- {
- r->filename = pstrcat(r->pool, p->real, r->uri + l, NULL);
- set_module_config (r->request_config, &cgi_module,
- "ScriptAlias is a crock");
- return OK;
- }
- }
-
- return DECLINED;
- }
-
int is_scriptaliased (request_rec *r)
{
! return (get_module_config (r->request_config, &cgi_module) != NULL);
}

- int type_scriptalias (request_rec *r)
- {
- if (!is_scriptaliased (r)) return DECLINED;
-
- r->content_type = CGI_MAGIC_TYPE;
- return OK;
- }
-
/****************************************************************
*
* Actual CGI handling...
--- 84,101 ----
#include "http_log.h"
#include "util_script.h"

! /* KLUDGE --- for back-combatibility, we don't have to check ExecCGI
! * in ScriptAliased directories, which means we need to know if this
! * request came through ScriptAlias or not... so the Alias module
! * leaves a note for us.
*/

int is_scriptaliased (request_rec *r)
{
! char *t = table_get (r->notes, "alias-forced-type");
! return t && (!strcmp (t, CGI_MAGIC_TYPE));
}

/****************************************************************
*
* Actual CGI handling...
***************
*** 415,429 ****
NULL, /* initializer */
NULL, /* dir config creater */
NULL, /* dir merger --- default is to override */
! cgi_server_config, /* server config */
! merge_cgi_server_config, /* merge server config */
! cgi_cmds, /* command table */
cgi_handlers, /* handlers */
! translate_scriptalias, /* filename translation */
NULL, /* check_user_id */
NULL, /* check auth */
NULL, /* check access */
! type_scriptalias, /* type_checker */
NULL, /* fixups */
NULL /* logger */
};
--- 352,366 ----
NULL, /* initializer */
NULL, /* dir config creater */
NULL, /* dir merger --- default is to override */
! NULL, /* server config */
! NULL, /* merge server config */
! NULL, /* command table */
cgi_handlers, /* handlers */
! NULL, /* filename translation */
NULL, /* check_user_id */
NULL, /* check auth */
NULL, /* check access */
! NULL, /* type_checker */
NULL, /* fixups */
NULL /* logger */
};