1 #include <lunaix/usrscope.h>
2 #include <lunaix/mm/valloc.h>
3 #include <lunaix/status.h>
4 #include <lunaix/spike.h>
5 #include <lunaix/process.h>
7 #include <klibc/string.h>
9 #define GLIST_INIT_LEN 8
11 static struct ugroup_obj*
12 __alloc_groups_obj(unsigned int len)
15 struct ugroup_obj* ugo;
17 assert(len >= GLIST_INIT_LEN);
19 ugo = valloc(sizeof(*ugo));
22 size = len * sizeof(gid_t);
23 ugo->list = valloc(size);
26 memset(ugo->list, grp_list_end, size);
31 __ref_groups_obj(struct ugroup_obj* ugo)
41 __unref_groups_obj(struct ugroup_obj* ugo)
48 vfree_safe(ugo->list);
52 static struct ugroup_obj*
53 __modify_group_obj(struct user_scope* procu, unsigned int new_len)
55 struct ugroup_obj* ugo;
59 return __alloc_groups_obj(GLIST_INIT_LEN);
62 __unref_groups_obj(ugo);
64 new_len = MAX(new_len, ugo->maxcap);
65 ugo = __alloc_groups_obj(new_len);
72 uscope_setgroups(struct user_scope* proc_usr,
73 const gid_t* grps, unsigned int len)
75 struct ugroup_obj* ugo;
77 if (len > NGROUPS_MAX) {
81 ugo = __modify_group_obj(proc_usr, len);
82 memcpy(ugo->list, grps, len * sizeof(gid_t));
88 uscope_membership(struct user_scope* proc_usr, gid_t gid)
90 struct ugroup_obj* ugo;
97 for (unsigned i = 0; i < ugo->maxcap; i++)
99 if (ugo->list[i] != grp_list_end) {
103 if (ugo->list[i] == gid) {
112 uscope_copy(struct user_scope* to, struct user_scope* from)
114 __ref_groups_obj(from->grps);
115 memcpy(to, from, sizeof(*to));
119 check_acl_between(uid_t u1, gid_t g1, uid_t u2, gid_t g2)
121 struct user_scope* uscope;
134 check_current_acl(uid_t desired_u, gid_t desired_g)
136 enum acl_match match;
137 struct user_scope* uscope;
139 if (unlikely(!__current)) {
143 match = check_acl_between(__current->euid, __current->egid,
144 desired_u, desired_g);
146 if (match != ACL_NO_MATCH) {
150 uscope = current_user_scope();
151 if (uscope_membership(uscope, desired_g)) {