4.5 of Advanced Programming in the UNIX programming has a very clear explanation for file access permissions.
Here is an experiment to show the explanation.
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, const char *argv[])
{
int fd;
if ((fd = open("data", O_RDONLY)) < 0) {
printf("open error\n");
return 1;
} else {
printf("open ok\n");
return 0;
}
}
$ gcc code.c
$ echo abc > data
$ ls -l
-rwxr-xr-x 1 jing jing 7174 2010-10-09 17:27 a.out
-rw-r--r-- 1 jing jing 302 2010-10-09 17:19 code.c
-rw-r--r-- 1 jing jing 4 2010-10-09 17:26 data
$ /a.out
open ok
$ chmod u-r data
$ /a.out
open error
$ id
uid=1000(jing) gid=1000(jing) groups=4(adm),20(dialout),24(cdrom),46(plugdev),104(lpadmin),115(admin),120(sambashare),121(vboxusers),125(kvm),126(libvirtd),1000(jing)
Here is the tricky part. If the effective user id is equal to the file owner id and it does not have the read permission, the permission is denied even the effective group id is equal to the file group id and does has the read permission.
$ sudo chown test data
$ ./a.out
open ok
$ sudo chown :kvm data
$ ./a.out
open ok
kvm is a supplementary group of the current user jing. So the file can be still opened after its group being set to kvm.
$ ./a.out
open error
$ sudo chown :fax data
$ ./aout
open ok
$ sudo chmod o-r data
$ ./a.out
open error
分享到:
相关推荐
controlling special permissions, encrypting file systems, and much moreMaster the art of securing a Linux environment with this end-to-end practical guideBook Description This book has extensive ...
Exactly how permissions work and how to decipher the most cryptic Linux permissions with ease. How to use the nano, vi, and emacs editors. Two methods to search for files and directories. How to ...
Introduction to Linux Module 2 — Logging In and General Orientation Module 3 — Navigating the File System Module 4 — Managing Files Module 5 — File Permissions and Access Module 6 ...
- **File System Management:** Understanding file permissions, managing directories, and working with different types of files and storage devices. - **User and Group Management:** Best practices for ...
9. **权限和访问控制(permissions and access control)**:`chmod()`, `chown()`, `access()`等函数用于改变文件或目录的权限和所有者,以确保系统安全。 10. **时间与定时器(time and timers)**:`time()`, `...
`getfacl`和`setfacl`命令是Linux中用于管理文件和目录访问控制列表(Access Control List, ACL)的工具,它们允许用户超越传统的用户、组和其他权限模型,提供更精细的权限控制。在本文中,我们将详细探讨这两个...
It provides Windows NT4.0/2000/XP/2003/Vista/2008 with full access to Linux Ext2 volumes (read access andwrite access). This may be useful if you have installed both Windows and Linux as a dual boot ...
- **File Permissions**: Understanding and modifying file permissions using `chmod` and `chown`. - **Finding Files**: Searching for files based on name, type, size, and other criteria using `find`, `...
Linux VM ASLR discussion, tiny bit on Meltdown/Spectre, file permissions/access control lists, discussion of TOCTTOU attacks, etc.), more about Linux CFS scheduler, more about Linux VM, changed VMS ...
printf("File permissions set to owner-read-only\n"); } else { perror("Failed to change file permissions"); } return 0; } ``` 4. `alphasort`函数: `alphasort`是`dirent.h`库中的一个辅助函数,用于...
- 文件权限(permissions) - 文件大小(file size) - 最近访问时间(access time) - 最近修改时间(modification time) - 最近改变元数据时间(change time) - 文件的块位置(block pointers),指向文件实际...
错误提示是"insufficient permissions to access the inventory",这是因为Oracle安装程序在寻找oraInst.loc文件,其中定义了inventory_loc的位置和inst_group。如果之前已安装了11g,oraInst.loc中的设置可能与10g...
The book begins with the concept of user management, group management, as well as file-system permissions. To manage your storage on Ubuntu Server systems, you will learn how to add and format ...
其中,ACL(Access Control Lists)提供了一种更为精细的权限控制方式,它可以为文件定义额外的权限,不仅限于用户和用户组。在Debian、Ubuntu、Linux Mint等系统中,可以通过`sudo apt-get install acl`安装ACL工具...
For more information on setting file permissions, see "Modifying Linux, Unix, and Mac file permissions" (http://drupal.org/node/202483) or "Modifying Windows file permissions" ...
You will then learn how to manage users and their permissions, software installs, disks, filesystems, and so on. You'll then see how to secure connection to remotely access a desktop and work with ...
File Access Permissions Section 4.6. Ownership of New Files and Directories Section 4.7. access Function Section 4.8. umask Function Section 4.9. chmod and fchmod Functions ...
- **Advanced Features**: Advanced features like searching for files, previewing file contents, and managing permissions are explored. **Command-Line Interface (CLI)** - **Basics of Command Line**: ...
- **Permissions and Ownership**: Detailed explanation of file permissions and ownership, including how to change them using commands like `chmod` and `chown`. #### Part V - Applications **Chapter 13...