]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Add maximum padding to fit IPv6-Addresses 259/head
authorInrin <inrin@caesia.net>
Sun, 24 May 2020 21:22:34 +0000 (23:22 +0200)
committerInrin <inrin@caesia.net>
Sun, 24 May 2020 21:48:25 +0000 (23:48 +0200)
We use a fixed padding for the From column to fit the maximum of a
minimized IPv6-LL-Address and it's interface.

src/lastlog.c

index c1caedb06ebd458d4089adc085ece66876cfdebb..492ac67efdfb7909bc653f51fc741129244b3fe1 100644 (file)
@@ -42,6 +42,9 @@
 #include <sys/types.h>
 #include <time.h>
 #include <assert.h>
+#ifdef HAVE_LL_HOST
+#include <net/if.h>
+#endif
 #include "defines.h"
 #include "prototypes.h"
 #include "getdef.h"
@@ -109,6 +112,10 @@ static void print_one (/*@null@*/const struct passwd *pw)
        char ptime[80];
 #endif
 
+#ifdef HAVE_LL_HOST
+       int maxIPv6Addrlen;
+#endif
+
        if (NULL == pw) {
                return;
        }
@@ -150,7 +157,17 @@ static void print_one (/*@null@*/const struct passwd *pw)
        /* Print the header only once */
        if (!once) {
 #ifdef HAVE_LL_HOST
-               puts (_("Username         Port     From             Latest"));
+               /*
+                * ll_host is in minimized form, thus the maximum IPv6 address possible is
+                * 8*4+7 = 39 characters.
+                * RFC 4291 2.5.6 states that for LL-addresses fe80+only the interface ID is set,
+                * thus having a maximum size of 25+1+IFNAMSIZ.
+                * POSIX says IFNAMSIZ should be 16 characters long including the null byte, thus
+                * 25+1+IFNAMSIZ >= 42 > 39
+                */
+               /* Link-Local address + % + Interfacename */
+               maxIPv6Addrlen = 25+1+IFNAMSIZ;
+               printf (_("Username         Port     From%*sLatest\n"), maxIPv6Addrlen-3, " ");
 #else
                puts (_("Username                Port     Latest"));
 #endif
@@ -172,8 +189,8 @@ static void print_one (/*@null@*/const struct passwd *pw)
        }
 
 #ifdef HAVE_LL_HOST
-       printf ("%-16s %-8.8s %-16.16s %s\n",
-               pw->pw_name, ll.ll_line, ll.ll_host, cp);
+       printf ("%-16s %-8.8s %*s%s\n",
+               pw->pw_name, ll.ll_line, -maxIPv6Addrlen, ll.ll_host, cp);
 #else
        printf ("%-16s\t%-8.8s %s\n",
                pw->pw_name, ll.ll_line, cp);