Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/stat.h>
- struct Task
- {
- unsigned uid;
- int gid_count;
- unsigned *gids;
- };
- static int isuser(const struct stat *stb, const struct Task *task) {
- if (stb->st_uid == task->uid) {
- return 1;
- }
- return 0;
- }
- static int isgrp (const struct stat *stb, const struct Task *task) {
- for (int i = 0; i < task->gid_count; i++) {
- if (task->gids[i] == stb->st_gid) {
- return 1;
- }
- }
- return 0;
- }
- enum masks
- {
- USER = 0700,
- GROUP = 0070,
- OTHER = 0007,
- U_OFFSET = 6,
- G_OFFSET = 3
- };
- enum { permissions = 3 };
- int myaccess(const struct stat *stb, const struct Task *task, int access) {
- if (task->uid == 0) {
- return 1;
- }
- int mode;
- if (isuser(stb, task)) {
- mode = stb->st_mode & USER;
- mode >>= U_OFFSET;
- if (access != mode) {
- return 0;
- }
- } else if (isgrp(stb, task)) {
- mode = stb->st_mode & GROUP;
- mode >>= G_OFFSET;
- if (access != mode) {
- return 0;
- }
- } else {
- mode = stb->st_mode & OTHER;
- if (access != mode) {
- return 0;
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement