]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
utmp: move `update_utmp`
authorIker Pedrosa <ipedrosa@redhat.com>
Tue, 18 Jul 2023 14:48:02 +0000 (16:48 +0200)
committerSerge Hallyn <serge@hallyn.com>
Wed, 2 Aug 2023 15:13:28 +0000 (10:13 -0500)
The functionality from this function is related to utmp. Restrict access
to `setutmp()` to the same file.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
lib/prototypes.h
libmisc/utmp.c
src/login.c

index 46b7d028f20886cbe3978c93d792acb6c8906e9d..d288a038b79ec7600421c0795b2907e5822b2437 100644 (file)
@@ -490,7 +490,6 @@ extern struct utmp *prepare_utmp (const char *name,
                                   const char *line,
                                   const char *host,
                                   /*@null@*/const struct utmp *ut);
-extern int setutmp (struct utmp *ut);
 /*
  * failtmp - update the cumulative failure log
  *
@@ -498,6 +497,18 @@ extern int setutmp (struct utmp *ut);
  *     maintains a record of all login failures.
  */
 extern void failtmp (const char *username, const struct utmp *);
+/**
+ * @brief Update or create an utmp entry in utmp, wtmp, utmpw, or wtmpx
+ *
+ * @param[in] user username
+ * @param[in] tty tty
+ * @param[in] host hostname
+ * @param[in] utent utmp entry
+ */
+extern void update_utmp (const char *user,
+                         const char *tty,
+                         const char *host,
+                         /*@null@*/const struct utmp *utent);
 
 /* valid.c */
 extern bool valid (const char *, const struct passwd *);
index 7441cbf8c5d4aa015e66ca62cb0a7f829f81368d..4ffaedc5332ffb3d11463fb58ae61697da89798e 100644 (file)
@@ -339,7 +339,7 @@ static void updwtmp (const char *filename, const struct utmp *ut)
  *
  *     Return 1 on failure and 0 on success.
  */
-int setutmp (struct utmp *ut)
+static int setutmp (struct utmp *ut)
 {
        int err = 0;
 
@@ -358,3 +358,14 @@ int setutmp (struct utmp *ut)
 
        return err;
 }
+
+void update_utmp (const char *user,
+                  const char *tty,
+                  const char *host,
+                  /*@null@*/const struct utmp *utent)
+{
+       struct utmp  *ut  = prepare_utmp  (user, tty, host, utent);
+
+       (void) setutmp  (ut);   /* make entry in the utmp & wtmp files */
+       free (ut);
+}
index 58d6912670a01d65e83a9722009cf09ab2d7ee1b..749747b267e3f57fb4826a073bf697d44efafd65 100644 (file)
@@ -109,10 +109,6 @@ static void usage (void);
 static void setup_tty (void);
 static void process_flags (int argc, char *const *argv);
 static /*@observer@*/const char *get_failent_user (/*@returned@*/const char *user);
-static void update_utmp (const char *user,
-                         const char *tty,
-                         const char *host,
-                         /*@null@*/const struct utmp *utent);
 
 #ifndef USE_PAM
 static struct faillog faillog;
@@ -458,24 +454,6 @@ static /*@observer@*/const char *get_failent_user (/*@returned@*/const char *use
        return failent_user;
 }
 
-/*
- * update_utmp - Update or create an utmp entry in utmp, wtmp, utmpw, and
- *               wtmpx
- *
- *     utent should be the utmp entry returned by get_current_utmp (or
- *     NULL).
- */
-static void update_utmp (const char *user,
-                         const char *tty,
-                         const char *host,
-                         /*@null@*/const struct utmp *utent)
-{
-       struct utmp  *ut  = prepare_utmp  (user, tty, host, utent);
-
-       (void) setutmp  (ut);   /* make entry in the utmp & wtmp files */
-       free (ut);
-}
-
 /*
  * login - create a new login session for a user
  *