From: Stefan Schubert Date: Tue, 30 Jan 2024 13:11:00 +0000 (+0100) Subject: cleanup; Added testcase for lslogins and lastlog2 DB X-Git-Tag: v2.42-start~535^2~10 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=919a325cc1931a0331b9833e5808c1228d9645a8;p=thirdparty%2Futil-linux.git cleanup; Added testcase for lslogins and lastlog2 DB --- diff --git a/login-utils/Makemodule.am b/login-utils/Makemodule.am index 3b844472b0..d18d375d2f 100644 --- a/login-utils/Makemodule.am +++ b/login-utils/Makemodule.am @@ -251,7 +251,7 @@ lslogins_LDADD += -leconf endif if BUILD_LIBLASTLOG2 lslogins_CFLAGS += -I$(ul_liblastlog2_incdir) -lslogins_LDADD += -llastlog2 +lslogins_LDADD += liblastlog2.la endif endif # BUILD_LSLOGINS diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c index 7ba78f0995..1a954bd541 100644 --- a/login-utils/lslogins.c +++ b/login-utils/lslogins.c @@ -535,7 +535,7 @@ fail: #ifdef HAVE_LIBLASTLOG2 static int get_lastlog2(struct lslogins_control *ctl, const char *user, void *dst, int what) { - struct ll2_context *context = ll2_new_context(ctl->lastlog2_path); /* LL2_DEFAULT_DATABASE is default path */ + struct ll2_context *context = ll2_new_context(ctl->lastlog2_path); switch (what) { case LASTLOG_TIME: { @@ -548,7 +548,7 @@ static int get_lastlog2(struct lslogins_control *ctl, const char *user, void *ds } *t = res_time; break; - } + } case LASTLOG_LINE: { char *res_tty = NULL; @@ -561,7 +561,7 @@ static int get_lastlog2(struct lslogins_control *ctl, const char *user, void *ds free (res_tty); } break; - } + } case LASTLOG_HOST: { char *res_host = NULL; @@ -571,10 +571,10 @@ static int get_lastlog2(struct lslogins_control *ctl, const char *user, void *ds } if (res_host) { mem2strcpy(dst, res_host, strlen(res_host), strlen(res_host) + 1); - free (res_host); + free(res_host); } break; - } + } default: abort(); } @@ -594,7 +594,7 @@ static void get_lastlog(struct lslogins_control *ctl, uid_t uid, struct lastlog ll; #ifdef HAVE_LIBLASTLOG2 - if (get_lastlog2(ctl, user, dst, LASTLOG_TIME) >= 0) + if (get_lastlog2(ctl, user, dst, what) >= 0) return; #endif if (ctl->lastlogin_fd < 0 || @@ -878,7 +878,7 @@ static struct lslogins_user *get_user_info(struct lslogins_control *ctl, const c sizeof(user_wtmp->ut_line), sizeof(user_wtmp->ut_line) + 1);; } else - get_lastlog(ctl, user->uid, user->login, user->last_tty, LASTLOG_LINE); + get_lastlog(ctl, user->uid, user->login, user->last_tty, LASTLOG_LINE); break; case COL_LAST_HOSTNAME: user->last_hostname = xcalloc(1, sizeof(user_wtmp->ut_host) + 1); @@ -887,7 +887,7 @@ static struct lslogins_user *get_user_info(struct lslogins_control *ctl, const c sizeof(user_wtmp->ut_host), sizeof(user_wtmp->ut_host) + 1);; } else - get_lastlog(ctl, user->uid, user->login, user->last_hostname, LASTLOG_HOST); + get_lastlog(ctl, user->uid, user->login, user->last_hostname, LASTLOG_HOST); break; case COL_FAILED_LOGIN: if (user_btmp) { diff --git a/tests/commands.sh b/tests/commands.sh index cb8013ef4c..5674c5ff07 100644 --- a/tests/commands.sh +++ b/tests/commands.sh @@ -126,6 +126,7 @@ TS_CMD_SETSID=${TS_CMD_SETSID-"${ts_commandsdir}setsid"} TS_CMD_SWAPLABEL=${TS_CMD_SWAPLABEL:-"${ts_commandsdir}swaplabel"} TS_CMD_SWAPOFF=${TS_CMD_SWAPOFF:-"${ts_commandsdir}swapoff"} TS_CMD_SWAPON=${TS_CMD_SWAPON:-"${ts_commandsdir}swapon"} +TS_CMD_LSLOGINS=${TS_CMD_LSLOGINS:-"${ts_commandsdir}lslogins"} TS_CMD_UL=${TS_CMD_UL-"${ts_commandsdir}ul"} TS_CMD_UMOUNT=${TS_CMD_UMOUNT:-"${ts_commandsdir}umount"} TS_CMD_UNSHARE=${TS_CMD_UNSHARE:-"${ts_commandsdir}unshare"} diff --git a/tests/ts/lslogins/checkuser b/tests/ts/lslogins/checkuser new file mode 100755 index 0000000000..5f0f33a523 --- /dev/null +++ b/tests/ts/lslogins/checkuser @@ -0,0 +1,31 @@ +#!/bin/bash + +TS_TOPDIR="${0%/*}/../.." +TS_DESC="read logins" + +. "$TS_TOPDIR"/functions.sh +ts_init "$*" +ts_check_test_command "$TS_CMD_LSLOGINS" + +# +# lslogin +# +$TS_CMD_LSLOGINS --help|grep "\--lastlog2" >/dev/null +if [ $? -eq 0 ]; then + # tests for lastlog2 environment + $TS_CMD_LSLOGINS -L --lastlog2="${0%/*}/lastlog2.db" root |grep "test-tty" >/dev/null + if [ $? -ne 0 ]; then + ts_die "Cannot find test-tty for user root in lastlog2.db" + fi + $TS_CMD_LSLOGINS -L --lastlog2="${0%/*}/lastlog2.db" root |grep "test-host" >>/dev/null + if [ $? -ne 0 ]; then + ts_die "Cannot find test-host for user root in lastlog2.db" + fi + $TS_CMD_LSLOGINS -L --lastlog2="${0%/*}/lastlog2.db" root |grep "Jan29/16:45" >>/dev/null + if [ $? -ne 0 ]; then + ts_die "Cannot find correct last login Jan29/16:45 for user root in lastlog2.db" + fi +fi + +ts_finalize + diff --git a/tests/ts/lslogins/lastlog2.db b/tests/ts/lslogins/lastlog2.db new file mode 100644 index 0000000000..2894308423 Binary files /dev/null and b/tests/ts/lslogins/lastlog2.db differ