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>
*/
#include <stdio.h>
+#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
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' },
}
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;