basic user, group and capability housekeeping.
[lunaix-os.git] / lunaix-os / includes / lunaix / usrscope.h
1 #ifndef __LUNAIX_USRSCOPE_H
2 #define __LUNAIX_USRSCOPE_H
3
4 #include <lunaix/types.h>
5 #include "usercaps.h"
6
7 struct ugroup_obj
8 {
9     gid_t* list;
10     unsigned int maxcap;
11     unsigned int refs;
12 };
13
14 struct user_scope
15 {
16     uid_t ruid;
17     gid_t rgid;
18     caps_t capabilities;
19
20     struct ugroup_obj* grps;
21 };
22
23 /*
24     Process ACL check result. 
25     The encoding here is designed to be the mask for file ACL value
26 */
27 enum acl_match
28 {
29     ACL_MATCH_U  = 0b111000000, // (U)ser
30     ACL_MATCH_G  = 0b000111000, // (G)roup
31     ACL_NO_MATCH = 0b000000111, // (O)ther
32 };
33
34 #define user_groups(uscope)     ((uscope)->grps)
35
36 #define grp_list_end       ((gid_t)-1)
37
38 int 
39 uscope_setgroups(struct user_scope* proc_usr, 
40                  const gid_t* grps, unsigned int len);
41
42 void 
43 uscope_copy(struct user_scope* from, struct user_scope* to);
44
45 bool
46 uscope_membership(struct user_scope* proc_usr, gid_t gid);
47
48 enum acl_match
49 check_current_acl(uid_t desired_u, gid_t desired_g);
50
51 static inline bool
52 uscope_with_capability(const struct user_scope* proc_usr, caps_t cap)
53 {
54     return !!(proc_usr->capabilities & (1UL << cap));
55 }
56
57 #endif /* __LUNAIX_USRSCOPE_H */