All of lore.kernel.org
 help / color / mirror / Atom feed
* Setting group/other write flags not honoured in open
@ 2020-10-31 15:05 Nicky Chorley
  2020-10-31 16:36 ` Marcelo Diop-Gonzalez
  0 siblings, 1 reply; 3+ messages in thread
From: Nicky Chorley @ 2020-10-31 15:05 UTC (permalink / raw)
  To: kernelnewbies

Hi folks,

I hope it's OK to ask this question here. I'm reading The Linux
Programming Interface and am beginning to get to grips with the file
oriented system calls.

I have a program that calls open to create a file, specifying the mode
flags for owner, group, other read and write. The file is created
sucessfully, but when I look at its permissions, I only see the read
perms set for group and others:

> ./create_file foo
> ls -l foo
-rw-r--r-- 1 nick users 0 Oct 31 14:52 foo

Why would that be? The entirety of my program is

#include <fcntl.h>
#include <unistd.h>

int main(int argc, char *argv[]) {
  int open_flags = O_CREAT | O_WRONLY | O_TRUNC;
  mode_t file_perms =
    S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;

  int output_fd = open(argv[1], open_flags, file_perms);

  close(output_fd);
}

I also ran the program with strace and the perms in the openat call are
as I would expect:

openat(AT_FDCWD, "foo", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3

I don't understand why the group and other write flags aren't being
set. Could someone help shed some light on this please?

I'm not sure what factors influence this, but I'm running openSUSE Leap
15.2, with kernel 5.3.18-lp152.47-default, gcc 7.5.0 and glibc 2.26.

Thanks,

Nicky

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Setting group/other write flags not honoured in open
  2020-10-31 15:05 Setting group/other write flags not honoured in open Nicky Chorley
@ 2020-10-31 16:36 ` Marcelo Diop-Gonzalez
  2021-01-08 15:09   ` Nicky Chorley
  0 siblings, 1 reply; 3+ messages in thread
From: Marcelo Diop-Gonzalez @ 2020-10-31 16:36 UTC (permalink / raw)
  To: Nicky Chorley; +Cc: kernelnewbies


[-- Attachment #1.1: Type: text/plain, Size: 1877 bytes --]

Hey, I think this is because the process's umask is changing the mode. In
fs/namei.c in the function lookup_open() there's this bit:

....
if (!IS_POSIXACL(dir->d_inode))
  mode &= ~current_umask();
....

the open(2) and umask(2) manpages will explain how to deal with it

-Marcelo



On Sat, Oct 31, 2020 at 11:06 AM Nicky Chorley <ndchorley@gmail.com> wrote:

> Hi folks,
>
> I hope it's OK to ask this question here. I'm reading The Linux
> Programming Interface and am beginning to get to grips with the file
> oriented system calls.
>
> I have a program that calls open to create a file, specifying the mode
> flags for owner, group, other read and write. The file is created
> sucessfully, but when I look at its permissions, I only see the read
> perms set for group and others:
>
> > ./create_file foo
> > ls -l foo
> -rw-r--r-- 1 nick users 0 Oct 31 14:52 foo
>
> Why would that be? The entirety of my program is
>
> #include <fcntl.h>
> #include <unistd.h>
>
> int main(int argc, char *argv[]) {
>   int open_flags = O_CREAT | O_WRONLY | O_TRUNC;
>   mode_t file_perms =
>     S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
>
>   int output_fd = open(argv[1], open_flags, file_perms);
>
>   close(output_fd);
> }
>
> I also ran the program with strace and the perms in the openat call are
> as I would expect:
>
> openat(AT_FDCWD, "foo", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
>
> I don't understand why the group and other write flags aren't being
> set. Could someone help shed some light on this please?
>
> I'm not sure what factors influence this, but I'm running openSUSE Leap
> 15.2, with kernel 5.3.18-lp152.47-default, gcc 7.5.0 and glibc 2.26.
>
> Thanks,
>
> Nicky
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>

[-- Attachment #1.2: Type: text/html, Size: 2684 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Setting group/other write flags not honoured in open
  2020-10-31 16:36 ` Marcelo Diop-Gonzalez
@ 2021-01-08 15:09   ` Nicky Chorley
  0 siblings, 0 replies; 3+ messages in thread
From: Nicky Chorley @ 2021-01-08 15:09 UTC (permalink / raw)
  To: Marcelo Diop-Gonzalez; +Cc: kernelnewbies


[-- Attachment #1.1: Type: text/plain, Size: 2136 bytes --]

I realised I never got back to this. Thanks Marcelo for that - I'll look
into it.

Best,

Nicky

On Sat, 31 Oct 2020 at 16:36, Marcelo Diop-Gonzalez <marcelo827@gmail.com>
wrote:

> Hey, I think this is because the process's umask is changing the mode. In
> fs/namei.c in the function lookup_open() there's this bit:
>
> ....
> if (!IS_POSIXACL(dir->d_inode))
>   mode &= ~current_umask();
> ....
>
> the open(2) and umask(2) manpages will explain how to deal with it
>
> -Marcelo
>
>
>
> On Sat, Oct 31, 2020 at 11:06 AM Nicky Chorley <ndchorley@gmail.com>
> wrote:
>
>> Hi folks,
>>
>> I hope it's OK to ask this question here. I'm reading The Linux
>> Programming Interface and am beginning to get to grips with the file
>> oriented system calls.
>>
>> I have a program that calls open to create a file, specifying the mode
>> flags for owner, group, other read and write. The file is created
>> sucessfully, but when I look at its permissions, I only see the read
>> perms set for group and others:
>>
>> > ./create_file foo
>> > ls -l foo
>> -rw-r--r-- 1 nick users 0 Oct 31 14:52 foo
>>
>> Why would that be? The entirety of my program is
>>
>> #include <fcntl.h>
>> #include <unistd.h>
>>
>> int main(int argc, char *argv[]) {
>>   int open_flags = O_CREAT | O_WRONLY | O_TRUNC;
>>   mode_t file_perms =
>>     S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
>>
>>   int output_fd = open(argv[1], open_flags, file_perms);
>>
>>   close(output_fd);
>> }
>>
>> I also ran the program with strace and the perms in the openat call are
>> as I would expect:
>>
>> openat(AT_FDCWD, "foo", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
>>
>> I don't understand why the group and other write flags aren't being
>> set. Could someone help shed some light on this please?
>>
>> I'm not sure what factors influence this, but I'm running openSUSE Leap
>> 15.2, with kernel 5.3.18-lp152.47-default, gcc 7.5.0 and glibc 2.26.
>>
>> Thanks,
>>
>> Nicky
>>
>> _______________________________________________
>> Kernelnewbies mailing list
>> Kernelnewbies@kernelnewbies.org
>> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>
>

[-- Attachment #1.2: Type: text/html, Size: 3227 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-01-08 15:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-31 15:05 Setting group/other write flags not honoured in open Nicky Chorley
2020-10-31 16:36 ` Marcelo Diop-Gonzalez
2021-01-08 15:09   ` Nicky Chorley

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.