diff options
author | Shreenidhi Shedi <sshedi@vmware.com> | 2022-07-01 12:13:31 +0530 |
---|---|---|
committer | Shreenidhi Shedi <53473811+sshedi@users.noreply.github.com> | 2022-07-01 16:16:04 +0530 |
commit | 5d7fa71d4db6acffbda59363e0b415e9a484ed9a (patch) | |
tree | 390940da7d7467ef81a07c777529f16c1c856425 | |
parent | df0d27720e578a37b46ec938efff4f7ec4cdcb6c (diff) | |
download | pam-5d7fa71d4db6acffbda59363e0b415e9a484ed9a.tar.gz pam-5d7fa71d4db6acffbda59363e0b415e9a484ed9a.tar.bz2 pam-5d7fa71d4db6acffbda59363e0b415e9a484ed9a.zip |
faillock: refactor faillock info printing code
Move the code to it's own function.
Signed-off-by: Shreenidhi Shedi <sshedi@vmware.com>
-rw-r--r-- | modules/pam_faillock/main.c | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/modules/pam_faillock/main.c b/modules/pam_faillock/main.c index a5e2cd60..1370a0e2 100644 --- a/modules/pam_faillock/main.c +++ b/modules/pam_faillock/main.c @@ -127,6 +127,36 @@ usage(const char *progname) progname); } +static void +print_in_new_format(struct options *opts, const struct tally_data *tallies, const char *user) +{ + uint32_t i; + + printf("%s:\n", user); + printf("%-19s %-5s %-48s %-5s\n", "When", "Type", "Source", "Valid"); + + for (i = 0; i < tallies->count; i++) { + struct tm *tm; + uint16_t status; + time_t when = 0; + char timebuf[80]; + + status = tallies->records[i].status; + when = tallies->records[i].time; + + tm = localtime(&when); + if(tm == NULL) { + fprintf(stderr, "%s: Invalid timestamp in the tally record\n", + opts->progname); + continue; + } + strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tm); + printf("%-19s %-5s %-52.52s %s\n", timebuf, + status & TALLY_STATUS_RHOST ? "RHOST" : (status & TALLY_STATUS_TTY ? "TTY" : "SVC"), + tallies->records[i].source, status & TALLY_STATUS_VALID ? "V":"I"); + } +} + static int do_user(struct options *opts, const char *user) { @@ -181,8 +211,6 @@ do_user(struct options *opts, const char *user) } } else { - unsigned int i; - memset(&tallies, 0, sizeof(tallies)); if (read_tally(fd, &tallies) == -1) { fprintf(stderr, "%s: Error reading the tally file for %s:", @@ -192,26 +220,8 @@ do_user(struct options *opts, const char *user) return 5; } - printf("%s:\n", user); - printf("%-19s %-5s %-48s %-5s\n", "When", "Type", "Source", "Valid"); - - for (i = 0; i < tallies.count; i++) { - struct tm *tm; - char timebuf[80]; - uint16_t status = tallies.records[i].status; - time_t when = tallies.records[i].time; + print_in_new_format(opts, &tallies, user); - tm = localtime(&when); - if(tm == NULL) { - fprintf(stderr, "%s: Invalid timestamp in the tally record\n", - opts->progname); - continue; - } - strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tm); - printf("%-19s %-5s %-52.52s %s\n", timebuf, - status & TALLY_STATUS_RHOST ? "RHOST" : (status & TALLY_STATUS_TTY ? "TTY" : "SVC"), - tallies.records[i].source, status & TALLY_STATUS_VALID ? "V":"I"); - } free(tallies.records); } close(fd); |