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