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!
相关问题
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- Error building gcc 4.8.3 from source: libstdc++.so
- Why should we check WIFEXITED after wait in order
- Null-terminated string, opening file for reading
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
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.