diff src/libpam/question.rs @ 108:e97534be35e3

Make some proc macros for doing cfg-like stuff for PAM impls.
author Paul Fisher <paul@pfish.zone>
date Sat, 28 Jun 2025 00:34:45 -0400
parents 49d9e2b5c189
children 178310336596
line wrap: on
line diff
--- a/src/libpam/question.rs	Thu Jun 26 22:42:32 2025 -0400
+++ b/src/libpam/question.rs	Sat Jun 28 00:34:45 2025 -0400
@@ -1,6 +1,6 @@
 //! Data and types dealing with PAM messages.
 
-#[cfg(feature = "linux-pam-extensions")]
+#[cfg(feature = "linux-pam-ext")]
 use crate::conv::{BinaryQAndA, RadioQAndA};
 use crate::conv::{ErrorMsg, InfoMsg, MaskedQAndA, Message, QAndA};
 use crate::libpam::conversation::OwnedMessage;
@@ -188,13 +188,13 @@
     /// An informational message.
     TextInfo = pam_ffi::PAM_TEXT_INFO,
     /// Yes/No/Maybe conditionals. A Linux-PAM extension.
-    #[cfg(feature = "linux-pam-extensions")]
+    #[cfg(feature = "linux-pam-ext")]
     RadioType = pam_ffi::PAM_RADIO_TYPE,
     /// For server–client non-human interaction.
     ///
     /// NOT part of the X/Open PAM specification.
     /// A Linux-PAM extension.
-    #[cfg(feature = "linux-pam-extensions")]
+    #[cfg(feature = "linux-pam-ext")]
     BinaryPrompt = pam_ffi::PAM_BINARY_PROMPT,
 }
 
@@ -236,13 +236,13 @@
             Message::Prompt(p) => alloc(Style::PromptEchoOn, p.question()),
             Message::Error(p) => alloc(Style::ErrorMsg, p.question()),
             Message::Info(p) => alloc(Style::TextInfo, p.question()),
-            #[cfg(feature = "linux-pam-extensions")]
+            #[cfg(feature = "linux-pam-ext")]
             Message::RadioPrompt(p) => alloc(Style::RadioType, p.question()),
-            #[cfg(feature = "linux-pam-extensions")]
+            #[cfg(feature = "linux-pam-ext")]
             Message::BinaryPrompt(p) => Ok((Style::BinaryPrompt, unsafe {
                 CHeapBox::cast(CBinaryData::alloc(p.question())?)
             })),
-            #[cfg(not(feature = "linux-pam-extensions"))]
+            #[cfg(not(feature = "linux-pam-ext"))]
             Message::RadioPrompt(_) | Message::BinaryPrompt(_) => Err(ErrorCode::ConversationError),
         }?;
         Ok(Self {
@@ -261,12 +261,12 @@
             // in the Question. If it's not a supported format, we skip it.
             if let Ok(style) = Style::try_from(self.style) {
                 let _ = match style {
-                    #[cfg(feature = "linux-pam-extensions")]
+                    #[cfg(feature = "linux-pam-ext")]
                     Style::BinaryPrompt => self
                         .data
                         .as_ref()
                         .map(|p| CBinaryData::zero_contents(CHeapBox::as_ptr(p).cast())),
-                    #[cfg(feature = "linux-pam-extensions")]
+                    #[cfg(feature = "linux-pam-ext")]
                     Style::RadioType => self
                         .data
                         .as_ref()
@@ -301,9 +301,9 @@
                 Style::PromptEchoOn => Self::Prompt(QAndA::new(question.string_data()?)),
                 Style::ErrorMsg => Self::Error(ErrorMsg::new(question.string_data()?)),
                 Style::TextInfo => Self::Info(InfoMsg::new(question.string_data()?)),
-                #[cfg(feature = "linux-pam-extensions")]
+                #[cfg(feature = "linux-pam-ext")]
                 Style::RadioType => Self::RadioPrompt(RadioQAndA::new(question.string_data()?)),
-                #[cfg(feature = "linux-pam-extensions")]
+                #[cfg(feature = "linux-pam-ext")]
                 Style::BinaryPrompt => Self::BinaryPrompt(BinaryQAndA::new(question.binary_data())),
             }
         };
@@ -353,7 +353,7 @@
             }
 
             #[test]
-            #[cfg(not(feature = "linux-pam-extensions"))]
+            #[cfg(not(feature = "linux-pam-ext"))]
             fn no_linux_extensions() {
                 use crate::conv::{BinaryQAndA, RadioQAndA};
                 <$typ>::new(&[
@@ -363,7 +363,7 @@
             }
 
             #[test]
-            #[cfg(feature = "linux-pam-extensions")]
+            #[cfg(feature = "linux-pam-ext")]
             fn linux_extensions() {
                 let interrogation = Box::pin(<$typ>::new(&[
                     BinaryQAndA::new((&[5, 4, 3, 2, 1], 66)).message(),