Mercurial > crates > nonstick
comparison src/libpam/items.rs @ 163:a75a66cb4181
Add end-to-end tests; fix issues found by tests.
- Create tests and installer/remover shell script
- Fix Pointer/pointee problems
- Add Debug formatting
- Misc cleanup
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Mon, 14 Jul 2025 17:40:11 -0400 |
parents | 1bc52025156b |
children | a1bb1d013567 |
comparison
equal
deleted
inserted
replaced
162:180237d0b498 | 163:a75a66cb4181 |
---|---|
56 /// Gets a C string item. | 56 /// Gets a C string item. |
57 /// | 57 /// |
58 /// # Safety | 58 /// # Safety |
59 /// | 59 /// |
60 /// You better be requesting an item which is a C string. | 60 /// You better be requesting an item which is a C string. |
61 pub unsafe fn get_cstr_item( | 61 pub unsafe fn get_cstr_item(hdl: &LibPamHandle, item_type: ItemType) -> Result<Option<OsString>> { |
62 hdl: &LibPamHandle, | |
63 item_type: ItemType, | |
64 ) -> crate::Result<Option<OsString>> { | |
65 let mut output = ptr::null(); | 62 let mut output = ptr::null(); |
66 let ret = unsafe { libpam_sys::pam_get_item(hdl.raw_ref(), item_type as c_int, &mut output) }; | 63 let ret = unsafe { libpam_sys::pam_get_item(hdl.inner(), item_type as c_int, &mut output) }; |
67 ErrorCode::result_from(ret)?; | 64 ErrorCode::result_from(ret)?; |
68 Ok(memory::copy_pam_string(output.cast())) | 65 Ok(memory::copy_pam_string(output.cast())) |
69 } | 66 } |
70 | 67 |
71 /// Sets a C string item. | 68 /// Sets a C string item. |
75 /// You better be setting an item which is a C string. | 72 /// You better be setting an item which is a C string. |
76 pub unsafe fn set_cstr_item( | 73 pub unsafe fn set_cstr_item( |
77 hdl: &mut LibPamHandle, | 74 hdl: &mut LibPamHandle, |
78 item_type: ItemType, | 75 item_type: ItemType, |
79 data: Option<&OsStr>, | 76 data: Option<&OsStr>, |
80 ) -> crate::Result<()> { | 77 ) -> Result<()> { |
81 let data_str = memory::option_cstr_os(data); | 78 let data_str = memory::option_cstr_os(data); |
82 let ret = unsafe { | 79 let ret = unsafe { |
83 libpam_sys::pam_set_item( | 80 libpam_sys::pam_set_item( |
84 hdl.raw_mut(), | 81 hdl.inner_mut(), |
85 item_type as c_int, | 82 item_type as c_int, |
86 memory::prompt_ptr(data_str.as_deref()).cast(), | 83 memory::prompt_ptr(data_str.as_deref()).cast(), |
87 ) | 84 ) |
88 }; | 85 }; |
89 ErrorCode::result_from(ret) | 86 ErrorCode::result_from(ret) |