-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathcheck_files.c
More file actions
52 lines (38 loc) · 928 Bytes
/
check_files.c
File metadata and controls
52 lines (38 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <assert.h>
#include <errno.h>
#include <string.h>
#include <sys/stat.h>
#include "defs.h"
int
file_mode_check(const char *file, const mode_t mode) {
struct stat sb;
assert(file != NULL);
assert(mode);
if (lstat(file, &sb) == -1)
return -errno;
if (sb.st_mode != mode)
return ERANGE;
return 0;
}
int
file_user_check(struct idtree * idt, const char *file, const char *user) {
struct stat sb;
char *act_user;
assert(file != NULL);
assert(user != NULL);
if (lstat(file, &sb) == -1)
return -errno;
act_user = idtree_username(idt, sb.st_uid);
return strcmp(user, act_user) == 0 ? 0 : ERANGE;
}
int
file_group_check(struct idtree * idt, const char *file, const char *grp) {
struct stat sb;
char *act_grp;
assert(file != NULL);
assert(grp != NULL);
if (lstat(file, &sb) == -1)
return -errno;
act_grp = idtree_groupname(idt, sb.st_gid);
return strcmp(grp, act_grp) == 0 ? 0 : ERANGE;
}