diff options
-rw-r--r-- | networking/httpd_indexcgi.c | 6 | ||||
-rw-r--r-- | networking/httpd_ssi.c | 102 |
2 files changed, 106 insertions, 2 deletions
diff --git a/networking/httpd_indexcgi.c b/networking/httpd_indexcgi.c index 94c6a692a..2605ad1bc 100644 --- a/networking/httpd_indexcgi.c +++ b/networking/httpd_indexcgi.c | |||
@@ -28,7 +28,8 @@ httpd_indexcgi.c -o index.cgi | |||
28 | /* We don't use printf, as it pulls in >12 kb of code from uclibc (i386). */ | 28 | /* We don't use printf, as it pulls in >12 kb of code from uclibc (i386). */ |
29 | /* Currently malloc machinery is the biggest part of libc we pull in. */ | 29 | /* Currently malloc machinery is the biggest part of libc we pull in. */ |
30 | /* We have only one realloc and one strdup, any idea how to do without? */ | 30 | /* We have only one realloc and one strdup, any idea how to do without? */ |
31 | /* Size (i386, approximate): | 31 | |
32 | /* Size (i386, static uclibc, approximate): | ||
32 | * text data bss dec hex filename | 33 | * text data bss dec hex filename |
33 | * 13036 44 3052 16132 3f04 index.cgi | 34 | * 13036 44 3052 16132 3f04 index.cgi |
34 | * 2576 4 2048 4628 1214 index.cgi.o | 35 | * 2576 4 2048 4628 1214 index.cgi.o |
@@ -210,7 +211,7 @@ static void fmt_04u(/*char *dst,*/ unsigned n) | |||
210 | fmt_02u(n % 100); | 211 | fmt_02u(n % 100); |
211 | } | 212 | } |
212 | 213 | ||
213 | int main(void) | 214 | int main(int argc, char *argv[]) |
214 | { | 215 | { |
215 | dir_list_t *dir_list; | 216 | dir_list_t *dir_list; |
216 | dir_list_t *cdir; | 217 | dir_list_t *cdir; |
@@ -225,6 +226,7 @@ int main(void) | |||
225 | QUERY_STRING = getenv("QUERY_STRING"); | 226 | QUERY_STRING = getenv("QUERY_STRING"); |
226 | if (!QUERY_STRING | 227 | if (!QUERY_STRING |
227 | || QUERY_STRING[0] != '/' | 228 | || QUERY_STRING[0] != '/' |
229 | || strstr(QUERY_STRING, "//") | ||
228 | || strstr(QUERY_STRING, "/../") | 230 | || strstr(QUERY_STRING, "/../") |
229 | || strcmp(strrchr(QUERY_STRING, '/'), "/..") == 0 | 231 | || strcmp(strrchr(QUERY_STRING, '/'), "/..") == 0 |
230 | ) { | 232 | ) { |
diff --git a/networking/httpd_ssi.c b/networking/httpd_ssi.c new file mode 100644 index 000000000..f75805923 --- /dev/null +++ b/networking/httpd_ssi.c | |||
@@ -0,0 +1,102 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2009 Denys Vlasenko <vda.linux@googlemail.com> | ||
3 | * | ||
4 | * Licensed under GPLv2, see file LICENSE in this tarball for details. | ||
5 | */ | ||
6 | |||
7 | /* | ||
8 | * This program is a CGI application. It processes server-side includes: | ||
9 | * <!--#include file="file.html" --> | ||
10 | */ | ||
11 | |||
12 | /* Build a-la | ||
13 | i486-linux-uclibc-gcc \ | ||
14 | -static -static-libgcc \ | ||
15 | -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 \ | ||
16 | -Wall -Wshadow -Wwrite-strings -Wundef -Wstrict-prototypes -Werror \ | ||
17 | -Wold-style-definition -Wdeclaration-after-statement -Wno-pointer-sign \ | ||
18 | -Wmissing-prototypes -Wmissing-declarations \ | ||
19 | -Os -fno-builtin-strlen -finline-limit=0 -fomit-frame-pointer \ | ||
20 | -ffunction-sections -fdata-sections -fno-guess-branch-probability \ | ||
21 | -funsigned-char \ | ||
22 | -falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1 \ | ||
23 | -march=i386 -mpreferred-stack-boundary=2 \ | ||
24 | -Wl,-Map -Wl,link.map -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \ | ||
25 | httpd_ssi.c -o httpd_ssi | ||
26 | */ | ||
27 | |||
28 | /* Size (i386, static uclibc, approximate): | ||
29 | text data bss dec hex filename | ||
30 | 8931 164 68552 77647 12f4f httpd_ssi | ||
31 | */ | ||
32 | |||
33 | #include <sys/types.h> | ||
34 | #include <sys/stat.h> | ||
35 | #include <errno.h> | ||
36 | #include <stdint.h> | ||
37 | #include <stdlib.h> | ||
38 | #include <string.h> | ||
39 | #include <unistd.h> | ||
40 | #include <stdio.h> | ||
41 | #include <dirent.h> | ||
42 | #include <time.h> | ||
43 | |||
44 | static char line[64 * 1024]; | ||
45 | |||
46 | /* | ||
47 | * Currently only handles directives which are alone on the line | ||
48 | */ | ||
49 | static void process_includes(const char *filename) | ||
50 | { | ||
51 | FILE *fp = fopen(filename, "r"); | ||
52 | if (!fp) | ||
53 | exit(1); | ||
54 | |||
55 | #define INCLUDE "<!--#include file=\"" | ||
56 | while (fgets(line, sizeof(line), fp)) { | ||
57 | char *closing_dq; | ||
58 | |||
59 | /* FIXME: output text leading to INCLUDE first */ | ||
60 | if (strncmp(line, INCLUDE, sizeof(INCLUDE)-1) != 0 | ||
61 | || (closing_dq = strchr(line + sizeof(INCLUDE)-1, '"')) == NULL | ||
62 | /* or strstr(line + sizeof(INCLUDE)-1, "\" -->")? */ | ||
63 | ) { | ||
64 | fputs(line, stdout); | ||
65 | continue; | ||
66 | } | ||
67 | *closing_dq = '\0'; | ||
68 | /* FIXME: (1) are relative paths ok? | ||
69 | * (2) if we include a/1.htm and it includes b/2.htm, | ||
70 | * do we need to insert a/b/2.htm or b/2.htm? | ||
71 | * IOW, do we need to "cd $dirname"? | ||
72 | */ | ||
73 | process_includes(line + sizeof(INCLUDE)-1); | ||
74 | /* FIXME: this should be the tail of line after --> */ | ||
75 | putchar('\n'); | ||
76 | } | ||
77 | } | ||
78 | |||
79 | int main(int argc, char *argv[]) | ||
80 | { | ||
81 | if (!argv[1]) | ||
82 | return 1; | ||
83 | |||
84 | /* Seen from busybox.net's Apache: | ||
85 | * HTTP/1.1 200 OK | ||
86 | * Date: Thu, 10 Sep 2009 18:23:28 GMT | ||
87 | * Server: Apache | ||
88 | * Accept-Ranges: bytes | ||
89 | * Connection: close | ||
90 | * Content-Type: text/html | ||
91 | */ | ||
92 | printf( | ||
93 | /* "Date: Thu, 10 Sep 2009 18:23:28 GMT\r\n" */ | ||
94 | /* "Server: Apache\r\n" */ | ||
95 | /* "Accept-Ranges: bytes\r\n" - do we really accept bytes?! */ | ||
96 | "Connection: close\r\n" | ||
97 | "Content-Type: text/html\r\n" | ||
98 | "\r\n" | ||
99 | ); | ||
100 | process_includes(argv[1]); | ||
101 | return 0; | ||
102 | } | ||