Format comments and imports
Diff
Cargo.toml | 1 +-
pisshoff-server/src/audit.rs | 6 ++--
pisshoff-server/src/command/echo.rs | 12 +++++----
pisshoff-server/src/command/exit.rs | 11 +++++---
pisshoff-server/src/command/pwd.rs | 8 +++---
pisshoff-server/src/command/scp.rs | 25 ++++++++++--------
pisshoff-server/src/command/uname.rs | 10 ++++---
pisshoff-server/src/command/whoami.rs | 8 +++---
pisshoff-server/src/config.rs | 5 +---
pisshoff-server/src/main.rs | 6 ++--
pisshoff-server/src/server.rs | 38 +++++++++++++---------------
pisshoff-server/src/state.rs | 3 +-
pisshoff-server/src/subsystem/mod.rs | 6 ++--
pisshoff-server/src/subsystem/sftp.rs | 6 ++--
pisshoff-server/src/subsystem/shell.rs | 9 +++----
pisshoff-server/src/subsystem/shell/parser.rs | 24 ++++++++++++------
pisshoff-timescaledb-exporter/src/config.rs | 3 +-
pisshoff-timescaledb-exporter/src/main.rs | 6 ++--
pisshoff-types/src/audit.rs | 7 ++---
rustfmt.toml | 8 ++++++-
20 files changed, 121 insertions(+), 81 deletions(-)
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = [
"pisshoff-server",
"pisshoff-timescaledb-exporter",
@@ -1,6 +1,6 @@
use crate::config::Config;
pub use pisshoff_types::audit::*;
use std::{io::ErrorKind, sync::Arc, time::Duration};
pub use pisshoff_types::audit::*;
use tokio::{
fs::OpenOptions,
io::{AsyncWriteExt, BufWriter},
@@ -9,6 +9,8 @@ use tokio::{
};
use tracing::{debug, info};
use crate::config::Config;
pub fn start_audit_writer(
config: Arc<Config>,
mut reload: watch::Receiver<()>,
@@ -1,10 +1,11 @@
use async_trait::async_trait;
use itertools::Itertools;
use thrussh::ChannelId;
use crate::{
command::{Command, CommandResult},
server::{ConnectionState, ThrusshSession},
};
use async_trait::async_trait;
use itertools::Itertools;
use thrussh::ChannelId;
#[derive(Debug, Clone)]
pub struct Echo {}
@@ -40,6 +41,9 @@ impl Command for Echo {
#[cfg(test)]
mod test {
use mockall::predicate::always;
use test_case::test_case;
use crate::{
command::{echo::Echo, Command, CommandResult},
server::{
@@ -47,8 +51,6 @@ mod test {
ConnectionState, MockThrusshSession,
},
};
use mockall::predicate::always;
use test_case::test_case;
#[test_case(&[], "\n"; "no parameters")]
#[test_case(&["hello"], "hello\n"; "single parameter")]
@@ -1,10 +1,12 @@
use std::str::FromStr;
use async_trait::async_trait;
use thrussh::ChannelId;
use crate::{
command::{Command, CommandResult},
server::{ConnectionState, ThrusshSession},
};
use async_trait::async_trait;
use std::str::FromStr;
use thrussh::ChannelId;
#[derive(Debug, Clone)]
pub struct Exit {}
@@ -39,11 +41,12 @@ impl Command for Exit {
#[cfg(test)]
mod test {
use test_case::test_case;
use crate::{
command::{exit::Exit, Command, CommandResult},
server::{test::fake_channel_id, ConnectionState, MockThrusshSession},
};
use test_case::test_case;
#[test_case(&[], 0; "no parameters")]
#[test_case(&["3"], 3; "with parameter")]
@@ -1,9 +1,10 @@
use async_trait::async_trait;
use thrussh::ChannelId;
use crate::{
command::{Command, CommandResult},
server::{ConnectionState, ThrusshSession},
};
use async_trait::async_trait;
use thrussh::ChannelId;
#[derive(Debug, Clone)]
pub struct Pwd {}
@@ -37,6 +38,8 @@ impl Command for Pwd {
#[cfg(test)]
mod test {
use mockall::predicate::always;
use crate::{
command::{pwd::Pwd, Command, CommandResult},
server::{
@@ -44,7 +47,6 @@ mod test {
ConnectionState, MockThrusshSession,
},
};
use mockall::predicate::always;
#[tokio::test]
async fn works() {
@@ -1,7 +1,5 @@
use crate::{
command::{Arg, Command, CommandResult},
server::{ConnectionState, ThrusshSession},
};
use std::{path::PathBuf, str::FromStr};
use async_trait::async_trait;
use bytes::{Buf, BytesMut};
use nom::{
@@ -11,10 +9,14 @@ use nom::{
IResult,
};
use pisshoff_types::audit::{AuditLogAction, WriteFileEvent};
use std::{path::PathBuf, str::FromStr};
use thrussh::ChannelId;
use tracing::warn;
use crate::{
command::{Arg, Command, CommandResult},
server::{ConnectionState, ThrusshSession},
};
const HELP: &str = "usage: scp [-346ABCOpqRrsTv] [-c cipher] [-D sftp_server_path] [-F ssh_config]
[-i identity_file] [-J destination] [-l limit] [-o ssh_option]
[-P port] [-S program] [-X sftp_option] source ... target\n";
@@ -115,8 +117,8 @@ impl Command for Scp {
self.pending_data
.advance(self.pending_data.len() - rest.len());
session.data(channel, SUCCESS.to_string().into());
state
@@ -150,8 +152,8 @@ impl Command for Scp {
if self.pending_data.starts_with(&[0]) {
self.pending_data.advance(1);
session.data(channel, SUCCESS.to_string().into());
}
@@ -281,6 +283,9 @@ impl<'a> Receive<'a> {
#[cfg(test)]
mod test {
use insta::assert_debug_snapshot;
use mockall::predicate::always;
use crate::{
command::{scp::Scp, Command},
server::{
@@ -288,8 +293,6 @@ mod test {
ConnectionState, MockThrusshSession,
},
};
use insta::assert_debug_snapshot;
use mockall::predicate::always;
mod packet_parser {
use crate::command::scp::Receive;
@@ -1,10 +1,11 @@
use async_trait::async_trait;
use bitflags::bitflags;
use thrussh::ChannelId;
use crate::{
command::{Arg, Command, CommandResult},
server::{ConnectionState, ThrusshSession},
};
use async_trait::async_trait;
use bitflags::bitflags;
use thrussh::ChannelId;
bitflags! {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
@@ -181,9 +182,10 @@ pub fn execute(params: &[String]) -> (String, u32) {
#[cfg(test)]
mod test {
use crate::command::uname::execute;
use test_case::test_case;
use crate::command::uname::execute;
#[test_case("", 0; "none")]
#[test_case("-a", 0; "all")]
#[test_case("-snrvmpio", 0; "all separate")]
@@ -1,9 +1,10 @@
use async_trait::async_trait;
use thrussh::ChannelId;
use crate::{
command::{Command, CommandResult},
server::{ConnectionState, ThrusshSession},
};
use async_trait::async_trait;
use thrussh::ChannelId;
#[derive(Debug, Clone)]
pub struct Whoami {}
@@ -33,6 +34,8 @@ impl Command for Whoami {
#[cfg(test)]
mod test {
use mockall::predicate::always;
use crate::{
command::{whoami::Whoami, Command, CommandResult},
server::{
@@ -40,7 +43,6 @@ mod test {
ConnectionState, MockThrusshSession,
},
};
use mockall::predicate::always;
#[tokio::test]
async fn works() {
@@ -1,8 +1,7 @@
use std::{io::ErrorKind, net::SocketAddr, path::PathBuf, sync::Arc};
use clap::Parser;
use serde::{de::DeserializeOwned, Deserialize};
use std::path::PathBuf;
use std::sync::Arc;
use std::{io::ErrorKind, net::SocketAddr};
@@ -1,11 +1,11 @@
#![deny(clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]
use crate::{config::Args, server::Server};
use std::sync::Arc;
use anyhow::anyhow;
use clap::Parser;
use futures::FutureExt;
use std::sync::Arc;
use thrussh::MethodSet;
use tokio::{
signal::unix::SignalKind,
@@ -14,6 +14,8 @@ use tokio::{
use tracing::{error, info};
use tracing_subscriber::EnvFilter;
use crate::{config::Args, server::Server};
mod audit;
mod command;
mod config;
@@ -1,21 +1,3 @@
use crate::{
audit::{
AuditLog, AuditLogAction, LoginAttemptEvent, OpenDirectTcpIpEvent, OpenX11Event,
PtyRequestEvent, X11RequestEvent,
},
audit::{
SignalEvent, SubsystemRequestEvent, TcpIpForwardEvent, WindowAdjustedEvent,
WindowChangeRequestEvent,
},
config::Config,
file_system::FileSystem,
state::State,
subsystem::{self, shell::Shell, Subsystem as SubsystemTrait},
};
use futures::{
future::{BoxFuture, InspectErr},
FutureExt, TryFutureExt,
};
use std::{
borrow::Cow,
collections::HashMap,
@@ -25,15 +7,31 @@ use std::{
sync::Arc,
task::{Context, Poll},
};
use futures::{
future::{BoxFuture, InspectErr},
FutureExt, TryFutureExt,
};
use thrussh::{
server::{Auth, Response, Session},
ChannelId, CryptoVec, Pty, Sig,
};
use thrussh_keys::key::PublicKey;
use tokio::sync::mpsc::UnboundedSender;
use tokio::sync::Mutex;
use tokio::sync::{mpsc::UnboundedSender, Mutex};
use tracing::{debug, error, info, info_span, instrument::Instrumented, Instrument, Span};
use crate::{
audit::{
AuditLog, AuditLogAction, LoginAttemptEvent, OpenDirectTcpIpEvent, OpenX11Event,
PtyRequestEvent, SignalEvent, SubsystemRequestEvent, TcpIpForwardEvent,
WindowAdjustedEvent, WindowChangeRequestEvent, X11RequestEvent,
},
config::Config,
file_system::FileSystem,
state::State,
subsystem::{self, shell::Shell, Subsystem as SubsystemTrait},
};
pub static KEYBOARD_INTERACTIVE_PROMPT: &[(Cow<'static, str>, bool)] =
&[(Cow::Borrowed("Password: "), false)];
@@ -1,6 +1,7 @@
use parking_lot::RwLock;
use std::{borrow::Cow, collections::HashSet};
use parking_lot::RwLock;
#[derive(Default)]
pub struct State {
@@ -1,7 +1,7 @@
use crate::server::ConnectionState;
use async_trait::async_trait;
use thrussh::server::Session;
use thrussh::ChannelId;
use thrussh::{server::Session, ChannelId};
use crate::server::ConnectionState;
pub mod sftp;
pub mod shell;
@@ -1,4 +1,5 @@
use crate::{server::ConnectionState, subsystem::Subsystem};
use std::{collections::HashMap, io::Write, mem::size_of, str::FromStr};
use async_trait::async_trait;
use bytes::Bytes;
use nom::{
@@ -9,12 +10,13 @@ use nom::{
IResult,
};
use pisshoff_types::audit::{AuditLogAction, MkdirEvent, WriteFileEvent};
use std::{collections::HashMap, io::Write, mem::size_of, str::FromStr};
use strum::FromRepr;
use thrussh::{server::Session, ChannelId};
use tracing::{debug, error, trace, warn};
use uuid::Uuid;
use crate::{server::ConnectionState, subsystem::Subsystem};
#[derive(Default, Clone, Debug)]
pub struct Sftp {
@@ -1,5 +1,10 @@
mod parser;
use async_trait::async_trait;
use pisshoff_types::audit::{AuditLogAction, ExecCommandEvent};
use thrussh::{server::Session, ChannelId};
use tracing::info;
use crate::{
command::{CommandResult, ConcreteCommand},
server::{ConnectionState, EitherSession, StdoutCaptureSession},
@@ -8,10 +13,6 @@ use crate::{
Subsystem,
},
};
use async_trait::async_trait;
use pisshoff_types::audit::{AuditLogAction, ExecCommandEvent};
use thrussh::{server::Session, ChannelId};
use tracing::info;
pub const SHELL_PROMPT: &str = "bash-5.1$ ";
@@ -1,4 +1,5 @@
use crate::{command::PartialCommand, subsystem::shell::IResult};
use std::{borrow::Cow, collections::HashMap};
use nom::{
branch::alt,
bytes::complete::{escaped_transform, is_not, tag, take, take_until, take_while1},
@@ -9,7 +10,8 @@ use nom::{
sequence::{delimited, preceded},
AsChar,
};
use std::{borrow::Cow, collections::HashMap};
use crate::{command::PartialCommand, subsystem::shell::IResult};
#[derive(Debug, PartialEq, Eq)]
pub enum IterState<'a> {
@@ -300,11 +302,14 @@ fn atoi(v: &[u8]) -> Option<u8> {
#[cfg(test)]
mod test {
mod iter {
use crate::command::PartialCommand;
use crate::server::ConnectionState;
use crate::subsystem::shell::parser::{tokenize, Iter, IterState};
use std::borrow::Cow;
use crate::{
command::PartialCommand,
server::ConnectionState,
subsystem::shell::parser::{tokenize, Iter, IterState},
};
#[test]
fn single_nested() {
let (rest, s) = tokenize(b"echo $(echo hello) world!").unwrap();
@@ -377,9 +382,10 @@ mod test {
}
mod parse_command {
use crate::subsystem::shell::parser::{tokenize, Expansion, ParsedPart, RedirectionTo};
use std::borrow::Cow;
use crate::subsystem::shell::parser::{tokenize, Expansion, ParsedPart, RedirectionTo};
#[test]
fn messed_up() {
let (rest, s) = tokenize(b"echo ${HI}'this' \"is a \\t${TEST}\"using'$(complex string)>|' $(echo parsing) for the hell of it;fin").unwrap();
@@ -450,9 +456,10 @@ mod test {
}
mod parse_expansion {
use crate::subsystem::shell::parser::{parse_expansion, Expansion, ParsedPart};
use std::borrow::Cow;
use crate::subsystem::shell::parser::{parse_expansion, Expansion, ParsedPart};
#[test]
fn double_dollar() {
let (rest, s) = parse_expansion(b"$$a").unwrap();
@@ -531,9 +538,10 @@ mod test {
}
mod parse_double_quoted {
use crate::subsystem::shell::parser::{parse_double_quoted, Expansion, ParsedPart};
use std::borrow::Cow;
use crate::subsystem::shell::parser::{parse_double_quoted, Expansion, ParsedPart};
#[test]
fn with_expansion() {
let (rest, s) = parse_double_quoted(b"\"hello world $('cat' 'test') test\"").unwrap();
@@ -1,6 +1,7 @@
use std::{io::ErrorKind, path::PathBuf, sync::Arc};
use clap::Parser;
use serde::{de::DeserializeOwned, Deserialize};
use std::{io::ErrorKind, path::PathBuf, sync::Arc};
#[derive(Parser)]
@@ -1,7 +1,8 @@
#![deny(clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]
use crate::config::Args;
use std::sync::Arc;
use clap::Parser;
use deadpool_postgres::{
tokio_postgres::{NoTls, Statement, Transaction},
@@ -9,12 +10,13 @@ use deadpool_postgres::{
};
use futures::{StreamExt, TryFutureExt};
use pisshoff_types::audit::{AuditLog, AuditLogEvent};
use std::sync::Arc;
use tokio::net::{UnixListener, UnixStream};
use tokio_util::codec::{Decoder, LinesCodec};
use tracing::{error, info};
use tracing_subscriber::EnvFilter;
use crate::config::Args;
mod config;
mod embedded {
@@ -1,11 +1,12 @@
use bytes::Bytes;
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use std::{
borrow::Cow,
fmt::{Debug, Formatter},
net::SocketAddr,
time::{Duration, Instant},
};
use bytes::Bytes;
use serde::{Deserialize, Serialize};
use strum::IntoStaticStr;
use time::OffsetDateTime;
use uuid::Uuid;
@@ -0,0 +1,8 @@
edition = "2021"
unstable_features = true
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
normalize_comments = true
comment_width = 100
wrap_comments = true