]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
nologin: require /etc/nologin.txt to be file
authorSami Kerola <kerolasa@iki.fi>
Tue, 6 Oct 2015 22:15:54 +0000 (23:15 +0100)
committerSami Kerola <kerolasa@iki.fi>
Sun, 18 Oct 2015 17:03:38 +0000 (18:03 +0100)
This makes silly practical jokes impossible, like for example symlinking
/dev/null or dev/random to /etc/nologin.txt

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
login-utils/nologin.c

index 3be50ca1219a3da48c4cb18dded9a72162284552..0a06ef8b6c00ce88b513030fc812a14b5588306c 100644 (file)
@@ -3,6 +3,7 @@
  */
 
 #include <stdio.h>
+#include <sys/stat.h>
 #include <sys/types.h>
 #include <fcntl.h>
 #include <string.h>
@@ -38,6 +39,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
 int main(int argc, char *argv[])
 {
        int c, fd;
+       struct stat st;
        static const struct option longopts[] = {
                { "help",    0, 0, 'h' },
                { "version", 0, 0, 'V' },
@@ -63,7 +65,8 @@ int main(int argc, char *argv[])
        }
 
        fd = open(_PATH_NOLOGIN_TXT, O_RDONLY);
-       if (fd >= 0) {
+       c = fstat(fd, &st);
+       if (fd >= 0 && !c && S_ISREG(st.st_mode)) {
                char buf[BUFSIZ];
                ssize_t rd;