0

There is a regular file file in the /tmp directory with write permissions -rw--w--w- 1 user1 user1 /tmp/file

When I try to open this file as a user (I run the code after su user2) who is not the owner of the file, I get Permission denied error:

int fd = open("/tmp/file", O_CREAT | O_WRONLY, 0622);
if (fd < 0)
{
    printf("%d, %s\n", fd, strerror(errno));
    return 0;
}

-1, Permission denied

And If I remove O_CREAT from the flags, the error disappears.

I don't understand this behavior, because the file has write permissions for everyone and there is no need to create it, since it already exists. Why does this fail with O_CREAT? Is this related to the sticky bit on /tmp ? drwxrwxrwt 25 root root /tmp/

Distro is ubuntu, no selinux involved

ibse
  • 295

0 Answers0