diff --git a/config/emgauwa-controller.pkl b/config/emgauwa-controller.pkl index ff265a5..70b60cd 100644 --- a/config/emgauwa-controller.pkl +++ b/config/emgauwa-controller.pkl @@ -8,8 +8,8 @@ server { database = "sqlite://emgauwa-controller.sqlite" permissions { - user = "emgauwa" - group = "emgauwa" + user = read("env:USER") + group = read("env:USER") } logging { diff --git a/config/emgauwa-core.pkl b/config/emgauwa-core.pkl index aed5358..b43b11e 100644 --- a/config/emgauwa-core.pkl +++ b/config/emgauwa-core.pkl @@ -8,8 +8,8 @@ server { database = "sqlite://emgauwa-core.sqlite" permissions { - user = "emgauwa" - group = "emgauwa" + user = read("env:USER") + group = read("env:USER") } logging { diff --git a/emgauwa-lib/src/utils.rs b/emgauwa-lib/src/utils.rs index b6419ad..0ce1079 100644 --- a/emgauwa-lib/src/utils.rs +++ b/emgauwa-lib/src/utils.rs @@ -48,17 +48,21 @@ fn drop_privileges_group(group: &str) -> Result<(), Error> { if let Ok(cstr) = CString::new(group.as_bytes()) { let p = unsafe { libc::getgrnam(cstr.as_ptr()) }; if p.is_null() { - log::error!("Unable to getgrnam of group: {}", group); - return Err(Error::last_os_error()); + return Err(Error::new( + ErrorKind::Other, + format!("Unable to find group: {}", group), + )); } if unsafe { libc::setgid((*p).gr_gid) } != 0 { - log::error!("Unable to setgid of group: {}", group); - return Err(Error::last_os_error()); + return Err(Error::new( + ErrorKind::Other, + format!("Unable set gid for group: {}", group), + )); } } else { return Err(Error::new( ErrorKind::Other, - "Cannot create CString from String (group)!", + format!("Cannot create CString from groupname: {}", group), )); } Ok(()) @@ -69,17 +73,21 @@ fn drop_privileges_user(user: &str) -> Result<(), Error> { if let Ok(cstr) = CString::new(user.as_bytes()) { let p = unsafe { libc::getpwnam(cstr.as_ptr()) }; if p.is_null() { - log::error!("Unable to getpwnam of user: {}", user); - return Err(Error::last_os_error()); + return Err(Error::new( + ErrorKind::Other, + format!("Unable to find user: {}", user), + )); } if unsafe { libc::setuid((*p).pw_uid) } != 0 { - log::error!("Unable to setuid of user: {}", user); - return Err(Error::last_os_error()); + return Err(Error::new( + ErrorKind::Other, + format!("Unable set uid for user: {}", user), + )); } } else { return Err(Error::new( ErrorKind::Other, - "Cannot create CString from String (user)!", + format!("Cannot create CString from username: {}", user), )); } Ok(())