diff --git a/src/pam/converse.rs b/src/pam/converse.rs index 93a4d8132..2ca26a6fc 100644 --- a/src/pam/converse.rs +++ b/src/pam/converse.rs @@ -25,7 +25,7 @@ impl PamMessageStyle { pub fn from_int(val: libc::c_int) -> Option { use PamMessageStyle::*; - match val as libc::c_uint { + match val { PAM_PROMPT_ECHO_OFF => Some(PromptEchoOff), PAM_PROMPT_ECHO_ON => Some(PromptEchoOn), PAM_ERROR_MSG => Some(ErrorMessage), diff --git a/src/pam/error.rs b/src/pam/error.rs index 7089951bb..e850cba05 100644 --- a/src/pam/error.rs +++ b/src/pam/error.rs @@ -84,7 +84,7 @@ impl PamErrorType { pub(super) fn from_int(errno: libc::c_int) -> PamErrorType { use PamErrorType::*; - match errno as libc::c_uint { + match errno { PAM_SUCCESS => Success, PAM_OPEN_ERR => OpenError, PAM_SYMBOL_ERR => SymbolError, diff --git a/src/pam/mod.rs b/src/pam/mod.rs index be68cfd2f..2cef3e4b9 100644 --- a/src/pam/mod.rs +++ b/src/pam/mod.rs @@ -140,7 +140,7 @@ impl PamContext { /// Get the PAM flag value for the silent flag fn silent_flag(&self) -> i32 { if self.silent { - PAM_SILENT as i32 + PAM_SILENT } else { 0 } @@ -151,7 +151,7 @@ impl PamContext { if self.allow_null_auth_token { 0 } else { - PAM_DISALLOW_NULL_AUTHTOK as i32 + PAM_DISALLOW_NULL_AUTHTOK } } @@ -196,18 +196,14 @@ impl PamContext { pub fn set_user(&mut self, user: &str) -> PamResult<()> { let c_user = CString::new(user)?; pam_err(unsafe { - pam_set_item( - self.pamh, - PAM_USER as i32, - c_user.as_ptr() as *const libc::c_void, - ) + pam_set_item(self.pamh, PAM_USER, c_user.as_ptr() as *const libc::c_void) }) } /// Get the user that is currently active in the PAM handle pub fn get_user(&mut self) -> PamResult { let mut data = std::ptr::null(); - pam_err(unsafe { pam_get_item(self.pamh, PAM_USER as i32, &mut data) })?; + pam_err(unsafe { pam_get_item(self.pamh, PAM_USER, &mut data) })?; // safety check to make sure that we do not ready a null ptr into a cstr if data.is_null() { @@ -223,25 +219,13 @@ impl PamContext { /// Set the TTY path for the current TTY that this PAM session started from. pub fn set_tty>(&mut self, tty_path: P) -> PamResult<()> { let data = CString::new(tty_path.as_ref().as_bytes())?; - pam_err(unsafe { - pam_set_item( - self.pamh, - PAM_TTY as i32, - data.as_ptr() as *const libc::c_void, - ) - }) + pam_err(unsafe { pam_set_item(self.pamh, PAM_TTY, data.as_ptr() as *const libc::c_void) }) } // Set the user that requested the actions in this PAM instance. pub fn set_requesting_user(&mut self, user: &str) -> PamResult<()> { let data = CString::new(user.as_bytes())?; - pam_err(unsafe { - pam_set_item( - self.pamh, - PAM_RUSER as i32, - data.as_ptr() as *const libc::c_void, - ) - }) + pam_err(unsafe { pam_set_item(self.pamh, PAM_RUSER, data.as_ptr() as *const libc::c_void) }) } /// Re-initialize the credentials stored in PAM @@ -266,7 +250,7 @@ impl PamContext { let mut flags = 0; flags |= self.silent_flag(); if expired_only { - flags |= PAM_CHANGE_EXPIRED_AUTHTOK as i32; + flags |= PAM_CHANGE_EXPIRED_AUTHTOK; } pam_err(unsafe { pam_chauthtok(self.pamh, flags) }) } @@ -362,7 +346,7 @@ impl Drop for PamContext { unsafe { pam_end( self.pamh, - self.last_pam_status.unwrap_or(PAM_SUCCESS as libc::c_int) | PAM_DATA_SILENT as i32, + self.last_pam_status.unwrap_or(PAM_SUCCESS as libc::c_int) | PAM_DATA_SILENT, ) }; } diff --git a/src/pam/sys.rs b/src/pam/sys.rs index f346a02ca..d222b0467 100644 --- a/src/pam/sys.rs +++ b/src/pam/sys.rs @@ -1,49 +1,53 @@ -/* automatically generated by rust-bindgen 0.66.1 */ +/* automatically generated by rust-bindgen 0.66.1, minified by cargo-minify, edited to be portable */ -pub const PAM_SUCCESS: u32 = 0; -pub const PAM_OPEN_ERR: u32 = 1; -pub const PAM_SYMBOL_ERR: u32 = 2; -pub const PAM_SERVICE_ERR: u32 = 3; -pub const PAM_SYSTEM_ERR: u32 = 4; -pub const PAM_BUF_ERR: u32 = 5; -pub const PAM_PERM_DENIED: u32 = 6; -pub const PAM_AUTH_ERR: u32 = 7; -pub const PAM_CRED_INSUFFICIENT: u32 = 8; -pub const PAM_AUTHINFO_UNAVAIL: u32 = 9; -pub const PAM_USER_UNKNOWN: u32 = 10; -pub const PAM_MAXTRIES: u32 = 11; -pub const PAM_NEW_AUTHTOK_REQD: u32 = 12; -pub const PAM_ACCT_EXPIRED: u32 = 13; -pub const PAM_SESSION_ERR: u32 = 14; -pub const PAM_CRED_UNAVAIL: u32 = 15; -pub const PAM_CRED_EXPIRED: u32 = 16; -pub const PAM_CRED_ERR: u32 = 17; -pub const PAM_NO_MODULE_DATA: u32 = 18; -pub const PAM_CONV_ERR: u32 = 19; -pub const PAM_AUTHTOK_ERR: u32 = 20; -pub const PAM_AUTHTOK_RECOVERY_ERR: u32 = 21; -pub const PAM_AUTHTOK_LOCK_BUSY: u32 = 22; -pub const PAM_AUTHTOK_DISABLE_AGING: u32 = 23; -pub const PAM_TRY_AGAIN: u32 = 24; -pub const PAM_IGNORE: u32 = 25; -pub const PAM_ABORT: u32 = 26; -pub const PAM_AUTHTOK_EXPIRED: u32 = 27; -pub const PAM_MODULE_UNKNOWN: u32 = 28; -pub const PAM_BAD_ITEM: u32 = 29; -pub const PAM_SILENT: u32 = 32768; -pub const PAM_DISALLOW_NULL_AUTHTOK: u32 = 1; -pub const PAM_REINITIALIZE_CRED: u32 = 8; -pub const PAM_CHANGE_EXPIRED_AUTHTOK: u32 = 32; -pub const PAM_USER: u32 = 2; -pub const PAM_TTY: u32 = 3; -pub const PAM_RUSER: u32 = 8; -pub const PAM_DATA_SILENT: u32 = 1073741824; -pub const PAM_PROMPT_ECHO_OFF: u32 = 1; -pub const PAM_PROMPT_ECHO_ON: u32 = 2; -pub const PAM_ERROR_MSG: u32 = 3; -pub const PAM_TEXT_INFO: u32 = 4; -pub const PAM_MAX_RESP_SIZE: u32 = 512; -pub type pam_handle_t = u8; +// NOTE: the tests below test the assumptions about the padding that a C compiler will use on the +// above structs; if these assumptions are incorrect, the tests will fail, but most likely the +// code will still be correct. + +pub const PAM_SUCCESS: libc::c_int = 0; +pub const PAM_OPEN_ERR: libc::c_int = 1; +pub const PAM_SYMBOL_ERR: libc::c_int = 2; +pub const PAM_SERVICE_ERR: libc::c_int = 3; +pub const PAM_SYSTEM_ERR: libc::c_int = 4; +pub const PAM_BUF_ERR: libc::c_int = 5; +pub const PAM_PERM_DENIED: libc::c_int = 6; +pub const PAM_AUTH_ERR: libc::c_int = 7; +pub const PAM_CRED_INSUFFICIENT: libc::c_int = 8; +pub const PAM_AUTHINFO_UNAVAIL: libc::c_int = 9; +pub const PAM_USER_UNKNOWN: libc::c_int = 10; +pub const PAM_MAXTRIES: libc::c_int = 11; +pub const PAM_NEW_AUTHTOK_REQD: libc::c_int = 12; +pub const PAM_ACCT_EXPIRED: libc::c_int = 13; +pub const PAM_SESSION_ERR: libc::c_int = 14; +pub const PAM_CRED_UNAVAIL: libc::c_int = 15; +pub const PAM_CRED_EXPIRED: libc::c_int = 16; +pub const PAM_CRED_ERR: libc::c_int = 17; +pub const PAM_NO_MODULE_DATA: libc::c_int = 18; +pub const PAM_CONV_ERR: libc::c_int = 19; +pub const PAM_AUTHTOK_ERR: libc::c_int = 20; +pub const PAM_AUTHTOK_RECOVERY_ERR: libc::c_int = 21; +pub const PAM_AUTHTOK_LOCK_BUSY: libc::c_int = 22; +pub const PAM_AUTHTOK_DISABLE_AGING: libc::c_int = 23; +pub const PAM_TRY_AGAIN: libc::c_int = 24; +pub const PAM_IGNORE: libc::c_int = 25; +pub const PAM_ABORT: libc::c_int = 26; +pub const PAM_AUTHTOK_EXPIRED: libc::c_int = 27; +pub const PAM_MODULE_UNKNOWN: libc::c_int = 28; +pub const PAM_BAD_ITEM: libc::c_int = 29; +pub const PAM_SILENT: libc::c_int = 32768; +pub const PAM_DISALLOW_NULL_AUTHTOK: libc::c_int = 1; +pub const PAM_REINITIALIZE_CRED: libc::c_int = 8; +pub const PAM_CHANGE_EXPIRED_AUTHTOK: libc::c_int = 32; +pub const PAM_USER: libc::c_int = 2; +pub const PAM_TTY: libc::c_int = 3; +pub const PAM_RUSER: libc::c_int = 8; +pub const PAM_DATA_SILENT: libc::c_int = 1073741824; +pub const PAM_PROMPT_ECHO_OFF: libc::c_int = 1; +pub const PAM_PROMPT_ECHO_ON: libc::c_int = 2; +pub const PAM_ERROR_MSG: libc::c_int = 3; +pub const PAM_TEXT_INFO: libc::c_int = 4; +pub const PAM_MAX_RESP_SIZE: libc::c_int = 512; +pub type pam_handle_t = libc::c_void; extern "C" { pub fn pam_set_item( pamh: *mut pam_handle_t, @@ -74,19 +78,15 @@ pub struct pam_message { fn bindgen_test_layout_pam_message() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(pam_message)) - ); assert_eq!( ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of::<*mut libc::c_void>(), concat!("Alignment of ", stringify!(pam_message)) ); + let mut offset: usize = 0; assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).msg_style) as usize - ptr as usize }, - 0usize, + offset, concat!( "Offset of field: ", stringify!(pam_message), @@ -94,9 +94,10 @@ fn bindgen_test_layout_pam_message() { stringify!(msg_style) ) ); + offset = aligned_offset::<*const libc::c_char>(offset + ::std::mem::size_of::()); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).msg) as usize - ptr as usize }, - 8usize, + offset, concat!( "Offset of field: ", stringify!(pam_message), @@ -104,6 +105,14 @@ fn bindgen_test_layout_pam_message() { stringify!(msg) ) ); + offset = aligned_offset::<*const libc::c_void>( + offset + ::std::mem::size_of::<*const libc::c_char>(), + ); + assert_eq!( + ::std::mem::size_of::(), + offset, + concat!("Size of: ", stringify!(pam_message)) + ); } #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -115,19 +124,15 @@ pub struct pam_response { fn bindgen_test_layout_pam_response() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(pam_response)) - ); assert_eq!( ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of::<*mut libc::c_char>(), concat!("Alignment of ", stringify!(pam_response)) ); + let mut offset: usize = 0; assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).resp) as usize - ptr as usize }, - 0usize, + offset, concat!( "Offset of field: ", stringify!(pam_response), @@ -135,9 +140,10 @@ fn bindgen_test_layout_pam_response() { stringify!(resp) ) ); + offset = aligned_offset::(offset + ::std::mem::size_of::<*mut libc::c_char>()); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).resp_retcode) as usize - ptr as usize }, - 8usize, + offset, concat!( "Offset of field: ", stringify!(pam_response), @@ -145,6 +151,12 @@ fn bindgen_test_layout_pam_response() { stringify!(resp_retcode) ) ); + offset = aligned_offset::<*mut libc::c_void>(offset + ::std::mem::size_of::()); + assert_eq!( + ::std::mem::size_of::(), + offset, + concat!("Size of: ", stringify!(pam_response)) + ); } #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -163,19 +175,15 @@ pub struct pam_conv { fn bindgen_test_layout_pam_conv() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(pam_conv)) - ); assert_eq!( ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of::<*mut libc::c_void>(), concat!("Alignment of ", stringify!(pam_conv)) ); + let mut offset: usize = 0; assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).conv) as usize - ptr as usize }, - 0usize, + offset, concat!( "Offset of field: ", stringify!(pam_conv), @@ -183,9 +191,11 @@ fn bindgen_test_layout_pam_conv() { stringify!(conv) ) ); + offset = + aligned_offset::<*mut libc::c_void>(offset + ::std::mem::size_of::<*mut libc::c_void>()); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).appdata_ptr) as usize - ptr as usize }, - 8usize, + offset, concat!( "Offset of field: ", stringify!(pam_conv), @@ -193,6 +203,13 @@ fn bindgen_test_layout_pam_conv() { stringify!(appdata_ptr) ) ); + offset = + aligned_offset::<*mut libc::c_void>(offset + ::std::mem::size_of::<*mut libc::c_void>()); + assert_eq!( + ::std::mem::size_of::(), + offset, + concat!("Size of: ", stringify!(pam_conv)) + ); } extern "C" { pub fn pam_start( @@ -242,19 +259,15 @@ pub struct passwd { fn bindgen_test_layout_passwd() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 48usize, - concat!("Size of: ", stringify!(passwd)) - ); assert_eq!( ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of::<*mut libc::c_char>(), concat!("Alignment of ", stringify!(passwd)) ); + let mut offset: usize = 0; assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pw_name) as usize - ptr as usize }, - 0usize, + offset, concat!( "Offset of field: ", stringify!(passwd), @@ -262,9 +275,11 @@ fn bindgen_test_layout_passwd() { stringify!(pw_name) ) ); + offset = + aligned_offset::<*mut libc::c_char>(offset + ::std::mem::size_of::<*mut libc::c_char>()); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pw_passwd) as usize - ptr as usize }, - 8usize, + offset, concat!( "Offset of field: ", stringify!(passwd), @@ -272,9 +287,10 @@ fn bindgen_test_layout_passwd() { stringify!(pw_passwd) ) ); + offset = aligned_offset::<__uid_t>(offset + ::std::mem::size_of::<*mut libc::c_char>()); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pw_uid) as usize - ptr as usize }, - 16usize, + offset, concat!( "Offset of field: ", stringify!(passwd), @@ -282,9 +298,10 @@ fn bindgen_test_layout_passwd() { stringify!(pw_uid) ) ); + offset = aligned_offset::<__gid_t>(offset + ::std::mem::size_of::<__uid_t>()); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pw_gid) as usize - ptr as usize }, - 20usize, + offset, concat!( "Offset of field: ", stringify!(passwd), @@ -292,9 +309,10 @@ fn bindgen_test_layout_passwd() { stringify!(pw_gid) ) ); + offset = aligned_offset::<*mut libc::c_char>(offset + ::std::mem::size_of::<__gid_t>()); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pw_gecos) as usize - ptr as usize }, - 24usize, + offset, concat!( "Offset of field: ", stringify!(passwd), @@ -302,9 +320,11 @@ fn bindgen_test_layout_passwd() { stringify!(pw_gecos) ) ); + offset = + aligned_offset::<*mut libc::c_char>(offset + ::std::mem::size_of::<*mut libc::c_char>()); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pw_dir) as usize - ptr as usize }, - 32usize, + offset, concat!( "Offset of field: ", stringify!(passwd), @@ -312,9 +332,11 @@ fn bindgen_test_layout_passwd() { stringify!(pw_dir) ) ); + offset = + aligned_offset::<*mut libc::c_char>(offset + ::std::mem::size_of::<*mut libc::c_char>()); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pw_shell) as usize - ptr as usize }, - 40usize, + offset, concat!( "Offset of field: ", stringify!(passwd), @@ -322,6 +344,13 @@ fn bindgen_test_layout_passwd() { stringify!(pw_shell) ) ); + offset = + aligned_offset::<*mut libc::c_void>(offset + ::std::mem::size_of::<*mut libc::c_char>()); + assert_eq!( + ::std::mem::size_of::(), + offset, + concat!("Size of: ", stringify!(passwd)) + ); } #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -335,19 +364,15 @@ pub struct group { fn bindgen_test_layout_group() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(group)) - ); assert_eq!( ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of::<*mut libc::c_char>(), concat!("Alignment of ", stringify!(group)) ); + let mut offset: usize = 0; assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).gr_name) as usize - ptr as usize }, - 0usize, + offset, concat!( "Offset of field: ", stringify!(group), @@ -355,9 +380,11 @@ fn bindgen_test_layout_group() { stringify!(gr_name) ) ); + offset = + aligned_offset::<*mut libc::c_char>(offset + ::std::mem::size_of::<*mut libc::c_char>()); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).gr_passwd) as usize - ptr as usize }, - 8usize, + offset, concat!( "Offset of field: ", stringify!(group), @@ -365,9 +392,10 @@ fn bindgen_test_layout_group() { stringify!(gr_passwd) ) ); + offset = aligned_offset::<__gid_t>(offset + ::std::mem::size_of::<*mut libc::c_char>()); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).gr_gid) as usize - ptr as usize }, - 16usize, + offset, concat!( "Offset of field: ", stringify!(group), @@ -375,9 +403,10 @@ fn bindgen_test_layout_group() { stringify!(gr_gid) ) ); + offset = aligned_offset::<*mut libc::c_char>(offset + ::std::mem::size_of::<__gid_t>()); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).gr_mem) as usize - ptr as usize }, - 24usize, + offset, concat!( "Offset of field: ", stringify!(group), @@ -385,6 +414,13 @@ fn bindgen_test_layout_group() { stringify!(gr_mem) ) ); + offset = + aligned_offset::<*mut libc::c_void>(offset + ::std::mem::size_of::<*mut libc::c_char>()); + assert_eq!( + ::std::mem::size_of::(), + offset, + concat!("Size of: ", stringify!(group)) + ); } #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -403,19 +439,15 @@ pub struct spwd { fn bindgen_test_layout_spwd() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 72usize, - concat!("Size of: ", stringify!(spwd)) - ); assert_eq!( ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of::<*mut libc::c_char>(), concat!("Alignment of ", stringify!(spwd)) ); + let mut offset: usize = 0; assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).sp_namp) as usize - ptr as usize }, - 0usize, + offset, concat!( "Offset of field: ", stringify!(spwd), @@ -423,9 +455,11 @@ fn bindgen_test_layout_spwd() { stringify!(sp_namp) ) ); + offset = + aligned_offset::<*mut libc::c_char>(offset + ::std::mem::size_of::<*mut libc::c_char>()); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).sp_pwdp) as usize - ptr as usize }, - 8usize, + offset, concat!( "Offset of field: ", stringify!(spwd), @@ -433,9 +467,10 @@ fn bindgen_test_layout_spwd() { stringify!(sp_pwdp) ) ); + offset = aligned_offset::(offset + ::std::mem::size_of::<*mut libc::c_char>()); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).sp_lstchg) as usize - ptr as usize }, - 16usize, + offset, concat!( "Offset of field: ", stringify!(spwd), @@ -443,9 +478,10 @@ fn bindgen_test_layout_spwd() { stringify!(sp_lstchg) ) ); + offset = aligned_offset::(offset + ::std::mem::size_of::()); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).sp_min) as usize - ptr as usize }, - 24usize, + offset, concat!( "Offset of field: ", stringify!(spwd), @@ -453,9 +489,10 @@ fn bindgen_test_layout_spwd() { stringify!(sp_min) ) ); + offset = aligned_offset::(offset + ::std::mem::size_of::()); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).sp_max) as usize - ptr as usize }, - 32usize, + offset, concat!( "Offset of field: ", stringify!(spwd), @@ -463,9 +500,10 @@ fn bindgen_test_layout_spwd() { stringify!(sp_max) ) ); + offset = aligned_offset::(offset + ::std::mem::size_of::()); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).sp_warn) as usize - ptr as usize }, - 40usize, + offset, concat!( "Offset of field: ", stringify!(spwd), @@ -473,9 +511,10 @@ fn bindgen_test_layout_spwd() { stringify!(sp_warn) ) ); + offset = aligned_offset::(offset + ::std::mem::size_of::()); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).sp_inact) as usize - ptr as usize }, - 48usize, + offset, concat!( "Offset of field: ", stringify!(spwd), @@ -483,9 +522,10 @@ fn bindgen_test_layout_spwd() { stringify!(sp_inact) ) ); + offset = aligned_offset::(offset + ::std::mem::size_of::()); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).sp_expire) as usize - ptr as usize }, - 56usize, + offset, concat!( "Offset of field: ", stringify!(spwd), @@ -493,9 +533,10 @@ fn bindgen_test_layout_spwd() { stringify!(sp_expire) ) ); + offset = aligned_offset::(offset + ::std::mem::size_of::()); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).sp_flag) as usize - ptr as usize }, - 64usize, + offset, concat!( "Offset of field: ", stringify!(spwd), @@ -503,6 +544,12 @@ fn bindgen_test_layout_spwd() { stringify!(sp_flag) ) ); + offset = aligned_offset::<*mut libc::c_void>(offset + ::std::mem::size_of::()); + assert_eq!( + ::std::mem::size_of::(), + offset, + concat!("Size of: ", stringify!(spwd)) + ); } #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -518,19 +565,15 @@ pub struct pam_modutil_privs { fn bindgen_test_layout_pam_modutil_privs() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(pam_modutil_privs)) - ); assert_eq!( ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of::<*mut gid_t>(), concat!("Alignment of ", stringify!(pam_modutil_privs)) ); + let mut offset: usize = 0; assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).grplist) as usize - ptr as usize }, - 0usize, + offset, concat!( "Offset of field: ", stringify!(pam_modutil_privs), @@ -538,9 +581,10 @@ fn bindgen_test_layout_pam_modutil_privs() { stringify!(grplist) ) ); + offset = aligned_offset::(offset + ::std::mem::size_of::<*mut gid_t>()); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).number_of_groups) as usize - ptr as usize }, - 8usize, + offset, concat!( "Offset of field: ", stringify!(pam_modutil_privs), @@ -548,9 +592,10 @@ fn bindgen_test_layout_pam_modutil_privs() { stringify!(number_of_groups) ) ); + offset = aligned_offset::(offset + ::std::mem::size_of::()); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).allocated) as usize - ptr as usize }, - 12usize, + offset, concat!( "Offset of field: ", stringify!(pam_modutil_privs), @@ -558,9 +603,10 @@ fn bindgen_test_layout_pam_modutil_privs() { stringify!(allocated) ) ); + offset = aligned_offset::<__gid_t>(offset + ::std::mem::size_of::()); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).old_gid) as usize - ptr as usize }, - 16usize, + offset, concat!( "Offset of field: ", stringify!(pam_modutil_privs), @@ -568,9 +614,10 @@ fn bindgen_test_layout_pam_modutil_privs() { stringify!(old_gid) ) ); + offset = aligned_offset::<__uid_t>(offset + ::std::mem::size_of::<__gid_t>()); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).old_uid) as usize - ptr as usize }, - 20usize, + offset, concat!( "Offset of field: ", stringify!(pam_modutil_privs), @@ -578,9 +625,10 @@ fn bindgen_test_layout_pam_modutil_privs() { stringify!(old_uid) ) ); + offset = aligned_offset::(offset + ::std::mem::size_of::<__uid_t>()); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).is_dropped) as usize - ptr as usize }, - 24usize, + offset, concat!( "Offset of field: ", stringify!(pam_modutil_privs), @@ -588,68 +636,17 @@ fn bindgen_test_layout_pam_modutil_privs() { stringify!(is_dropped) ) ); -} -pub type __builtin_va_list = [__va_list_tag; 1usize]; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct __va_list_tag { - pub gp_offset: libc::c_uint, - pub fp_offset: libc::c_uint, - pub overflow_arg_area: *mut libc::c_void, - pub reg_save_area: *mut libc::c_void, -} -#[test] -fn bindgen_test_layout___va_list_tag() { - const UNINIT: ::std::mem::MaybeUninit<__va_list_tag> = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); + offset = aligned_offset::<*mut libc::c_void>(offset + ::std::mem::size_of::()); assert_eq!( - ::std::mem::size_of::<__va_list_tag>(), - 24usize, - concat!("Size of: ", stringify!(__va_list_tag)) - ); - assert_eq!( - ::std::mem::align_of::<__va_list_tag>(), - 8usize, - concat!("Alignment of ", stringify!(__va_list_tag)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).gp_offset) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__va_list_tag), - "::", - stringify!(gp_offset) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).fp_offset) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(__va_list_tag), - "::", - stringify!(fp_offset) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).overflow_arg_area) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__va_list_tag), - "::", - stringify!(overflow_arg_area) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).reg_save_area) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(__va_list_tag), - "::", - stringify!(reg_save_area) - ) + ::std::mem::size_of::(), + offset, + concat!("Size of: ", stringify!(pam_modutil_privs)) ); } + +#[cfg(test)] +fn aligned_offset(offset: usize) -> usize { + let offset = offset as isize; + let alignment = ::std::mem::align_of::() as isize; + (offset + (-offset).rem_euclid(alignment)) as usize +}