--- su.c 2014-08-19 12:59:16.385301498 -0400 +++ su.c 2014-08-19 13:56:47.112915751 -0400 @@ -158,15 +158,12 @@ char * const *b; } np; uid_t ruid; - pid_t child_pid, child_pgrp, pid; int asme, ch, asthem, fastlogin, prio, i, retcode, statusp, setmaclabel; u_int setwhat; char *username, *class, shellbuf[MAXPATHLEN]; const char *p, *user, *shell, *mytty, **nargv; const void *v; - struct sigaction sa, sa_int, sa_quit, sa_pipe; - int temp, fds[2]; #ifdef USE_BSM_AUDIT const char *aerr; au_id_t auid; @@ -425,66 +422,6 @@ } } - /* - * We must fork() before setuid() because we need to call - * pam_setcred(pamh, PAM_DELETE_CRED) as root. - */ - sa.sa_flags = SA_RESTART; - sa.sa_handler = SIG_IGN; - sigemptyset(&sa.sa_mask); - sigaction(SIGINT, &sa, &sa_int); - sigaction(SIGQUIT, &sa, &sa_quit); - sigaction(SIGPIPE, &sa, &sa_pipe); - sa.sa_handler = SIG_DFL; - sigaction(SIGTSTP, &sa, NULL); - statusp = 1; - if (pipe(fds) == -1) { - PAM_END(); - err(1, "pipe"); - } - child_pid = fork(); - switch (child_pid) { - default: - sa.sa_handler = SIG_IGN; - sigaction(SIGTTOU, &sa, NULL); - close(fds[0]); - setpgid(child_pid, child_pid); - if (tcgetpgrp(STDERR_FILENO) == getpgrp()) - tcsetpgrp(STDERR_FILENO, child_pid); - close(fds[1]); - sigaction(SIGPIPE, &sa_pipe, NULL); - while ((pid = waitpid(child_pid, &statusp, WUNTRACED)) != -1) { - if (WIFSTOPPED(statusp)) { - child_pgrp = getpgid(child_pid); - if (tcgetpgrp(STDERR_FILENO) == child_pgrp) - tcsetpgrp(STDERR_FILENO, getpgrp()); - kill(getpid(), SIGSTOP); - if (tcgetpgrp(STDERR_FILENO) == getpgrp()) { - child_pgrp = getpgid(child_pid); - tcsetpgrp(STDERR_FILENO, child_pgrp); - } - kill(child_pid, SIGCONT); - statusp = 1; - continue; - } - break; - } - tcsetpgrp(STDERR_FILENO, getpgrp()); - if (pid == -1) - err(1, "waitpid"); - PAM_END(); - exit(WEXITSTATUS(statusp)); - case -1: - PAM_END(); - err(1, "fork"); - case 0: - close(fds[1]); - read(fds[0], &temp, 1); - close(fds[0]); - sigaction(SIGPIPE, &sa_pipe, NULL); - sigaction(SIGINT, &sa_int, NULL); - sigaction(SIGQUIT, &sa_quit, NULL); - /* * Set all user context except for: Environmental variables * Umask Login records (wtmp, etc) Path @@ -555,7 +492,6 @@ execv(shell, np.b); err(1, "%s", shell); - } } static void