mkdir: Fix created directory permissions

Previously, with -p, the specified directory and all of its parents
would be 0777&~filemask (regardless of the -m flag). POSIX says parent
directories must created as (0300|~filemask)&0777, and of course if -m
is set, the specified directory should be created with those
permissions.

Additionally, POSIX says that for symbolic_mode strings, + and - should
be interpretted relative to a default mode of 0777 (not 0).

Without -p, previously the directory would be created first with
0777&~filemask (before a chmod), but POSIX says that the directory shall
at no point in time have permissions less restrictive than the -m mode
argument.

Rather than dealing with mkdir removing the filemask bits by calling
chmod afterward, just clear the umask and remove the bits manually.
This commit is contained in:
Michael Forney
2016-12-14 19:40:06 -08:00
committed by Anselm R Garbe
parent 6ac5f01cc9
commit 529e50a7ad
4 changed files with 13 additions and 16 deletions

2
util.h
View File

@@ -75,6 +75,6 @@ long long strtonum(const char *, long long, long long, const char **);
long long enstrtonum(int, const char *, long long, long long);
long long estrtonum(const char *, long long, long long);
size_t unescape(char *);
int mkdirp(const char *);
int mkdirp(const char *, mode_t, mode_t);
#undef memmem
void *memmem(const void *, size_t, const void *, size_t);