]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
last/lastb field truncation indicator
authorJason Stewart <support@eggplantsd.com>
Sun, 5 May 2024 06:49:28 +0000 (02:49 -0400)
committerJason Stewart <support@eggplantsd.com>
Sun, 5 May 2024 06:49:28 +0000 (02:49 -0400)
  - indicate truncated fields with an asterisk character
  - updated man page and unit tests

login-utils/last.1.adoc
login-utils/last.c
tests/expected/utmp/last-dns
tests/expected/utmp/last-ipv6-dns
tests/expected/utmp/last-ipv6-nodns
tests/expected/utmp/last-nodns

index a3b8afe039d98c05aac8264d70aae2c58a2e10de..099b281ccb32a499f0f3708b134af92c17cf7060 100644 (file)
@@ -82,7 +82,7 @@ Use ASCII *tab* characters to separate the columns in the output instead of spac
 Define the output timestamp _format_ to be one of _notime_, _short_, _full_, or _iso_. The _notime_ variant will not print any timestamps at all, _short_ is the default, and _full_ is the same as the *--fulltimes* option. The _iso_ variant will display the timestamp in ISO-8601 format. The ISO format contains timezone information, making it preferable when printouts are investigated outside of the system.
 
 *-w*, *--fullnames*::
-Display full user names and domain names in the output.
+Display full user names and domain names / IP addresses in the output.  Domain names and IP addresses are truncated to 16 characters, and user names are truncated to 8 characters when this flag is not specified.  An asterisk is set as the last character of truncated fields.
 
 *-x*, *--system*::
 Display the system shutdown entries and run level changes.
index f5a9fec0804c8b9bc435dd097f17d45688e6f379..0f92fef353ec58bde1536516ae9220641be6030f 100644 (file)
@@ -96,6 +96,8 @@ struct last_control {
        time_t present;         /* who where present at time_t */
        unsigned int time_fmt;  /* time format */
        char separator;        /* output separator */
+
+       bool fullnames_mode;
 };
 
 /* Double linked list of struct utmp's */
