comparison src/conv.rs @ 8:a83c56216e21

Ran everything through rustfmt.
author Marc Brinkmann <git@marcbrinkmann.de>
date Sun, 26 Feb 2017 11:29:31 +0100
parents 9380392b9a60
children 30831c70e5c0
comparison
equal deleted inserted replaced
7:9380392b9a60 8:a83c56216e21
1 use libc::{c_char, c_int}; 1 use libc::{c_char, c_int};
2 use std::{ptr}; 2 use std::ptr;
3 use std::ffi::{CStr, CString}; 3 use std::ffi::{CStr, CString};
4 use std::marker::{PhantomData}; 4 use std::marker::PhantomData;
5 5
6 use constants; 6 use constants;
7 use constants::*; 7 use constants::*;
8 use module::{PamItem, PamResult}; 8 use module::{PamItem, PamResult};
9 9
11 pub enum AppDataPtr {} 11 pub enum AppDataPtr {}
12 12
13 #[repr(C)] 13 #[repr(C)]
14 struct PamMessage { 14 struct PamMessage {
15 msg_style: PamMessageStyle, 15 msg_style: PamMessageStyle,
16 msg: *const c_char, 16 msg: *const c_char,
17 } 17 }
18 18
19 #[repr(C)] 19 #[repr(C)]
20 struct PamResponse { 20 struct PamResponse {
21 resp: *const c_char, 21 resp: *const c_char,
27 /// Communication is mediated by the pam client (the application that invoked 27 /// Communication is mediated by the pam client (the application that invoked
28 /// pam). Messages sent will be relayed to the user by the client, and response 28 /// pam). Messages sent will be relayed to the user by the client, and response
29 /// will be relayed back. 29 /// will be relayed back.
30 #[repr(C)] 30 #[repr(C)]
31 pub struct PamConv { 31 pub struct PamConv {
32 conv: extern fn(num_msg: c_int, 32 conv: extern "C" fn(num_msg: c_int,
33 pam_message: &&PamMessage, 33 pam_message: &&PamMessage,
34 pam_response: &mut *const PamResponse, 34 pam_response: &mut *const PamResponse,
35 appdata_ptr: *const AppDataPtr 35 appdata_ptr: *const AppDataPtr)
36 ) -> PamResultCode, 36 -> PamResultCode,
37 appdata_ptr: *const AppDataPtr, 37 appdata_ptr: *const AppDataPtr,
38 } 38 }
39 39
40 impl PamConv { 40 impl PamConv {
41 /// Sends a message to the pam client. 41 /// Sends a message to the pam client.
63 let ret = (self.conv)(1, &&msg, &mut resp_ptr, self.appdata_ptr); 63 let ret = (self.conv)(1, &&msg, &mut resp_ptr, self.appdata_ptr);
64 64
65 if constants::PAM_SUCCESS == ret { 65 if constants::PAM_SUCCESS == ret {
66 if resp_ptr.is_null() { 66 if resp_ptr.is_null() {
67 Ok(None) 67 Ok(None)
68 } 68 } else {
69 else {
70 let bytes = unsafe { CStr::from_ptr((*resp_ptr).resp).to_bytes() }; 69 let bytes = unsafe { CStr::from_ptr((*resp_ptr).resp).to_bytes() };
71 Ok(String::from_utf8(bytes.to_vec()).ok()) 70 Ok(String::from_utf8(bytes.to_vec()).ok())
72 } 71 }
73 } else { 72 } else {
74 Err(ret) 73 Err(ret)
75 } 74 }
76 } 75 }
77 } 76 }
78 77
79 impl PamItem for PamConv { 78 impl PamItem for PamConv {
80 fn item_type(_: PhantomData<Self>) -> PamItemType { PAM_CONV } 79 fn item_type(_: PhantomData<Self>) -> PamItemType {
80 PAM_CONV
81 }
81 } 82 }