🏡 index : ~doyle/pisshoff.git

author Jordan Doyle <jordan@doyle.la> 2023-06-26 7:54:30.0 +00:00:00
committer Jordan Doyle <jordan@doyle.la> 2023-06-26 7:54:51.0 +00:00:00
commit
1710f36e77e950d57c319f974bb7bc56b35a0ea6 [patch]
tree
1c61bc8051d5e7db74d92debc6e9420eb6d63843
parent
b947760e2257ee96b9e150b4666be386f3628da9
download
1710f36e77e950d57c319f974bb7bc56b35a0ea6.tar.gz

Add mock uname command



Diff

 pisshoff-server/src/command.rs | 52 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)

diff --git a/pisshoff-server/src/command.rs b/pisshoff-server/src/command.rs
index 7929f7a..36fa090 100644
--- a/pisshoff-server/src/command.rs
+++ b/pisshoff-server/src/command.rs
@@ -1,5 +1,5 @@
use itertools::Itertools;
use std::{f32, str::FromStr, time::Duration};
use std::{borrow::Cow, f32, str::FromStr, time::Duration};
use thrussh::{server::Session, ChannelId};

pub async fn run_command(args: &[String], channel: ChannelId, session: &mut Session) {
@@ -40,6 +40,56 @@ pub async fn run_command(args: &[String], channel: ChannelId, session: &mut Sess
                tokio::time::sleep(Duration::from_secs_f32(secs)).await;
            }
        }
        "uname" => {
            // todo: move this out to its own module
            let out: Cow<'static, str> = match args.get(1).map(String::as_str) {
                None | Some("-s" | "--kernel-name") => "Linux\n".into(),
                Some("-a" | "--all") => "Linux cd5079c0d642 5.15.49 #1 SMP PREEMPT Tue Sep 13 07:51:32 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux\n".into(),
                Some("-n" | "--nodename") => "cd5079c0d642\n".into(),
                Some("-r" | "--kernel-release") => "5.15.49\n".into(),
                Some("-v" | "--kernel-version") => "#1 SMP PREEMPT Tue Sep 13 07:51:32 UTC 2022\n".into(),
                Some("-m" | "--machine" | "-p" | "--processor" | "-i" | "--hardware-platform") => "x86_64\n".into(),
                Some("-o" | "--operating-system") => "GNU/Linux\n".into(),
                Some("--version") => "uname (GNU coreutils) 8.32
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David MacKenzie.\n".into(),
                Some("--help") => "Usage: uname [OPTION]...
Print certain system information.  With no OPTION, same as -s.

  -a, --all                print all information, in the following order,
                             except omit -p and -i if unknown:
  -s, --kernel-name        print the kernel name
  -n, --nodename           print the network node hostname
  -r, --kernel-release     print the kernel release
  -v, --kernel-version     print the kernel version
  -m, --machine            print the machine hardware name
  -p, --processor          print the processor type (non-portable)
  -i, --hardware-platform  print the hardware platform (non-portable)
  -o, --operating-system   print the operating system
      --help     display this help and exit
      --version  output version information and exit

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Report any translation bugs to <https://translationproject.org/team/>
Full documentation <https://www.gnu.org/software/coreutils/uname>
or available locally via: info '(coreutils) uname invocation'\n".into(),
                Some("-") => "uname: extra operand '-'\nTry 'uname --help' for more information.\n".into(),
                Some(v) => format!(
                    "uname: invalid option -- '{}'\nTry 'uname --help' for more information.\n",
                    if v.starts_with("-") && !v.starts_with("--") {
                        &v[1..]
                    } else {
                        v
                    }
                ).into(),
            };

            session.data(channel, out.into_owned().into());
        }
        other => {
            // TODO: fix stderr displaying out of order
            session.data(