@@ -521,8 +523,19 @@ static int list(const struct last_control *ctl, struct utmpx *p, time_t logout_t
        if (r < 0)
                mem2strcpy(domain, p->ut_host, sizeof(p->ut_host), sizeof(domain));
 
+       /*
+        * set last displayed character to an asterisk when
+        * user/domain/ip fields are to be truncated in non-fullnames mode
+        */
+       if (!ctl->fullnames_mode && (strnlen(p->ut_user, sizeof(p->ut_user)) > ctl->name_len))
+               p->ut_user[ctl->name_len-1] = '*';
+
        if (ctl->showhost) {
                if (!ctl->altlist) {
+
+                       if (!ctl->fullnames_mode && (strnlen(domain, sizeof(domain)) > ctl->domain_len))
+                               domain[ctl->domain_len-1] = '*';
+
                        len = snprintf(final, sizeof(final),
                                "%-8.*s%c%-12.12s%c%-16.*s%c%-*.*s%c%-*.*s%c%s\n",
                                ctl->name_len, p->ut_user, ctl->separator, utline, ctl->separator,
@@ -958,7 +971,8 @@ int main(int argc, char **argv)
                .showhost = TRUE,
                .name_len = LAST_LOGIN_LEN,
                .time_fmt = LAST_TIMEFTM_SHORT,
-               .domain_len = LAST_DOMAIN_LEN
+               .domain_len = LAST_DOMAIN_LEN,
+               .fullnames_mode = false,
        };
        char **files = NULL;
        size_t i, nfiles = 0;
@@ -1055,6 +1069,7 @@ int main(int argc, char **argv)
                        ctl.until = (time_t) (p / 1000000);
                        break;
                case 'w':
+                       ctl.fullnames_mode = true;
                        if (ctl.name_len < sizeof_member(struct utmpx, ut_user))
                                ctl.name_len = sizeof_member(struct utmpx, ut_user);
                        if (ctl.domain_len < sizeof_member(struct utmpx, ut_host))
index 34012c7f12eb2c57deb28c4405f87361dc9785af..6a0ce54d7e2ff39a063c7fe9376606725884b1c5 100644 (file)
@@ -1,5 +1,5 @@
 ~~~ dns short ~~~
-IPv4     root         a.root-servers.n Wed Aug 28 13:00 - 14:00  (01:00)
+IPv4     root         a.root-servers.* Wed Aug 28 13:00 - 14:00  (01:00)
 
 wtmp-a begins Wed Aug 28 03:00:00 2013
 ~~~ dns long ~~~
index aa53a6451d4dff0d974f08fbaeff12a3c797e86d..9687b3f5a07d880b1b7a4bb3ce13b7588f981efa 100644 (file)
@@ -1,5 +1,5 @@
 ~~~ dns short ~~~
-IPv6     root         a.root-servers.n Wed Aug 28 20:30 - 20:40  (00:10)
+IPv6     root         a.root-servers.* Wed Aug 28 20:30 - 20:40  (00:10)
 
 wtmp-ipv6 begins Wed Aug 28 20:30:40 2013
 ~~~ dns long ~~~
index 65d422a452ae830c7f1a390f108a2475ac749811..5909d028c2acd86e976f3735ce20203238f19a30 100644 (file)
@@ -1,5 +1,5 @@
 ~~~ show ip ~~~
-IPv6     root         2001:503:ba3e::2 Wed Aug 28 20:30 - 20:40  (00:10)
+IPv6     root         2001:503:ba3e::* Wed Aug 28 20:30 - 20:40  (00:10)
 
 wtmp-ipv6 begins Wed Aug 28 20:30:40 2013
 ~~~ show ip last ~~~
index 5b9171de316c0ddad7004735c8039fbf66b4118d..9f874f726d718235b6d17e7ab073f6eb3dd03609 100644 (file)
@@ -1,5 +1,5 @@
 ~~~ basic output ~~~
-rick     long         never-gonna-logo Thu Jan  1 00:00 - 03:14 (24855+03:14)
+rick     long         never-gonna-log* Thu Jan  1 00:00 - 03:14 (24855+03:14)
 torvalds linux        hobby            Mon Aug 26 00:57    gone - no logout
 reboot   system boot  system-name      Wed Aug 28 18:00   still running
 reboot   system boot  system-name      Wed Aug 28 16:00 - 17:00  (01:00)
@@ -11,12 +11,12 @@ newtime  foo          three            Wed Aug 28 09:00 - 10:00  (01:00)
 oldtime  foo          four             Wed Aug 28 08:00 - 09:00  (01:00)
 init     foo          five             Wed Aug 28 07:00 - 08:00  (01:00)
 login    foo          six              Wed Aug 28 06:00 - 07:00  (01:00)
-user_pro foo          seven            Wed Aug 28 05:00 - 06:00  (01:00)
-accounti foo          nine             Wed Aug 28 03:00 - 04:00  (01:00)
+user_pr* foo          seven            Wed Aug 28 05:00 - 06:00  (01:00)
+account* foo          nine             Wed Aug 28 03:00 - 04:00  (01:00)
 
 wtmp-a begins Wed Aug 28 03:00:00 2013
 ~~~ include system ~~~
-rick     long         never-gonna-logo Thu Jan  1 00:00 - 03:14 (24855+03:14)
+rick     long         never-gonna-log* Thu Jan  1 00:00 - 03:14 (24855+03:14)
 torvalds linux        hobby            Mon Aug 26 00:57    gone - no logout
 reboot   system boot  system-name      Wed Aug 28 18:00   still running
 shutdown system down  system-name      Wed Aug 28 17:00 - 18:00  (01:00)
@@ -30,8 +30,8 @@ newtime  foo          three            Wed Aug 28 09:00 - 10:00  (01:00)
 oldtime  foo          four             Wed Aug 28 08:00 - 09:00  (01:00)
 init     foo          five             Wed Aug 28 07:00 - 08:00  (01:00)
 login    foo          six              Wed Aug 28 06:00 - 07:00  (01:00)
-user_pro foo          seven            Wed Aug 28 05:00 - 06:00  (01:00)
-accounti foo          nine             Wed Aug 28 03:00 - 04:00  (01:00)
+user_pr* foo          seven            Wed Aug 28 05:00 - 06:00  (01:00)
+account* foo          nine             Wed Aug 28 03:00 - 04:00  (01:00)
 
 wtmp-a begins Wed Aug 28 03:00:00 2013
 ~~~ show ip ~~~
@@ -43,7 +43,7 @@ torvalds linux        Mon Aug 26 00:57    gone - no logout
 
 wtmp-a begins Wed Aug 28 03:00:00 2013
 ~~~ full times shortopt ~~~
-rick     long         never-gonna-logo Thu Jan  1 00:00:00 1970 - Tue Jan 19 03:14:07 2038 (24855+03:14)
+rick     long         never-gonna-log* Thu Jan  1 00:00:00 1970 - Tue Jan 19 03:14:07 2038 (24855+03:14)
 torvalds linux        hobby            Mon Aug 26 00:57:08 1991   gone - no logout
 reboot   system boot  system-name      Wed Aug 28 18:00:00 2013   still running
 reboot   system boot  system-name      Wed Aug 28 16:00:00 2013 - Wed Aug 28 17:00:00 2013  (01:00)
@@ -55,12 +55,12 @@ newtime  foo          three            Wed Aug 28 09:00:00 2013 - Wed Aug 28 10:
 oldtime  foo          four             Wed Aug 28 08:00:00 2013 - Wed Aug 28 09:00:00 2013  (01:00)
 init     foo          five             Wed Aug 28 07:00:00 2013 - Wed Aug 28 08:00:00 2013  (01:00)
 login    foo          six              Wed Aug 28 06:00:00 2013 - Wed Aug 28 07:00:00 2013  (01:00)
-user_pro foo          seven            Wed Aug 28 05:00:00 2013 - Wed Aug 28 06:00:00 2013  (01:00)
-accounti foo          nine             Wed Aug 28 03:00:00 2013 - Wed Aug 28 04:00:00 2013  (01:00)
+user_pr* foo          seven            Wed Aug 28 05:00:00 2013 - Wed Aug 28 06:00:00 2013  (01:00)
+account* foo          nine             Wed Aug 28 03:00:00 2013 - Wed Aug 28 04:00:00 2013  (01:00)
 
 wtmp-a begins Wed Aug 28 03:00:00 2013
 ~~~ full times longopt ~~~
-rick     long         never-gonna-logo Thu Jan  1 00:00:00 1970 - Tue Jan 19 03:14:07 2038 (24855+03:14)
+rick     long         never-gonna-log* Thu Jan  1 00:00:00 1970 - Tue Jan 19 03:14:07 2038 (24855+03:14)
 torvalds linux        hobby            Mon Aug 26 00:57:08 1991   gone - no logout
 reboot   system boot  system-name      Wed Aug 28 18:00:00 2013   still running
 reboot   system boot  system-name      Wed Aug 28 16:00:00 2013 - Wed Aug 28 17:00:00 2013  (01:00)
@@ -72,12 +72,12 @@ newtime  foo          three            Wed Aug 28 09:00:00 2013 - Wed Aug 28 10:
 oldtime  foo          four             Wed Aug 28 08:00:00 2013 - Wed Aug 28 09:00:00 2013  (01:00)
 init     foo          five             Wed Aug 28 07:00:00 2013 - Wed Aug 28 08:00:00 2013  (01:00)
 login    foo          six              Wed Aug 28 06:00:00 2013 - Wed Aug 28 07:00:00 2013  (01:00)
-user_pro foo          seven            Wed Aug 28 05:00:00 2013 - Wed Aug 28 06:00:00 2013  (01:00)
-accounti foo          nine             Wed Aug 28 03:00:00 2013 - Wed Aug 28 04:00:00 2013  (01:00)
+user_pr* foo          seven            Wed Aug 28 05:00:00 2013 - Wed Aug 28 06:00:00 2013  (01:00)
+account* foo          nine             Wed Aug 28 03:00:00 2013 - Wed Aug 28 04:00:00 2013  (01:00)
 
 wtmp-a begins Wed Aug 28 03:00:00 2013
 ~~~ no time ~~~
-rick     long         never-gonna-logo   (24855+03:14)
+rick     long         never-gonna-log*   (24855+03:14)
 torvalds linux        hobby              no logout
 reboot   system boot  system-name        running
 reboot   system boot  system-name         (01:00)
@@ -89,8 +89,8 @@ newtime  foo          three               (01:00)
 oldtime  foo          four                (01:00)
 init     foo          five                (01:00)
 login    foo          six                 (01:00)
-user_pro foo          seven               (01:00)
-accounti foo          nine                (01:00)
+user_pr* foo          seven               (01:00)
+account* foo          nine                (01:00)
 ~~~ iso-8601 time ~~~
 rick     long         never-gonna-logout 1970-01-01T00:00:00+00:00 - 2038-01-19T03:14:07+00:00 (24855+03:14)
 torvalds linux        hobby            1991-08-26T00:57:08+00:00   gone - no logout
@@ -112,12 +112,12 @@ wtmp-a begins 2013-08-28T03:00:00+00:00
 oldtime  foo          four             Wed Aug 28 08:00    gone - no logout
 init     foo          five             Wed Aug 28 07:00 - 08:00  (01:00)
 login    foo          six              Wed Aug 28 06:00 - 07:00  (01:00)
-user_pro foo          seven            Wed Aug 28 05:00 - 06:00  (01:00)
-accounti foo          nine             Wed Aug 28 03:00 - 04:00  (01:00)
+user_pr* foo          seven            Wed Aug 28 05:00 - 06:00  (01:00)
+account* foo          nine             Wed Aug 28 03:00 - 04:00  (01:00)
 
 wtmp-a begins Wed Aug 28 03:00:00 2013
 ~~~ present ~~~
-rick     long         never-gonna-logo Thu Jan  1 00:00 - 03:14 (24855+03:14)
+rick     long         never-gonna-log* Thu Jan  1 00:00 - 03:14 (24855+03:14)
 torvalds linux        hobby            Mon Aug 26 00:57    gone - no logout
 runlevel foo          one              Wed Aug 28 11:00 - 12:00  (01:00)