static char *sccsid
= "@(#)login.c 4.17 82/05/19";
#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=";
{ "0", "50", "75", "110", "134", "150", "200", "300",
"600", "1200", "1800", "2400", "4800", "9600", "19200", "38400" };
#define NSPEEDS (sizeof (speeds) / sizeof (speeds[0]))
{homedir
, shell
, "PATH=:/usr/ucb:/bin:/usr/bin", term
, user
, 0};
struct passwd
*getpwnam();
char *strcat(), *rindex(), *index();
#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
)
char rusername
[NMAX
+1], lusername
[NMAX
+1];
FILE *hostf
; int first
= 1;
signal(SIGQUIT
, SIG_IGN
);
if (argc
> 1 && !strcmp(argv
[1], "-r")) {
getstr(rusername
, sizeof (rusername
), "remuser");
getstr(lusername
, sizeof (lusername
), "locuser");
getstr(term
+5, sizeof(term
)-5, "Terminal type");
pwd
= getpwnam(lusername
);
if (strcmp(rusername
, lusername
))
printf("%s: No such user\r\n", lusername
);
hostf
= pwd
->pw_uid
? fopen("/etc/hosts.equiv", "r") : 0;
while (fgets(ahost
, sizeof (ahost
), hostf
)) {
user
= index(ahost
, ' ');
if (!strcmp(rhost
, ahost
) &&
!strcmp(rusername
, user
? user
: lusername
)) {
if (chdir(pwd
->pw_dir
) < 0)
hostf
= fopen(".rhosts", "r");
ioctl(0, TIOCLSET
, &zero
);
ioctl(0, FIONBIO
, &zero
);
ioctl(0, FIOASYNC
, &zero
);
char *cp
= index(term
, '/');
for (i
= 0; i
< NSPEEDS
; i
++)
if (!strcmp(speeds
[i
], cp
)) {
ttyb
.sg_ispeed
= ttyb
.sg_ospeed
= i
;
ttyb
.sg_flags
= ECHO
|CRMOD
|ANYP
|XTABS
;
ioctl(0, TIOCSLTC
, <c
);
ioctl(0, TIOCSETD
, &ldisc
);
SCPYN(utmp
.ut_name
, argv
[1]);
strcpy(utmp
.ut_name
, lusername
);
while (utmp
.ut_name
[0] == '\0') {
gethostname(hostname
, sizeof (hostname
));
printf("%s login: ", hostname
); }
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') {
pp
= getpass("Password:");
namep
= crypt(pp
,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)) {
logerr("ROOT LOGIN REFUSED %s",
printf("Login incorrect\n");
if (ttyn
[sizeof("/dev/tty")-1] == 'd')
logerr("BADDIALUP %s %s\n",
ttyn
+sizeof("/dev/")-1, utmp
.ut_name
);
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 ((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
);
strncpy(name
, utmp
.ut_name
, NMAX
);
inigrp(name
, pwd
->pw_gid
);
strncat(homedir
, pwd
->pw_dir
, sizeof(homedir
)-6);
strncat(shell
, pwd
->pw_shell
, sizeof(shell
)-7);
if (term
[strlen("TERM=")] == 0)
strncat(term
, stypeof(ttyn
), sizeof(term
)-6);
strncat(user
, pwd
->pw_name
, sizeof(user
)-6);
if ((namep
= rindex(pwd
->pw_shell
, '/')) == NULL
)
if (ttyn
[sizeof("/dev/tty")-1] == 'd')
logerr("DIALUP %s %s\n", ttyn
+sizeof("/dev/")-1, pwd
->pw_name
);
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);
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')
printf("%s too long\r\n", err
);
char *fmt
, *a1
, *a2
, *a3
;