comparison src/conv.rs @ 14:51b097c12d3c

make PamResultCode an enum
author Anthony Nowell <anthony@algorithmia.com>
date Sat, 23 Sep 2017 14:30:18 -0600
parents 30831c70e5c0
children
comparison
equal deleted inserted replaced
13:cc39d168aeb8 14:51b097c12d3c
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 4
5 use constants; 5 use constants::PamResultCode;
6 use constants::*; 6 use constants::*;
7 use module::{PamItem, PamResult}; 7 use module::{PamItem, PamResult};
8 8
9 #[allow(missing_copy_implementations)] 9 #[allow(missing_copy_implementations)]
10 pub enum AppDataPtr {} 10 pub enum AppDataPtr {}
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, &mut 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 PamResultCode::PAM_SUCCESS == ret {
65 if resp_ptr.is_null() { 65 if resp_ptr.is_null() {
66 Ok(None) 66 Ok(None)
67 } else { 67 } else {
68 let bytes = unsafe { CStr::from_ptr((*resp_ptr).resp).to_bytes() }; 68 let bytes = unsafe { CStr::from_ptr((*resp_ptr).resp).to_bytes() };
69 Ok(String::from_utf8(bytes.to_vec()).ok()) 69 Ok(String::from_utf8(bytes.to_vec()).ok())