]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
utmp: move `failtmp()`
authorIker Pedrosa <ipedrosa@redhat.com>
Tue, 18 Jul 2023 14:36:35 +0000 (16:36 +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 btmp.

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

index 066c3d16915ef27195bf2cf1c14376f3d1384c90..46b7d028f20886cbe3978c93d792acb6c8906e9d 100644 (file)
@@ -491,6 +491,13 @@ extern struct utmp *prepare_utmp (const char *name,
                                   const char *host,
                                   /*@null@*/const struct utmp *ut);
 extern int setutmp (struct utmp *ut);
+/*
+ * failtmp - update the cumulative failure log
+ *
+ *     failtmp updates the (struct utmp) formatted failure log which
+ *     maintains a record of all login failures.
+ */
+extern void failtmp (const char *username, const struct utmp *);
 
 /* valid.c */
 extern bool valid (const char *, const struct passwd *);
index 4c434a0b353f13df965095bf2f34a4528b569741..df8614a24191f13f406110cecf750c2d1ce3174b 100644 (file)
@@ -16,7 +16,6 @@
 #include <unistd.h>
 #include "defines.h"
 #include "faillog.h"
-#include "getdef.h"
 #include "failure.h"
 #define        YEAR    (365L*DAY)
 /*
@@ -234,56 +233,3 @@ void failprint (const struct faillog *fail)
                       fail->fail_cnt, lasttime, fail->fail_line);
        /*@=formatconst@*/
 }
-
-/*
- * failtmp - update the cumulative failure log
- *
- *     failtmp updates the (struct utmp) formatted failure log which
- *     maintains a record of all login failures.
- */
-
-void failtmp (const char *username, const struct utmp *failent)
-{
-       const char *ftmp;
-       int fd;
-
-       /*
-        * Get the name of the failure file.  If no file has been defined
-        * in login.defs, don't do this.
-        */
-
-       ftmp = getdef_str ("FTMP_FILE");
-       if (NULL == ftmp) {
-               return;
-       }
-
-       /*
-        * Open the file for append.  It must already exist for this
-        * feature to be used.
-        */
-
-       if (access (ftmp, F_OK) != 0) {
-               return;
-       }
-
-       fd = open (ftmp, O_WRONLY | O_APPEND);
-       if (-1 == fd) {
-               SYSLOG ((LOG_WARN,
-                        "Can't append failure of user %s to %s.",
-                        username, ftmp));
-               return;
-       }
-
-       /*
-        * Append the new failure record and close the log file.
-        */
-
-       if (   (write (fd, failent, sizeof *failent) != (ssize_t) sizeof *failent)
-           || (close (fd) != 0)) {
-               SYSLOG ((LOG_WARN,
-                        "Can't append failure of user %s to %s.",
-                        username, ftmp));
-               (void) close (fd);
-       }
-}
-
index 374e54cc061d5d5a8378fb05446e687c72b3dc32..1352b68c1e3b1b8c132f48d86b6a0eaca88af1ca 100644 (file)
@@ -13,7 +13,6 @@
 
 #include "defines.h"
 #include "faillog.h"
-#include <utmp.h>
 
 /*
  * failure - make failure entry
@@ -41,13 +40,5 @@ extern int failcheck (uid_t uid, struct faillog *fl, bool failed);
  */
 extern void failprint (const struct faillog *);
 
-/*
- * failtmp - update the cumulative failure log
- *
- *     failtmp updates the (struct utmp) formatted failure log which
- *     maintains a record of all login failures.
- */
-extern void failtmp (const char *username, const struct utmp *);
-
 #endif
 
index c1bc1972563a44a9d0037aaf0347fe4ba9312b71..7441cbf8c5d4aa015e66ca62cb0a7f829f81368d 100644 (file)
@@ -11,6 +11,7 @@
 
 #include "defines.h"
 #include "prototypes.h"
+#include "getdef.h"
 
 #include <utmp.h>
 #include <assert.h>
@@ -19,6 +20,7 @@
 #include <sys/socket.h>
 #include <netdb.h>
 #include <stdio.h>
+#include <fcntl.h>
 
 #include "alloc.h"
 
@@ -53,6 +55,57 @@ static bool is_my_tty (const char tty[UT_LINESIZE])
        return strcmp (full_tty, tmptty) == 0;
 }
 
+/*
+ * failtmp - update the cumulative failure log
+ *
+ *     failtmp updates the (struct utmp) formatted failure log which
+ *     maintains a record of all login failures.
+ */
+void failtmp (const char *username, const struct utmp *failent)
+{
+       const char *ftmp;
+       int fd;
+
+       /*
+        * Get the name of the failure file.  If no file has been defined
+        * in login.defs, don't do this.
+        */
+
+       ftmp = getdef_str ("FTMP_FILE");
+       if (NULL == ftmp) {
+               return;
+       }
+
+       /*
+        * Open the file for append.  It must already exist for this
+        * feature to be used.
+        */
+
+       if (access (ftmp, F_OK) != 0) {
+               return;
+       }
+
+       fd = open (ftmp, O_WRONLY | O_APPEND);
+       if (-1 == fd) {
+               SYSLOG ((LOG_WARN,
+                        "Can't append failure of user %s to %s.",
+                        username, ftmp));
+               return;
+       }
+
+       /*
+        * Append the new failure record and close the log file.
+        */
+
+       if (   (write (fd, failent, sizeof *failent) != (ssize_t) sizeof *failent)
+           || (close (fd) != 0)) {
+               SYSLOG ((LOG_WARN,
+                        "Can't append failure of user %s to %s.",
+                        username, ftmp));
+               (void) close (fd);
+       }
+}
+
 /*
  * get_current_utmp - return the most probable utmp entry for the current
  *                    session