comparison src/libpam/question.rs @ 105:13b4d2a19674

Support Rust v1.75.0. This is the version included in Ubuntu 24.04 LTS and Debian Trixie, so it's old enough to have wide penetration without being too old to get new features (Debian Stable, I love you but v1.63 is just not going to work out).
author Paul Fisher <paul@pfish.zone>
date Thu, 26 Jun 2025 00:48:51 -0400
parents 94b51fa4f797
children 49d9e2b5c189
comparison
equal deleted inserted replaced
104:a2676475e86b 105:13b4d2a19674
1 //! Data and types dealing with PAM messages. 1 //! Data and types dealing with PAM messages.
2 2
3 use std::cell::Cell;
3 #[cfg(feature = "linux-pam-extensions")] 4 #[cfg(feature = "linux-pam-extensions")]
4 use crate::conv::{BinaryQAndA, RadioQAndA}; 5 use crate::conv::{BinaryQAndA, RadioQAndA};
5 use crate::conv::{ErrorMsg, InfoMsg, MaskedQAndA, Message, QAndA}; 6 use crate::conv::{ErrorMsg, InfoMsg, MaskedQAndA, Message, QAndA};
6 use crate::libpam::conversation::OwnedMessage; 7 use crate::libpam::conversation::OwnedMessage;
7 use crate::libpam::memory::{CBinaryData, CHeapBox, CHeapString, Immovable}; 8 use crate::libpam::memory::{CBinaryData, CHeapBox, CHeapString, Immovable};
10 use crate::ErrorCode; 11 use crate::ErrorCode;
11 use crate::Result; 12 use crate::Result;
12 use num_enum::{IntoPrimitive, TryFromPrimitive}; 13 use num_enum::{IntoPrimitive, TryFromPrimitive};
13 use std::ffi::{c_void, CStr}; 14 use std::ffi::{c_void, CStr};
14 use std::pin::Pin; 15 use std::pin::Pin;
15 use std::slice; 16 use std::{ptr, slice};
16 17
17 /// Abstraction of a collection of questions to be sent in a PAM conversation. 18 /// Abstraction of a collection of questions to be sent in a PAM conversation.
18 /// 19 ///
19 /// The PAM C API conversation function looks like this: 20 /// The PAM C API conversation function looks like this:
20 /// 21 ///
89 #[repr(C)] 90 #[repr(C)]
90 pub struct XSsoQuestions { 91 pub struct XSsoQuestions {
91 /// Points to the memory address where the meat of `questions` is. 92 /// Points to the memory address where the meat of `questions` is.
92 /// **The memory layout of Vec is not specified**, and we need to return 93 /// **The memory layout of Vec is not specified**, and we need to return
93 /// a pointer to the pointer, hence we have to store it here. 94 /// a pointer to the pointer, hence we have to store it here.
94 pointer: *const Question, 95 pointer: Cell<*const Question>,
95 questions: Vec<Question>, 96 questions: Vec<Question>,
96 _marker: Immovable, 97 _marker: Immovable,
97 } 98 }
98 99
99 impl XSsoQuestions { 100 impl XSsoQuestions {
108 impl QuestionsTrait for XSsoQuestions { 109 impl QuestionsTrait for XSsoQuestions {
109 fn new(messages: &[Message]) -> Result<Self> { 110 fn new(messages: &[Message]) -> Result<Self> {
110 let questions: Result<Vec<_>> = messages.iter().map(Question::try_from).collect(); 111 let questions: Result<Vec<_>> = messages.iter().map(Question::try_from).collect();
111 let questions = questions?; 112 let questions = questions?;
112 Ok(Self { 113 Ok(Self {
113 pointer: questions.as_ptr(), 114 pointer: Cell::new(ptr::null()),
114 questions, 115 questions,
115 _marker: Default::default(), 116 _marker: Default::default(),
116 }) 117 })
117 } 118 }
118 119
119 fn ptr(self: Pin<&Self>) -> *const *const Question { 120 fn ptr(self: Pin<&Self>) -> *const *const Question {
120 &self.pointer as *const *const Question 121 let me = self.get_ref();
122 me.pointer.set(self.questions.as_ptr());
123 me.pointer.as_ptr()
121 } 124 }
122 125
123 unsafe fn borrow_ptr<'a>( 126 unsafe fn borrow_ptr<'a>(
124 ptr: *const *const Question, 127 ptr: *const *const Question,
125 count: usize, 128 count: usize,