[PATCH] teach swat to default to serving index.html
James Peach
jpeach at sgi.com
Tue Aug 10 02:56:39 GMT 2004
Hi all,
The attached patch (applies against 3.0.6rc2) teaches swat to serve an
index.html file when the enclosing directory is requested. I found this
useful when packaging the HTML docs to be accessible from the swat front
page.
--
James Peach | jpeach at sgi.com | SGI Australian Software Group
I don't speak for SGI.
-------------- next part --------------
diff -r -u samba3-rsync/samba_3_0/source/web/cgi.c work/source/web/cgi.c
--- samba3-rsync/samba_3_0/source/web/cgi.c Tue Jul 27 11:51:32 2004
+++ work/source/web/cgi.c Tue Jul 27 14:16:42 2004
@@ -421,18 +421,38 @@
}
}
- if (!file_exist(file, &st)) {
+ if (sys_stat(file, &st) != 0)
+ {
cgi_setup_error("404 File Not Found","",
"The requested file was not found");
}
- fd = web_open(file,O_RDONLY,0);
+ if (S_ISDIR(st.st_mode))
+ {
+ snprintf(buf, sizeof(buf), "%s/index.html", file);
+ if (!file_exist(buf, &st) || !S_ISREG(st.st_mode))
+ {
+ cgi_setup_error("404 File Not Found","",
+ "The requested file was not found");
+ }
+ }
+ else if (S_ISREG(st.st_mode))
+ {
+ snprintf(buf, sizeof(buf), "%s", file);
+ }
+ else
+ {
+ cgi_setup_error("404 File Not Found","",
+ "The requested file was not found");
+ }
+
+ fd = web_open(buf,O_RDONLY,0);
if (fd == -1) {
cgi_setup_error("404 File Not Found","",
"The requested file was not found");
}
printf("HTTP/1.0 200 OK\r\n");
- if ((p=strrchr_m(file,'.'))) {
+ if ((p=strrchr_m(buf, '.'))) {
if (strcmp(p,".gif")==0) {
printf("Content-Type: image/gif\r\n");
} else if (strcmp(p,".jpg")==0) {
@@ -554,7 +574,7 @@
string_sub(url, "/swat/", "", 0);
- if (url[0] != '/' && strstr(url,"..")==0 && file_exist(url, NULL)) {
+ if (url[0] != '/' && strstr(url,"..")==0) {
cgi_download(url);
}
More information about the samba-technical
mailing list