-static char *sccsid = "@(#)login.c 4.15 82/03/27";
+static char *sccsid = "@(#)login.c 4.23 83/05/19";
/*
* login [ name ]
* login -r
char securetty[] = "/etc/securetty";
char maildir[30] = "/usr/spool/mail/";
char lastlog[] = "/usr/adm/lastlog";
-struct passwd nouser = {"", "nope"};
+struct passwd nouser = {"", "nope", -1, -1, -1, "", "", "", "" };
struct sgttyb ttyb;
struct utmp utmp;
char minusnam[16] = "-";
char *ttyname();
char *crypt();
char *getpass();
-char *rindex();
char *stypeof();
extern char **environ;
-#define CTRL(c) ('c'&037)
-#define CERASE '#'
-#define CEOT CTRL(d)
-#define CKILL '@'
-#define CQUIT 034 /* FS, cntl shift L */
-#define CINTR 0177 /* DEL */
-#define CSTOP CTRL(s)
-#define CSTART CTRL(q)
-#define CBRK 0377
-struct tchars tc = {
- CINTR, CQUIT, CSTART, CSTOP, CEOT, CBRK
-};
-struct ltchars ltc = {
- CTRL(z), CTRL(y), CTRL(r), CTRL(o), CTRL(w), CTRL(v)
+struct ttychars tc = {
+ CERASE, CKILL, CINTR, CQUIT, CSTART,
+ CSTOP, CEOF, CBRK, CSUSP, CDSUSP,
+ CRPRNT, CFLUSH, CWERASE,CLNEXT
};
int rflag;
char rusername[NMAX+1], lusername[NMAX+1];
char rpassword[NMAX+1];
+char name[NMAX+1];
char *rhost;
main(argc, argv)
setpwent();
pwd = getpwnam(lusername);
endpwent();
- if (pwd == NULL) {
- if (strcmp(rusername, lusername))
- printf("%s: No such user\r\n", lusername);
+ if (pwd == NULL)
goto abnormal;
- }
- hostf = fopen("/etc/hosts.equiv", "r");
+ hostf = pwd->pw_uid ? fopen("/etc/hosts.equiv", "r") : 0;
again:
if (hostf) {
- char ahost[32];
- while (fgets(ahost, sizeof (ahost), hostf)) {
- char *user;
- if (index(ahost, '\n'))
- *index(ahost, '\n') = 0;
- user = index(ahost, ' ');
- if (user)
- *user++ = 0;
- if (!strcmp(rhost, ahost) &&
- !strcmp(rusername, user ? user : lusername)) {
- fclose(hostf);
- goto normal;
+ char ahost[32];
+
+ while (fgets(ahost, sizeof (ahost), hostf)) {
+ char *user;
+
+ if ((user = index(ahost, '\n')) != 0)
+ *user++ = '\0';
+ if ((user = index(ahost, ' ')) != 0)
+ *user++ = '\0';
+ if (!strcmp(rhost, ahost) &&
+ !strcmp(rusername, user ?
+ user : lusername)) {
+ fclose(hostf);
+ goto normal;
+ }
}
- }
- fclose(hostf);
+ fclose(hostf);
}
if (first == 1) {
+ char *rhosts = ".rhosts";
+ struct stat sbuf;
+
first = 0;
if (chdir(pwd->pw_dir) < 0)
goto again;
- hostf = fopen(".rhosts", "r");
- goto again;
+ if (lstat(rhosts, &sbuf) < 0)
+ goto again;
+ if ((sbuf.st_mode & S_IFMT) == S_IFLNK) {
+ printf("login: .rhosts is a soft link.\r\n");
+ goto abnormal;
+ }
+ hostf = fopen(rhosts, "r");
+ fstat(fileno(hostf), &sbuf);
+ if ((int) sbuf.st_uid != pwd->pw_uid &&
+ (int) sbuf.st_uid != 0) {
+ printf("login: Bad .rhosts ownership.\r\n");
+ fclose(hostf);
+ goto abnormal;
+ }
+ goto again;
}
abnormal:
rhost = 0;
rflag = -1;
}
normal:
- ioctl(0, TIOCLSET, &zero);
+ ioctl(0, TIOCLSET, &zero); /* XXX */
ioctl(0, TIOCNXCL, 0);
ioctl(0, FIONBIO, &zero);
ioctl(0, FIOASYNC, &zero);
- gtty(0, &ttyb);
+ ioctl(0, TIOCGETP, &ttyb); /* XXX */
if (rflag) {
char *cp = index(term, '/');
if (cp) {
}
ttyb.sg_flags = ECHO|CRMOD|ANYP|XTABS;
}
- ttyb.sg_erase = CERASE;
- ttyb.sg_kill = CKILL;
- stty(0, &ttyb);
- ioctl(0, TIOCSETC, &tc);
- ioctl(0, TIOCSLTC, <c);
+ ioctl(0, TIOCSETP, &ttyb); /* XXX */
+ ioctl(0, TIOCCSET, &tc);
for (t=3; t<20; t++)
close(t);
ttyn = ttyname(0);
argc = 0;
}
if (rflag) {
- strcpy(utmp.ut_name, lusername);
+ SCPYN(utmp.ut_name, lusername);
if (rflag == -1)
rflag = 0;
} else
close(f);
}
chown(ttyn, pwd->pw_uid, pwd->pw_gid);
+ chmod(ttyn, 0622);
setgid(pwd->pw_gid);
- inigrp(utmp.ut_name, pwd->pw_gid);
+ strncpy(name, utmp.ut_name, NMAX);
+ name[NMAX] = '\0';
+ initgroups(name, pwd->pw_gid);
setuid(pwd->pw_uid);
environ = envinit;
strncat(homedir, pwd->pw_dir, sizeof(homedir)-6);
int stopmotd;
catch()
{
+
signal(SIGINT, SIG_IGN);
stopmotd++;
}
-/*
- * return true if OK for root to login on this terminal
- */
rootterm(tty)
- char *tty;
+ char *tty;
{
register FILE *fd;
- char buf[100];
+ char buf[100];
if ((fd = fopen(securetty, "r")) == NULL)
return(1);