if (getuid() == 0 || geteuid() != 0) {
// if we are root, set fileowner to owner of 001.vdr/00001.ts file
This code looks as it doesnt work the way wanted:
if user == root
[ getuid() == geteuid() ] == 0 // both zero. always xrw permissions.
elseif user != root && !(sudo or setuidbit)
[ getuid() == geteuid() ] != 0 // both equal. may or may not have xrw permissions.
elseif user != root && (sudo or setuidbit)
[ getuid() != 0; geteuid() == 0 ] // euid == 0, we have permissions, but this 'if' evaluates to false
else
...
The difference between the regular UID and the Effective UID is that only the EUID is checked when you do something that requires special access (such as reading or writing a file, or making certain system calls). The UID indicates the actual user who is performing the action, but it is (usually) not considered when examining permissions. In normal programs they will be the same. Some programs change their EUID to add or subtract from the actions they are allowed to take. A smaller number also change their UID, to effectively "become" another user.
(..)
There are a few other cases where the UID and EUID won't match, but they're not too common. For instance, a file server running as the super user might change its EUID to match a specific user who is requesting some file manipulations. Using the user's EUID allows the server to avoid accessing things that the user is not allowed to touch.
Normally markad should not run as root anyway, but with the user that also runs VDR. But if the function exists, it should work. Thank you for your contribution, I have included it in branch V03.
Hi kfb77,
Sorry to bother you again..
In https://github.com/kfb77/vdr-plugin-markad/blob/ec3575a68816eac5ce90f0decf95833d7f3b2de5/command/marks.cpp#L626
This code looks as it doesnt work the way wanted:
For the check permissions of writing a file, geteuid is enough. See also https://stackoverflow.com/questions/14950378/what-is-difference-between-os-getuid-and-os-geteuid
The difference between the regular UID and the Effective UID is that only the EUID is checked when you do something that requires special access (such as reading or writing a file, or making certain system calls). The UID indicates the actual user who is performing the action, but it is (usually) not considered when examining permissions. In normal programs they will be the same. Some programs change their EUID to add or subtract from the actions they are allowed to take. A smaller number also change their UID, to effectively "become" another user. (..) There are a few other cases where the UID and EUID won't match, but they're not too common. For instance, a file server running as the super user might change its EUID to match a specific user who is requesting some file manipulations. Using the user's EUID allows the server to avoid accessing things that the user is not allowed to touch.
I think, it would already work if we change to
But simpler would be
?