| 1 | #![allow(dead_code)] |
| 2 | |
| 3 | use pam::{Pam, PamError, PamFlags}; |
| 4 | use pam_types::{LogLvl, PamConv, PamHandle, PamItemType, PamMessage, PamMsgStyle, PamResponse}; |
| 5 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::{CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#, CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#, NulErrorrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/NulError#}; |
| 6 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#; |
| 7 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/::Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#; |
| 8 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::{c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#, c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#, c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void#}; |
| 9 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/; |
| 10 | |
| 11 | pub type PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<T> = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, PamErrorrust-analyzer cargo pamsm 0.5.5 pam/PamError#>; |
| 12 | /// Prototype of the callback used with [`PamLibExt::send_bytes`] |
| 13 | pub type PamCleanupCbrust-analyzer cargo pamsm 0.5.5 libpam/PamCleanupCb# = fn(&Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, Pamrust-analyzer cargo pamsm 0.5.5 pam/Pam#, PamFlagsrust-analyzer cargo pamsm 0.5.5 pam/PamFlags#, PamErrorrust-analyzer cargo pamsm 0.5.5 pam/PamError#); |
| 14 | |
| 15 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 16 | struct PamByteDatarust-analyzer cargo pamsm 0.5.5 libpam/PamByteData# { |
| 17 | cbrust-analyzer cargo pamsm 0.5.5 libpam/PamByteData#cb.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<PamCleanupCbrust-analyzer cargo pamsm 0.5.5 libpam/PamCleanupCb#>, |
| 18 | datarust-analyzer cargo pamsm 0.5.5 libpam/PamByteData#data.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, |
| 19 | } |
| 20 | |
| 21 | /// Trait to implement for data stored with pam using [`PamLibExt::send_data`] |
| 22 | /// in order to provide a cleanup callback. |
| 23 | /// # Example |
| 24 | /// ``` |
| 25 | /// extern crate pamsm; |
| 26 | /// use pamsm::{Pam, PamData, PamError, PamFlags}; |
| 27 | /// use std::fs::write; |
| 28 | /// |
| 29 | /// struct Token([u8; 32]); |
| 30 | /// |
| 31 | /// impl PamData for Token { |
| 32 | /// fn cleanup(&self, _pam: Pam, flags: PamFlags, status: PamError) { |
| 33 | /// if !flags.contains(PamFlags::DATA_REPLACE) && status == PamError::SUCCESS { |
| 34 | /// match write(".token.bin", self.0) { |
| 35 | /// Ok(_) => (), |
| 36 | /// Err(err) => { |
| 37 | /// if !flags.contains(PamFlags::SILENT) { |
| 38 | /// println!("Error persisting token : {:?}", err); |
| 39 | /// } |
| 40 | /// } |
| 41 | /// }; |
| 42 | /// } |
| 43 | /// } |
| 44 | /// } |
| 45 | /// ``` |
| 46 | pub trait PamDatarust-analyzer cargo pamsm 0.5.5 libpam/PamData# { |
| 47 | /// The cleanup method will be called before the data is dropped by pam. |
| 48 | /// See `pam_set_data (3)` |
| 49 | fn cleanuprust-analyzer cargo pamsm 0.5.5 libpam/PamData#cleanup().(&self, _pam: Pamrust-analyzer cargo pamsm 0.5.5 pam/Pam#, _flags: PamFlagsrust-analyzer cargo pamsm 0.5.5 pam/PamFlags#, _status: PamErrorrust-analyzer cargo pamsm 0.5.5 pam/PamError#) {} |
| 50 | } |
| 51 | |
| 52 | impl PamDatarust-analyzer cargo pamsm 0.5.5 libpam/PamData# for PamByteDatarust-analyzer cargo pamsm 0.5.5 libpam/PamByteData# { |
| 53 | fn cleanuprust-analyzer cargo pamsm 0.5.5 libpam/impl#[PamByteData][PamData]cleanup().(&self, pam: Pamrust-analyzer cargo pamsm 0.5.5 pam/Pam#, flags: PamFlagsrust-analyzer cargo pamsm 0.5.5 pam/PamFlags#, status: PamErrorrust-analyzer cargo pamsm 0.5.5 pam/PamError#) { |
| 54 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cb) = self.cbrust-analyzer cargo pamsm 0.5.5 libpam/PamByteData#cb. { |
| 55 | (cb)(&self.datarust-analyzer cargo pamsm 0.5.5 libpam/PamByteData#data., pam, flags, status); |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /// Blanket implementation for types that implement `Deref<T>` when `T` implements `PamData`. |
| 61 | impl<T: PamDatarust-analyzer cargo pamsm 0.5.5 libpam/PamData#, U> PamDatarust-analyzer cargo pamsm 0.5.5 libpam/PamData# for U |
| 62 | where |
| 63 | U: Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#<Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target# = T>, |
| 64 | { |
| 65 | fn cleanuprust-analyzer cargo pamsm 0.5.5 libpam/impl#[U][PamData]cleanup().(&self, pam: Pamrust-analyzer cargo pamsm 0.5.5 pam/Pam#, flags: PamFlagsrust-analyzer cargo pamsm 0.5.5 pam/PamFlags#, status: PamErrorrust-analyzer cargo pamsm 0.5.5 pam/PamError#) { |
| 66 | T::cleanuprust-analyzer cargo pamsm 0.5.5 libpam/PamData#cleanup().(self, pam, flags, status) |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | impl PamErrorrust-analyzer cargo pamsm 0.5.5 pam/PamError# { |
| 71 | fn to_resultrust-analyzer cargo pamsm 0.5.5 libpam/impl#[PamError]to_result().<T>(self, ok: T) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<T> { |
| 72 | if self rust-analyzer cargo pamsm 0.5.5 pam/impl#[PamError][`PartialEq<Self>`]eq().==rust-analyzer cargo pamsm 0.5.5 pam/impl#[PamError][`PartialEq<Self>`]eq(). rust-analyzer cargo pamsm 0.5.5 pam/impl#[PamError][`PartialEq<Self>`]eq().PamErrorrust-analyzer cargo pamsm 0.5.5 pam/PamError#::SUCCESSrust-analyzer cargo pamsm 0.5.5 pam/PamError#SUCCESS# { |
| 73 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ok) |
| 74 | } else { |
| 75 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(self) |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | /// This contains a private marker trait, used to seal private traits. |
| 81 | mod privaterust-analyzer cargo pamsm 0.5.5 libpam/private/ { |
| 82 | pub trait Sealedrust-analyzer cargo pamsm 0.5.5 libpam/private/Sealed# {} |
| 83 | impl Sealedrust-analyzer cargo pamsm 0.5.5 libpam/private/Sealed# for superrust-analyzer cargo pamsm 0.5.5 libpam/::Pamrust-analyzer cargo pamsm 0.5.5 pam/Pam# {} |
| 84 | } |
| 85 | |
| 86 | impl Pamrust-analyzer cargo pamsm 0.5.5 pam/Pam# { |
| 87 | // End users should call the item specific methods |
| 88 | fn get_cstr_itemrust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam]get_cstr_item().(&self, item_type: PamItemTyperust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#>> { |
| 89 | match item_type { |
| 90 | PamItemTyperust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#::CONVrust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#CONV# | PamItemTyperust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#::FAIL_DELAYrust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#FAIL_DELAY# | PamItemTyperust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#::XAUTHDATArust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#XAUTHDATA# => { |
| 91 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Error, get_cstr_item can only be used with pam item returning c-strings") |
| 92 | } |
| 93 | _ => (), |
| 94 | } |
| 95 | let mut raw_item: *const c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void# = ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null().(); |
| 96 | let r = unsafe { PamErrorrust-analyzer cargo pamsm 0.5.5 pam/PamError#::newrust-analyzer cargo pamsm 0.5.5 pam/impl#[PamError]new().(pam_get_itemrust-analyzer cargo pamsm 0.5.5 pam_get_item().(self.0rust-analyzer cargo pamsm 0.5.5 pam/Pam#0., item_type as c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#, &mut raw_item)) }; |
| 97 | if raw_item.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]is_null().() { |
| 98 | r.to_resultrust-analyzer cargo pamsm 0.5.5 libpam/impl#[PamError]to_result().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) |
| 99 | } else { |
| 100 | // pam should keep the underlying token allocated during the lifetime of the module |
| 101 | r.to_resultrust-analyzer cargo pamsm 0.5.5 libpam/impl#[PamError]to_result().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(unsafe { CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#::from_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]from_ptr().(raw_item as *const c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#) })) |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | /// Extension trait over `Pam`, usually provided by the `libpam` shared library. |
| 107 | pub trait PamLibExtrust-analyzer cargo pamsm 0.5.5 libpam/PamLibExt#: privaterust-analyzer cargo pamsm 0.5.5 libpam/private/::Sealedrust-analyzer cargo pamsm 0.5.5 libpam/private/Sealed# { |
| 108 | /// Get the username. If the PAM_USER item is not set, this function |
| 109 | /// prompts for a username (like get_authtok). |
| 110 | /// Returns PamError::SERVICE_ERR if the prompt contains any null byte |
| 111 | fn get_userrust-analyzer cargo pamsm 0.5.5 libpam/PamLibExt#get_user().(&self, prompt: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#>>; |
| 112 | |
| 113 | /// Get the username, i.e. the PAM_USER item. If it's not set return None. |
| 114 | fn get_cached_userrust-analyzer cargo pamsm 0.5.5 libpam/PamLibExt#get_cached_user().(&self) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#>>; |
| 115 | |
| 116 | /// Get the cached authentication token. |
| 117 | fn get_cached_authtokrust-analyzer cargo pamsm 0.5.5 libpam/PamLibExt#get_cached_authtok().(&self) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#>>; |
| 118 | |
| 119 | /// Get the cached old authentication token. |
| 120 | fn get_cached_oldauthtokrust-analyzer cargo pamsm 0.5.5 libpam/PamLibExt#get_cached_oldauthtok().(&self) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#>>; |
| 121 | |
| 122 | /// Get the cached authentication token or prompt the user for one if there isn't any. |
| 123 | /// Returns PamError::SERVICE_ERR if the prompt contains any null byte |
| 124 | fn get_authtokrust-analyzer cargo pamsm 0.5.5 libpam/PamLibExt#get_authtok().(&self, prompt: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#>>; |
| 125 | |
| 126 | fn set_authtokrust-analyzer cargo pamsm 0.5.5 libpam/PamLibExt#set_authtok().(&self, authtok: &CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<()>; |
| 127 | |
| 128 | /// Get the remote hostname. |
| 129 | fn get_rhostrust-analyzer cargo pamsm 0.5.5 libpam/PamLibExt#get_rhost().(&self) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#>>; |
| 130 | |
| 131 | /// Get the remote username. |
| 132 | fn get_ruserrust-analyzer cargo pamsm 0.5.5 libpam/PamLibExt#get_ruser().(&self) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#>>; |
| 133 | |
| 134 | /// Get the service name. |
| 135 | fn get_servicerust-analyzer cargo pamsm 0.5.5 libpam/PamLibExt#get_service().(&self) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#>>; |
| 136 | |
| 137 | /// Prompt the user for custom input. |
| 138 | /// Returns PamError::SERVICE_ERR if the prompt contains any null byte |
| 139 | fn convrust-analyzer cargo pamsm 0.5.5 libpam/PamLibExt#conv().(&self, prompt: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>, style: PamMsgStylerust-analyzer cargo pamsm 0.5.5 pam_types/PamMsgStyle#) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#>>; |
| 140 | |
| 141 | /// Get a variable from the pam environment list. |
| 142 | fn getenvrust-analyzer cargo pamsm 0.5.5 libpam/PamLibExt#getenv().(&self, name: &str) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#>>; |
| 143 | |
| 144 | /// Put a variable in the pam environment list. |
| 145 | /// `name_value` takes for form documented in pam_putent(3) : |
| 146 | /// |
| 147 | /// - `NAME=value` will set variable `NAME` to value `value` |
| 148 | /// - `NAME=` will set variable `NAME` to an empty value |
| 149 | /// - `NAME` will unset the variable `NAME` |
| 150 | fn putenvrust-analyzer cargo pamsm 0.5.5 libpam/PamLibExt#putenv().(&self, name_value: &str) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<()>; |
| 151 | |
| 152 | /// Send data to be stored by the pam library under the name `module_name`. |
| 153 | /// The data can then be retrieved from a different |
| 154 | /// callback in this module, or even by a different module |
| 155 | /// using [`retrieve_data<T>`][Self::retrieve_data]. |
| 156 | /// |
| 157 | /// When this method is called a second time with the same `module_name`, the method |
| 158 | /// [`PamData::cleanup`] is called on the data previously stored. |
| 159 | /// The same happens when the application calls `pam_end (3)` |
| 160 | /// |
| 161 | /// If your data can be converted into / from [`Vec<u8>`][std::vec::Vec] |
| 162 | /// you should consider using the [`send_bytes`][Self::send_bytes] method instead. |
| 163 | /// |
| 164 | /// # Safety |
| 165 | /// This method should not be used if the [`send_bytes`][Self::send_bytes] method is also used |
| 166 | /// with the same `module_name`. |
| 167 | unsafe fn send_datarust-analyzer cargo pamsm 0.5.5 libpam/PamLibExt#send_data().<T: PamDatarust-analyzer cargo pamsm 0.5.5 libpam/PamData# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#>( |
| 168 | &self, |
| 169 | module_name: &str, |
| 170 | data: T, |
| 171 | ) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<()>; |
| 172 | |
| 173 | /// Retrieve data previously stored with [`send_data<T>`][Self::send_data]. |
| 174 | /// |
| 175 | /// Note that the result is a _copy_ of the data and not a shared reference, |
| 176 | /// which differs from the behavior of the underlying `pam_get_data (3)` function. |
| 177 | /// |
| 178 | /// If you want to share the data instead you can wrap it in [`Arc`][std::sync::Arc]. |
| 179 | /// # Safety |
| 180 | /// The type parameter `T` must be the same as the one used in |
| 181 | /// [`send_data<T>`][Self::send_data] with the name `module_name`. |
| 182 | /// |
| 183 | /// If the data was stored with [`send_bytes`][Self::send_bytes] you must use |
| 184 | /// [`retrieve_bytes`][Self::retrieve_bytes] instead. |
| 185 | unsafe fn retrieve_datarust-analyzer cargo pamsm 0.5.5 libpam/PamLibExt#retrieve_data().<T: PamDatarust-analyzer cargo pamsm 0.5.5 libpam/PamData# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#>(&self, module_name: &str) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<T>; |
| 186 | |
| 187 | /// Similar to [`send_data`][Self::send_data], but only works with [`Vec<u8>`][std::vec::Vec]. |
| 188 | /// The PamData trait doesn't have to be implemented on the data, a callback can be passed |
| 189 | /// as an argument instead. |
| 190 | fn send_bytesrust-analyzer cargo pamsm 0.5.5 libpam/PamLibExt#send_bytes().( |
| 191 | &self, |
| 192 | module_name: &str, |
| 193 | data: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, |
| 194 | cb: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<PamCleanupCbrust-analyzer cargo pamsm 0.5.5 libpam/PamCleanupCb#>, |
| 195 | ) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<()>; |
| 196 | |
| 197 | /// Retrieve bytes previously stored with [`send_bytes`][Self::send_bytes]. |
| 198 | /// The result is a clone of the data. |
| 199 | fn retrieve_bytesrust-analyzer cargo pamsm 0.5.5 libpam/PamLibExt#retrieve_bytes().(&self, module_name: &str) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>; |
| 200 | |
| 201 | /// Send a message to syslog. |
| 202 | fn syslogrust-analyzer cargo pamsm 0.5.5 libpam/PamLibExt#syslog().(&self, lvl: LogLvlrust-analyzer cargo pamsm 0.5.5 pam_types/LogLvl#, msg: &str) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<()>; |
| 203 | } |
| 204 | |
| 205 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<NulErrorrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/NulError#> for PamErrorrust-analyzer cargo pamsm 0.5.5 pam/PamError# { |
| 206 | fn fromrust-analyzer cargo pamsm 0.5.5 libpam/impl#[PamError][`From<NulError>`]from().(_: NulErrorrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/NulError#) -> PamErrorrust-analyzer cargo pamsm 0.5.5 pam/PamError# { |
| 207 | PamErrorrust-analyzer cargo pamsm 0.5.5 pam/PamError#::SERVICE_ERRrust-analyzer cargo pamsm 0.5.5 pam/PamError#SERVICE_ERR# |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | impl PamLibExtrust-analyzer cargo pamsm 0.5.5 libpam/PamLibExt# for Pamrust-analyzer cargo pamsm 0.5.5 pam/Pam# { |
| 212 | fn get_userrust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam][PamLibExt]get_user().(&self, prompt: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#>> { |
| 213 | let cprompt = match prompt { |
| 214 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 215 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(p) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString]new().(p)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().), |
| 216 | }; |
| 217 | let mut raw_user: *const c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char# = ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null().(); |
| 218 | let r = unsafe { |
| 219 | PamErrorrust-analyzer cargo pamsm 0.5.5 pam/PamError#::newrust-analyzer cargo pamsm 0.5.5 pam/impl#[PamError]new().(pam_get_userrust-analyzer cargo pamsm 0.5.5 pam_get_user().( |
| 220 | self.0rust-analyzer cargo pamsm 0.5.5 pam/Pam#0., |
| 221 | &mut raw_user, |
| 222 | cprompt.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null().(), |p| p.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().()), |
| 223 | )) |
| 224 | }; |
| 225 | |
| 226 | if raw_user.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]is_null().() { |
| 227 | r.to_resultrust-analyzer cargo pamsm 0.5.5 libpam/impl#[PamError]to_result().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) |
| 228 | } else { |
| 229 | r.to_resultrust-analyzer cargo pamsm 0.5.5 libpam/impl#[PamError]to_result().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(unsafe { CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#::from_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]from_ptr().(raw_user) })) |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | fn get_cached_userrust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam][PamLibExt]get_cached_user().(&self) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#>> { |
| 234 | self.get_cstr_itemrust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam]get_cstr_item().(PamItemTyperust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#::USERrust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#USER#) |
| 235 | } |
| 236 | |
| 237 | fn get_cached_authtokrust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam][PamLibExt]get_cached_authtok().(&self) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#>> { |
| 238 | self.get_cstr_itemrust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam]get_cstr_item().(PamItemTyperust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#::AUTHTOKrust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#AUTHTOK#) |
| 239 | } |
| 240 | |
| 241 | fn get_cached_oldauthtokrust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam][PamLibExt]get_cached_oldauthtok().(&self) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#>> { |
| 242 | self.get_cstr_itemrust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam]get_cstr_item().(PamItemTyperust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#::OLDAUTHTOKrust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#OLDAUTHTOK#) |
| 243 | } |
| 244 | |
| 245 | fn get_authtokrust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam][PamLibExt]get_authtok().(&self, prompt: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#>> { |
| 246 | let cprompt = match prompt { |
| 247 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 248 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(p) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString]new().(p)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().), |
| 249 | }; |
| 250 | let mut raw_at: *const c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char# = ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null().(); |
| 251 | let r = unsafe { |
| 252 | PamErrorrust-analyzer cargo pamsm 0.5.5 pam/PamError#::newrust-analyzer cargo pamsm 0.5.5 pam/impl#[PamError]new().(pam_get_authtokrust-analyzer cargo pamsm 0.5.5 pam_get_authtok().( |
| 253 | self.0rust-analyzer cargo pamsm 0.5.5 pam/Pam#0., |
| 254 | PamItemTyperust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#::AUTHTOKrust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#AUTHTOK# as i32, |
| 255 | &mut raw_at, |
| 256 | cprompt.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null().(), |p| p.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().()), |
| 257 | )) |
| 258 | }; |
| 259 | |
| 260 | if raw_at.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]is_null().() { |
| 261 | r.to_resultrust-analyzer cargo pamsm 0.5.5 libpam/impl#[PamError]to_result().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) |
| 262 | } else { |
| 263 | r.to_resultrust-analyzer cargo pamsm 0.5.5 libpam/impl#[PamError]to_result().(unsafe { Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#::from_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]from_ptr().(raw_at)) }) |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | fn set_authtokrust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam][PamLibExt]set_authtok().(&self, authtok: &CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<()> { |
| 268 | unsafe { |
| 269 | set_itemrust-analyzer cargo pamsm 0.5.5 libpam/set_item().( |
| 270 | self.0rust-analyzer cargo pamsm 0.5.5 pam/Pam#0., |
| 271 | PamItemTyperust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#::AUTHTOKrust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#AUTHTOK#, |
| 272 | authtok.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().() as *const c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void#, |
| 273 | ) |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | fn get_rhostrust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam][PamLibExt]get_rhost().(&self) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#>> { |
| 278 | self.get_cstr_itemrust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam]get_cstr_item().(PamItemTyperust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#::RHOSTrust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#RHOST#) |
| 279 | } |
| 280 | |
| 281 | fn get_ruserrust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam][PamLibExt]get_ruser().(&self) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#>> { |
| 282 | self.get_cstr_itemrust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam]get_cstr_item().(PamItemTyperust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#::RUSERrust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#RUSER#) |
| 283 | } |
| 284 | |
| 285 | fn get_servicerust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam][PamLibExt]get_service().(&self) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#>> { |
| 286 | self.get_cstr_itemrust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam]get_cstr_item().(PamItemTyperust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#::SERVICErust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#SERVICE#) |
| 287 | } |
| 288 | |
| 289 | fn convrust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam][PamLibExt]conv().(&self, prompt: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>, style: PamMsgStylerust-analyzer cargo pamsm 0.5.5 pam_types/PamMsgStyle#) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#>> { |
| 290 | let mut conv_pointer: *const c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void# = ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null().(); |
| 291 | let r = unsafe { |
| 292 | PamErrorrust-analyzer cargo pamsm 0.5.5 pam/PamError#::newrust-analyzer cargo pamsm 0.5.5 pam/impl#[PamError]new().(pam_get_itemrust-analyzer cargo pamsm 0.5.5 pam_get_item().( |
| 293 | self.0rust-analyzer cargo pamsm 0.5.5 pam/Pam#0., |
| 294 | PamItemTyperust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#::CONVrust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#CONV# as c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#, |
| 295 | &mut conv_pointer, |
| 296 | )) |
| 297 | }; |
| 298 | |
| 299 | if r rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().PamErrorrust-analyzer cargo pamsm 0.5.5 pam/PamError#::SUCCESSrust-analyzer cargo pamsm 0.5.5 pam/PamError#SUCCESS# { |
| 300 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(r); |
| 301 | } |
| 302 | |
| 303 | if conv_pointer.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]is_null().() { |
| 304 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 305 | } |
| 306 | |
| 307 | let conv = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().(conv_pointer as *const PamConvrust-analyzer cargo pamsm 0.5.5 pam_types/PamConv#) }; |
| 308 | let mut resp_ptr: *mut PamResponserust-analyzer cargo pamsm 0.5.5 pam_types/PamResponse# = ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::null_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null_mut().(); |
| 309 | let msg_cstr = CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString]new().(prompt.unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(""))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 310 | let msg = PamMessagerust-analyzer cargo pamsm 0.5.5 pam_types/PamMessage# { |
| 311 | msg_stylerust-analyzer cargo pamsm 0.5.5 pam_types/PamMessage#msg_style.: style, |
| 312 | msgrust-analyzer cargo pamsm 0.5.5 pam_types/PamMessage#msg.: msg_cstr.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().(), |
| 313 | }; |
| 314 | |
| 315 | match conv.cbrust-analyzer cargo pamsm 0.5.5 pam_types/PamConv#cb..maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|cb| { |
| 316 | PamErrorrust-analyzer cargo pamsm 0.5.5 pam/PamError#::newrust-analyzer cargo pamsm 0.5.5 pam/impl#[PamError]new().(cb( |
| 317 | 1, |
| 318 | &mut (&msg as *const PamMessagerust-analyzer cargo pamsm 0.5.5 pam_types/PamMessage#), |
| 319 | &mut resp_ptr, |
| 320 | conv.appdata_ptrrust-analyzer cargo pamsm 0.5.5 pam_types/PamConv#appdata_ptr., |
| 321 | )) |
| 322 | }) { |
| 323 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(PamErrorrust-analyzer cargo pamsm 0.5.5 pam/PamError#::SUCCESSrust-analyzer cargo pamsm 0.5.5 pam/PamError#SUCCESS#) => { |
| 324 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(unsafe { (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().resp_ptr).resprust-analyzer cargo pamsm 0.5.5 pam_types/PamResponse#resp. }.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|r| unsafe { CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#::from_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]from_ptr().(r.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/non_null/impl#[`NonNull<T>`]as_ptr().()) })) |
| 325 | } |
| 326 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ret) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ret), |
| 327 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#), |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | fn getenvrust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam][PamLibExt]getenv().(&self, name: &str) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#>> { |
| 332 | let cname = CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString]new().(name)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 333 | let cenv = unsafe { pam_getenvrust-analyzer cargo pamsm 0.5.5 pam_getenv().(self.0rust-analyzer cargo pamsm 0.5.5 pam/Pam#0., cname.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().()) }; |
| 334 | |
| 335 | if cenv.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]is_null().() { |
| 336 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) |
| 337 | } else { |
| 338 | unsafe { Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#::from_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]from_ptr().(cenv))) } |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | fn putenvrust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam][PamLibExt]putenv().(&self, name_value: &str) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<()> { |
| 343 | let cenv = CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString]new().(name_value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 344 | unsafe { PamErrorrust-analyzer cargo pamsm 0.5.5 pam/PamError#::newrust-analyzer cargo pamsm 0.5.5 pam/impl#[PamError]new().(pam_putenvrust-analyzer cargo pamsm 0.5.5 pam_putenv().(self.0rust-analyzer cargo pamsm 0.5.5 pam/Pam#0., cenv.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().())).to_resultrust-analyzer cargo pamsm 0.5.5 libpam/impl#[PamError]to_result().(()) } |
| 345 | } |
| 346 | |
| 347 | unsafe fn send_datarust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam][PamLibExt]send_data().<T: PamDatarust-analyzer cargo pamsm 0.5.5 libpam/PamData# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#>( |
| 348 | &self, |
| 349 | module_name: &str, |
| 350 | data: T, |
| 351 | ) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<()> { |
| 352 | // The data has to be allocated on the heap because it will outlive the call stack. |
| 353 | let data_copy = Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(data); |
| 354 | PamErrorrust-analyzer cargo pamsm 0.5.5 pam/PamError#::newrust-analyzer cargo pamsm 0.5.5 pam/impl#[PamError]new().(pam_set_datarust-analyzer cargo pamsm 0.5.5 pam_set_data().( |
| 355 | self.0rust-analyzer cargo pamsm 0.5.5 pam/Pam#0., |
| 356 | CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString]new().(module_name)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().(), |
| 357 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::into_rawrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]into_raw().(data_copy) as *mut c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void#, |
| 358 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(pam_data_cleanuprust-analyzer cargo pamsm 0.5.5 libpam/pam_data_cleanup().::<T>), |
| 359 | )) |
| 360 | .to_resultrust-analyzer cargo pamsm 0.5.5 libpam/impl#[PamError]to_result().(()) |
| 361 | } |
| 362 | |
| 363 | unsafe fn retrieve_datarust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam][PamLibExt]retrieve_data().<T: PamDatarust-analyzer cargo pamsm 0.5.5 libpam/PamData# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#>(&self, module_name: &str) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<T> { |
| 364 | let mut data_ptr: *const c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void# = ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null().(); |
| 365 | // pam_get_data should be safe as long as T is the type that what used in send_data. |
| 366 | PamErrorrust-analyzer cargo pamsm 0.5.5 pam/PamError#::newrust-analyzer cargo pamsm 0.5.5 pam/impl#[PamError]new().(pam_get_datarust-analyzer cargo pamsm 0.5.5 pam_get_data().( |
| 367 | self.0rust-analyzer cargo pamsm 0.5.5 pam/Pam#0., |
| 368 | CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString]new().(module_name)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().(), |
| 369 | &mut data_ptr, |
| 370 | )) |
| 371 | .to_resultrust-analyzer cargo pamsm 0.5.5 libpam/impl#[PamError]to_result().(data_ptr as *const T) |
| 372 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|ptr| (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().ptr).clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()) // pam guaranties the data is valid when SUCCESS is returned. |
| 373 | } |
| 374 | |
| 375 | fn send_bytesrust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam][PamLibExt]send_bytes().( |
| 376 | &self, |
| 377 | module_name: &str, |
| 378 | data: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, |
| 379 | cb: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<PamCleanupCbrust-analyzer cargo pamsm 0.5.5 libpam/PamCleanupCb#>, |
| 380 | ) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<()> { |
| 381 | let data_cb = PamByteDatarust-analyzer cargo pamsm 0.5.5 libpam/PamByteData# { cbrust-analyzer cargo pamsm 0.5.5 libpam/PamByteData#cb., datarust-analyzer cargo pamsm 0.5.5 libpam/PamByteData#data. }; |
| 382 | unsafe { self.send_datarust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam][PamLibExt]send_data().(module_name, data_cb) } |
| 383 | } |
| 384 | |
| 385 | fn retrieve_bytesrust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam][PamLibExt]retrieve_bytes().(&self, module_name: &str) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>> { |
| 386 | unsafe { self.retrieve_datarust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam][PamLibExt]retrieve_data().::<PamByteDatarust-analyzer cargo pamsm 0.5.5 libpam/PamByteData#>(module_name) }.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|data_cb| data_cb.datarust-analyzer cargo pamsm 0.5.5 libpam/PamByteData#data.) |
| 387 | } |
| 388 | |
| 389 | fn syslogrust-analyzer cargo pamsm 0.5.5 libpam/impl#[Pam][PamLibExt]syslog().(&self, lvl: LogLvlrust-analyzer cargo pamsm 0.5.5 pam_types/LogLvl#, msg: &str) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<()> { |
| 390 | let fmt = b"%s\0".as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_ptr().() as *const c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#; |
| 391 | let cmsg = CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString]new().(msg)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 392 | unsafe { |
| 393 | pam_syslogrust-analyzer cargo pamsm 0.5.5 pam_syslog().(self.0rust-analyzer cargo pamsm 0.5.5 pam/Pam#0., lvl as c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#, fmt, cmsg.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().()); |
| 394 | } |
| 395 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | unsafe extern "C" fn pam_data_cleanuprust-analyzer cargo pamsm 0.5.5 libpam/pam_data_cleanup().<T: PamDatarust-analyzer cargo pamsm 0.5.5 libpam/PamData# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#>( |
| 400 | handle: PamHandlerust-analyzer cargo pamsm 0.5.5 pam_types/PamHandle#, |
| 401 | data: *mut c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void#, |
| 402 | error_status: c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#, |
| 403 | ) { |
| 404 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::from_rawrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]from_raw().(data as *mut T).cleanuprust-analyzer cargo pamsm 0.5.5 libpam/impl#[U][PamData]cleanup().( |
| 405 | Pamrust-analyzer cargo pamsm 0.5.5 pam/Pam#(handle), |
| 406 | PamFlagsrust-analyzer cargo pamsm 0.5.5 pam/PamFlags#::from_bits_truncaterust-analyzer cargo pamsm 0.5.5 pam/impl#[PamFlags]from_bits_truncate().(error_status), |
| 407 | PamErrorrust-analyzer cargo pamsm 0.5.5 pam/PamError#::newrust-analyzer cargo pamsm 0.5.5 pam/impl#[PamError]new().(error_status rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitAnd<Self>`]bitand().0xff), |
| 408 | ); |
| 409 | } |
| 410 | |
| 411 | unsafe fn set_itemrust-analyzer cargo pamsm 0.5.5 libpam/set_item().(pamh: PamHandlerust-analyzer cargo pamsm 0.5.5 pam_types/PamHandle#, item_type: PamItemTyperust-analyzer cargo pamsm 0.5.5 pam_types/PamItemType#, item: *const c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void#) -> PamResultrust-analyzer cargo pamsm 0.5.5 libpam/PamResult#<()> { |
| 412 | PamErrorrust-analyzer cargo pamsm 0.5.5 pam/PamError#::newrust-analyzer cargo pamsm 0.5.5 pam/impl#[PamError]new().(pam_set_itemrust-analyzer cargo pamsm 0.5.5 pam_set_item().(pamh, item_type as c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#, item)).to_resultrust-analyzer cargo pamsm 0.5.5 libpam/impl#[PamError]to_result().(()) |
| 413 | } |
| 414 | |
| 415 | // Raw functions |
| 416 | #[link(name = "pam")] |
| 417 | extern "C" { |
| 418 | pub fn pam_set_itemrust-analyzer cargo pamsm 0.5.5 pam_set_item().(pamh: PamHandlerust-analyzer cargo pamsm 0.5.5 pam_types/PamHandle#, item_type: c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#, item: *const c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void#) -> c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#; |
| 419 | pub fn pam_get_itemrust-analyzer cargo pamsm 0.5.5 pam_get_item().(pamh: PamHandlerust-analyzer cargo pamsm 0.5.5 pam_types/PamHandle#, item_type: c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#, item: *mut *const c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void#) -> c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#; |
| 420 | pub fn pam_strerrorrust-analyzer cargo pamsm 0.5.5 pam_strerror().(pamh: PamHandlerust-analyzer cargo pamsm 0.5.5 pam_types/PamHandle#, errnum: c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#) -> *const c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#; |
| 421 | pub fn pam_putenvrust-analyzer cargo pamsm 0.5.5 pam_putenv().(pamh: PamHandlerust-analyzer cargo pamsm 0.5.5 pam_types/PamHandle#, name_value: *const c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#) -> c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#; |
| 422 | pub fn pam_getenvrust-analyzer cargo pamsm 0.5.5 pam_getenv().(pamh: PamHandlerust-analyzer cargo pamsm 0.5.5 pam_types/PamHandle#, name: *const c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#) -> *const c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#; |
| 423 | pub fn pam_getenvlistrust-analyzer cargo pamsm 0.5.5 pam_getenvlist().(pamh: PamHandlerust-analyzer cargo pamsm 0.5.5 pam_types/PamHandle#) -> *mut *mut c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#; |
| 424 | |
| 425 | pub fn pam_set_datarust-analyzer cargo pamsm 0.5.5 pam_set_data().( |
| 426 | pamh: PamHandlerust-analyzer cargo pamsm 0.5.5 pam_types/PamHandle#, |
| 427 | module_data_name: *const c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#, |
| 428 | data: *mut c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void#, |
| 429 | cleanup: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<unsafe extern "C" fn(_: PamHandlerust-analyzer cargo pamsm 0.5.5 pam_types/PamHandle#, _: *mut c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void#, _: c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#)>, |
| 430 | ) -> c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#; |
| 431 | pub fn pam_get_datarust-analyzer cargo pamsm 0.5.5 pam_get_data().( |
| 432 | pamh: PamHandlerust-analyzer cargo pamsm 0.5.5 pam_types/PamHandle#, |
| 433 | module_data_name: *const c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#, |
| 434 | data: *mut *const c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void#, |
| 435 | ) -> c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#; |
| 436 | pub fn pam_get_userrust-analyzer cargo pamsm 0.5.5 pam_get_user().(pamh: PamHandlerust-analyzer cargo pamsm 0.5.5 pam_types/PamHandle#, user: *mut *const c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#, prompt: *const c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#) -> c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#; |
| 437 | pub fn pam_get_authtokrust-analyzer cargo pamsm 0.5.5 pam_get_authtok().( |
| 438 | pamh: PamHandlerust-analyzer cargo pamsm 0.5.5 pam_types/PamHandle#, |
| 439 | item: c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#, |
| 440 | authok_ptr: *mut *const c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#, |
| 441 | prompt: *const c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#, |
| 442 | ) -> c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#; |
| 443 | |
| 444 | pub fn pam_syslogrust-analyzer cargo pamsm 0.5.5 pam_syslog().(pamh: PamHandlerust-analyzer cargo pamsm 0.5.5 pam_types/PamHandle#, priority: c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#, fmt: *const c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#, ...) -> c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void#; |
| 445 | } |