Line 0
Link Here
|
|
|
1 |
diff -N -u -r publicfile-0.52.orig/Makefile publicfile-0.52/Makefile |
2 |
--- publicfile-0.52.orig/Makefile Mon Nov 8 23:23:46 1999 |
3 |
+++ publicfile-0.52/Makefile Wed Aug 29 20:27:09 2001 |
4 |
@@ -234,21 +234,43 @@ |
5 |
compile hier.c auto_home.h |
6 |
./compile hier.c |
7 |
|
8 |
+htrules: \ |
9 |
+load htrules.o base64.o |
10 |
+ ./load htrules cdb.a base64.o byte.a getln.a stralloc.a alloc.a \ |
11 |
+ substdio.a str.a buffer.a unix.a |
12 |
+ |
13 |
+htrules.o: \ |
14 |
+compile htrules.c strerr.h stralloc.h gen_alloc.h getln.h buffer.h \ |
15 |
+stralloc.h buffer.h exit.h fmt.h byte.h cdb_make.h buffer.h uint32.h \ |
16 |
+base64.h |
17 |
+ ./compile htrules.c |
18 |
+ |
19 |
+base64.o: \ |
20 |
+compile base64.c base64.h |
21 |
+ ./compile base64.c |
22 |
+ |
23 |
httpd: \ |
24 |
load httpd.o main.o pathdecode.o file.o filetype.o httpdate.o \ |
25 |
percent.o prot.o timeoutread.o timeoutwrite.o libtai.a case.a getln.a \ |
26 |
stralloc.a alloc.a substdio.a error.a open.a sig.a env.a str.a fs.a \ |
27 |
-socket.lib |
28 |
+socket.lib readclose.o openreadclose.o |
29 |
./load httpd main.o pathdecode.o file.o filetype.o \ |
30 |
httpdate.o percent.o prot.o timeoutread.o timeoutwrite.o \ |
31 |
libtai.a case.a getln.a stralloc.a alloc.a substdio.a \ |
32 |
- error.a open.a sig.a env.a str.a fs.a `cat socket.lib` |
33 |
+ error.a open.a sig.a env.a str.a fs.a cdb.a byte.a seek_set.o \ |
34 |
+ readclose.o openreadclose.o `cat socket.lib` |
35 |
+ |
36 |
+cdb: |
37 |
+ (cd /usr/ports/databases/cdb/work/cdb-0.75 && \ |
38 |
+ make && \ |
39 |
+ cp -p cdb_make.h buffer.h cdb.h uint32.h cdb.a byte.a seek_set.o \ |
40 |
+ cdb_make.o error.c buffer.a unix.a /usr/ports/www/publicfile.new/work/publicfile-0.52/) |
41 |
|
42 |
httpd.o: \ |
43 |
compile httpd.c pathdecode.h stralloc.h gen_alloc.h file.h tai.h \ |
44 |
uint64.h filetype.h stralloc.h percent.h stralloc.h stralloc.h sig.h \ |
45 |
exit.h fmt.h case.h str.h tai.h httpdate.h stralloc.h tai.h \ |
46 |
-timeoutread.h timeoutwrite.h substdio.h error.h getln.h |
47 |
+timeoutread.h timeoutwrite.h substdio.h error.h getln.h byte.h |
48 |
./compile httpd.c |
49 |
|
50 |
httpdate.o: \ |
51 |
@@ -358,6 +380,11 @@ |
52 |
compile open_trunc.c open.h |
53 |
./compile open_trunc.c |
54 |
|
55 |
+openreadclose.o: \ |
56 |
+compile openreadclose.c error.h open.h readclose.h stralloc.h \ |
57 |
+gen_alloc.h openreadclose.h stralloc.h |
58 |
+ ./compile openreadclose.c |
59 |
+ |
60 |
pathdecode.o: \ |
61 |
compile pathdecode.c pathdecode.h stralloc.h gen_alloc.h |
62 |
./compile pathdecode.c |
63 |
@@ -367,7 +394,7 @@ |
64 |
./compile percent.c |
65 |
|
66 |
prog: \ |
67 |
-configure httpd ftpd rts utime |
68 |
+cdb configure httpd ftpd rts utime htrules |
69 |
|
70 |
prot.o: \ |
71 |
compile prot.c hasshsgr.h prot.h |
72 |
diff -N -u -r publicfile-0.52.orig/README.basicauth publicfile-0.52/README.basicauth |
73 |
--- publicfile-0.52.orig/README.basicauth Wed Dec 31 16:00:00 1969 |
74 |
+++ publicfile-0.52/README.basicauth Wed Aug 29 22:16:02 2001 |
75 |
@@ -0,0 +1,100 @@ |
76 |
+Here is a patch for publicfile to allow for Basic Auth. |
77 |
+ |
78 |
+Building Instructions: |
79 |
+ |
80 |
+Save this patch as publicfile-0.52.basicauth.patch |
81 |
+Download publicfile-0.52 |
82 |
+Download cdb-0.75 |
83 |
+ |
84 |
+gunzip publicfile-0.52.tar |
85 |
+gunzip cdb-0.75.tar |
86 |
+tar -xf publicfile-0.52.tar |
87 |
+cd publicfile-0.52 |
88 |
+tar -xf ../cdb-0.75.tar |
89 |
+patch -p1 < publicfile-0.52.basicauth.patch |
90 |
+ |
91 |
+Follow normal installation instructions for publicfile beginning with |
92 |
+'make setup check' |
93 |
+ |
94 |
+Usage Instructions: |
95 |
+ |
96 |
+Once this patch has been applied, httpd will check for a file |
97 |
+called '.access' in the current directory of any requested |
98 |
+file. e.g, if /public/file/0/path/to/file.html is requested, httpd |
99 |
+will first check for /public/file/0/path/to/.access. |
100 |
+ |
101 |
+.access should have the format: |
102 |
+ realm_id:realm_txt |
103 |
+ |
104 |
+realm_id is used as documented below. realm_txt is typically |
105 |
+presented by the user's browser. .access must be readable by httpd |
106 |
+and only protects a specific directory. Sub-directories are not |
107 |
+protected unless they also contain a .access file. |
108 |
+ |
109 |
+An additional program will be installed in /usr/local/publicfile (or |
110 |
+whatever conf-home is) called htrules. Use this like tcprules: |
111 |
+ |
112 |
+cd /public/file |
113 |
+htrules access.cdb access.tmp < access |
114 |
+ |
115 |
+This may safely be run at any time. |
116 |
+ |
117 |
+access should have the format: |
118 |
+ |
119 |
+ # this is a comment. blank lines are allowed too. |
120 |
+ # the next line authorizes a user to a specific realm_id |
121 |
+ realm_id:username:password |
122 |
+ # the next line authorizes host class. |
123 |
+ realm_id:LOCALHOST |
124 |
+ |
125 |
+access.cdb must be readable by httpd. |
126 |
+ |
127 |
+realm_id corresponds to the realm_id in the .access file(s). |
128 |
+ |
129 |
+Each realm_id line specifies either a username:password combination |
130 |
+or a host class. Note that the same username may have different |
131 |
+passwords in different realm_id's. |
132 |
+ |
133 |
+A host is mapped into a host class via the environment |
134 |
+variable HTTPCLIENT. This environment variable should be |
135 |
+set in tcpserver's rules.cdb. |
136 |
+ |
137 |
+Here is an example: |
138 |
+ |
139 |
+ === /public/file/0/private1/.access === |
140 |
+ realm1:Dr. Suess |
141 |
+ |
142 |
+ === /public/file/0/private2/.access === |
143 |
+ realm2:Sesame Street |
144 |
+ |
145 |
+ === /public/file/access === |
146 |
+ # realm1 are Dr Suess users/clients |
147 |
+ realm1:john:catinthehat |
148 |
+ realm1:mary:greeneggswithham |
149 |
+ realm1:LOCALHOST |
150 |
+ realm1:DR SUESS |
151 |
+ # realm1 are Sesame Street users/clients |
152 |
+ realm2:tom:bigbird |
153 |
+ realm2:abi:cookiemonster |
154 |
+ realm2:mary:earnie |
155 |
+ realm2:LOCALHOST |
156 |
+ realm2:SESAME STREET |
157 |
+ |
158 |
+ === /etc/rules === |
159 |
+ 127.0.0.1:allow,HTTPCLIENT="LOCALHOST" |
160 |
+ 10.0.0.:allow,HTTPCLIENT="DR SUESS" |
161 |
+ 10.1.0.:allow,HTTPCLIENT="SESAME STREET" |
162 |
+ :allow |
163 |
+ |
164 |
+The changes to the Makefile aren't very clean, but everything compiles |
165 |
+correctly. |
166 |
+ |
167 |
+Thanks to Eric M. Johnston's for base64.{c,h} from YAQSAP |
168 |
+(Yet Another qmail SMTP AUTH Patch) - |
169 |
+http://qmail.goof.com/qmail-auth-20010105.tar.gz |
170 |
+ |
171 |
+This patch available at |
172 |
+http://www.soffian.org/downloads/publicfile-0.52_basicauth.patch |
173 |
+ |
174 |
+Jay Soffian <jay@soffian.org> 29 Aug 2001 |
175 |
+ |
176 |
diff -N -u -r publicfile-0.52.orig/base64.c publicfile-0.52/base64.c |
177 |
--- publicfile-0.52.orig/base64.c Wed Dec 31 16:00:00 1969 |
178 |
+++ publicfile-0.52/base64.c Wed Aug 22 22:17:39 2001 |
179 |
@@ -0,0 +1,90 @@ |
180 |
+#include "base64.h" |
181 |
+#include "stralloc.h" |
182 |
+#include "substdio.h" |
183 |
+#include "str.h" |
184 |
+ |
185 |
+static char *b64alpha = |
186 |
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
187 |
+#define B64PAD '=' |
188 |
+ |
189 |
+/* returns 0 ok, 1 illegal, -1 problem */ |
190 |
+ |
191 |
+int b64decode(in,l,out) |
192 |
+const unsigned char *in; |
193 |
+int l; |
194 |
+stralloc *out; /* not null terminated */ |
195 |
+{ |
196 |
+ int i, j; |
197 |
+ unsigned char a[4]; |
198 |
+ unsigned char b[3]; |
199 |
+ char *s; |
200 |
+ |
201 |
+ if (l == 0) |
202 |
+ { |
203 |
+ if (!stralloc_copys(out,"")) return -1; |
204 |
+ return 0; |
205 |
+ } |
206 |
+ |
207 |
+ if (!stralloc_ready(out,l + 2)) return -1; /* XXX generous */ |
208 |
+ s = out->s; |
209 |
+ |
210 |
+ for (i = 0;i < l;i += 4) { |
211 |
+ for (j = 0;j < 4;j++) |
212 |
+ if ((i + j) < l && in[i + j] != B64PAD) |
213 |
+ { |
214 |
+ a[j] = str_chr(b64alpha,in[i + j]); |
215 |
+ if (a[j] > 63) return 1; |
216 |
+ } |
217 |
+ else a[j] = 0; |
218 |
+ |
219 |
+ b[0] = (a[0] << 2) | (a[1] >> 4); |
220 |
+ b[1] = (a[1] << 4) | (a[2] >> 2); |
221 |
+ b[2] = (a[2] << 6) | (a[3]); |
222 |
+ |
223 |
+ *s++ = b[0]; |
224 |
+ |
225 |
+ if (in[i + 1] == B64PAD) break; |
226 |
+ *s++ = b[1]; |
227 |
+ |
228 |
+ if (in[i + 2] == B64PAD) break; |
229 |
+ *s++ = b[2]; |
230 |
+ } |
231 |
+ out->len = s - out->s; |
232 |
+ while (out->len && !out->s[out->len - 1]) --out->len; /* XXX avoid? */ |
233 |
+ return 0; |
234 |
+} |
235 |
+ |
236 |
+int b64encode(in,out) |
237 |
+stralloc *in; |
238 |
+stralloc *out; /* not null terminated */ |
239 |
+{ |
240 |
+ unsigned char a, b, c; |
241 |
+ int i; |
242 |
+ char *s; |
243 |
+ |
244 |
+ if (in->len == 0) |
245 |
+ { |
246 |
+ if (!stralloc_copys(out,"")) return -1; |
247 |
+ return 0; |
248 |
+ } |
249 |
+ |
250 |
+ if (!stralloc_ready(out,in->len / 3 * 4 + 4)) return -1; |
251 |
+ s = out->s; |
252 |
+ |
253 |
+ for (i = 0;i < in->len;i += 3) { |
254 |
+ a = in->s[i]; |
255 |
+ b = i + 1 < in->len ? in->s[i + 1] : 0; |
256 |
+ c = i + 2 < in->len ? in->s[i + 2] : 0; |
257 |
+ |
258 |
+ *s++ = b64alpha[a >> 2]; |
259 |
+ *s++ = b64alpha[((a & 3 ) << 4) | (b >> 4)]; |
260 |
+ |
261 |
+ if (i + 1 >= in->len) *s++ = B64PAD; |
262 |
+ else *s++ = b64alpha[((b & 15) << 2) | (c >> 6)]; |
263 |
+ |
264 |
+ if (i + 2 >= in->len) *s++ = B64PAD; |
265 |
+ else *s++ = b64alpha[c & 63]; |
266 |
+ } |
267 |
+ out->len = s - out->s; |
268 |
+ return 0; |
269 |
+} |
270 |
diff -N -u -r publicfile-0.52.orig/base64.h publicfile-0.52/base64.h |
271 |
--- publicfile-0.52.orig/base64.h Wed Dec 31 16:00:00 1969 |
272 |
+++ publicfile-0.52/base64.h Wed Aug 22 22:17:39 2001 |
273 |
@@ -0,0 +1,7 @@ |
274 |
+#ifndef BASE64_H |
275 |
+#define BASE64_H |
276 |
+ |
277 |
+extern int b64decode(); |
278 |
+extern int b64encode(); |
279 |
+ |
280 |
+#endif |
281 |
diff -N -u -r publicfile-0.52.orig/hier.c publicfile-0.52/hier.c |
282 |
--- publicfile-0.52.orig/hier.c Mon Nov 8 23:23:46 1999 |
283 |
+++ publicfile-0.52/hier.c Wed Aug 22 22:17:39 2001 |
284 |
@@ -7,6 +7,7 @@ |
285 |
d(auto_home,"bin",-1,-1,02755); |
286 |
|
287 |
c(auto_home,"bin","configure",-1,-1,0755); |
288 |
+ c(auto_home,"bin","htrules",-1,-1,0755); |
289 |
c(auto_home,"bin","httpd",-1,-1,0755); |
290 |
c(auto_home,"bin","ftpd",-1,-1,0755); |
291 |
} |
292 |
diff -N -u -r publicfile-0.52.orig/htrules.c publicfile-0.52/htrules.c |
293 |
--- publicfile-0.52.orig/htrules.c Wed Dec 31 16:00:00 1969 |
294 |
+++ publicfile-0.52/htrules.c Wed Aug 29 21:27:42 2001 |
295 |
@@ -0,0 +1,117 @@ |
296 |
+#include "strerr.h" |
297 |
+#include "stralloc.h" |
298 |
+#include "getln.h" |
299 |
+#include "buffer.h" |
300 |
+#include "exit.h" |
301 |
+#include "fmt.h" |
302 |
+#include "byte.h" |
303 |
+#include "base64.h" |
304 |
+#include "cdb_make.h" |
305 |
+ |
306 |
+#define FATAL "htrules: fatal: " |
307 |
+ |
308 |
+unsigned long linenum = 0; |
309 |
+char *fntemp; |
310 |
+char *fn; |
311 |
+ |
312 |
+stralloc line = {0}; |
313 |
+int match = 1; |
314 |
+ |
315 |
+stralloc base64 = {0}; |
316 |
+stralloc key = {0}; |
317 |
+stralloc realm = {0}; |
318 |
+stralloc userpass = {0}; |
319 |
+ |
320 |
+struct cdb_make c; |
321 |
+ |
322 |
+void nomem(void) |
323 |
+{ |
324 |
+ strerr_die2x(111,FATAL,"out of memory"); |
325 |
+} |
326 |
+void usage(void) |
327 |
+{ |
328 |
+ strerr_die1x(100,"htrules: usage: htrules access.cdb access.tmp"); |
329 |
+} |
330 |
+void die_bad(void) |
331 |
+{ |
332 |
+ if (!stralloc_0(&line)) nomem(); |
333 |
+ strerr_die3x(100,FATAL,"unable to parse this line: ",line.s); |
334 |
+} |
335 |
+void die_write(void) |
336 |
+{ |
337 |
+ strerr_die4sys(111,FATAL,"unable to write to ",fntemp,": "); |
338 |
+} |
339 |
+ |
340 |
+main(int argc,char **argv) |
341 |
+{ |
342 |
+ int colon; |
343 |
+ char *x; |
344 |
+ int len; |
345 |
+ int fd; |
346 |
+ int i; |
347 |
+ char ch; |
348 |
+ |
349 |
+ fn = argv[1]; |
350 |
+ if (!fn) usage(); |
351 |
+ fntemp = argv[2]; |
352 |
+ if (!fntemp) usage(); |
353 |
+ |
354 |
+ fd = open_trunc(fntemp); |
355 |
+ if (fd == -1) |
356 |
+ strerr_die4sys(111,FATAL,"unable to create ",fntemp,": "); |
357 |
+ if (cdb_make_start(&c,fd) == -1) die_write(); |
358 |
+ |
359 |
+ while (match) { |
360 |
+ if (getln(buffer_0,&line,&match,'\n') == -1) |
361 |
+ strerr_die2sys(111,FATAL,"unable to read input: "); |
362 |
+ |
363 |
+ x = line.s; len = line.len; |
364 |
+ |
365 |
+ if (!len) break; |
366 |
+ if (x[0] == '#') continue; |
367 |
+ if (x[0] == '\n') continue; |
368 |
+ |
369 |
+ while (len) { |
370 |
+ ch = x[len - 1]; |
371 |
+ if (ch != '\n') if (ch != ' ') if (ch != '\t') break; |
372 |
+ --len; |
373 |
+ } |
374 |
+ line.len = len; /* for die_bad() */ |
375 |
+ if (!len) continue; |
376 |
+ |
377 |
+ colon = byte_chr(x,len,':'); |
378 |
+ if (!colon || colon == len) die_bad(); |
379 |
+ if (!stralloc_copyb(&realm,x,colon)) nomem(); |
380 |
+ x += colon + 1; len -= colon + 1; |
381 |
+ |
382 |
+ colon = byte_chr(x,len,':'); |
383 |
+ if (colon == len) { |
384 |
+ if (!stralloc_copyb(&key,"C",1)) nomem(); |
385 |
+ if (!stralloc_cat(&key,&realm)) nomem(); |
386 |
+ if (!stralloc_catb(&key,":",1)) nomem(); |
387 |
+ if (!stralloc_catb(&key,x,len)) nomem(); |
388 |
+ if (cdb_make_add(&c,key.s,key.len,"",0) == -1) die_write(); |
389 |
+ } else { |
390 |
+ if (!stralloc_copyb(&userpass,x,len)) nomem(); |
391 |
+ if (b64encode(&userpass,&base64) == -1) nomem(); |
392 |
+ |
393 |
+ if (!stralloc_copyb(&key,"U",1)) nomem(); |
394 |
+ if (!stralloc_cat(&key,&base64)) nomem(); |
395 |
+ if (cdb_make_add(&c,key.s,key.len,"",0) == -1) die_write(); |
396 |
+ |
397 |
+ if (!stralloc_copyb(&key,"R",1)) nomem(); |
398 |
+ if (!stralloc_cat(&key,&realm)) nomem(); |
399 |
+ if (!stralloc_catb(&key,":",1)) nomem(); |
400 |
+ if (!stralloc_cat(&key,&base64)) nomem(); |
401 |
+ if (cdb_make_add(&c,key.s,key.len,"",0) == -1) die_write(); |
402 |
+ } |
403 |
+ } |
404 |
+ |
405 |
+ if (cdb_make_finish(&c) == -1) die_write(); |
406 |
+ if (fsync(fd) == -1) die_write(); |
407 |
+ if (close(fd) == -1) die_write(); /* NFS stupidity */ |
408 |
+ if (rename(fntemp,fn)) |
409 |
+ strerr_die6sys(111,FATAL,"unable to move ",fntemp," to ",fn,": "); |
410 |
+ |
411 |
+ _exit(0); |
412 |
+} |
413 |
diff -N -u -r publicfile-0.52.orig/httpd.c publicfile-0.52/httpd.c |
414 |
--- publicfile-0.52.orig/httpd.c Mon Nov 8 23:23:46 1999 |
415 |
+++ publicfile-0.52/httpd.c Wed Aug 29 21:30:34 2001 |
416 |
@@ -15,6 +15,10 @@ |
417 |
#include "substdio.h" |
418 |
#include "error.h" |
419 |
#include "getln.h" |
420 |
+#include "byte.h" |
421 |
+#include "cdb.h" |
422 |
+#include "openreadclose.h" |
423 |
+#include "env.h" |
424 |
|
425 |
int safewrite(int fd,char *buf,int len) |
426 |
{ |
427 |
@@ -51,6 +55,7 @@ |
428 |
stralloc host = {0}; |
429 |
stralloc path = {0}; |
430 |
stralloc ims = {0}; |
431 |
+stralloc basic_auth = {0}; |
432 |
int flagbody = 1; |
433 |
|
434 |
char filebuf[1024]; |
435 |
@@ -75,11 +80,16 @@ |
436 |
out_puts("\r\n"); |
437 |
} |
438 |
|
439 |
-void barf(char *code,char *message) |
440 |
+void barf2(char *code,char *message,char *realm) |
441 |
{ |
442 |
if (protocolnum > 0) { |
443 |
tai_now(&now); |
444 |
header(code,message); |
445 |
+ if(realm) { |
446 |
+ out_puts("WWW-Authenticate: Basic realm=\""); |
447 |
+ out_puts(realm); |
448 |
+ out_puts("\"\r\n"); |
449 |
+ } |
450 |
out_puts("Content-Length: "); |
451 |
out_put(strnum,fmt_ulong(strnum,str_len(message) + 28)); |
452 |
out_puts("\r\n"); |
453 |
@@ -100,8 +110,81 @@ |
454 |
_exit(0); |
455 |
} |
456 |
|
457 |
+void barf(char *code,char *message) |
458 |
+{ |
459 |
+ barf2(code,message,(char *)0); |
460 |
+} |
461 |
+ |
462 |
stralloc fn = {0}; |
463 |
+stralloc accessfn = {0}; |
464 |
stralloc contenttype = {0}; |
465 |
+stralloc realm = {0}; |
466 |
+stralloc realmtxt = {0}; |
467 |
+stralloc key = {0}; |
468 |
+ |
469 |
+void checkauth(void) |
470 |
+{ |
471 |
+ int len; |
472 |
+ int fd; |
473 |
+ int colon; |
474 |
+ static struct cdb c; |
475 |
+ char *x; |
476 |
+ |
477 |
+ len = byte_rchr(fn.s,fn.len,'/'); |
478 |
+ if (!stralloc_copyb(&accessfn,fn.s,len)) _exit(21); |
479 |
+ if (!stralloc_cats(&accessfn,"/.access")) _exit(21); |
480 |
+ if (!stralloc_0(&accessfn)) _exit(21); |
481 |
+ |
482 |
+ if (openreadclose(accessfn.s,&realm,256) == 0) return; |
483 |
+ if (!realm.len) _exit(23); /* no realm */ |
484 |
+ realm.len = byte_chr(realm.s,realm.len,'\n'); |
485 |
+ while (realm.len) { |
486 |
+ if (realm.s[realm.len - 1] != ' ') |
487 |
+ if (realm.s[realm.len - 1] != '\t') |
488 |
+ break; |
489 |
+ --realm.len; |
490 |
+ } |
491 |
+ colon = byte_chr(realm.s,realm.len,':'); |
492 |
+ if (!colon) _exit(23); /* no realm */ |
493 |
+ if (colon == realm.len) { |
494 |
+ if (!stralloc_copys(&realmtxt,"restricted access")) _exit(21); |
495 |
+ } else { |
496 |
+ if (!stralloc_copyb(&realmtxt,realm.s+colon+1,realm.len-(colon+1))) _exit(21); |
497 |
+ realm.len = colon; |
498 |
+ } |
499 |
+ if (!stralloc_0(&realmtxt)) _exit(21); |
500 |
+ |
501 |
+ fd = open_read("/access.cdb"); |
502 |
+ if (fd == -1) _exit(23); |
503 |
+ cdb_init(&c,fd); |
504 |
+ |
505 |
+ x = env_get("HTTPCLIENT"); |
506 |
+ if (x) { |
507 |
+ if (!stralloc_copyb(&key,"C",1)) _exit(21); |
508 |
+ if (!stralloc_cat(&key,&realm)) _exit(21); |
509 |
+ if (!stralloc_catb(&key,":",1)) _exit(21); |
510 |
+ if (!stralloc_cats(&key,x)) _exit(21); |
511 |
+ if (cdb_find(&c,key.s,key.len) == 1) goto AUTH_OK; |
512 |
+ } |
513 |
+ |
514 |
+ if (!basic_auth.len) barf2("401 ","Authorization Required", realmtxt.s); |
515 |
+ |
516 |
+ if (!stralloc_copyb(&key,"U",1)) _exit(21); |
517 |
+ if (!stralloc_cat(&key,&basic_auth)) _exit(21); |
518 |
+ if (cdb_find(&c,key.s,key.len) != 1) |
519 |
+ barf2("401 ","Authorization Required",realmtxt.s); |
520 |
+ |
521 |
+ if (!stralloc_copyb(&key,"R",1)) _exit(21); |
522 |
+ if (!stralloc_cat(&key,&realm)) _exit(21); |
523 |
+ if (!stralloc_catb(&key,":",1)) _exit(21); |
524 |
+ if (!stralloc_cat(&key,&basic_auth)) _exit(21); |
525 |
+ if (cdb_find(&c,key.s,key.len) != 1) barf("403 ","Forbidden"); |
526 |
+ |
527 |
+ AUTH_OK: |
528 |
+ alloc_free(key); |
529 |
+ cdb_free(&c); |
530 |
+ close(fd); |
531 |
+} |
532 |
|
533 |
void get(void) |
534 |
{ |
535 |
@@ -124,6 +207,8 @@ |
536 |
if (!stralloc_cat(&fn,&path)) _exit(21); |
537 |
pathdecode(&fn); |
538 |
if (!stralloc_0(&fn)) _exit(21); |
539 |
+ |
540 |
+ checkauth(); |
541 |
|
542 |
fd = file_open(fn.s,&mtime,&length,1); |
543 |
if (fd == -1) |
544 |
@@ -227,6 +312,7 @@ |
545 |
if (!stralloc_copys(&path,"")) _exit(21); |
546 |
if (!stralloc_copys(&protocol,"")) _exit(21); |
547 |
if (!stralloc_copys(&ims,"")) _exit(21); |
548 |
+ if (!stralloc_copys(&basic_auth,"")) _exit(21); |
549 |
protocolnum = 2; |
550 |
|
551 |
spaces = 0; |
552 |
@@ -302,6 +388,8 @@ |
553 |
if (!stralloc_append(&host,&field.s[i])) _exit(21); |
554 |
if (case_startb(field.s,field.len,"if-modified-since:")) |
555 |
if (!stralloc_copyb(&ims,field.s + 18,field.len - 18)) _exit(21); |
556 |
+ if (case_startb(field.s,field.len,"authorization: basic ")) |
557 |
+ if (!stralloc_copyb(&basic_auth,field.s + 21,field.len - 21)) _exit(21); |
558 |
field.len = 0; |
559 |
} |
560 |
if (!line.len) break; |
561 |
diff -N -u -r publicfile-0.52.orig/openreadclose.c publicfile-0.52/openreadclose.c |
562 |
--- publicfile-0.52.orig/openreadclose.c Wed Dec 31 16:00:00 1969 |
563 |
+++ publicfile-0.52/openreadclose.c Wed Aug 29 14:24:21 2001 |
564 |
@@ -0,0 +1,18 @@ |
565 |
+/* Public domain. */ |
566 |
+ |
567 |
+#include "error.h" |
568 |
+#include "open.h" |
569 |
+#include "readclose.h" |
570 |
+#include "openreadclose.h" |
571 |
+ |
572 |
+int openreadclose(const char *fn,stralloc *sa,unsigned int bufsize) |
573 |
+{ |
574 |
+ int fd; |
575 |
+ fd = open_read(fn); |
576 |
+ if (fd == -1) { |
577 |
+ if (errno == error_noent) return 0; |
578 |
+ return -1; |
579 |
+ } |
580 |
+ if (readclose(fd,sa,bufsize) == -1) return -1; |
581 |
+ return 1; |
582 |
+} |
583 |
diff -N -u -r publicfile-0.52.orig/openreadclose.h publicfile-0.52/openreadclose.h |
584 |
--- publicfile-0.52.orig/openreadclose.h Wed Dec 31 16:00:00 1969 |
585 |
+++ publicfile-0.52/openreadclose.h Wed Aug 29 14:24:21 2001 |
586 |
@@ -0,0 +1,10 @@ |
587 |
+/* Public domain. */ |
588 |
+ |
589 |
+#ifndef OPENREADCLOSE_H |
590 |
+#define OPENREADCLOSE_H |
591 |
+ |
592 |
+#include "stralloc.h" |
593 |
+ |
594 |
+extern int openreadclose(const char *,stralloc *,unsigned int); |
595 |
+ |
596 |
+#endif |
597 |
diff -N -u -r publicfile-0.52.orig/readclose.c publicfile-0.52/readclose.c |
598 |
--- publicfile-0.52.orig/readclose.c Wed Dec 31 16:00:00 1969 |
599 |
+++ publicfile-0.52/readclose.c Wed Aug 29 14:30:52 2001 |
600 |
@@ -0,0 +1,23 @@ |
601 |
+/* Public domain. */ |
602 |
+ |
603 |
+#include <unistd.h> |
604 |
+#include "error.h" |
605 |
+#include "readclose.h" |
606 |
+ |
607 |
+int readclose_append(int fd,stralloc *sa,unsigned int bufsize) |
608 |
+{ |
609 |
+ int r; |
610 |
+ for (;;) { |
611 |
+ if (!stralloc_readyplus(sa,bufsize)) { close(fd); return -1; } |
612 |
+ r = read(fd,sa->s + sa->len,bufsize); |
613 |
+ if (r == -1) if (errno == error_intr) continue; |
614 |
+ if (r <= 0) { close(fd); return r; } |
615 |
+ sa->len += r; |
616 |
+ } |
617 |
+} |
618 |
+ |
619 |
+int readclose(int fd,stralloc *sa,unsigned int bufsize) |
620 |
+{ |
621 |
+ if (!stralloc_copys(sa,"")) { close(fd); return -1; } |
622 |
+ return readclose_append(fd,sa,bufsize); |
623 |
+} |
624 |
diff -N -u -r publicfile-0.52.orig/readclose.h publicfile-0.52/readclose.h |
625 |
--- publicfile-0.52.orig/readclose.h Wed Dec 31 16:00:00 1969 |
626 |
+++ publicfile-0.52/readclose.h Wed Aug 29 14:30:52 2001 |
627 |
@@ -0,0 +1,11 @@ |
628 |
+/* Public domain. */ |
629 |
+ |
630 |
+#ifndef READCLOSE_H |
631 |
+#define READCLOSE_H |
632 |
+ |
633 |
+#include "stralloc.h" |
634 |
+ |
635 |
+extern int readclose_append(int,stralloc *,unsigned int); |
636 |
+extern int readclose(int,stralloc *,unsigned int); |
637 |
+ |
638 |
+#endif |