Somewhat changed the way utmpx entries are created. It should now work

on both Solaris and IRIX, without stale login information.


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@553 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
1996-06-03 01:41:48 +00:00
parent 4c5aa01e62
commit db1b2a3ae9

View File

@@ -357,6 +357,9 @@ getnpty()
static char Xline[] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
char *line = Xline;
char *line_nodev;
char *line_notty;
#ifdef CRAY
char *myline = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
#endif /* CRAY */
@@ -372,9 +375,41 @@ static char *ptsname(int fd)
}
#endif
#ifdef HAVE_UTMPX_H
static char utid[32]; /* XXX larger than ut_id */
void
set_utid(void)
{
int ptynum;
line_nodev = line;
if(!strncmp(line, "/dev/", 5))
line_nodev += 5;
line_notty = line_nodev;
if(!strncmp(line_nodev, "tty", 3))
line_notty += 3;
else if(!strncmp(line_nodev, "pts/", 4))
line_notty += 4;
/* Derive utmp ID from pty slave number */
if(isdigit(line_notty[0]) && sscanf(line_notty, "%d", &ptynum) == 1)
sprintf(utid, "tn%02x", ptynum & 0xff);
else
sprintf(utid, "tn%s", line_notty);
}
#else
void
set_utid(void)
{
}
#endif
int getpty(int *ptynum)
{
#ifdef __osf__
#ifdef __osf__ /* XXX */
int master;
int slave;
if(openpty(&master, &slave, line, 0, 0) == 0){
@@ -1425,19 +1460,22 @@ init_env(void)
/*
* scrub_env()
*
* Remove a few things from the environment that
* don't need to be there.
* Remove variables from the environment that might cause login to
* behave in a bad manner. To avoid this, login should be staticly
* linked.
*/
static void scrub_env(void)
{
static char *remove[] = { "LD_", "_RLD_", "LIBPATH=", "IFS=", NULL };
char **cpp, **cpp2;
char **p;
for (cpp2 = cpp = environ; *cpp; cpp++) {
if (strncmp(*cpp, "LD_", 3) &&
strncmp(*cpp, "_RLD_", 5) &&
strncmp(*cpp, "LIBPATH=", 8) &&
strncmp(*cpp, "IFS=", 4))
for(p = remove; *p; p++)
if(strncmp(*cpp, *p, strlen(*p)) == 0)
continue;
*cpp2++ = *cpp;
}
*cpp2 = 0;
@@ -1464,6 +1502,7 @@ void start_login(char *host, int autologin, char *name)
register char *cp;
struct arg_val argv;
extern char *getenv(const char *);
#ifdef HAVE_UTMPX_H
char id_buf[3];
int ptynum;
@@ -1478,18 +1517,13 @@ void start_login(char *host, int autologin, char *name)
memset(&utmpx, 0, sizeof(utmpx));
SCPYN(utmpx.ut_user, ".telnet");
SCPYN(utmpx.ut_line, line + sizeof("/dev/") - 1);
SCPYN(utmpx.ut_line, line_nodev);
utmpx.ut_pid = pid;
/* Derive utmp ID from pty slave number */
if(sscanf(line, "%*[^0-9]%d", &ptynum) != 1 || ptynum > 255)
fatal(net, "pty slave number incorrect");
sprintf(id_buf, "%02x", ptynum);
utmpx.ut_id[0] = 't';
utmpx.ut_id[1] = 'n';
utmpx.ut_id[2] = id_buf[0];
utmpx.ut_id[3] = id_buf[1];
SCPYN(utmpx.ut_id, utid);
utmpx.ut_type = LOGIN_PROCESS;
(void) time(&utmpx.ut_tv.tv_sec);
gettimeofday(&utmpx.ut_tv);
if (pututxline(&utmpx) == NULL)
fatal(net, "pututxline failed");
#endif
@@ -1726,12 +1760,15 @@ int addarg(struct arg_val *argv, char *val)
* This is the routine to call when we are all through, to
* clean up anything that needs to be cleaned up.
*/
/* ARGSUSED */
extern void rmut(void);
void
cleanup(int sig)
{
#ifndef PARENT_DOES_UTMP
# if (BSD > 43) || defined(convex)
#ifndef HAVE_UTMPX_H
/* # if (BSD > 43) || defined(convex) */
char *p;
p = line + sizeof("/dev/") - 1;
@@ -1745,8 +1782,6 @@ cleanup(int sig)
(void) shutdown(net, 2);
exit(1);
# else
void rmut();
rmut();
#ifdef HAVE_VHANGUP
vhangup(); /* XXX */
@@ -2086,15 +2121,19 @@ rmut()
* This updates the utmpx and utmp entries and make a wtmp/x entry
*/
SCPYN(utmpx.ut_line, line + sizeof("/dev/") - 1);
utxp = getutxline(&utmpx);
setutxent();
memset(&utmpx, 0, sizeof(utmpx));
strncpy(utmpx.ut_id, utid, sizeof(utmpx.ut_id));
utmpx.ut_type = LOGIN_PROCESS;
utxp = getutxid(&utmpx);
if (utxp) {
strcpy(utxp->ut_user, "");
utxp->ut_type = DEAD_PROCESS;
utxp->ut_exit.e_termination = 0;
utxp->ut_exit.e_exit = 0;
(void) time(&utmpx.ut_tv.tv_sec);
utmpx.ut_tv.tv_usec = 0;
modutx(utxp);
gettimeofday(&utxp->ut_tv, NULL);
pututxline(utxp);
updwtmpx(WTMPX_FILE, utxp);
}
endutxent();
} /* end of rmut */