summaryrefslogtreecommitdiff
path: root/src/mkdir.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2013-05-11 19:17:10 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2013-05-11 19:22:54 -0700
commite7198a67b8dd7f23925dfa40b7a90342e185f729 (patch)
tree783abb446c0b54bb34e1770442e1a5f824904341 /src/mkdir.c
parent7b65f8e92888ffe3ea7d0b3824affa1dfc76b8c5 (diff)
downloadcoreutils-e7198a67b8dd7f23925dfa40b7a90342e185f729.tar.xz
mkdir: don't assume umask equals POSIX default ACL mask
This fixes Bug#14371, reported by Killer Bassist. * NEWS: Document this. * src/mkdir.c (struct mkdir_options): Remove member ancestor_mode. New member umask_value. All uses changed. * src/mkdir.c (make_ancestor): Fix umask assumption. * src/mkdir.c, src/mkfifo.c, src/mknod.c (main): Leave umask alone. This requires invoking lchmod after creating the file, which introduces a race condition, but this can't be avoided on hosts with "POSIX" default ACLs, and there's no easy way with network file systems to tell what kind of host the directory is on. * tests/local.mk (all_tests): Add tests/mkdir/p-acl.sh. * tests/mkdir/p-acl.sh: New file.
Diffstat (limited to 'src/mkdir.c')
-rw-r--r--src/mkdir.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/mkdir.c b/src/mkdir.c
index a94f96e14..b36237a33 100644
--- a/src/mkdir.c
+++ b/src/mkdir.c
@@ -81,8 +81,8 @@ struct mkdir_options
made. */
int (*make_ancestor_function) (char const *, char const *, void *);
- /* Mode for ancestor directory. */
- mode_t ancestor_mode;
+ /* Umask value in effect. */
+ mode_t umask_value;
/* Mode for directory itself. */
mode_t mode;
@@ -112,10 +112,21 @@ static int
make_ancestor (char const *dir, char const *component, void *options)
{
struct mkdir_options const *o = options;
- int r = mkdir (component, o->ancestor_mode);
+ int r;
+ mode_t user_wx = S_IWUSR | S_IXUSR;
+ bool self_denying_umask = (o->umask_value & user_wx) != 0;
+ if (self_denying_umask)
+ umask (o->umask_value & ~user_wx);
+ r = mkdir (component, S_IRWXUGO);
+ if (self_denying_umask)
+ {
+ int mkdir_errno = errno;
+ umask (o->umask_value);
+ errno = mkdir_errno;
+ }
if (r == 0)
{
- r = ! (o->ancestor_mode & S_IRUSR);
+ r = (o->umask_value & S_IRUSR) != 0;
announce_mkdir (dir, options);
}
return r;
@@ -191,8 +202,8 @@ main (int argc, char **argv)
if (options.make_ancestor_function || specified_mode)
{
mode_t umask_value = umask (0);
-
- options.ancestor_mode = (S_IRWXUGO & ~umask_value) | (S_IWUSR | S_IXUSR);
+ umask (umask_value);
+ options.umask_value = umask_value;
if (specified_mode)
{
@@ -205,7 +216,7 @@ main (int argc, char **argv)
free (change);
}
else
- options.mode = S_IRWXUGO & ~umask_value;
+ options.mode = S_IRWXUGO;
}
exit (savewd_process_files (argc - optind, argv + optind,