Mercurial > crates > nonstick
diff src/module.rs @ 71:58f9d2a4df38
Reorganize everything again???
- Splits ffi/memory stuff into a bunch of stuff in the pam_ffi module.
- Builds infrastructure for passing Messages and Responses.
- Adds tests for some things at least.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Tue, 03 Jun 2025 21:54:58 -0400 |
parents | 9f8381a1c09c |
children | 47eb242a4f88 |
line wrap: on
line diff
--- a/src/module.rs Tue Jun 03 01:21:59 2025 -0400 +++ b/src/module.rs Tue Jun 03 21:54:58 2025 -0400 @@ -5,8 +5,9 @@ use crate::constants::{ErrorCode, Flags, Result}; use crate::conv::BinaryData; -use crate::conv::{Conversation, Message, Response}; +use crate::conv::{Conversation, Response}; use crate::handle::PamModuleHandle; +use crate::pam_ffi::Message; use secure_string::SecureString; use std::ffi::CStr; @@ -362,12 +363,12 @@ argc: c_int, argv: *const *const c_char, ) -> c_int { - let args = extract_argv(argc, argv); - ErrorCode::result_to_c(super::$ident::account_management( - unsafe { LibPamHandle::from_ptr(pamh) }, - args, - flags, - )) + if let Some(handle) = unsafe { pamh.cast::<LibPamHandle>().as_mut() } { + let args = extract_argv(argc, argv); + ErrorCode::result_to_c(super::$ident::account_management(handle, args, flags)) + } else { + ErrorCode::Ignore as c_int + } } #[no_mangle] @@ -377,12 +378,12 @@ argc: c_int, argv: *const *const c_char, ) -> c_int { - let args = extract_argv(argc, argv); - ErrorCode::result_to_c(super::$ident::authenticate( - unsafe { LibPamHandle::from_ptr(pamh) }, - args, - flags, - )) + if let Some(handle) = unsafe { pamh.cast::<LibPamHandle>().as_mut() } { + let args = extract_argv(argc, argv); + ErrorCode::result_to_c(super::$ident::authenticate(handle, args, flags)) + } else { + ErrorCode::Ignore as c_int + } } #[no_mangle] @@ -392,12 +393,12 @@ argc: c_int, argv: *const *const c_char, ) -> c_int { - let args = extract_argv(argc, argv); - ErrorCode::result_to_c(super::$ident::change_authtok( - unsafe { LibPamHandle::from_ptr(pamh) }, - args, - flags, - )) + if let Some(handle) = unsafe { pamh.cast::<LibPamHandle>().as_mut() } { + let args = extract_argv(argc, argv); + ErrorCode::result_to_c(super::$ident::change_authtok(handle, args, flags)) + } else { + ErrorCode::Ignore as c_int + } } #[no_mangle] @@ -407,12 +408,12 @@ argc: c_int, argv: *const *const c_char, ) -> c_int { - let args = extract_argv(argc, argv); - ErrorCode::result_to_c(super::$ident::close_session( - unsafe { LibPamHandle::from_ptr(pamh) }, - args, - flags, - )) + if let Some(handle) = unsafe { pamh.cast::<LibPamHandle>().as_mut() } { + let args = extract_argv(argc, argv); + ErrorCode::result_to_c(super::$ident::close_session(handle, args, flags)) + } else { + ErrorCode::Ignore as c_int + } } #[no_mangle] @@ -423,11 +424,11 @@ argv: *const *const c_char, ) -> c_int { let args = extract_argv(argc, argv); - ErrorCode::result_to_c(super::$ident::open_session( - unsafe { LibPamHandle::from_ptr(pamh) }, - args, - flags, - )) + if let Some(handle) = unsafe { pamh.cast::<LibPamHandle>().as_mut() } { + ErrorCode::result_to_c(super::$ident::open_session(handle, args, flags)) + } else { + ErrorCode::Ignore as c_int + } } #[no_mangle] @@ -438,11 +439,11 @@ argv: *const *const c_char, ) -> c_int { let args = extract_argv(argc, argv); - ErrorCode::result_to_c(super::$ident::set_credentials( - unsafe { LibPamHandle::from_ptr(pamh) }, - args, - flags, - )) + if let Some(handle) = unsafe { pamh.cast::<LibPamHandle>().as_mut() } { + ErrorCode::result_to_c(super::$ident::set_credentials(handle, args, flags)) + } else { + ErrorCode::Ignore as c_int + } } /// Turns `argc`/`argv` into a [Vec] of [CStr]s. @@ -460,7 +461,7 @@ } #[cfg(test)] -mod test { +mod tests { use super::{ Conversation, ConversationMux, ErrorCode, Message, Response, Result, SecureString, };