X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=sources%2Fwwwd.c;h=9fceda5330c020cf5635f43f2a36bdb914e56b76;hp=f9b49fa86fcef631eb9c3c2821cba1841111b3c2;hb=d5df702be171519375f3e260cffb7ee93ab656f4;hpb=4702c4198c0a6601c72f3b95d33d654c568f1b5f diff --git a/sources/wwwd.c b/sources/wwwd.c index f9b49fa..9fceda5 100644 --- a/sources/wwwd.c +++ b/sources/wwwd.c @@ -70,6 +70,8 @@ int main(int argc, char *argv[]) int list_fd, conn_fd; int waiting = 0; int compat = 0; + int reroot = 0; + char * rootdir; pid_t pid; struct sockaddr_in cli_add; socklen_t len; @@ -80,7 +82,7 @@ int main(int argc, char *argv[]) */ int i; opterr = 0; /* don't want writing to stderr */ - while ( (i = getopt(argc, argv, "hdicw:")) != -1) { + while ( (i = getopt(argc, argv, "hdicw:r:")) != -1) { switch (i) { /* * Handling options @@ -102,6 +104,11 @@ int main(int argc, char *argv[]) case 'w': waiting = strtol(optarg, NULL, 10); break; + case 'r': + printf("chroot\n"); + reroot = 1; + rootdir = optarg; + break; case '?': /* unrecognized options */ printf("Unrecognized options -%c\n",optopt); usage(); @@ -126,6 +133,18 @@ int main(int argc, char *argv[]) if ( (list_fd = sockbind2(argv[optind], "www", 6, SOCK_STREAM)) < 0) { return 1; } + /* chroot if requested */ + if (reroot) { + printf("chroot to %s\n", rootdir); + if (chdir(rootdir)) { + perror("Cannot find directory to chroot"); + exit(1); + } + if (chroot(rootdir)) { + perror("Cannot chroot"); + exit(1); + } + } /* release privileges and go daemon */ if (setgid(65534) !=0) { /* first give away group privileges */ perror("cannot give away group privileges");