]> granicus.if.org Git - sudo/commitdiff
In sudo_mkdir_parents() inherit the gid of / instead of using gid
authorTodd C. Miller <Todd.Miller@courtesan.com>
Sun, 30 Oct 2016 15:09:12 +0000 (09:09 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Sun, 30 Oct 2016 15:09:12 +0000 (09:09 -0600)
0 for the first component.

plugins/sudoers/mkdir_parents.c

index e2a7ca1ac839e2ba14d9a8272330756049c7bd12..53f1feb72bbf73f77bc94ba3ec0c7f1c66d9cc34 100644 (file)
@@ -40,13 +40,18 @@ bool
 sudo_mkdir_parents(char *path, uid_t uid, gid_t *gidp, mode_t mode, bool quiet)
 {
     struct stat sb;
-    gid_t parent_gid;
+    gid_t parent_gid = 0;
     char *slash = path;
     bool rval = true;
     debug_decl(sudo_mkdir_parents, SUDOERS_DEBUG_UTIL)
 
+    /* If no gid specified, inherit from parent dir. */
+    if (*gidp != (gid_t)-1)
+       parent_gid = *gidp;
+    else if (stat("/", &sb) == 0)
+       parent_gid = sb.st_gid;
+
     /* Create parent directories as needed. */
-    parent_gid = *gidp != (gid_t)-1 ? *gidp : 0;
     while ((slash = strchr(slash + 1, '/')) != NULL) {
        *slash = '\0';
        sudo_debug_printf(SUDO_DEBUG_DEBUG|SUDO_DEBUG_LINENO,