| 1 | //! Parts of the code below are Copyright (c) 2023, Conrad Kleinespel et al |
| 2 | //! |
| 3 | //! This module contains code that was originally written by Conrad Kleinespel for the rpassword |
| 4 | //! crate. No copyright notices were found in the original code. |
| 5 | //! |
| 6 | //! See: <https://docs.rs/rpassword/latest/rpassword/> |
| 7 | //! |
| 8 | //! Most code was replaced and so is no longer a derived work; work that we kept: |
| 9 | //! |
| 10 | //! - the "HiddenInput" struct and implementation, with changes: |
| 11 | //! * replaced occurrences of explicit 'i32' and 'c_int' with RawFd |
| 12 | //! * open the TTY ourselves to mitigate Linux CVE-2023-2002 |
| 13 | //! - the general idea of a "SafeString" type that clears its memory |
| 14 | //! (although much more robust than in the original code) |
| 15 | |
| 16 | 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/::c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void#; |
| 17 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#}; |
| 18 | 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/::fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/::{AsFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/AsFd#, AsRawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/AsRawFd#, BorrowedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/BorrowedFd#}; |
| 19 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#; |
| 20 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::{Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#, Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#}; |
| 21 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/, memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/}; |
| 22 | |
| 23 | use libcrust-analyzer cargo libc 0.2.186 crate/::{ |
| 24 | ECHOrust-analyzer cargo libc 0.2.186 unix/linux_like/ECHO., ECHONLrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/ECHONL., ICANONrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/ICANON., SIGALRMrust-analyzer cargo libc 0.2.186 unix/linux_like/SIGALRM., SIGHUPrust-analyzer cargo libc 0.2.186 unix/linux_like/SIGHUP., SIGINTrust-analyzer cargo libc 0.2.186 unix/linux_like/SIGINT., SIGQUITrust-analyzer cargo libc 0.2.186 unix/linux_like/SIGQUIT., SIGTERMrust-analyzer cargo libc 0.2.186 unix/linux_like/SIGTERM., SIGTSTPrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/SIGTSTP., SIGTTINrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/SIGTTIN., SIGTTOUrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/SIGTTOU., |
| 25 | TCSANOWrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/TCSANOW., VEOFrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/VEOF., VERASErust-analyzer cargo libc 0.2.186 unix/linux_like/VERASE., VKILLrust-analyzer cargo libc 0.2.186 unix/linux_like/VKILL., tcsetattrrust-analyzer cargo libc 0.2.186 tcsetattr()., termiosrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#, |
| 26 | }; |
| 27 | |
| 28 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::cutilsrust-analyzer cargo sudo-rs 0.2.14 cutils/::{cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr()., safe_isattyrust-analyzer cargo sudo-rs 0.2.14 cutils/safe_isatty().}; |
| 29 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::pamrust-analyzer cargo sudo-rs 0.2.14 pam/::{PamErrorrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamError#, PamResultrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamResult#, askpassrust-analyzer cargo sudo-rs 0.2.14 pam/askpass/}; |
| 30 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::systemrust-analyzer cargo sudo-rs 0.2.14 system/::signalrust-analyzer cargo sudo-rs 0.2.14 system/signal/::{ |
| 31 | selfrust-analyzer cargo sudo-rs 0.2.14 system/signal/, SignalHandlerrust-analyzer cargo sudo-rs 0.2.14 system/signal/handler/SignalHandler#, SignalHandlerBehaviorrust-analyzer cargo sudo-rs 0.2.14 system/signal/handler/SignalHandlerBehavior#, SignalsStaterust-analyzer cargo sudo-rs 0.2.14 system/signal/state/SignalsState#, exit_with_signalrust-analyzer cargo sudo-rs 0.2.14 system/signal/exit_with_signal()., |
| 32 | }; |
| 33 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::systemrust-analyzer cargo sudo-rs 0.2.14 system/::waitrust-analyzer cargo sudo-rs 0.2.14 system/wait/::{Waitrust-analyzer cargo sudo-rs 0.2.14 system/wait/Wait#, WaitErrorrust-analyzer cargo sudo-rs 0.2.14 system/wait/WaitError#, WaitOptionsrust-analyzer cargo sudo-rs 0.2.14 system/wait/WaitOptions#}; |
| 34 | |
| 35 | use superrust-analyzer cargo sudo-rs 0.2.14 pam/::securememrust-analyzer cargo sudo-rs 0.2.14 pam/securemem/::PamBufferrust-analyzer cargo sudo-rs 0.2.14 pam/securemem/PamBuffer#; |
| 36 | |
| 37 | struct HiddenInputrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/HiddenInput#<'a> { |
| 38 | ttyrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/HiddenInput#tty.: BorrowedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/BorrowedFd#<'a>, |
| 39 | term_origrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/HiddenInput#term_orig.: termiosrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#, |
| 40 | } |
| 41 | |
| 42 | impl HiddenInputrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/HiddenInput#<'_> { |
| 43 | fn newrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`HiddenInput<'_>`]new().(tty: BorrowedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/BorrowedFd#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<HiddenInputrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/HiddenInput#> { |
| 44 | // Make two copies of the terminal settings. The first one will be modified |
| 45 | // and the second one will act as a backup for when we want to set the |
| 46 | // terminal back to its original state. |
| 47 | let mut term = safe_tcgetattrrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/safe_tcgetattr().(tty)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 48 | let term_orig = safe_tcgetattrrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/safe_tcgetattr().(tty)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 49 | |
| 50 | // Hide the password. This is what makes this function useful. |
| 51 | term.c_lflagrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#c_lflag. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAndAssign<Self>`]bitand_assign().&=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAndAssign<Self>`]bitand_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAndAssign<Self>`]bitand_assign().!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][Not]not().ECHOrust-analyzer cargo libc 0.2.186 unix/linux_like/ECHO.; |
| 52 | |
| 53 | // But don't hide the NL character when the user hits ENTER. |
| 54 | term.c_lflagrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#c_lflag. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOrAssign<Self>`]bitor_assign().ECHONLrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/ECHONL.; |
| 55 | |
| 56 | // Disable canonical mode to read character by character when pwfeedback is enabled. |
| 57 | term.c_lflagrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#c_lflag. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAndAssign<Self>`]bitand_assign().&=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAndAssign<Self>`]bitand_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAndAssign<Self>`]bitand_assign().!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][Not]not().ICANONrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/ICANON.; |
| 58 | |
| 59 | // Save the settings for now. |
| 60 | // SAFETY: we are passing tcsetattr a valid file descriptor and pointer-to-struct |
| 61 | cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr().(unsafe { tcsetattrrust-analyzer cargo libc 0.2.186 tcsetattr().(tty.as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`BorrowedFd<'_>`][AsRawFd]as_raw_fd().(), TCSANOWrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/TCSANOW., &term) })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 62 | |
| 63 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(HiddenInputrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/HiddenInput# { ttyrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/HiddenInput#tty., term_origrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/HiddenInput#term_orig. }) |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | impl Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for HiddenInputrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/HiddenInput#<'_> { |
| 68 | fn droprust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`HiddenInput<'_>`][Drop]drop().(&mut self) { |
| 69 | // Set the the mode back to normal |
| 70 | // SAFETY: we are passing tcsetattr a valid file descriptor and pointer-to-struct |
| 71 | unsafe { |
| 72 | tcsetattrrust-analyzer cargo libc 0.2.186 tcsetattr().(self.ttyrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/HiddenInput#tty..as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`BorrowedFd<'_>`][AsRawFd]as_raw_fd().(), TCSANOWrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/TCSANOW., &self.term_origrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/HiddenInput#term_orig.); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | fn safe_tcgetattrrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/safe_tcgetattr().(tty: impl AsFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/AsFd#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<termiosrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#> { |
| 78 | let mut term = memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::MaybeUninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/MaybeUninit#::<termiosrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#>::uninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]uninit().(); |
| 79 | // SAFETY: we are passing tcgetattr a pointer to valid memory |
| 80 | cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr().(unsafe { ::libcrust-analyzer cargo libc 0.2.186 crate/::tcgetattrrust-analyzer cargo libc 0.2.186 tcgetattr().(tty.as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/AsFd#as_fd().().as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`BorrowedFd<'_>`][AsRawFd]as_raw_fd().(), term.as_mut_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]as_mut_ptr().()) })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 81 | // SAFETY: if the previous call was a success, `tcgetattr` has initialized `term` |
| 82 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(unsafe { term.assume_initrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]assume_init().() }) |
| 83 | } |
| 84 | |
| 85 | fn erase_feedbackrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/erase_feedback().(sink: &mut dyn iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#, i: usize) { |
| 86 | const BACKSPACErust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/BACKSPACE.: u8 = 0x08; |
| 87 | for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#i { |
| 88 | if sink.writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write().(&[BACKSPACErust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/BACKSPACE., b' ', BACKSPACErust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/BACKSPACE.]).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().() { |
| 89 | return; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | // Erase everyting after the cursor to make sure we don't leak the password |
| 94 | // size through the amount of spaces that are shown if you select the line |
| 95 | // containing the password in your terminal emulator. |
| 96 | // CSI n K: Erase in Line, 0 = erase from cursor to end of line |
| 97 | let _ = sink.writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write().(b"\x1b[0K"); |
| 98 | } |
| 99 | |
| 100 | #[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:)] |
| 101 | pub(superrust-analyzer cargo sudo-rs 0.2.14 pam/) enum Hiddenrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#<T> { |
| 102 | Norust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#No#, |
| 103 | Yesrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#Yes#(T), |
| 104 | WithFeedbackrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#WithFeedback#(T), |
| 105 | } |
| 106 | |
| 107 | /// Prompt for a password while optionally showing feedback to the user. |
| 108 | fn prompt_passwordrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/prompt_password().( |
| 109 | source: BorrowedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/BorrowedFd#<'_>, |
| 110 | sink: &mut dyn iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#, |
| 111 | prompt: &str, |
| 112 | timeout: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#>, |
| 113 | hidden: Hiddenrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#<()>, |
| 114 | ) -> PamResultrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamResult#<PamBufferrust-analyzer cargo sudo-rs 0.2.14 pam/securemem/PamBuffer#> { |
| 115 | 'getpass: loop { |
| 116 | let hide_input = match hidden.clonerust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`Hidden<T>`][Clone]clone().() { |
| 117 | // If input is not a tty, we can't hide feedback. |
| 118 | _ if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().safe_isattyrust-analyzer cargo sudo-rs 0.2.14 cutils/safe_isatty().(source) => Hiddenrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#::Norust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#No#, |
| 119 | |
| 120 | Hiddenrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#::Norust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#No# => Hiddenrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#::Norust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#No#, |
| 121 | Hiddenrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#::Yesrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#Yes#(()) => Hiddenrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#::Yesrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#Yes#(HiddenInputrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/HiddenInput#::newrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`HiddenInput<'_>`]new().(source)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().), |
| 122 | Hiddenrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#::WithFeedbackrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#WithFeedback#(()) => Hiddenrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#::WithFeedbackrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#WithFeedback#(HiddenInputrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/HiddenInput#::newrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`HiddenInput<'_>`]new().(source)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().), |
| 123 | }; |
| 124 | let mut reader = TimeoutReadrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/TimeoutRead#::newrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`TimeoutRead<'a>`]new().(source, timeout); |
| 125 | |
| 126 | // Write prompt after hiding input to ensure the prompt shows after resuming sudo-rs if it |
| 127 | // was started in the background using & rather than -b. |
| 128 | write_unbufferedrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/write_unbuffered().(sink, prompt.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 129 | |
| 130 | let handlers = { |
| 131 | // Creating a new SignalsState is fine here as we are guaranteed to restore the signals |
| 132 | // again before returning. |
| 133 | let original_signals: &mut SignalsStaterust-analyzer cargo sudo-rs 0.2.14 system/signal/state/SignalsState# = &mut SignalsStaterust-analyzer cargo sudo-rs 0.2.14 system/signal/state/SignalsState#::saverust-analyzer cargo sudo-rs 0.2.14 system/signal/state/impl#[SignalsState]save().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 134 | [ |
| 135 | SIGALRMrust-analyzer cargo libc 0.2.186 unix/linux_like/SIGALRM., SIGINTrust-analyzer cargo libc 0.2.186 unix/linux_like/SIGINT., SIGHUPrust-analyzer cargo libc 0.2.186 unix/linux_like/SIGHUP., SIGQUITrust-analyzer cargo libc 0.2.186 unix/linux_like/SIGQUIT., SIGTERMrust-analyzer cargo libc 0.2.186 unix/linux_like/SIGTERM., SIGTSTPrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/SIGTSTP., SIGTTINrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/SIGTTIN., SIGTTOUrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/SIGTTOU., |
| 136 | ] |
| 137 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`]map().(|signal| { |
| 138 | SignalHandlerrust-analyzer cargo sudo-rs 0.2.14 system/signal/handler/SignalHandler#::registerrust-analyzer cargo sudo-rs 0.2.14 system/signal/handler/impl#[SignalHandler]register().( |
| 139 | signal, |
| 140 | SignalHandlerBehaviorrust-analyzer cargo sudo-rs 0.2.14 system/signal/handler/SignalHandlerBehavior#::StorePendingrust-analyzer cargo sudo-rs 0.2.14 system/signal/handler/SignalHandlerBehavior#StorePending#, |
| 141 | original_signals, |
| 142 | ) |
| 143 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 144 | }) |
| 145 | }; |
| 146 | |
| 147 | let res = read_unbufferedrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/read_unbuffered().(&mut reader, sink, &hide_input); |
| 148 | |
| 149 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(hide_input); |
| 150 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(handlers); |
| 151 | |
| 152 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(signal) = signalrust-analyzer cargo sudo-rs 0.2.14 system/signal/::take_first_pendingrust-analyzer cargo sudo-rs 0.2.14 system/signal/set/take_first_pending().() { |
| 153 | match signal { |
| 154 | SIGTSTPrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/SIGTSTP. | SIGTTINrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/SIGTTIN. | SIGTTOUrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/SIGTTOU. => { |
| 155 | craterust-analyzer cargo sudo-rs 0.2.14 crate/::systemrust-analyzer cargo sudo-rs 0.2.14 system/::killrust-analyzer cargo sudo-rs 0.2.14 system/kill().(craterust-analyzer cargo sudo-rs 0.2.14 crate/::systemrust-analyzer cargo sudo-rs 0.2.14 system/::Processrust-analyzer cargo sudo-rs 0.2.14 system/Process#::process_idrust-analyzer cargo sudo-rs 0.2.14 system/impl#[Process]process_id().(), signal)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 156 | continue 'getpass; |
| 157 | } |
| 158 | _ => { |
| 159 | exit_with_signalrust-analyzer cargo sudo-rs 0.2.14 system/signal/exit_with_signal().(signal).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | return res; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | /// Heuristically determine the length of the final (potentially incomplete) UTF8 sequence |
| 169 | fn last_char_sizerust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/last_char_size().(slice: &[u8]) -> usize { |
| 170 | let start = |byte| byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[`&u8`][`BitAnd<u8>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[`&u8`][`BitAnd<u8>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[`&u8`][`BitAnd<u8>`]bitand().0b1100_0000 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0b1100_0000; |
| 171 | let trail = |byte| byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[`&u8`][`BitAnd<u8>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[`&u8`][`BitAnd<u8>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[`&u8`][`BitAnd<u8>`]bitand().0b1100_0000 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0b1000_0000; |
| 172 | |
| 173 | match slice { |
| 174 | [] => 0, |
| 175 | [.., a, b] if start(a) && trail(b) => 2, |
| 176 | [.., a, b, c] if start(a) && [b, c].into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/iter/impl#[`[T; N]`][IntoIterator]into_iter().().allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#all().(trail) => 3, |
| 177 | [.., a, b, c, d] if start(a) && [b, c, d].into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/iter/impl#[`[T; N]`][IntoIterator]into_iter().().allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#all().(trail) => 4, |
| 178 | _ => 1, |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | /// Reads a password from the given file descriptor while optionally showing feedback to the user. |
| 183 | fn read_unbufferedrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/read_unbuffered().( |
| 184 | source: &mut TimeoutReadrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/TimeoutRead#<'_>, |
| 185 | sink: &mut dyn iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#, |
| 186 | hide_input: &Hiddenrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#<HiddenInputrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/HiddenInput#>, |
| 187 | ) -> PamResultrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamResult#<PamBufferrust-analyzer cargo sudo-rs 0.2.14 pam/securemem/PamBuffer#> { |
| 188 | struct Bulletsrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Bullets#<'a> { |
| 189 | visible_lenrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Bullets#visible_len.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>, |
| 190 | sinkrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Bullets#sink.: &'a mut dyn iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#, |
| 191 | } |
| 192 | |
| 193 | const BULLETrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/BULLET.: &[u8] = b"*"; |
| 194 | |
| 195 | impl Bulletsrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Bullets#<'_> { |
| 196 | fn pushrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`Bullets<'_>`]push().(&mut self) { |
| 197 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref mut len) = self.visible_lenrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Bullets#visible_len. { |
| 198 | let _ = self.sinkrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Bullets#sink..writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write().(BULLETrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/BULLET.); |
| 199 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | fn poprust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`Bullets<'_>`]pop().(&mut self) { |
| 204 | match self.visible_lenrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Bullets#visible_len. { |
| 205 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref mut len) if *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 => { |
| 206 | erase_feedbackrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/erase_feedback().(self.sinkrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Bullets#sink., 1); |
| 207 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1; |
| 208 | } |
| 209 | _ => {} |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | fn clearrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`Bullets<'_>`]clear().(&mut self) { |
| 214 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref mut len) = self.visible_lenrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Bullets#visible_len. { |
| 215 | erase_feedbackrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/erase_feedback().(self.sinkrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Bullets#sink., *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().len); |
| 216 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().len = 0; |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | // Ensure we erase the password feedback no matter how we exit read_unbuffered |
| 222 | impl Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for Bulletsrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Bullets#<'_> { |
| 223 | fn droprust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`Bullets<'_>`][Drop]drop().(&mut self) { |
| 224 | self.clearrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`Bullets<'_>`]clear().(); |
| 225 | let _ = self.sinkrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Bullets#sink..writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write().(b"\n"); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | let mut feedback = Bulletsrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Bullets# { |
| 230 | visible_lenrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Bullets#visible_len.: matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(hide_input, Hiddenrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#::WithFeedbackrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#WithFeedback#(_)).then_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core bool/impl#[bool]then_some().(0), |
| 231 | sinkrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Bullets#sink., |
| 232 | }; |
| 233 | |
| 234 | let mut password = PamBufferrust-analyzer cargo sudo-rs 0.2.14 pam/securemem/PamBuffer#::defaultrust-analyzer cargo sudo-rs 0.2.14 pam/securemem/impl#[PamBuffer][Default]default().(); |
| 235 | let mut pw_len = 0; |
| 236 | |
| 237 | loop { |
| 238 | let read_byte = match source.read_byterust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`TimeoutRead<'_>`]read_byte().() { |
| 239 | 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#(byte)) => byte, |
| 240 | 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#) => break, |
| 241 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) if err.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().() rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().==rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq(). rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::TimedOutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#TimedOut# => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(PamErrorrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamError#::TimedOutrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamError#TimedOut#), |
| 242 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(PamErrorrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamError#::IoErrorrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamError#IoError#(err)), |
| 243 | }; |
| 244 | |
| 245 | if read_byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'\n' || read_byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'\r' { |
| 246 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(password); |
| 247 | } |
| 248 | |
| 249 | if let Hiddenrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#::Yesrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#Yes#(input) | Hiddenrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#::WithFeedbackrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#WithFeedback#(input) = hide_input { |
| 250 | if read_byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().input.term_origrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/HiddenInput#term_orig..c_ccrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#c_cc.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().VEOFrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/VEOF.]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). { |
| 251 | break; |
| 252 | } |
| 253 | |
| 254 | if read_byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().input.term_origrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/HiddenInput#term_orig..c_ccrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#c_cc.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().VERASErust-analyzer cargo libc 0.2.186 unix/linux_like/VERASE.]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). { |
| 255 | feedback.poprust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`Bullets<'_>`]pop().(); |
| 256 | let chunk = last_char_sizerust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/last_char_size().(&password[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#pw_len]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 257 | password[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().pw_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().chunk..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#pw_len]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()..fillrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]fill().(0); |
| 258 | pw_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().chunk; |
| 259 | continue; |
| 260 | } |
| 261 | |
| 262 | if read_byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().input.term_origrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/HiddenInput#term_orig..c_ccrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#c_cc.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().VKILLrust-analyzer cargo libc 0.2.186 unix/linux_like/VKILL.]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). { |
| 263 | feedback.clearrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`Bullets<'_>`]clear().(); |
| 264 | password.fillrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]fill().(0); |
| 265 | pw_len = 0; |
| 266 | continue; |
| 267 | } |
| 268 | |
| 269 | if read_byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'\t' && feedback.visible_lenrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Bullets#visible_len..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 270 | feedback.clearrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`Bullets<'_>`]clear().(); |
| 271 | feedback.visible_lenrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Bullets#visible_len. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 272 | let _ = feedback.sinkrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Bullets#sink..writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write().(b"(no echo)"); |
| 273 | continue; |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(dest) = password.get_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_mut().(pw_len) { |
| 278 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().dest = read_byte; |
| 279 | pw_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 280 | if last_char_sizerust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/last_char_size().(&password[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#pw_len]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().1 { |
| 281 | feedback.pushrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`Bullets<'_>`]push().(); |
| 282 | } |
| 283 | } else { |
| 284 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(PamErrorrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamError#::IncorrectPasswordAttemptrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamError#IncorrectPasswordAttempt#); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | if pw_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 { |
| 289 | // In case of EOF or Ctrl-D we don't want to ask for a password a second |
| 290 | // time, so return an error. |
| 291 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(PamErrorrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamError#::NoPasswordProvidedrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamError#NoPasswordProvided#) |
| 292 | } else { |
| 293 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(password) |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | /// Write something and immediately flush |
| 298 | fn write_unbufferedrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/write_unbuffered().(sink: &mut dyn iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#, text: &[u8]) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 299 | sink.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(text)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 300 | sink.flushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#flush().() |
| 301 | } |
| 302 | |
| 303 | struct TimeoutReadrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/TimeoutRead#<'a> { |
| 304 | timeout_atrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/TimeoutRead#timeout_at.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#>, |
| 305 | fdrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/TimeoutRead#fd.: BorrowedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/BorrowedFd#<'a>, |
| 306 | } |
| 307 | |
| 308 | impl<'a> TimeoutReadrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/TimeoutRead#<'a> { |
| 309 | fn newrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`TimeoutRead<'a>`]new().(fd: BorrowedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/BorrowedFd#<'a>, timeout: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#>) -> TimeoutReadrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/TimeoutRead#<'a> { |
| 310 | TimeoutReadrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/TimeoutRead# { |
| 311 | timeout_atrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/TimeoutRead#timeout_at.: timeout.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|timeout| Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#::nowrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]now().() rust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant][`Add<Duration>`]add().+rust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant][`Add<Duration>`]add(). rust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant][`Add<Duration>`]add().timeout), |
| 312 | fdrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/TimeoutRead#fd., |
| 313 | } |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | impl TimeoutReadrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/TimeoutRead#<'_> { |
| 318 | fn read_byterust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`TimeoutRead<'_>`]read_byte().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u8>> { |
| 319 | let pollmask = libcrust-analyzer cargo libc 0.2.186 crate/::POLLINrust-analyzer cargo libc 0.2.186 unix/linux_like/POLLIN. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i16][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i16][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i16][`BitOr<Self>`]bitor().libcrust-analyzer cargo libc 0.2.186 crate/::POLLRDHUPrust-analyzer cargo libc 0.2.186 unix/linux_like/POLLRDHUP.; |
| 320 | |
| 321 | let mut pollfd = [libcrust-analyzer cargo libc 0.2.186 crate/::pollfdrust-analyzer cargo libc 0.2.186 unix/pollfd# { |
| 322 | fdrust-analyzer cargo libc 0.2.186 unix/pollfd#fd.: self.fdrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/TimeoutRead#fd..as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`BorrowedFd<'_>`][AsRawFd]as_raw_fd().(), |
| 323 | eventsrust-analyzer cargo libc 0.2.186 unix/pollfd#events.: pollmask, |
| 324 | reventsrust-analyzer cargo libc 0.2.186 unix/pollfd#revents.: 0, |
| 325 | }; 1]; |
| 326 | |
| 327 | let timeout = match self.timeout_atrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/TimeoutRead#timeout_at. { |
| 328 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(timeout_at) => { |
| 329 | let now = Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#::nowrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]now().(); |
| 330 | if now rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt().timeout_at { |
| 331 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error][`From<ErrorKind>`]from().(ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::TimedOutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#TimedOut#)); |
| 332 | } |
| 333 | |
| 334 | (timeout_at rust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant][`Sub<Self>`]sub().-rust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant][`Sub<Self>`]sub(). rust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant][`Sub<Self>`]sub().now) |
| 335 | .as_millisrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]as_millis().() |
| 336 | .try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().() |
| 337 | .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().(i32::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]MAX.) |
| 338 | } |
| 339 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().1, |
| 340 | }; |
| 341 | |
| 342 | if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(miri) { |
| 343 | // Miri doesn't support poll: rust-lang/miri#4413 |
| 344 | // FIXME(#1500) remove once miri supports it |
| 345 | pollfd[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()..reventsrust-analyzer cargo libc 0.2.186 unix/pollfd#revents. = libcrust-analyzer cargo libc 0.2.186 crate/::POLLINrust-analyzer cargo libc 0.2.186 unix/linux_like/POLLIN.; |
| 346 | } else { |
| 347 | // SAFETY: pollfd is initialized and its length matches |
| 348 | cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr().(unsafe { |
| 349 | libcrust-analyzer cargo libc 0.2.186 crate/::pollrust-analyzer cargo libc 0.2.186 poll().( |
| 350 | pollfd.as_mut_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_mut_ptr().(), |
| 351 | pollfd.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().().try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 352 | timeout, |
| 353 | ) |
| 354 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 355 | } |
| 356 | |
| 357 | // There may yet be data waiting to be read even if POLLHUP is set. |
| 358 | if pollfd[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()..reventsrust-analyzer cargo libc 0.2.186 unix/pollfd#revents. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i16][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i16][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i16][`BitAnd<Self>`]bitand().(pollmask rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i16][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i16][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i16][`BitOr<Self>`]bitor().libcrust-analyzer cargo libc 0.2.186 crate/::POLLHUPrust-analyzer cargo libc 0.2.186 unix/linux_like/POLLHUP.) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]gt().0 { |
| 359 | let mut buf = [0u8]; |
| 360 | |
| 361 | // SAFETY: buf is initialized and its length matches |
| 362 | let ret = cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr().(unsafe { |
| 363 | libcrust-analyzer cargo libc 0.2.186 crate/::readrust-analyzer cargo libc 0.2.186 read().( |
| 364 | self.fdrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/TimeoutRead#fd..as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`BorrowedFd<'_>`][AsRawFd]as_raw_fd().(), |
| 365 | buf.as_mut_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_mut_ptr().() as *mut c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void#, |
| 366 | buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), |
| 367 | ) |
| 368 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 369 | |
| 370 | if ret rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]ne().1 { |
| 371 | 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#); |
| 372 | } |
| 373 | |
| 374 | 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#(buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().)) |
| 375 | } else { |
| 376 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error][`From<ErrorKind>`]from().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::TimedOutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#TimedOut#)) |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | /// A data structure representing either /dev/tty or /dev/stdin+stderr |
| 382 | pub enum Terminalrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Terminal#<'a> { |
| 383 | Ttyrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Terminal#Tty#(fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#), |
| 384 | StdIErust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Terminal#StdIE#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::StdinLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/StdinLock#<'a>, iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::StderrLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/StderrLock#<'a>), |
| 385 | Askpassrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Terminal#Askpass#(PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#, iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Sinkrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/util/Sink#), |
| 386 | } |
| 387 | |
| 388 | impl Terminalrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Terminal#<'_> { |
| 389 | /// Open the current TTY for user communication |
| 390 | pub fn open_ttyrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`Terminal<'_>`]open_tty().() -> PamResultrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamResult#<Selfrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`Terminal<'_>`]> { |
| 391 | // control ourselves that we are really talking to a TTY |
| 392 | // mitigates: https://marc.info/?l=oss-security&m=168164424404224 |
| 393 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Terminalrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Terminal#::Ttyrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Terminal#Tty#( |
| 394 | fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::OpenOptionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/OpenOptions#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]new().() |
| 395 | .readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]read().(true) |
| 396 | .writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]write().(true) |
| 397 | .openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]open().("/dev/tty") |
| 398 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| PamErrorrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamError#::TtyRequiredrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamError#TtyRequired#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 399 | )) |
| 400 | } |
| 401 | |
| 402 | /// Open standard input and standard error for user communication |
| 403 | pub fn open_stdierust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`Terminal<'_>`]open_stdie().() -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Selfrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`Terminal<'_>`]> { |
| 404 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Terminalrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Terminal#::StdIErust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Terminal#StdIE#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdin().().lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[Stdin]lock().(), iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stderrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stderr().().lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[Stderr]lock().())) |
| 405 | } |
| 406 | |
| 407 | pub fn open_askpassrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`Terminal<'_>`]open_askpass().() -> PamResultrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamResult#<Selfrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`Terminal<'_>`]> { |
| 408 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(program) = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::var_osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var_os().("SUDO_ASKPASS") else { |
| 409 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(PamErrorrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamError#::NoAskpassProgramrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamError#NoAskpassProgram#); |
| 410 | }; |
| 411 | let program = PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`From<OsString>`]from().(program); |
| 412 | |
| 413 | if program.is_absoluterust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]is_absolute().() { |
| 414 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Terminalrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Terminal#::Askpassrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Terminal#Askpass#(program, iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::sinkrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/util/sink().())) |
| 415 | } else { |
| 416 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(PamErrorrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamError#::InvalidAskpassProgramrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamError#InvalidAskpassProgram#(program)) |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | /// Reads input with TTY echo and visual feedback set according to the `hidden` parameter. |
| 421 | pub(superrust-analyzer cargo sudo-rs 0.2.14 pam/) fn read_inputrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`Terminal<'_>`]read_input().( |
| 422 | &mut self, |
| 423 | prompt: &str, |
| 424 | timeout: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#>, |
| 425 | hidden: Hiddenrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#<()>, |
| 426 | ) -> PamResultrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamResult#<PamBufferrust-analyzer cargo sudo-rs 0.2.14 pam/securemem/PamBuffer#> { |
| 427 | match self { |
| 428 | Terminalrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Terminal#::StdIErust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Terminal#StdIE#(stdin, stdout) => { |
| 429 | prompt_passwordrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/prompt_password().(stdin.as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`&mut T`][AsFd]as_fd().(), stdout, prompt, timeout, hidden) |
| 430 | } |
| 431 | Terminalrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Terminal#::Ttyrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Terminal#Tty#(file) => { |
| 432 | prompt_passwordrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/prompt_password().(file.as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`&mut T`][AsFd]as_fd().(), &mut &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().file, prompt, timeout, hidden) |
| 433 | } |
| 434 | Terminalrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Terminal#::Askpassrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Terminal#Askpass#(program, sink) => { |
| 435 | let (command_pid, askpass_stdout) = askpassrust-analyzer cargo sudo-rs 0.2.14 pam/askpass/::spawn_askpassrust-analyzer cargo sudo-rs 0.2.14 pam/askpass/spawn_askpass().(program, prompt)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 436 | |
| 437 | let mut reader = TimeoutReadrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/TimeoutRead#::newrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`TimeoutRead<'a>`]new().(askpass_stdout.as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[OwnedFd][AsFd]as_fd().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 438 | let password = read_unbufferedrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/read_unbuffered().(&mut reader, sink, &Hiddenrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#::Norust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#No#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 439 | |
| 440 | loop { |
| 441 | match command_pid.waitrust-analyzer cargo sudo-rs 0.2.14 system/wait/impl#[ProcessId][Wait]wait().(WaitOptionsrust-analyzer cargo sudo-rs 0.2.14 system/wait/WaitOptions#::newrust-analyzer cargo sudo-rs 0.2.14 system/wait/impl#[WaitOptions]new().()) { |
| 442 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => break, |
| 443 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(WaitErrorrust-analyzer cargo sudo-rs 0.2.14 system/wait/WaitError#::Iorust-analyzer cargo sudo-rs 0.2.14 system/wait/WaitError#Io#(err)) if err.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().() rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().==rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq(). rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::Interruptedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#Interrupted# => {} |
| 444 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(WaitErrorrust-analyzer cargo sudo-rs 0.2.14 system/wait/WaitError#::Iorust-analyzer cargo sudo-rs 0.2.14 system/wait/WaitError#Io#(err)) => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(PamErrorrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamError#::IoErrorrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamError#IoError#(err)), |
| 445 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(WaitErrorrust-analyzer cargo sudo-rs 0.2.14 system/wait/WaitError#::NotReadyrust-analyzer cargo sudo-rs 0.2.14 system/wait/WaitError#NotReady#) => unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!(), |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(password) |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | /// Display information |
| 455 | pub fn promptrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`Terminal<'_>`]prompt().(&mut self, text: &str) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 456 | write_unbufferedrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/write_unbuffered().(self.sinkrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`Terminal<'_>`]sink().(), text.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()) |
| 457 | } |
| 458 | |
| 459 | /// Ring the bell |
| 460 | pub fn bellrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`Terminal<'_>`]bell().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 461 | const BELLrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/BELL.: &[u8; 1] = b"\x07"; |
| 462 | write_unbufferedrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/write_unbuffered().(self.sinkrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`Terminal<'_>`]sink().(), BELLrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/BELL.) |
| 463 | } |
| 464 | |
| 465 | // boilerplate reduction functions |
| 466 | fn sinkrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`Terminal<'_>`]sink().(&mut self) -> &mut dyn iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# { |
| 467 | match self { |
| 468 | Terminalrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Terminal#::StdIErust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Terminal#StdIE#(_, x) => x, |
| 469 | Terminalrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Terminal#::Ttyrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Terminal#Tty#(x) => x, |
| 470 | Terminalrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Terminal#::Askpassrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Terminal#Askpass#(_, x) => x, |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | #[cfg(test)] |
| 476 | mod testrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/test/ { |
| 477 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#; |
| 478 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#}; |
| 479 | 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/::fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/::FromRawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/FromRawFd#; |
| 480 | |
| 481 | use libcrust-analyzer cargo libc 0.2.186 crate/::O_CLOEXECrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/O_CLOEXEC.; |
| 482 | |
| 483 | use superrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/::*; |
| 484 | |
| 485 | fn make_piperust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/test/make_pipe().() -> (Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#, Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#) { |
| 486 | // SAFETY: A valid pointer to a mutable array of 2 fds is passed in. |
| 487 | unsafe { |
| 488 | let mut pipes = [-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().1, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().1]; |
| 489 | cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr().(libcrust-analyzer cargo libc 0.2.186 crate/::pipe2rust-analyzer cargo libc 0.2.186 pipe2().(pipes.as_mut_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_mut_ptr().(), O_CLOEXECrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/O_CLOEXEC.)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 490 | (Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::from_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/impl#[`fs::File`][FromRawFd]from_raw_fd().(pipes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().), Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::from_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/impl#[`fs::File`][FromRawFd]from_raw_fd().(pipes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().)) |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 495 | fn miri_test_readrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/test/miri_test_read().() { |
| 496 | let mut stdout = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 497 | let (mut rx, mut tx) = make_piperust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/test/make_pipe().(); |
| 498 | tx.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().("password123\nhello world".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 499 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(tx); |
| 500 | let buf = read_unbufferedrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/read_unbuffered().( |
| 501 | &mut TimeoutReadrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/TimeoutRead#::newrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`TimeoutRead<'a>`]new().(rx.as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`fs::File`][AsFd]as_fd().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#), |
| 502 | &mut stdout, |
| 503 | &Hiddenrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#::Norust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#No#, |
| 504 | ) |
| 505 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 506 | // check that the \n is not part of input |
| 507 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 508 | buf.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 509 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|&b| b as char) |
| 510 | .take_whilerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take_while().(|&x| x != '\0') |
| 511 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>(), |
| 512 | "password123" |
| 513 | ); |
| 514 | // check that the \n is also consumed but the rest of the input is still there |
| 515 | let mut data = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0; "hello world".lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().()]; |
| 516 | rx.read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_exact().(&mut data).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 517 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data, b"hello world"); |
| 518 | } |
| 519 | |
| 520 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 521 | fn miri_test_longpwdrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/test/miri_test_longpwd().() { |
| 522 | let mut stdout = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 523 | let (rx, mut tx) = make_piperust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/test/make_pipe().(); |
| 524 | tx.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().("a".repeatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]repeat().(511).as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 525 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(tx); |
| 526 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 527 | read_unbufferedrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/read_unbuffered().( |
| 528 | &mut TimeoutReadrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/TimeoutRead#::newrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`TimeoutRead<'a>`]new().(rx.as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`fs::File`][AsFd]as_fd().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#), |
| 529 | &mut stdout, |
| 530 | &Hiddenrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#::Norust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#No# |
| 531 | ) |
| 532 | .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().() |
| 533 | ); |
| 534 | |
| 535 | let (rx, mut tx) = make_piperust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/test/make_pipe().(); |
| 536 | tx.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().("a".repeatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]repeat().(512).as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 537 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(tx); |
| 538 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 539 | read_unbufferedrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/read_unbuffered().( |
| 540 | &mut TimeoutReadrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/TimeoutRead#::newrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/impl#[`TimeoutRead<'a>`]new().(rx.as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`fs::File`][AsFd]as_fd().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#), |
| 541 | &mut stdout, |
| 542 | &Hiddenrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#::Norust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/Hidden#No# |
| 543 | ) |
| 544 | .is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().() |
| 545 | ); |
| 546 | } |
| 547 | |
| 548 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 549 | fn miri_test_writerust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/test/miri_test_write().() { |
| 550 | let mut data = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 551 | write_unbufferedrust-analyzer cargo sudo-rs 0.2.14 pam/rpassword/write_unbuffered().(&mut data, b"prompt").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 552 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(&data).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "prompt"); |
| 553 | } |
| 554 | } |