about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/include/utmps/utmpx.h3
-rw-r--r--src/utmps/utmps-utmpd.c26
2 files changed, 27 insertions, 2 deletions
diff --git a/src/include/utmps/utmpx.h b/src/include/utmps/utmpx.h
index dd68945..f0414fb 100644
--- a/src/include/utmps/utmpx.h
+++ b/src/include/utmps/utmpx.h
@@ -67,8 +67,9 @@ extern void logwtmp (char const *, char const *, char const *) ;
 #define UT_NAMESIZE UTMPS_UT_NAMESIZE
 #define UT_HOSTSIZE UTMPS_UT_HOSTSIZE
 
-/* Unused, but some packages (ex: procps-ng) require this macro to be present */
+/* Unused, but some packages (ex: procps-ng) require these macros to be present */
 #define UTMPX_FILE "/run/utmps/utmp"
+#define WTMPX_FILE "/run/utmps/wtmp"
 
 /* More old GNU/crap compatibility */
 #define ut_name ut_user
diff --git a/src/utmps/utmps-utmpd.c b/src/utmps/utmps-utmpd.c
index 17f4cab..af77a06 100644
--- a/src/utmps/utmps-utmpd.c
+++ b/src/utmps/utmps-utmpd.c
@@ -104,6 +104,11 @@ static int idmatch (unsigned short type, char const *id, struct utmpx const *b)
   return 0 ;
 }
 
+static inline int onestepback (void)
+{
+  return lseek(fd, -(off_t)sizeof(struct utmpx), SEEK_CUR) >= 0 ;
+}
+
 static void do_getent (void)
 {
   struct utmpx b ;
@@ -116,6 +121,12 @@ static void do_getent (void)
     answer(ESRCH) ;
     return ;
   }
+  if (!onestepback())
+  {
+    unlockit() ;
+    answer(errno) ;
+    return ;
+  }
   unlockit() ;
   utmps_utmpx_unpack(buf+1, &b) ;
   utmps_utmpx_pack(buf+1, &b) ;
@@ -145,11 +156,18 @@ static void do_getid (void)
     utmps_utmpx_unpack(sbuf+1, &b) ;
     if (idmatch(type, rbuf + USHORT_PACK, &b)) break ;
   }
+  if (!onestepback())
+  {
+    unlockit() ;
+    answer(errno) ;
+    return ;
+  }
   unlockit() ;
   buffer_putnoflush(buffer_1small, sbuf, 1 + sizeof(struct utmpx)) ;
   flush1() ;
 }
 
+
 static void do_getline (void)
 {
   char rbuf[UTMPS_UT_LINESIZE] ;
@@ -171,6 +189,12 @@ static void do_getline (void)
     if ((b.ut_type == LOGIN_PROCESS || b.ut_type == USER_PROCESS)
       && !strncmp(rbuf, b.ut_line, UTMPS_UT_LINESIZE - 1)) break ;
   }
+  if (!onestepback())
+  {
+    unlockit() ;
+    answer(errno) ;
+    return ;
+  }
   unlockit() ;
   buffer_putnoflush(buffer_1small, sbuf, 1 + sizeof(struct utmpx)) ;
   flush1() ;
@@ -197,7 +221,7 @@ static void do_putline (uid_t uid, gid_t gid)
     utmps_utmpx_unpack(tmp, &b) ;
     if (idmatch(u.ut_type, u.ut_id, &b) && !strncmp(u.ut_line, b.ut_line, UTMPS_UT_LINESIZE - 1))
     {
-      if (lseek(fd, -(off_t)sizeof(struct utmpx), SEEK_CUR) < 0)
+      if (!onestepback())
       {
         unlockit() ;
         answer(errno) ;