comparison src/libpam/pam_ffi.rs @ 87:05291b601f0a

Well and truly separate the Linux extensions. This separates the Linux extensions on the libpam side, and disables the two enums on the interface side. Users can still call the Linux extensions from non-Linux PAM impls, but they'll get a conversation error back.
author Paul Fisher <paul@pfish.zone>
date Tue, 10 Jun 2025 04:40:01 -0400
parents a8f4718fed5d
children
comparison
equal deleted inserted replaced
86:23162cd399aa 87:05291b601f0a
1 //! The types that are directly represented in PAM function signatures. 1 //! The types that are directly represented in PAM function signatures.
2 2
3 #![allow(non_camel_case_types)] 3 #![allow(non_camel_case_types)]
4 4
5 use crate::libpam::memory::Immovable; 5 use crate::libpam::memory::Immovable;
6 use num_enum::{IntoPrimitive, TryFromPrimitive}; 6 use std::ffi::{c_int, c_uint, c_void};
7 use std::ffi::{c_int, c_void};
8 use std::marker::PhantomData; 7 use std::marker::PhantomData;
9 8
10 /// An opaque structure that a PAM handle points to. 9 /// An opaque structure that a PAM handle points to.
11 #[repr(C)] 10 #[repr(C)]
12 pub struct LibPamHandle { 11 pub struct LibPamHandle {
36 /// Unused. 35 /// Unused.
37 return_code: c_int, 36 return_code: c_int,
38 _marker: Immovable, 37 _marker: Immovable,
39 } 38 }
40 39
41 /// The C enum values for messages shown to the user.
42 #[derive(Debug, PartialEq, TryFromPrimitive, IntoPrimitive)]
43 #[repr(i32)]
44 pub enum Style {
45 /// Requests information from the user; will be masked when typing.
46 PromptEchoOff = 1,
47 /// Requests information from the user; will not be masked.
48 PromptEchoOn = 2,
49 /// An error message.
50 ErrorMsg = 3,
51 /// An informational message.
52 TextInfo = 4,
53 /// Yes/No/Maybe conditionals. A Linux-PAM extension.
54 RadioType = 5,
55 /// For server–client non-human interaction.
56 ///
57 /// NOT part of the X/Open PAM specification.
58 /// A Linux-PAM extension.
59 BinaryPrompt = 7,
60 }
61
62 /// A question sent by PAM or a module to an application. 40 /// A question sent by PAM or a module to an application.
63 /// 41 ///
64 /// PAM refers to this as a "message", but we call it a question 42 /// PAM refers to this as a "message", but we call it a question
65 /// to avoid confusion with [`Message`](crate::Message). 43 /// to avoid confusion with [`Message`](crate::Message).
66 /// 44 ///
67 /// This question, and its internal data, is owned by its creator 45 /// This question, and its internal data, is owned by its creator
68 /// (either the module or PAM itself). 46 /// (either the module or PAM itself).
69 #[repr(C)] 47 #[repr(C)]
70 pub struct Question { 48 pub struct Question {
71 /// The style of message to request. 49 /// The style of message to request.
72 pub style: c_int, 50 pub style: c_uint,
73 /// A description of the data requested. 51 /// A description of the data requested.
74 /// 52 ///
75 /// For most requests, this will be an owned [`CStr`](std::ffi::CStr), but for requests 53 /// For most requests, this will be an owned [`CStr`](std::ffi::CStr), but for requests
76 /// with [`Style::BinaryPrompt`], this will be [`CBinaryData`] 54 /// with [`Style::BinaryPrompt`], this will be [`CBinaryData`]
77 /// (a Linux-PAM extension). 55 /// (a Linux-PAM extension).