summaryrefslogtreecommitdiff
path: root/www/bozohttpd/patches/patch-aa
blob: fe5758f4c7c4e388aa8282c685c7f67436ea7094 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
$NetBSD: patch-aa,v 1.14 2004/04/29 12:12:31 lukem Exp $

--- bozohttpd.c.orig	2004-02-19 00:11:57.000000000 +1100
+++ bozohttpd.c
@@ -136,6 +136,9 @@
 #ifndef REDIRECT_FILE
 #define REDIRECT_FILE	".bzredirect"
 #endif
+#ifndef ABSREDIRECT_FILE
+#define ABSREDIRECT_FILE	".bzabsredirect"
+#endif
 
 /*
  * And so it begins ..
@@ -329,7 +332,7 @@ static	void	process_request(http_req *);
 static	void	check_special_files(http_req *, const char *);
 static	int	check_direct_access(http_req *request);
 static	char	*transform_request(http_req *, int *);
-static	void	handle_redirect(http_req *, const char *);
+static	void	handle_redirect(http_req *, const char *, int absolute);
 static	void	print_header(http_req *, struct stat *, const char *,
 			     const char *);
 
@@ -1186,7 +1189,7 @@ process_request(request)
 	if (fstat(fd, &sb) < 0)
 		http_error(500, request, "can't fstat");
 	if (S_ISDIR(sb.st_mode))
-		handle_redirect(request, NULL);
+		handle_redirect(request, NULL, 0);
 		/* NOTREACHED */
 	/* XXX RFC1945 10.9 If-Modified-Since (http code 304) */
 
@@ -1438,6 +1441,9 @@ check_special_files(http_req *request, c
 	if (strcmp(name, REDIRECT_FILE) == 0)
 		http_error(403, request,
 		    "no permission to open redirect file");
+	if (strcmp(name, ABSREDIRECT_FILE) == 0)
+		http_error(403, request,
+		    "no permission to open redirect file");
 #ifdef DO_HTPASSWD
 	if (strcmp(name, AUTH_FILE) == 0)
 		http_error(403, request,
@@ -1454,8 +1460,8 @@ check_bzredirect(http_req *request)
 {
 	struct stat sb;
 	char dir[MAXPATHLEN], redir[MAXPATHLEN], redirpath[MAXPATHLEN];
-	char *basename;
-	int rv;
+	char *basename, *finalredir;
+	int rv, absolute;
 
 
 	/*
@@ -1477,19 +1483,35 @@ check_bzredirect(http_req *request)
 	}
 
 	snprintf(redir, sizeof(redir), "%s/%s", dir, REDIRECT_FILE);
-	if (lstat(redir, &sb) < 0 || S_ISLNK(sb.st_mode) == 0)
-		return;
+	if (lstat(redir, &sb) == 0) {
+		if (S_ISLNK(sb.st_mode) == 0)
+			return;
+		absolute = 0;
+	} else {
+		snprintf(redir, sizeof(redir), "%s/%s", dir, ABSREDIRECT_FILE);
+		if (lstat(redir, &sb) < 0 || S_ISLNK(sb.st_mode) == 0)
+			return;
+		absolute = 1;
+	}
 	debug((DEBUG_FAT, "check_bzredirect: calling readlink"));
 	rv = readlink(redir, redirpath, sizeof redirpath);
-	if (rv == -1)
+	if (rv == -1) {
+		debug((DEBUG_FAT, "readlink failed"));
 		return;
+	}
 	if (rv - 1 < sizeof redirpath)
 		redirpath[rv] = '\0';
+	debug((DEBUG_FAT, "readlink returned \"%s\"", redirpath));
 	
 	/* now we have the link pointer, redirect to the real place */
-	snprintf(redir, sizeof(redir), "/%s/%s", dir, redirpath);
-	debug((DEBUG_FAT, "check_bzredirect: new redir %s", redir));
-	handle_redirect(request, redir);
+	if (absolute) {
+		finalredir = redirpath;
+	} else {
+		snprintf(redir, sizeof(redir), "/%s/%s", dir, redirpath);
+		finalredir = redir;
+	}
+	debug((DEBUG_FAT, "check_bzredirect: new redir %s", finalredir));
+	handle_redirect(request, finalredir, absolute);
 }
 
 /*
@@ -1602,7 +1624,7 @@ transform_request(request, isindex)
 			if (asprintf(&slashindexhtml, "/%s", index_html) < 0)
 				error(1, "asprintf");
 			debug((DEBUG_FAT, "rflag: redirecting %s to %s", url, slashindexhtml));
-			handle_redirect(request, slashindexhtml);
+			handle_redirect(request, slashindexhtml, 0);
 			/* NOTREACHED */
 		}
 	}
