Port ppp(8) to utmpx.

A nice thing about utmpx is that it makes it very easy to log sessions
that don't use TTYs. This is because the file is not indexed by TTY
slots anymore.

Silence from:	brian
This commit is contained in:
Ed Schouten 2010-01-13 17:54:32 +00:00
parent 550dcc5960
commit adc17f0a42
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=202192
4 changed files with 32 additions and 55 deletions

View File

@ -49,7 +49,7 @@
#else
#include <libutil.h>
#endif
#include <utmp.h>
#include <utmpx.h>
#include "log.h"
#include "main.h"
@ -202,36 +202,25 @@ ID0uu_unlock(const char *basettyname)
}
void
ID0login(struct utmp *ut)
ID0login(const struct utmpx *ut)
{
ID0set0();
if (logout(ut->ut_line)) {
log_Printf(LogID0, "logout(\"%s\")\n", ut->ut_line);
logwtmp(ut->ut_line, "", "");
log_Printf(LogID0, "logwtmp(\"%s\", \"\", \"\")\n", ut->ut_line);
}
login(ut);
log_Printf(LogID0, "login(\"%s\", \"%.*s\")\n",
ut->ut_line, (int)(sizeof ut->ut_name), ut->ut_name);
pututxline(ut);
log_Printf(LogID0, "pututxline(\"%.*s\", \"%.*s\", \"%.*s\", \"%.*s\")\n",
(int)sizeof ut->ut_id, ut->ut_id,
(int)sizeof ut->ut_user, ut->ut_user,
(int)sizeof ut->ut_line, ut->ut_line,
(int)sizeof ut->ut_host, ut->ut_host);
ID0setuser();
}
void
ID0logout(const char *device, int nologout)
ID0logout(const struct utmpx *ut)
{
struct utmp ut;
char ut_line[sizeof ut.ut_line + 1];
strncpy(ut_line, device, sizeof ut_line - 1);
ut_line[sizeof ut_line - 1] = '\0';
ID0set0();
if (nologout || logout(ut_line)) {
log_Printf(LogID0, "logout(\"%s\")\n", ut_line);
logwtmp(ut_line, "", "");
log_Printf(LogID0, "logwtmp(\"%s\", \"\", \"\")\n", ut_line);
} else
log_Printf(LogERROR, "ID0logout: No longer logged in on %s\n", ut_line);
pututxline(ut);
log_Printf(LogID0, "pututxline(\"%.*s\")\n",
(int)sizeof ut->ut_id, ut->ut_id);
ID0setuser();
}

View File

@ -27,7 +27,7 @@
*/
#ifndef NOSUID
struct utmp;
struct utmpx;
struct sockaddr_un;
extern void ID0init(void);
@ -41,8 +41,8 @@ extern int ID0write(int, const void *, size_t);
extern int ID0uu_lock(const char *);
extern int ID0uu_lock_txfr(const char *, pid_t);
extern int ID0uu_unlock(const char *);
extern void ID0login(struct utmp *);
extern void ID0logout(const char *, int);
extern void ID0login(const struct utmpx *);
extern void ID0logout(const struct utmpx *);
extern int ID0bind_un(int, const struct sockaddr_un *);
extern int ID0connect_un(int, const struct sockaddr_un *);
extern int ID0kill(pid_t, int);
@ -64,20 +64,8 @@ extern int ID0NgMkSockNode(const char *, int *, int *);
#define ID0uu_lock uu_lock
#define ID0uu_lock_txfr uu_lock_txfr
#define ID0uu_unlock uu_unlock
#define ID0login(u) \
do { \
if (logout((u)->ut_line)) \
logwtmp((u)->ut_line, "", ""); \
login(u); \
} while (0)
#define ID0logout(dev, no) \
do { \
struct utmp ut; \
strncpy(ut.ut_line, dev, sizeof ut.ut_line - 1); \
ut.ut_line[sizeof ut.ut_line - 1] = '\0'; \
if (no || logout(ut.ut_line)) \
logwtmp(ut.ut_line, "", ""); \
} while (0)
#define ID0login pututxline
#define ID0logout pututxline
#define ID0bind_un(s, n) bind(s, (const struct sockaddr *)(n), sizeof *(n))
#define ID0connect_un(s, n) \
connect(s, (const struct sockaddr *)(n), sizeof *(n))

View File

@ -25,6 +25,7 @@
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/un.h>
#include <errno.h>
@ -42,7 +43,7 @@
#include <termios.h>
#include <time.h>
#include <unistd.h>
#include <utmp.h>
#include <utmpx.h>
#if defined(__OpenBSD__) || defined(__NetBSD__)
#include <sys/ioctl.h>
#include <util.h>
@ -106,8 +107,6 @@
#endif
#include "tcpmss.h"
#define PPPOTCPLINE "ppp"
static int physical_DescriptorWrite(struct fdescriptor *, struct bundle *,
const fd_set *);
@ -333,6 +332,7 @@ physical_Close(struct physical *p)
{
int newsid;
char fn[PATH_MAX];
struct utmpx ut;
if (p->fd < 0)
return;
@ -344,12 +344,11 @@ physical_Close(struct physical *p)
physical_StopDeviceTimer(p);
if (p->Utmp) {
if (p->handler && (p->handler->type == TCP_DEVICE ||
p->handler->type == UDP_DEVICE))
/* Careful - we logged in on line ``ppp'' with IP as our host */
ID0logout(PPPOTCPLINE, 1);
else
ID0logout(p->name.base, 0);
memset(&ut, 0, sizeof ut);
ut.ut_type = DEAD_PROCESS;
gettimeofday(&ut.ut_tv, NULL);
snprintf(ut.ut_id, sizeof ut.ut_id, "%xppp", (int)getpid());
ID0logout(&ut);
p->Utmp = 0;
}
newsid = tcgetpgrp(p->fd) == getpgrp();
@ -911,16 +910,17 @@ void
physical_Login(struct physical *p, const char *name)
{
if (p->type == PHYS_DIRECT && *p->name.base && !p->Utmp) {
struct utmp ut;
struct utmpx ut;
const char *connstr;
char *colon;
memset(&ut, 0, sizeof ut);
ut.ut_time = time(NULL);
strncpy(ut.ut_name, name, sizeof ut.ut_name);
ut.ut_type = USER_PROCESS;
gettimeofday(&ut.ut_tv, NULL);
snprintf(ut.ut_id, sizeof ut.ut_id, "%xppp", (int)getpid());
strncpy(ut.ut_user, name, sizeof ut.ut_user);
if (p->handler && (p->handler->type == TCP_DEVICE ||
p->handler->type == UDP_DEVICE)) {
strncpy(ut.ut_line, PPPOTCPLINE, sizeof ut.ut_line);
strncpy(ut.ut_host, p->name.base, sizeof ut.ut_host);
colon = memchr(ut.ut_host, ':', sizeof ut.ut_host);
if (colon)
@ -931,7 +931,7 @@ physical_Login(struct physical *p, const char *name)
/* mgetty sets this to the connection speed */
strncpy(ut.ut_host, connstr, sizeof ut.ut_host);
ID0login(&ut);
p->Utmp = ut.ut_time;
p->Utmp = 1;
}
}

View File

@ -97,7 +97,7 @@ struct physical {
char *base;
} name;
time_t Utmp; /* Are we in utmp ? */
int Utmp; /* Are we in utmp ? */
pid_t session_owner; /* HUP this when closing the link */
struct device *handler; /* device specific handler */