Mercurial > crates > nonstick
changeset 6:2ec97116d72c
Updates for rustc 1.0.0-beta
author | Jesse Hallett <jesse@galois.com> |
---|---|
date | Fri, 03 Apr 2015 23:16:44 -0700 |
parents | a5cc18a3db47 |
children | 9380392b9a60 |
files | Cargo.toml src/conv.rs src/lib.rs src/module.rs |
diffstat | 4 files changed, 22 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/Cargo.toml Fri Mar 06 14:01:36 2015 -0800 +++ b/Cargo.toml Fri Apr 03 23:16:44 2015 -0700 @@ -12,5 +12,7 @@ license = "MIT" [lib] +name = "pam" -name = "pam" +[dependencies] +libc = "~0.1.5"
--- a/src/conv.rs Fri Mar 06 14:01:36 2015 -0800 +++ b/src/conv.rs Fri Apr 03 23:16:44 2015 -0700 @@ -30,7 +30,7 @@ pub struct PamConv { conv: extern fn(num_msg: c_int, pam_message: &&PamMessage, - pam_response: &*mut PamResponse, + pam_response: &mut *const PamResponse, appdata_ptr: *const AppDataPtr ) -> PamResultCode, appdata_ptr: *const AppDataPtr, @@ -53,26 +53,22 @@ /// these message styles - and not all applications implement all message /// styles. pub fn send(&self, style: PamMessageStyle, msg: &str) -> PamResult<Option<String>> { - let resp_ptr: *mut PamResponse = ptr::null_mut(); + let mut resp_ptr: *const PamResponse = ptr::null(); let msg = PamMessage { msg_style: style, msg: CString::new(msg).unwrap().as_ptr(), }; - let ret = (self.conv)(1, &&msg, &resp_ptr, self.appdata_ptr); + let ret = (self.conv)(1, &&msg, &mut resp_ptr, self.appdata_ptr); if constants::PAM_SUCCESS == ret { - let s = unsafe { resp_ptr.as_ref() } - .and_then(|r| { - if r.resp.is_null() { - None - } - else { - let bytes = unsafe { CStr::from_ptr(r.resp).to_bytes() }; - String::from_utf8(bytes.to_vec()).ok() - } - }); - Ok(s) + if resp_ptr.is_null() { + Ok(None) + } + else { + let bytes = unsafe { CStr::from_ptr((*resp_ptr).resp).to_bytes() }; + Ok(String::from_utf8(bytes.to_vec()).ok()) + } } else { Err(ret) }
--- a/src/lib.rs Fri Mar 06 14:01:36 2015 -0800 +++ b/src/lib.rs Fri Apr 03 23:16:44 2015 -0700 @@ -1,7 +1,3 @@ -#![feature(core)] -#![feature(libc)] -#![feature(std_misc)] - //! Interface to the pluggable authentication module framework (PAM). //! //! The goal of this library is to provide a type-safe API that can be used to
--- a/src/module.rs Fri Mar 06 14:01:36 2015 -0800 +++ b/src/module.rs Fri Apr 03 23:16:44 2015 -0700 @@ -25,7 +25,7 @@ extern { fn pam_get_data(pamh: *const PamHandleT, module_data_name: *const c_char, - data: & *mut PamDataT, + data: &mut *const PamDataT, ) -> PamResultCode; fn pam_set_data(pamh: *const PamHandleT, @@ -39,7 +39,7 @@ fn pam_get_item(pamh: *const PamHandleT, item_type: PamItemType, - item: & *mut PamItemT, + item: &mut *const PamItemT, ) -> PamResultCode; fn pam_set_item(pamh: *mut PamHandleT, @@ -79,11 +79,11 @@ /// http://www.linux-pam.org/Linux-PAM-html/mwg-expected-by-module-item.html pub unsafe fn get_data<'a, T>(pamh: &'a PamHandleT, key: &str) -> PamResult<&'a T> { let c_key = CString::new(key).unwrap().as_ptr(); - let mut ptr: *mut PamDataT = ptr::null_mut(); + 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() { - let raw_data: &PamDataT = ptr.as_ref().unwrap(); - let data: &T = mem::transmute(raw_data); + let typed_ptr: *const T = mem::transmute(ptr); + let data: &T = &*typed_ptr; Ok(data) } else { @@ -119,11 +119,11 @@ /// See `pam_get_item` in /// http://www.linux-pam.org/Linux-PAM-html/mwg-expected-by-module-item.html pub fn get_item<'a, T: PamItem>(pamh: &'a PamHandleT) -> PamResult<&'a T> { - let ptr: *mut PamItemT = ptr::null_mut(); + let mut ptr: *const PamItemT = ptr::null(); let (res, item) = unsafe { - let r = pam_get_item(pamh, PamItem::item_type(None::<T>), &ptr); - let raw_item: &PamItemT = ptr.as_ref().unwrap(); - let t: &T = mem::transmute(raw_item); + let r = pam_get_item(pamh, PamItem::item_type(None::<T>), &mut ptr); + let typed_ptr: *const T = mem::transmute(ptr); + let t: &T = &*typed_ptr; (r, t) }; if constants::PAM_SUCCESS == res { Ok(item) } else { Err(res) }