]>
git.proxmox.com Git - proxmox-backup.git/blob - pbs-tools/src/sys.rs
1 //! System level helpers.
3 use nix
::unistd
::{Gid, Group, Uid, User}
;
5 /// Query a user by name but only unless built with `#[cfg(test)]`.
7 /// This is to avoid having regression tests query the users of development machines which may
8 /// not be compatible with PBS or privileged enough.
9 pub fn query_user(user_name
: &str) -> Result
<Option
<User
>, nix
::Error
> {
12 User
::from_uid(Uid
::current())?
.expect("current user does not exist"),
15 User
::from_name(user_name
)
19 /// Query a group by name but only unless built with `#[cfg(test)]`.
21 /// This is to avoid having regression tests query the groups of development machines which may
22 /// not be compatible with PBS or privileged enough.
23 pub fn query_group(group_name
: &str) -> Result
<Option
<Group
>, nix
::Error
> {
26 Group
::from_gid(Gid
::current())?
.expect("current group does not exist"),
29 Group
::from_name(group_name
)