static char *dirname = NULL;
static char **childspec;
static uid_t minuid = 0;
+static int usesyslog = 0;
static struct user *users = NULL;
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));
flog(LOG_ERR, "could not change to home directory for %s: %s", pwd->pw_name, strerror(errno));
exit(1);
}
+ if(usesyslog)
+ putenv("ASHD_USESYSLOG=1");
+ else
+ unsetenv("ASHD_USESYSLOG");
putenv(sprintf2("HOME=%s", pwd->pw_dir));
putenv(sprintf2("SHELL=%s", pwd->pw_shell));
putenv(sprintf2("USER=%s", pwd->pw_name));
{
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
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]);
}
if(usr->fd < 0)
usr->fd = forkchild(usr->name);
if(sendreq(usr->fd, req, fd)) {
- if(errno == EPIPE) {
+ if((errno == EPIPE) || (errno == ECONNRESET)) {
/* Assume that the child has crashed and restart it. */
close(usr->fd);
usr->fd = forkchild(usr->name);
static void usage(FILE *out)
{
- fprintf(out, "usage: userplex [-hI] [-g GROUP] [-m MIN-UID] [-d PUB-DIR] [PROGRAM ARGS...]\n");
+ fprintf(out, "usage: userplex [-hIs] [-g GROUP] [-m MIN-UID] [-d PUB-DIR] [PROGRAM ARGS...]\n");
}
int main(int argc, char **argv)
int fd;
struct charvbuf csbuf;
- while((c = getopt(argc, argv, "+hIg:m:d:")) >= 0) {
+ while((c = getopt(argc, argv, "+hIsg:m:d:")) >= 0) {
switch(c) {
case 'I':
ignore = 1;
break;
+ case 's':
+ usesyslog = 1;
+ break;
case 'm':
if((minuid = atoi(optarg)) < 1) {
fprintf(stderr, "userplex: argument to -m must be greater than 0\n");