comparison src/handle.rs @ 141:a508a69c068a

Remove a lot of Results from functions. Many functions are documented to only return failing Results when given improper inputs or when there is a memory allocation failure (which can be verified by looking at the source). In cases where we know our input is correct, we don't need to check for memory allocation errors for the same reason that Rust doesn't do so when you, e.g., create a new Vec.
author Paul Fisher <paul@pfish.zone>
date Sat, 05 Jul 2025 17:16:56 -0400
parents a12706e42c9d
children ebb71a412b58
comparison
equal deleted inserted replaced
140:add7228adb2f 141:a508a69c068a
315 /// of PAM for testing PAM modules. 315 /// of PAM for testing PAM modules.
316 pub trait PamHandleModule: Conversation + PamShared { 316 pub trait PamHandleModule: Conversation + PamShared {
317 /// Retrieves the authentication token from the user. 317 /// Retrieves the authentication token from the user.
318 /// 318 ///
319 /// This should only be used by *authentication* and *password-change* 319 /// This should only be used by *authentication* and *password-change*
320 /// PAM modules. This is an extension provided by 320 /// PAM modules.
321 /// both Linux-PAM and OpenPAM.
322 /// 321 ///
323 /// # References 322 /// # References
324 /// 323 ///
325 #[doc = linklist!(pam_get_authtok: man7, manbsd)] 324 #[doc = linklist!(pam_get_authtok: man7, manbsd)]
326 /// 325 ///
338 /// ``` 337 /// ```
339 #[doc = man7!(3 pam_get_authtok)] 338 #[doc = man7!(3 pam_get_authtok)]
340 #[doc = manbsd!(3 pam_get_authtok)] 339 #[doc = manbsd!(3 pam_get_authtok)]
341 fn authtok(&mut self, prompt: Option<&str>) -> Result<String>; 340 fn authtok(&mut self, prompt: Option<&str>) -> Result<String>;
342 341
342 /// Retrieves the user's old authentication token when changing passwords.
343 ///
344 ///
345 fn old_authtok(&mut self, prompt: Option<&str>) -> Result<String>;
346
343 trait_item!( 347 trait_item!(
344 /// Gets the user's authentication token (e.g., password). 348 /// Gets the user's authentication token (e.g., password).
345 /// 349 ///
346 /// This is normally set automatically by PAM when calling 350 /// This is normally set automatically by PAM when calling
347 /// [`authtok`](Self::authtok), but can be set explicitly. 351 /// [`authtok`](Self::authtok), but can be set explicitly.
354 ); 358 );
355 359
356 trait_item!( 360 trait_item!(
357 /// Gets the user's old authentication token when changing passwords. 361 /// Gets the user's old authentication token when changing passwords.
358 /// 362 ///
363 /// This is normally set automatically by PAM when calling
364 /// [`old_authtok`](Self::old_authtok), but can be set explicitly.
365 ///
359 /// This should only ever be called by *password-change* PAM modules. 366 /// This should only ever be called by *password-change* PAM modules.
360 get = old_authtok_item, 367 get = old_authtok_item,
361 item = "PAM_OLDAUTHTOK", 368 item = "PAM_OLDAUTHTOK",
362 see = PamShared::set_old_authtok_item 369 see = PamShared::set_old_authtok_item
363 ); 370 );
364
365 /*
366 TODO: Re-enable this at some point.
367 /// Gets some pointer, identified by `key`, that has been set previously
368 /// using [`set_data`](Self::set_data).
369 ///
370 /// The data, if present, is still owned by the current PAM session.
371 ///
372 /// See the [`pam_get_data` manual page][man]
373 /// or [`pam_get_data` in the Module Writer's Guide][mwg].
374 ///
375 /// # Safety
376 ///
377 /// The data stored under the provided key must be of type `T`,
378 /// otherwise you'll get back a completely invalid `&T`
379 /// and further behavior is undefined.
380 ///
381 /// [man]: https://www.man7.org/linux/man-pages/man3/pam_get_data.3.html
382 /// [mwg]: https://www.chiark.greenend.org.uk/doc/libpam-doc/html/mwg-expected-by-module-item.html#mwg-pam_get_data
383 unsafe fn get_data<T>(&mut self, key: &str) -> Result<Option<&T>>;
384
385 /// Stores a pointer that can be retrieved later with [`get_data`](Self::get_data).
386 ///
387 /// This data is accessible to this module and other PAM modules
388 /// (using the provided `key`), but is *not* accessible to the application.
389 /// The PAM session takes ownership of the data, and it will be dropped
390 /// when the session ends.
391 ///
392 /// See the [`pam_set_data` manual page][man]
393 /// or [`pam_set_data` in the Module Writer's Guide][mwg].
394 ///
395 /// [man]: https://www.man7.org/linux/man-pages/man3/pam_set_data.3.html
396 /// [mwg]: https://www.chiark.greenend.org.uk/doc/libpam-doc/html/mwg-expected-by-module-item.html#mwg-pam_set_data
397 fn set_data<T>(&mut self, key: &str, data: Box<T>) -> Result<()>;
398 */
399 } 371 }