From cb57f04cb26553c23feb9874da15b4386f68a98f Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Mon, 29 Oct 2012 17:19:43 +0000 Subject: make pw_init and gr_init fail if the specified master password or group file is a directory. MFC after: 1 month --- libutil/pw_util.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'libutil/pw_util.c') diff --git a/libutil/pw_util.c b/libutil/pw_util.c index 4bf3001..6013e6d 100644 --- a/libutil/pw_util.c +++ b/libutil/pw_util.c @@ -96,6 +96,7 @@ pw_init(const char *dir, const char *master) #if 0 struct rlimit rlim; #endif + struct stat st; if (dir == NULL) { strcpy(passwd_dir, _PATH_ETC); @@ -123,6 +124,14 @@ pw_init(const char *dir, const char *master) strcpy(masterpasswd, master); } + if (stat(masterpasswd, &st) == -1) + return (-1); + + if (S_ISDIR(st.st_mode)) { + errno = EISDIR; + return (-1); + } + /* * The code that follows is extremely disruptive to the calling * process, and is therefore disabled until someone can conceive -- cgit v1.2.3