comparison src/conv.rs @ 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 b195a14058bb
children 9380392b9a60
comparison
equal deleted inserted replaced
5:a5cc18a3db47 6:2ec97116d72c
28 /// will be relayed back. 28 /// will be relayed back.
29 #[repr(C)] 29 #[repr(C)]
30 pub struct PamConv { 30 pub struct PamConv {
31 conv: extern fn(num_msg: c_int, 31 conv: extern fn(num_msg: c_int,
32 pam_message: &&PamMessage, 32 pam_message: &&PamMessage,
33 pam_response: &*mut PamResponse, 33 pam_response: &mut *const PamResponse,
34 appdata_ptr: *const AppDataPtr 34 appdata_ptr: *const AppDataPtr
35 ) -> PamResultCode, 35 ) -> PamResultCode,
36 appdata_ptr: *const AppDataPtr, 36 appdata_ptr: *const AppDataPtr,
37 } 37 }
38 38
51 /// 51 ///
52 /// Note that the user experience will depend on how the client implements 52 /// Note that the user experience will depend on how the client implements
53 /// these message styles - and not all applications implement all message 53 /// these message styles - and not all applications implement all message
54 /// styles. 54 /// styles.
55 pub fn send(&self, style: PamMessageStyle, msg: &str) -> PamResult<Option<String>> { 55 pub fn send(&self, style: PamMessageStyle, msg: &str) -> PamResult<Option<String>> {
56 let resp_ptr: *mut PamResponse = ptr::null_mut(); 56 let mut resp_ptr: *const PamResponse = ptr::null();
57 let msg = PamMessage { 57 let msg = PamMessage {
58 msg_style: style, 58 msg_style: style,
59 msg: CString::new(msg).unwrap().as_ptr(), 59 msg: CString::new(msg).unwrap().as_ptr(),
60 }; 60 };
61 61
62 let ret = (self.conv)(1, &&msg, &resp_ptr, self.appdata_ptr); 62 let ret = (self.conv)(1, &&msg, &mut resp_ptr, self.appdata_ptr);
63 63
64 if constants::PAM_SUCCESS == ret { 64 if constants::PAM_SUCCESS == ret {
65 let s = unsafe { resp_ptr.as_ref() } 65 if resp_ptr.is_null() {
66 .and_then(|r| { 66 Ok(None)
67 if r.resp.is_null() { 67 }
68 None 68 else {
69 } 69 let bytes = unsafe { CStr::from_ptr((*resp_ptr).resp).to_bytes() };
70 else { 70 Ok(String::from_utf8(bytes.to_vec()).ok())
71 let bytes = unsafe { CStr::from_ptr(r.resp).to_bytes() }; 71 }
72 String::from_utf8(bytes.to_vec()).ok()
73 }
74 });
75 Ok(s)
76 } else { 72 } else {
77 Err(ret) 73 Err(ret)
78 } 74 }
79 } 75 }
80 } 76 }