X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fuserplex.c;h=357d791225b6f00dfd50a7ba6fbebb1ed9866a20;hb=5f0c1cd631b9abcca90afe15cf129babba86f7f1;hp=3a2da874512f4760bcfbdc69bcc3f0291955ced9;hpb=f2df7a1b1aeeb0cec2309aeb62fae051fd3c687c;p=ashd.git diff --git a/src/userplex.c b/src/userplex.c index 3a2da87..357d791 100644 --- a/src/userplex.c +++ b/src/userplex.c @@ -53,6 +53,7 @@ static void login(struct passwd *pwd) { int fd; + setsid(); if(getuid() == 0) { if(initgroups(pwd->pw_name, pwd->pw_gid)) { flog(LOG_ERR, "could not init group list for %s: %s", pwd->pw_name, strerror(errno)); @@ -86,12 +87,12 @@ static void login(struct passwd *pwd) * getting Kerberos credentials, running PAM session modules, and * who knows what. I'll add them along as I find them useful. */ if(((fd = open(".ashd/output", O_WRONLY | O_APPEND)) >= 0) || - ((fd = open("/dev/null", 0)) >= 0)) { + ((fd = open("/dev/null", O_WRONLY)) >= 0)) { dup2(fd, 1); close(fd); } if(((fd = open(".ashd/error", O_WRONLY | O_APPEND)) >= 0) || - ((fd = open("/dev/null", 0)) >= 0)) { + ((fd = open("/dev/null", O_WRONLY)) >= 0)) { dup2(fd, 2); close(fd); } @@ -112,7 +113,7 @@ static int forkchild(char *usrnm) { struct passwd *pwd; pid_t pid; - int i, fd[2]; + int fd[2]; /* XXX: There should be a way for the child to report errors (like * 404 when htpub doesn't exist), but for now I don't bother with @@ -126,17 +127,15 @@ static int forkchild(char *usrnm) if((pid = fork()) < 0) return(-1); if(pid == 0) { - for(i = 3; i < FD_SETSIZE; i++) { - if(i != fd[0]) - close(i); - } dup2(fd[0], 0); close(fd[0]); + close(fd[1]); login(pwd); execchild(pwd); exit(127); } close(fd[0]); + fcntl(fd[1], F_SETFD, FD_CLOEXEC); return(fd[1]); }