From 69400e983e949a4f1a307a755b02af5fcd3efe65 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Thu, 25 Jul 2024 10:52:48 +0200 Subject: [PATCH] termproxy: clippy fixes Signed-off-by: Wolfgang Bumiller --- termproxy/src/cli.rs | 7 ++----- termproxy/src/main.rs | 12 ++++++------ termproxy/src/pty.rs | 22 +++++++++++----------- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/termproxy/src/cli.rs b/termproxy/src/cli.rs index 8108c3e..553374f 100644 --- a/termproxy/src/cli.rs +++ b/termproxy/src/cli.rs @@ -8,7 +8,7 @@ Usage: proxmox-termproxy [OPTIONS] --path -- Arguments: Port or file descriptor to listen for TCP connections - ... The command to run connected via a proxied PTY + ... The command to run connected via a proxied pty Options: --authport Port to relay auth-request, default 85 @@ -113,9 +113,6 @@ impl Options { } pub fn use_listen_port_as_fd(&self) -> bool { - match self.listen_port { - PortOrFd::Fd(_) => true, - _ => false, - } + matches!(self.listen_port, PortOrFd::Fd(_)) } } diff --git a/termproxy/src/main.rs b/termproxy/src/main.rs index d2bebb1..1641757 100644 --- a/termproxy/src/main.rs +++ b/termproxy/src/main.rs @@ -21,7 +21,7 @@ mod cli; use crate::cli::{Options, PortOrFd}; mod pty; -use crate::pty::{make_controlling_terminal, PTY}; +use crate::pty::{make_controlling_terminal, Pty}; const MSG_TYPE_DATA: u8 = 0; const MSG_TYPE_RESIZE: u8 = 1; @@ -55,7 +55,7 @@ fn remove_number(buf: &mut ByteBuffer) -> Option { None } -fn process_queue(buf: &mut ByteBuffer, pty: &mut PTY) -> Option { +fn process_queue(buf: &mut ByteBuffer, pty: &mut Pty) -> Option { if buf.is_empty() { return None; } @@ -221,7 +221,7 @@ fn listen_and_accept( ) -> Result<(TcpStream, u16)> { let listener = match listen_port { PortOrFd::Fd(fd) => unsafe { std::net::TcpListener::from_raw_fd(*fd) }, - PortOrFd::Port(port) => std::net::TcpListener::bind((hostname, *port as u16))?, + PortOrFd::Port(port) => std::net::TcpListener::bind((hostname, *port))?, }; let port = listener.local_addr()?.port(); let mut listener = TcpListener::from_std(listener); @@ -250,14 +250,14 @@ fn listen_and_accept( } } -fn run_pty<'a>(mut full_cmd: impl Iterator) -> Result { +fn run_pty<'a>(mut full_cmd: impl Iterator) -> Result { let cmd_exe = full_cmd.next().unwrap(); let params = full_cmd; // rest - let (mut pty, secondary_name) = PTY::new().map_err(io_err_other)?; + let (mut pty, secondary_name) = Pty::new().map_err(io_err_other)?; let mut filtered_env: HashMap = std::env::vars_os() - .filter(|&(ref k, _)| { + .filter(|(k, _)| { k == "PATH" || k == "USER" || k == "HOME" diff --git a/termproxy/src/pty.rs b/termproxy/src/pty.rs index 660d3ab..073a098 100644 --- a/termproxy/src/pty.rs +++ b/termproxy/src/pty.rs @@ -1,6 +1,6 @@ //! Helper for creating a pseudo-terminal //! -//! see [PTY](struct.PTY.html) for an example on how to use it +//! see [Pty](struct.Pty.html) for an example on how to use it use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, OwnedFd, RawFd}; @@ -13,7 +13,7 @@ use nix::{ioctl_write_int_bad, ioctl_write_ptr_bad, Result}; ioctl_write_int_bad!(set_controlling_tty, libc::TIOCSCTTY); ioctl_write_ptr_bad!(set_size, libc::TIOCSWINSZ, nix::pty::Winsize); -/// Represents a PTY +/// Represents a pty. /// /// Implements Read and Write (from std::io) so one can simply use it /// to read and write the terminal of a child process @@ -34,7 +34,7 @@ ioctl_write_ptr_bad!(set_size, libc::TIOCSWINSZ, nix::pty::Winsize); /// } /// /// fn main() -> Result<()> { -/// let (mut pty, secondary) = PTY::new()?; +/// let (mut pty, secondary) = Pty::new()?; /// /// let child = fork()?; /// if child == 0 { @@ -48,7 +48,7 @@ ioctl_write_ptr_bad!(set_size, libc::TIOCSWINSZ, nix::pty::Winsize); /// Ok(()) /// } /// ``` -pub struct PTY { +pub struct Pty { primary: PtyMaster, } @@ -77,9 +77,9 @@ pub fn make_controlling_terminal(terminal: &str) -> Result<()> { Ok(()) } -impl PTY { - /// Creates a new PTY by opening /dev/ptmx and returns - /// a new PTY and the path to the secondary terminal on success. +impl Pty { + /// Creates a new pty by opening /dev/ptmx and returns + /// a new pty and the path to the secondary terminal on success. pub fn new() -> Result<(Self, String)> { let primary = posix_openpt(OFlag::O_RDWR | OFlag::O_NOCTTY | OFlag::O_NONBLOCK | OFlag::O_CLOEXEC)?; @@ -105,13 +105,13 @@ impl PTY { } } -impl std::io::Read for PTY { +impl std::io::Read for Pty { fn read(&mut self, buf: &mut [u8]) -> std::io::Result { Ok(nix::unistd::read(self.primary.as_raw_fd(), buf)?) } } -impl std::io::Write for PTY { +impl std::io::Write for Pty { fn write(&mut self, buf: &[u8]) -> std::io::Result { Ok(nix::unistd::write(self.primary.as_raw_fd(), buf)?) } @@ -121,13 +121,13 @@ impl std::io::Write for PTY { } } -impl AsRawFd for PTY { +impl AsRawFd for Pty { fn as_raw_fd(&self) -> RawFd { self.primary.as_raw_fd() } } -impl AsFd for PTY { +impl AsFd for Pty { fn as_fd(&self) -> BorrowedFd<'_> { unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } } -- 2.39.5