2 * sulogin This program gives Linux machines a reasonable
3 * secure way to boot single user. It forces the
4 * user to supply the root password before a
7 * If there is a shadow password file and the
8 * encrypted root password is "x" the shadow
9 * password will be used.
11 * Version: @(#)sulogin 2.85-3 23-Apr-2003 miquels@cistron.nl
13 * Copyright (C) 1998-2003 Miquel van Smoorenburg.
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
32 #include <sys/types.h>
44 #include <sys/ttydefaults.h>
46 #include <sys/ioctl.h>
47 #if defined(__GLIBC__)
49 # define dovoid(f) if ((f)){}
52 # include <sys/statfs.h>
53 # include <sys/mount.h>
54 # include <linux/fs.h>
55 # include <linux/magic.h>
56 # include <linux/major.h>
58 # define TMPFS_MAGIC 0x01021994
70 # include <selinux/selinux.h>
71 # include <selinux/get_context_list.h>
80 #define F_PASSWD "/etc/passwd"
81 #define F_SHADOW "/etc/shadow"
82 #define BINSH "/bin/sh"
83 #define STATICSH "/bin/sash"
85 char *Version
= "@(#)sulogin 2.85-3 23-Apr-2003 miquels@cistron.nl";
89 static volatile uint32_t openfd
; /* Remember higher file descriptors */
90 static volatile uint32_t *usemask
;
92 static sighandler_t saved_sigint
= SIG_DFL
;
93 static sighandler_t saved_sigtstp
= SIG_DFL
;
94 static sighandler_t saved_sigquit
= SIG_DFL
;
95 static sighandler_t saved_sighup
= SIG_DFL
;
97 static volatile sig_atomic_t alarm_rised
;
98 static volatile sig_atomic_t sigchild
;
105 * Fix the tty modes and set reasonable defaults.
108 void tcinit(struct console
*con
)
111 struct termios
*tio
= &con
->tio
;
117 /* Get line attributes */
118 if (tcgetattr(fd
, tio
) < 0) {
119 con
->flags
|= CON_NOTTY
;
123 /* Handle serial lines here */
124 if (ioctl (fd
, TIOCMGET
, (char*)&serial
) == 0) {
125 speed_t ispeed
, ospeed
;
128 /* this is a modem line */
129 con
->flags
|= CON_SERIAL
;
131 /* Flush input and output queues on modem lines */
132 (void) tcflush(fd
, TCIOFLUSH
);
134 ispeed
= cfgetispeed(tio
);
135 ospeed
= cfgetospeed(tio
);
137 if (!ispeed
) ispeed
= TTYDEF_SPEED
;
138 if (!ospeed
) ospeed
= TTYDEF_SPEED
;
140 tio
->c_iflag
= tio
->c_lflag
= tio
->c_oflag
= 0;
141 tio
->c_cflag
= CREAD
| CS8
| HUPCL
| (tio
->c_cflag
& CLOCAL
);
143 cfsetispeed(tio
, ispeed
);
144 cfsetospeed(tio
, ospeed
);
147 tio
->c_cc
[VTIME
] = 0;
150 if (ioctl(fd
, TIOCGWINSZ
, &ws
) == 0) {
152 if (ws
.ws_row
== 0) {
156 if (ws
.ws_col
== 0) {
160 (void)ioctl(fd
, TIOCSWINSZ
, &ws
);
165 #if defined(SANE_TIO) && (SANE_TIO == 1)
167 * Use defaults of <sys/ttydefaults.h> for base settings
168 * of a local terminal line like a virtual console.
170 tio
->c_iflag
|= TTYDEF_IFLAG
;
171 tio
->c_oflag
|= TTYDEF_OFLAG
;
172 tio
->c_lflag
|= TTYDEF_LFLAG
;
174 tio
->c_lflag
&= ~CBAUD
;
176 tio
->c_cflag
|= (B38400
| TTYDEF_CFLAG
);
178 /* Sane setting, allow eight bit characters, no carriage return delay
179 * the same result as `stty sane cr0 pass8'
181 tio
->c_iflag
|= (BRKINT
| ICRNL
| IMAXBEL
);
182 tio
->c_iflag
&= ~(IGNBRK
| INLCR
| IGNCR
| IXOFF
| IUCLC
| IXANY
| INPCK
| ISTRIP
);
183 tio
->c_oflag
|= (OPOST
| ONLCR
| NL0
| CR0
| TAB0
| BS0
| VT0
| FF0
);
184 tio
->c_oflag
&= ~(OLCUC
| OCRNL
| ONOCR
| ONLRET
| OFILL
| OFDEL
|\
185 NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
|FFDLY
);
186 tio
->c_lflag
|= (ISIG
| ICANON
| IEXTEN
| ECHO
|ECHOE
|ECHOK
|ECHOKE
);
187 tio
->c_lflag
&= ~(ECHONL
|ECHOCTL
|ECHOPRT
| NOFLSH
| XCASE
| TOSTOP
);
188 tio
->c_cflag
|= (CREAD
| CS8
| HUPCL
);
189 tio
->c_cflag
&= ~(PARODD
| PARENB
);
192 * VTIME and VMIN can overlap with VEOF and VEOL since they are
193 * only used for non-canonical mode. We just set the at the
194 * beginning, so nothing bad should happen.
196 tio
->c_cc
[VTIME
] = 0;
197 tio
->c_cc
[VMIN
] = CMIN
;
198 tio
->c_cc
[VINTR
] = CINTR
;
199 tio
->c_cc
[VQUIT
] = CQUIT
;
200 tio
->c_cc
[VERASE
] = CERASE
; /* ASCII DEL (0177) */
201 tio
->c_cc
[VKILL
] = CKILL
;
202 tio
->c_cc
[VEOF
] = CEOF
;
204 tio
->c_cc
[VSWTC
] = _POSIX_VDISABLE
;
206 tio
->c_cc
[VSWTCH
] = _POSIX_VDISABLE
;
208 tio
->c_cc
[VSTART
] = CSTART
;
209 tio
->c_cc
[VSTOP
] = CSTOP
;
210 tio
->c_cc
[VSUSP
] = CSUSP
;
211 tio
->c_cc
[VEOL
] = _POSIX_VDISABLE
;
212 tio
->c_cc
[VREPRINT
] = CREPRINT
;
213 tio
->c_cc
[VDISCARD
] = CDISCARD
;
214 tio
->c_cc
[VWERASE
] = CWERASE
;
215 tio
->c_cc
[VLNEXT
] = CLNEXT
;
216 tio
->c_cc
[VEOL2
] = _POSIX_VDISABLE
;
219 /* Set line attributes */
220 tcsetattr(fd
, TCSANOW
, tio
);
222 /* Enable blocking mode for read and write */
223 if ((flags
= fcntl(fd
, F_GETFL
, 0)) != -1)
224 (void)fcntl(fd
, F_SETFL
, flags
& ~O_NONBLOCK
);
229 * Finalize the tty modes on modem lines.
232 void tcfinal(struct console
*con
)
235 struct termios
*tio
= &con
->tio
;
241 if ((con
->flags
& CON_SERIAL
) == 0) {
243 setenv("TERM", "linux", 1);
245 setenv("TERM", "vt100", 1);
249 if (con
->flags
& CON_NOTTY
)
251 setenv("TERM", "vt100", 1);
253 tio
->c_iflag
|= (IXON
| IXOFF
);
254 tio
->c_lflag
|= (ICANON
| ISIG
| ECHO
|ECHOE
|ECHOK
|ECHOKE
);
255 tio
->c_oflag
|= OPOST
;
257 tio
->c_cc
[VINTR
] = CINTR
;
258 tio
->c_cc
[VQUIT
] = CQUIT
;
259 tio
->c_cc
[VERASE
] = con
->cp
.erase
;
260 tio
->c_cc
[VKILL
] = con
->cp
.kill
;
261 tio
->c_cc
[VEOF
] = CEOF
;
263 tio
->c_cc
[VSWTC
] = _POSIX_VDISABLE
;
265 tio
->c_cc
[VSWTCH
] = _POSIX_VDISABLE
;
267 tio
->c_cc
[VSTART
] = CSTART
;
268 tio
->c_cc
[VSTOP
] = CSTOP
;
269 tio
->c_cc
[VSUSP
] = CSUSP
;
270 tio
->c_cc
[VEOL
] = _POSIX_VDISABLE
;
272 if (con
->cp
.eol
== CR
) {
273 tio
->c_iflag
|= ICRNL
;
274 tio
->c_iflag
&= ~(INLCR
|IGNCR
);
275 tio
->c_oflag
|= ONLCR
;
276 tio
->c_oflag
&= ~(OCRNL
|ONLRET
);
279 switch (con
->cp
.parity
) {
282 tio
->c_cflag
&= ~(PARODD
| PARENB
);
283 tio
->c_iflag
&= ~(INPCK
| ISTRIP
);
285 case 1: /* odd parity */
286 tio
->c_cflag
|= PARODD
;
288 case 2: /* even parity */
289 tio
->c_cflag
|= PARENB
;
290 tio
->c_iflag
|= (INPCK
| ISTRIP
);
292 case (1 | 2): /* no parity bit */
293 tio
->c_cflag
&= ~CSIZE
;
298 /* Set line attributes */
299 (void)tcsetattr(fd
, TCSANOW
, tio
);
307 __attribute__((__noinline__
))
308 void alrm_handler(int sig
__attribute__((unused
)))
310 void alrm_handler(int sig
)
321 __attribute__((__noinline__
))
322 void chld_handler(int sig
__attribute__((unused
)))
324 void chld_handler(int sig
)
331 * See if an encrypted password is valid. The encrypted
332 * password is checked for traditional-style DES and
333 * FreeBSD-style MD5 encryption.
336 int valid(const char *pass
)
343 if (pass
[0] == 0) return 1;
345 if (pass
[0] != '$') goto check_des
;
348 * up to 4 bytes for the signature e.g. $1$
350 for(s
= pass
+1; *s
&& *s
!= '$'; s
++)
352 if (*s
++ != '$') return 0;
353 if ((off
= (off_t
)(s
-pass
)) > 4 || off
< 3) return 0;
355 memset(id
, '\0', sizeof(id
));
356 strncpy(id
, pass
, off
);
359 * up to 16 bytes for the salt
361 for(; *s
&& *s
!= '$'; s
++)
363 if (*s
++ != '$') return 0;
364 if ((off_t
)(s
-pass
) > 16) return 0;
368 * the MD5 hash (128 bits or 16 bytes) encoded in base64 = 22 bytes
370 if ((strcmp(id
, "$1$") == 0) && (len
< 22 || len
> 24)) return 0;
373 * the SHA-256 hash 43 bytes
375 if ((strcmp(id
, "$5$") == 0) && (len
< 42 || len
> 44)) return 0;
378 * the SHA-512 hash 86 bytes
380 if ((strcmp(id
, "$6$") == 0) && (len
< 85 || len
> 87)) return 0;
389 if (strlen(pass
) != 13) return 0;
390 for (s
= pass
; *s
; s
++) {
391 if ((*s
< '0' || *s
> '9') &&
392 (*s
< 'a' || *s
> 'z') &&
393 (*s
< 'A' || *s
> 'Z') &&
394 *s
!= '.' && *s
!= '/') return 0;
401 * Set a variable if the value is not NULL.
404 void set(char **var
, char *val
)
410 * Get the root password entry.
413 struct passwd
*getrootpwent(int try_manually
)
415 static struct passwd pwd
;
419 static char line
[256];
420 static char sline
[256];
424 * First, we try to get the password the standard
425 * way using normal library calls.
427 if ((pw
= getpwnam("root")) &&
428 !strcmp(pw
->pw_passwd
, "x") &&
429 (spw
= getspnam("root")))
430 pw
->pw_passwd
= spw
->sp_pwdp
;
431 if (pw
|| !try_manually
) return pw
;
434 * If we come here, we could not retrieve the root
435 * password through library calls and we try to
436 * read the password and shadow files manually.
438 pwd
.pw_name
= "root";
440 pwd
.pw_gecos
= "Super User";
446 if ((fp
= fopen(F_PASSWD
, "r")) == NULL
) {
452 * Find root in the password file.
454 while((p
= fgets(line
, 256, fp
)) != NULL
) {
455 if (strncmp(line
, "root:", 5) != 0)
458 set(&pwd
.pw_passwd
, strsep(&p
, ":"));
459 (void)strsep(&p
, ":");
460 (void)strsep(&p
, ":");
461 set(&pwd
.pw_gecos
, strsep(&p
, ":"));
462 set(&pwd
.pw_dir
, strsep(&p
, ":"));
463 set(&pwd
.pw_shell
, strsep(&p
, "\n"));
470 * If the encrypted password is valid
471 * or not found, return.
474 fprintf(stderr
, "sulogin: %s: no entry for root\n\r", F_PASSWD
);
477 if (valid(pwd
.pw_passwd
)) return &pwd
;
480 * The password is invalid. If there is a
481 * shadow password, try it.
483 strcpy(pwd
.pw_passwd
, "");
484 if ((fp
= fopen(F_SHADOW
, "r")) == NULL
) {
485 fprintf(stderr
, "sulogin: %s: root password garbled\n\r", F_PASSWD
);
488 while((p
= fgets(sline
, 256, fp
)) != NULL
) {
489 if (strncmp(sline
, "root:", 5) != 0)
492 set(&pwd
.pw_passwd
, strsep(&p
, ":"));
498 * If the password is still invalid,
499 * NULL it, and return.
502 fprintf(stderr
, "sulogin: %s: no entry for root\n\r", F_SHADOW
);
503 strcpy(pwd
.pw_passwd
, "");
505 if (!valid(pwd
.pw_passwd
)) {
506 fprintf(stderr
, "sulogin: %s: root password garbled\n\r", F_SHADOW
);
507 strcpy(pwd
.pw_passwd
, ""); }
512 * Ask by prompt for the password.
515 void doprompt(const char *crypted
, struct console
*con
)
519 if (con
->flags
& CON_SERIAL
) {
522 * For prompting: map NL in output to CR-NL
523 * otherwise we may see stairs in the output.
525 tty
.c_oflag
|= (ONLCR
| OPOST
);
526 (void) tcsetattr(con
->fd
, TCSADRAIN
, &tty
);
528 if (con
->file
== (FILE*)0) {
529 if ((con
->file
= fdopen(con
->fd
, "r+")) == (FILE*)0)
532 #if defined(USE_ONELINE)
534 fprintf(con
->file
, "Give root password for login: ");
536 fprintf(con
->file
, "Press enter for login: ");
539 fprintf(con
->file
, "Give root password for maintenance\n\r");
541 fprintf(con
->file
, "Press enter for maintenance");
542 fprintf(con
->file
, "(or type Control-D to continue): ");
546 if (con
->flags
& CON_SERIAL
)
547 (void) tcsetattr(con
->fd
, TCSADRAIN
, &con
->tio
);
551 * Make sure to have an own session and controlling terminal
554 void setup(struct console
*con
)
556 pid_t pid
, pgrp
, ppgrp
, ttypgrp
;
559 if (con
->flags
& CON_NOTTY
)
564 * Only go through this trouble if the new
565 * tty doesn't fall in this process group.
569 ppgrp
= getpgid(getppid());
570 ttypgrp
= tcgetpgrp(fd
);
572 if (pgrp
!= ttypgrp
&& ppgrp
!= ttypgrp
) {
573 if (pid
!= getsid(0)) {
574 if (pid
== getpgid(0))
575 setpgid(0, getpgid(getppid()));
579 signal(SIGHUP
, SIG_IGN
);
581 ioctl(0, TIOCNOTTY
, (char *)1);
582 signal(SIGHUP
, saved_sighup
);
583 if (fd
> 0) close(0);
584 if (fd
> 1) close(1);
585 if (fd
> 2) close(2);
587 ioctl(fd
, TIOCSCTTY
, (char *)1);
588 tcsetpgrp(fd
, ppgrp
);
595 for (fd
= 3; fd
< 32; fd
++) {
596 if (openfd
& (1<<fd
)) {
604 * Fetch the password. Note that there is no
605 * default timeout as we normally skip this during boot.
608 char *getpasswd(struct console
*con
)
610 static char pass
[128], *ptr
;
620 if (con
->flags
& CON_NOTTY
)
626 tty
.c_iflag
&= ~(IUCLC
|IXON
|IXOFF
|IXANY
);
627 tty
.c_lflag
&= ~(ECHO
|ECHOE
|ECHOK
|ECHONL
|TOSTOP
|ISIG
);
628 tc
= (tcsetattr(fd
, TCSAFLUSH
, &tty
) == 0);
630 sa
.sa_handler
= alrm_handler
;
632 sigaction(SIGALRM
, &sa
, NULL
);
633 if (timeout
) alarm(timeout
);
636 cp
->eol
= *ptr
= '\0';
638 eightbit
= ((con
->flags
& CON_SERIAL
) == 0 || (tty
.c_cflag
& (PARODD
|PARENB
)) == 0);
639 while (cp
->eol
== '\0') {
640 if (read(fd
, &c
, 1) < 1) {
641 if (errno
== EINTR
|| errno
== EAGAIN
) {
654 fprintf(stderr
, "sulogin: read(%s): %m\n\r", con
->tty
);
662 else if (c
!= (ascval
= (c
& 0177))) {
664 for (bits
= 1, mask
= 1; mask
& 0177; mask
<<= 1) {
668 cp
->parity
|= ((bits
& 1) ? 1 : 2);
688 while (ptr
> &pass
[0])
694 if ((size_t)(ptr
- &pass
[0]) >= (sizeof(pass
) -1 )) {
695 fprintf(stderr
, "sulogin: input overrun at %s\n\r", con
->tty
);
706 (void)tcsetattr(fd
, TCSAFLUSH
, &con
->tio
);
707 if (ret
&& *ret
!= '\0')
715 * Password was OK, execute a shell.
718 void sushell(struct passwd
*pwd
)
726 * Set directory and shell.
728 if (chdir(pwd
->pw_dir
) < 0) {
730 fprintf(stderr
, "sulogin: change of working directory failed: %m\n\r");
732 if ((p
= getenv("SUSHELL")) != NULL
)
734 else if ((p
= getenv("sushell")) != NULL
)
737 if (pwd
->pw_shell
[0])
738 sushell
= pwd
->pw_shell
;
742 if ((p
= strrchr(sushell
, '/')) == NULL
)
746 snprintf(shell
, sizeof(shell
), profile
? "-%s" : "%s", p
);
749 * Set some important environment variables.
751 if (getcwd(home
, sizeof(home
)) == (char*)0)
753 setenv("HOME", home
, 1);
754 setenv("LOGNAME", "root", 1);
755 setenv("USER", "root", 1);
757 setenv("SHLVL","0",1);
760 * Try to execute a shell.
762 setenv("SHELL", sushell
, 1);
763 signal(SIGINT
, saved_sigint
);
764 signal(SIGTSTP
, saved_sigtstp
);
765 signal(SIGQUIT
, saved_sigquit
);
766 signal(SIGHUP
, SIG_DFL
);
768 if (is_selinux_enabled() > 0) {
769 security_context_t scon
=NULL
;
772 if (getseuserbyname("root", &seuser
, &level
) == 0)
773 if (get_default_context_with_level(seuser
, level
, 0, &scon
) == 0) {
774 if (setexeccon(scon
) != 0)
775 fprintf(stderr
, "sulogin: setexeccon failed\n\r");
782 execl(sushell
, shell
, NULL
);
785 setenv("SHELL", BINSH
, 1);
786 execl(BINSH
, profile
? "-sh" : "sh", NULL
);
789 /* Fall back to staticly linked shell if both the users shell
790 and /bin/sh failed to execute. */
791 setenv("SHELL", STATICSH
, 1);
792 execl(STATICSH
, STATICSH
, NULL
);
798 * Make C library standard calls like ttyname(3) work.
800 static uint32_t mounts
;
801 #define MNT_PROCFS 0x0001
802 #define MNT_DEVTMPFS 0x0002
804 static __attribute__((__noinline__
))
807 if (mounts
& MNT_DEVTMPFS
)
808 umount2("/dev", MNT_DETACH
);
809 if (mounts
& MNT_PROCFS
)
810 umount2("/proc", MNT_DETACH
);
813 static __attribute__((__constructor__
))
817 if (statfs("/proc", &st
) == 0 && st
.f_type
!= PROC_SUPER_MAGIC
) {
818 if (mount("proc", "/proc", "proc", MS_RELATIME
, NULL
) == 0)
819 mounts
|= MNT_PROCFS
;
821 if (statfs("/dev", &st
) == 0 && st
.f_type
!= TMPFS_MAGIC
) {
822 if (mount("devtmpfs", "/dev", "devtmpfs", MS_RELATIME
, "mode=0755,nr_inodes=0") == 0) {
823 mounts
|= MNT_DEVTMPFS
;
824 (void)mknod("/dev/console", S_IFCHR
|S_IRUSR
|S_IWUSR
, makedev(TTYAUX_MAJOR
, 1));
825 if (symlink("/proc/self/fd", "/dev/fd") == 0) {
826 dovoid(symlink("fd/0", "/dev/stdin"));
827 dovoid(symlink("fd/1", "/dev/stdout"));
828 dovoid(symlink("fd/2", "/dev/stderr"));
832 if (mounts
) atexit(putmounts
);
839 fprintf(stderr
, "Usage: sulogin [-e] [-p] [-t timeout] [tty device]\n\r");
842 int main(int argc
, char **argv
)
853 * We are init. We hence need to set uo a session.
855 if ((pid
= getpid()) == 1) {
857 (void)ioctl(0, TIOCSCTTY
, (char *)1);
861 * See if we have a timeout flag.
864 while((c
= getopt(argc
, argv
, "ept:")) != EOF
) switch(c
) {
866 timeout
= atoi(optarg
);
880 if (geteuid() != 0) {
881 fprintf(stderr
, "sulogin: only root can run sulogin.\n\r");
885 saved_sigint
= signal(SIGINT
, SIG_IGN
);
886 saved_sigquit
= signal(SIGQUIT
, SIG_IGN
);
887 saved_sigtstp
= signal(SIGTSTP
, SIG_IGN
);
888 saved_sighup
= signal(SIGHUP
, SIG_IGN
);
891 * See if we need to open an other tty device.
895 if (!tty
|| *tty
== '\0')
896 tty
= getenv("CONSOLE");
899 * Detect possible consoles, use stdin as fallback.
900 * If an optional tty is given, reconnect it to stdin.
902 reconnect
= detect_consoles(tty
, 0);
910 fprintf(stderr
, "sulogin: cannot open console: %m\n\r");
915 * If previous stdin was not the speified tty and therefore reconnected
916 * to the specified tty also reconnect stdout and stderr.
926 * Get the root password.
928 if ((pwd
= getrootpwent(opt_e
)) == NULL
) {
929 fprintf(stderr
, "sulogin: cannot open password database!\n\r");
934 * Prompt for input on the consoles
936 for (con
= consoles
; con
&& con
->id
< CONMAX
; con
= con
->next
) {
938 openfd
|= (1<<con
->fd
);
942 if ((con
->fd
= open(con
->tty
, O_RDWR
| O_NOCTTY
| O_NONBLOCK
)) < 0)
944 openfd
|= (1<<con
->fd
);
948 usemask
= (uint32_t*)mmap(NULL
, sizeof(uint32_t), PROT_READ
|PROT_WRITE
, MAP_ANONYMOUS
|MAP_SHARED
, -1, 0);
950 if (con
->next
== (struct console
*)0)
953 signal(SIGCHLD
, chld_handler
);
955 switch ((con
->pid
= fork())) {
957 signal(SIGCHLD
, SIG_DFL
);
962 char *passwd
= pwd
->pw_passwd
;
966 doprompt(passwd
, con
);
967 if ((answer
= getpasswd(con
)) == NULL
)
970 if (passwd
[0] == '\0' ||
971 strcmp(crypt(answer
, passwd
), passwd
) == 0) {
972 *usemask
|= (1<<con
->id
);
974 *usemask
&= ~(1<<con
->id
);
977 signal(SIGQUIT
, SIG_IGN
);
978 signal(SIGTSTP
, SIG_IGN
);
979 signal(SIGINT
, SIG_IGN
);
982 fprintf(stderr
, "sulogin: can not execute su shell.\n\r");
985 fprintf(stderr
, "Login incorrect.\n\r");
990 printf("Timed out.\n\r");
993 * User may pressed Control-D.
997 fprintf(stderr
, "sulogin: can not fork: %m\n\r");
1002 } while ((con
= con
->next
) && (con
->id
< CONMAX
));
1004 while ((pid
= wait(&status
))) {
1005 if (errno
== ECHILD
)
1009 for (con
= consoles
; con
&& con
->id
< CONMAX
; con
= con
->next
) {
1010 if (con
->pid
== pid
) {
1011 *usemask
&= ~(1<<con
->id
);
1014 if (kill(con
->pid
, 0) < 0) {
1015 *usemask
&= ~(1<<con
->id
);
1018 if (*usemask
& (1<<con
->id
))
1020 kill(con
->pid
, SIGHUP
);
1022 kill(con
->pid
, SIGKILL
);
1025 signal(SIGCHLD
, SIG_DFL
);