From 8997a351b0aa7a487cb78288f05d4edf5bd6d8f4 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 19 Nov 2013 23:07:26 +0100 Subject: m MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/cerberus.c | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/cerberus.c b/src/cerberus.c index 4f9dd0c..26e6b3f 100644 --- a/src/cerberus.c +++ b/src/cerberus.c @@ -48,7 +48,7 @@ int main(int argc, char** argv) signal(SIGQUIT, SIG_IGN); signal(SIGINT, SIG_IGN); - /* Wait for the login shell to exit */ + /* Wait for the login shell to exit */ waitpid(child_pid, &_status, 0); /* Reset terminal ownership and mode */ @@ -139,7 +139,7 @@ void do_login(int argc, char** argv) /* Change that a username has been specified */ - if (username == 0) + if (username == NULL) { printf("%s: no username specified\n", *argv); sleep(ERROR_SLEEP); @@ -233,37 +233,37 @@ void do_login(int argc, char** argv) child_pid = fork(); /* vfork cannot be used as the child changes the user, the parent would not be able to chown the TTY */ - + if (child_pid == -1) { perror("fork"); sleep(ERROR_SLEEP); _exit(1); } - else if (child_pid == 0) + else + return; /* Do not go beyond this in the parent */ + + int ret; + + /* In case the shell does not do this */ + setsid(); + + /* Set controlling terminal */ + if (ioctl(STDIN_FILENO, TIOCSCTTY, 1)) + perror("TIOCSCTTY"); + signal(SIGINT, SIG_DFL); + + /* Partial login */ + ret = entry->pw_uid + ? initgroups(username, entry->pw_gid) /* supplemental groups for user, can require network */ + : setgroups(0, NULL); /* supplemental groups for root, does not require netork */ + if (ret == -1) { - int ret; - - /* In case the shell does not do this */ - setsid(); - - /* Set controlling terminal */ - if (ioctl(STDIN_FILENO, TIOCSCTTY, 1)) - perror("TIOCSCTTY"); - signal(SIGINT, SIG_DFL); - - /* Partial login */ - ret = entry->pw_uid - ? initgroups(username, entry->pw_gid) /* supplemental groups for user, can require network */ - : setgroups(0, NULL); /* supplemental groups for root, does not require netork */ - if (ret == -1) - { - perror(entry->pw_uid ? "initgroups" : "setgroups"); - sleep(ERROR_SLEEP); - _exit(1); - } - set_user(entry); - exec_shell(entry); + perror(entry->pw_uid ? "initgroups" : "setgroups"); + sleep(ERROR_SLEEP); + _exit(1); } + set_user(entry); + exec_shell(entry); } -- cgit v1.2.3-70-g09d2