]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
login: add MOTD_FIRSTONLY=
authorKarel Zak <kzak@redhat.com>
Tue, 12 May 2020 13:21:21 +0000 (15:21 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 12 May 2020 13:21:21 +0000 (15:21 +0200)
This login.defs option allow to configure login to be more compatible
with pam_motd.

Addresses: https://github.com/karelzak/util-linux/issues/1034
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/login.1
login-utils/login.c

index 1e2d3cb28990c60b080449e31eb111d9deb1feb1..24cd7d2bc1b52c5ab0446b996370e57ecaccdd5e 100644 (file)
@@ -168,6 +168,25 @@ PAM module.
 The directories in the
 .B MOTD_FILE
 are supported since version 2.36.
+.PP
+Note that
+.B login
+does not implement any filenames overriding behavior like pam_motd
+(see also MOTD_FIRSTONLY), but all content from all files is displayed.  It is
+recommended to keep extra logic in content generators and use /run/motd.d rather
+than rely on overriding behavior hardcoded in system tools.
+.RE
+.PP
+.B MOTD_FIRSTONLY (boolean)
+.RS 4
+Forces
+.B login
+to stop display content specified by
+.B MOTD_FILE
+after first accessible item in the list.  Note that a directory is one item in this case.
+This option allows to configure
+.B login
+semantic to be more compatible with pam_motd.
 .RE
 .PP
 .B LOGIN_PLAIN_PROMPT
index 0ea2fbb3fa030556322cf5c8cc27543b08d94510..4be8bcfaf3a3c30bc97111b96cf270edb6bf93b6 100644 (file)
@@ -267,14 +267,14 @@ static int motddir_filter(const struct dirent *d)
        return 1; /* accept */
 }
 
-static void motddir(const char *dirname)
+static int motddir(const char *dirname)
 {
-        int dd, nfiles, i;
+        int dd, nfiles, i, done = 0;
         struct dirent **namelist = NULL;
 
        dd = open(dirname, O_RDONLY|O_CLOEXEC|O_DIRECTORY);
        if (dd < 0)
-               return;
+               return 0;
 
        nfiles = scandirat(dd, ".", &namelist, motddir_filter, versionsort);
        if (nfiles <= 0)
@@ -290,6 +290,7 @@ static void motddir(const char *dirname)
                        if (fstat(fd, &st) == 0 && st.st_size > 0)
                                sendfile(fileno(stdout), fd, NULL, st.st_size);
                        close(fd);
+                       done++;
                }
        }
 
@@ -298,6 +299,7 @@ static void motddir(const char *dirname)
        free(namelist);
 done:
        close(dd);
+       return done;
 }
 #endif /* MOTDDIR_SUPPORT */
 
@@ -313,6 +315,9 @@ static void motd(void)
 {
        const char *mb;
        char *file, *list;
+       int firstonly, done = 0;
+
+       firstonly = getlogindefs_bool("MOTD_FIRSTONLY", 0);
 
        mb = getlogindefs_str("MOTD_FILE", _PATH_MOTDFILE);
        if (!mb || !*mb)
@@ -327,15 +332,17 @@ static void motd(void)
                        continue;
 #ifdef MOTDDIR_SUPPORT
                if (S_ISDIR(st.st_mode))
-                       motddir(file);
-               else
+                       done += motddir(file);
 #endif
                if (S_ISREG(st.st_mode) && st.st_size > 0) {
                        int fd = open(file, O_RDONLY, 0);
                        if (fd >= 0)
                                sendfile(fileno(stdout), fd, NULL, st.st_size);
                        close(fd);
+                       done++;
                }
+               if (firstonly && done)
+                       break;
        }
        free(list);
 }