summaryrefslogtreecommitdiffstats
path: root/libutil
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2012-10-29 17:19:43 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2012-10-29 17:19:43 +0000
commitcb57f04cb26553c23feb9874da15b4386f68a98f (patch)
tree8d516f43d4f42d8be55284d31fb593d2f649bf3e /libutil
parent9c0cbb83460f1161374ff312897e5212fcf1dd78 (diff)
downloadpw-darwin-cb57f04cb26553c23feb9874da15b4386f68a98f.tar.gz
pw-darwin-cb57f04cb26553c23feb9874da15b4386f68a98f.tar.zst
pw-darwin-cb57f04cb26553c23feb9874da15b4386f68a98f.zip
make pw_init and gr_init fail if the specified master password or group file is
a directory. MFC after: 1 month
Diffstat (limited to 'libutil')
-rw-r--r--libutil/gr_util.c11
-rw-r--r--libutil/pw_util.c9
2 files changed, 20 insertions, 0 deletions
diff --git a/libutil/gr_util.c b/libutil/gr_util.c
index 0173595..323d3ff 100644
--- a/libutil/gr_util.c
+++ b/libutil/gr_util.c
@@ -63,6 +63,8 @@ static const char group_line_format[] = "%s:%s:%ju:";
int
gr_init(const char *dir, const char *group)
{
+ struct stat st;
+
if (dir == NULL) {
strcpy(group_dir, _PATH_ETC);
} else {
@@ -88,6 +90,15 @@ gr_init(const char *dir, const char *group)
}
strcpy(group_file, group);
}
+
+ if (stat(group_file, &st) == -1)
+ return (-1);
+
+ if (S_ISDIR(st.st_mode)) {
+ errno = EISDIR;
+ return (-1);
+ }
+
initialized = 1;
return (0);
}
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