cancel
Showing results for 
Search instead for 
Did you mean: 

umask

SOLVED
Go to solution
navin
Super Advisor

umask

Hello All,
In my server i did not set any umask value - but usually the file and dor craeted as 666.
I have a oracle user oracle . For that particular user ...the file mode is the same - but not when it creates using some pl / sql command .
Anyidea?
Thanks in advance
Learning ...
4 REPLIES
Michael Steele_2
Honored Contributor
Solution

Re: umask

In /etc/profile.d/umash.sh there should be this setting:

umask 022

Refer to this link:

http://www.linuxfromscratch.org/blfs/view/svn/postlfs/profile.html

Here is an example of /etc/profile.d/umask.sh:

cat > /etc/profile.d/umask.sh << "EOF"
# By default we want the umask to get set.
if [ "$(id -gn)" = "$(id -un)" -a $EUID -gt 99 ] ; then
umask 002
else
umask 022
fi
EOF

Support Fatherhood - Stop Family Law
James R. Ferguson
Acclaimed Contributor

Re: umask

Hi Navin:

Two things come into play when a file is created. First, when a 'create()' system call is performed, the code has the option of specifying an octal permissions value. The shell uses 666 for files. Whatever value is supplied, though, is subject to the application of the 'umaask' of the process. Hence if the 'umask' is 022 and the default permissions for the 'create()' are 666, the "subtraction" of the two means that the created file will have permissions of 644. With a creation mask of 666 and a 'umask' of 000, the file has permissions of 666.

If the code performing the file creation uses a creation mask of 644 (instead of 666), then even with a 'umask' of 000, a resulting file will have permissions of 644.

Hence, the creating code has the "upper limit" of the least restrictive permissions that will apply.

Regards!

...JRF...
navin
Super Advisor

Re: umask

James
Thanks for the reply.What determines the code to create file with umask 644 .How do we change it.Please any idea?
Thanks
Learning ...
James R. Ferguson
Acclaimed Contributor

Re: umask

Hi (again) Navin:

> What determines the code to create file with umask 644. How do we change it?

I'll use an example in C and in Perl --- the syntax is close and the concept is identical. The following code will create a file called "/tmp/myfile" with permissions of 644 (-rw-r--r--) *EVEN WHEN* your 'umask' has been set to zero (000). This demonstrates that setting the MODE during a 'creat()' to other than 666 (the default) takes away the user's ability to have a more permissive permissions by default.

In a shell, set your 'umask' to zero (000) and then run either of these pieces of code. You will need to compile the C code first, of course:

# cat mycreate.c
#include
#include
#include
int main() {
int fh;
unlink("/tmp/myfile");
fh = creat("/tmp/myfile",0644);
if (fh > 0) {
printf("file created\n");
}
else {
printf("errno %d\n", errno);
exit(1);
}
}

...or use:

# cat mycreate.pl
#!/usr/bin/perl
use strict;
use Fcntl;
my $file = '/tmp/myfile';
unlink $file;
sysopen( FH, $file, O_CREAT, 0644 ) or die "Error: $!\n";
print "file created\n";

...in either example, the MODE of the file during creation is set to octal 644. Hence, applying a umask of 000 or 022 still leaves a permission of 644 (-rw-r--r--) for the resulting file. Had the code used a default MODE of 666, then a umask of 000 would have given a file with octal permissions of 666.

Regards!

...JRF...
Server: AkamaiGHost Mime-Version: 1.0 Content-Type: text/html Content-Length: 215 Expires: Sun, 27 May 2018 08:21:37 GMT Date: Sun, 27 May 2018 08:21:37 GMT Connection: close Bad Request

Bad Request

Your browser sent a request that this server could not understand.

Reference #7.5f955b8.1527409297.0