This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.mkdir() handles SETGID inconsistently
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: akuchling, barry, dgrassi, jvr, lniles, loewis
Priority: normal Keywords:

Created on 2002-04-05 19:31 by lniles, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Messages (9)
msg10180 - (view) Author: Les Niles (lniles) Date: 2002-04-05 19:31
Under FreeBSD 4.4, with the 2.1.2, 2.1.1 or 1.5.2 
library, os.mkdir() does NOT set the SETGID or SETUID 
bits, regardless of whether they're specified in the 
mode argument to os.mkdir().  The bits can be set via 
a call to os.chmod().  This behavior appears to be 
inherited from FreeBSD's mkdir() os call.  On Linux, 
the SETGID/SETUID bits are set via os.mkdir()'s mode 
argument.  (As near as I can tell, POSIX.1 specifies 
yet a different behavior.)  This is a bug from the 
standpoint of Python's os module providing a uniform 
interface.
 
msg10181 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2002-04-05 23:50
Logged In: YES 
user_id=21627

This is not a bug. The posix module exposes functions from
the OS as-is, not trying to unify them. The os module
re-exposes those functions where available. Minor details of
the behaviour of those functions across platforms are
acceptable. For example, on Windows, os.mkdir does not set
any bits. Instead, ACLs are inherited according to the OS
semantics (i.e. it does on NTFS, but doesn't on FAT32).

If you need a function that makes certain additional
guarantees, write a new function.
msg10182 - (view) Author: Dan Grassi (dgrassi) Date: 2002-04-18 16:08
Logged In: YES 
user_id=366473

On Mac OS X which is also a BSD derivative the mode argument to mkdir()is completely ignored.  This becomes more of an issue when makedirs() is used because a simple chmod (which does work) is not sufficient if multiple directories were created.
msg10183 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2002-04-18 17:40
Logged In: YES 
user_id=12800

It's also quite inconvenient for cross platform portability
because now you have to either always call os.chmod()
everytime you call os.mkdir(), or replace os.mkdir() with a
function that does that (so all call sites, even in library
modules actually DTRT).

IWBNI Python's default os.mkdir() provided that cross
platform compatibility.
msg10184 - (view) Author: Just van Rossum (jvr) * (Python triager) Date: 2002-04-18 18:04
Logged In: YES 
user_id=92689

For the record: I cannot reproduce what dgrassi
reports; the mod argument to os.mkdir() works for
me on MacOSX.
msg10185 - (view) Author: Dan Grassi (dgrassi) Date: 2002-04-18 20:23
Logged In: YES 
user_id=366473

Indeed MAC OS X mkdir() is correct, it abides by umask.
msg10186 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2002-04-19 08:21
Logged In: YES 
user_id=21627

POSIX specifies

  The file permission bits of the new directory shall be 
  initialized from mode. These file permission bits of 
  the mode shall be modified by the process' file creation 
  mask. When bits in mode other than the file permission
  bits are set, the meaning of these additional bits is 
  implementation-defined.

(see
http://www.opengroup.org/onlinepubs/007904975/functions/mkdir.html)

S_ISGID is such an additional bit, so its meaning is
implementation defined. Portability with respect to S_ISGID
cannot be achieved by implicitly invoking chmod afterwards:
S_ISGID might not be supported for directories at all, or
its meaning might vary from system to system.

So I'd rather honor system policies than trying to cheat them.

*If* somebody tries to produce a patch to provide that
feature, I'd require that a) there is an autoconf test for
it, instead of merely checking whether the system is
FreeBSD; b) no additional system call is made on systems
where mkdir already has the desired effect; and c) that this
deviation from the system's mkdir(2) is properly documented.

msg10187 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2002-04-19 14:13
Logged In: YES 
user_id=12800

Martin, I agree with all your requirements (this shouldn't
be construed as an offer to produce such a patch!)
msg10188 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2004-06-05 21:48
Logged In: YES 
user_id=11375

No one seems interested in providing a patch, and there's been no 
discussion of this bug for over two years, so I'm going to close it.
History
Date User Action Args
2022-04-10 16:05:11adminsetgithub: 36388
2002-04-05 19:31:08lnilescreate