diff --git a/src/cache.rs b/src/cache.rs index 6a77b707e8271da5ec6398c7400e9b063c43e493..b2e753b4ce179e087fad6dbfa571fabf0987e929 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -65,8 +65,8 @@ pub struct Cache<'a> { pub context_user: UserInfo<'a> } -impl Cache<'_> { - pub fn new<'a>() -> Cache<'a> { +impl Cache { + pub fn new() -> Cache { let euid = unsafe { geteuid() }; @@ -401,8 +401,8 @@ fn get_original_euid() -> uid_t { } lazy_static! { - static ref CACHE: Mutex<Cache<'static>> = Mutex::new(Cache::new()); + static ref CACHE: Mutex<Cache> = Mutex::new(Cache::new()); } -pub fn get_cache() -> MutexGuard<'static, Cache<'static>> { +pub fn get_cache() -> MutexGuard<'static, Cache> { CACHE.lock().unwrap() } diff --git a/src/unix.rs b/src/unix.rs index 86712179fe74893484f233d18ab72525eb0e06c0..d74e0e7076661ddabd647bee51b6263dcc46ec47 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -1,5 +1,5 @@ /* Copyright 2021 Dominik George <dominik.george@teckids.org> -65;6203;1c * Copyright 2021 mirabilos <thorsten.glaser@teckids.org> + * Copyright 2021 mirabilos <thorsten.glaser@teckids.org> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,33 +20,33 @@ use std::io; use std::mem::uninitialized; use std::ptr::null_mut; -pub struct Passwd<'a> { - pub pw_name: &'a str, - pub pw_passwd: &'a str, +pub struct Passwd { + pub pw_name: String, + pub pw_passwd: String, pub pw_uid: uid_t, pub pw_gid: gid_t, - pub pw_gecos: &'a str, - pub pw_dir: &'a str, - pub pw_shell: &'a str + pub pw_gecos: String, + pub pw_dir: String, + pub pw_shell: String } const MAX_BUFLEN: size_t = 1024 * 1024; -fn getpwxx_fillpw<'a>(c_passwd: passwd) -> Passwd<'a> { +fn getpwxx_fillpw(c_passwd: passwd) -> Passwd { unsafe { Passwd { - pw_name: CStr::from_ptr(c_passwd.pw_name).to_str().ok().unwrap(), - pw_passwd: CStr::from_ptr(c_passwd.pw_passwd).to_str().ok().unwrap(), + pw_name: CStr::from_ptr(c_passwd.pw_name).to_string_lossy().into_owned(), + pw_passwd: CStr::from_ptr(c_passwd.pw_passwd).to_string_lossy().into_owned(), pw_uid: c_passwd.pw_uid, pw_gid: c_passwd.pw_gid, - pw_gecos: CStr::from_ptr(c_passwd.pw_gecos).to_str().ok().unwrap(), - pw_dir: CStr::from_ptr(c_passwd.pw_dir).to_str().ok().unwrap(), - pw_shell: CStr::from_ptr(c_passwd.pw_shell).to_str().ok().unwrap(), + pw_gecos: CStr::from_ptr(c_passwd.pw_gecos).to_string_lossy().into_owned(), + pw_dir: CStr::from_ptr(c_passwd.pw_dir).to_string_lossy().into_owned(), + pw_shell: CStr::from_ptr(c_passwd.pw_shell).to_string_lossy().into_owned(), } } } -pub fn getpwnam_safe<'a>(name: String) -> Result<Passwd<'a>, io::Error> { +pub fn getpwnam_safe(name: String) -> Result<Passwd, io::Error> { let res: Passwd; unsafe { @@ -82,7 +82,7 @@ pub fn getpwnam_safe<'a>(name: String) -> Result<Passwd<'a>, io::Error> { return Ok(res); } -pub fn getpwuid_safe<'a>(uid: uid_t) -> Result<Passwd<'a>, io::Error> { +pub fn getpwuid_safe(uid: uid_t) -> Result<Passwd, io::Error> { let res: Passwd; unsafe {