From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 3F8199E49A for ; Mon, 27 Nov 2023 13:30:59 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 2168F7208 for ; Mon, 27 Nov 2023 13:30:59 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Mon, 27 Nov 2023 13:30:57 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 46A8C44C03 for ; Mon, 27 Nov 2023 13:30:57 +0100 (CET) Date: Mon, 27 Nov 2023 13:30:49 +0100 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox Backup Server development discussion References: <20231117132414.195758-1-m.sandoval@proxmox.com> In-Reply-To: <20231117132414.195758-1-m.sandoval@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.16.0 (https://github.com/astroidmail/astroid) Message-Id: <1701088241.ssoujmg5te.astroid@yuna.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.064 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [proxmox.com, key.rs, diff.rs] Subject: [pbs-devel] applied: [PATCH backup] use IsTerminal trait whenever possible X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Nov 2023 12:30:59 -0000 On November 17, 2023 2:24 pm, Maximiliano Sandoval R wrote: > Continuation of > https://lists.proxmox.com/pipermail/pbs-devel/2023-November/007078.html. >=20 > Signed-off-by: Maximiliano Sandoval R > --- > pbs-client/src/http_client.rs | 10 +++++----- > pbs-client/src/tools/key_source.rs | 4 ++-- > proxmox-backup-client/src/key.rs | 7 ++++--- > src/bin/proxmox_backup_debug/diff.rs | 4 ++-- > src/bin/proxmox_tape/encryption_key.rs | 8 +++++--- > 5 files changed, 18 insertions(+), 15 deletions(-) >=20 > diff --git a/pbs-client/src/http_client.rs b/pbs-client/src/http_client.r= s > index b803c19f..ab67bba2 100644 > --- a/pbs-client/src/http_client.rs > +++ b/pbs-client/src/http_client.rs > @@ -1,4 +1,4 @@ > -use std::io::Write; > +use std::io::{IsTerminal, Write}; > use std::sync::{Arc, Mutex, RwLock}; > use std::time::Duration; > =20 > @@ -458,7 +458,7 @@ impl HttpClient { > &auth.ticket, > &auth.token, > ) { > - if tty::stdout_isatty() { > + if std::io::stdout().is_terminal() { > log::error!("storing login ticket fa= iled: {}", err); > } > } > @@ -496,7 +496,7 @@ impl HttpClient { > &auth.ticket, > &auth.token, > ) { > - if tty::stdout_isatty() { > + if std::io::stdout().is_terminal() { > log::error!("storing login ticket failed: {}= ", err); > } > } > @@ -548,7 +548,7 @@ impl HttpClient { > =20 > fn get_password(username: &Userid, interactive: bool) -> Result { > // If we're on a TTY, query the user for a password > - if interactive && tty::stdin_isatty() { > + if interactive && std::io::stdin().is_terminal() { > let msg =3D format!("Password for \"{}\": ", username); > return Ok(String::from_utf8(tty::read_password(&msg)?)?); > } > @@ -599,7 +599,7 @@ impl HttpClient { > } > =20 > // If we're on a TTY, query the user > - if interactive && tty::stdin_isatty() { > + if interactive && std::io::stdin().is_terminal() { > log::info!("fingerprint: {}", fp_string); > loop { > eprint!("Are you sure you want to continue connecting? (= y/n): "); > diff --git a/pbs-client/src/tools/key_source.rs b/pbs-client/src/tools/ke= y_source.rs > index 0f78d0d1..2c15423f 100644 > --- a/pbs-client/src/tools/key_source.rs > +++ b/pbs-client/src/tools/key_source.rs > @@ -1,4 +1,4 @@ > -use std::io::Read; > +use std::io::{IsTerminal, Read}; > use std::os::unix::io::{FromRawFd, RawFd}; > use std::path::PathBuf; > =20 > @@ -351,7 +351,7 @@ pub fn get_encryption_key_password() -> Result, Error> { > } > =20 > // If we're on a TTY, query the user for a password > - if tty::stdin_isatty() { > + if std::io::stdin().is_terminal() { > return tty::read_password("Encryption Key Password: "); > } > =20 > diff --git a/proxmox-backup-client/src/key.rs b/proxmox-backup-client/src= /key.rs > index 560e05b7..748cd9d3 100644 > --- a/proxmox-backup-client/src/key.rs > +++ b/proxmox-backup-client/src/key.rs > @@ -1,3 +1,4 @@ > +use std::io::IsTerminal; > use std::path::PathBuf; > =20 > use anyhow::{bail, format_err, Error}; > @@ -100,7 +101,7 @@ fn create(kdf: Option, path: Option, hin= t: Option) -> Resul > } > Kdf::Scrypt | Kdf::PBKDF2 =3D> { > // always read passphrase from tty > - if !tty::stdin_isatty() { > + if !std::io::stdin().is_terminal() { > bail!("unable to read passphrase - no tty"); > } > =20 > @@ -236,7 +237,7 @@ fn change_passphrase( > =20 > let kdf =3D kdf.unwrap_or_default(); > =20 > - if !tty::stdin_isatty() { > + if !std::io::stdin().is_terminal() { > bail!("unable to change passphrase - no tty"); > } > =20 > @@ -359,7 +360,7 @@ fn import_master_pubkey(path: String) -> Result<(), E= rror> { > /// encryption key onto the backup server along with each backup. > fn create_master_key() -> Result<(), Error> { > // we need a TTY to query the new password > - if !tty::stdin_isatty() { > + if !std::io::stdin().is_terminal() { > bail!("unable to create master key - no tty"); > } > =20 > diff --git a/src/bin/proxmox_backup_debug/diff.rs b/src/bin/proxmox_backu= p_debug/diff.rs > index 9924fb7b..0e861974 100644 > --- a/src/bin/proxmox_backup_debug/diff.rs > +++ b/src/bin/proxmox_backup_debug/diff.rs > @@ -1,6 +1,6 @@ > use std::collections::{HashMap, HashSet}; > use std::ffi::{OsStr, OsString}; > -use std::io::Write; > +use std::io::{IsTerminal, Write}; > use std::iter::FromIterator; > use std::path::{Path, PathBuf}; > use std::sync::Arc; > @@ -601,7 +601,7 @@ impl FileEntryPrinter { > let color_choice =3D match output_params.color { > ColorMode::Always =3D> ColorChoice::Always, > ColorMode::Auto =3D> { > - if unsafe { libc::isatty(1) =3D=3D 1 } { > + if std::io::stdout().is_terminal() { > // Show colors unless `TERM=3Ddumb` or `NO_COLOR` is= set. > ColorChoice::Auto > } else { > diff --git a/src/bin/proxmox_tape/encryption_key.rs b/src/bin/proxmox_tap= e/encryption_key.rs > index bed37171..6ca93aba 100644 > --- a/src/bin/proxmox_tape/encryption_key.rs > +++ b/src/bin/proxmox_tape/encryption_key.rs > @@ -1,3 +1,5 @@ > +use std::io::IsTerminal; > + > use anyhow::{bail, format_err, Error}; > use serde_json::Value; > =20 > @@ -149,7 +151,7 @@ fn change_passphrase( > mut param: Value, > rpcenv: &mut dyn RpcEnvironment, > ) -> Result<(), Error> { > - if !tty::stdin_isatty() { > + if !std::io::stdin().is_terminal() { > bail!("unable to change passphrase - no tty"); > } > =20 > @@ -208,7 +210,7 @@ async fn restore_key( > } else if !drive_passed && key.is_none() && key_file.is_none() { > bail!("one of either 'drive' or 'key' parameter must be set!"); > } > - if !tty::stdin_isatty() { > + if !std::io::stdin().is_terminal() { > bail!("no password input mechanism available"); > } > =20 > @@ -283,7 +285,7 @@ async fn restore_key( > )] > /// Create key (read password from stdin) > fn create_key(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Resu= lt<(), Error> { > - if !tty::stdin_isatty() { > + if !std::io::stdin().is_terminal() { > bail!("no password input mechanism available"); > } > =20 > --=20 > 2.39.2 >=20 >=20 >=20 > _______________________________________________ > pbs-devel mailing list > pbs-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel >=20 >=20 >=20