]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
cleanup; Added testcase for lslogins and lastlog2 DB
authorStefan Schubert <schubi@suse.de>
Tue, 30 Jan 2024 13:11:00 +0000 (14:11 +0100)
committerStefan Schubert <schubi@suse.de>
Tue, 30 Jan 2024 13:11:00 +0000 (14:11 +0100)
login-utils/Makemodule.am
login-utils/lslogins.c
tests/commands.sh
tests/ts/lslogins/checkuser [new file with mode: 0755]
tests/ts/lslogins/lastlog2.db [new file with mode: 0644]

index 3b844472b007ff575c0d47275cc60399268a84d1..d18d375d2fc0e42f85537f8a7d939b98e0c045b1 100644 (file)
@@ -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
 
index 7ba78f0995c707f359cfd3731a6563bf18e5d267..1a954bd5417d4b0bc4730d864226b7b40f8ecb48 100644 (file)
@@ -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) {
index cb8013ef4c1b76bf6d7369a762d027f374e8708c..5674c5ff07ea04c2ae45f6f136f031f524c8b592 100644 (file)
@@ -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 (executable)
index 0000000..5f0f33a
--- /dev/null
@@ -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 (file)
index 0000000..2894308
Binary files /dev/null and b/tests/ts/lslogins/lastlog2.db differ