Follow up to my swat FAQ addition and *.txt file format failure
Ron Alexander
rcalex at home.com
Thu Aug 31 18:35:39 GMT 2000
I have found and fixed the problem. The problem was that swat was not
designed to handle links to txt files. The fix was to detect that and change
the Content-Type to text/plain. (see listing at end)
The swat home page had the following added between Books and Feedback
Additional Documentation and FAQS
Samba FAQ
Samba META FAQ
Samba SERVER FAQ
I also had to move the files like DIAGNOSIS.txt to the docs directory since
the html references are to ../DIAGNOSIS.txt not ../textdocs/DIAGNOSIS.txt.
My question is, would the samba team like to accept these changes or not. I
have to tell you that I am NOT a Unix or Linux guy, so I will have some
difficulty creating patches. I am also going to be on vacation for a month
starting Sep. 16.
I also noticed lot's of other problems with the entire set of documentation
that I would be happy to work on if anyone is interested and can act as
mentor.
Here is my new version with the additions marked with <<<<<<<<<<<<<<<<
/***************************************************************************
handle a file download
***************************************************************************/
static void cgi_download(char *file)
{
SMB_STRUCT_STAT st;
char buf[1024];
int fd, l, i;
char *p;
/* sanitise the filename */
for (i=0;file[i];i++) {
if (!isalnum((int)file[i]) && !strchr("/.-_", file[i])) {
cgi_setup_error("404 File Not Found","",
"Illegal character in filename");
}
}
if (!file_exist(file, &st)) {
cgi_setup_error("404 File Not Found","",
"The requested file was not found");
}
fd = sys_open(file,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(file,'.'))) {
if (strcmp(p,".gif")==0) {
printf("Content-Type: image/gif\r\n");
} else if (strcmp(p,".jpg")==0) {
printf("Content-Type: image/jpeg\r\n");
} else if (strcmp(p,".txt")==0) { <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
printf("Content-Type: text/plain\r\n"); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
} else {
printf("Content-Type: text/html\r\n");
}
}
printf("Expires: %s\r\n", http_timestring(time(NULL)+EXPIRY_TIME));
printf("Content-Length: %d\r\n\r\n", (int)st.st_size);
while ((l=read(fd,buf,sizeof(buf)))>0) {
fwrite(buf, 1, l, stdout);
}
close(fd);
exit(0);
}
Regards,
Ron Alexander
More information about the samba-technical
mailing list