use std::cmp::min;
use std::collections::HashMap;
use std::ffi::{OsStr, OsString};
-use std::io::{ErrorKind, Result, Write};
+use std::io::{ErrorKind, Write};
use std::os::unix::io::{AsRawFd, FromRawFd};
use std::os::unix::process::CommandExt;
use std::process::Command;
use std::time::{Duration, Instant};
+use anyhow::{bail, format_err, Result};
use clap::{App, AppSettings, Arg};
use curl::easy::Easy;
use mio::net::{TcpListener, TcpStream};
use proxmox_io::ByteBuffer;
use proxmox_sys::{
error::io_err_other,
- io_bail, io_format_err,
linux::pty::{make_controlling_terminal, PTY},
};
match buf.read_from(stream) {
Ok(n) => {
if n == 0 {
- io_bail!("connection closed before authentication");
+ bail!("connection closed before authentication");
}
}
Err(err) if err.kind() == ErrorKind::WouldBlock => {}
- Err(err) => return Err(err),
+ Err(err) => return Err(err.into()),
}
if buf[..].contains(&b'\n') {
}
if buf.is_full() {
- io_bail!("authentication data is incomplete: {:?}", &buf[..]);
+ bail!("authentication data is incomplete: {:?}", &buf[..]);
}
}
elapsed = now.elapsed();
if elapsed > timeout {
- io_bail!("timed out");
+ bail!("timed out");
}
}
let (username, ticket) = line.split_at(pos);
Ok((username.into(), ticket[1..].into()))
}
- None => io_bail!("authentication data is invalid"),
+ None => bail!("authentication data is invalid"),
}
}
let response_code = curl.response_code()?;
if response_code != 200 {
- io_bail!("invalid authentication, code {}", response_code);
+ bail!("invalid authentication, code {}", response_code);
}
Ok(())
elapsed = now.elapsed();
if elapsed > timeout {
- io_bail!("timed out");
+ bail!("timed out");
}
}
}
let use_port_as_fd = matches.is_present("use-port-as-fd");
if use_port_as_fd && port > u16::MAX as u64 {
- return Err(io_format_err!("port too big"));
+ return Err(format_err!("port too big"));
} else if port > i32::MAX as u64 {
- return Err(io_format_err!("Invalid FD number"));
+ return Err(format_err!("Invalid FD number"));
}
let (mut tcp_handle, port) =
listen_and_accept("localhost", port, use_port_as_fd, Duration::new(10, 0))
- .map_err(|err| io_format_err!("failed waiting for client: {}", err))?;
+ .map_err(|err| format_err!("failed waiting for client: {}", err))?;
let (username, ticket) = read_ticket_line(&mut tcp_handle, &mut pty_buf, Duration::new(10, 0))
- .map_err(|err| io_format_err!("failed reading ticket: {}", err))?;
+ .map_err(|err| format_err!("failed reading ticket: {}", err))?;
let port = if use_port_as_fd { Some(port) } else { None };
authenticate(&username, &ticket, path, perm, authport, port)?;
tcp_handle.write_all(b"OK").expect("error writing response");
}
Err(err) => {
if !finished {
- return Err(io_format_err!("error reading from tcp: {}", err));
+ return Err(format_err!("error reading from tcp: {}", err));
}
break;
}
}
Err(err) => {
if !finished {
- return Err(io_format_err!("error reading from pty: {}", err));
+ return Err(format_err!("error reading from pty: {}", err));
}
break;
}
}
Err(err) => {
if !finished {
- return Err(io_format_err!("error writing to tcp : {}", err));
+ return Err(format_err!("error writing to tcp : {}", err));
}
break;
}
}
Err(err) => {
if !finished {
- return Err(io_format_err!("error writing to pty : {}", err));
+ return Err(format_err!("error writing to pty : {}", err));
}
break;
}