Given a string indicating the symbolic notation of UNIX permission of a file and its ownership (user ID and group ID), decide whether a given user
A has permission to read / write / execute it.
Permissions in UNIX system
In UNIX, every file has three classes of permissions (user, group and others) and ownership, including which user and which group it belongs to.
The symbolic notation consists of ten characters. The first character is not important in this challenge. The remaining nine characters are in three sets of three characters, representing permissions of user, group and others class. Characters in each set indicates whether reading / writing / executing is permitted. If permitted, it will be
x. Otherwise, it will be
Note that setuid, setgid and sticky bit may change the third character of each set to
T. Here's a simple rule: if the character is lowercase letter, then the permission is set; otherwise, it is not.
(For the details of symbolic notation of permissions, please refer to here.)
Every user has its user ID, and every group has its group ID. All IDs will be non-negative integers. A user will belong to at least one group. If a user
A want to get access to a file, the system will check their permissions as follows:
If the file belongs to user
A, check the permissions of user class.
If the file doesn't belong to
Abelongs to the group which the file belongs to, check the permissions of group class.
Otherwise, check the permissions of others class.
However, there is one exception: if the user ID is 0 (superuser), they have permission to do anything!
- Your program / function should take these as input in any reasonable format:
- Permissions in symbolic notation.
- User ID and group ID which the file belongs to.
- The user ID of
A, and a list of group IDs which
- Type of access. You can use any three different one-digit or one-character values for read, write and execute.
- Return / output a truthy value if
Ahas permission to access the file, or a falsy value if not.
- You can assume that the first character of the notation will always be
- This is code-golf, so the shortest in bytes wins!
The format here is
[permissions, user ID of file, group ID of file, user ID of A, group IDs of A, type(r/w/x)].
[-rwx------, 13, 15, 13, [15, 24], r]: True # user [-rwxr-xr-x, 13, 24, 24, [15, 24], w]: False # group [-rwxr-Sr-T, 13, 15, 24, [15, 35], x]: False # group [-rwsr-xr-t, 13, 15, 24, [24, 35], x]: True # others [----------, 13, 15, 0, [0, 1, 2], r]: True # superuser [----------, 13, 15, 1, [0, 1, 2], r]: False # others [----rwxrwx, 13, 15, 13, [15, 24], r]: False # user