diff options
author | Mattias Andrée <maandree@operamail.com> | 2013-11-19 01:23:19 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2013-11-19 01:23:19 +0100 |
commit | 38e79ce39355048352a26489793bfa8ab9ccf090 (patch) | |
tree | a34d6f8c7bbfc6d8e4532f4393af43b0d612c781 /src | |
parent | move exec instructions into login.c (diff) | |
download | libpassphrase-38e79ce39355048352a26489793bfa8ab9ccf090.tar.gz libpassphrase-38e79ce39355048352a26489793bfa8ab9ccf090.tar.bz2 libpassphrase-38e79ce39355048352a26489793bfa8ab9ccf090.tar.xz |
m
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | src/cerberus.c | 82 |
1 files changed, 50 insertions, 32 deletions
diff --git a/src/cerberus.c b/src/cerberus.c index a4fa33d..6f0ce91 100644 --- a/src/cerberus.c +++ b/src/cerberus.c @@ -21,6 +21,16 @@ /* TODO use log */ +#ifdef USE_TTY_GROUP +static gid_t tty_group = 0; +#endif +static struct passwd* entry; +static pid_t child_pid; + + +void do_login(int argc, char** argv); + + /** * Mane method * @@ -30,17 +40,36 @@ */ int main(int argc, char** argv) { + int _status; + + do_login(argc, argv); + + /* Wait for the login shell to exit */ + waitpid(child_pid, &_status, 0); + + /* Reset terminal ownership and mode */ + chown_tty(0, tty_group, 0); + + return 0; +} + + +/** + * Do everything before the fork and do everything the exec fork + * + * @param argc The number of command line arguments + * @param argv The command line arguments + */ +void do_login(int argc, char** argv) +{ char* username = NULL; char* hostname = NULL; char* passphrase = NULL; char preserve_env = 0; char skip_auth = 0; #ifdef USE_TTY_GROUP - static gid_t tty_group = 0; struct group* group; #endif - struct passwd* entry; - pid_t child_pid; /* Disable echoing */ @@ -110,7 +139,7 @@ int main(int argc, char** argv) { printf("%s: no username specified\n", *argv); sleep(ERROR_SLEEP); - return 2; + _exit(2); } @@ -152,7 +181,7 @@ int main(int argc, char** argv) else printf("User does not exist\n"); sleep(ERROR_SLEEP); - return 1; + _exit(1); } username = entry->pw_name; @@ -190,33 +219,22 @@ int main(int argc, char** argv) ensure_shell(entry); set_environ(entry, preserve_env); - { - 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"); - return 1; - } - else if (child_pid == 0) - { - /* Partial login */ - /* TODO set supplemental groups */ - set_user(entry); - exec_shell(entry); - } - else - { - int _status; - waitpid(child_pid, &_status, 0); - - /* Reset terminal ownership and mode */ - chown_tty(0, tty_group, 0); - } - } - return 0; + 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"); + _exit(1); + } + else if (child_pid == 0) + { + /* Partial login */ + /* TODO set supplemental groups */ + set_user(entry); + exec_shell(entry); + } } |