for marc; hushlogin for password expiration and Kerberos messages
[unix-history] / usr / src / usr.bin / login / login.c
CommitLineData
bcf1365c 1/*
ede75793
KB
2 * Copyright (c) 1980, 1987, 1988 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
bcf1365c
DF
16 */
17
18#ifndef lint
19char copyright[] =
ede75793 20"@(#) Copyright (c) 1980, 1987, 1988 The Regents of the University of California.\n\
bcf1365c 21 All rights reserved.\n";
ede75793 22#endif /* not lint */
bcf1365c 23
22d4760e 24#ifndef lint
6fb89ef9 25static char sccsid[] = "@(#)login.c 5.37 (Berkeley) %G%";
ede75793 26#endif /* not lint */
22d4760e 27
88a01c09
BJ
28/*
29 * login [ name ]
5dbe2745
MK
30 * login -h hostname (for telnetd, etc.)
31 * login -f name (for pre-authenticated login: datakit, xterm, etc.)
88a01c09
BJ
32 */
33
7a625b73 34#include <sys/param.h>
3b8dd95e
SL
35#include <sys/quota.h>
36#include <sys/stat.h>
37#include <sys/time.h>
38#include <sys/resource.h>
9479aa87 39#include <sys/file.h>
80f91e3f 40#include <sys/ioctl.h>
3b8dd95e 41
88a01c09
BJ
42#include <utmp.h>
43#include <signal.h>
88a01c09 44#include <lastlog.h>
22d4760e 45#include <errno.h>
9479aa87
BJ
46#include <ttyent.h>
47#include <syslog.h>
c89291e2 48#include <grp.h>
80f91e3f 49#include <pwd.h>
ede75793 50#include <setjmp.h>
80f91e3f
KB
51#include <stdio.h>
52#include <strings.h>
fb6e7f7e 53#include "pathnames.h"
c89291e2 54
80f91e3f 55#define TTYGRPNAME "tty" /* name of group to own ttys */
88a01c09 56
3b8dd95e 57/*
80f91e3f
KB
58 * This bounds the time given to login. Not a define so it can
59 * be patched on machines where it's too small.
3b8dd95e 60 */
a9b031fe 61int timeout = 300;
86eb6c9e 62
659be7fb
MK
63struct passwd *pwd;
64int failures;
65char term[64], *hostname, *username, *tty;
88a01c09 66
659be7fb
MK
67struct sgttyb sgttyb;
68struct tchars tc = {
714accc5
SL
69 CINTR, CQUIT, CSTART, CSTOP, CEOT, CBRK
70};
659be7fb 71struct ltchars ltc = {
714accc5 72 CSUSP, CDSUSP, CRPRNT, CFLUSH, CWERASE, CLNEXT
841d84b0
BJ
73};
74
83cc7253
KB
75char *months[] =
76 { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
77 "Sep", "Oct", "Nov", "Dec" };
78
c91c86eb
KB
79char *months[] =
80 { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
81 "Sep", "Oct", "Nov", "Dec" };
82
88a01c09 83main(argc, argv)
80f91e3f
KB
84 int argc;
85 char **argv;
88a01c09 86{
80f91e3f
KB
87 extern int errno, optind;
88 extern char *optarg, **environ;
c91c86eb
KB
89 struct timeval tp;
90 struct tm *ttp;
83cc7253
KB
91 struct timeval tp;
92 struct tm *ttp;
80f91e3f
KB
93 struct group *gr;
94 register int ch;
659be7fb 95 register char *p;
f0c0c252 96 int ask, fflag, hflag, pflag, cnt;
80f91e3f 97 int quietlog, passwd_req, ioctlval, timedout();
659be7fb 98 char *domain, *salt, *envinit[1], *ttyn, *pp;
80f91e3f 99 char tbuf[MAXPATHLEN + 2];
c91c86eb 100 char *ctime(), *ttyname(), *stypeof(), *crypt(), *getpass();
80f91e3f
KB
101 time_t time();
102 off_t lseek();
103
104 (void)signal(SIGALRM, timedout);
105 (void)alarm((u_int)timeout);
106 (void)signal(SIGQUIT, SIG_IGN);
107 (void)signal(SIGINT, SIG_IGN);
108 (void)setpriority(PRIO_PROCESS, 0, 0);
109 (void)quota(Q_SETUID, 0, 0, 0);
110
3b8dd95e 111 /*
d3737d51 112 * -p is used by getty to tell login not to destroy the environment
5dbe2745 113 * -f is used to skip a second login authentication
ee1eff74
MK
114 * -h is used by other servers to pass the name of the remote
115 * host to login so that it may be placed in utmp and wtmp
3b8dd95e 116 */
80f91e3f
KB
117 (void)gethostname(tbuf, sizeof(tbuf));
118 domain = index(tbuf, '.');
119
ee1eff74 120 fflag = hflag = pflag = 0;
80f91e3f 121 passwd_req = 1;
ee1eff74 122 while ((ch = getopt(argc, argv, "fh:p")) != EOF)
ede75793 123 switch (ch) {
80f91e3f 124 case 'f':
80f91e3f 125 fflag = 1;
80f91e3f
KB
126 break;
127 case 'h':
128 if (getuid()) {
129 fprintf(stderr,
130 "login: -h for super-user only.\n");
b6f7cade 131 exit(1);
5dbe2745 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;
80f91e3f
KB
142 case '?':
143 default:
ede75793 144 fprintf(stderr, "usage: login [-fp] [username]\n");
80f91e3f 145 exit(1);
d3737d51 146 }
80f91e3f
KB
147 argc -= optind;
148 argv += optind;
f0c0c252 149 if (*argv) {
80f91e3f 150 username = *argv;
659be7fb
MK
151 ask = 0;
152 } else
f0c0c252 153 ask = 1;
80f91e3f
KB
154
155 ioctlval = 0;
156 (void)ioctl(0, TIOCLSET, &ioctlval);
157 (void)ioctl(0, TIOCNXCL, 0);
ede75793
KB
158 (void)fcntl(0, F_SETFL, ioctlval);
159 (void)ioctl(0, TIOCGETP, &sgttyb);
ede75793
KB
160 sgttyb.sg_erase = CERASE;
161 sgttyb.sg_kill = CKILL;
80f91e3f
KB
162 (void)ioctl(0, TIOCSLTC, &ltc);
163 (void)ioctl(0, TIOCSETC, &tc);
ede75793 164 (void)ioctl(0, TIOCSETP, &sgttyb);
80f91e3f
KB
165
166 for (cnt = getdtablesize(); cnt > 2; cnt--)
167 close(cnt);
168
88a01c09 169 ttyn = ttyname(0);
80f91e3f 170 if (ttyn == NULL || *ttyn == '\0')
88a01c09 171 ttyn = "/dev/tty??";
80f91e3f
KB
172 if (tty = rindex(ttyn, '/'))
173 ++tty;
9479aa87 174 else
80f91e3f
KB
175 tty = ttyn;
176
076ae92c 177 openlog("login", LOG_ODELAY, LOG_AUTH);
80f91e3f 178
f0c0c252 179 for (cnt = 0;; ask = 1) {
80f91e3f
KB
180 ioctlval = 0;
181 (void)ioctl(0, TIOCSETD, &ioctlval);
182
f0c0c252 183 if (ask) {
ede75793 184 fflag = 0;
80f91e3f 185 getloginname();
ede75793 186 }
659be7fb
MK
187 /*
188 * Note if trying multiple user names;
189 * log failures for previous user name,
190 * but don't bother logging one failure
191 * for nonexistent name (mistyped username).
192 */
193 if (failures && strcmp(tbuf, username)) {
194 if (failures > (pwd ? 0 : 1))
f0c0c252 195 badlogin(tbuf);
659be7fb 196 failures = 0;
f0c0c252 197 }
659be7fb 198 (void)strcpy(tbuf, username);
ede75793
KB
199 if (pwd = getpwnam(username))
200 salt = pwd->pw_passwd;
201 else
202 salt = "xx";
80f91e3f
KB
203
204 /* if user not super-user, check for disabled logins */
ede75793 205 if (pwd == NULL || pwd->pw_uid)
80f91e3f
KB
206 checknologin();
207
3b8dd95e 208 /*
ede75793
KB
209 * Disallow automatic login to root; if not invoked by
210 * root, disallow if the uid's differ.
3b8dd95e 211 */
ede75793 212 if (fflag && pwd) {
5dbe2745
MK
213 int uid = getuid();
214
ede75793
KB
215 passwd_req = pwd->pw_uid == 0 ||
216 (uid && uid != pwd->pw_uid);
f570e1ff 217 }
80f91e3f 218
3b8dd95e 219 /*
ee1eff74 220 * If no pre-authentication and a password exists
80f91e3f 221 * for this user, prompt for one and verify it.
3b8dd95e 222 */
9d6a5a69 223 if (!passwd_req || (pwd && !*pwd->pw_passwd))
80f91e3f
KB
224 break;
225
226 setpriority(PRIO_PROCESS, 0, -4);
9d6a5a69
KF
227 pp = getpass("Password:");
228 p = crypt(pp, salt);
80f91e3f 229 setpriority(PRIO_PROCESS, 0, 0);
9d6a5a69 230
9d6a5a69 231 (void) bzero(pp, strlen(pp));
ede75793 232 if (pwd && !strcmp(p, pwd->pw_passwd))
80f91e3f
KB
233 break;
234
235 printf("Login incorrect\n");
659be7fb 236 failures++;
f0c0c252
KB
237 /* we allow 10 tries, but after 3 we start backing off */
238 if (++cnt > 3) {
239 if (cnt >= 10) {
240 badlogin(username);
241 (void)ioctl(0, TIOCHPCL, (struct sgttyb *)NULL);
242 sleepexit(1);
243 }
244 sleep((u_int)((cnt - 3) * 5));
f570e1ff 245 }
80f91e3f 246 }
88a01c09 247
80f91e3f
KB
248 /* committed to login -- turn off timeout */
249 (void)alarm((u_int)0);
250
251 /*
252 * If valid so far and root is logging in, see if root logins on
253 * this terminal are permitted.
254 */
659be7fb 255 if (pwd->pw_uid == 0 && !rootterm(tty)) {
80f91e3f 256 if (hostname)
659be7fb
MK
257 syslog(LOG_NOTICE, "ROOT LOGIN REFUSED FROM %s",
258 hostname);
22d4760e 259 else
659be7fb 260 syslog(LOG_NOTICE, "ROOT LOGIN REFUSED ON %s", tty);
80f91e3f
KB
261 printf("Login incorrect\n");
262 sleepexit(1);
22d4760e 263 }
80f91e3f 264
80f91e3f
KB
265 if (quota(Q_SETUID, pwd->pw_uid, 0, 0) < 0 && errno != EINVAL) {
266 switch(errno) {
267 case EUSERS:
268 fprintf(stderr,
269 "Too many users logged on already.\nTry again later.\n");
270 break;
271 case EPROCLIM:
272 fprintf(stderr,
273 "You have too many processes running.\n");
274 break;
275 default:
276 perror("quota (Q_SETUID)");
f570e1ff 277 }
80f91e3f
KB
278 sleepexit(0);
279 }
280
ede75793
KB
281 if (chdir(pwd->pw_dir) < 0) {
282 printf("No directory %s!\n", pwd->pw_dir);
283 if (chdir("/"))
284 exit(0);
285 pwd->pw_dir = "/";
286 printf("Logging in with home = \"/\".\n");
287 }
288
83cc7253
KB
289#define TWOWEEKS (14*24*60*60)
290 if (pwd->pw_change || pwd->pw_expire)
291 (void)gettimeofday(&tp, (struct timezone *)NULL);
292 if (pwd->pw_change)
293 if (tp.tv_sec >= pwd->pw_change) {
294 printf("Sorry -- your password has expired.\n");
295 sleepexit(1);
296 }
297 else if (tp.tv_sec - pwd->pw_change < TWOWEEKS) {
298 ttp = localtime(&pwd->pw_change);
299 printf("Warning: your password expires on %s %d, 19%d\n",
300 months[ttp->tm_mon], ttp->tm_mday, ttp->tm_year);
301 }
302 if (pwd->pw_expire)
303 if (tp.tv_sec >= pwd->pw_expire) {
304 printf("Sorry -- your account has expired.\n");
305 sleepexit(1);
306 }
307 else if (tp.tv_sec - pwd->pw_expire < TWOWEEKS) {
308 ttp = localtime(&pwd->pw_expire);
309 printf("Warning: your account expires on %s %d, 19%d\n",
310 months[ttp->tm_mon], ttp->tm_mday, ttp->tm_year);
311 }
312
c91c86eb
KB
313#define TWOWEEKS (14*24*60*60)
314 if (pwd->pw_change || pwd->pw_expire)
315 (void)gettimeofday(&tp, (struct timezone *)NULL);
316 if (pwd->pw_change)
317 if (tp.tv_sec >= pwd->pw_change) {
318 printf("Sorry -- your password has expired.\n");
319 sleepexit(1);
320 }
6fb89ef9 321 else if (tp.tv_sec - pwd->pw_change < TWOWEEKS && !quietlog) {
c91c86eb
KB
322 ttp = localtime(&pwd->pw_change);
323 printf("Warning: your password expires on %s %d, 19%d\n",
324 months[ttp->tm_mon], ttp->tm_mday, ttp->tm_year);
325 }
326 if (pwd->pw_expire)
327 if (tp.tv_sec >= pwd->pw_expire) {
328 printf("Sorry -- your account has expired.\n");
329 sleepexit(1);
330 }
6fb89ef9 331 else if (tp.tv_sec - pwd->pw_expire < TWOWEEKS && !quietlog) {
c91c86eb
KB
332 ttp = localtime(&pwd->pw_expire);
333 printf("Warning: your account expires on %s %d, 19%d\n",
334 months[ttp->tm_mon], ttp->tm_mday, ttp->tm_year);
335 }
336
ede75793 337 /* nothing else left to fail -- really log in */
80f91e3f
KB
338 {
339 struct utmp utmp;
340
659be7fb 341 bzero((char *)&utmp, sizeof(utmp));
80f91e3f
KB
342 (void)time(&utmp.ut_time);
343 strncpy(utmp.ut_name, username, sizeof(utmp.ut_name));
a829b33b
KB
344 if (hostname)
345 strncpy(utmp.ut_host, hostname, sizeof(utmp.ut_host));
80f91e3f
KB
346 strncpy(utmp.ut_line, tty, sizeof(utmp.ut_line));
347 login(&utmp);
f570e1ff 348 }
80f91e3f 349
f0c0c252 350 dolastlog(quietlog);
80f91e3f 351
ee1eff74 352 if (!hflag) { /* XXX */
80f91e3f
KB
353 static struct winsize win = { 0, 0, 0, 0 };
354
355 (void)ioctl(0, TIOCSWINSZ, &win);
356 }
357
358 (void)chown(ttyn, pwd->pw_uid,
359 (gr = getgrnam(TTYGRPNAME)) ? gr->gr_gid : pwd->pw_gid);
360 (void)chmod(ttyn, 0620);
361 (void)setgid(pwd->pw_gid);
362
363 initgroups(username, pwd->pw_gid);
364
22d4760e 365 quota(Q_DOWARN, pwd->pw_uid, (dev_t)-1, 0);
80f91e3f 366 (void)setuid(pwd->pw_uid);
3daca631 367
ede75793 368 if (*pwd->pw_shell == '\0')
fb6e7f7e 369 pwd->pw_shell = _PATH_BSHELL;
ede75793 370 /* turn on new line discipline for the csh */
9a448eee 371 else if (!strcmp(pwd->pw_shell, _PATH_CSHELL)) {
ede75793
KB
372 ioctlval = NTTYDISC;
373 (void)ioctl(0, TIOCSETD, &ioctlval);
374 }
375
80f91e3f 376 /* destroy environment unless user has requested preservation */
d3737d51
SL
377 if (!pflag)
378 environ = envinit;
ede75793
KB
379 (void)setenv("HOME", pwd->pw_dir, 1);
380 (void)setenv("SHELL", pwd->pw_shell, 1);
d3737d51 381 if (term[0] == '\0')
659be7fb 382 strncpy(term, stypeof(tty), sizeof(term));
ede75793
KB
383 (void)setenv("TERM", term, 0);
384 (void)setenv("USER", pwd->pw_name, 1);
385 (void)setenv("PATH", "/usr/ucb:/bin:/usr/bin:", 0);
d3737d51 386
9479aa87 387 if (tty[sizeof("tty")-1] == 'd')
d3737d51
SL
388 syslog(LOG_INFO, "DIALUP %s, %s", tty, pwd->pw_name);
389 if (pwd->pw_uid == 0)
80f91e3f 390 if (hostname)
659be7fb 391 syslog(LOG_NOTICE, "ROOT LOGIN ON %s FROM %s",
f0c0c252 392 tty, hostname);
df9d9536 393 else
659be7fb 394 syslog(LOG_NOTICE, "ROOT LOGIN ON %s", tty);
80f91e3f 395
4f8d3876 396 if (!quietlog) {
6821e9c5 397 struct stat st;
d3737d51 398
80f91e3f 399 motd();
fb6e7f7e 400 (void)sprintf(tbuf, "%s/%s", _PATH_MAILDIR, pwd->pw_name);
80f91e3f 401 if (stat(tbuf, &st) == 0 && st.st_size != 0)
6821e9c5 402 printf("You have %smail.\n",
80f91e3f 403 (st.st_mtime > st.st_atime) ? "new " : "");
f570e1ff 404 }
80f91e3f
KB
405
406 (void)signal(SIGALRM, SIG_DFL);
407 (void)signal(SIGQUIT, SIG_DFL);
408 (void)signal(SIGINT, SIG_DFL);
409 (void)signal(SIGTSTP, SIG_IGN);
410
411 tbuf[0] = '-';
412 strcpy(tbuf + 1, (p = rindex(pwd->pw_shell, '/')) ?
413 p + 1 : pwd->pw_shell);
414 execlp(pwd->pw_shell, tbuf, 0);
ede75793 415 fprintf(stderr, "login: no shell: ");
f570e1ff 416 perror(pwd->pw_shell);
88a01c09
BJ
417 exit(0);
418}
419
80f91e3f 420getloginname()
3b8dd95e 421{
80f91e3f
KB
422 register int ch;
423 register char *p;
424 static char nbuf[UT_NAMESIZE + 1];
3b8dd95e 425
80f91e3f 426 for (;;) {
5a786176 427 printf("login: ");
ede75793 428 for (p = nbuf; (ch = getchar()) != '\n'; ) {
f0c0c252
KB
429 if (ch == EOF) {
430 badlogin(username);
3b8dd95e 431 exit(0);
f0c0c252 432 }
ede75793 433 if (p < nbuf + UT_NAMESIZE)
80f91e3f 434 *p++ = ch;
3b8dd95e 435 }
80f91e3f
KB
436 if (p > nbuf)
437 if (nbuf[0] == '-')
438 fprintf(stderr,
439 "login names may not start with '-'.\n");
440 else {
441 *p = '\0';
442 username = nbuf;
ede75793 443 break;
80f91e3f 444 }
3b8dd95e 445 }
3b8dd95e
SL
446}
447
448timedout()
449{
80f91e3f 450 fprintf(stderr, "Login timed out after %d seconds\n", timeout);
3b8dd95e
SL
451 exit(0);
452}
453
659be7fb
MK
454rootterm(ttyn)
455 char *ttyn;
88a01c09 456{
80f91e3f 457 struct ttyent *t;
1886582e 458
659be7fb 459 return((t = getttynam(ttyn)) && t->ty_status&TTY_SECURE);
88a01c09
BJ
460}
461
ede75793
KB
462jmp_buf motdinterrupt;
463
80f91e3f 464motd()
f570e1ff 465{
ede75793 466 register int fd, nchars;
80f91e3f 467 int (*oldint)(), sigint();
ede75793 468 char tbuf[8192];
80f91e3f 469
fb6e7f7e 470 if ((fd = open(_PATH_MOTDFILE, O_RDONLY, 0)) < 0)
80f91e3f
KB
471 return;
472 oldint = signal(SIGINT, sigint);
ede75793
KB
473 if (setjmp(motdinterrupt) == 0)
474 while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0)
475 (void)write(fileno(stdout), tbuf, nchars);
80f91e3f 476 (void)signal(SIGINT, oldint);
ede75793 477 (void)close(fd);
80f91e3f 478}
9479aa87 479
80f91e3f
KB
480sigint()
481{
ede75793 482 longjmp(motdinterrupt, 1);
80f91e3f
KB
483}
484
485checknologin()
486{
487 register int fd, nchars;
ede75793 488 char tbuf[8192];
80f91e3f 489
fb6e7f7e 490 if ((fd = open(_PATH_NOLOGIN, O_RDONLY, 0)) >= 0) {
80f91e3f
KB
491 while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0)
492 (void)write(fileno(stdout), tbuf, nchars);
493 sleepexit(0);
f570e1ff 494 }
f570e1ff
BJ
495}
496
f0c0c252 497dolastlog(quiet)
80f91e3f 498 int quiet;
88a01c09 499{
80f91e3f
KB
500 struct lastlog ll;
501 int fd;
c91c86eb 502 char *ctime();
83cc7253 503 char *ctime();
80f91e3f 504
fb6e7f7e 505 if ((fd = open(_PATH_LASTLOG, O_RDWR, 0)) >= 0) {
ede75793 506 (void)lseek(fd, (off_t)pwd->pw_uid * sizeof(ll), L_SET);
80f91e3f
KB
507 if (!quiet) {
508 if (read(fd, (char *)&ll, sizeof(ll)) == sizeof(ll) &&
509 ll.ll_time != 0) {
510 printf("Last login: %.*s ",
511 24-5, (char *)ctime(&ll.ll_time));
512 if (*ll.ll_host != '\0')
513 printf("from %.*s\n",
514 sizeof(ll.ll_host), ll.ll_host);
515 else
516 printf("on %.*s\n",
517 sizeof(ll.ll_line), ll.ll_line);
518 }
ede75793 519 (void)lseek(fd, (off_t)pwd->pw_uid * sizeof(ll), L_SET);
80f91e3f 520 }
659be7fb 521 bzero((char *)&ll, sizeof(ll));
80f91e3f
KB
522 (void)time(&ll.ll_time);
523 strncpy(ll.ll_line, tty, sizeof(ll.ll_line));
a829b33b
KB
524 if (hostname)
525 strncpy(ll.ll_host, hostname, sizeof(ll.ll_host));
80f91e3f
KB
526 (void)write(fd, (char *)&ll, sizeof(ll));
527 (void)close(fd);
88a01c09 528 }
88a01c09
BJ
529}
530
f0c0c252
KB
531badlogin(name)
532 char *name;
533{
659be7fb 534 if (failures == 0)
f0c0c252
KB
535 return;
536 if (hostname)
659be7fb
MK
537 syslog(LOG_NOTICE, "%d LOGIN FAILURE%s FROM %s, %s",
538 failures, failures > 1 ? "S" : "", hostname, name);
f0c0c252 539 else
659be7fb
MK
540 syslog(LOG_NOTICE, "%d LOGIN FAILURE%s ON %s, %s",
541 failures, failures > 1 ? "S" : "", tty, name);
f0c0c252
KB
542}
543
f570e1ff 544#undef UNKNOWN
80f91e3f 545#define UNKNOWN "su"
88a01c09
BJ
546
547char *
659be7fb
MK
548stypeof(ttyid)
549 char *ttyid;
88a01c09 550{
80f91e3f 551 struct ttyent *t;
88a01c09 552
659be7fb 553 return(ttyid && (t = getttynam(ttyid)) ? t->ty_type : UNKNOWN);
88a01c09 554}
86eb6c9e
BJ
555
556getstr(buf, cnt, err)
80f91e3f 557 char *buf, *err;
86eb6c9e 558 int cnt;
86eb6c9e 559{
80f91e3f 560 char ch;
86eb6c9e
BJ
561
562 do {
80f91e3f 563 if (read(0, &ch, sizeof(ch)) != sizeof(ch))
86eb6c9e
BJ
564 exit(1);
565 if (--cnt < 0) {
80f91e3f
KB
566 fprintf(stderr, "%s too long\r\n", err);
567 sleepexit(1);
86eb6c9e 568 }
80f91e3f
KB
569 *buf++ = ch;
570 } while (ch);
86eb6c9e 571}
4f8d3876 572
80f91e3f
KB
573sleepexit(eval)
574 int eval;
c89291e2 575{
80f91e3f
KB
576 sleep((u_int)5);
577 exit(eval);
c89291e2 578}