aboutsummaryrefslogtreecommitdiffstats
path: root/src/cerberus.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2013-11-19 23:07:26 +0100
committerMattias Andrée <maandree@operamail.com>2013-11-19 23:07:26 +0100
commit8997a351b0aa7a487cb78288f05d4edf5bd6d8f4 (patch)
tree69f577d838da75e2a3dacc6f02ea47e9c5ab3956 /src/cerberus.c
parentset supplemental groups (diff)
downloadlibpassphrase-8997a351b0aa7a487cb78288f05d4edf5bd6d8f4.tar.gz
libpassphrase-8997a351b0aa7a487cb78288f05d4edf5bd6d8f4.tar.bz2
libpassphrase-8997a351b0aa7a487cb78288f05d4edf5bd6d8f4.tar.xz
m
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/cerberus.c')
-rw-r--r--src/cerberus.c52
1 files changed, 26 insertions, 26 deletions
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);
}