@@ -1619,7 +1641,7 @@ transform_request(request, isindex)
 		if (url[2] == '\0')
 			http_error(404, request, "missing username");
 		if (strchr(url + 2, '/') == NULL)
-			handle_redirect(request, NULL);
+			handle_redirect(request, NULL, 0);
 			/* NOTREACHED */
 		debug((DEBUG_FAT, "calling transform_user"));
 		return (transform_user(request, isindex));
@@ -1733,9 +1755,10 @@ transform_user(request, isindex)
  * do automatic redirection
  */
 static void
-handle_redirect(request, url)
+handle_redirect(request, url, absolute)
 	http_req *request;
 	const char *url;
+	int absolute;
 {
 	char *urlbuf;
 	char portbuf[20];
@@ -1755,16 +1778,24 @@ handle_redirect(request, url)
 	(void)bozoprintf("%s 301 Document Moved\r\n", request->hr_proto);
 	if (request->hr_proto != http_09) 
 		print_header(request, NULL, "text/html", NULL);
-	if (request->hr_proto != http_09)
-		(void)bozoprintf("Location: http://%s%s%s\r\n", myname, portbuf,
-		    url);
+	if (request->hr_proto != http_09) {
+		if (absolute) 
+			(void)bozoprintf("Location: http://%s\r\n", url);
+		else
+			(void)bozoprintf("Location: http://%s%s%s\r\n", myname, portbuf,
+			    url);
+	}
 	(void)bozoprintf("\r\n");
 	if (request->hr_method == HTTP_HEAD)
 		goto head;
 	(void)bozoprintf("<html><head><title>Document Moved</title></head>\n");
 	(void)bozoprintf("<body><h1>Document Moved</h1>\n");
-	(void)bozoprintf("This document had moved <a href=\"http://%s%s%s\">here</a>\n",
-	    myname, portbuf, url);
+	if (absolute) 
+		(void)bozoprintf("This document had moved <a href=\"http://%s\">here</a>\n",
+		    url);
+	else
+		(void)bozoprintf("This document had moved <a href=\"http://%s%s%s\">here</a>\n",
+		    myname, portbuf, url);
 	(void)bozoprintf("</body></html>\n");
 head:
 	fflush(stdout);
@@ -1951,6 +1982,7 @@ process_cgi(request)
 	spsetenv("SERVER_PROTOCOL", request->hr_proto, curenvp++);
 	spsetenv("REQUEST_METHOD", request->hr_methodstr, curenvp++);
 	spsetenv("SCRIPT_NAME", url, curenvp++);
+	spsetenv("SCRIPT_FILENAME", url+1, curenvp++);
 	spsetenv("SERVER_SOFTWARE", server_software, curenvp++);
 	spsetenv("REQUEST_URI", request->hr_url, curenvp++);
 	spsetenv("DATE_GMT", date, curenvp++);
@@ -1977,8 +2009,8 @@ process_cgi(request)
 
 	/* may as well wait as long as possible */
 print_cgi_header:
-	(void)bozoprintf("%s 200 Here it is\r\n", request->hr_proto);
 	if (!aflag) {
+		(void)bozoprintf("%s 200 Here it is\r\n", request->hr_proto);
 		debug((DEBUG_OBESE, "process_cgi:  writing HTTP header .."));
 		if (request->hr_proto != http_09)
 			print_header(NULL, NULL, NULL, NULL);
@@ -1988,8 +2020,6 @@ print_cgi_header:
 	} else
 		debug((DEBUG_OBESE, "process_cgi:  not-writing HTTP header .."));
 
-	/* XXX we should be printing 200 here? */
-	(void)bozoprintf("%s 200 Here it is\r\n", request->hr_proto);
 	debug((DEBUG_FAT, "process_cgi: going exec %s, %s %s %s",
 	    path, argv[0], strornull(argv[1]), strornull(argv[2])));
 
@@ -2291,6 +2321,7 @@ static struct content_map content_map[] 
 	{ ".ppt",	"application/powerpoint",	"",		"", NULL },
 	{ ".rtf",	"application/rtf",		"",		"", NULL },
 	{ ".bcpio",	"application/x-bcpio",		"",		"", NULL },
+	{ ".torrent",	"application/x-bittorrent",	"",		"", NULL },
 	{ ".vcd",	"application/x-cdlink",		"",		"", NULL },
 	{ ".cpio",	"application/x-cpio",		"",		"", NULL },
 	{ ".csh",	"application/x-csh",		"",		"", NULL },