From 919a325cc1931a0331b9833e5808c1228d9645a8 Mon Sep 17 00:00:00 2001 From: Stefan Schubert Date: Tue, 30 Jan 2024 14:11:00 +0100 Subject: [PATCH] cleanup; Added testcase for lslogins and lastlog2 DB --- login-utils/Makemodule.am | 2 +- login-utils/lslogins.c | 16 ++++++++-------- tests/commands.sh | 1 + tests/ts/lslogins/checkuser | 31 +++++++++++++++++++++++++++++++ tests/ts/lslogins/lastlog2.db | Bin 0 -> 12288 bytes 5 files changed, 41 insertions(+), 9 deletions(-) create mode 100755 tests/ts/lslogins/checkuser create mode 100644 tests/ts/lslogins/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 0000000000000000000000000000000000000000..2894308423bca678f997b852674da6212b4c3a89 GIT binary patch literal 12288 zc-rmQzfasS6bJC_N^jJ=TAvzBoK!PIf+Pw!vE#itwE(156QZU>}Iig++q9bGf z4*rNP-C?Pi+qD}KGaYLO(jt~hom%Ppku2Nq`8kn1*}a|aNGo}eO~#3qZJH$^=%tiI zR5Q(`--K!2qxqlI=-I*b4F4d9H;6a*f&c&j00000{!?cpYJL!ivz|`grK+3cI?WDS zW$&yFhp)oO%;J8rW=TeB zoN4ts%k_PrrzR((y}KH{JOKaz00000{#MhgHoTxolg!-WKV431mFs1#KNS7Y-0J5lRo|l~ z9p`HD!mdcOy(G06Q$6nmRAin%tYz1h+$GvJG3`|S`hB4FRG4hgY}m=_!?Ir++rSgE zyuw$4zw#~L@OQq#Spfh500000{NtuvUlcD0mAcyy_OZe9%2?YiM=huB`cuWjz)yw8 Bg&Y6? literal 0 Hc-jL100001 -- 2.47.3