comparison libpam-sys/src/constants.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 bb465393621f
comparison
equal deleted inserted replaced
107:49c6633f6fd2 108:e97534be35e3
1 //! All the constants. 1 //! All the constants.
2 #![allow(dead_code)] 2
3 // We have to enable these otherwise we get lit up with warnings
4 // during conditional compilation.
5 #![allow(dead_code, unused_imports)]
3 6
4 /// Macro to make defining a bunch of constants way easier. 7 /// Macro to make defining a bunch of constants way easier.
5 macro_rules! define { 8 macro_rules! define {
6 ($(#[$attr:meta])* $($name:ident = $value:expr);+$(;)?) => { 9 ($(#[$attr:meta])* $($name:ident = $value:expr);+$(;)?) => {
7 define!( 10 define!(
8 @meta { $(#[$attr])* } 11 @meta { $(#[$attr])* }
9 $(pub const $name: u32 = $value;)+ 12 $(pub const $name: u32 = $value;)+
10 ); 13 );
11 }; 14 };
12 (@meta $m:tt $($i:item)+) => { define!(@expand $($m $i)+); }; 15 (@meta $m:tt $($i:item)+) => { define!(@expand $($m $i)+); };
13 (@expand $({ $(#[$m:meta])* } $i:item)+) => {$($(#[$m])* $i)+}; 16 (@expand $({ $(#[$m:meta])* } $i:item)+) => {$($(#[$m])* $i)+};
14 } 17 }
15 18
16 #[cfg(feature = "use-system-headers")] 19 #[cfg(feature = "use-system-headers")]
17 pub use system_headers::*; 20 pub use system_headers::*;
18 21
19 #[cfg(not(feature = "use-system-headers"))] 22 #[cfg(not(feature = "use-system-headers"))]
53 56
54 #[cfg(pam_impl = "linux-pam")] 57 #[cfg(pam_impl = "linux-pam")]
55 pub use super::linux_pam::*; 58 pub use super::linux_pam::*;
56 59
57 #[cfg(not(pam_impl = "linux-pam"))] 60 #[cfg(not(pam_impl = "linux-pam"))]
58 pub use super::shared::*; 61 pub use super::illumos_openpam::*;
59 62
60 #[cfg(pam_impl = "illumos")] 63 #[cfg(pam_impl = "illumos")]
61 pub use super::illumos::*; 64 pub use super::illumos::*;
62 65
63 #[cfg(pam_impl = "openpam")] 66 #[cfg(pam_impl = "openpam")]
64 pub use super::openpam::*; 67 pub use super::openpam::*;
65 } 68 }
66 69
67 /// Constants extracted from PAM header files. 70 /// Constants extracted from PAM header files.
68 mod system_headers { 71 mod system_headers {
69 include!(concat!(env!("OUT_DIR"), "/constants.rs")); 72 // include!(concat!(env!("OUT_DIR"), "/constants.rs"));
70 } 73 }
71 74
72 /// Constants used by Linux-PAM. 75 /// Constants used by Linux-PAM.
73 mod linux_pam { 76 mod linux_pam {
74 define!( 77 define!(
112 PAM_SILENT = 0x8000; 115 PAM_SILENT = 0x8000;
113 PAM_DISALLOW_NULL_AUTHTOK = 0x0001; 116 PAM_DISALLOW_NULL_AUTHTOK = 0x0001;
114 PAM_ESTABLISH_CRED = 0x0002; 117 PAM_ESTABLISH_CRED = 0x0002;
115 PAM_DELETE_CRED = 0x0004; 118 PAM_DELETE_CRED = 0x0004;
116 PAM_REINITIALIZE_CRED = 0x0008; 119 PAM_REINITIALIZE_CRED = 0x0008;
120 PAM_REFRESH_CRED = 0x0010;
117 121
118 PAM_CHANGE_EXPIRED_AUTHTOK = 0x0020; 122 PAM_CHANGE_EXPIRED_AUTHTOK = 0x0020;
123
124 PAM_PRELIM_CHECK = 0x4000;
125 PAM_UPDATE_AUTHTOK = 0x2000;
126 PAM_DATA_REPLACE = 0x20000000;
119 ); 127 );
120 128
121 define!( 129 define!(
122 PAM_USER_PROMPT = 9; 130 PAM_USER_PROMPT = 9;
123 PAM_FAIL_DELAY = 10; 131 PAM_FAIL_DELAY = 10;
136 PAM_BINARY_PROMPT = 7; 144 PAM_BINARY_PROMPT = 7;
137 ); 145 );
138 } 146 }
139 147
140 /// Constants shared between Illumos and OpenPAM. 148 /// Constants shared between Illumos and OpenPAM.
141 mod shared { 149 mod illumos_openpam {
142 define!( 150 define!(
143 /// An error code. 151 /// An error code.
144 PAM_OPEN_ERR = 1; 152 PAM_OPEN_ERR = 1;
145 PAM_SYMBOL_ERR = 2; 153 PAM_SYMBOL_ERR = 2;
146 PAM_SERVICE_ERR = 3; 154 PAM_SERVICE_ERR = 3;