The following reply was made to PR mod_autoindex/4256; it has been noted by
GNATS.
From: RSBX <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: mod_autoindex/4256: Patch to permit HeaderName and Readme files to
be server parsed.
Date: Wed, 21 Apr 1999 03:04:02 +0000
[EMAIL PROTECTED] wrote:
...
> If you change it to use ap_sub_req_lookup_uri() it should
> go through all the negotiation stuff -- so if multiviews
> is enabled it will find the foo.html... and you don't have
> to append .html. This would be a much cleaner solution.
>
> You should just be able to ap_run_subrequest... the default
> handler should take care of including plain text files...
> a good example of this is handle_include() in mod_include.
>
> Also, ap_cpystrn is generally evil. Look at ap_pstrcat()
> which you could have used to catenate the two strings without
> fixed length limits.
>
> Dean
OK, a new and improved patch follows. This one actually manages
to get the situation where no header or readme file names are
specified and multiviews appear to work.
--- apache_1.3.6/src/modules/standard/mod_autoindex.c Mon Jan 4
14:49:41 1999
+++ apache_1.3.6-rsbx/src/modules/standard/mod_autoindex.c Tue Apr
20 22:53:21 1999
@@ -178,8 +178,11 @@
* We include the DOCTYPE because we may be using features therefrom
(i.e.,
* HEIGHT and WIDTH attributes on the icons if we're FancyIndexing).
*/
-static void emit_preamble(request_rec *r, char *title)
+static void emit_preamble(request_rec *r, char *title, int whichend)
{
+ if (FRONT_MATTER != whichend) {
+ return;
+ }
ap_rvputs(r, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2
Final//EN\">\n",
"<HTML>\n <HEAD>\n <TITLE>Index of ", title,
"</TITLE>\n </HEAD>\n <BODY>\n", NULL);
@@ -764,10 +767,8 @@
static int insert_readme(char *name, char *readme_fname, char *title,
int hrule, int whichend, request_rec *r)
{
- char *fn;
- FILE *f;
+ FILE *f = NULL;
struct stat finfo;
- int plaintext = 0;
request_rec *rr;
autoindex_config_rec *cfg;
int autoindex_opts;
@@ -775,44 +776,56 @@
cfg = (autoindex_config_rec *)
ap_get_module_config(r->per_dir_config,
&autoindex_module);
autoindex_opts = cfg->opts;
- /* XXX: this is a load of crap, it needs to do a full
sub_req_lookup_uri */
- fn = ap_make_full_path(r->pool, name, readme_fname);
- fn = ap_pstrcat(r->pool, fn, ".html", NULL);
- if (stat(fn, &finfo) == -1) {
- /* A brief fake multiviews search for README.html */
- fn[strlen(fn) - 5] = '\0';
- if (stat(fn, &finfo) == -1) {
+
+ if ((!readme_fname) || (!(rr = ap_sub_req_lookup_uri(readme_fname,
r)))) {
+ emit_preamble(r, title, whichend);
+ return 0;
+ }
+
+ if ((rr->status != HTTP_OK)
+ || (!(rr->filename))
+ || (!S_ISREG(rr->finfo.st_mode))) {
+ ap_destroy_sub_req(rr);
+ emit_preamble(r, title, whichend);
+ return 0;
+ }
+
+ if ((!(rr->content_type)) || strcmp("text/html", rr->content_type))
{
+ if (!(f = ap_pfopen(r->pool, rr->filename, "r"))) {
+ ap_destroy_sub_req(rr);
+ emit_preamble(r, title, whichend);
return 0;
}
- plaintext = 1;
- if (hrule) {
- ap_rputs("<HR>\n", r);
- }
}
- else if (hrule) {
+
+ if (hrule) {
+ /* Not set for FRONT_MATTER */
ap_rputs("<HR>\n", r);
}
- /* XXX: when the above is rewritten properly, this necessary
security
- * check will be redundant. -djg */
- rr = ap_sub_req_lookup_file(fn, r);
- if (rr->status != HTTP_OK) {
+
+ if (!f) {
+ if (!(autoindex_opts & SUPPRESS_PREAMBLE)) {
+ emit_preamble(r, title, whichend);
+ }
+ if (ap_run_sub_req(rr)) {
+ ap_destroy_sub_req(rr);
+ if (autoindex_opts & SUPPRESS_PREAMBLE) {
+ emit_preamble(r, title, whichend);
+ }
+
+ /* if END_MATTER & hrule, an incorrect <HR> was put. */
+#if 0
+ ap_rputs("<!-- ap_run_sub_req failed -->\n", r);
+#endif
+ return 0;
+ }
ap_destroy_sub_req(rr);
- return 0;
- }
- ap_destroy_sub_req(rr);
- if (!(f = ap_pfopen(r->pool, fn, "r"))) {
- return 0;
- }
- if ((whichend == FRONT_MATTER)
- && (!(autoindex_opts & SUPPRESS_PREAMBLE))) {
- emit_preamble(r, title);
- }
- if (!plaintext) {
- ap_send_fd(f, r);
}
else {
char buf[IOBUFSIZE + 1];
int i, n, c, ch;
+
+ emit_preamble(r, title, whichend);
ap_rputs("<PRE>\n", r);
while (!feof(f)) {
do {
@@ -845,9 +858,7 @@
c = i + 1;
}
}
- }
- ap_pfclose(r->pool, f);
- if (plaintext) {
+ ap_pfclose(r->pool, f);
ap_rputs("</PRE>\n", r);
}
return 1;
@@ -1326,7 +1337,6 @@
int num_ent = 0, x;
struct ent *head, *p;
struct ent **ar = NULL;
- char *tmp;
const char *qstring;
int autoindex_opts = autoindex_conf->opts;
char keyid;
@@ -1356,10 +1366,8 @@
*title_endp-- = '\0';
}
- if ((!(tmp = find_header(autoindex_conf, r)))
- || (!(insert_readme(name, tmp, title_name, NO_HRULE,
FRONT_MATTER, r)))
- ) {
- emit_preamble(r, title_name);
+ if (!insert_readme(name, find_header(autoindex_conf, r),
+ title_name, NO_HRULE, FRONT_MATTER, r)) {
ap_rvputs(r, "<H1>Index of ", title_name, "</H1>\n", NULL);
}
@@ -1426,15 +1434,17 @@
direction);
ap_pclosedir(r->pool, d);
- if ((tmp = find_readme(autoindex_conf, r))) {
- if (!insert_readme(name, tmp, "",
- ((autoindex_opts & FANCY_INDEXING) ? HRULE
- :
NO_HRULE),
- END_MATTER, r)) {
- ap_rputs(ap_psignature("<HR>\n", r), r);
+ if (!insert_readme(name, find_readme(autoindex_conf, r), "",
+ ((autoindex_opts & FANCY_INDEXING) ? HRULE : NO_HRULE),
+ END_MATTER, r)) {
+ ap_rputs(ap_psignature("<HR>\n", r), r);
+ ap_rputs("</BODY></HTML>\n", r);
+ }
+ else {
+ if (!(autoindex_opts & SUPPRESS_PREAMBLE)) {
+ ap_rputs("</BODY></HTML>\n", r);
}
}
- ap_rputs("</BODY></HTML>\n", r);
ap_kill_timeout(r);
return 0;
Raymond S Brand