]> git.cameronkatri.com Git - pw-darwin.git/commitdiff
make pw_init and gr_init fail if the specified master password or group file is
authorBaptiste Daroussin <bapt@FreeBSD.org>
Mon, 29 Oct 2012 17:19:43 +0000 (17:19 +0000)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Mon, 29 Oct 2012 17:19:43 +0000 (17:19 +0000)
a directory.

MFC after: 1 month

libutil/gr_util.c
libutil/pw_util.c

index 0173595c24d0fb3cad6b9a4329e3946ad15fbdfe..323d3ff8ee3e0f853750271843db330779e5f001 100644 (file)
@@ -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);
 }
index 4bf3001ffe79b6f2e7b98c829b98ca51aa1460aa..6013e6d0640fa8de0a9817f6439683d3c577a6d8 100644 (file)
@@ -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