svn commit: r201933 - in user/ed/utmpx/usr.sbin: . ppp

Ed Schouten ed at FreeBSD.org
Sat Jan 9 21:57:41 UTC 2010


Author: ed
Date: Sat Jan  9 21:57:41 2010
New Revision: 201933
URL: http://svn.freebsd.org/changeset/base/201933

Log:
  Let ppp(8) use utmpx.
  
  This is a great example of what's so nice about utmpx. Because we use
  separate cookies to identify the entry instead of the TTY name, we don't
  need ugly hacks to perform any logging. We can just create entries
  without a TTY.

Modified:
  user/ed/utmpx/usr.sbin/Makefile
  user/ed/utmpx/usr.sbin/ppp/id.c
  user/ed/utmpx/usr.sbin/ppp/id.h
  user/ed/utmpx/usr.sbin/ppp/physical.c

Modified: user/ed/utmpx/usr.sbin/Makefile
==============================================================================
--- user/ed/utmpx/usr.sbin/Makefile	Sat Jan  9 21:23:39 2010	(r201932)
+++ user/ed/utmpx/usr.sbin/Makefile	Sat Jan  9 21:57:41 2010	(r201933)
@@ -135,6 +135,7 @@ SUBDIR=	${_ac} \
 	${_pnpinfo} \
 	${_portsnap} \
 	powerd \
+	${_ppp} \
 	${_pppctl} \
 	${_praliases} \
 	${_praudit} \

Modified: user/ed/utmpx/usr.sbin/ppp/id.c
==============================================================================
--- user/ed/utmpx/usr.sbin/ppp/id.c	Sat Jan  9 21:23:39 2010	(r201932)
+++ user/ed/utmpx/usr.sbin/ppp/id.c	Sat Jan  9 21:57:41 2010	(r201933)
@@ -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();
 }
 

Modified: user/ed/utmpx/usr.sbin/ppp/id.h
==============================================================================
--- user/ed/utmpx/usr.sbin/ppp/id.h	Sat Jan  9 21:23:39 2010	(r201932)
+++ user/ed/utmpx/usr.sbin/ppp/id.h	Sat Jan  9 21:57:41 2010	(r201933)
@@ -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 *, s
 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 *,
 #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))

Modified: user/ed/utmpx/usr.sbin/ppp/physical.c
==============================================================================
--- user/ed/utmpx/usr.sbin/ppp/physical.c	Sat Jan  9 21:23:39 2010	(r201932)
+++ user/ed/utmpx/usr.sbin/ppp/physical.c	Sat Jan  9 21:57:41 2010	(r201933)
@@ -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, "%dppp", (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, "%dppp", (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
       /* 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;
   }
 }
 


More information about the svn-src-user mailing list