use libc::{c_char, c_int, c_void};
use std::fmt::{Display, Error, Formatter};
pub type ConvClosure = (extern "C" fn(c_int,
*mut *mut PamMessage,
*mut *mut PamResponse,
*mut c_void)
-> c_int);
pub enum PamHandle {}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct PamMessage {
pub msg_style: c_int,
pub msg: *const c_char,
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct PamResponse {
pub resp: *mut c_char,
pub resp_retcode: c_int,
}
#[repr(C)]
pub struct PamConversation {
pub conv: Option<ConvClosure>,
pub data_ptr: *mut c_void,
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct PamXAuthData {
pub namelen: c_int,
pub name: *mut c_char,
pub datalen: c_int,
pub data: *mut c_char,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum PamReturnCode {
SUCCESS = 0,
OPEN_ERR = 1,
SYMBOL_ERR = 2,
SERVICE_ERR = 3,
SYSTEM_ERR = 4,
BUF_ERR = 5,
PERM_DENIED = 6,
AUTH_ERR = 7,
CRED_INSUFFICIENT = 8,
AUTHINFO_UNAVAIL = 9,
USER_UNKNOWN = 10,
MAXTRIES = 11,
NEW_AUTHTOK_REQD = 12,
ACCT_EXPIRED = 13,
SESSION_ERR = 14,
CRED_UNAVAIL = 15,
CRED_EXPIRED = 16,
CRED_ERR = 17,
NO_MODULE_DATA = 18,
CONV_ERR = 19,
AUTHTOK_ERR = 20,
AUTHTOK_RECOVERY_ERR = 21,
AUTHTOK_LOCK_BUSY = 22,
AUTHTOK_DISABLE_AGING = 23,
TRY_AGAIN = 24,
IGNORE = 25,
AUTHTOK_EXPIRED = 27,
ABORT = 26,
MODULE_UNKNOWN = 28,
BAD_ITEM = 29,
CONV_AGAIN = 30,
INCOMPLETE = 31,
}
impl Display for PamReturnCode {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
f.write_str(&format!("{:?} ({})", self, *self as i32))
}
}
impl From<i32> for PamReturnCode {
fn from(status: i32) -> PamReturnCode {
match status {
0 => PamReturnCode::SUCCESS,
1 => PamReturnCode::OPEN_ERR,
2 => PamReturnCode::SYMBOL_ERR,
3 => PamReturnCode::SERVICE_ERR,
4 => PamReturnCode::SYSTEM_ERR,
5 => PamReturnCode::BUF_ERR,
6 => PamReturnCode::PERM_DENIED,
7 => PamReturnCode::AUTH_ERR,
8 => PamReturnCode::CRED_INSUFFICIENT,
9 => PamReturnCode::AUTHINFO_UNAVAIL,
10 => PamReturnCode::USER_UNKNOWN,
11 => PamReturnCode::MAXTRIES,
12 => PamReturnCode::NEW_AUTHTOK_REQD,
13 => PamReturnCode::ACCT_EXPIRED,
14 => PamReturnCode::SESSION_ERR,
15 => PamReturnCode::CRED_UNAVAIL,
16 => PamReturnCode::CRED_EXPIRED,
17 => PamReturnCode::CRED_ERR,
18 => PamReturnCode::NO_MODULE_DATA,
19 => PamReturnCode::CONV_ERR,
20 => PamReturnCode::AUTHTOK_ERR,
21 => PamReturnCode::AUTHTOK_RECOVERY_ERR,
22 => PamReturnCode::AUTHTOK_LOCK_BUSY,
23 => PamReturnCode::AUTHTOK_DISABLE_AGING,
24 => PamReturnCode::TRY_AGAIN,
25 => PamReturnCode::IGNORE,
26 => PamReturnCode::ABORT,
27 => PamReturnCode::AUTHTOK_EXPIRED,
28 => PamReturnCode::MODULE_UNKNOWN,
29 => PamReturnCode::BAD_ITEM,
30 => PamReturnCode::CONV_AGAIN,
31 => PamReturnCode::INCOMPLETE,
_ => PamReturnCode::SYSTEM_ERR,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum PamFlag {
SILENT = 0x8000,
DISALLOW_NULL_AUTHTOK = 0x0001,
ESTABLISH_CRED = 0x0002,
DELETE_CRED = 0x0004,
REINITIALIZE_CRED = 0x0008,
REFRESH_CRED = 0x0010,
CHANGE_EXPIRED_AUTHTOK = 0x0020,
NONE = 0x0000,
}
impl Display for PamFlag {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
f.write_str(&format!("{:?} ({})", self, *self as i32))
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum PamItemType {
SERVICE = 1,
USER = 2,
TTY = 3,
RHOST = 4,
CONV = 5,
AUTHTOK = 6,
OLDAUTHTOK = 7,
RUSER = 8,
USER_PROMPT = 9,
FAIL_DELAY = 10,
XDISPLAY = 11,
XAUTHDATA = 12,
AUTHTOK_TYPE = 13,
}
impl Display for PamItemType {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
f.write_str(&format!("{:?} ({})", self, *self as i32))
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum PamMessageStyle {
PROMPT_ECHO_OFF = 1,
PROMPT_ECHO_ON = 2,
ERROR_MSG = 3,
TEXT_INFO = 4,
}
impl Display for PamMessageStyle {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
f.write_str(&format!("{:?} ({})", self, *self as i32))
}
}
impl From<i32> for PamMessageStyle {
fn from(style: i32) -> PamMessageStyle {
match style {
1 => PamMessageStyle::PROMPT_ECHO_OFF,
2 => PamMessageStyle::PROMPT_ECHO_ON,
3 => PamMessageStyle::ERROR_MSG,
4 => PamMessageStyle::TEXT_INFO,
_ => PamMessageStyle::ERROR_MSG,
}
}
}