Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--no-daemon only valid 3rd arg #11

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed nweb
Binary file not shown.
92 changes: 0 additions & 92 deletions nweb.log

This file was deleted.

32 changes: 22 additions & 10 deletions nweb23.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ struct {
{"tar", "image/tar" },
{"htm", "text/html" },
{"html","text/html" },
{"json","application/json" },
{"pdf","application/pdf"},
{"css","text/css"},
{"js","application/javascript"},
{0,0} };

void logger(int type, char *s1, char *s2, int socket_fd)
Expand Down Expand Up @@ -91,6 +95,8 @@ void web(int fd, int hit)
break;
}
}
if(buffer[5] == '/') /* check for illegal absolute directory path use */
logger(FORBIDDEN,"Absolute directory (/) path names not supported",buffer,fd);
for(j=0;j<i-1;j++) /* check for illegal parent directory use .. */
if(buffer[j] == '.' && buffer[j+1] == '.') {
logger(FORBIDDEN,"Parent directory (..) path names not supported",buffer,fd);
Expand All @@ -108,7 +114,7 @@ void web(int fd, int hit)
break;
}
}
if(fstr == 0) logger(FORBIDDEN,"file extension type not supported",buffer,fd);
if(fstr == 0) fstr = "application/octet-stream";

if(( file_fd = open(&buffer[5],O_RDONLY)) == -1) { /* open the file for reading */
logger(NOTFOUND, "failed to open file",&buffer[5],fd);
Expand Down Expand Up @@ -136,13 +142,13 @@ int main(int argc, char **argv)
static struct sockaddr_in cli_addr; /* static = initialised to zeros */
static struct sockaddr_in serv_addr; /* static = initialised to zeros */

if( argc < 3 || argc > 3 || !strcmp(argv[1], "-?") ) {
if( argc < 3 || argc > 4 || !strcmp(argv[1], "-?") ) {
(void)printf("hint: nweb Port-Number Top-Directory\t\tversion %d\n\n"
"\tnweb is a small and very safe mini web server\n"
"\tnweb only servers out file/web pages with extensions named below\n"
"\t and only from the named directory or its sub-directories.\n"
"\tThere is no fancy features = safe and secure.\n\n"
"\tExample: nweb 8181 /home/nwebdir &\n\n"
"\tExample: nweb 8181 /home/nwebdir --no-daemon &\n\n"
"\tOnly Supports:", VERSION);
for(i=0;extensions[i].ext != 0;i++)
(void)printf(" %s",extensions[i].ext);
Expand All @@ -164,13 +170,19 @@ int main(int argc, char **argv)
exit(4);
}
/* Become deamon + unstopable and no zombies children (= no wait()) */
if(fork() != 0)
return 0; /* parent returns OK to shell */
(void)signal(SIGCLD, SIG_IGN); /* ignore child death */
(void)signal(SIGHUP, SIG_IGN); /* ignore terminal hangups */
for(i=0;i<32;i++)
(void)close(i); /* close open files */
(void)setpgrp(); /* break away from process group */
if(argc == 3){
if(fork() != 0)
return 0; /* parent returns OK to shell */
(void)signal(SIGCLD, SIG_IGN); /* ignore child death */
(void)signal(SIGHUP, SIG_IGN); /* ignore terminal hangups */
for(i=0;i<32;i++)
(void)close(i); /* close open files */
(void)setpgrp(); /* break away from process group */
}else if(argc == 4 && strcmp(argv[3] ,"--no-daemon")){
(void)printf("ERROR: wrong arg %s, only correct: --no-daemon \n",argv[3]);
exit(4);
}

logger(LOG,"nweb starting",argv[1],getpid());
/* setup the network socket */
if((listenfd = socket(AF_INET, SOCK_STREAM,0)) <0)
Expand Down
Binary file removed nweb23_Fedora_17_64
Binary file not shown.
Binary file removed nweb23_RHEL63_64
Binary file not shown.
Binary file removed nweb23_SLES_11_64
Binary file not shown.
Binary file removed nweb23_aix6_1_7
Binary file not shown.
Binary file removed nweb23_openSUSU_12_1_64
Binary file not shown.
Binary file removed nweb23_raspberry_pi
Binary file not shown.
Binary file removed nweb23_ubuntu_12_4_32
Binary file not shown.
Binary file removed nweb23_ubuntu_12_4_64
Binary file not shown.