[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: difference between /tmp and other directory for loadable mkdir?
From: |
Chet Ramey |
Subject: |
Re: difference between /tmp and other directory for loadable mkdir? |
Date: |
Thu, 27 Dec 2018 14:50:23 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 |
On 12/26/18 2:56 PM, Eduardo A. Bustamante López wrote:
> On Wed, Dec 26, 2018 at 12:40:09PM -0600, Peng Yu wrote:
>> Hi,
>>
>> I can not mkdir -p . in /tmp/ via the loadable mkdir. What is the
>> difference between /tmp/ and other directories? I am on Mac OS X. Is
>> this a bug in mkdir?
The difference between /tmp and your home directory, at least in this
case, is that /tmp has the sticky bit (S_ISVTX) set.
> mkdir("/tmp/", 0777) = -1 EEXIST (File exists)
> stat("/tmp/", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=4096, ...}) = 0
> +++ exited with 0 +++
>
>
> My guess is that the "problem" has to do with how bash computes the
> `parent_mode':
>
> dualbus@debian:~/src/gnu/bash$ cat -n examples/loadables/mkdir.c | sed -n
> '106,114p'
> 106 /* Make the new mode */
> 107 original_umask = umask (0);
> 108 umask (original_umask);
> 109
> 110 nmode = (S_IRWXU | S_IRWXG | S_IRWXO) & ~original_umask;
> 111 parent_mode = nmode | (S_IWUSR|S_IXUSR); /* u+wx */
> 112
> 113 /* Adjust new mode based on mode argument */
> 114 nmode &= omode;
That's the POSIX algorithm for creating the intermediate directories and
setting the mode of the final created directory:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/mkdir.html#tag_20_79
but the code should probably perform the mkdir and chmod separately, as the
text suggests.
In any event, that's not the problem. The existing code tries to chmod the
directory even if it already exists, and doesn't take the non-permission
bits (SVTX/SUID/SGID) into account, as POSIX says it shouldn't. It should
probably attempt the chmod only if the user has specified a mode using
`-m mode'.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/