4 * This program gives Linux machines a reasonable secure way to boot single
5 * user. It forces the user to supply the root password before a shell is
6 * started. If there is a shadow password file and the encrypted root password
7 * is "x" the shadow password will be used.
9 * Copyright (C) 1998-2003 Miquel van Smoorenburg.
10 * Copyright (C) 2012 Karel Zak <kzak@redhat.com>
11 * Copyright (C) 2012 Werner Fink <werner@suse.de>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 #include <sys/types.h>
42 #include <sys/ioctl.h>
47 #ifdef HAVE_LIBSELINUX
48 # include <selinux/selinux.h>
49 # include <selinux/get_context_list.h>
54 # include <sys/param.h>
58 #include "closestream.h"
60 #include "pathnames.h"
63 #include "sulogin-consoles.h"
66 static unsigned int timeout
;
68 static volatile uint32_t openfd
; /* Remember higher file descriptors */
69 static volatile uint32_t *usemask
;
71 struct sigaction saved_sigint
;
72 struct sigaction saved_sigtstp
;
73 struct sigaction saved_sigquit
;
74 struct sigaction saved_sighup
;
75 struct sigaction saved_sigchld
;
77 static volatile sig_atomic_t alarm_rised
;
78 static volatile sig_atomic_t sigchild
;
84 static int locked_account_password(const char *passwd
)
86 if (passwd
&& (*passwd
== '*' || *passwd
== '!'))
93 * For the case plymouth is found on this system
95 static int plymouth_command(const char* arg
)
97 const char *cmd
= "/usr/bin/plymouth";
98 static int has_plymouth
= 1;
106 int fd
= open("/dev/null", O_RDWR
);
113 execl(cmd
, cmd
, arg
, (char *) NULL
);
115 } else if (pid
> 0) {
117 waitpid(pid
, &status
, 0);
127 * Fix the tty modes and set reasonable defaults.
129 static void tcinit(struct console
*con
)
131 int mode
= 0, flags
= 0;
132 struct termios
*tio
= &con
->tio
;
135 #ifdef TIOCGLCKTRMIOS
136 int i
= (plymouth_command("--ping")) ? 20 : 0;
140 * With plymouth the termios flags become changed after this
141 * function had changed the termios.
143 memset(&lock
, 0, sizeof(struct termios
));
144 if (ioctl(fd
, TIOCGLCKTRMIOS
, &lock
) < 0)
146 if (!lock
.c_iflag
&& !lock
.c_oflag
&& !lock
.c_cflag
&& !lock
.c_lflag
)
148 if (i
== 15 && plymouth_command("quit") != 0)
152 memset(&lock
, 0, sizeof(struct termios
));
153 ioctl(fd
, TIOCSLCKTRMIOS
, &lock
);
158 if (tcgetattr(fd
, tio
) < 0) {
159 warn(_("tcgetattr failed"));
160 con
->flags
|= CON_NOTTY
;
164 /* Handle lines other than virtual consoles here */
165 #if defined(KDGKBMODE)
166 if (ioctl(fd
, KDGKBMODE
, &mode
) < 0)
169 speed_t ispeed
, ospeed
;
173 /* this is a modem line */
174 con
->flags
|= CON_SERIAL
;
176 /* Flush input and output queues on modem lines */
177 tcflush(fd
, TCIOFLUSH
);
179 ispeed
= cfgetispeed(tio
);
180 ospeed
= cfgetospeed(tio
);
182 if (!ispeed
) ispeed
= TTYDEF_SPEED
;
183 if (!ospeed
) ospeed
= TTYDEF_SPEED
;
185 tio
->c_cflag
= CREAD
| CS8
| HUPCL
| (tio
->c_cflag
& CLOCAL
);
188 tio
->c_oflag
&= OPOST
| ONLCR
;
190 cfsetispeed(tio
, ispeed
);
191 cfsetospeed(tio
, ospeed
);
193 #ifdef HAVE_STRUCT_TERMIOS_C_LINE
196 tio
->c_cc
[VTIME
] = 0;
199 if (ioctl(fd
, TIOCGWINSZ
, &ws
) == 0) {
201 if (ws
.ws_row
== 0) {
205 if (ws
.ws_col
== 0) {
210 ignore_result( ioctl(fd
, TIOCSWINSZ
, &ws
) );
213 setlocale(LC_CTYPE
, "POSIX");
216 #if defined(IUTF8) && defined(KDGKBMODE)
217 /* Handle mode of current keyboard setup, e.g. for UTF-8 */
220 setlocale(LC_CTYPE
, "C.UTF-8");
221 flags
|= UL_TTY_UTF8
;
227 setlocale(LC_CTYPE
, "POSIX");
231 setlocale(LC_CTYPE
, "POSIX");
233 reset_virtual_console(tio
, flags
);
235 if (tcsetattr(fd
, TCSANOW
, tio
))
236 warn(_("tcsetattr failed"));
238 /* Enable blocking mode for read and write */
239 if ((flags
= fcntl(fd
, F_GETFL
, 0)) != -1)
240 ignore_result( fcntl(fd
, F_SETFL
, flags
& ~O_NONBLOCK
) );
244 * Finalize the tty modes on modem lines.
246 static void tcfinal(struct console
*con
)
251 if ((con
->flags
& CON_SERIAL
) == 0) {
252 setenv("TERM", "linux", 1);
255 if (con
->flags
& CON_NOTTY
) {
256 setenv("TERM", "dumb", 1);
260 #if defined (__s390__) || defined (__s390x__)
261 setenv("TERM", "dumb", 1);
263 setenv("TERM", "vt102", 1);
268 tio
->c_iflag
|= (IXON
| IXOFF
);
269 tio
->c_lflag
|= (ICANON
| ISIG
| ECHO
|ECHOE
|ECHOK
|ECHOKE
);
270 tio
->c_oflag
|= OPOST
;
272 tio
->c_cc
[VINTR
] = CINTR
;
273 tio
->c_cc
[VQUIT
] = CQUIT
;
274 tio
->c_cc
[VERASE
] = con
->cp
.erase
;
275 tio
->c_cc
[VKILL
] = con
->cp
.kill
;
276 tio
->c_cc
[VEOF
] = CEOF
;
278 tio
->c_cc
[VSWTC
] = _POSIX_VDISABLE
;
279 #elif defined(VSWTCH)
280 tio
->c_cc
[VSWTCH
] = _POSIX_VDISABLE
;
282 tio
->c_cc
[VSTART
] = CSTART
;
283 tio
->c_cc
[VSTOP
] = CSTOP
;
284 tio
->c_cc
[VSUSP
] = CSUSP
;
285 tio
->c_cc
[VEOL
] = _POSIX_VDISABLE
;
287 if (con
->cp
.eol
== CR
) {
288 tio
->c_iflag
|= ICRNL
;
289 tio
->c_iflag
&= ~(INLCR
|IGNCR
);
290 tio
->c_oflag
|= ONLCR
;
291 tio
->c_oflag
&= ~(OCRNL
|ONLRET
);
294 switch (con
->cp
.parity
) {
297 tio
->c_cflag
&= ~(PARODD
| PARENB
);
298 tio
->c_iflag
&= ~(INPCK
| ISTRIP
);
300 case 1: /* odd parity */
301 tio
->c_cflag
|= PARODD
;
303 case 2: /* even parity */
304 tio
->c_cflag
|= PARENB
;
305 tio
->c_iflag
|= (INPCK
| ISTRIP
);
307 case (1 | 2): /* no parity bit */
308 tio
->c_cflag
&= ~CSIZE
;
313 /* Set line attributes */
314 tcsetattr(fd
, TCSANOW
, tio
);
320 static void alrm_handler(int sig
__attribute__((unused
)))
322 /* Timeout expired */
326 static void chld_handler(int sig
__attribute__((unused
)))
331 static void mask_signal(int signal
, void (*handler
)(int),
332 struct sigaction
*origaction
)
334 struct sigaction newaction
;
336 newaction
.sa_handler
= handler
;
337 sigemptyset(&newaction
.sa_mask
);
338 newaction
.sa_flags
= 0;
340 sigaction(signal
, &newaction
, origaction
);
343 static void unmask_signal(int signal
, struct sigaction
*sa
)
345 sigaction(signal
, sa
, NULL
);
349 * See if an encrypted password is valid. The encrypted password is checked for
350 * traditional-style DES and FreeBSD-style MD5 encryption.
352 static int valid(const char *pass
)
365 * up to 4 bytes for the signature e.g. $1$
367 for (s
= pass
+1; *s
&& *s
!= '$'; s
++);
372 if ((off
= (off_t
)(s
-pass
)) > 4 || off
< 3)
375 memset(id
, '\0', sizeof(id
));
376 strncpy(id
, pass
, off
);
379 * up to 16 bytes for the salt
381 for (; *s
&& *s
!= '$'; s
++);
386 if ((off_t
)(s
-pass
) > 16)
392 * the MD5 hash (128 bits or 16 bytes) encoded in base64 = 22 bytes
394 if ((strcmp(id
, "$1$") == 0) && (len
< 22 || len
> 24))
398 * the SHA-256 hash 43 bytes
400 if ((strcmp(id
, "$5$") == 0) && (len
< 42 || len
> 44))
404 * the SHA-512 hash 86 bytes
406 if ((strcmp(id
, "$6$") == 0) && (len
< 85 || len
> 87))
414 if (strlen(pass
) != 13)
417 for (s
= pass
; *s
; s
++) {
418 if ((*s
< '0' || *s
> '9') &&
419 (*s
< 'a' || *s
> 'z') &&
420 (*s
< 'A' || *s
> 'Z') &&
421 *s
!= '.' && *s
!= '/')
428 * Set a variable if the value is not NULL.
430 static inline void set(char **var
, char *val
)
437 * Get the root password entry.
439 static struct passwd
*getrootpwent(int try_manually
)
441 static struct passwd pwd
;
445 static char line
[2 * BUFSIZ
];
446 static char sline
[2 * BUFSIZ
];
450 * First, we try to get the password the standard way using normal
453 if ((pw
= getpwnam("root")) &&
454 !strcmp(pw
->pw_passwd
, "x") &&
455 (spw
= getspnam("root")))
456 pw
->pw_passwd
= spw
->sp_pwdp
;
458 if (pw
|| !try_manually
)
462 * If we come here, we could not retrieve the root password through
463 * library calls and we try to read the password and shadow files
466 pwd
.pw_name
= "root";
468 pwd
.pw_gecos
= "Super User";
474 if ((fp
= fopen(_PATH_PASSWD
, "r")) == NULL
) {
475 warn(_("cannot open %s"), _PATH_PASSWD
);
480 * Find root in the password file.
482 while ((p
= fgets(line
, sizeof(line
), fp
)) != NULL
) {
483 if (strncmp(line
, "root:", 5) != 0)
486 set(&pwd
.pw_passwd
, strsep(&p
, ":"));
489 set(&pwd
.pw_gecos
, strsep(&p
, ":"));
490 set(&pwd
.pw_dir
, strsep(&p
, ":"));
491 set(&pwd
.pw_shell
, strsep(&p
, "\n"));
498 * If the encrypted password is valid or not found, return.
501 warnx(_("%s: no entry for root\n"), _PATH_PASSWD
);
504 if (valid(pwd
.pw_passwd
))
508 * The password is invalid. If there is a shadow password, try it.
510 *pwd
.pw_passwd
= '\0';
511 if ((fp
= fopen(_PATH_SHADOW_PASSWD
, "r")) == NULL
) {
512 warn(_("cannot open %s"), _PATH_PASSWD
);
515 while ((p
= fgets(sline
, sizeof(sline
), fp
)) != NULL
) {
516 if (strncmp(sline
, "root:", 5) != 0)
519 set(&pwd
.pw_passwd
, strsep(&p
, ":"));
525 * If the password is still invalid, NULL it, and return.
528 warnx(_("%s: no entry for root"), _PATH_SHADOW_PASSWD
);
529 *pwd
.pw_passwd
= '\0';
531 /* locked accont passwords are valid too */
532 if (!locked_account_password(pwd
.pw_passwd
) && !valid(pwd
.pw_passwd
)) {
533 warnx(_("%s: root password garbled"), _PATH_SHADOW_PASSWD
);
534 *pwd
.pw_passwd
= '\0';
540 * Ask by prompt for the password.
542 static void doprompt(const char *crypted
, struct console
*con
, int deny
)
546 if (con
->flags
& CON_SERIAL
) {
549 * For prompting: map NL in output to CR-NL
550 * otherwise we may see stairs in the output.
552 tty
.c_oflag
|= (ONLCR
| OPOST
);
553 tcsetattr(con
->fd
, TCSADRAIN
, &tty
);
555 if (con
->file
== (FILE*)0) {
556 if ((con
->file
= fdopen(con
->fd
, "r+")) == (FILE*)0)
561 fprintf(con
->file
, _("\nCannot open access to console, the root account is locked.\n"
562 "See sulogin(8) man page for more details.\n\n"
563 "Press Enter to continue.\n"));
565 #if defined(USE_ONELINE)
566 if (crypted
[0] && !locked_account_password(crypted
))
567 fprintf(con
->file
, _("Give root password for login: "));
569 fprintf(con
->file
, _("Press Enter for login: "));
571 if (crypted
[0] && !locked_account_password(crypted
))
572 fprintf(con
->file
, _("Give root password for maintenance\n"));
574 fprintf(con
->file
, _("Press Enter for maintenance\n"));
575 fprintf(con
->file
, _("(or press Control-D to continue): "));
580 if (con
->flags
& CON_SERIAL
)
581 tcsetattr(con
->fd
, TCSADRAIN
, &con
->tio
);
585 * Make sure to have an own session and controlling terminal
587 static void setup(struct console
*con
)
589 pid_t pid
, pgrp
, ppgrp
, ttypgrp
;
592 if (con
->flags
& CON_NOTTY
)
597 * Only go through this trouble if the new
598 * tty doesn't fall in this process group.
602 ppgrp
= getpgid(getppid());
603 ttypgrp
= tcgetpgrp(fd
);
605 if (pgrp
!= ttypgrp
&& ppgrp
!= ttypgrp
) {
606 if (pid
!= getsid(0)) {
607 if (pid
== getpgid(0))
608 setpgid(0, getpgid(getppid()));
612 mask_signal(SIGHUP
, SIG_IGN
, &saved_sighup
);
614 ioctl(STDIN_FILENO
, TIOCNOTTY
, (char *)1);
615 unmask_signal(SIGHUP
, &saved_sighup
);
616 if (fd
> STDIN_FILENO
) close(STDIN_FILENO
);
617 if (fd
> STDOUT_FILENO
) close(STDOUT_FILENO
);
618 if (fd
> STDERR_FILENO
) close(STDERR_FILENO
);
620 ioctl(fd
, TIOCSCTTY
, (char *)1);
621 tcsetpgrp(fd
, ppgrp
);
623 dup2(fd
, STDIN_FILENO
);
624 dup2(fd
, STDOUT_FILENO
);
625 dup2(fd
, STDERR_FILENO
);
626 con
->fd
= STDIN_FILENO
;
628 for (fd
= STDERR_FILENO
+1; fd
< 32; fd
++) {
629 if (openfd
& (1<<fd
)) {
637 * Ask for the password. Note that there is no default timeout as we normally
638 * skip this during boot.
640 static char *getpasswd(struct console
*con
)
644 static char pass
[128], *ptr
;
652 if (con
->flags
& CON_NOTTY
)
658 tty
.c_iflag
&= ~(IUCLC
|IXON
|IXOFF
|IXANY
);
659 tty
.c_lflag
&= ~(ECHO
|ECHOE
|ECHOK
|ECHONL
|TOSTOP
|ISIG
);
660 tc
= (tcsetattr(fd
, TCSAFLUSH
, &tty
) == 0);
662 sigemptyset(&sa
.sa_mask
);
663 sa
.sa_handler
= alrm_handler
;
665 sigaction(SIGALRM
, &sa
, NULL
);
671 cp
->eol
= *ptr
= '\0';
673 eightbit
= ((con
->flags
& CON_SERIAL
) == 0 || (tty
.c_cflag
& (PARODD
|PARENB
)) == 0);
674 while (cp
->eol
== '\0') {
675 if (read(fd
, &c
, 1) < 1) {
676 if (errno
== EINTR
|| errno
== EAGAIN
) {
689 warn(_("cannot read %s"), con
->tty
);
697 else if (c
!= (ascval
= (c
& 0177))) {
699 for (bits
= 1, mask
= 1; mask
& 0177; mask
<<= 1) {
703 cp
->parity
|= ((bits
& 1) ? 1 : 2);
723 while (ptr
> &pass
[0])
729 if ((size_t)(ptr
- &pass
[0]) >= (sizeof(pass
) -1 )) {
730 fprintf(stderr
, "sulogin: input overrun at %s\n\r", con
->tty
);
741 tcsetattr(fd
, TCSAFLUSH
, &con
->tio
);
742 if (ret
&& *ret
!= '\0')
750 * Password was OK, execute a shell.
752 static void sushell(struct passwd
*pwd
)
754 char shell
[PATH_MAX
];
760 * Set directory and shell.
762 if (chdir(pwd
->pw_dir
) != 0) {
763 warn(_("%s: change directory failed"), pwd
->pw_dir
);
764 printf(_("Logging in with home = \"/\".\n"));
767 warn(_("change directory to system root failed"));
770 if ((p
= getenv("SUSHELL")) != NULL
)
772 else if ((p
= getenv("sushell")) != NULL
)
775 if (pwd
->pw_shell
[0])
776 su_shell
= pwd
->pw_shell
;
778 su_shell
= "/bin/sh";
780 if ((p
= strrchr(su_shell
, '/')) == NULL
)
785 snprintf(shell
, sizeof(shell
), profile
? "-%s" : "%s", p
);
788 * Set some important environment variables.
790 if (getcwd(home
, sizeof(home
)) == NULL
)
793 setenv("HOME", home
, 1);
794 setenv("LOGNAME", "root", 1);
795 setenv("USER", "root", 1);
797 setenv("SHLVL","0",1);
800 * Try to execute a shell.
802 setenv("SHELL", su_shell
, 1);
803 unmask_signal(SIGINT
, &saved_sigint
);
804 unmask_signal(SIGTSTP
, &saved_sigtstp
);
805 unmask_signal(SIGQUIT
, &saved_sigquit
);
806 mask_signal(SIGHUP
, SIG_DFL
, NULL
);
808 #ifdef HAVE_LIBSELINUX
809 if (is_selinux_enabled() > 0) {
810 security_context_t scon
=NULL
;
813 if (getseuserbyname("root", &seuser
, &level
) == 0) {
814 if (get_default_context_with_level(seuser
, level
, 0, &scon
) == 0) {
815 if (setexeccon(scon
) != 0)
816 warnx(_("setexeccon failed"));
824 execl(su_shell
, shell
, NULL
);
825 warn(_("failed to execute %s"), su_shell
);
827 setenv("SHELL", "/bin/sh", 1);
828 execl("/bin/sh", profile
? "-sh" : "sh", NULL
);
829 warn(_("failed to execute %s"), "/bin/sh");
832 static void usage(FILE *out
)
834 fputs(USAGE_HEADER
, out
);
836 " %s [options] [tty device]\n"), program_invocation_short_name
);
838 fputs(USAGE_SEPARATOR
, out
);
839 fputs(_("Single-user login.\n"), out
);
841 fputs(USAGE_OPTIONS
, out
);
842 fputs(_(" -p, --login-shell start a login shell\n"
843 " -t, --timeout <seconds> max time to wait for a password (default: no limit)\n"
844 " -e, --force examine password files directly if getpwnam(3) fails\n"),
847 fputs(USAGE_SEPARATOR
, out
);
848 fputs(USAGE_HELP
, out
);
849 fputs(USAGE_VERSION
, out
);
850 fprintf(out
, USAGE_MAN_TAIL("sulogin(8)"));
853 int main(int argc
, char **argv
)
856 struct list_head
*ptr
;
865 static const struct option longopts
[] = {
866 { "login-shell", 0, 0, 'p' },
867 { "timeout", 1, 0, 't' },
868 { "force", 0, 0, 'e' },
869 { "help", 0, 0, 'h' },
870 { "version", 0, 0, 'V' },
875 * If we are init we need to set up a own session.
877 if ((pid
= getpid()) == 1) {
879 ignore_result( ioctl(STDIN_FILENO
, TIOCSCTTY
, (char *) 1) );
882 setlocale(LC_ALL
, "");
883 bindtextdomain(PACKAGE
, LOCALEDIR
);
885 atexit(close_stdout
); /* XXX */
888 * See if we have a timeout flag.
890 while ((c
= getopt_long(argc
, argv
, "ehpt:V", longopts
, NULL
)) != -1) {
893 timeout
= strtou32_or_err(optarg
, _("invalid timeout argument"));
902 printf(UTIL_LINUX_VERSION
);
915 errx(EXIT_FAILURE
, _("only superuser can run this program"));
917 mask_signal(SIGQUIT
, SIG_IGN
, &saved_sigquit
);
918 mask_signal(SIGTSTP
, SIG_IGN
, &saved_sigtstp
);
919 mask_signal(SIGINT
, SIG_IGN
, &saved_sigint
);
920 mask_signal(SIGHUP
, SIG_IGN
, &saved_sighup
);
923 emergency_do_mounts();
924 atexit( emergency_do_umounts
);
927 * See if we need to open an other tty device.
932 if (!tty
|| *tty
== '\0')
933 tty
= getenv("CONSOLE");
936 * Detect possible consoles, use stdin as fallback.
937 * If an optional tty is given, reconnect it to stdin.
939 reconnect
= detect_consoles(tty
, STDIN_FILENO
, &consoles
);
942 * If previous stdin was not the speified tty and therefore reconnected
943 * to the specified tty also reconnect stdout and stderr.
946 if (isatty(STDOUT_FILENO
) == 0)
947 dup2(STDOUT_FILENO
, STDIN_FILENO
);
948 if (isatty(STDERR_FILENO
) == 0)
949 dup2(STDOUT_FILENO
, STDERR_FILENO
);
955 if (list_empty(&consoles
)) {
958 err(EXIT_FAILURE
, _("cannot open console"));
962 * Get the root password.
964 if ((pwd
= getrootpwent(opt_e
)) == NULL
) {
965 warnx(_("cannot open password database"));
971 * Ask for the password on the consoles.
973 list_for_each(ptr
, &consoles
) {
974 con
= list_entry(ptr
, struct console
, entry
);
975 if (con
->id
>= CONMAX
)
978 openfd
|= (1 << con
->fd
);
982 if ((con
->fd
= open(con
->tty
, O_RDWR
| O_NOCTTY
| O_NONBLOCK
)) < 0)
984 openfd
|= (1 << con
->fd
);
987 ptr
= (&consoles
)->next
;
988 usemask
= (uint32_t*) mmap(NULL
, sizeof(uint32_t),
989 PROT_READ
|PROT_WRITE
,
990 MAP_ANONYMOUS
|MAP_SHARED
, -1, 0);
992 if (ptr
->next
== &consoles
) {
993 con
= list_entry(ptr
, struct console
, entry
);
998 mask_signal(SIGCHLD
, chld_handler
, &saved_sigchld
);
1000 con
= list_entry(ptr
, struct console
, entry
);
1001 if (con
->id
>= CONMAX
)
1004 switch ((con
->pid
= fork())) {
1006 mask_signal(SIGCHLD
, SIG_DFL
, NULL
);
1011 const char *passwd
= pwd
->pw_passwd
;
1013 int failed
= 0, doshell
= 0;
1014 int deny
= !opt_e
&& locked_account_password(pwd
->pw_passwd
);
1016 doprompt(passwd
, con
, deny
);
1018 if ((answer
= getpasswd(con
)) == NULL
)
1023 /* no password or locked account */
1024 if (!passwd
[0] || locked_account_password(passwd
))
1027 const char *cryptbuf
;
1028 cryptbuf
= crypt(answer
, passwd
);
1029 if (cryptbuf
== NULL
)
1030 warn(_("crypt failed"));
1031 else if (strcmp(cryptbuf
, pwd
->pw_passwd
) == 0)
1036 *usemask
|= (1<<con
->id
);
1038 *usemask
&= ~(1<<con
->id
);
1042 mask_signal(SIGQUIT
, SIG_IGN
, &saved_sigquit
);
1043 mask_signal(SIGTSTP
, SIG_IGN
, &saved_sigtstp
);
1044 mask_signal(SIGINT
, SIG_IGN
, &saved_sigint
);
1047 fprintf(stderr
, _("Can not execute su shell\n\n"));
1050 fprintf(stderr
, _("Login incorrect\n\n"));
1054 warnx(_("Timed out\n\n"));
1057 * User pressed Control-D.
1061 warn(_("fork failed"));
1069 } while (ptr
!= &consoles
);
1071 while ((pid
= wait(&status
))) {
1072 if (errno
== ECHILD
)
1076 list_for_each(ptr
, &consoles
) {
1077 con
= list_entry(ptr
, struct console
, entry
);
1078 if (con
->pid
== pid
) {
1079 *usemask
&= ~(1<<con
->id
);
1082 if (kill(con
->pid
, 0) < 0) {
1083 *usemask
&= ~(1<<con
->id
);
1086 if (*usemask
& (1<<con
->id
))
1088 kill(con
->pid
, SIGHUP
);
1090 kill(con
->pid
, SIGKILL
);
1094 mask_signal(SIGCHLD
, SIG_DFL
, NULL
);
1095 return EXIT_SUCCESS
;