]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
creating lastlog2 database in the tests
authorStefan Schubert <schubi@suse.de>
Tue, 30 Jan 2024 17:04:58 +0000 (18:04 +0100)
committerStefan Schubert <schubi@suse.de>
Tue, 30 Jan 2024 17:04:58 +0000 (18:04 +0100)
login-utils/lslogins.c
tests/ts/lslogins/checkuser
tests/ts/lslogins/create_db.sql [new file with mode: 0644]
tests/ts/lslogins/lastlog2.db [deleted file]

index 1a954bd5417d4b0bc4730d864226b7b40f8ecb48..c6958a464f4e4d1108a46fdfc6b5fbf76e914361 100644 (file)
@@ -1738,7 +1738,15 @@ int main(int argc, char *argv[])
                        ctl->time_mode = parse_time_mode(optarg);
                        break;
                case 'V':
-                       print_version(EXIT_SUCCESS);
+               {
+                       static const char *features[] = {
+#ifdef HAVE_LIBLASTLOG2
+                               "lastlog2",
+#endif
+                               NULL
+                       };
+                       print_version_with_features(EXIT_SUCCESS, features);
+               }
                case 'Z':
                {
 #ifdef HAVE_LIBSELINUX
index b04f824b51c6bd87c61d76587da0fb6d8321da44..9da3ac734f432b6a268b3435bb4ebda45bb38e44 100755 (executable)
@@ -10,23 +10,31 @@ 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
-       echo `$TS_CMD_LSLOGINS -L --lastlog2="${0%/*}/lastlog2.db" root` >> $TS_OUTPUT
-       ts_die "Cannot find correct last login Jan29/16:45 for user root in lastlog2.db"
-    fi    
+$TS_CMD_LSLOGINS --version|grep "lastlog2" >/dev/null
+if [ $? -ne 0 ]; then
+    ts_skip "lastlog2 not supported"
 fi
 
+sqlite3 $TS_SELF/lastlog2.db < $TS_SELF/create_db.sql
+
+# tests for lastlog2 environment
+$TS_CMD_LSLOGINS -L --lastlog2="${TS_SELF}/lastlog2.db" root |grep "test-tty" >/dev/null
+if [ $? -ne 0 ]; then
+    rm $TS_SELF/lastlog2.db
+    ts_die "Cannot find test-tty for user root in lastlog2.db"
+fi
+$TS_CMD_LSLOGINS -L --lastlog2="${TS_SELF}/lastlog2.db" root |grep "test-host" >/dev/null
+if [ $? -ne 0 ]; then
+    rm $TS_SELF/lastlog2.db
+    ts_die "Cannot find test-host for user root in lastlog2.db"
+fi
+$TS_CMD_LSLOGINS -L --lastlog2="${TS_SELF}/lastlog2.db" root |grep "Jan29/16:45" >/dev/null
+if [ $? -ne 0 ]; then
+    echo `$TS_CMD_LSLOGINS -L --lastlog2="${TS_SELF}/lastlog2.db" root` >> $TS_OUTPUT
+    rm $TS_SELF/lastlog2.db
+    ts_die "Cannot find correct last login Jan29/16:45 for user root in lastlog2.db"
+fi
+
+rm $TS_SELF/lastlog2.db
 ts_finalize
 
diff --git a/tests/ts/lslogins/create_db.sql b/tests/ts/lslogins/create_db.sql
new file mode 100644 (file)
index 0000000..c8a9e5a
--- /dev/null
@@ -0,0 +1,9 @@
+PRAGMA foreign_keys=OFF;
+BEGIN TRANSACTION;
+CREATE TABLE Lastlog2(Name TEXT PRIMARY KEY, Time INTEGER, TTY TEXT, RemoteHost TEXT, Service TEXT);
+INSERT INTO Lastlog2 VALUES('user1',1706543115,'test-tty','localhost','test');
+INSERT INTO Lastlog2 VALUES('user2',0,NULL,NULL,NULL);
+INSERT INTO Lastlog2 VALUES('user3',1706543115,NULL,NULL,NULL);
+INSERT INTO Lastlog2 VALUES('root',1706543115,'test-tty','test-host',NULL);
+INSERT INTO Lastlog2 VALUES('user5',1706543115,NULL,'localhost',NULL);
+COMMIT;
\ No newline at end of file
diff --git a/tests/ts/lslogins/lastlog2.db b/tests/ts/lslogins/lastlog2.db
deleted file mode 100644 (file)
index 2894308..0000000
Binary files a/tests/ts/lslogins/lastlog2.db and /dev/null differ