Commit | Line | Data |
---|---|---|
9bcf1061 | 1 | /*- |
ede75793 KB |
2 | * Copyright (c) 1980, 1987, 1988 The Regents of the University of California. |
3 | * All rights reserved. | |
4 | * | |
9bcf1061 | 5 | * %sccs.include.redist.c% |
bcf1365c DF |
6 | */ |
7 | ||
8 | #ifndef lint | |
9 | char copyright[] = | |
ede75793 | 10 | "@(#) Copyright (c) 1980, 1987, 1988 The Regents of the University of California.\n\ |
bcf1365c | 11 | All rights reserved.\n"; |
ede75793 | 12 | #endif /* not lint */ |
bcf1365c | 13 | |
22d4760e | 14 | #ifndef lint |
58241a29 | 15 | static char sccsid[] = "@(#)login.c 5.64 (Berkeley) %G%"; |
ede75793 | 16 | #endif /* not lint */ |
22d4760e | 17 | |
88a01c09 BJ |
18 | /* |
19 | * login [ name ] | |
d0faf133 | 20 | * login -r hostname (for rlogind) |
5dbe2745 MK |
21 | * login -h hostname (for telnetd, etc.) |
22 | * login -f name (for pre-authenticated login: datakit, xterm, etc.) | |
88a01c09 BJ |
23 | */ |
24 | ||
7a625b73 | 25 | #include <sys/param.h> |
3b8dd95e SL |
26 | #include <sys/stat.h> |
27 | #include <sys/time.h> | |
28 | #include <sys/resource.h> | |
9479aa87 | 29 | #include <sys/file.h> |
2d4a74b8 | 30 | #include <sgtty.h> |
3b8dd95e | 31 | |
88a01c09 BJ |
32 | #include <utmp.h> |
33 | #include <signal.h> | |
22d4760e | 34 | #include <errno.h> |
9479aa87 BJ |
35 | #include <ttyent.h> |
36 | #include <syslog.h> | |
c89291e2 | 37 | #include <grp.h> |
80f91e3f | 38 | #include <pwd.h> |
ede75793 | 39 | #include <setjmp.h> |
80f91e3f | 40 | #include <stdio.h> |
38dde0cd | 41 | #include <string.h> |
0e08a2b3 | 42 | #include <tzfile.h> |
fb6e7f7e | 43 | #include "pathnames.h" |
c89291e2 | 44 | |
80f91e3f | 45 | #define TTYGRPNAME "tty" /* name of group to own ttys */ |
88a01c09 | 46 | |
3b8dd95e | 47 | /* |
80f91e3f KB |
48 | * This bounds the time given to login. Not a define so it can |
49 | * be patched on machines where it's too small. | |
3b8dd95e | 50 | */ |
a9b031fe | 51 | int timeout = 300; |
9bcf1061 KB |
52 | #ifdef KERBEROS |
53 | int notickets = 1; | |
54 | #endif | |
86eb6c9e | 55 | |
659be7fb MK |
56 | struct passwd *pwd; |
57 | int failures; | |
657e5a3c | 58 | char term[64], *envinit[1], *hostname, *username, *tty; |
88a01c09 | 59 | |
c91c86eb KB |
60 | char *months[] = |
61 | { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", | |
62 | "Sep", "Oct", "Nov", "Dec" }; | |
63 | ||
88a01c09 | 64 | main(argc, argv) |
80f91e3f KB |
65 | int argc; |
66 | char **argv; | |
88a01c09 | 67 | { |
9bcf1061 | 68 | extern int optind; |
80f91e3f | 69 | extern char *optarg, **environ; |
c91c86eb KB |
70 | struct timeval tp; |
71 | struct tm *ttp; | |
83cc7253 | 72 | struct timeval tp; |
80f91e3f KB |
73 | struct group *gr; |
74 | register int ch; | |
659be7fb | 75 | register char *p; |
d0faf133 | 76 | int ask, fflag, hflag, pflag, rflag, cnt; |
71236658 | 77 | int quietlog, rval; |
9bcf1061 | 78 | char *domain, *salt, *ttyn; |
a339b173 | 79 | char tbuf[MAXPATHLEN + 2], tname[sizeof(_PATH_TTY) + 10]; |
e2a7a526 | 80 | char localhost[MAXHOSTNAMELEN]; |
c91c86eb | 81 | char *ctime(), *ttyname(), *stypeof(), *crypt(), *getpass(); |
80f91e3f KB |
82 | time_t time(); |
83 | off_t lseek(); | |
9bcf1061 | 84 | void timedout(); |
80f91e3f KB |
85 | |
86 | (void)signal(SIGALRM, timedout); | |
87 | (void)alarm((u_int)timeout); | |
88 | (void)signal(SIGQUIT, SIG_IGN); | |
89 | (void)signal(SIGINT, SIG_IGN); | |
90 | (void)setpriority(PRIO_PROCESS, 0, 0); | |
80f91e3f | 91 | |
9e76b9f1 KB |
92 | openlog("login", LOG_ODELAY, LOG_AUTH); |
93 | ||
3b8dd95e | 94 | /* |
d3737d51 | 95 | * -p is used by getty to tell login not to destroy the environment |
d0faf133 | 96 | * -r is used by rlogind to cause the autologin protocol; |
5dbe2745 | 97 | * -f is used to skip a second login authentication |
ee1eff74 MK |
98 | * -h is used by other servers to pass the name of the remote |
99 | * host to login so that it may be placed in utmp and wtmp | |
3b8dd95e | 100 | */ |
e2a7a526 KF |
101 | domain = NULL; |
102 | if (gethostname(localhost, sizeof(localhost)) < 0) | |
103 | syslog(LOG_ERR, "couldn't get local hostname: %m"); | |
104 | else | |
105 | domain = index(localhost, '.'); | |
80f91e3f | 106 | |
d0faf133 | 107 | fflag = hflag = pflag = rflag = 0; |
2d4a74b8 | 108 | uid = getuid(); |
d0faf133 | 109 | while ((ch = getopt(argc, argv, "fh:pr:")) != EOF) |
ede75793 | 110 | switch (ch) { |
80f91e3f | 111 | case 'f': |
d0faf133 KB |
112 | if (rflag) { |
113 | fprintf(stderr, | |
114 | "login: only one of -r and -f allowed.\n"); | |
115 | exit(1); | |
116 | } | |
80f91e3f | 117 | fflag = 1; |
80f91e3f KB |
118 | break; |
119 | case 'h': | |
2d4a74b8 | 120 | if (uid) { |
0e08a2b3 | 121 | (void)fprintf(stderr, |
80f91e3f | 122 | "login: -h for super-user only.\n"); |
b6f7cade | 123 | exit(1); |
5dbe2745 | 124 | } |
d0faf133 KB |
125 | if (rflag) { |
126 | fprintf(stderr, | |
127 | "login: only one of -r and -h allowed.\n"); | |
128 | exit(1); | |
129 | } | |
80f91e3f KB |
130 | hflag = 1; |
131 | if (domain && (p = index(optarg, '.')) && | |
abc4056e | 132 | strcasecmp(p, domain) == 0) |
80f91e3f KB |
133 | *p = 0; |
134 | hostname = optarg; | |
135 | break; | |
136 | case 'p': | |
d3737d51 | 137 | pflag = 1; |
80f91e3f | 138 | break; |
d0faf133 KB |
139 | case 'r': |
140 | if (hflag || fflag) { | |
141 | fprintf(stderr, | |
142 | "login: -f and -h not allowed with -r.\n"); | |
143 | exit(1); | |
144 | } | |
145 | if (getuid()) { | |
146 | fprintf(stderr, | |
147 | "login: -r for super-user only.\n"); | |
148 | exit(1); | |
149 | } | |
150 | /* "-r hostname" must be last args */ | |
151 | if (optind != argc) { | |
152 | fprintf(stderr, "Syntax error.\n"); | |
153 | exit(1); | |
154 | } | |
155 | rflag = 1; | |
156 | passwd_req = (doremotelogin(optarg) == -1); | |
157 | if (domain && (p = index(optarg, '.')) && | |
158 | !strcmp(p, domain)) | |
159 | *p = '\0'; | |
160 | hostname = optarg; | |
161 | break; | |
80f91e3f KB |
162 | case '?': |
163 | default: | |
2d4a74b8 KF |
164 | if (!uid) |
165 | syslog(LOG_ERR, "invalid flag %c", ch); | |
0e08a2b3 KB |
166 | (void)fprintf(stderr, |
167 | "usage: login [-fp] [username]\n"); | |
80f91e3f | 168 | exit(1); |
d3737d51 | 169 | } |
80f91e3f KB |
170 | argc -= optind; |
171 | argv += optind; | |
f0c0c252 | 172 | if (*argv) { |
80f91e3f | 173 | username = *argv; |
9bcf1061 KB |
174 | if (strlen(username) > UT_NAMESIZE) |
175 | username[UT_NAMESIZE] = '\0'; | |
659be7fb MK |
176 | ask = 0; |
177 | } else | |
f0c0c252 | 178 | ask = 1; |
d0faf133 KB |
179 | if (rflag) |
180 | ask = 0; | |
80f91e3f | 181 | |
80f91e3f KB |
182 | for (cnt = getdtablesize(); cnt > 2; cnt--) |
183 | close(cnt); | |
184 | ||
88a01c09 | 185 | ttyn = ttyname(0); |
a339b173 KB |
186 | if (ttyn == NULL || *ttyn == '\0') { |
187 | (void)sprintf(tname, "%s??", _PATH_TTY); | |
188 | ttyn = tname; | |
189 | } | |
80f91e3f KB |
190 | if (tty = rindex(ttyn, '/')) |
191 | ++tty; | |
9479aa87 | 192 | else |
80f91e3f KB |
193 | tty = ttyn; |
194 | ||
f0c0c252 | 195 | for (cnt = 0;; ask = 1) { |
f0c0c252 | 196 | if (ask) { |
ede75793 | 197 | fflag = 0; |
80f91e3f | 198 | getloginname(); |
ede75793 | 199 | } |
659be7fb | 200 | /* |
2d4a74b8 KF |
201 | * Note if trying multiple user names; log failures for |
202 | * previous user name, but don't bother logging one failure | |
659be7fb MK |
203 | * for nonexistent name (mistyped username). |
204 | */ | |
205 | if (failures && strcmp(tbuf, username)) { | |
206 | if (failures > (pwd ? 0 : 1)) | |
f0c0c252 | 207 | badlogin(tbuf); |
659be7fb | 208 | failures = 0; |
f0c0c252 | 209 | } |
659be7fb | 210 | (void)strcpy(tbuf, username); |
320a5e84 | 211 | |
ede75793 KB |
212 | if (pwd = getpwnam(username)) |
213 | salt = pwd->pw_passwd; | |
320a5e84 KB |
214 | else |
215 | salt = "xx"; | |
80f91e3f | 216 | |
3b8dd95e | 217 | /* |
cb400a97 KB |
218 | * if we have a valid account name, and it doesn't have a |
219 | * password, or the -f option was specified and the caller | |
220 | * is root or the caller isn't changing their uid, don't | |
221 | * authenticate. | |
3b8dd95e | 222 | */ |
cb400a97 KB |
223 | if (pwd && (*pwd->pw_passwd == '\0' || |
224 | fflag && (uid == 0 || uid == pwd->pw_uid))) | |
80f91e3f | 225 | break; |
e83bda0c | 226 | fflag = 0; |
80f91e3f | 227 | |
2d4a74b8 KF |
228 | /* |
229 | * If trying to log in as root, but with insecure terminal, | |
230 | * refuse the login attempt. | |
231 | */ | |
320a5e84 | 232 | if (pwd && pwd->pw_uid == 0 && !rootterm(tty)) { |
2d4a74b8 KF |
233 | (void)fprintf(stderr, |
234 | "%s login refused on this terminal.\n", | |
235 | pwd->pw_name); | |
236 | if (hostname) | |
237 | syslog(LOG_NOTICE, | |
238 | "LOGIN %s REFUSED FROM %s ON TTY %s", | |
239 | pwd->pw_name, hostname, tty); | |
240 | else | |
241 | syslog(LOG_NOTICE, | |
242 | "LOGIN %s REFUSED ON TTY %s", | |
243 | pwd->pw_name, tty); | |
244 | continue; | |
245 | } | |
246 | ||
9bcf1061 | 247 | (void)setpriority(PRIO_PROCESS, 0, -4); |
320a5e84 | 248 | |
9bcf1061 | 249 | p = getpass("Password:"); |
9d6a5a69 | 250 | |
320a5e84 | 251 | if (pwd) { |
9bcf1061 | 252 | bzero(p, strlen(p)); |
320a5e84 KB |
253 | |
254 | (void)setpriority(PRIO_PROCESS, 0, 0); | |
255 | ||
256 | if (pwd && !rval) | |
80f91e3f KB |
257 | break; |
258 | ||
320a5e84 | 259 | (void)printf("Login incorrect\n"); |
659be7fb | 260 | failures++; |
f0c0c252 KB |
261 | /* we allow 10 tries, but after 3 we start backing off */ |
262 | if (++cnt > 3) { | |
263 | if (cnt >= 10) { | |
264 | badlogin(username); | |
f0c0c252 KB |
265 | sleepexit(1); |
266 | } | |
267 | sleep((u_int)((cnt - 3) * 5)); | |
f570e1ff | 268 | } |
80f91e3f | 269 | } |
88a01c09 | 270 | |
80f91e3f KB |
271 | /* committed to login -- turn off timeout */ |
272 | (void)alarm((u_int)0); | |
273 | ||
a339b173 KB |
274 | /* paranoia... */ |
275 | endpwent(); | |
276 | ||
c374ff7b KB |
277 | /* if user not super-user, check for disabled logins */ |
278 | if (pwd->pw_uid) | |
279 | checknologin(); | |
280 | ||
ede75793 | 281 | if (chdir(pwd->pw_dir) < 0) { |
0e08a2b3 | 282 | (void)printf("No directory %s!\n", pwd->pw_dir); |
ede75793 KB |
283 | if (chdir("/")) |
284 | exit(0); | |
285 | pwd->pw_dir = "/"; | |
0e08a2b3 | 286 | (void)printf("Logging in with home = \"/\".\n"); |
ede75793 | 287 | } |
83cc7253 KB |
288 | #define TWOWEEKS (14*24*60*60) |
289 | if (pwd->pw_change || pwd->pw_expire) | |
290 | (void)gettimeofday(&tp, (struct timezone *)NULL); | |
291 | if (pwd->pw_change) | |
292 | if (tp.tv_sec >= pwd->pw_change) { | |
293 | printf("Sorry -- your password has expired.\n"); | |
294 | sleepexit(1); | |
295 | } | |
296 | else if (tp.tv_sec - pwd->pw_change < TWOWEEKS) { | |
297 | ttp = localtime(&pwd->pw_change); | |
298 | printf("Warning: your password expires on %s %d, 19%d\n", | |
299 | months[ttp->tm_mon], ttp->tm_mday, ttp->tm_year); | |
300 | } | |
301 | if (pwd->pw_expire) | |
302 | if (tp.tv_sec >= pwd->pw_expire) { | |
303 | printf("Sorry -- your account has expired.\n"); | |
304 | sleepexit(1); | |
305 | } | |
306 | else if (tp.tv_sec - pwd->pw_expire < TWOWEEKS) { | |
307 | ttp = localtime(&pwd->pw_expire); | |
308 | printf("Warning: your account expires on %s %d, 19%d\n", | |
309 | months[ttp->tm_mon], ttp->tm_mday, ttp->tm_year); | |
310 | } | |
311 | ||
c91c86eb KB |
312 | if (pwd->pw_change || pwd->pw_expire) |
313 | (void)gettimeofday(&tp, (struct timezone *)NULL); | |
314 | if (pwd->pw_change) | |
315 | if (tp.tv_sec >= pwd->pw_change) { | |
0e08a2b3 | 316 | (void)printf("Sorry -- your password has expired.\n"); |
c91c86eb KB |
317 | sleepexit(1); |
318 | } | |
50112e48 | 319 | else if (pwd->pw_change - tp.tv_sec < |
44d9892d KB |
320 | 2 * DAYSPERWEEK * SECSPERDAY && !quietlog) |
321 | (void)printf("Warning: your password expires on %s", | |
322 | ctime(&pwd->pw_expire)); | |
c91c86eb KB |
323 | if (pwd->pw_expire) |
324 | if (tp.tv_sec >= pwd->pw_expire) { | |
0e08a2b3 | 325 | (void)printf("Sorry -- your account has expired.\n"); |
c91c86eb KB |
326 | sleepexit(1); |
327 | } | |
50112e48 | 328 | else if (pwd->pw_expire - tp.tv_sec < |
44d9892d KB |
329 | 2 * DAYSPERWEEK * SECSPERDAY && !quietlog) |
330 | (void)printf("Warning: your account expires on %s", | |
331 | ctime(&pwd->pw_expire)); | |
c91c86eb | 332 | |
ede75793 | 333 | /* nothing else left to fail -- really log in */ |
80f91e3f KB |
334 | { |
335 | struct utmp utmp; | |
336 | ||
9bcf1061 | 337 | bzero((void *)&utmp, sizeof(utmp)); |
80f91e3f KB |
338 | (void)time(&utmp.ut_time); |
339 | strncpy(utmp.ut_name, username, sizeof(utmp.ut_name)); | |
a829b33b KB |
340 | if (hostname) |
341 | strncpy(utmp.ut_host, hostname, sizeof(utmp.ut_host)); | |
80f91e3f KB |
342 | strncpy(utmp.ut_line, tty, sizeof(utmp.ut_line)); |
343 | login(&utmp); | |
f570e1ff | 344 | } |
80f91e3f | 345 | |
f0c0c252 | 346 | dolastlog(quietlog); |
80f91e3f | 347 | |
80f91e3f KB |
348 | (void)chown(ttyn, pwd->pw_uid, |
349 | (gr = getgrnam(TTYGRPNAME)) ? gr->gr_gid : pwd->pw_gid); | |
350 | (void)chmod(ttyn, 0620); | |
351 | (void)setgid(pwd->pw_gid); | |
352 | ||
353 | initgroups(username, pwd->pw_gid); | |
354 | ||
ede75793 | 355 | if (*pwd->pw_shell == '\0') |
fb6e7f7e | 356 | pwd->pw_shell = _PATH_BSHELL; |
ede75793 | 357 | |
80f91e3f | 358 | /* destroy environment unless user has requested preservation */ |
d3737d51 SL |
359 | if (!pflag) |
360 | environ = envinit; | |
ede75793 KB |
361 | (void)setenv("HOME", pwd->pw_dir, 1); |
362 | (void)setenv("SHELL", pwd->pw_shell, 1); | |
d3737d51 | 363 | if (term[0] == '\0') |
659be7fb | 364 | strncpy(term, stypeof(tty), sizeof(term)); |
ede75793 KB |
365 | (void)setenv("TERM", term, 0); |
366 | (void)setenv("USER", pwd->pw_name, 1); | |
c502712b | 367 | (void)setenv("PATH", _PATH_DEFPATH, 0); |
d3737d51 | 368 | |
9479aa87 | 369 | if (tty[sizeof("tty")-1] == 'd') |
d3737d51 | 370 | syslog(LOG_INFO, "DIALUP %s, %s", tty, pwd->pw_name); |
e83bda0c MK |
371 | /* if fflag is on, assume caller/authenticator has logged root login */ |
372 | if (pwd->pw_uid == 0 && fflag == 0) | |
80f91e3f | 373 | if (hostname) |
659be7fb | 374 | syslog(LOG_NOTICE, "ROOT LOGIN ON %s FROM %s", |
f0c0c252 | 375 | tty, hostname); |
df9d9536 | 376 | else |
659be7fb | 377 | syslog(LOG_NOTICE, "ROOT LOGIN ON %s", tty); |
80f91e3f | 378 | |
9bcf1061 KB |
379 | #ifdef KERBEROS |
380 | if (!quietlog && notickets == 1) | |
381 | (void)printf("Warning: no Kerberos tickets issued.\n"); | |
382 | #endif | |
383 | ||
4f8d3876 | 384 | if (!quietlog) { |
6821e9c5 | 385 | struct stat st; |
d3737d51 | 386 | |
80f91e3f | 387 | motd(); |
fb6e7f7e | 388 | (void)sprintf(tbuf, "%s/%s", _PATH_MAILDIR, pwd->pw_name); |
80f91e3f | 389 | if (stat(tbuf, &st) == 0 && st.st_size != 0) |
0e08a2b3 | 390 | (void)printf("You have %smail.\n", |
80f91e3f | 391 | (st.st_mtime > st.st_atime) ? "new " : ""); |
f570e1ff | 392 | } |
80f91e3f KB |
393 | |
394 | (void)signal(SIGALRM, SIG_DFL); | |
395 | (void)signal(SIGQUIT, SIG_DFL); | |
396 | (void)signal(SIGINT, SIG_DFL); | |
397 | (void)signal(SIGTSTP, SIG_IGN); | |
398 | ||
399 | tbuf[0] = '-'; | |
400 | strcpy(tbuf + 1, (p = rindex(pwd->pw_shell, '/')) ? | |
401 | p + 1 : pwd->pw_shell); | |
0e08a2b3 | 402 | |
3d28f6dd KS |
403 | if (setlogin(pwd->pw_name) < 0) |
404 | syslog(LOG_ERR, "setlogin() failure: %m"); | |
a339b173 | 405 | |
0e08a2b3 KB |
406 | /* discard permissions last so can't get killed and drop core */ |
407 | (void)setuid(pwd->pw_uid); | |
408 | ||
80f91e3f | 409 | execlp(pwd->pw_shell, tbuf, 0); |
0e08a2b3 | 410 | (void)fprintf(stderr, "login: no shell: %s.\n", strerror(errno)); |
88a01c09 BJ |
411 | exit(0); |
412 | } | |
413 | ||
80f91e3f | 414 | getloginname() |
3b8dd95e | 415 | { |
80f91e3f KB |
416 | register int ch; |
417 | register char *p; | |
418 | static char nbuf[UT_NAMESIZE + 1]; | |
3b8dd95e | 419 | |
80f91e3f | 420 | for (;;) { |
0e08a2b3 | 421 | (void)printf("login: "); |
ede75793 | 422 | for (p = nbuf; (ch = getchar()) != '\n'; ) { |
f0c0c252 KB |
423 | if (ch == EOF) { |
424 | badlogin(username); | |
3b8dd95e | 425 | exit(0); |
f0c0c252 | 426 | } |
ede75793 | 427 | if (p < nbuf + UT_NAMESIZE) |
80f91e3f | 428 | *p++ = ch; |
3b8dd95e | 429 | } |
80f91e3f KB |
430 | if (p > nbuf) |
431 | if (nbuf[0] == '-') | |
0e08a2b3 | 432 | (void)fprintf(stderr, |
80f91e3f KB |
433 | "login names may not start with '-'.\n"); |
434 | else { | |
435 | *p = '\0'; | |
436 | username = nbuf; | |
ede75793 | 437 | break; |
80f91e3f | 438 | } |
3b8dd95e | 439 | } |
3b8dd95e SL |
440 | } |
441 | ||
9bcf1061 | 442 | void |
3b8dd95e SL |
443 | timedout() |
444 | { | |
0e08a2b3 | 445 | (void)fprintf(stderr, "Login timed out after %d seconds\n", timeout); |
3b8dd95e SL |
446 | exit(0); |
447 | } | |
448 | ||
659be7fb MK |
449 | rootterm(ttyn) |
450 | char *ttyn; | |
88a01c09 | 451 | { |
80f91e3f | 452 | struct ttyent *t; |
1886582e | 453 | |
659be7fb | 454 | return((t = getttynam(ttyn)) && t->ty_status&TTY_SECURE); |
88a01c09 BJ |
455 | } |
456 | ||
ede75793 KB |
457 | jmp_buf motdinterrupt; |
458 | ||
80f91e3f | 459 | motd() |
f570e1ff | 460 | { |
ede75793 | 461 | register int fd, nchars; |
b32e4ad7 KF |
462 | sig_t oldint; |
463 | int sigint(); | |
ede75793 | 464 | char tbuf[8192]; |
80f91e3f | 465 | |
fb6e7f7e | 466 | if ((fd = open(_PATH_MOTDFILE, O_RDONLY, 0)) < 0) |
80f91e3f KB |
467 | return; |
468 | oldint = signal(SIGINT, sigint); | |
ede75793 KB |
469 | if (setjmp(motdinterrupt) == 0) |
470 | while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0) | |
471 | (void)write(fileno(stdout), tbuf, nchars); | |
80f91e3f | 472 | (void)signal(SIGINT, oldint); |
ede75793 | 473 | (void)close(fd); |
80f91e3f | 474 | } |
9479aa87 | 475 | |
80f91e3f KB |
476 | sigint() |
477 | { | |
ede75793 | 478 | longjmp(motdinterrupt, 1); |
80f91e3f KB |
479 | } |
480 | ||
481 | checknologin() | |
482 | { | |
483 | register int fd, nchars; | |
ede75793 | 484 | char tbuf[8192]; |
80f91e3f | 485 | |
fb6e7f7e | 486 | if ((fd = open(_PATH_NOLOGIN, O_RDONLY, 0)) >= 0) { |
80f91e3f KB |
487 | while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0) |
488 | (void)write(fileno(stdout), tbuf, nchars); | |
489 | sleepexit(0); | |
f570e1ff | 490 | } |
f570e1ff BJ |
491 | } |
492 | ||
f0c0c252 | 493 | dolastlog(quiet) |
80f91e3f | 494 | int quiet; |
88a01c09 | 495 | { |
80f91e3f KB |
496 | struct lastlog ll; |
497 | int fd; | |
c91c86eb | 498 | char *ctime(); |
83cc7253 | 499 | char *ctime(); |
80f91e3f | 500 | |
fb6e7f7e | 501 | if ((fd = open(_PATH_LASTLOG, O_RDWR, 0)) >= 0) { |
ede75793 | 502 | (void)lseek(fd, (off_t)pwd->pw_uid * sizeof(ll), L_SET); |
80f91e3f KB |
503 | if (!quiet) { |
504 | if (read(fd, (char *)&ll, sizeof(ll)) == sizeof(ll) && | |
505 | ll.ll_time != 0) { | |
0e08a2b3 | 506 | (void)printf("Last login: %.*s ", |
80f91e3f KB |
507 | 24-5, (char *)ctime(&ll.ll_time)); |
508 | if (*ll.ll_host != '\0') | |
0e08a2b3 | 509 | (void)printf("from %.*s\n", |
80f91e3f KB |
510 | sizeof(ll.ll_host), ll.ll_host); |
511 | else | |
0e08a2b3 | 512 | (void)printf("on %.*s\n", |
80f91e3f KB |
513 | sizeof(ll.ll_line), ll.ll_line); |
514 | } | |
ede75793 | 515 | (void)lseek(fd, (off_t)pwd->pw_uid * sizeof(ll), L_SET); |
80f91e3f | 516 | } |
9bcf1061 | 517 | bzero((void *)&ll, sizeof(ll)); |
80f91e3f KB |
518 | (void)time(&ll.ll_time); |
519 | strncpy(ll.ll_line, tty, sizeof(ll.ll_line)); | |
a829b33b KB |
520 | if (hostname) |
521 | strncpy(ll.ll_host, hostname, sizeof(ll.ll_host)); | |
80f91e3f KB |
522 | (void)write(fd, (char *)&ll, sizeof(ll)); |
523 | (void)close(fd); | |
88a01c09 | 524 | } |
88a01c09 BJ |
525 | } |
526 | ||
f0c0c252 KB |
527 | badlogin(name) |
528 | char *name; | |
529 | { | |
659be7fb | 530 | if (failures == 0) |
f0c0c252 KB |
531 | return; |
532 | if (hostname) | |
659be7fb MK |
533 | syslog(LOG_NOTICE, "%d LOGIN FAILURE%s FROM %s, %s", |
534 | failures, failures > 1 ? "S" : "", hostname, name); | |
f0c0c252 | 535 | else |
659be7fb MK |
536 | syslog(LOG_NOTICE, "%d LOGIN FAILURE%s ON %s, %s", |
537 | failures, failures > 1 ? "S" : "", tty, name); | |
f0c0c252 KB |
538 | } |
539 | ||
f570e1ff | 540 | #undef UNKNOWN |
80f91e3f | 541 | #define UNKNOWN "su" |
88a01c09 BJ |
542 | |
543 | char * | |
659be7fb MK |
544 | stypeof(ttyid) |
545 | char *ttyid; | |
88a01c09 | 546 | { |
80f91e3f | 547 | struct ttyent *t; |
88a01c09 | 548 | |
659be7fb | 549 | return(ttyid && (t = getttynam(ttyid)) ? t->ty_type : UNKNOWN); |
88a01c09 | 550 | } |
86eb6c9e | 551 | |
80f91e3f KB |
552 | sleepexit(eval) |
553 | int eval; | |
c89291e2 | 554 | { |
80f91e3f KB |
555 | sleep((u_int)5); |
556 | exit(eval); | |
c89291e2 | 557 | } |
d0faf133 KB |
558 | |
559 | doremotelogin(host) | |
560 | char *host; | |
561 | { | |
562 | static char lusername[UT_NAMESIZE+1]; | |
563 | char rusername[UT_NAMESIZE+1]; | |
564 | ||
565 | getstr(rusername, sizeof(rusername), "remuser"); | |
566 | getstr(lusername, sizeof(lusername), "locuser"); | |
567 | getstr(term, sizeof(term), "Terminal type"); | |
568 | username = lusername; | |
569 | pwd = getpwnam(username); | |
570 | if (pwd == NULL) | |
571 | return(-1); | |
572 | return(ruserok(host, (pwd->pw_uid == 0), rusername, username)); | |
573 | } | |
574 | ||
575 | char *speeds[] = { | |
576 | "0", "50", "75", "110", "134", "150", "200", "300", "600", | |
577 | "1200", "1800", "2400", "4800", "9600", "19200", "38400", | |
578 | }; | |
579 | #define NSPEEDS (sizeof(speeds) / sizeof(speeds[0])) | |
580 | ||
581 | doremoteterm(tp) | |
582 | struct sgttyb *tp; | |
583 | { | |
584 | register char *cp = index(term, '/'), **cpp; | |
585 | char *speed; | |
586 | ||
587 | if (cp) { | |
588 | *cp++ = '\0'; | |
589 | speed = cp; | |
590 | cp = index(speed, '/'); | |
591 | if (cp) | |
592 | *cp++ = '\0'; | |
593 | for (cpp = speeds; cpp < &speeds[NSPEEDS]; cpp++) | |
594 | if (strcmp(*cpp, speed) == 0) { | |
595 | tp->sg_ispeed = tp->sg_ospeed = cpp-speeds; | |
596 | break; | |
597 | } | |
598 | } | |
599 | tp->sg_flags = ECHO|CRMOD|ANYP|XTABS; | |
600 | } |