Mercurial > crates > nonstick
comparison src/libpam/pam_ffi.rs @ 113:178310336596
Fix up more constants, make things i32 rather than u32.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Sun, 29 Jun 2025 03:11:33 -0400 |
parents | e97534be35e3 |
children |
comparison
equal
deleted
inserted
replaced
112:82995b4dccee | 113:178310336596 |
---|---|
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, non_upper_case_globals)] | 3 #![allow(non_camel_case_types, non_upper_case_globals)] |
4 | 4 |
5 use crate::libpam::memory::{CHeapBox, Immovable}; | 5 use crate::libpam::memory::{CHeapBox, Immovable}; |
6 use std::ffi::{c_int, c_uint, c_void, CStr}; | 6 use std::ffi::{c_int, c_void, CStr}; |
7 use std::marker::PhantomData; | 7 use std::marker::PhantomData; |
8 use std::ptr; | 8 use std::ptr; |
9 | 9 |
10 /// An opaque structure that a PAM handle points to. | 10 /// An opaque structure that a PAM handle points to. |
11 #[repr(C)] | 11 #[repr(C)] |
49 /// (either the module or PAM itself). | 49 /// (either the module or PAM itself). |
50 #[repr(C)] | 50 #[repr(C)] |
51 #[derive(Debug)] | 51 #[derive(Debug)] |
52 pub struct Question { | 52 pub struct Question { |
53 /// The style of message to request. | 53 /// The style of message to request. |
54 pub style: c_uint, | 54 pub style: c_int, |
55 /// A description of the data requested. | 55 /// A description of the data requested. |
56 /// | 56 /// |
57 /// For most requests, this will be an owned [`CStr`], | 57 /// For most requests, this will be an owned [`CStr`], |
58 /// but for requests with style `PAM_BINARY_PROMPT`, | 58 /// but for requests with style `PAM_BINARY_PROMPT`, |
59 /// this will be `CBinaryData` (a Linux-PAM extension). | 59 /// this will be `CBinaryData` (a Linux-PAM extension). |
90 /// that was passed in. | 90 /// that was passed in. |
91 pub life: PhantomData<&'a mut ()>, | 91 pub life: PhantomData<&'a mut ()>, |
92 } | 92 } |
93 | 93 |
94 /// Gets a string version of an error message. | 94 /// Gets a string version of an error message. |
95 pub fn strerror(code: c_uint) -> Option<&'static str> { | 95 pub fn strerror(code: c_int) -> Option<&'static str> { |
96 // SAFETY: Every single PAM implementation I can find (Linux-PAM, OpenPAM, | 96 // SAFETY: Every single PAM implementation I can find (Linux-PAM, OpenPAM, |
97 // Solaris, etc.) returns a static string and ignores the handle value. | 97 // Sun, etc.) returns a static string and ignores the handle value. |
98 let strerror = unsafe { pam_strerror(ptr::null_mut(), code as c_int) }; | 98 let strerror = unsafe { pam_strerror(ptr::null_mut(), code as c_int) }; |
99 if strerror.is_null() { | 99 if strerror.is_null() { |
100 None | 100 None |
101 } else { | 101 } else { |
102 unsafe { CStr::from_ptr(strerror) }.to_str().ok() | 102 unsafe { CStr::from_ptr(strerror) }.to_str().ok() |