diff options
| author | Paul Buetow <git@mx.buetow.org> | 2020-12-29 08:34:04 +0000 |
|---|---|---|
| committer | Paul Buetow <git@mx.buetow.org> | 2020-12-29 08:34:04 +0000 |
| commit | 0099a7ab9e1d28300c69c3b50b4ebe1cde9a8cbc (patch) | |
| tree | c9f0dfa884927079de309b68c48224f4b0f00d0d /internal/io/fs/permissions/permission_linuxacl.h | |
| parent | cab8f9f1e1576dbe42b6e88a5c9c3d14b00d9a37 (diff) | |
Make Linux ACL support optional, as it requires CGo and makes the binary less portable
Diffstat (limited to 'internal/io/fs/permissions/permission_linuxacl.h')
| -rw-r--r-- | internal/io/fs/permissions/permission_linuxacl.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/internal/io/fs/permissions/permission_linuxacl.h b/internal/io/fs/permissions/permission_linuxacl.h new file mode 100644 index 0000000..52dadcf --- /dev/null +++ b/internal/io/fs/permissions/permission_linuxacl.h @@ -0,0 +1,62 @@ +// +build linuxacl + +#ifndef PERMISSION_LINUX_H +#define PERMISSION_LINUX_H + +#include <acl/libacl.h> +#include <errno.h> +#include <grp.h> +#include <pwd.h> +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <sys/acl.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> + +//#define DEBUG +#define USER_CHECK 0 +#define GROUP_CHECK 1 + +struct permission_checker { + char *user_name; + uid_t uid; + gid_t *gids; + int ngids; + char *file_path; + struct stat file_stat; + struct passwd pw; +}; + + +#ifdef DEBUG +// Print out permission_checker struct. +void debug_print_checker(struct permission_checker *pc); +#endif + +// Stat a given file to retrieve traditional UNIX permissions. +int stat_file(struct permission_checker *pc); + +// Retrieve UID of user. +int get_user_uid(struct permission_checker *pc); + +// Retrieve all groups of the user. +int get_user_groups(struct permission_checker *pc); + +// Check whether user is member of a group or not. +int is_member_of_group(struct permission_checker *pc, gid_t gid); + +// Check whether user can read file according Linux ACLs. +// As flag use either USER_CHECK or GROUP_CHECK. +int check_acl(struct permission_checker *pc, const int flag); + +// Check whether user has permissions to read file according traditional +// UNIX permissions. As flag use either USER_CHECK or GROUP_CHECK. +int check_traditional(struct permission_checker *pc, const int flag); + +// Returns 1 if user has permission to read file. +// Returns <0 on error and returns 0 if no permissions. +int permission_to_read(char* user, char *file_path); + +#endif // PERMISSION_LINUX_H |
