summaryrefslogtreecommitdiff
path: root/lib/mkdir-p.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2005-12-20 14:23:20 +0000
committerJim Meyering <jim@meyering.net>2005-12-20 14:23:20 +0000
commitd0344cfc55944d3993667c5b41bd9234ad35e4d4 (patch)
treef01109190744bde8f9afc3a7b5fa915537d1f6d2 /lib/mkdir-p.c
parent0b7757fac4176d8c080b20dca28e3245f86504a1 (diff)
downloadcoreutils-d0344cfc55944d3993667c5b41bd9234ad35e4d4.tar.xz
(RW_USR): Remove definition.
(make_dir_parents): Use S_IRWXU, now that read access is also required. Avoid a race condition, on systems where open honors O_NOFOLLOW. (make_dir_parents): Include chdir-safer.h. Use chdir_no_follow in place of chdir.
Diffstat (limited to 'lib/mkdir-p.c')
-rw-r--r--lib/mkdir-p.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/mkdir-p.c b/lib/mkdir-p.c
index 3923fbee1..1fd577994 100644
--- a/lib/mkdir-p.c
+++ b/lib/mkdir-p.c
@@ -39,14 +39,13 @@
#include "gettext.h"
#define _(msgid) gettext (msgid)
-#include "save-cwd.h"
+#include "chdir-safer.h"
#include "dirname.h"
#include "error.h"
#include "quote.h"
+#include "save-cwd.h"
#include "stat-macros.h"
-#define WX_USR (S_IWUSR | S_IXUSR)
-
/* Ensure that the directory ARG exists.
Create any leading directories that don't already exist, with
@@ -128,10 +127,10 @@ make_dir_parents (char const *arg,
strip_trailing_slashes (dir);
full_dir = dir;
- /* If leading directories shouldn't be writable or executable,
+ /* If leading directories shouldn't be readable, writable or executable,
or should have set[ug]id or sticky bits set and we are setting
their owners, we need to fix their permissions after making them. */
- if (((parent_mode & WX_USR) != WX_USR)
+ if (((parent_mode & S_IRWXU) != S_IRWXU)
|| ((owner != (uid_t) -1 || group != (gid_t) -1)
&& (parent_mode & (S_ISUID | S_ISGID | S_ISVTX)) != 0))
{
@@ -223,7 +222,7 @@ make_dir_parents (char const *arg,
mkdir process O(n^2) file name components. */
if (do_chdir)
{
- if (chdir (basename_dir) == 0)
+ if (chdir_no_follow (basename_dir) == 0)
dir_known_to_exist = true;
else if (dir_known_to_exist)
{