- register char *namep;
- int t, f, c;
- int invalid;
- int quietlog;
- int i;
- FILE *nlfd;
- char *ttyn;
- int ldisc = 0, zero = 0;
- FILE *hostf; int first = 1;
-
- alarm(60);
- signal(SIGQUIT, SIG_IGN);
- signal(SIGINT, SIG_IGN);
- nice(-100);
- nice(20);
- nice(0);
- if (argc > 0 && !strcmp(argv[1], "-r")) {
- rflag++;
- if (argc > 1)
- rhost = argv[2];
- argc = 1;
- if (rhost) {
- getstr(rusername, sizeof (rusername), "remuser");
- getstr(lusername, sizeof (lusername), "locuser");
- } else {
- getstr(lusername, sizeof (lusername), "Username");
- getstr(rpassword, sizeof (rpassword), "Password");
- }
- getstr(term+5, sizeof(term)-5, "Terminal type");
- if (rhost == 0)
- goto normal;
- if (getuid()) {
- rflag = 0;
- goto normal;
- }
- setpwent();
- pwd = getpwnam(lusername);
- if (pwd == NULL) {
- fprintf(stderr, "Login incorrect.\n");
+ extern int errno, optind;
+ extern char *optarg, **environ;
+ struct group *gr;
+ register int ch;
+ register char *p;
+ int ask, fflag, hflag, pflag, cnt;
+ int quietlog, passwd_req, ioctlval, timedout();
+ char *domain, *salt, *envinit[1], *ttyn;
+ char tbuf[MAXPATHLEN + 2];
+ char *ttyname(), *stypeof(), *crypt(), *getpass();
+ time_t time();
+ off_t lseek();
+
+ (void)signal(SIGALRM, timedout);
+ (void)alarm((u_int)timeout);
+ (void)signal(SIGQUIT, SIG_IGN);
+ (void)signal(SIGINT, SIG_IGN);
+ (void)setpriority(PRIO_PROCESS, 0, 0);
+ (void)quota(Q_SETUID, 0, 0, 0);
+
+ /*
+ * -p is used by getty to tell login not to destroy the environment
+ * -f is used to skip a second login authentication
+ * -h is used by other servers to pass the name of the remote
+ * host to login so that it may be placed in utmp and wtmp
+ */
+ (void)gethostname(tbuf, sizeof(tbuf));
+ domain = index(tbuf, '.');
+
+ fflag = hflag = pflag = 0;
+ passwd_req = 1;
+ while ((ch = getopt(argc, argv, "fh:p")) != EOF)
+ switch (ch) {
+ case 'f':
+ fflag = 1;
+ break;
+ case 'h':
+ if (getuid()) {
+ fprintf(stderr,
+ "login: -h for super-user only.\n");
+ exit(1);
+ }
+ hflag = 1;
+ if (domain && (p = index(optarg, '.')) &&
+ strcasecmp(p, domain) == 0)
+ *p = 0;
+ hostname = optarg;
+ break;
+ case 'p':
+ pflag = 1;
+ break;
+ case '?':
+ default:
+ fprintf(stderr, "usage: login [-fp] [username]\n");