Mercurial > crates > nonstick
comparison src/libpam/handle.rs @ 166:2f5913131295
Separate flag/action flags into flags and action.
This also individualizes the type of flag for each PAM function,
so that you can only call a function with the right flags and values.
| author | Paul Fisher <paul@pfish.zone> |
|---|---|
| date | Tue, 15 Jul 2025 00:32:24 -0400 |
| parents | a75a66cb4181 |
| children | 77470e45e397 |
comparison
equal
deleted
inserted
replaced
| 165:c4b1e280463c | 166:2f5913131295 |
|---|---|
| 7 use crate::items::{Items, ItemsMut}; | 7 use crate::items::{Items, ItemsMut}; |
| 8 use crate::libpam::environ::{LibPamEnviron, LibPamEnvironMut}; | 8 use crate::libpam::environ::{LibPamEnviron, LibPamEnvironMut}; |
| 9 use crate::libpam::items::{LibPamItems, LibPamItemsMut}; | 9 use crate::libpam::items::{LibPamItems, LibPamItemsMut}; |
| 10 use crate::libpam::{items, memory}; | 10 use crate::libpam::{items, memory}; |
| 11 use crate::logging::{Level, Location, Logger}; | 11 use crate::logging::{Level, Location, Logger}; |
| 12 use crate::{Conversation, EnvironMap, Flags, ModuleClient, Transaction}; | 12 use crate::{AuthnFlags, AuthtokFlags, Conversation, EnvironMap, ModuleClient, Transaction}; |
| 13 use libpam_sys_consts::constants; | 13 use libpam_sys_consts::constants; |
| 14 use num_enum::{IntoPrimitive, TryFromPrimitive}; | 14 use num_enum::{IntoPrimitive, TryFromPrimitive}; |
| 15 use std::any::TypeId; | 15 use std::any::TypeId; |
| 16 use std::cell::Cell; | 16 use std::cell::Cell; |
| 17 use std::ffi::{c_char, c_int, c_void, CString, OsStr, OsString}; | 17 use std::ffi::{c_char, c_int, c_void, CString, OsStr, OsString}; |
| 151 unsafe { libpam_sys::pam_end(self.handle.cast(), result) }; | 151 unsafe { libpam_sys::pam_end(self.handle.cast(), result) }; |
| 152 } | 152 } |
| 153 } | 153 } |
| 154 | 154 |
| 155 macro_rules! wrap { | 155 macro_rules! wrap { |
| 156 (fn $name:ident { $pam_func:ident }) => { | 156 (fn $name:ident($ftype:ident) { $pam_func:ident }) => { |
| 157 fn $name(&mut self, flags: Flags) -> Result<()> { | 157 fn $name(&mut self, flags: $ftype) -> Result<()> { |
| 158 ErrorCode::result_from(unsafe { | 158 ErrorCode::result_from(unsafe { |
| 159 libpam_sys::$pam_func((self as *mut Self).cast(), flags.bits()) | 159 libpam_sys::$pam_func((self as *mut Self).cast(), flags.bits()) |
| 160 }) | 160 }) |
| 161 } | 161 } |
| 162 }; | 162 }; |
| 163 } | 163 } |
| 164 | 164 |
| 165 impl Transaction for LibPamHandle { | 165 impl Transaction for LibPamHandle { |
| 166 wrap!(fn authenticate { pam_authenticate }); | 166 wrap!(fn authenticate(AuthnFlags) { pam_authenticate }); |
| 167 wrap!(fn account_management { pam_acct_mgmt }); | 167 wrap!(fn account_management(AuthnFlags) { pam_acct_mgmt }); |
| 168 wrap!(fn change_authtok { pam_chauthtok }); | 168 wrap!(fn change_authtok(AuthtokFlags) { pam_chauthtok }); |
| 169 } | 169 } |
| 170 | 170 |
| 171 // TODO: pam_setcred - app | 171 // TODO: pam_setcred - app |
| 172 // pam_open_session - app | 172 // pam_open_session - app |
| 173 // pam_close_session - app | 173 // pam_close_session - app |
| 231 impl<C: Conversation> Logger for LibPamTransaction<C> { | 231 impl<C: Conversation> Logger for LibPamTransaction<C> { |
| 232 delegate!(fn log(&self, level: Level, location: Location<'_>, entry: fmt::Arguments) -> ()); | 232 delegate!(fn log(&self, level: Level, location: Location<'_>, entry: fmt::Arguments) -> ()); |
| 233 } | 233 } |
| 234 | 234 |
| 235 impl<C: Conversation> Transaction for LibPamTransaction<C> { | 235 impl<C: Conversation> Transaction for LibPamTransaction<C> { |
| 236 delegate!(fn authenticate(&mut self, flags: Flags) -> Result<()>); | 236 delegate!(fn authenticate(&mut self, flags: AuthnFlags) -> Result<()>); |
| 237 delegate!(fn account_management(&mut self, flags: Flags) -> Result<()>); | 237 delegate!(fn account_management(&mut self, flags: AuthnFlags) -> Result<()>); |
| 238 delegate!(fn change_authtok(&mut self, flags: Flags) -> Result<()>); | 238 delegate!(fn change_authtok(&mut self, flags: AuthtokFlags) -> Result<()>); |
| 239 } | 239 } |
| 240 | 240 |
| 241 impl<C: Conversation> PamShared for LibPamTransaction<C> { | 241 impl<C: Conversation> PamShared for LibPamTransaction<C> { |
| 242 delegate!(fn environ(&self) -> impl EnvironMap); | 242 delegate!(fn environ(&self) -> impl EnvironMap); |
| 243 delegate!(fn environ_mut(&mut self) -> impl EnvironMapMut); | 243 delegate!(fn environ_mut(&mut self) -> impl EnvironMapMut); |
