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