Restore the '/' in the path before returning if we encounter an error.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2016 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
* Copyright (c) 2009-2017 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
/*
|
||||
* Create any parent directories needed by path (but not path itself).
|
||||
* Note that path is modified but is restored before it returns.
|
||||
*/
|
||||
bool
|
||||
sudo_mkdir_parents(char *path, uid_t uid, gid_t *gidp, mode_t mode, bool quiet)
|
||||
@@ -42,7 +43,6 @@ sudo_mkdir_parents(char *path, uid_t uid, gid_t *gidp, mode_t mode, bool quiet)
|
||||
struct stat sb;
|
||||
gid_t parent_gid = 0;
|
||||
char *slash = path;
|
||||
bool ret = true;
|
||||
debug_decl(sudo_mkdir_parents, SUDOERS_DEBUG_UTIL)
|
||||
|
||||
/* If no gid specified, inherit from parent dir. */
|
||||
@@ -63,22 +63,19 @@ sudo_mkdir_parents(char *path, uid_t uid, gid_t *gidp, mode_t mode, bool quiet)
|
||||
if (errno != EEXIST) {
|
||||
if (!quiet)
|
||||
sudo_warn(U_("unable to mkdir %s"), path);
|
||||
ret = false;
|
||||
break;
|
||||
goto bad;
|
||||
}
|
||||
/* Already exists, make sure it is a directory. */
|
||||
if (stat(path, &sb) != 0) {
|
||||
if (!quiet)
|
||||
sudo_warn(U_("unable to stat %s"), path);
|
||||
ret = false;
|
||||
break;
|
||||
goto bad;
|
||||
}
|
||||
if (!S_ISDIR(sb.st_mode)) {
|
||||
if (!quiet)
|
||||
sudo_warnx(U_("%s exists but is not a directory (0%o)"),
|
||||
path, (unsigned int) sb.st_mode);
|
||||
ret = false;
|
||||
break;
|
||||
goto bad;
|
||||
}
|
||||
/* Inherit gid of parent dir for ownership. */
|
||||
if (*gidp == (gid_t)-1)
|
||||
@@ -88,7 +85,11 @@ sudo_mkdir_parents(char *path, uid_t uid, gid_t *gidp, mode_t mode, bool quiet)
|
||||
}
|
||||
|
||||
/* Return parent gid if none was specified by caller. */
|
||||
if (ret && *gidp == (gid_t)-1)
|
||||
if (*gidp == (gid_t)-1)
|
||||
*gidp = parent_gid;
|
||||
debug_return_bool(ret);
|
||||
debug_return_bool(true);
|
||||
bad:
|
||||
/* We must restore the path before we return. */
|
||||
*slash = '/';
|
||||
debug_return_bool(false);
|
||||
}
|
||||
|
Reference in New Issue
Block a user