SCCS-vsn: old/init/init.c 4.13
SCCS-vsn: sbin/init/init.c 4.13
SCCS-vsn: usr.bin/login/login.c 4.34
SCCS-vsn: usr.bin/login/login.c.1 4.34
SCCS-vsn: usr.bin/tset/tset.c 1.9
-static char *sccsid = "@(#)init.c 4.12 (Berkeley) %G%";
+static char *sccsid = "@(#)init.c 4.13 (Berkeley) %G%";
#endif
#include <signal.h>
#endif
#include <signal.h>
#include <sys/reboot.h>
#include <errno.h>
#include <sys/file.h>
#include <sys/reboot.h>
#include <errno.h>
#include <sys/file.h>
#define LINSIZ sizeof(wtmp.ut_line)
#define LINSIZ sizeof(wtmp.ut_line)
#define TABSIZ 100
#define ALL p = &itab[0]; p < &itab[TABSIZ]; p++
#define EVER ;;
#define TABSIZ 100
#define ALL p = &itab[0]; p < &itab[TABSIZ]; p++
#define EVER ;;
char getty[] = "/etc/getty";
char minus[] = "-";
char runc[] = "/etc/rc";
char getty[] = "/etc/getty";
char minus[] = "-";
char runc[] = "/etc/rc";
-char ifile[] = "/etc/ttys";
char utmp[] = "/etc/utmp";
char wtmpf[] = "/usr/adm/wtmp";
char ctty[] = "/dev/console";
char dev[] = "/dev/";
struct utmp wtmp;
char utmp[] = "/etc/utmp";
char wtmpf[] = "/usr/adm/wtmp";
char ctty[] = "/dev/console";
char dev[] = "/dev/";
struct utmp wtmp;
-struct
-{
- char line[LINSIZ];
- char comn;
- char flag;
-} line;
struct tab
{
char line[LINSIZ];
struct tab
{
char line[LINSIZ];
char xflag;
int pid;
time_t gettytime;
char xflag;
int pid;
time_t gettytime;
signal(SIGTERM, SIG_DFL);
signal(SIGHUP, SIG_DFL);
signal(SIGALRM, SIG_DFL);
signal(SIGTERM, SIG_DFL);
signal(SIGHUP, SIG_DFL);
signal(SIGALRM, SIG_DFL);
+ signal(SIGTSTP, SIG_IGN);
(void) open(ctty, O_RDWR);
dup2(0, 1);
dup2(0, 2);
(void) open(ctty, O_RDWR);
dup2(0, 1);
dup2(0, 2);
merge()
{
register struct tab *p;
merge()
{
register struct tab *p;
+ register struct ttyent *t;
- fi = open(ifile, 0);
- if (fi < 0)
- return;
+ setttyent();
+ while (t = getttyent()) {
+ if ((t->ty_status & TTY_ON) == 0)
+ continue;
+ strcpy(tty, dev);
+ strcat(tty, t->ty_name);
+ if (access(tty, R_OK|W_OK) < 0)
+ continue;
- if (SCMPN(p->line, line.line))
+ if (SCMPN(p->line, t->ty_name))
continue;
p->xflag |= FOUND;
continue;
p->xflag |= FOUND;
- if (line.comn != p->comn) {
+ if (SCMPN(p->comn, t->ty_getty)) {
+ SCPYN(p->comn, t->ty_getty);
}
goto contin1;
}
for (ALL) {
if (p->line[0] != 0)
continue;
}
goto contin1;
}
for (ALL) {
if (p->line[0] != 0)
continue;
- SCPYN(p->line, line.line);
+ SCPYN(p->line, t->ty_name);
p->xflag |= FOUND|CHANGE;
p->xflag |= FOUND|CHANGE;
+ SCPYN(p->comn, t->ty_getty);
goto contin1;
}
contin1:
;
}
goto contin1;
}
contin1:
;
}
for (ALL) {
if ((p->xflag&FOUND) == 0) {
term(p);
for (ALL) {
if ((p->xflag&FOUND) == 0) {
term(p);
-rline()
-{
- register c, i;
-
-loop:
- c = get();
- if (c < 0)
- return(0);
- if (c == 0)
- goto loop;
- line.flag = c;
- c = get();
- if (c <= 0)
- goto loop;
- line.comn = c;
- SCPYN(line.line, "");
- for (i = 0; i < LINSIZ; i++) {
- c = get();
- if (c <= 0)
- break;
- line.line[i] = c;
- }
- while (c > 0)
- c = get();
- if (line.line[0] == 0)
- goto loop;
- if (line.flag == '0')
- goto loop;
- strcpy(tty, dev);
- strncat(tty, line.line, LINSIZ);
- if (access(tty, 06) < 0)
- goto loop;
- return (1);
-}
-
-get()
-{
- char b;
-
- if (read(fi, &b, 1) != 1)
- return (-1);
- if (b == '\n')
- return (0);
- return (b);
-}
-
#include <sys/ioctl.h>
dfork(p)
#include <sys/ioctl.h>
dfork(p)
close(0);
dup(1);
dup(0);
close(0);
dup(1);
dup(0);
- tty[0] = p->comn;
- tty[1] = 0;
+ strncpy(tty, p->comn, sizeof(p->comn));
+ tty[sizeof(p->comn)] = 0;
execl(getty, minus, tty, (char *)0);
exit(0);
}
execl(getty, minus, tty, (char *)0);
exit(0);
}
-static char *sccsid = "@(#)init.c 4.12 (Berkeley) %G%";
+static char *sccsid = "@(#)init.c 4.13 (Berkeley) %G%";
#endif
#include <signal.h>
#endif
#include <signal.h>
#include <sys/reboot.h>
#include <errno.h>
#include <sys/file.h>
#include <sys/reboot.h>
#include <errno.h>
#include <sys/file.h>
#define LINSIZ sizeof(wtmp.ut_line)
#define LINSIZ sizeof(wtmp.ut_line)
#define TABSIZ 100
#define ALL p = &itab[0]; p < &itab[TABSIZ]; p++
#define EVER ;;
#define TABSIZ 100
#define ALL p = &itab[0]; p < &itab[TABSIZ]; p++
#define EVER ;;
char getty[] = "/etc/getty";
char minus[] = "-";
char runc[] = "/etc/rc";
char getty[] = "/etc/getty";
char minus[] = "-";
char runc[] = "/etc/rc";
-char ifile[] = "/etc/ttys";
char utmp[] = "/etc/utmp";
char wtmpf[] = "/usr/adm/wtmp";
char ctty[] = "/dev/console";
char dev[] = "/dev/";
struct utmp wtmp;
char utmp[] = "/etc/utmp";
char wtmpf[] = "/usr/adm/wtmp";
char ctty[] = "/dev/console";
char dev[] = "/dev/";
struct utmp wtmp;
-struct
-{
- char line[LINSIZ];
- char comn;
- char flag;
-} line;
struct tab
{
char line[LINSIZ];
struct tab
{
char line[LINSIZ];
char xflag;
int pid;
time_t gettytime;
char xflag;
int pid;
time_t gettytime;
signal(SIGTERM, SIG_DFL);
signal(SIGHUP, SIG_DFL);
signal(SIGALRM, SIG_DFL);
signal(SIGTERM, SIG_DFL);
signal(SIGHUP, SIG_DFL);
signal(SIGALRM, SIG_DFL);
+ signal(SIGTSTP, SIG_IGN);
(void) open(ctty, O_RDWR);
dup2(0, 1);
dup2(0, 2);
(void) open(ctty, O_RDWR);
dup2(0, 1);
dup2(0, 2);
merge()
{
register struct tab *p;
merge()
{
register struct tab *p;
+ register struct ttyent *t;
- fi = open(ifile, 0);
- if (fi < 0)
- return;
+ setttyent();
+ while (t = getttyent()) {
+ if ((t->ty_status & TTY_ON) == 0)
+ continue;
+ strcpy(tty, dev);
+ strcat(tty, t->ty_name);
+ if (access(tty, R_OK|W_OK) < 0)
+ continue;
- if (SCMPN(p->line, line.line))
+ if (SCMPN(p->line, t->ty_name))
continue;
p->xflag |= FOUND;
continue;
p->xflag |= FOUND;
- if (line.comn != p->comn) {
+ if (SCMPN(p->comn, t->ty_getty)) {
+ SCPYN(p->comn, t->ty_getty);
}
goto contin1;
}
for (ALL) {
if (p->line[0] != 0)
continue;
}
goto contin1;
}
for (ALL) {
if (p->line[0] != 0)
continue;
- SCPYN(p->line, line.line);
+ SCPYN(p->line, t->ty_name);
p->xflag |= FOUND|CHANGE;
p->xflag |= FOUND|CHANGE;
+ SCPYN(p->comn, t->ty_getty);
goto contin1;
}
contin1:
;
}
goto contin1;
}
contin1:
;
}
for (ALL) {
if ((p->xflag&FOUND) == 0) {
term(p);
for (ALL) {
if ((p->xflag&FOUND) == 0) {
term(p);
-rline()
-{
- register c, i;
-
-loop:
- c = get();
- if (c < 0)
- return(0);
- if (c == 0)
- goto loop;
- line.flag = c;
- c = get();
- if (c <= 0)
- goto loop;
- line.comn = c;
- SCPYN(line.line, "");
- for (i = 0; i < LINSIZ; i++) {
- c = get();
- if (c <= 0)
- break;
- line.line[i] = c;
- }
- while (c > 0)
- c = get();
- if (line.line[0] == 0)
- goto loop;
- if (line.flag == '0')
- goto loop;
- strcpy(tty, dev);
- strncat(tty, line.line, LINSIZ);
- if (access(tty, 06) < 0)
- goto loop;
- return (1);
-}
-
-get()
-{
- char b;
-
- if (read(fi, &b, 1) != 1)
- return (-1);
- if (b == '\n')
- return (0);
- return (b);
-}
-
#include <sys/ioctl.h>
dfork(p)
#include <sys/ioctl.h>
dfork(p)
close(0);
dup(1);
dup(0);
close(0);
dup(1);
dup(0);
- tty[0] = p->comn;
- tty[1] = 0;
+ strncpy(tty, p->comn, sizeof(p->comn));
+ tty[sizeof(p->comn)] = 0;
execl(getty, minus, tty, (char *)0);
exit(0);
}
execl(getty, minus, tty, (char *)0);
exit(0);
}
-static char *sccsid = "@(#)login.c 4.33 (Berkeley) 83/09/02";
+static char *sccsid = "@(#)login.c 4.34 (Berkeley) 84/05/07";
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sgtty.h>
#include <utmp.h>
#include <sgtty.h>
#include <utmp.h>
#include <stdio.h>
#include <lastlog.h>
#include <errno.h>
#include <stdio.h>
#include <lastlog.h>
#include <errno.h>
+#include <ttyent.h>
+#include <syslog.h>
+#define SCMPN(a, b) strncmp(a, b, sizeof(a))
#define SCPYN(a, b) strncpy(a, b, sizeof(a))
#define NMAX sizeof(utmp.ut_name)
#define SCPYN(a, b) strncpy(a, b, sizeof(a))
#define NMAX sizeof(utmp.ut_name)
char nolog[] = "/etc/nologin";
char qlog[] = ".hushlogin";
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", -1, -1, -1, "", "", "", "" };
char maildir[30] = "/usr/spool/mail/";
char lastlog[] = "/usr/adm/lastlog";
struct passwd nouser = {"", "nope", -1, -1, -1, "", "", "", "" };
{ homedir, shell, "PATH=:/usr/ucb:/bin:/usr/bin", term, user, 0 };
struct passwd *pwd;
{ homedir, shell, "PATH=:/usr/ucb:/bin:/usr/bin", term, user, 0 };
struct passwd *pwd;
-struct passwd *getpwnam();
char *strcat(), *rindex(), *index();
char *strcat(), *rindex(), *index();
int timedout();
char *ttyname();
char *crypt();
int timedout();
char *ttyname();
char *crypt();
char *argv[];
{
register char *namep;
char *argv[];
{
register char *namep;
int invalid, quietlog;
FILE *nlfd;
int invalid, quietlog;
FILE *nlfd;
int ldisc = 0, zero = 0;
signal(SIGALRM, timedout);
int ldisc = 0, zero = 0;
signal(SIGALRM, timedout);
for (t = getdtablesize(); t > 3; t--)
close(t);
ttyn = ttyname(0);
for (t = getdtablesize(); t > 3; t--)
close(t);
ttyn = ttyname(0);
+ tty = rindex(ttyn, '/');
+ if (tty == NULL)
+ tty = ttyn;
+ else
+ tty++;
+ openlog("login", 0, 0);
+ t = 0;
do {
ldisc = 0;
ioctl(0, TIOCSETD, &ldisc);
do {
ldisc = 0;
ioctl(0, TIOCSETD, &ldisc);
* If valid so far and root is logging in,
* see if root logins on this terminal are permitted.
*/
* If valid so far and root is logging in,
* see if root logins on this terminal are permitted.
*/
- if (!invalid && pwd->pw_uid == 0 &&
- !rootterm(ttyn+sizeof("/dev/")-1)) {
- logerr("ROOT LOGIN REFUSED %s",
- ttyn+sizeof("/dev/")-1);
+ if (!invalid && pwd->pw_uid == 0 && !rootterm(tty)) {
+ syslog(LOG_INFO, "ROOT LOGIN REFUSED %s", tty);
invalid = TRUE;
}
if (invalid) {
printf("Login incorrect\n");
invalid = TRUE;
}
if (invalid) {
printf("Login incorrect\n");
- if (ttyn[sizeof("/dev/tty")-1] == 'd')
- logerr("BADDIALUP %s %s",
- ttyn+sizeof("/dev/")-1, utmp.ut_name);
+ if (++t >= 5) {
+ syslog(LOG_INFO,
+ "REPEATED LOGIN FAILURES %s, %s",
+ tty, utmp.ut_name);
+ ioctl(0, TIOCHPCL, (struct sgttyb *) 0);
+ close(0);
+ close(1);
+ close(2);
+ sleep(10);
+ exit(1);
+ }
}
if (*pwd->pw_shell == '\0')
pwd->pw_shell = "/bin/sh";
}
if (*pwd->pw_shell == '\0')
pwd->pw_shell = "/bin/sh";
- i = strlen(pwd->pw_shell);
if (chdir(pwd->pw_dir) < 0 && !invalid ) {
if (chdir("/") < 0) {
printf("No directory!\n");
if (chdir(pwd->pw_dir) < 0 && !invalid ) {
if (chdir("/") < 0) {
printf("No directory!\n");
}
time(&utmp.ut_time);
t = ttyslot();
}
time(&utmp.ut_time);
t = ttyslot();
- if (t > 0 && (f = open("/etc/utmp", 1)) >= 0) {
+ if (t > 0 && (f = open("/etc/utmp", O_WRONLY)) >= 0) {
lseek(f, (long)(t*sizeof(utmp)), 0);
lseek(f, (long)(t*sizeof(utmp)), 0);
- SCPYN(utmp.ut_line, rindex(ttyn, '/')+1);
+ SCPYN(utmp.ut_line, tty);
write(f, (char *)&utmp, sizeof(utmp));
close(f);
}
write(f, (char *)&utmp, sizeof(utmp));
close(f);
}
- if (t > 0 && (f = open("/usr/adm/wtmp", 1)) >= 0) {
- lseek(f, 0L, 2);
+ if ((f = open("/usr/adm/wtmp", O_WRONLY|O_APPEND)) >= 0) {
write(f, (char *)&utmp, sizeof(utmp));
close(f);
}
write(f, (char *)&utmp, sizeof(utmp));
close(f);
}
- quietlog = access(qlog, 0) == 0;
- if ((f = open(lastlog, 2)) >= 0) {
+ quietlog = access(qlog, F_OK) == 0;
+ if ((f = open(lastlog, O_RDWR)) >= 0) {
struct lastlog ll;
lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
struct lastlog ll;
lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
}
lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
time(&ll.ll_time);
}
lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
time(&ll.ll_time);
- SCPYN(ll.ll_line, rindex(ttyn, '/')+1);
+ SCPYN(ll.ll_line, tty);
SCPYN(ll.ll_host, utmp.ut_host);
write(f, (char *) &ll, sizeof ll);
close(f);
SCPYN(ll.ll_host, utmp.ut_host);
write(f, (char *) &ll, sizeof ll);
close(f);
strncat(homedir, pwd->pw_dir, sizeof(homedir)-6);
strncat(shell, pwd->pw_shell, sizeof(shell)-7);
if (term[strlen("TERM=")] == 0)
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(term, stypeof(tty), sizeof(term)-6);
strncat(user, pwd->pw_name, sizeof(user)-6);
if ((namep = rindex(pwd->pw_shell, '/')) == NULL)
namep = pwd->pw_shell;
else
namep++;
strcat(minusnam, namep);
strncat(user, pwd->pw_name, sizeof(user)-6);
if ((namep = rindex(pwd->pw_shell, '/')) == NULL)
namep = pwd->pw_shell;
else
namep++;
strcat(minusnam, namep);
- umask(022);
- if (ttyn[sizeof("/dev/tty")-1] == 'd')
- logerr("DIALUP %s %s",
- ttyn+sizeof("/dev/")-1, pwd->pw_name);
+ if (tty[sizeof("tty")-1] == 'd')
+ syslog(LOG_INFO, "DIALUP %s %s", tty, pwd->pw_name);
if (!quietlog) {
showmotd();
strcat(maildir, pwd->pw_name);
if (!quietlog) {
showmotd();
strcat(maildir, pwd->pw_name);
- if (access(maildir,4)==0) {
+ if (access(maildir, R_OK) == 0) {
struct stat statb;
stat(maildir, &statb);
if (statb.st_size)
struct stat statb;
stat(maildir, &statb);
if (statb.st_size)
}
strncpy(lusername, up->ut_name, NMAX);
lusername[NMAX] = 0;
}
strncpy(lusername, up->ut_name, NMAX);
lusername[NMAX] = 0;
if ((pwd = getpwnam(lusername)) == NULL)
pwd = &nouser;
if ((pwd = getpwnam(lusername)) == NULL)
pwd = &nouser;
rootterm(tty)
char *tty;
{
rootterm(tty)
char *tty;
{
- register FILE *fd;
- char buf[100];
-
- if ((fd = fopen(securetty, "r")) == NULL)
- return(1);
- while (fgets(buf, sizeof buf, fd) != NULL) {
- buf[strlen(buf)-1] = '\0';
- if (strcmp(tty, buf) == 0) {
- fclose(fd);
- return(1);
- }
+ register struct ttyent *t;
+
+ if ((t = getttynam(tty)) != NULL) {
+ if (t->ty_status & TTY_SECURE)
+ return (1);
- fclose(fd);
- return(0);
register c;
signal(SIGINT, catch);
register c;
signal(SIGINT, catch);
- if ((mf = fopen("/etc/motd","r")) != NULL) {
+ if ((mf = fopen("/etc/motd", "r")) != NULL) {
while ((c = getc(mf)) != EOF && stopmotd == 0)
putchar(c);
fclose(mf);
while ((c = getc(mf)) != EOF && stopmotd == 0)
putchar(c);
fclose(mf);
stypeof(ttyid)
char *ttyid;
{
stypeof(ttyid)
char *ttyid;
{
- static char typebuf[16];
- char buf[50];
- register FILE *f;
- register char *p, *t, *q;
+ register struct ttyent *t;
+ if (ttyid == NULL || (t = getttynam(ttyid)) == NULL)
- f = fopen("/etc/ttytype", "r");
- if (f == NULL)
- return (UNKNOWN);
- /* split off end of name */
- for (p = q = ttyid; *p != 0; p++)
- if (*p == '/')
- q = p + 1;
-
- /* scan the file */
- while (fgets(buf, sizeof buf, f) != NULL) {
- for (t = buf; *t != ' ' && *t != '\t'; t++)
- ;
- *t++ = 0;
- while (*t == ' ' || *t == '\t')
- t++;
- for (p = t; *p > ' '; p++)
- ;
- *p = 0;
- if (strcmp(q,t) == 0) {
- strcpy(typebuf, buf);
- fclose(f);
- return (typebuf);
- }
- }
- fclose (f);
- return (UNKNOWN);
pwd = &nouser;
goto bad;
}
pwd = &nouser;
goto bad;
}
pwd = getpwnam(lusername);
pwd = getpwnam(lusername);
if (pwd == NULL) {
pwd = &nouser;
goto bad;
if (pwd == NULL) {
pwd = &nouser;
goto bad;
}
tp->sg_flags = ECHO|CRMOD|ANYP|XTABS;
}
}
tp->sg_flags = ECHO|CRMOD|ANYP|XTABS;
}
-
-logerr(fmt, a1, a2, a3)
- char *fmt, *a1, *a2, *a3;
-{
-#ifdef LOGERR
- FILE *cons = fopen("/dev/console", "w");
-
- if (cons != NULL) {
- fprintf(cons, fmt, a1, a2, a3);
- fprintf(cons, "\n\r");
- fclose(cons);
- }
-#endif
-}
-static char *sccsid = "@(#)login.c.1 4.33 (Berkeley) 83/09/02";
+static char *sccsid = "@(#)login.c.1 4.34 (Berkeley) 84/05/07";
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sgtty.h>
#include <utmp.h>
#include <sgtty.h>
#include <utmp.h>
#include <stdio.h>
#include <lastlog.h>
#include <errno.h>
#include <stdio.h>
#include <lastlog.h>
#include <errno.h>
+#include <ttyent.h>
+#include <syslog.h>
+#define SCMPN(a, b) strncmp(a, b, sizeof(a))
#define SCPYN(a, b) strncpy(a, b, sizeof(a))
#define NMAX sizeof(utmp.ut_name)
#define SCPYN(a, b) strncpy(a, b, sizeof(a))
#define NMAX sizeof(utmp.ut_name)
char nolog[] = "/etc/nologin";
char qlog[] = ".hushlogin";
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", -1, -1, -1, "", "", "", "" };
char maildir[30] = "/usr/spool/mail/";
char lastlog[] = "/usr/adm/lastlog";
struct passwd nouser = {"", "nope", -1, -1, -1, "", "", "", "" };
{ homedir, shell, "PATH=:/usr/ucb:/bin:/usr/bin", term, user, 0 };
struct passwd *pwd;
{ homedir, shell, "PATH=:/usr/ucb:/bin:/usr/bin", term, user, 0 };
struct passwd *pwd;
-struct passwd *getpwnam();
char *strcat(), *rindex(), *index();
char *strcat(), *rindex(), *index();
int timedout();
char *ttyname();
char *crypt();
int timedout();
char *ttyname();
char *crypt();
char *argv[];
{
register char *namep;
char *argv[];
{
register char *namep;
int invalid, quietlog;
FILE *nlfd;
int invalid, quietlog;
FILE *nlfd;
int ldisc = 0, zero = 0;
signal(SIGALRM, timedout);
int ldisc = 0, zero = 0;
signal(SIGALRM, timedout);
for (t = getdtablesize(); t > 3; t--)
close(t);
ttyn = ttyname(0);
for (t = getdtablesize(); t > 3; t--)
close(t);
ttyn = ttyname(0);
+ tty = rindex(ttyn, '/');
+ if (tty == NULL)
+ tty = ttyn;
+ else
+ tty++;
+ openlog("login", 0, 0);
+ t = 0;
do {
ldisc = 0;
ioctl(0, TIOCSETD, &ldisc);
do {
ldisc = 0;
ioctl(0, TIOCSETD, &ldisc);
* If valid so far and root is logging in,
* see if root logins on this terminal are permitted.
*/
* If valid so far and root is logging in,
* see if root logins on this terminal are permitted.
*/
- if (!invalid && pwd->pw_uid == 0 &&
- !rootterm(ttyn+sizeof("/dev/")-1)) {
- logerr("ROOT LOGIN REFUSED %s",
- ttyn+sizeof("/dev/")-1);
+ if (!invalid && pwd->pw_uid == 0 && !rootterm(tty)) {
+ syslog(LOG_INFO, "ROOT LOGIN REFUSED %s", tty);
invalid = TRUE;
}
if (invalid) {
printf("Login incorrect\n");
invalid = TRUE;
}
if (invalid) {
printf("Login incorrect\n");
- if (ttyn[sizeof("/dev/tty")-1] == 'd')
- logerr("BADDIALUP %s %s",
- ttyn+sizeof("/dev/")-1, utmp.ut_name);
+ if (++t >= 5) {
+ syslog(LOG_INFO,
+ "REPEATED LOGIN FAILURES %s, %s",
+ tty, utmp.ut_name);
+ ioctl(0, TIOCHPCL, (struct sgttyb *) 0);
+ close(0);
+ close(1);
+ close(2);
+ sleep(10);
+ exit(1);
+ }
}
if (*pwd->pw_shell == '\0')
pwd->pw_shell = "/bin/sh";
}
if (*pwd->pw_shell == '\0')
pwd->pw_shell = "/bin/sh";
- i = strlen(pwd->pw_shell);
if (chdir(pwd->pw_dir) < 0 && !invalid ) {
if (chdir("/") < 0) {
printf("No directory!\n");
if (chdir(pwd->pw_dir) < 0 && !invalid ) {
if (chdir("/") < 0) {
printf("No directory!\n");
}
time(&utmp.ut_time);
t = ttyslot();
}
time(&utmp.ut_time);
t = ttyslot();
- if (t > 0 && (f = open("/etc/utmp", 1)) >= 0) {
+ if (t > 0 && (f = open("/etc/utmp", O_WRONLY)) >= 0) {
lseek(f, (long)(t*sizeof(utmp)), 0);
lseek(f, (long)(t*sizeof(utmp)), 0);
- SCPYN(utmp.ut_line, rindex(ttyn, '/')+1);
+ SCPYN(utmp.ut_line, tty);
write(f, (char *)&utmp, sizeof(utmp));
close(f);
}
write(f, (char *)&utmp, sizeof(utmp));
close(f);
}
- if (t > 0 && (f = open("/usr/adm/wtmp", 1)) >= 0) {
- lseek(f, 0L, 2);
+ if ((f = open("/usr/adm/wtmp", O_WRONLY|O_APPEND)) >= 0) {
write(f, (char *)&utmp, sizeof(utmp));
close(f);
}
write(f, (char *)&utmp, sizeof(utmp));
close(f);
}
- quietlog = access(qlog, 0) == 0;
- if ((f = open(lastlog, 2)) >= 0) {
+ quietlog = access(qlog, F_OK) == 0;
+ if ((f = open(lastlog, O_RDWR)) >= 0) {
struct lastlog ll;
lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
struct lastlog ll;
lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
}
lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
time(&ll.ll_time);
}
lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
time(&ll.ll_time);
- SCPYN(ll.ll_line, rindex(ttyn, '/')+1);
+ SCPYN(ll.ll_line, tty);
SCPYN(ll.ll_host, utmp.ut_host);
write(f, (char *) &ll, sizeof ll);
close(f);
SCPYN(ll.ll_host, utmp.ut_host);
write(f, (char *) &ll, sizeof ll);
close(f);
strncat(homedir, pwd->pw_dir, sizeof(homedir)-6);
strncat(shell, pwd->pw_shell, sizeof(shell)-7);
if (term[strlen("TERM=")] == 0)
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(term, stypeof(tty), sizeof(term)-6);
strncat(user, pwd->pw_name, sizeof(user)-6);
if ((namep = rindex(pwd->pw_shell, '/')) == NULL)
namep = pwd->pw_shell;
else
namep++;
strcat(minusnam, namep);
strncat(user, pwd->pw_name, sizeof(user)-6);
if ((namep = rindex(pwd->pw_shell, '/')) == NULL)
namep = pwd->pw_shell;
else
namep++;
strcat(minusnam, namep);
- umask(022);
- if (ttyn[sizeof("/dev/tty")-1] == 'd')
- logerr("DIALUP %s %s",
- ttyn+sizeof("/dev/")-1, pwd->pw_name);
+ if (tty[sizeof("tty")-1] == 'd')
+ syslog(LOG_INFO, "DIALUP %s %s", tty, pwd->pw_name);
if (!quietlog) {
showmotd();
strcat(maildir, pwd->pw_name);
if (!quietlog) {
showmotd();
strcat(maildir, pwd->pw_name);
- if (access(maildir,4)==0) {
+ if (access(maildir, R_OK) == 0) {
struct stat statb;
stat(maildir, &statb);
if (statb.st_size)
struct stat statb;
stat(maildir, &statb);
if (statb.st_size)
}
strncpy(lusername, up->ut_name, NMAX);
lusername[NMAX] = 0;
}
strncpy(lusername, up->ut_name, NMAX);
lusername[NMAX] = 0;
if ((pwd = getpwnam(lusername)) == NULL)
pwd = &nouser;
if ((pwd = getpwnam(lusername)) == NULL)
pwd = &nouser;
rootterm(tty)
char *tty;
{
rootterm(tty)
char *tty;
{
- register FILE *fd;
- char buf[100];
-
- if ((fd = fopen(securetty, "r")) == NULL)
- return(1);
- while (fgets(buf, sizeof buf, fd) != NULL) {
- buf[strlen(buf)-1] = '\0';
- if (strcmp(tty, buf) == 0) {
- fclose(fd);
- return(1);
- }
+ register struct ttyent *t;
+
+ if ((t = getttynam(tty)) != NULL) {
+ if (t->ty_status & TTY_SECURE)
+ return (1);
- fclose(fd);
- return(0);
register c;
signal(SIGINT, catch);
register c;
signal(SIGINT, catch);
- if ((mf = fopen("/etc/motd","r")) != NULL) {
+ if ((mf = fopen("/etc/motd", "r")) != NULL) {
while ((c = getc(mf)) != EOF && stopmotd == 0)
putchar(c);
fclose(mf);
while ((c = getc(mf)) != EOF && stopmotd == 0)
putchar(c);
fclose(mf);
stypeof(ttyid)
char *ttyid;
{
stypeof(ttyid)
char *ttyid;
{
- static char typebuf[16];
- char buf[50];
- register FILE *f;
- register char *p, *t, *q;
+ register struct ttyent *t;
+ if (ttyid == NULL || (t = getttynam(ttyid)) == NULL)
- f = fopen("/etc/ttytype", "r");
- if (f == NULL)
- return (UNKNOWN);
- /* split off end of name */
- for (p = q = ttyid; *p != 0; p++)
- if (*p == '/')
- q = p + 1;
-
- /* scan the file */
- while (fgets(buf, sizeof buf, f) != NULL) {
- for (t = buf; *t != ' ' && *t != '\t'; t++)
- ;
- *t++ = 0;
- while (*t == ' ' || *t == '\t')
- t++;
- for (p = t; *p > ' '; p++)
- ;
- *p = 0;
- if (strcmp(q,t) == 0) {
- strcpy(typebuf, buf);
- fclose(f);
- return (typebuf);
- }
- }
- fclose (f);
- return (UNKNOWN);
pwd = &nouser;
goto bad;
}
pwd = &nouser;
goto bad;
}
pwd = getpwnam(lusername);
pwd = getpwnam(lusername);
if (pwd == NULL) {
pwd = &nouser;
goto bad;
if (pwd == NULL) {
pwd = &nouser;
goto bad;
}
tp->sg_flags = ECHO|CRMOD|ANYP|XTABS;
}
}
tp->sg_flags = ECHO|CRMOD|ANYP|XTABS;
}
-
-logerr(fmt, a1, a2, a3)
- char *fmt, *a1, *a2, *a3;
-{
-#ifdef LOGERR
- FILE *cons = fopen("/dev/console", "w");
-
- if (cons != NULL) {
- fprintf(cons, fmt, a1, a2, a3);
- fprintf(cons, "\n\r");
- fclose(cons);
- }
-#endif
-}
-static char sccsid[] = "@(#)tset.c 1.8 (Berkeley) %G%";
+static char sccsid[] = "@(#)tset.c 1.9 (Berkeley) %G%";
** (-d type -> -m dialup:type)
** (-p type -> -m plug:type)
** Syntax: -m identifier [test baudrate] :type
** (-d type -> -m dialup:type)
** (-p type -> -m plug:type)
** Syntax: -m identifier [test baudrate] :type
-** where: ``identifier'' is whatever is found in
-** /etc/ttytype for this port, (abscence of an identifier
+** where: ``identifier'' is terminal type found in
+** /etc/ttys for this port, (abscence of an identifier
** matches any identifier); ``test'' may be any combination
** of > = < ! @; ``baudrate'' is as with stty(1);
** ``type'' is the actual terminal type to use if the
** matches any identifier); ``test'' may be any combination
** of > = < ! @; ``baudrate'' is as with stty(1);
** ``type'' is the actual terminal type to use if the
** the output of -s to use virtual terminal sequences.
**
** Files:
** the output of -s to use virtual terminal sequences.
**
** Files:
** contains a terminal id -> terminal type
** mapping; used when any user mapping is specified,
** or the environment doesn't have TERM set.
** contains a terminal id -> terminal type
** mapping; used when any user mapping is specified,
** or the environment doesn't have TERM set.
** and compiles code to look there.
**
** Requires:
** and compiles code to look there.
**
** Requires:
-** Routines to handle htmp, ttytype, and ttycap.
+** Routines to handle htmp, ttys, and ttycap.
**
** Compilation Flags:
** OLDFLAGS -- must be defined to compile code for any of
**
** Compilation Flags:
** OLDFLAGS -- must be defined to compile code for any of
** OLDDIALUP -- accept the -d flag.
** OLDPLUGBOARD -- accept the -p flag.
** OLDARPANET -- accept the -a flag.
** OLDDIALUP -- accept the -d flag.
** OLDPLUGBOARD -- accept the -p flag.
** OLDARPANET -- accept the -a flag.
-** FULLLOGIN -- if defined, login sets the ttytype from
-** /etc/ttytype file.
** V6 -- if clear, use environments, not htmp.
** also use TIOCSETN rather than stty to avoid flushing
** V6 -- if clear, use environments, not htmp.
** also use TIOCSETN rather than stty to avoid flushing
-** GTTYN -- if set, compiles code to look at /etc/ttytype.
+** GTTYN -- if set, compiles code to look at /etc/ttys.
** UCB_NTTY -- set to handle new tty driver modes.
**
** Trace Flags:
** UCB_NTTY -- set to handle new tty driver modes.
**
** Trace Flags:
** 12/78 -- modified for eventual migration to VAX/UNIX,
** so the '-' option is changed to output only
** the terminal type to STDOUT instead of
** 12/78 -- modified for eventual migration to VAX/UNIX,
** so the '-' option is changed to output only
** the terminal type to STDOUT instead of
-** FILEDES. FULLLOGIN flag added.
** 9/78 -- '-' and '-p' options added (now fully
** compatible with ttytype!), and spaces are
** permitted between the -d and the type.
** 9/78 -- '-' and '-p' options added (now fully
** compatible with ttytype!), and spaces are
** permitted between the -d and the type.
# define oldkill oldmode.sg_kill
# endif
# define oldkill oldmode.sg_kill
# endif
-/*
-# define FULLLOGIN 1
-/*/
-# define GTTYN "/etc/ttytype"
+# define GTTYN
+# include <ttyent.h>
stypeof(ttyid)
char *ttyid;
{
stypeof(ttyid)
char *ttyid;
{
- static char typebuf[BUFSIZ];
register char *PortType;
register char *PortName;
register char *TtyId;
register char *PortType;
register char *PortName;
register char *TtyId;
- register char *p;
- register FILE *f;
if (ttyid == NOTTY)
return (DEFTYPE);
if (ttyid == NOTTY)
return (DEFTYPE);
- f = fopen(GTTYN, "r");
- if (f == NULL)
- return (DEFTYPE);
/* split off end of name */
TtyId = ttyid;
/* split off end of name */
TtyId = ttyid;
TtyId = ttyid;
/* scan the file */
TtyId = ttyid;
/* scan the file */
- while (fgets(typebuf, sizeof typebuf, f) != NULL)
+ if ((t = getttynam(TtyId)) != NULL)
- p = PortType = typebuf;
- while (*p && isalnum(*p))
- p++;
- *p++ = NULL;
-
- /* skip separator */
- while (*p && !isalnum(*p))
- p++;
-
- PortName = p;
- /* put NULL at end of name */
- while (*p && isalnum(*p))
- p++;
- *p = NULL;
-
- /* check match on port name */
- if (sequal(PortName, TtyId)) /* found it */
- {
- fclose (f);
- /* get aliases from termcap entry */
- if (Mapped && tgetent(Capbuf, PortType) > 0) {
- makealias(Capbuf);
- if (sequal(Alias[0], PortType) && Alias[1])
- PortType = Alias[1];
- }
- return(PortType);
+ PortType = t->ty_type;
+ /* get aliases from termcap entry */
+ if (Mapped && tgetent(Capbuf, PortType) > 0) {
+ makealias(Capbuf);
+ if (sequal(Alias[0], PortType) && Alias[1])
+ PortType = Alias[1];
return (DEFTYPE);
}
# endif
return (DEFTYPE);
}
# endif