view src/constants.rs @ 55:676675c3d434

Make PamResultCode implement Error.
author Paul Fisher <paul@pfish.zone>
date Sun, 04 May 2025 00:58:04 -0400
parents ce47901aab7a
children daa2cde64601
line wrap: on
line source

use libc::{c_int, c_uint};

// TODO: Import constants from C header file at compile time.

pub type PamFlag = c_uint;
pub type PamItemType = c_int;
pub type PamMessageStyle = c_int;

// The Linux-PAM flags
// see /usr/include/security/_pam_types.h
pub const PAM_SILENT: PamFlag = 0x8000;
pub const PAM_DISALLOW_NULL_AUTHTOK: PamFlag = 0x0001;
pub const PAM_ESTABLISH_CRED: PamFlag = 0x0002;
pub const PAM_DELETE_CRED: PamFlag = 0x0004;
pub const PAM_REINITIALIZE_CRED: PamFlag = 0x0008;
pub const PAM_REFRESH_CRED: PamFlag = 0x0010;
pub const PAM_CHANGE_EXPIRED_AUTHTOK: PamFlag = 0x0020;

// Message styles
pub const PAM_PROMPT_ECHO_OFF: PamMessageStyle = 1;
pub const PAM_PROMPT_ECHO_ON: PamMessageStyle = 2;
pub const PAM_ERROR_MSG: PamMessageStyle = 3;
pub const PAM_TEXT_INFO: PamMessageStyle = 4;
/// yes/no/maybe conditionals
pub const PAM_RADIO_TYPE: PamMessageStyle = 5;
pub const PAM_BINARY_PROMPT: PamMessageStyle = 7;

/// The Linux-PAM return values.
/// For more detailed information, see
/// /usr/include/security/_pam_types.h
#[allow(non_camel_case_types, dead_code)]
#[derive(Debug, PartialEq, thiserror::Error)]
#[repr(C)]
pub enum PamResultCode {
    #[error("Not an error")]
    PAM_SUCCESS = 0,
    #[error("dlopen() failure when dynamically loading a service module")]
    PAM_OPEN_ERR = 1,
    #[error("symbol not found")]
    PAM_SYMBOL_ERR = 2,
    #[error("error in service module")]
    PAM_SERVICE_ERR = 3,
    #[error("system error")]
    PAM_SYSTEM_ERR = 4,
    #[error("memory buffer error")]
    PAM_BUF_ERR = 5,
    #[error("permission denied")]
    PAM_PERM_DENIED = 6,
    #[error("authentication failure")]
    PAM_AUTH_ERR = 7,
    #[error("cannot access authentication data due to insufficient credentials")]
    PAM_CRED_INSUFFICIENT = 8,
    #[error("underlying authentication service cannot retrieve authentication information")]
    PAM_AUTHINFO_UNAVAIL = 9,
    #[error("user not known to the underlying authentication module")]
    PAM_USER_UNKNOWN = 10,
    #[error("retry limit reached; do not attempt further")]
    PAM_MAXTRIES = 11,
    #[error("new authentication token required")]
    PAM_NEW_AUTHTOK_REQD = 12,
    #[error("user account has expired")]
    PAM_ACCT_EXPIRED = 13,
    #[error("cannot make/remove an entry for the specified session")]
    PAM_SESSION_ERR = 14,
    #[error("underlying authentication service cannot retrieve user credentials")]
    PAM_CRED_UNAVAIL = 15,
    #[error("user credentials expired")]
    PAM_CRED_EXPIRED = 16,
    #[error("failure setting user credentials")]
    PAM_CRED_ERR = 17,
    #[error("no module-specific data is present")]
    PAM_NO_MODULE_DATA = 18,
    #[error("conversation error")]
    PAM_CONV_ERR = 19,
    #[error("authentication token manipulation error")]
    PAM_AUTHTOK_ERR = 20,
    #[error("authentication information cannot be recovered")]
    PAM_AUTHTOK_RECOVERY_ERR = 21,
    #[error("authentication token lock busy")]
    PAM_AUTHTOK_LOCK_BUSY = 22,
    #[error("authentication token aging disabled")]
    PAM_AUTHTOK_DISABLE_AGING = 23,
    #[error("preliminary check by password service")]
    PAM_TRY_AGAIN = 24,
    #[error("ignore underlying account module, regardless of control flag")]
    PAM_IGNORE = 25,
    #[error("critical error; this module should fail now")]
    PAM_ABORT = 26,
    #[error("authentication token has expired")]
    PAM_AUTHTOK_EXPIRED = 27,
    #[error("module is not known")]
    PAM_MODULE_UNKNOWN = 28,
    #[error("bad item passed to pam_[whatever]_item")]
    PAM_BAD_ITEM = 29,
    #[error("conversation function is event-driven and data is not available yet")]
    PAM_CONV_AGAIN = 30,
    #[error("call this function again to complete authentication stack")]
    PAM_INCOMPLETE = 31,
}