comparison src/libpam/handle.rs @ 155:ab8020566cd9

Only use real PAM constants for logging within `nonstick/libpam`.
author Paul Fisher <paul@pfish.zone>
date Tue, 08 Jul 2025 00:49:38 -0400
parents 3036f2e6a022
children 66e662cde087
comparison
equal deleted inserted replaced
154:f71bfffb6de1 155:ab8020566cd9
320 unsafe { libpam_sys::pam_end(self.0.as_mut(), 0) }; 320 unsafe { libpam_sys::pam_end(self.0.as_mut(), 0) };
321 } 321 }
322 } 322 }
323 323
324 impl PamShared for LibPamHandle { 324 impl PamShared for LibPamHandle {
325 #[cfg(any())]
326 fn log(&self, level: Level, loc: Location<'_>, entry: &str) { 325 fn log(&self, level: Level, loc: Location<'_>, entry: &str) {
327 let entry = match CString::new(entry).or_else(|_| CString::new(dbg!(entry))) { 326 let entry = match CString::new(entry).or_else(|_| CString::new(dbg!(entry))) {
328 Ok(cstr) => cstr, 327 Ok(cstr) => cstr,
329 _ => return, 328 _ => return,
330 }; 329 };
331 #[cfg(pam_impl = "LinuxPam")] 330 #[cfg(pam_impl = "LinuxPam")]
332 { 331 {
332 let level = match level {
333 Level::Error => libc::LOG_ERR,
334 Level::Warning => libc::LOG_WARNING,
335 Level::Info => libc::LOG_INFO,
336 Level::Debug => libc::LOG_DEBUG,
337 };
333 _ = loc; 338 _ = loc;
334 // SAFETY: We're calling this function with a known value. 339 // SAFETY: We're calling this function with a known value.
335 unsafe { 340 unsafe {
336 libpam_sys::pam_syslog(self, level as c_int, "%s\0".as_ptr().cast(), entry.as_ptr()) 341 libpam_sys::pam_syslog(self.raw_ref(), level, "%s\0".as_ptr().cast(), entry.as_ptr())
337 } 342 }
338 } 343 }
339 #[cfg(pam_impl = "OpenPam")] 344 #[cfg(pam_impl = "OpenPam")]
340 { 345 {
341 let func = CString::new(loc.function).unwrap_or(CString::default()); 346 let func = CString::new(loc.function).unwrap_or(CString::default());
347 let level = match level {
348 Level::Error => libpam_sys::PAM_LOG_ERROR,
349 Level::Warning => libpam_sys::PAM_LOG_NOTICE,
350 Level::Info => libpam_sys::PAM_LOG_VERBOSE,
351 Level::Debug => libpam_sys::PAM_LOG_DEBUG,
352 };
342 // SAFETY: We're calling this function with a known value. 353 // SAFETY: We're calling this function with a known value.
343 unsafe { 354 unsafe {
344 libpam_sys::_openpam_log( 355 libpam_sys::_openpam_log(
345 level as c_int, 356 level as c_int,
346 func.as_ptr(), 357 func.as_ptr(),
348 entry.as_ptr(), 359 entry.as_ptr(),
349 ) 360 )
350 } 361 }
351 } 362 }
352 } 363 }
353
354 fn log(&self, _level: Level, _loc: Location<'_>, _entry: &str) {}
355 364
356 fn username(&mut self, prompt: Option<&OsStr>) -> Result<OsString> { 365 fn username(&mut self, prompt: Option<&OsStr>) -> Result<OsString> {
357 let prompt = memory::option_cstr_os(prompt); 366 let prompt = memory::option_cstr_os(prompt);
358 let mut output: *const c_char = ptr::null(); 367 let mut output: *const c_char = ptr::null();
359 let ret = unsafe { 368 let ret = unsafe {