summaryrefslogtreecommitdiffstats
path: root/src/passwd.rs
diff options
context:
space:
mode:
authorTomasz Kramkowski <tomasz@kramkow.ski>2023-01-29 17:23:14 +0000
committerTomasz Kramkowski <tomasz@kramkow.ski>2023-01-29 17:23:14 +0000
commitdca986f599e1abe4270a06efaf91759a926f2424 (patch)
treeaee9f548eb5f39fbb5f36581b7b28fe500034559 /src/passwd.rs
parent63aab7ac772622173f38309cc9ed5b0cd11ea58f (diff)
downloadpam_usercg_rust-dca986f599e1abe4270a06efaf91759a926f2424.tar.gz
pam_usercg_rust-dca986f599e1abe4270a06efaf91759a926f2424.tar.xz
pam_usercg_rust-dca986f599e1abe4270a06efaf91759a926f2424.zip
Remove users dependency
Diffstat (limited to 'src/passwd.rs')
-rw-r--r--src/passwd.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/passwd.rs b/src/passwd.rs
new file mode 100644
index 0000000..40ec947
--- /dev/null
+++ b/src/passwd.rs
@@ -0,0 +1,11 @@
+use libc::uid_t;
+use std::ffi::CStr;
+
+pub fn get_uid_by_name<S: AsRef<CStr> + ?Sized>(name: &S) -> Option<uid_t> {
+ let passwd = unsafe { libc::getpwnam(name.as_ref().as_ptr()) };
+ if !passwd.is_null() {
+ Some(unsafe { *passwd }.pw_uid)
+ } else {
+ None
+ }
+}