Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider nosound and novideo when keeping groups & misc refactors #4632

Merged
merged 4 commits into from
Nov 20, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
util.c: [ref] move group find/copy into new functions
Move the logic from clean_supplementary_groups into the following new
functions:

* find_group
* copy_group_ifcont

These will be reused later.

Misc: The latter function's signature is based on getgrouplist(2), which
is used on clean_supplementary_groups.
  • Loading branch information
kmk3 committed Oct 22, 2021
commit 25f7c7e0b7119dfd396077685695b646d02b1f9e
37 changes: 26 additions & 11 deletions src/firejail/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,30 @@ void errLogExit(char* fmt, ...) {
exit(1);
}

static int find_group(gid_t group, const gid_t *groups, int ngroups) {
int i;
for (i = 0; i < ngroups; i++) {
if (group == groups[i])
return i;
}

return -1;
}

// Gets group from "groupname" and adds it to "new_groups" if it exists on
// "groups". Always returns the current value of new_ngroups.
static int copy_group_ifcont(const char *groupname,
const gid_t *groups, int ngroups,
gid_t *new_groups, int *new_ngroups) {
gid_t g = get_group_id(groupname);
if (g && find_group(g, groups, ngroups) >= 0) {
new_groups[*new_ngroups] = g;
(*new_ngroups)++;
}

return *new_ngroups;
}

static void clean_supplementary_groups(gid_t gid) {
assert(cfg.username);
gid_t groups[MAX_GROUPS];
Expand All @@ -126,17 +150,8 @@ static void clean_supplementary_groups(gid_t gid) {

int i = 0;
while (allowed[i]) {
gid_t g = get_group_id(allowed[i]);
if (g) {
int j;
for (j = 0; j < ngroups; j++) {
if (g == groups[j]) {
new_groups[new_ngroups] = g;
new_ngroups++;
break;
}
}
}
copy_group_ifcont(allowed[i], groups, ngroups,
new_groups, &new_ngroups);
i++;
}

Expand Down