annotate libpam-sys/src/aliases.rs @ 183:4f46681b3f54 default tip

Catch a few stray cargo fmt things.
author Paul Fisher <paul@pfish.zone>
date Wed, 30 Jul 2025 18:43:07 -0400
parents 9e4ce1631bd3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
148
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
1 //! Convenience aliases for complex types in PAM.
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
2
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
3 use super::{pam_conv, pam_handle, pam_message, pam_response, pam_set_data};
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
4 use std::ffi::{c_int, c_void};
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
5
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
6 /// The type of [`pam_conv::conv`].
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
7 ///
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
8 /// The exact format of `messages` varies between Linux-PAM and other
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
9 /// implementations. See `libpam_sys_helpers::PtrPtrVec` for details
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
10 /// (and a workaround).
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
11 ///
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
12 /// ```no_run
174
9e4ce1631bd3 Dramatically expand documentation.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
13 /// use libpam_sys::aliases::ConversationCallback;
148
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
14 /// use libpam_sys::pam_conv;
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
15 /// fn convo() -> ConversationCallback {
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
16 /// // ...
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
17 /// # unimplemented!()
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
18 /// }
174
9e4ce1631bd3 Dramatically expand documentation.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
19 /// let conv = pam_conv {
9e4ce1631bd3 Dramatically expand documentation.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
20 /// conv: convo(),
9e4ce1631bd3 Dramatically expand documentation.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
21 /// appdata_ptr: std::ptr::null_mut(),
9e4ce1631bd3 Dramatically expand documentation.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
22 /// };
148
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
23 /// ```
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
24 pub type ConversationCallback = unsafe extern "C" fn(
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
25 num_msg: c_int,
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
26 msg: *const *const pam_message,
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
27 resp: *mut *mut pam_response,
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
28 appdata: *mut c_void,
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
29 ) -> c_int;
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
30
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
31 /// Alias for the callback to [`pam_set_data`].
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
32 ///
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
33 /// ```no_run
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
34 /// # use std::ffi::CString;
174
9e4ce1631bd3 Dramatically expand documentation.
Paul Fisher <paul@pfish.zone>
parents: 148
diff changeset
35 /// use libpam_sys::aliases::CleanupCallback;
148
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
36 /// use libpam_sys::pam_set_data;
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
37 /// # use libpam_sys::pam_handle;
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
38 /// # let handle: *mut pam_handle = std::ptr::null_mut();
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
39 /// # let mut my_data = 100;
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
40 /// # let data_ptr = &mut my_data as *mut i32;
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
41 /// fn cleanup() -> CleanupCallback {
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
42 /// // ...
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
43 /// # unimplemented!()
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
44 /// }
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
45 /// let name = CString::new("name").unwrap();
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
46 /// unsafe {
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
47 /// pam_set_data(handle, name.as_ptr().cast_mut(), data_ptr.cast(), cleanup());
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
48 /// }
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
49 /// ```
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
50 pub type CleanupCallback =
4b3a5095f68c Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
51 unsafe extern "C" fn(pamh: *mut pam_handle, data: *mut c_void, pam_end_status: c_int);