Mercurial > crates > nonstick
diff src/module.rs @ 14:51b097c12d3c
make PamResultCode an enum
author | Anthony Nowell <anthony@algorithmia.com> |
---|---|
date | Sat, 23 Sep 2017 14:30:18 -0600 |
parents | cc39d168aeb8 |
children |
line wrap: on
line diff
--- a/src/module.rs Sun Feb 26 12:16:03 2017 +0100 +++ b/src/module.rs Sat Sep 23 14:30:18 2017 -0600 @@ -4,8 +4,7 @@ use std::{mem, ptr}; use std::ffi::{CStr, CString}; -use constants; -use constants::*; +use constants::{PamResultCode, PamItemType}; /// Opaque type, used as a pointer when making pam API calls. /// @@ -77,7 +76,7 @@ let c_key = CString::new(key).unwrap().as_ptr(); let mut ptr: *const PamDataT = ptr::null(); let res = pam_get_data(pamh, c_key, &mut ptr); - if constants::PAM_SUCCESS == res && !ptr.is_null() { + if PamResultCode::PAM_SUCCESS == res && !ptr.is_null() { let typed_ptr: *const T = mem::transmute(ptr); let data: &T = &*typed_ptr; Ok(data) @@ -97,7 +96,7 @@ let c_data: Box<PamDataT> = mem::transmute(data); pam_set_data(pamh, c_key, c_data, cleanup::<T>) }; - if constants::PAM_SUCCESS == res { + if PamResultCode::PAM_SUCCESS == res { Ok(()) } else { Err(res) @@ -125,7 +124,7 @@ let t: &T = &*typed_ptr; (r, t) }; - if constants::PAM_SUCCESS == res { + if PamResultCode::PAM_SUCCESS == res { Ok(item) } else { Err(res) @@ -150,7 +149,7 @@ // pointer (c_item as *const PamItemT).as_ref().unwrap()) }; - if constants::PAM_SUCCESS == res { + if PamResultCode::PAM_SUCCESS == res { Ok(()) } else { Err(res) @@ -170,10 +169,10 @@ None => ptr::null(), }; let res = unsafe { pam_get_user(pamh, &ptr, c_prompt) }; - if constants::PAM_SUCCESS == res && !ptr.is_null() { + if PamResultCode::PAM_SUCCESS == res && !ptr.is_null() { let const_ptr = ptr as *const c_char; let bytes = unsafe { CStr::from_ptr(const_ptr).to_bytes() }; - String::from_utf8(bytes.to_vec()).map_err(|_| PAM_CONV_ERR) + String::from_utf8(bytes.to_vec()).map_err(|_| PamResultCode::PAM_CONV_ERR) } else { Err(res) }