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