+ invalid = FALSE;
+ SCPYN(utmp.ut_name, "");
+ if (argc>1) {
+ SCPYN(utmp.ut_name, argv[1]);
+ argc = 0;
+ }
+ if (rflag)
+ strcpy(utmp.ut_name, lusername);
+ else
+ while (utmp.ut_name[0] == '\0') {
+ namep = utmp.ut_name;
+ { char hostname[32];
+ gethostname(hostname, sizeof (hostname));
+ printf("%s login: ", hostname); }
+ while ((c = getchar()) != '\n') {
+ if (c == ' ')
+ c = '_';
+ if (c == EOF)
+ exit(0);
+ if (namep < utmp.ut_name+NMAX)
+ *namep++ = c;
+ }
+ }
+ if (rhost == 0) {
+ setpwent();
+ if ((pwd = getpwnam(utmp.ut_name)) == NULL)
+ pwd = &nouser;
+ endpwent();
+ }
+ if (!strcmp(pwd->pw_shell, "/bin/csh")) {
+ ldisc = NTTYDISC;
+ ioctl(0, TIOCSETD, &ldisc);
+ }
+ if (rhost == 0) {
+ if (*pwd->pw_passwd != '\0') {
+ char *pp;
+ nice(-4);
+ if (rflag == 0)
+ pp = getpass("Password:");
+ else
+ pp = rpassword;
+ namep = crypt(pp,pwd->pw_passwd);
+ nice(4);
+ if (strcmp(namep, pwd->pw_passwd))
+ invalid = TRUE;
+ }
+ }
+ if (pwd->pw_uid != 0 && (nlfd = fopen(nolog, "r")) > 0) {
+ /* logins are disabled except for root */
+ while ((c = getc(nlfd)) != EOF)
+ putchar(c);
+ fflush(stdout);
+ sleep(5);
+ exit(0);
+ }
+ if (!invalid && pwd->pw_uid == 0 &&
+ !rootterm(ttyn+sizeof("/dev/")-1)) {
+ FILE *console = fopen("/dev/console", "w");
+ if (console != NULL) {
+ fprintf(console, "\r\nROOT LOGIN REFUSED %s\r\n"
+ , ttyn+sizeof("/dev/")-1
+ );
+ fclose(console);
+ }
+ invalid = TRUE;
+ }
+ if (invalid) {