]>
Commit | Line | Data |
---|---|---|
a74aeac6 PR |
1 | /* |
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 | |
5 | * shell is started. | |
6 | * | |
7 | * If there is a shadow password file and the | |
8 | * encrypted root password is "x" the shadow | |
9 | * password will be used. | |
10 | * | |
11 | * Version: @(#)sulogin 2.85-3 23-Apr-2003 miquels@cistron.nl | |
12 | * | |
13 | * Copyright (C) 1998-2003 Miquel van Smoorenburg. | |
14 | * | |
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. | |
19 | * | |
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. | |
24 | * | |
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 | |
28 | * | |
29 | */ | |
30 | ||
31 | #include <sys/types.h> | |
32 | #include <sys/stat.h> | |
33 | #include <stdio.h> | |
34 | #include <string.h> | |
35 | #include <stdlib.h> | |
36 | #include <unistd.h> | |
37 | #include <fcntl.h> | |
38 | #include <signal.h> | |
39 | #include <pwd.h> | |
40 | #include <shadow.h> | |
41 | #include <termios.h> | |
c5b4c135 | 42 | #include <sys/ttydefaults.h> |
a74aeac6 PR |
43 | #include <errno.h> |
44 | #include <sys/ioctl.h> | |
45 | #if defined(__GLIBC__) | |
46 | # include <crypt.h> | |
47 | #endif | |
48 | ||
49 | #ifdef WITH_SELINUX | |
50 | # include <selinux/selinux.h> | |
51 | # include <selinux/get_context_list.h> | |
52 | #endif | |
53 | ||
54 | #define CHECK_DES 1 | |
55 | #define CHECK_MD5 1 | |
56 | ||
57 | #define F_PASSWD "/etc/passwd" | |
58 | #define F_SHADOW "/etc/shadow" | |
59 | #define BINSH "/bin/sh" | |
60 | #define STATICSH "/bin/sash" | |
61 | ||
62 | char *Version = "@(#)sulogin 2.85-3 23-Apr-2003 miquels@cistron.nl"; | |
63 | ||
c5b4c135 DWF |
64 | static int timeout; |
65 | static int profile; | |
66 | ||
67 | static void (*saved_sigint) = SIG_DFL; | |
68 | static void (*saved_sigtstp) = SIG_DFL; | |
69 | static void (*saved_sigquit) = SIG_DFL; | |
a74aeac6 PR |
70 | |
71 | #ifndef IUCLC | |
72 | # define IUCLC 0 | |
73 | #endif | |
74 | ||
c5b4c135 | 75 | #if defined(SANE_TIO) && (SANE_TIO == 1) |
a74aeac6 PR |
76 | /* |
77 | * Fix the tty modes and set reasonable defaults. | |
78 | * (I'm not sure if this is needed under Linux, but..) | |
79 | */ | |
c5b4c135 | 80 | static |
a74aeac6 PR |
81 | void fixtty(void) |
82 | { | |
83 | struct termios tty; | |
c5b4c135 DWF |
84 | int serial; |
85 | ||
86 | /* Skip serial console */ | |
87 | if (ioctl (0, TIOCMGET, (char*)&serial) == 0) | |
88 | goto out; | |
89 | /* Expected error */ | |
90 | serial = errno = 0; | |
a74aeac6 PR |
91 | |
92 | tcgetattr(0, &tty); | |
93 | ||
c5b4c135 DWF |
94 | /* Use defaults of <sys/ttydefaults.h> for base settings */ |
95 | tty.c_iflag |= TTYDEF_IFLAG; | |
96 | tty.c_oflag |= TTYDEF_OFLAG; | |
97 | tty.c_lflag |= TTYDEF_LFLAG; | |
98 | tty.c_cflag |= (TTYDEF_SPEED | TTYDEF_CFLAG); | |
a74aeac6 | 99 | |
c5b4c135 DWF |
100 | /* Sane setting, allow eight bit characters, no carriage return delay |
101 | * the same result as `stty sane cr0 pass8' | |
102 | */ | |
103 | tty.c_iflag |= (BRKINT | ICRNL | IMAXBEL); | |
c5b4c135 DWF |
104 | tty.c_iflag &= ~(IGNBRK | INLCR | IGNCR | IXOFF | IUCLC | IXANY | ISTRIP); |
105 | tty.c_oflag |= (OPOST | ONLCR | NL0 | CR0 | TAB0 | BS0 | VT0 | FF0); | |
106 | tty.c_oflag &= ~(OLCUC | OCRNL | ONOCR | ONLRET | OFILL | OFDEL |\ | |
107 | NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY); | |
108 | tty.c_lflag |= (ISIG | ICANON | IEXTEN | ECHO|ECHOE|ECHOK|ECHOCTL|ECHOKE); | |
109 | tty.c_lflag &= ~(ECHONL | NOFLSH | XCASE | TOSTOP | ECHOPRT); | |
110 | tty.c_cflag |= (CREAD | CS8 | B9600); | |
111 | tty.c_cflag &= ~(PARENB); | |
112 | ||
113 | /* VTIME and VMIN can overlap with VEOF and VEOL since they are | |
114 | * only used for non-canonical mode. We just set the at the | |
115 | * beginning, so nothing bad should happen. | |
a74aeac6 | 116 | */ |
c5b4c135 DWF |
117 | tty.c_cc[VTIME] = 0; |
118 | tty.c_cc[VMIN] = 1; | |
119 | tty.c_cc[VINTR] = CINTR; | |
120 | tty.c_cc[VQUIT] = CQUIT; | |
121 | tty.c_cc[VERASE] = CERASE; /* ASCII DEL (0177) */ | |
122 | tty.c_cc[VKILL] = CKILL; | |
123 | tty.c_cc[VEOF] = CEOF; | |
124 | tty.c_cc[VSWTC] = _POSIX_VDISABLE; | |
125 | tty.c_cc[VSTART] = CSTART; | |
126 | tty.c_cc[VSTOP] = CSTOP; | |
127 | tty.c_cc[VSUSP] = CSUSP; | |
128 | tty.c_cc[VEOL] = _POSIX_VDISABLE; | |
129 | tty.c_cc[VREPRINT] = CREPRINT; | |
130 | tty.c_cc[VDISCARD] = CDISCARD; | |
131 | tty.c_cc[VWERASE] = CWERASE; | |
132 | tty.c_cc[VLNEXT] = CLNEXT; | |
133 | tty.c_cc[VEOL2] = _POSIX_VDISABLE; | |
21421926 | 134 | |
a74aeac6 | 135 | tcsetattr(0, TCSANOW, &tty); |
c5b4c135 DWF |
136 | out: |
137 | return; | |
a74aeac6 PR |
138 | } |
139 | #endif | |
140 | ||
141 | ||
142 | /* | |
143 | * Called at timeout. | |
144 | */ | |
c5b4c135 DWF |
145 | static |
146 | # ifdef __GNUC__ | |
147 | void alrm_handler(int sig __attribute__((unused))) | |
148 | # else | |
149 | void alrm_handler(int sig) | |
150 | # endif | |
a74aeac6 PR |
151 | { |
152 | } | |
153 | ||
154 | /* | |
155 | * See if an encrypted password is valid. The encrypted | |
156 | * password is checked for traditional-style DES and | |
157 | * FreeBSD-style MD5 encryption. | |
158 | */ | |
c5b4c135 | 159 | static |
22786b24 | 160 | int valid(const char *pass) |
a74aeac6 | 161 | { |
22786b24 DWF |
162 | const char *s; |
163 | char id[5]; | |
164 | size_t len; | |
165 | off_t off; | |
a74aeac6 PR |
166 | |
167 | if (pass[0] == 0) return 1; | |
168 | #if CHECK_MD5 | |
22786b24 DWF |
169 | if (pass[0] != '$') goto check_des; |
170 | ||
171 | /* | |
172 | * up to 4 bytes for the signature e.g. $1$ | |
173 | */ | |
174 | for(s = pass+1; *s && *s != '$'; s++) | |
175 | ; | |
176 | if (*s++ != '$') return 0; | |
177 | if ((off = (off_t)(s-pass)) > 4 || off < 3) return 0; | |
178 | ||
179 | memset(id, '\0', sizeof(id)); | |
180 | strncpy(id, pass, off); | |
181 | ||
182 | /* | |
183 | * up to 16 bytes for the salt | |
184 | */ | |
185 | for(; *s && *s != '$'; s++) | |
186 | ; | |
187 | if (*s++ != '$') return 0; | |
188 | if ((off_t)(s-pass) > 16) return 0; | |
189 | len = strlen(s); | |
190 | ||
a74aeac6 | 191 | /* |
a74aeac6 PR |
192 | * the MD5 hash (128 bits or 16 bytes) encoded in base64 = 22 bytes |
193 | */ | |
22786b24 DWF |
194 | if ((strcmp(id, "$1$") == 0) && (len < 22 || len > 24)) return 0; |
195 | ||
196 | /* | |
197 | * the SHA-256 hash 43 bytes | |
198 | */ | |
199 | if ((strcmp(id, "$5$") == 0) && (len < 42 || len > 44)) return 0; | |
200 | ||
201 | /* | |
202 | * the SHA-512 hash 86 bytes | |
203 | */ | |
204 | if ((strcmp(id, "$6$") == 0) && (len < 85 || len > 87)) return 0; | |
205 | ||
206 | /* | |
207 | * e.g. Blowfish hash | |
208 | */ | |
209 | return 1; | |
210 | check_des: | |
a74aeac6 PR |
211 | #endif |
212 | #if CHECK_DES | |
213 | if (strlen(pass) != 13) return 0; | |
214 | for (s = pass; *s; s++) { | |
215 | if ((*s < '0' || *s > '9') && | |
216 | (*s < 'a' || *s > 'z') && | |
217 | (*s < 'A' || *s > 'Z') && | |
218 | *s != '.' && *s != '/') return 0; | |
219 | } | |
220 | #endif | |
221 | return 1; | |
222 | } | |
223 | ||
224 | /* | |
225 | * Set a variable if the value is not NULL. | |
226 | */ | |
c5b4c135 | 227 | static |
a74aeac6 PR |
228 | void set(char **var, char *val) |
229 | { | |
230 | if (val) *var = val; | |
231 | } | |
232 | ||
233 | /* | |
234 | * Get the root password entry. | |
235 | */ | |
c5b4c135 | 236 | static |
a74aeac6 PR |
237 | struct passwd *getrootpwent(int try_manually) |
238 | { | |
239 | static struct passwd pwd; | |
240 | struct passwd *pw; | |
241 | struct spwd *spw; | |
242 | FILE *fp; | |
243 | static char line[256]; | |
244 | static char sline[256]; | |
245 | char *p; | |
246 | ||
247 | /* | |
248 | * First, we try to get the password the standard | |
249 | * way using normal library calls. | |
250 | */ | |
251 | if ((pw = getpwnam("root")) && | |
252 | !strcmp(pw->pw_passwd, "x") && | |
253 | (spw = getspnam("root"))) | |
254 | pw->pw_passwd = spw->sp_pwdp; | |
255 | if (pw || !try_manually) return pw; | |
256 | ||
257 | /* | |
258 | * If we come here, we could not retrieve the root | |
259 | * password through library calls and we try to | |
260 | * read the password and shadow files manually. | |
261 | */ | |
262 | pwd.pw_name = "root"; | |
263 | pwd.pw_passwd = ""; | |
264 | pwd.pw_gecos = "Super User"; | |
265 | pwd.pw_dir = "/"; | |
266 | pwd.pw_shell = ""; | |
267 | pwd.pw_uid = 0; | |
268 | pwd.pw_gid = 0; | |
269 | ||
270 | if ((fp = fopen(F_PASSWD, "r")) == NULL) { | |
271 | perror(F_PASSWD); | |
272 | return &pwd; | |
273 | } | |
274 | ||
275 | /* | |
276 | * Find root in the password file. | |
277 | */ | |
278 | while((p = fgets(line, 256, fp)) != NULL) { | |
279 | if (strncmp(line, "root:", 5) != 0) | |
280 | continue; | |
281 | p += 5; | |
282 | set(&pwd.pw_passwd, strsep(&p, ":")); | |
283 | (void)strsep(&p, ":"); | |
284 | (void)strsep(&p, ":"); | |
285 | set(&pwd.pw_gecos, strsep(&p, ":")); | |
286 | set(&pwd.pw_dir, strsep(&p, ":")); | |
287 | set(&pwd.pw_shell, strsep(&p, "\n")); | |
288 | p = line; | |
289 | break; | |
290 | } | |
291 | fclose(fp); | |
292 | ||
293 | /* | |
294 | * If the encrypted password is valid | |
295 | * or not found, return. | |
296 | */ | |
297 | if (p == NULL) { | |
298 | fprintf(stderr, "%s: no entry for root\n", F_PASSWD); | |
299 | return &pwd; | |
300 | } | |
301 | if (valid(pwd.pw_passwd)) return &pwd; | |
302 | ||
303 | /* | |
304 | * The password is invalid. If there is a | |
305 | * shadow password, try it. | |
306 | */ | |
307 | strcpy(pwd.pw_passwd, ""); | |
308 | if ((fp = fopen(F_SHADOW, "r")) == NULL) { | |
309 | fprintf(stderr, "%s: root password garbled\n", F_PASSWD); | |
310 | return &pwd; | |
311 | } | |
312 | while((p = fgets(sline, 256, fp)) != NULL) { | |
313 | if (strncmp(sline, "root:", 5) != 0) | |
314 | continue; | |
315 | p += 5; | |
316 | set(&pwd.pw_passwd, strsep(&p, ":")); | |
317 | break; | |
318 | } | |
319 | fclose(fp); | |
320 | ||
321 | /* | |
322 | * If the password is still invalid, | |
323 | * NULL it, and return. | |
324 | */ | |
325 | if (p == NULL) { | |
326 | fprintf(stderr, "%s: no entry for root\n", F_SHADOW); | |
327 | strcpy(pwd.pw_passwd, ""); | |
328 | } | |
329 | if (!valid(pwd.pw_passwd)) { | |
330 | fprintf(stderr, "%s: root password garbled\n", F_SHADOW); | |
331 | strcpy(pwd.pw_passwd, ""); } | |
332 | return &pwd; | |
333 | } | |
334 | ||
335 | /* | |
336 | * Ask for the password. Note that there is no | |
337 | * default timeout as we normally skip this during boot. | |
338 | */ | |
c5b4c135 | 339 | static |
a74aeac6 PR |
340 | char *getpasswd(char *crypted) |
341 | { | |
342 | struct sigaction sa; | |
343 | struct termios old, tty; | |
344 | static char pass[128]; | |
345 | char *ret = pass; | |
346 | int i; | |
ad6831b9 DWF |
347 | #if defined(USE_ONELINE) |
348 | if (crypted[0]) | |
c5b4c135 | 349 | printf("Give root password for login: "); |
ad6831b9 | 350 | else |
c5b4c135 | 351 | printf("Press enter for login: "); |
ad6831b9 DWF |
352 | #else |
353 | if (crypted[0]) | |
354 | printf("Give root password for maintenance\n"); | |
355 | else | |
356 | printf("Press enter for maintenance"); | |
357 | printf("(or type Control-D to continue): "); | |
358 | #endif | |
a74aeac6 PR |
359 | fflush(stdout); |
360 | ||
361 | tcgetattr(0, &old); | |
362 | tcgetattr(0, &tty); | |
363 | tty.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY); | |
364 | tty.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|TOSTOP); | |
365 | tcsetattr(0, TCSANOW, &tty); | |
366 | ||
367 | pass[sizeof(pass) - 1] = 0; | |
368 | ||
369 | sa.sa_handler = alrm_handler; | |
370 | sa.sa_flags = 0; | |
371 | sigaction(SIGALRM, &sa, NULL); | |
372 | if (timeout) alarm(timeout); | |
373 | ||
374 | if (read(0, pass, sizeof(pass) - 1) <= 0) | |
375 | ret = NULL; | |
376 | else { | |
192c4567 | 377 | for(i = 0; i < (int)sizeof(pass) && pass[i]; i++) |
a74aeac6 PR |
378 | if (pass[i] == '\r' || pass[i] == '\n') { |
379 | pass[i] = 0; | |
380 | break; | |
381 | } | |
382 | } | |
383 | alarm(0); | |
384 | tcsetattr(0, TCSANOW, &old); | |
385 | printf("\n"); | |
386 | ||
387 | return ret; | |
388 | } | |
389 | ||
390 | /* | |
391 | * Password was OK, execute a shell. | |
392 | */ | |
c5b4c135 | 393 | static |
a74aeac6 PR |
394 | void sushell(struct passwd *pwd) |
395 | { | |
396 | char shell[128]; | |
397 | char home[128]; | |
398 | char *p; | |
399 | char *sushell; | |
400 | ||
401 | /* | |
402 | * Set directory and shell. | |
403 | */ | |
404 | (void)chdir(pwd->pw_dir); | |
405 | if ((p = getenv("SUSHELL")) != NULL) | |
406 | sushell = p; | |
407 | else if ((p = getenv("sushell")) != NULL) | |
408 | sushell = p; | |
409 | else { | |
410 | if (pwd->pw_shell[0]) | |
411 | sushell = pwd->pw_shell; | |
412 | else | |
413 | sushell = BINSH; | |
414 | } | |
415 | if ((p = strrchr(sushell, '/')) == NULL) | |
416 | p = sushell; | |
417 | else | |
418 | p++; | |
419 | snprintf(shell, sizeof(shell), profile ? "-%s" : "%s", p); | |
420 | ||
421 | /* | |
422 | * Set some important environment variables. | |
423 | */ | |
424 | getcwd(home, sizeof(home)); | |
425 | setenv("HOME", home, 1); | |
426 | setenv("LOGNAME", "root", 1); | |
427 | setenv("USER", "root", 1); | |
428 | if (!profile) | |
429 | setenv("SHLVL","0",1); | |
430 | ||
431 | /* | |
432 | * Try to execute a shell. | |
433 | */ | |
434 | setenv("SHELL", sushell, 1); | |
c5b4c135 DWF |
435 | signal(SIGINT, saved_sigint); |
436 | signal(SIGTSTP, saved_sigtstp); | |
437 | signal(SIGQUIT, saved_sigquit); | |
a74aeac6 | 438 | #ifdef WITH_SELINUX |
9af2d863 | 439 | if (is_selinux_enabled() > 0) { |
a74aeac6 PR |
440 | security_context_t scon=NULL; |
441 | char *seuser=NULL; | |
442 | char *level=NULL; | |
443 | if (getseuserbyname("root", &seuser, &level) == 0) | |
872353ef | 444 | if (get_default_context_with_level(seuser, level, 0, &scon) == 0) { |
a74aeac6 PR |
445 | if (setexeccon(scon) != 0) |
446 | fprintf(stderr, "setexeccon faile\n"); | |
447 | freecon(scon); | |
448 | } | |
449 | free(seuser); | |
450 | free(level); | |
451 | } | |
452 | #endif | |
453 | execl(sushell, shell, NULL); | |
454 | perror(sushell); | |
455 | ||
456 | setenv("SHELL", BINSH, 1); | |
457 | execl(BINSH, profile ? "-sh" : "sh", NULL); | |
458 | perror(BINSH); | |
459 | ||
460 | /* Fall back to staticly linked shell if both the users shell | |
461 | and /bin/sh failed to execute. */ | |
462 | setenv("SHELL", STATICSH, 1); | |
463 | execl(STATICSH, STATICSH, NULL); | |
464 | perror(STATICSH); | |
465 | } | |
466 | ||
c5b4c135 | 467 | static |
a74aeac6 PR |
468 | void usage(void) |
469 | { | |
470 | fprintf(stderr, "Usage: sulogin [-e] [-p] [-t timeout] [tty device]\n"); | |
471 | } | |
472 | ||
473 | int main(int argc, char **argv) | |
474 | { | |
475 | char *tty = NULL; | |
476 | char *p; | |
477 | struct passwd *pwd; | |
478 | int c, fd = -1; | |
479 | int opt_e = 0; | |
480 | pid_t pid, pgrp, ppgrp, ttypgrp; | |
481 | ||
482 | /* | |
483 | * See if we have a timeout flag. | |
484 | */ | |
485 | opterr = 0; | |
486 | while((c = getopt(argc, argv, "ept:")) != EOF) switch(c) { | |
487 | case 't': | |
488 | timeout = atoi(optarg); | |
489 | break; | |
490 | case 'p': | |
491 | profile = 1; | |
492 | break; | |
493 | case 'e': | |
494 | opt_e = 1; | |
495 | break; | |
496 | default: | |
497 | usage(); | |
498 | /* Do not exit! */ | |
499 | break; | |
500 | } | |
501 | ||
502 | if (geteuid() != 0) { | |
503 | fprintf(stderr, "sulogin: only root can run sulogin.\n"); | |
504 | exit(1); | |
505 | } | |
506 | ||
507 | /* | |
508 | * See if we need to open an other tty device. | |
509 | */ | |
c5b4c135 DWF |
510 | saved_sigint = signal(SIGINT, SIG_IGN); |
511 | saved_sigtstp = signal(SIGQUIT, SIG_IGN); | |
512 | saved_sigquit = signal(SIGTSTP, SIG_IGN); | |
a74aeac6 | 513 | if (optind < argc) tty = argv[optind]; |
c5b4c135 DWF |
514 | |
515 | if (tty || (tty = getenv("CONSOLE"))) { | |
516 | ||
a74aeac6 PR |
517 | if ((fd = open(tty, O_RDWR)) < 0) { |
518 | perror(tty); | |
c5b4c135 DWF |
519 | fd = dup(0); |
520 | } | |
521 | ||
522 | if (!isatty(fd)) { | |
a74aeac6 PR |
523 | fprintf(stderr, "%s: not a tty\n", tty); |
524 | close(fd); | |
525 | } else { | |
526 | ||
527 | /* | |
528 | * Only go through this trouble if the new | |
529 | * tty doesn't fall in this process group. | |
530 | */ | |
531 | pid = getpid(); | |
532 | pgrp = getpgid(0); | |
533 | ppgrp = getpgid(getppid()); | |
c5b4c135 | 534 | ttypgrp = tcgetpgrp(fd); |
a74aeac6 PR |
535 | |
536 | if (pgrp != ttypgrp && ppgrp != ttypgrp) { | |
537 | if (pid != getsid(0)) { | |
538 | if (pid == getpgid(0)) | |
539 | setpgid(0, getpgid(getppid())); | |
540 | setsid(); | |
541 | } | |
542 | ||
543 | signal(SIGHUP, SIG_IGN); | |
c5b4c135 DWF |
544 | if (ttypgrp > 0) |
545 | ioctl(0, TIOCNOTTY, (char *)1); | |
a74aeac6 PR |
546 | signal(SIGHUP, SIG_DFL); |
547 | close(0); | |
548 | close(1); | |
549 | close(2); | |
c5b4c135 DWF |
550 | if (fd > 2) |
551 | close(fd); | |
ad6831b9 | 552 | if ((fd = open(tty, O_RDWR|O_NOCTTY)) < 0) { |
c5b4c135 DWF |
553 | perror(tty); |
554 | } else { | |
555 | ioctl(0, TIOCSCTTY, (char *)1); | |
556 | tcsetpgrp(fd, ppgrp); | |
557 | dup2(fd, 0); | |
558 | dup2(fd, 1); | |
559 | dup2(fd, 2); | |
560 | if (fd > 2) | |
561 | close(fd); | |
562 | } | |
a74aeac6 | 563 | } else |
c5b4c135 DWF |
564 | if (fd > 2) |
565 | close(fd); | |
a74aeac6 PR |
566 | } |
567 | } else if (getpid() == 1) { | |
568 | /* We are init. We hence need to set a session anyway */ | |
569 | setsid(); | |
570 | if (ioctl(0, TIOCSCTTY, (char *)1)) | |
571 | perror("ioctl(TIOCSCTTY)"); | |
572 | } | |
573 | ||
c5b4c135 DWF |
574 | #if defined(SANE_TIO) && (SANE_TIO == 1) |
575 | fixtty(); | |
576 | #endif | |
577 | ||
a74aeac6 PR |
578 | /* |
579 | * Get the root password. | |
580 | */ | |
581 | if ((pwd = getrootpwent(opt_e)) == NULL) { | |
582 | fprintf(stderr, "sulogin: cannot open password database!\n"); | |
583 | sleep(2); | |
584 | } | |
585 | ||
586 | /* | |
587 | * Ask for the password. | |
588 | */ | |
589 | while(pwd) { | |
590 | if ((p = getpasswd(pwd->pw_passwd)) == NULL) break; | |
591 | if (pwd->pw_passwd[0] == 0 || | |
592 | strcmp(crypt(p, pwd->pw_passwd), pwd->pw_passwd) == 0) | |
593 | sushell(pwd); | |
c5b4c135 DWF |
594 | saved_sigquit = signal(SIGQUIT, SIG_IGN); |
595 | saved_sigtstp = signal(SIGTSTP, SIG_IGN); | |
596 | saved_sigint = signal(SIGINT, SIG_IGN); | |
a74aeac6 PR |
597 | printf("Login incorrect.\n"); |
598 | } | |
599 | ||
600 | /* | |
601 | * User pressed Control-D. | |
602 | */ | |
603 | return 0; | |
604 | } |