aboutsummaryrefslogtreecommitdiff
path: root/toys/posix
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2013-09-05 04:28:40 -0500
committerRob Landley <rob@landley.net>2013-09-05 04:28:40 -0500
commit314dc6881f0439478f483d26726c52c1c3f536ff (patch)
tree1b8affa10549d3f7ac5fd98eee6f17501cf2aa91 /toys/posix
parent829497311b541b63e08aa17768c8e67e95b73638 (diff)
downloadtoybox-314dc6881f0439478f483d26726c52c1c3f536ff.tar.gz
Make chdir handle permissions according to posix, reported by Jacek Bukarewicz..
Diffstat (limited to 'toys/posix')
-rw-r--r--toys/posix/mkdir.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/toys/posix/mkdir.c b/toys/posix/mkdir.c
index 24930f4a..202eaa79 100644
--- a/toys/posix/mkdir.c
+++ b/toys/posix/mkdir.c
@@ -4,7 +4,7 @@
*
* See http://opengroup.org/onlinepubs/9699919799/utilities/mkdir.html
-USE_MKDIR(NEWTOY(mkdir, "<1pm:", TOYFLAG_BIN))
+USE_MKDIR(NEWTOY(mkdir, "<1pm:", TOYFLAG_BIN|TOYFLAG_UMASK))
config MKDIR
bool "mkdir"
@@ -30,7 +30,6 @@ static int do_mkdir(char *dir)
{
struct stat buf;
char *s;
- mode_t mode = 0777;
// mkdir -p one/two/three is not an error if the path already exists,
// but is if "three" is a file. The others we dereference and catch
@@ -44,6 +43,7 @@ static int do_mkdir(char *dir)
for (s=dir; ; s++) {
char save=0;
+ mode_t mode = 0777&~toys.old_umask;
// Skip leading / of absolute paths.
if (s!=dir && *s == '/' && (toys.optflags&FLAG_p)) {
@@ -52,9 +52,10 @@ static int do_mkdir(char *dir)
} else if (*s) continue;
// Use the mode from the -m option only for the last directory.
- if ((toys.optflags&FLAG_m) && save != '/') mode = TT.mode;
+ if (save == '/') mode |= 0300;
+ else if (toys.optflags&FLAG_m) mode = TT.mode;
- if (mkdir(dir, mode)<0 && ((toys.optflags&~FLAG_p) || errno != EEXIST))
+ if (mkdir(dir, mode)<0 && (!(toys.optflags&FLAG_p) || errno != EEXIST))
return 1;
if (!(*s = save)) break;