如何检查 Linux 中的 ACL 中是否存在 UID?
我需要编写一个程序,其中一部分涉及检查执行该程序的人的用户ID是否存在于该程序使用的文件的ACL文件中。也就是说,该程序写入文件,并且只有其 ID 和权限在 ACL 中输入的用户才允许执行此操作。程序如何检查这一点?我知道我需要使用 getresid 函数来获取执行进程的 RUID,但是如何根据 ACL 中存储的所有值检查该值?请帮我!
I need to write a program, part of which involves checking if the userid of the person executing the program exists in the ACL file of a file which the program uses. That is, this program writes into the file and only users whose ID and privileges are entered in the ACL are allowed to do so. How can the program check this? I know that I need to use the getresid
function to get the RUID of the executing process, but how do I check this value against all the values stored in the ACL? Please help me!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
传统上,Linux 程序不做太多解释性访问控制。有两种情况。
案例1,简单案例。一个文件有一个 acl(或只是模式)。某些用户在其用户/组集下运行程序,内核根据模式/acl 允许或拒绝。全部完成。
案例2,硬质案例。程序以 root 身份运行,但希望代表其他用户进行操作。因此,它调用 setuid/setgid 来“成为”该用户,然后执行操作(如打开文件),然后调用将自身恢复到根权限。
但是,根据您对 chown 的回答的评论,我认为您属于情况 1。用户 foo 运行该程序,因此内核为您完成所有工作。
Traditionally, linux programs don't do interpretive access control very much. There are two cases.
Case 1, the simple case. A file has an acl (or just modes). Some user runs a program under his user/group set, and the kernel either allows or denies based on the modes/acl. All done.
Case 2, the hard case. A program runs as root, but wishes to operate on behalf of some other user. So, it calls setuid/setgid to 'become' that user, then performs the operation (like opening a file), and then calls to restore itself to root-itude afterwards.
However, based on your comments to chown's answer, I think that you are just in case 1. The user foo runs the program, so the kernel does all the work for you.
如果我误解了这个问题,我深表歉意,但希望您会发现这有帮助:
摘自一些 acl 文档:
以下函数检索和操作 ACL 条目:
以下函数检索和操作字段在 ACL 条目中:
...
来自acl_update.c:
我不认为你需要检查特定文件的 ACL,但如果我错了,这里有一些信息:
然后从名称中获取 uid(未经测试但应该接近):
更多资源:
acl/facl 示例和参考
man acl
POSIX 访问控制列表
斯塔塔克
If I misunderstood the question I apologize, but hopefully you will find this helpful:
Exceprt from some acl documentation:
The following functions retrieve and manipulate ACL entries:
The following functions retrieve and manipulate fields in an ACL entry:
...
From acl_update.c:
I dont think u need to check the ACL of a specific file, but if I am wrong, here is some info to do so:
then to get a uid from the name (untested but should be close):
Some more resources:
acl/facl examples and reference
man acl
POSIX Access Control Lists
statacl