Skip to content

Commit a3ae861

Browse files
committed
fix: user.name instead user.gecos
1 parent 3b9138d commit a3ae861

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

swhkd/src/daemon.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::{
1212
collections::{HashMap, HashSet},
1313
env,
1414
error::Error,
15+
ffi::CString,
1516
fs::{self, File, OpenOptions, Permissions},
1617
io::{Read, Write},
1718
os::unix::{fs::PermissionsExt, net::UnixStream},
@@ -200,7 +201,9 @@ async fn main() -> Result<(), Box<dyn Error>> {
200201
.expect("Failed to get user info")
201202
.expect(&format!("User with UID {} not found", invoking_uid));
202203

203-
nix::unistd::initgroups(&user.gecos, user.gid)
204+
let username = CString::new(user.name.as_str())
205+
.expect("Failed to convert username to CString");
206+
nix::unistd::initgroups(&username, user.gid)
204207
.expect(&format!("Failed to set supplementary groups for UID {}", invoking_uid));
205208
setgid(user.gid)
206209
.expect(&format!("Failed to set group-id to {}", user.gid));

swhkd/src/perms.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use nix::unistd::{Gid, Uid, User};
2-
use std::process::exit;
2+
use std::{ffi::CString, process::exit};
33

44
pub fn _drop_privileges(user_uid: u32) {
55
let user_uid = Uid::from_raw(user_uid);
@@ -20,7 +20,8 @@ pub fn raise_privileges() {
2020

2121
fn set_initgroups(user: &nix::unistd::User, gid: u32) {
2222
let gid = Gid::from_raw(gid);
23-
match nix::unistd::initgroups(&user.gecos, gid) {
23+
let username = CString::new(user.name.as_str()).expect("Failed to convert username to CString");
24+
match nix::unistd::initgroups(&username, gid) {
2425
Ok(_) => log::debug!("Setting initgroups..."),
2526
Err(e) => {
2627
log::error!("Failed to set init groups: {:#?}", e);

0 commit comments

Comments
 (0)