[Gambas-user] [Gambas Bug Tracker] Bug #1216: umask ignored by gambas while Mkdir command used

bugtracker at gambaswiki.org bugtracker at gambaswiki.org
Sun Dec 3 01:49:56 CET 2017


http://gambaswiki.org/bugtracker/edit?object=BUG.1216&from=L21haW4-

Comment #5 by Damien COTTIER:

You're right, this is the behavior of mkdir command call in shell bash interpreter.
My understanding is that umask is a process attribute, normally propagated to the child.

I suppose if i have a UMASK environment variable, bash will fork child process with such umask attribute.
That the reason that /bin/mkdir command executed from a bash with UMASK environment variable set the attribute properly.

taken for man bash
=================================

COMMAND EXECUTION ENVIRONMENT
       The shell has an execution environment, which consists of  the  follow‐
       ing:

       ·      open  files inherited by the shell at invocation, as modified by
              redirections supplied to the exec builtin

       ·      the current working directory as set by cd, pushd, or  popd,  or
              inherited by the shell at invocation

       ·      the  file  creation  mode mask as set by umask or inherited from
              the shell's parent

=================================


umask is a process attribute
that can be changed by the following api
    mode_t umask(mode_t mask);

do you use this api while the gambas interpreter process is started.
I suppose that if the shell (ex bash) is forking gambas interpreter
it would inherit the umask attribute of his parent


taken from http://www.tutorialspoint.com/unix_system_calls/mkdir.htm
mkdir system call is doing: (mode & ~umask & 0777) where umask is taken from the process

==================================
DESCRIPTION

mkdir() attempts to create a directory named pathname.

The parameter mode specifies the permissions to use. It is modified by the process’s umask in the usual way: the permissions of the created directory are (mode & ~umask & 0777). Other mode bits of the created directory depend on the operating system. For Linux, see below.

The newly created directory will be owned by the effective user ID of the process. If the directory containing the file has the set-group-ID bit set, or if the filesystem is mounted with BSD group semantics, the new directory will inherit the group ownership from its parent; otherwise it will be owned by the effective group ID of the process.

If the parent directory has the set-group-ID bit set then so will the newly created directory.

.... below:

NOTES
Under Linux apart from the permission bits, only the S_ISVTX mode bit is honored. That is, under Linux the created directory actually gets mode (mode & ~umask & 01777). See also stat(2).

There are many infelicities in the protocol underlying NFS. Some of these affect mkdir(). 

==================================

Indeed you're right, even if umask is properly passed to gambas interpreter meaning 0002 in our case,
the mkdir system call requiere a mode and that mode is set in gambas to 0x755
allowing us to be more restrictive by umask but not more permissive due to (mode & ~umask & 01777) done in Linux.


However this pb should also occur with bash and /bin/mkdir program... then i checked and found that:

http://www.linfo.org/mkdir.html
==================================
New directories are by default created with the read, write and execute (i.e., run as a program if a program) permissions enabled for the owner (i.e., the creator of the directory by default) and group and the read and execute permissions enabled for other users.
==================================

The /sbin/mkdir command seem to use 0775 by default and not 0755.




More information about the User mailing list