static char *sccsid = "@(#)login.c.1 4.11 (Berkeley) 81/07/05";
#define SCPYN(a, b) strncpy(a, b, sizeof(a))
#define NMAX sizeof(utmp.ut_name)
#define LMAX sizeof(utmp.ut_line)
char nolog[] = "/etc/nologin";
char qlog[] = ".hushlogin";
char securetty[] = "/etc/securetty";
char maildir[30] = "/usr/spool/mail/";
char lastlog[] = "/usr/adm/lastlog";
struct passwd nouser = {"", "nope"};
char homedir[64] = "HOME=";
char shell[64] = "SHELL=";
char *envinit[] = {homedir, shell, "PATH=:/usr/ucb:/bin:/usr/bin", term, user, 0};
struct passwd *getpwnam();
#define CTRL(c) ('c'&037)
#define CQUIT 034 /* FS, cntl shift L */
#define CINTR 0177 /* DEL */
CINTR, CQUIT, CSTART, CSTOP, CEOT, CBRK
CTRL(z), CTRL(y), CTRL(r), CTRL(o), CTRL(w), CTRL(v)
signal(SIGQUIT, SIG_IGN);
ioctl(0, TIOCSLTC, <c);
ioctl(0, TIOCSETD, &ldisc);
SCPYN(utmp.ut_name, argv[1]);
while (utmp.ut_name[0] == '\0') {
printf("%s login: ", uts.nodename);
while ((c = getchar()) != '\n') {
if (namep < utmp.ut_name+NMAX)
if ((pwd = getpwnam(utmp.ut_name)) == NULL)
if (!strcmp(pwd->pw_shell, "/bin/csh")) {
ioctl(0, TIOCSETD, &ldisc);
if (*pwd->pw_passwd != '\0') {
namep = crypt(getpass("Password:"),pwd->pw_passwd);
if (strcmp(namep, pwd->pw_passwd))
if (pwd->pw_uid != 0 && (nlfd = fopen(nolog, "r")) > 0) {
/* logins are disabled except for root */
while ((c = getc(nlfd)) != EOF)
if (!invalid && pwd->pw_uid == 0 &&
!rootterm(ttyn+sizeof("/dev/")-1)) {
FILE *console = fopen("/dev/console", "w");
fprintf(console, "\r\nROOT LOGIN REFUSED %s\r\n"
printf("Login incorrect\n");
if (ttyn[sizeof("/dev/tty")-1] == 'd') {
FILE *console = fopen("/dev/console", "w");
fprintf(console, "\r\nBADDIALUP %s %s\r\n"
if (*pwd->pw_shell == '\0')
pwd->pw_shell = "/bin/sh";
i = strlen(pwd->pw_shell);
if (chdir(pwd->pw_dir) < 0 && !invalid ) {
printf("No directory!\n");
printf("No directory! Logging in with home=/\n");
if (t>0 && (f = open("/etc/utmp", 1)) >= 0) {
lseek(f, (long)(t*sizeof(utmp)), 0);
SCPYN(utmp.ut_line, rindex(ttyn, '/')+1);
write(f, (char *)&utmp, sizeof(utmp));
if (t>0 && (f = open("/usr/adm/wtmp", 1)) >= 0) {
write(f, (char *)&utmp, sizeof(utmp));
if (access(qlog, 0) == 0)
if ( !quietlog && (f = open(lastlog, 2)) >= 0 ) {
lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
if (read(f, (char *) &ll, sizeof ll) == sizeof ll &&
printf("Last login: %.*s on %.*s\n"
, (char *) ctime(&ll.ll_time)
lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
SCPYN(ll.ll_line, rindex(ttyn, '/')+1);
write(f, (char *) &ll, sizeof ll);
chown(ttyn, pwd->pw_uid, pwd->pw_gid);
strncat(homedir, pwd->pw_dir, sizeof(homedir)-6);
strncat(shell, pwd->pw_shell, sizeof(shell)-7);
strncat(term, stypeof(ttyn), sizeof(term)-6);
strncat(user, pwd->pw_name, sizeof(user)-6);
if ((namep = rindex(pwd->pw_shell, '/')) == NULL)
if (pwd->pw_gid == 27) /* UGLY ! */
if (ttyn[sizeof("/dev/tty")-1] == 'd') {
FILE *console = fopen("/dev/console", "w");
fprintf(console, "\r\nDIALUP %s %s\r\n"
strcat(maildir, pwd->pw_name);
if (access(maildir,4)==0) {
printf("You have mail.\n");
signal(SIGQUIT, SIG_DFL);
signal(SIGTSTP, SIG_IGN);
execlp(pwd->pw_shell, minusnam, 0);
* return true if OK for root to login on this terminal
if ((fd = fopen(securetty, "r")) == NULL)
while (fgets(buf, sizeof buf, fd) != NULL) {
buf[strlen(buf)-1] = '\0';
if (strcmp(tty, buf) == 0) {
if ((mf = fopen("/etc/motd","r")) != NULL) {
while ((c = getc(mf)) != EOF && stopmotd == 0)
register char *p, *t, *q;
f = fopen("/etc/ttytype", "r");
/* split off end of name */
for (p = q = ttyid; *p != 0; p++)
while (fgets(buf, sizeof buf, f) != NULL)
for (t=buf; *t!=' ' && *t != '\t'; t++)
while (*t == ' ' || *t == '\t')