Skip to content

Commit

Permalink
rotate the requested group id to the front if it is not there already
Browse files Browse the repository at this point in the history
  • Loading branch information
squell committed Dec 19, 2024
1 parent 6e26ab1 commit b663634
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,15 @@ pub fn set_target_user(
) {
use std::os::unix::process::CommandExt;

// add target group to list of additional groups if not present
if !target_user.groups.contains(&target_group.gid) {
if let Some(index) = target_user
.groups
.iter()
.position(|id| id == &target_group.gid)
{
// make sure the requested group id is the first in the list (necessary on FreeBSD)
target_user.groups.swap(0, index)
} else {
// add target group to list of additional groups if not present
target_user.groups.insert(0, target_group.gid);
}

Expand Down

0 comments on commit b663634

Please sign in to comment.