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"
61 #include "pathnames.h"
62 #ifdef USE_PLYMOUTH_SUPPORT
63 # include "plymouth-ctrl.h"
67 #include "sulogin-consoles.h"
70 static unsigned int timeout
;
72 static volatile uint32_t openfd
; /* Remember higher file descriptors */
74 static struct sigaction saved_sigint
;
75 static struct sigaction saved_sigtstp
;
76 static struct sigaction saved_sigquit
;
77 static struct sigaction saved_sighup
;
78 static struct sigaction saved_sigchld
;
80 static volatile sig_atomic_t alarm_rised
;
81 static volatile sig_atomic_t sigchild
;
88 # warning "WEXITED is missing, sulogin may not work as expected"
92 static int locked_account_password(const char *passwd
)
94 if (passwd
&& (*passwd
== '*' || *passwd
== '!'))
100 * Fix the tty modes and set reasonable defaults.
102 static void tcinit(struct console
*con
)
104 int mode
= 0, flags
= 0;
105 struct termios
*tio
= &con
->tio
;
107 #ifdef USE_PLYMOUTH_SUPPORT
109 int i
= (plymouth_command(MAGIC_PING
)) ? PLYMOUTH_TERMIOS_FLAGS_DELAY
: 0;
111 plymouth_command(MAGIC_QUIT
);
114 * With plymouth the termios flags become changed after this
115 * function had changed the termios.
117 memset(&lock
, 0, sizeof(struct termios
));
118 if (ioctl(fd
, TIOCGLCKTRMIOS
, &lock
) < 0)
120 if (!lock
.c_iflag
&& !lock
.c_oflag
&& !lock
.c_cflag
&& !lock
.c_lflag
)
124 memset(&lock
, 0, sizeof(struct termios
));
125 ioctl(fd
, TIOCSLCKTRMIOS
, &lock
);
129 if (tcgetattr(fd
, tio
) < 0) {
130 warn(_("tcgetattr failed"));
131 con
->flags
|= CON_NOTTY
;
135 /* Handle lines other than virtual consoles here */
136 #if defined(KDGKBMODE)
137 if (ioctl(fd
, KDGKBMODE
, &mode
) < 0)
140 speed_t ispeed
, ospeed
;
144 /* this is a modem line */
145 con
->flags
|= CON_SERIAL
;
147 /* Flush input and output queues on modem lines */
148 tcflush(fd
, TCIOFLUSH
);
150 ispeed
= cfgetispeed(tio
);
151 ospeed
= cfgetospeed(tio
);
153 if (!ispeed
) ispeed
= TTYDEF_SPEED
;
154 if (!ospeed
) ospeed
= TTYDEF_SPEED
;
156 tio
->c_cflag
= CREAD
| CS8
| HUPCL
| (tio
->c_cflag
& CLOCAL
);
159 tio
->c_oflag
&= OPOST
| ONLCR
;
161 cfsetispeed(tio
, ispeed
);
162 cfsetospeed(tio
, ospeed
);
164 #ifdef HAVE_STRUCT_TERMIOS_C_LINE
167 tio
->c_cc
[VTIME
] = 0;
170 if (ioctl(fd
, TIOCGWINSZ
, &ws
) == 0) {
172 if (ws
.ws_row
== 0) {
176 if (ws
.ws_col
== 0) {
181 ignore_result( ioctl(fd
, TIOCSWINSZ
, &ws
) );
184 setlocale(LC_CTYPE
, "POSIX");
187 #if defined(IUTF8) && defined(KDGKBMODE)
188 /* Handle mode of current keyboard setup, e.g. for UTF-8 */
191 setlocale(LC_CTYPE
, "C.UTF-8");
192 flags
|= UL_TTY_UTF8
;
198 setlocale(LC_CTYPE
, "POSIX");
202 setlocale(LC_CTYPE
, "POSIX");
204 reset_virtual_console(tio
, flags
);
206 if (tcsetattr(fd
, TCSANOW
, tio
))
207 warn(_("tcsetattr failed"));
209 /* Enable blocking mode for read and write */
210 if ((flags
= fcntl(fd
, F_GETFL
, 0)) != -1)
211 ignore_result( fcntl(fd
, F_SETFL
, flags
& ~O_NONBLOCK
) );
215 * Finalize the tty modes on modem lines.
217 static void tcfinal(struct console
*con
)
222 if ((con
->flags
& CON_SERIAL
) == 0) {
223 xsetenv("TERM", "linux", 1);
226 if (con
->flags
& CON_NOTTY
) {
227 xsetenv("TERM", "dumb", 1);
231 #if defined (__s390__) || defined (__s390x__)
232 xsetenv("TERM", "dumb", 1);
234 xsetenv("TERM", "vt102", 1);
239 tio
->c_iflag
|= (IXON
| IXOFF
);
240 tio
->c_lflag
|= (ICANON
| ISIG
| ECHO
|ECHOE
|ECHOK
|ECHOKE
);
241 tio
->c_oflag
|= OPOST
;
243 tio
->c_cc
[VINTR
] = CINTR
;
244 tio
->c_cc
[VQUIT
] = CQUIT
;
245 tio
->c_cc
[VERASE
] = con
->cp
.erase
;
246 tio
->c_cc
[VKILL
] = con
->cp
.kill
;
247 tio
->c_cc
[VEOF
] = CEOF
;
249 tio
->c_cc
[VSWTC
] = _POSIX_VDISABLE
;
250 #elif defined(VSWTCH)
251 tio
->c_cc
[VSWTCH
] = _POSIX_VDISABLE
;
253 tio
->c_cc
[VSTART
] = CSTART
;
254 tio
->c_cc
[VSTOP
] = CSTOP
;
255 tio
->c_cc
[VSUSP
] = CSUSP
;
256 tio
->c_cc
[VEOL
] = _POSIX_VDISABLE
;
258 if (con
->cp
.eol
== CR
) {
259 tio
->c_iflag
|= ICRNL
;
260 tio
->c_iflag
&= ~(INLCR
|IGNCR
);
261 tio
->c_oflag
|= ONLCR
;
262 tio
->c_oflag
&= ~(OCRNL
|ONLRET
);
265 switch (con
->cp
.parity
) {
268 tio
->c_cflag
&= ~(PARODD
| PARENB
);
269 tio
->c_iflag
&= ~(INPCK
| ISTRIP
);
271 case 1: /* odd parity */
272 tio
->c_cflag
|= PARODD
;
274 case 2: /* even parity */
275 tio
->c_cflag
|= PARENB
;
276 tio
->c_iflag
|= (INPCK
| ISTRIP
);
278 case (1 | 2): /* no parity bit */
279 tio
->c_cflag
&= ~CSIZE
;
284 /* Set line attributes */
285 tcsetattr(fd
, TCSANOW
, tio
);
291 static void alrm_handler(int sig
__attribute__((unused
)))
293 /* Timeout expired */
297 static void chld_handler(int sig
__attribute__((unused
)))
302 static void mask_signal(int signal
, void (*handler
)(int),
303 struct sigaction
*origaction
)
305 struct sigaction newaction
;
307 newaction
.sa_handler
= handler
;
308 sigemptyset(&newaction
.sa_mask
);
309 newaction
.sa_flags
= 0;
311 sigaction(signal
, &newaction
, origaction
);
314 static void unmask_signal(int signal
, struct sigaction
*sa
)
316 sigaction(signal
, sa
, NULL
);
320 * See if an encrypted password is valid. The encrypted password is checked for
321 * traditional-style DES and FreeBSD-style MD5 encryption.
323 static int valid(const char *pass
)
336 * up to 4 bytes for the signature e.g. $1$
338 for (s
= pass
+1; *s
&& *s
!= '$'; s
++);
343 if ((off
= (off_t
)(s
-pass
)) > 4 || off
< 3)
346 memset(id
, '\0', sizeof(id
));
347 strncpy(id
, pass
, off
);
350 * up to 16 bytes for the salt
352 for (; *s
&& *s
!= '$'; s
++);
357 if ((off_t
)(s
-pass
) > 16)
363 * the MD5 hash (128 bits or 16 bytes) encoded in base64 = 22 bytes
365 if ((strcmp(id
, "$1$") == 0) && (len
< 22 || len
> 24))
369 * the SHA-256 hash 43 bytes
371 if ((strcmp(id
, "$5$") == 0) && (len
< 42 || len
> 44))
375 * the SHA-512 hash 86 bytes
377 if ((strcmp(id
, "$6$") == 0) && (len
< 85 || len
> 87))
385 if (strlen(pass
) != 13)
388 for (s
= pass
; *s
; s
++) {
389 if ((*s
< '0' || *s
> '9') &&
390 (*s
< 'a' || *s
> 'z') &&
391 (*s
< 'A' || *s
> 'Z') &&
392 *s
!= '.' && *s
!= '/')
399 * Set a variable if the value is not NULL.
401 static inline void set(char **var
, char *val
)
408 * Get the root password entry.
410 static struct passwd
*getrootpwent(int try_manually
)
412 static struct passwd pwd
;
416 static char line
[2 * BUFSIZ
];
417 static char sline
[2 * BUFSIZ
];
421 * First, we try to get the password the standard way using normal
424 if ((pw
= getpwnam("root")) &&
425 !strcmp(pw
->pw_passwd
, "x") &&
426 (spw
= getspnam("root")))
427 pw
->pw_passwd
= spw
->sp_pwdp
;
429 if (pw
|| !try_manually
)
433 * If we come here, we could not retrieve the root password through
434 * library calls and we try to read the password and shadow files
437 pwd
.pw_name
= "root";
439 pwd
.pw_gecos
= "Super User";
445 if ((fp
= fopen(_PATH_PASSWD
, "r")) == NULL
) {
446 warn(_("cannot open %s"), _PATH_PASSWD
);
451 * Find root in the password file.
453 while ((p
= fgets(line
, sizeof(line
), fp
)) != NULL
) {
454 if (strncmp(line
, "root:", 5) != 0)
457 set(&pwd
.pw_passwd
, strsep(&p
, ":"));
460 set(&pwd
.pw_gecos
, strsep(&p
, ":"));
461 set(&pwd
.pw_dir
, strsep(&p
, ":"));
462 set(&pwd
.pw_shell
, strsep(&p
, "\n"));
469 * If the encrypted password is valid or not found, return.
472 warnx(_("%s: no entry for root\n"), _PATH_PASSWD
);
475 if (valid(pwd
.pw_passwd
))
479 * The password is invalid. If there is a shadow password, try it.
481 *pwd
.pw_passwd
= '\0';
482 if ((fp
= fopen(_PATH_SHADOW_PASSWD
, "r")) == NULL
) {
483 warn(_("cannot open %s"), _PATH_PASSWD
);
486 while ((p
= fgets(sline
, sizeof(sline
), fp
)) != NULL
) {
487 if (strncmp(sline
, "root:", 5) != 0)
490 set(&pwd
.pw_passwd
, strsep(&p
, ":"));
496 * If the password is still invalid, NULL it, and return.
499 warnx(_("%s: no entry for root"), _PATH_SHADOW_PASSWD
);
500 *pwd
.pw_passwd
= '\0';
502 /* locked account passwords are valid too */
503 if (!locked_account_password(pwd
.pw_passwd
) && !valid(pwd
.pw_passwd
)) {
504 warnx(_("%s: root password garbled"), _PATH_SHADOW_PASSWD
);
505 *pwd
.pw_passwd
= '\0';
511 * Ask by prompt for the password.
513 static void doprompt(const char *crypted
, struct console
*con
, int deny
)
517 if (con
->flags
& CON_SERIAL
) {
520 * For prompting: map NL in output to CR-NL
521 * otherwise we may see stairs in the output.
523 tty
.c_oflag
|= (ONLCR
| OPOST
);
524 tcsetattr(con
->fd
, TCSADRAIN
, &tty
);
526 if (con
->file
== (FILE*)0) {
527 if ((con
->file
= fdopen(con
->fd
, "r+")) == (FILE*)0)
532 fprintf(con
->file
, _("\nCannot open access to console, the root account is locked.\n"
533 "See sulogin(8) man page for more details.\n\n"
534 "Press Enter to continue.\n"));
536 #if defined(USE_ONELINE)
537 if (crypted
[0] && !locked_account_password(crypted
))
538 fprintf(con
->file
, _("Give root password for login: "));
540 fprintf(con
->file
, _("Press Enter for login: "));
542 if (crypted
[0] && !locked_account_password(crypted
))
543 fprintf(con
->file
, _("Give root password for maintenance\n"));
545 fprintf(con
->file
, _("Press Enter for maintenance\n"));
546 fprintf(con
->file
, _("(or press Control-D to continue): "));
551 if (con
->flags
& CON_SERIAL
)
552 tcsetattr(con
->fd
, TCSADRAIN
, &con
->tio
);
556 * Make sure to have an own session and controlling terminal
558 static void setup(struct console
*con
)
560 pid_t pid
, pgrp
, ppgrp
, ttypgrp
;
563 if (con
->flags
& CON_NOTTY
)
568 * Only go through this trouble if the new
569 * tty doesn't fall in this process group.
573 ppgrp
= getpgid(getppid());
574 ttypgrp
= tcgetpgrp(fd
);
576 if (pgrp
!= ttypgrp
&& ppgrp
!= ttypgrp
) {
577 if (pid
!= getsid(0)) {
578 if (pid
== getpgid(0))
579 setpgid(0, getpgid(getppid()));
583 mask_signal(SIGHUP
, SIG_IGN
, &saved_sighup
);
585 ioctl(STDIN_FILENO
, TIOCNOTTY
, (char *)1);
586 unmask_signal(SIGHUP
, &saved_sighup
);
587 if (fd
> STDIN_FILENO
) close(STDIN_FILENO
);
588 if (fd
> STDOUT_FILENO
) close(STDOUT_FILENO
);
589 if (fd
> STDERR_FILENO
) close(STDERR_FILENO
);
591 ioctl(fd
, TIOCSCTTY
, (char *)1);
592 tcsetpgrp(fd
, ppgrp
);
594 dup2(fd
, STDIN_FILENO
);
595 dup2(fd
, STDOUT_FILENO
);
596 dup2(fd
, STDERR_FILENO
);
597 con
->fd
= STDIN_FILENO
;
599 for (fd
= STDERR_FILENO
+1; fd
< 32; fd
++) {
600 if (openfd
& (1<<fd
)) {
608 * Ask for the password. Note that there is no default timeout as we normally
609 * skip this during boot.
611 static char *getpasswd(struct console
*con
)
615 static char pass
[128], *ptr
;
623 if (con
->flags
& CON_NOTTY
)
629 tty
.c_iflag
&= ~(IUCLC
|IXON
|IXOFF
|IXANY
);
630 tty
.c_lflag
&= ~(ECHO
|ECHOE
|ECHOK
|ECHONL
|TOSTOP
|ISIG
);
631 tc
= (tcsetattr(fd
, TCSAFLUSH
, &tty
) == 0);
633 sigemptyset(&sa
.sa_mask
);
634 sa
.sa_handler
= alrm_handler
;
636 sigaction(SIGALRM
, &sa
, NULL
);
642 cp
->eol
= *ptr
= '\0';
644 eightbit
= ((con
->flags
& CON_SERIAL
) == 0 || (tty
.c_cflag
& (PARODD
|PARENB
)) == 0);
645 while (cp
->eol
== '\0') {
646 if (read(fd
, &c
, 1) < 1) {
647 if (errno
== EINTR
|| errno
== EAGAIN
) {
664 warn(_("cannot read %s"), con
->tty
);
672 else if (c
!= (ascval
= (c
& 0177))) {
674 for (bits
= 1, mask
= 1; mask
& 0177; mask
<<= 1) {
678 cp
->parity
|= ((bits
& 1) ? 1 : 2);
698 while (ptr
> &pass
[0])
705 if ((size_t)(ptr
- &pass
[0]) >= (sizeof(pass
) -1 )) {
706 fprintf(stderr
, "sulogin: input overrun at %s\n\r", con
->tty
);
717 tcsetattr(fd
, TCSAFLUSH
, &con
->tio
);
725 * Password was OK, execute a shell.
727 static void sushell(struct passwd
*pwd
)
729 char shell
[PATH_MAX
];
735 * Set directory and shell.
737 if (chdir(pwd
->pw_dir
) != 0) {
738 warn(_("%s: change directory failed"), pwd
->pw_dir
);
739 printf(_("Logging in with home = \"/\".\n"));
742 warn(_("change directory to system root failed"));
745 if ((p
= getenv("SUSHELL")) != NULL
)
747 else if ((p
= getenv("sushell")) != NULL
)
750 if (pwd
->pw_shell
[0])
751 su_shell
= pwd
->pw_shell
;
753 su_shell
= "/bin/sh";
755 if ((p
= strrchr(su_shell
, '/')) == NULL
)
760 snprintf(shell
, sizeof(shell
), profile
? "-%s" : "%s", p
);
763 * Set some important environment variables.
765 if (getcwd(home
, sizeof(home
)) == NULL
)
768 xsetenv("HOME", home
, 1);
769 xsetenv("LOGNAME", "root", 1);
770 xsetenv("USER", "root", 1);
772 xsetenv("SHLVL","0",1);
775 * Try to execute a shell.
777 xsetenv("SHELL", su_shell
, 1);
778 unmask_signal(SIGINT
, &saved_sigint
);
779 unmask_signal(SIGTSTP
, &saved_sigtstp
);
780 unmask_signal(SIGQUIT
, &saved_sigquit
);
781 mask_signal(SIGHUP
, SIG_DFL
, NULL
);
783 #ifdef HAVE_LIBSELINUX
784 if (is_selinux_enabled() > 0) {
785 security_context_t scon
=NULL
;
788 if (getseuserbyname("root", &seuser
, &level
) == 0) {
789 if (get_default_context_with_level(seuser
, level
, 0, &scon
) == 0) {
790 if (setexeccon(scon
) != 0)
791 warnx(_("setexeccon failed"));
799 execl(su_shell
, shell
, NULL
);
800 warn(_("failed to execute %s"), su_shell
);
802 xsetenv("SHELL", "/bin/sh", 1);
803 execl("/bin/sh", profile
? "-sh" : "sh", NULL
);
804 warn(_("failed to execute %s"), "/bin/sh");
807 static void usage(FILE *out
)
809 fputs(USAGE_HEADER
, out
);
811 " %s [options] [tty device]\n"), program_invocation_short_name
);
813 fputs(USAGE_SEPARATOR
, out
);
814 fputs(_("Single-user login.\n"), out
);
816 fputs(USAGE_OPTIONS
, out
);
817 fputs(_(" -p, --login-shell start a login shell\n"
818 " -t, --timeout <seconds> max time to wait for a password (default: no limit)\n"
819 " -e, --force examine password files directly if getpwnam(3) fails\n"),
822 fputs(USAGE_SEPARATOR
, out
);
823 fputs(USAGE_HELP
, out
);
824 fputs(USAGE_VERSION
, out
);
825 fprintf(out
, USAGE_MAN_TAIL("sulogin(8)"));
828 int main(int argc
, char **argv
)
830 struct list_head
*ptr
, consoles
;
834 struct timespec sigwait
= { .tv_sec
= 0, .tv_nsec
= 50000000 };
835 siginfo_t status
= {};
837 int c
, reconnect
= 0;
842 static const struct option longopts
[] = {
843 { "login-shell", no_argument
, NULL
, 'p' },
844 { "timeout", required_argument
, NULL
, 't' },
845 { "force", no_argument
, NULL
, 'e' },
846 { "help", no_argument
, NULL
, 'h' },
847 { "version", no_argument
, NULL
, 'V' },
851 INIT_LIST_HEAD(&consoles
);
854 * If we are init we need to set up a own session.
856 if ((pid
= getpid()) == 1) {
858 ignore_result( ioctl(STDIN_FILENO
, TIOCSCTTY
, (char *) 1) );
861 setlocale(LC_ALL
, "");
862 bindtextdomain(PACKAGE
, LOCALEDIR
);
864 atexit(close_stdout
); /* XXX */
867 * See if we have a timeout flag.
869 while ((c
= getopt_long(argc
, argv
, "ehpt:V", longopts
, NULL
)) != -1) {
872 timeout
= strtou32_or_err(optarg
, _("invalid timeout argument"));
881 printf(UTIL_LINUX_VERSION
);
894 errx(EXIT_FAILURE
, _("only superuser can run this program"));
896 mask_signal(SIGQUIT
, SIG_IGN
, &saved_sigquit
);
897 mask_signal(SIGTSTP
, SIG_IGN
, &saved_sigtstp
);
898 mask_signal(SIGINT
, SIG_IGN
, &saved_sigint
);
899 mask_signal(SIGHUP
, SIG_IGN
, &saved_sighup
);
902 emergency_do_mounts();
903 atexit( emergency_do_umounts
);
906 * See if we need to open an other tty device.
911 if (!tty
|| *tty
== '\0')
912 tty
= getenv("CONSOLE");
915 * Detect possible consoles, use stdin as fallback.
916 * If an optional tty is given, reconnect it to stdin.
918 reconnect
= detect_consoles(tty
, STDIN_FILENO
, &consoles
);
921 * If previous stdin was not the specified tty and therefore reconnected
922 * to the specified tty also reconnect stdout and stderr.
925 if (isatty(STDOUT_FILENO
) == 0)
926 dup2(STDOUT_FILENO
, STDIN_FILENO
);
927 if (isatty(STDERR_FILENO
) == 0)
928 dup2(STDOUT_FILENO
, STDERR_FILENO
);
934 if (list_empty(&consoles
)) {
937 err(EXIT_FAILURE
, _("cannot open console"));
941 * Get the root password.
943 if ((pwd
= getrootpwent(opt_e
)) == NULL
) {
944 warnx(_("cannot open password database"));
950 * Ask for the password on the consoles.
952 list_for_each(ptr
, &consoles
) {
953 con
= list_entry(ptr
, struct console
, entry
);
954 if (con
->id
>= CONMAX
)
957 openfd
|= (1 << con
->fd
);
961 if ((con
->fd
= open(con
->tty
, O_RDWR
| O_NOCTTY
| O_NONBLOCK
)) < 0)
963 openfd
|= (1 << con
->fd
);
966 ptr
= (&consoles
)->next
;
968 if (ptr
->next
== &consoles
) {
969 con
= list_entry(ptr
, struct console
, entry
);
974 mask_signal(SIGCHLD
, chld_handler
, &saved_sigchld
);
976 con
= list_entry(ptr
, struct console
, entry
);
977 if (con
->id
>= CONMAX
)
980 switch ((con
->pid
= fork())) {
982 mask_signal(SIGCHLD
, SIG_DFL
, NULL
);
987 const char *passwd
= pwd
->pw_passwd
;
989 int failed
= 0, doshell
= 0;
990 int deny
= !opt_e
&& locked_account_password(pwd
->pw_passwd
);
992 doprompt(passwd
, con
, deny
);
994 if ((answer
= getpasswd(con
)) == NULL
)
999 /* no password or locked account */
1000 if (!passwd
[0] || locked_account_password(passwd
))
1003 const char *cryptbuf
;
1004 cryptbuf
= crypt(answer
, passwd
);
1005 if (cryptbuf
== NULL
)
1006 warn(_("crypt failed"));
1007 else if (strcmp(cryptbuf
, pwd
->pw_passwd
) == 0)
1016 mask_signal(SIGQUIT
, SIG_IGN
, &saved_sigquit
);
1017 mask_signal(SIGTSTP
, SIG_IGN
, &saved_sigtstp
);
1018 mask_signal(SIGINT
, SIG_IGN
, &saved_sigint
);
1021 fprintf(stderr
, _("cannot execute su shell\n\n"));
1024 fprintf(stderr
, _("Login incorrect\n\n"));
1028 warnx(_("Timed out\n\n"));
1031 * User pressed Control-D.
1035 warn(_("fork failed"));
1043 } while (ptr
!= &consoles
);
1049 ret
= waitid(P_ALL
, 0, &status
, WEXITED
);
1054 if (errno
== ECHILD
)
1060 errx(EXIT_FAILURE
, _("cannot wait on su shell\n\n"));
1064 list_for_each(ptr
, &consoles
) {
1065 con
= list_entry(ptr
, struct console
, entry
);
1071 if (con
->pid
== status
.si_pid
)
1074 kill(con
->pid
, SIGTERM
);
1080 sigaddset(&set
, SIGCHLD
);
1089 ret
= waitid(P_ALL
, 0, &status
, WEXITED
|WNOHANG
);
1092 if (errno
== ECHILD
)
1098 if (!ret
&& status
.si_pid
> 0) {
1099 list_for_each(ptr
, &consoles
) {
1100 con
= list_entry(ptr
, struct console
, entry
);
1106 if (con
->pid
== status
.si_pid
) {
1114 signum
= sigtimedwait(&set
, NULL
, &sigwait
);
1115 if (signum
!= SIGCHLD
&& signum
< 0 && errno
== EAGAIN
)
1120 mask_signal(SIGCHLD
, SIG_DFL
, NULL
);
1121 return EXIT_SUCCESS
;