From: Iker Pedrosa Date: Tue, 18 Jul 2023 14:36:35 +0000 (+0200) Subject: utmp: move `failtmp()` X-Git-Tag: 4.14.0-rc1~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b6ca83ea4c4404771d896a23c3ac7fbb4d44a4d1;p=thirdparty%2Fshadow.git utmp: move `failtmp()` The functionality from this function is related to btmp. Signed-off-by: Iker Pedrosa --- diff --git a/lib/prototypes.h b/lib/prototypes.h index 066c3d169..46b7d028f 100644 --- a/lib/prototypes.h +++ b/lib/prototypes.h @@ -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 *); diff --git a/libmisc/failure.c b/libmisc/failure.c index 4c434a0b3..df8614a24 100644 --- a/libmisc/failure.c +++ b/libmisc/failure.c @@ -16,7 +16,6 @@ #include #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); - } -} - diff --git a/libmisc/failure.h b/libmisc/failure.h index 374e54cc0..1352b68c1 100644 --- a/libmisc/failure.h +++ b/libmisc/failure.h @@ -13,7 +13,6 @@ #include "defines.h" #include "faillog.h" -#include /* * 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 diff --git a/libmisc/utmp.c b/libmisc/utmp.c index c1bc19725..7441cbf8c 100644 --- a/libmisc/utmp.c +++ b/libmisc/utmp.c @@ -11,6 +11,7 @@ #include "defines.h" #include "prototypes.h" +#include "getdef.h" #include #include @@ -19,6 +20,7 @@ #include #include #include +#include #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