Fix Rust 2024 unsafe block warnings in PAM callback
Wrap raw pointer operations in explicit unsafe blocks inside the unsafe extern "C" conv callback, as required by Rust 2024 edition. Remove unused mut binding.
This commit is contained in:
parent
817a9547ad
commit
60e63a6857
56
src/auth.rs
56
src/auth.rs
@ -64,34 +64,36 @@ unsafe extern "C" fn pam_conv_callback(
|
||||
resp: *mut *mut PamResponse,
|
||||
appdata_ptr: *mut libc::c_void,
|
||||
) -> libc::c_int {
|
||||
// Safety: appdata_ptr was set to a valid *const CString in authenticate()
|
||||
let password = appdata_ptr as *const CString;
|
||||
if password.is_null() {
|
||||
return 7; // PAM_AUTH_ERR
|
||||
unsafe {
|
||||
// Safety: appdata_ptr was set to a valid *const CString in authenticate()
|
||||
let password = appdata_ptr as *const CString;
|
||||
if password.is_null() {
|
||||
return 7; // PAM_AUTH_ERR
|
||||
}
|
||||
|
||||
// Safety: calloc returns zeroed memory for num_msg PamResponse structs.
|
||||
// PAM owns this memory and will free() it.
|
||||
let resp_array = libc::calloc(
|
||||
num_msg as libc::size_t,
|
||||
std::mem::size_of::<PamResponse>() as libc::size_t,
|
||||
) as *mut PamResponse;
|
||||
|
||||
if resp_array.is_null() {
|
||||
return 7; // PAM_AUTH_ERR
|
||||
}
|
||||
|
||||
for i in 0..num_msg as isize {
|
||||
// Safety: strdup allocates with malloc — PAM will free() the resp strings.
|
||||
// We dereference password which is valid for the lifetime of authenticate().
|
||||
let resp_ptr = resp_array.offset(i);
|
||||
(*resp_ptr).resp = libc::strdup((*password).as_ptr());
|
||||
(*resp_ptr).resp_retcode = 0;
|
||||
}
|
||||
|
||||
// Safety: resp is a valid pointer provided by PAM
|
||||
*resp = resp_array;
|
||||
PAM_SUCCESS
|
||||
}
|
||||
|
||||
// Safety: calloc returns zeroed memory for num_msg PamResponse structs.
|
||||
// PAM owns this memory and will free() it.
|
||||
let resp_array = libc::calloc(
|
||||
num_msg as libc::size_t,
|
||||
std::mem::size_of::<PamResponse>() as libc::size_t,
|
||||
) as *mut PamResponse;
|
||||
|
||||
if resp_array.is_null() {
|
||||
return 7; // PAM_AUTH_ERR
|
||||
}
|
||||
|
||||
for i in 0..num_msg as isize {
|
||||
// Safety: strdup allocates with malloc — PAM will free() the resp strings.
|
||||
// We dereference password which is valid for the lifetime of authenticate().
|
||||
let resp_ptr = resp_array.offset(i);
|
||||
(*resp_ptr).resp = libc::strdup((*password).as_ptr());
|
||||
(*resp_ptr).resp_retcode = 0;
|
||||
}
|
||||
|
||||
// Safety: resp is a valid pointer provided by PAM
|
||||
*resp = resp_array;
|
||||
PAM_SUCCESS
|
||||
}
|
||||
|
||||
/// Authenticate a user via PAM.
|
||||
|
||||
@ -47,7 +47,7 @@ pub fn create_lockscreen_window(
|
||||
}
|
||||
};
|
||||
|
||||
let mut fp_listener = FingerprintListener::new();
|
||||
let fp_listener = FingerprintListener::new();
|
||||
let fp_available = config.fingerprint_enabled
|
||||
&& fp_listener.is_available(&user.username);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user