From f3f82c7afce4bff37d5b0fa373d29abbf159fad6 Mon Sep 17 00:00:00 2001 From: Joseph Lewis III Date: Sun, 24 Dec 2023 13:33:52 -0800 Subject: [PATCH] Added disable/nohup and refactored noop commands. --- commands/aaa_noop.go | 178 +++++++++++++++++++++++++++++++++++++ commands/apt.go | 4 +- commands/base.go | 62 +++++++++++-- commands/base_test.go | 14 +++ commands/cat.go | 2 +- commands/chmod.go | 2 +- commands/clear.go | 2 +- commands/curl.go | 2 +- commands/echo.go | 2 +- commands/env.go | 2 +- commands/free.go | 2 +- commands/grep.go | 4 +- commands/hostname.go | 2 +- commands/id.go | 2 +- commands/kill.go | 28 ------ commands/killall.go | 26 ------ commands/last.go | 2 +- commands/ls.go | 4 +- commands/lscpu.go | 68 -------------- commands/lspci.go | 47 ---------- commands/lsusb.go | 36 -------- commands/mail.go | 2 +- commands/make.go | 31 ------- commands/mkdir.go | 2 +- commands/nettools.go | 4 +- commands/nice.go | 2 +- commands/passwd.go | 2 +- commands/perl.go | 30 ------- commands/php.go | 30 ------- commands/pkill.go | 26 ------ commands/ps.go | 2 +- commands/pwd.go | 2 +- commands/python.go | 30 ------- commands/reboot.go | 2 +- commands/reset.go | 2 +- commands/rm.go | 2 +- commands/rmdir.go | 2 +- commands/scp.go | 3 +- commands/screen.go | 27 ------ commands/shell.go | 2 +- commands/shell_builtins.go | 1 + commands/tar.go | 2 +- commands/touch.go | 2 +- commands/uname.go | 2 +- commands/unzip.go | 2 +- commands/uptime.go | 2 +- commands/w.go | 4 +- commands/wc.go | 2 +- commands/wget.go | 2 +- commands/which.go | 2 +- commands/whoami.go | 2 +- 51 files changed, 291 insertions(+), 426 deletions(-) create mode 100644 commands/aaa_noop.go delete mode 100644 commands/kill.go delete mode 100644 commands/killall.go delete mode 100644 commands/lscpu.go delete mode 100644 commands/lspci.go delete mode 100644 commands/lsusb.go delete mode 100644 commands/make.go delete mode 100644 commands/perl.go delete mode 100644 commands/php.go delete mode 100644 commands/pkill.go delete mode 100644 commands/python.go delete mode 100644 commands/screen.go diff --git a/commands/aaa_noop.go b/commands/aaa_noop.go new file mode 100644 index 0000000..23f2116 --- /dev/null +++ b/commands/aaa_noop.go @@ -0,0 +1,178 @@ +package commands + +import ( + "fmt" + + "github.com/josephlewis42/honeyssh/core/vos" +) + +// No-op commands. +type NoOpCommand struct { + Name string + Use string + Short string + Stdout string + ExitCode int +} + +// Convert the no-op command description to a functioning command. +func (c *NoOpCommand) ToCommand() vos.ProcessFunc { + return func(virtOS vos.VOS) int { + cmd := &SimpleCommand{ + Use: c.Use, + Short: c.Short, + // Never bail, even if args are bad. + NeverBail: true, + } + + return cmd.Run(virtOS, func() int { + if c.Stdout != "" { + w := virtOS.Stdout() + fmt.Fprintln(w, c.Stdout) + } + + return c.ExitCode + }) + } +} + +var noOpBinCommands = []NoOpCommand{ + { + Name: "kill", + Use: "kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]", + Short: "Send a signal to a process.", + }, + { + Name: "killall", + Use: "killall [OPTION]... [--] NAME...", + Short: "Kill a process by name.", + }, + { + Name: "lscpu", + Use: "lscpu [OPTION...]", + Short: "Display information about the CPU architecture.", + Stdout: mustDedent(` + Architecture: x86_64 + CPU op-mode(s): 32-bit, 64-bit + Address sizes: 40 bits physical, 48 bits virtual + Byte Order: Little Endian + CPU(s): 1 + On-line CPU(s) list: 0 + Vendor ID: GenuineIntel + BIOS Vendor ID: unknown + Model name: unknown + BIOS CPU family: 1 + CPU family: 6 + Model: 63 + Thread(s) per core: 1 + Core(s) per socket: 1 + Socket(s): 1 + Stepping: 2 + BogoMIPS: 1234.59 + Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx + fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm pni pclmulqdq dtes64 monitor ds_cpl + vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer + aes xsave avx xsaveopt + Virtualization features: + Virtualization: VT-x + Hypervisor vendor: KVM + Virtualization type: full + Caches (sum of all): + L1d: 32 KiB (1 instance) + L1i: 32 KiB (1 instance) + L2: 4 MiB (1 instance) + NUMA: + NUMA node(s): 1 + NUMA node0 CPU(s): 0 + `), + }, + { + Name: "lspci", + Use: "lspci [OPTION...]", + Short: "List PCI devices.", + Stdout: mustDedent(` + 00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02) + 00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II] + 00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II] + 00:01.2 USB controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01) + 00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03) + 00:02.0 VGA compatible controller: Red Hat, Inc. Virtio 1.0 GPU (rev 01) + 00:03.0 Ethernet controller: Red Hat, Inc. Virtio network device + 00:04.0 Ethernet controller: Red Hat, Inc. Virtio network device + 00:05.0 SCSI storage controller: Red Hat, Inc. Virtio SCSI + 00:06.0 SCSI storage controller: Red Hat, Inc. Virtio block device + 00:07.0 SCSI storage controller: Red Hat, Inc. Virtio block device + 00:08.0 Unclassified device [00ff]: Red Hat, Inc. Virtio memory balloon`), + }, + { + Name: "lsusb", + Use: "lsusb [OPTION...]", + Short: "List USB devices.", + Stdout: "Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub", + }, + { + Name: "make", + Use: "make [options] [target] ...", + Short: "Run a dependency graph of commands.", + Stdout: "make: *** No rule to make target. Stop.", + ExitCode: 1, + }, + { + Name: "nohup", + Use: "nohup COMMAND [ARG]...", + Short: "Run COMMAND, ignoring hangup signals.", + }, + { + Name: "perl", + Use: "perl [switches] [--] [programfile] [arguments]", + Short: "The Perl 5 language interpreter.", + Stdout: "Can't locate perl5db.pl: No such file or directory", + ExitCode: 1, + }, + { + Name: "php", + Use: "php [options] [-f] [--] [args...]", + Short: "PHP Command Line Interface.", + Stdout: "PHP: Error parsing php.ini on line 424", + ExitCode: 1, + }, + { + Name: "pkill", + Use: "pkill [OPTION]... PATTERN", + Short: "Signal a process by pattern", + }, + { + Name: "python", + Use: "python [option] ... [-c cmd | -m mod | file | -] [arg] ...", + Short: "Embedded version of the Python language.", + Stdout: "python: No module named os", + ExitCode: 1, + }, + { + Name: "python3", + Use: "python3 [option] ... [-c cmd | -m mod | file | -] [arg] ...", + Short: "Embedded version of the Python language.", + Stdout: "python: No module named os", + ExitCode: 1, + }, + { + Name: "screen", + Use: "screen [-opts] [cmd [args]]", + Short: "screen manager with VT100/ANSI terminal emulation", + }, +} + +var noOpSbinCommands = []NoOpCommand{} + +func init() { + for i := range noOpBinCommands { + cmd := noOpBinCommands[i] + mustAddBinCmd(cmd.Name, cmd.ToCommand()) + } + + for i := range noOpSbinCommands { + cmd := noOpSbinCommands[i] + + mustAddSbinCmd(cmd.Name, cmd.ToCommand()) + } +} diff --git a/commands/apt.go b/commands/apt.go index d04c2d5..c7436fc 100644 --- a/commands/apt.go +++ b/commands/apt.go @@ -96,6 +96,6 @@ func Apt(virtOS vos.VOS) int { var _ vos.ProcessFunc = Apt func init() { - addBinCmd("apt", Apt) - addBinCmd("apt-get", Apt) + mustAddBinCmd("apt", Apt) + mustAddBinCmd("apt-get", Apt) } diff --git a/commands/base.go b/commands/base.go index f04bceb..3307ce4 100644 --- a/commands/base.go +++ b/commands/base.go @@ -7,6 +7,7 @@ import ( "path" "strconv" "strings" + "unicode" "github.com/fatih/color" fcolor "github.com/fatih/color" @@ -28,7 +29,7 @@ type commandTable struct { lookup map[string]vos.ProcessFunc } -func (ct *commandTable) AddCommand(proc vos.ProcessFunc, names ...string) { +func (ct *commandTable) AddCommand(proc vos.ProcessFunc, names ...string) error { ct.commands = append(ct.commands, CommandEntry{ Names: names, Proc: proc, @@ -37,8 +38,12 @@ func (ct *commandTable) AddCommand(proc vos.ProcessFunc, names ...string) { ct.lookup = make(map[string]vos.ProcessFunc) } for _, name := range names { + if _, ok := ct.lookup[name]; ok { + return fmt.Errorf("name already registered: %q", name) + } ct.lookup[name] = proc } + return nil } var allCommands = commandTable{} @@ -56,13 +61,27 @@ func ListBuiltinCommands() []CommandEntry { var _ vos.ProcessResolver = BuiltinProcessResolver // addBinCmd adds a command under /bin and /usr/bin. -func addBinCmd(name string, cmd vos.ProcessFunc) { - allCommands.AddCommand(cmd, path.Join("/bin", name), path.Join("/usr/bin", name)) +func addBinCmd(name string, cmd vos.ProcessFunc) error { + return allCommands.AddCommand(cmd, path.Join("/bin", name), path.Join("/usr/bin", name)) } // addSbinCmd adds a command under /sbin and /usr/sbin. -func addSbinCmd(name string, cmd vos.ProcessFunc) { - allCommands.AddCommand(cmd, path.Join("/sbin", name), path.Join("/usr/sbin", name)) +func addSbinCmd(name string, cmd vos.ProcessFunc) error { + return allCommands.AddCommand(cmd, path.Join("/sbin", name), path.Join("/usr/sbin", name)) +} + +// mustAddBinCmd adds a command under /bin and /usr/bin and panics if it already exists. +func mustAddBinCmd(name string, cmd vos.ProcessFunc) { + if err := addBinCmd(name, cmd); err != nil { + panic(err) + } +} + +// mustAddSbinCmd adds a command under /sbin and /usr/sbin and panics if it already exists. +func mustAddSbinCmd(name string, cmd vos.ProcessFunc) { + if err := addSbinCmd(name, cmd); err != nil { + panic(err) + } } func BytesToHuman(bytes int64) string { @@ -318,3 +337,36 @@ func (c *ColorPrinter) Sprintf(color *color.Color, format string, a ...interface } return fmt.Sprintf(format, a...) } + +// mustDedent takes a multline string and dedents it based on the +// indentation of the second line. The first line MUST be blank. +func mustDedent(s string) string { + s = strings.TrimRightFunc(s, unicode.IsSpace) + lines := strings.Split(s, "\n") + if lines[0] != "" { + panic("First line must be blank.") + } + + if len(lines) == 1 { + return "" + } + + firstLine := lines[1] + remainderLen := len(strings.TrimLeftFunc(firstLine, unicode.IsSpace)) + prefix := firstLine[:len(firstLine)-remainderLen] + + out := "" + for i, line := range lines[1:] { + if i != 0 { + out += "\n" + } + trimmed := strings.TrimPrefix(line, prefix) + if trimmed == line { + panic(fmt.Sprintf("Line %q doesn't have prefix %q", line, prefix)) + } + + out += trimmed + } + + return out +} diff --git a/commands/base_test.go b/commands/base_test.go index b1dc0b5..2685868 100644 --- a/commands/base_test.go +++ b/commands/base_test.go @@ -125,3 +125,17 @@ func AssertScript(t *testing.T, commands ...string) { g.AssertJson(t, t.Name(), steps) } + +func TestMustDedent(t *testing.T) { + got := mustDedent(` + abc + def + ghi + jkl + `) + want := "abc\n\tdef\n\t\tghi\njkl" + + if got != want { + t.Fatalf("Wanted %q, got %q", want, got) + } +} diff --git a/commands/cat.go b/commands/cat.go index 903dafd..421d575 100644 --- a/commands/cat.go +++ b/commands/cat.go @@ -30,5 +30,5 @@ func Cat(virtOS vos.VOS) int { var _ vos.ProcessFunc = Cat func init() { - addBinCmd("cat", Cat) + mustAddBinCmd("cat", Cat) } diff --git a/commands/chmod.go b/commands/chmod.go index f138442..712f176 100644 --- a/commands/chmod.go +++ b/commands/chmod.go @@ -139,5 +139,5 @@ func Chmod(virtOS vos.VOS) int { var _ vos.ProcessFunc = Chmod func init() { - addBinCmd("chmod", Chmod) + mustAddBinCmd("chmod", Chmod) } diff --git a/commands/clear.go b/commands/clear.go index 68d4f48..b5167aa 100644 --- a/commands/clear.go +++ b/commands/clear.go @@ -27,5 +27,5 @@ func Clear(virtOS vos.VOS) int { var _ vos.ProcessFunc = Clear func init() { - addBinCmd("clear", Clear) + mustAddBinCmd("clear", Clear) } diff --git a/commands/curl.go b/commands/curl.go index 74198a0..cae1f9d 100644 --- a/commands/curl.go +++ b/commands/curl.go @@ -127,5 +127,5 @@ func Curl(virtOS vos.VOS) int { } func init() { - addBinCmd("curl", Curl) + mustAddBinCmd("curl", Curl) } diff --git a/commands/echo.go b/commands/echo.go index 16fe780..a262633 100644 --- a/commands/echo.go +++ b/commands/echo.go @@ -76,5 +76,5 @@ func Echo(virtOS vos.VOS) int { var _ vos.ProcessFunc = Echo func init() { - addBinCmd("echo", Echo) + mustAddBinCmd("echo", Echo) } diff --git a/commands/env.go b/commands/env.go index f8220c8..8530a4a 100644 --- a/commands/env.go +++ b/commands/env.go @@ -30,5 +30,5 @@ func Env(virtOS vos.VOS) int { var _ vos.ProcessFunc = Env func init() { - addBinCmd("env", Env) + mustAddBinCmd("env", Env) } diff --git a/commands/free.go b/commands/free.go index 4c96aa5..f46e22e 100644 --- a/commands/free.go +++ b/commands/free.go @@ -41,5 +41,5 @@ Swap: 24587768 4301240 20286528`) var _ vos.ProcessFunc = Free func init() { - addBinCmd("free", Free) + mustAddBinCmd("free", Free) } diff --git a/commands/grep.go b/commands/grep.go index 9a8eaee..31762c6 100644 --- a/commands/grep.go +++ b/commands/grep.go @@ -99,6 +99,6 @@ func Grep(virtOS vos.VOS) int { var _ vos.ProcessFunc = Grep func init() { - addBinCmd("grep", Grep) - addBinCmd("egrep", Grep) + mustAddBinCmd("grep", Grep) + mustAddBinCmd("egrep", Grep) } diff --git a/commands/hostname.go b/commands/hostname.go index 626244c..b5a6c57 100644 --- a/commands/hostname.go +++ b/commands/hostname.go @@ -24,5 +24,5 @@ func Hostname(virtOS vos.VOS) int { var _ vos.ProcessFunc = Hostname func init() { - addBinCmd("hostname", Hostname) + mustAddBinCmd("hostname", Hostname) } diff --git a/commands/id.go b/commands/id.go index 50b96da..8e6d494 100644 --- a/commands/id.go +++ b/commands/id.go @@ -27,5 +27,5 @@ func Id(virtOS vos.VOS) int { var _ vos.ProcessFunc = Id func init() { - addBinCmd("id", Id) + mustAddBinCmd("id", Id) } diff --git a/commands/kill.go b/commands/kill.go deleted file mode 100644 index cad9e61..0000000 --- a/commands/kill.go +++ /dev/null @@ -1,28 +0,0 @@ -package commands - -import ( - "github.com/josephlewis42/honeyssh/core/vos" -) - -// Kill implements a no-op kill command. -// -// https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/ -func Kill(virtOS vos.VOS) int { - cmd := &SimpleCommand{ - Use: "kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]", - Short: "Send a signal to a process.", - // Never bail, even if args are bad. - NeverBail: true, - } - - return cmd.Run(virtOS, func() int { - // No-op. - return 0 - }) -} - -var _ vos.ProcessFunc = Kill - -func init() { - addBinCmd("kill", Kill) -} diff --git a/commands/killall.go b/commands/killall.go deleted file mode 100644 index 59b42cf..0000000 --- a/commands/killall.go +++ /dev/null @@ -1,26 +0,0 @@ -package commands - -import ( - "github.com/josephlewis42/honeyssh/core/vos" -) - -// Killall implements a no-op killall command. -func Killall(virtOS vos.VOS) int { - cmd := &SimpleCommand{ - Use: "killall [OPTION]... [--] NAME...", - Short: "Kill a process by name.", - // Never bail, even if args are bad. - NeverBail: true, - } - - return cmd.Run(virtOS, func() int { - // No-op. - return 0 - }) -} - -var _ vos.ProcessFunc = Killall - -func init() { - addBinCmd("killall", Killall) -} diff --git a/commands/last.go b/commands/last.go index 5f9bdeb..63e63cb 100644 --- a/commands/last.go +++ b/commands/last.go @@ -31,5 +31,5 @@ func Last(virtOS vos.VOS) int { var _ vos.ProcessFunc = Last func init() { - addBinCmd("last", Last) + mustAddBinCmd("last", Last) } diff --git a/commands/ls.go b/commands/ls.go index 9fbb4db..8865190 100644 --- a/commands/ls.go +++ b/commands/ls.go @@ -14,9 +14,9 @@ import ( "time" fcolor "github.com/fatih/color" - getopt "github.com/pborman/getopt/v2" "github.com/josephlewis42/honeyssh/core/vos" "github.com/josephlewis42/honeyssh/third_party/memmapfs/mem" + getopt "github.com/pborman/getopt/v2" ) // Ls implements the UNIX ls command. @@ -307,5 +307,5 @@ func getUIDGID(fileInfo os.FileInfo) (uid, gid int) { var _ vos.ProcessFunc = Ls func init() { - addBinCmd("ls", Ls) + mustAddBinCmd("ls", Ls) } diff --git a/commands/lscpu.go b/commands/lscpu.go deleted file mode 100644 index 779fc9a..0000000 --- a/commands/lscpu.go +++ /dev/null @@ -1,68 +0,0 @@ -package commands - -import ( - "fmt" - "strings" - - "github.com/josephlewis42/honeyssh/core/vos" -) - -var ( - // Match procfs.go - lscpuText = strings.TrimSpace(` -Architecture: x86_64 - CPU op-mode(s): 32-bit, 64-bit - Address sizes: 40 bits physical, 48 bits virtual - Byte Order: Little Endian -CPU(s): 1 - On-line CPU(s) list: 0 -Vendor ID: GenuineIntel - BIOS Vendor ID: unknown - Model name: unknown - BIOS CPU family: 1 - CPU family: 6 - Model: 63 - Thread(s) per core: 1 - Core(s) per socket: 1 - Socket(s): 1 - Stepping: 2 - BogoMIPS: 1234.59 - Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx - fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm pni pclmulqdq dtes64 monitor ds_cpl - vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer - aes xsave avx xsaveopt -Virtualization features: - Virtualization: VT-x - Hypervisor vendor: KVM - Virtualization type: full -Caches (sum of all): - L1d: 32 KiB (1 instance) - L1i: 32 KiB (1 instance) - L2: 4 MiB (1 instance) -NUMA: - NUMA node(s): 1 - NUMA node0 CPU(s): 0 -`) -) - -// Lscpu implements the lscpu command. -func Lscpu(virtOS vos.VOS) int { - cmd := &SimpleCommand{ - Use: "lscpu [OPTION...]", - Short: "Display information about the CPU architecture.", - - // Never bail, even if args are bad. - NeverBail: true, - } - - return cmd.Run(virtOS, func() int { - fmt.Fprintln(virtOS.Stdout(), lscpuText) - return 0 - }) -} - -var _ vos.ProcessFunc = Lscpu - -func init() { - addBinCmd("lscpu", Lscpu) -} diff --git a/commands/lspci.go b/commands/lspci.go deleted file mode 100644 index 68e04ff..0000000 --- a/commands/lspci.go +++ /dev/null @@ -1,47 +0,0 @@ -package commands - -import ( - "fmt" - "strings" - - "github.com/josephlewis42/honeyssh/core/vos" -) - -var ( - lspciText = strings.TrimSpace(` -00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02) -00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II] -00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II] -00:01.2 USB controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01) -00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03) -00:02.0 VGA compatible controller: Red Hat, Inc. Virtio 1.0 GPU (rev 01) -00:03.0 Ethernet controller: Red Hat, Inc. Virtio network device -00:04.0 Ethernet controller: Red Hat, Inc. Virtio network device -00:05.0 SCSI storage controller: Red Hat, Inc. Virtio SCSI -00:06.0 SCSI storage controller: Red Hat, Inc. Virtio block device -00:07.0 SCSI storage controller: Red Hat, Inc. Virtio block device -00:08.0 Unclassified device [00ff]: Red Hat, Inc. Virtio memory balloon - `) -) - -// Lspci implements the lspci command. -func Lspci(virtOS vos.VOS) int { - cmd := &SimpleCommand{ - Use: "lspci [OPTION...]", - Short: "List PCI devices.", - - // Never bail, even if args are bad. - NeverBail: true, - } - - return cmd.Run(virtOS, func() int { - fmt.Fprintln(virtOS.Stdout(), lspciText) - return 0 - }) -} - -var _ vos.ProcessFunc = Lspci - -func init() { - addBinCmd("lspci", Lspci) -} diff --git a/commands/lsusb.go b/commands/lsusb.go deleted file mode 100644 index c826d65..0000000 --- a/commands/lsusb.go +++ /dev/null @@ -1,36 +0,0 @@ -package commands - -import ( - "fmt" - "strings" - - "github.com/josephlewis42/honeyssh/core/vos" -) - -var ( - lsusbText = strings.TrimSpace(` -Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub - `) -) - -// Lsusb implements the lsusb command. -func Lsusb(virtOS vos.VOS) int { - cmd := &SimpleCommand{ - Use: "lspci [OPTION...]", - Short: "List USB devices.", - - // Never bail, even if args are bad. - NeverBail: true, - } - - return cmd.Run(virtOS, func() int { - fmt.Fprintln(virtOS.Stdout(), lsusbText) - return 0 - }) -} - -var _ vos.ProcessFunc = Lsusb - -func init() { - addBinCmd("lsusb", Lsusb) -} diff --git a/commands/mail.go b/commands/mail.go index 9f42c1e..cb9a023 100644 --- a/commands/mail.go +++ b/commands/mail.go @@ -27,5 +27,5 @@ func Mail(virtOS vos.VOS) int { var _ vos.ProcessFunc = Mail func init() { - addBinCmd("mail", Mail) + mustAddBinCmd("mail", Mail) } diff --git a/commands/make.go b/commands/make.go deleted file mode 100644 index fdc1e50..0000000 --- a/commands/make.go +++ /dev/null @@ -1,31 +0,0 @@ -package commands - -import ( - "fmt" - - "github.com/josephlewis42/honeyssh/core/vos" -) - -// Make implements a no-op POSIX make command. -// -// https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/utilities/make.html -func Make(virtOS vos.VOS) int { - cmd := &SimpleCommand{ - Use: "make [options] [target] ...", - Short: "Run a dependency graph of commands.", - - // Never bail, even if args are bad. - NeverBail: true, - } - - return cmd.Run(virtOS, func() int { - fmt.Fprintln(virtOS.Stderr(), "make: *** No rule to make target. Stop.") - return 1 - }) -} - -var _ vos.ProcessFunc = Make - -func init() { - addBinCmd("make", Make) -} diff --git a/commands/mkdir.go b/commands/mkdir.go index 6a07cda..bceb5f7 100644 --- a/commands/mkdir.go +++ b/commands/mkdir.go @@ -59,5 +59,5 @@ func Mkdir(virtOS vos.VOS) int { var _ vos.ProcessFunc = Mkdir func init() { - addBinCmd("mkdir", Mkdir) + mustAddBinCmd("mkdir", Mkdir) } diff --git a/commands/nettools.go b/commands/nettools.go index ff943dd..228a583 100644 --- a/commands/nettools.go +++ b/commands/nettools.go @@ -194,6 +194,6 @@ func Ip(virtOS vos.VOS) int { var _ vos.ProcessFunc = Ifconfig func init() { - addSbinCmd("ifconfig", Ifconfig) - addSbinCmd("ip", Ip) + mustAddSbinCmd("ifconfig", Ifconfig) + mustAddSbinCmd("ip", Ip) } diff --git a/commands/nice.go b/commands/nice.go index 273b5f6..2a80003 100644 --- a/commands/nice.go +++ b/commands/nice.go @@ -43,5 +43,5 @@ func Nice(virtOS vos.VOS) int { var _ vos.ProcessFunc = Nice func init() { - addBinCmd("nice", Nice) + mustAddBinCmd("nice", Nice) } diff --git a/commands/passwd.go b/commands/passwd.go index c2c4654..cd38e60 100644 --- a/commands/passwd.go +++ b/commands/passwd.go @@ -72,5 +72,5 @@ func Passwd(virtualOS vos.VOS) int { var _ vos.ProcessFunc = Passwd func init() { - addBinCmd("passwd", Passwd) + mustAddBinCmd("passwd", Passwd) } diff --git a/commands/perl.go b/commands/perl.go deleted file mode 100644 index d78a941..0000000 --- a/commands/perl.go +++ /dev/null @@ -1,30 +0,0 @@ -package commands - -import ( - "fmt" - - "github.com/josephlewis42/honeyssh/core/vos" -) - -// Perl implements a fake Perl interpreter. -func Perl(virtOS vos.VOS) int { - cmd := &SimpleCommand{ - Use: "perl [switches] [--] [programfile] [arguments]", - Short: "The Perl 5 language interpreter.", - - // Never bail, even if args are bad. - NeverBail: true, - } - - return cmd.Run(virtOS, func() int { - w := virtOS.Stdout() - fmt.Fprintln(w, `Can't locate perl5db.pl: No such file or directory`) - return 1 - }) -} - -var _ vos.ProcessFunc = Perl - -func init() { - addBinCmd("perl", Perl) -} diff --git a/commands/php.go b/commands/php.go deleted file mode 100644 index 51473dd..0000000 --- a/commands/php.go +++ /dev/null @@ -1,30 +0,0 @@ -package commands - -import ( - "fmt" - - "github.com/josephlewis42/honeyssh/core/vos" -) - -// Php implements a fake PHP interpreter. -func Php(virtOS vos.VOS) int { - cmd := &SimpleCommand{ - Use: "php [options] [-f] [--] [args...]", - Short: "PHP Command Line Interface.", - - // Never bail, even if args are bad. - NeverBail: true, - } - - return cmd.Run(virtOS, func() int { - w := virtOS.Stdout() - fmt.Fprintln(w, `PHP: Error parsing php.ini on line 424`) - return 1 - }) -} - -var _ vos.ProcessFunc = Php - -func init() { - addBinCmd("php", Php) -} diff --git a/commands/pkill.go b/commands/pkill.go deleted file mode 100644 index 7330c24..0000000 --- a/commands/pkill.go +++ /dev/null @@ -1,26 +0,0 @@ -package commands - -import ( - "github.com/josephlewis42/honeyssh/core/vos" -) - -// Pkill implements a no-op pkill command. -func Pkill(virtOS vos.VOS) int { - cmd := &SimpleCommand{ - Use: "pkill [OPTION]... PATTERN", - Short: "Signal a process by pattern", - // Never bail, even if args are bad. - NeverBail: true, - } - - return cmd.Run(virtOS, func() int { - // No-op. - return 0 - }) -} - -var _ vos.ProcessFunc = Pkill - -func init() { - addBinCmd("pkill", Pkill) -} diff --git a/commands/ps.go b/commands/ps.go index ff89fbc..b5c43d4 100644 --- a/commands/ps.go +++ b/commands/ps.go @@ -106,5 +106,5 @@ func Ps(virtOS vos.VOS) int { var _ vos.ProcessFunc = Ps func init() { - addBinCmd("ps", Ps) + mustAddBinCmd("ps", Ps) } diff --git a/commands/pwd.go b/commands/pwd.go index b744786..b0459b2 100644 --- a/commands/pwd.go +++ b/commands/pwd.go @@ -28,5 +28,5 @@ func Pwd(virtOS vos.VOS) int { var _ vos.ProcessFunc = Pwd func init() { - addBinCmd("pwd", Pwd) + mustAddBinCmd("pwd", Pwd) } diff --git a/commands/python.go b/commands/python.go deleted file mode 100644 index 4e4e2db..0000000 --- a/commands/python.go +++ /dev/null @@ -1,30 +0,0 @@ -package commands - -import ( - "fmt" - - "github.com/josephlewis42/honeyssh/core/vos" -) - -// Python implements a fake Python interpreter. -func Python(virtOS vos.VOS) int { - cmd := &SimpleCommand{ - Use: "python [option] ... [-c cmd | -m mod | file | -] [arg] ...", - Short: "Embedded version of the Python language.", - - // Never bail, even if args are bad. - NeverBail: true, - } - - return cmd.Run(virtOS, func() int { - w := virtOS.Stdout() - fmt.Fprintln(w, "python: No module named os") - return 1 - }) -} - -var _ vos.ProcessFunc = Python - -func init() { - addBinCmd("python", Python) -} diff --git a/commands/reboot.go b/commands/reboot.go index 5af3b0d..f0155b2 100644 --- a/commands/reboot.go +++ b/commands/reboot.go @@ -25,5 +25,5 @@ func Reboot(virtOS vos.VOS) int { var _ vos.ProcessFunc = Reboot func init() { - addSbinCmd("reboot", Reboot) + mustAddSbinCmd("reboot", Reboot) } diff --git a/commands/reset.go b/commands/reset.go index 482215c..3db687a 100644 --- a/commands/reset.go +++ b/commands/reset.go @@ -27,5 +27,5 @@ func Reset(virtOS vos.VOS) int { var _ vos.ProcessFunc = Reset func init() { - addBinCmd("reset", Reset) + mustAddBinCmd("reset", Reset) } diff --git a/commands/rm.go b/commands/rm.go index 4f1f8c5..548000c 100644 --- a/commands/rm.go +++ b/commands/rm.go @@ -57,5 +57,5 @@ func Rm(virtOS vos.VOS) int { var _ vos.ProcessFunc = Rm func init() { - addBinCmd("rm", Rm) + mustAddBinCmd("rm", Rm) } diff --git a/commands/rmdir.go b/commands/rmdir.go index 13bf9f2..76c3e38 100644 --- a/commands/rmdir.go +++ b/commands/rmdir.go @@ -90,5 +90,5 @@ func Rmdir(virtOS vos.VOS) int { var _ vos.ProcessFunc = Rmdir func init() { - addBinCmd("rmdir", Rmdir) + mustAddBinCmd("rmdir", Rmdir) } diff --git a/commands/scp.go b/commands/scp.go index 1cd8e35..bac32d0 100644 --- a/commands/scp.go +++ b/commands/scp.go @@ -11,7 +11,6 @@ import ( "github.com/josephlewis42/honeyssh/core/vos" ) -// func scpUpload(vos vos.VOS, path string) (err error) { // Start upload in VOS uploadFd, err := vos.DownloadPath(fmt.Sprintf("scp_upload://%s", path)) @@ -115,5 +114,5 @@ func Scp(virtOS vos.VOS) int { var _ vos.ProcessFunc = Scp func init() { - addBinCmd("scp", Scp) + mustAddBinCmd("scp", Scp) } diff --git a/commands/screen.go b/commands/screen.go deleted file mode 100644 index 0e6a56e..0000000 --- a/commands/screen.go +++ /dev/null @@ -1,27 +0,0 @@ -package commands - -import ( - "github.com/josephlewis42/honeyssh/core/vos" -) - -// Screen implements a fake screen command. -func Screen(virtOS vos.VOS) int { - cmd := &SimpleCommand{ - Use: "screen [-opts] [cmd [args]]", - Short: "screen manager with VT100/ANSI terminal emulation", - - // Never bail, even if args are bad. - NeverBail: true, - } - - return cmd.Run(virtOS, func() int { - // Noop - return 0 - }) -} - -var _ vos.ProcessFunc = Screen - -func init() { - addBinCmd("screen", Screen) -} diff --git a/commands/shell.go b/commands/shell.go index b18115c..d54dd5b 100644 --- a/commands/shell.go +++ b/commands/shell.go @@ -456,5 +456,5 @@ func (s *Shell) executeProgramOrBuiltin(ec execContext) { } func init() { - addBinCmd("sh", RunShell) + mustAddBinCmd("sh", RunShell) } diff --git a/commands/shell_builtins.go b/commands/shell_builtins.go index b8ac5bb..522fdbd 100644 --- a/commands/shell_builtins.go +++ b/commands/shell_builtins.go @@ -146,4 +146,5 @@ func init() { AllBuiltins["set"] = ShellBuiltinFunc(NopBuiltin) AllBuiltins["su"] = ShellBuiltinFunc(NopBuiltin) AllBuiltins["export"] = ShellBuiltinFunc(NopBuiltin) + AllBuiltins["disown"] = ShellBuiltinFunc(NopBuiltin) } diff --git a/commands/tar.go b/commands/tar.go index 4642e2f..677539a 100644 --- a/commands/tar.go +++ b/commands/tar.go @@ -102,5 +102,5 @@ func Tar(virtOS vos.VOS) int { var _ vos.ProcessFunc = Tar func init() { - addBinCmd("tar", Tar) + mustAddBinCmd("tar", Tar) } diff --git a/commands/touch.go b/commands/touch.go index bfb447b..df0b6cf 100644 --- a/commands/touch.go +++ b/commands/touch.go @@ -57,5 +57,5 @@ func Touch(virtOS vos.VOS) int { var _ vos.ProcessFunc = Touch func init() { - addBinCmd("touch", Touch) + mustAddBinCmd("touch", Touch) } diff --git a/commands/uname.go b/commands/uname.go index 3ee7e5c..b74ee50 100644 --- a/commands/uname.go +++ b/commands/uname.go @@ -60,5 +60,5 @@ func Uname(virtOS vos.VOS) int { var _ vos.ProcessFunc = Uname func init() { - addBinCmd("uname", Uname) + mustAddBinCmd("uname", Uname) } diff --git a/commands/unzip.go b/commands/unzip.go index 6b56b11..11376ca 100644 --- a/commands/unzip.go +++ b/commands/unzip.go @@ -87,5 +87,5 @@ func Unzip(virtOS vos.VOS) int { var _ vos.ProcessFunc = Unzip func init() { - addBinCmd("unzip", Unzip) + mustAddBinCmd("unzip", Unzip) } diff --git a/commands/uptime.go b/commands/uptime.go index 66309d9..d2d031b 100644 --- a/commands/uptime.go +++ b/commands/uptime.go @@ -41,5 +41,5 @@ func formatUptime(virtOS uptimeable) string { var _ vos.ProcessFunc = Uptime func init() { - addBinCmd("uptime", Uptime) + mustAddBinCmd("uptime", Uptime) } diff --git a/commands/w.go b/commands/w.go index cdafb14..f4a9344 100644 --- a/commands/w.go +++ b/commands/w.go @@ -35,6 +35,6 @@ func W(virtOS vos.VOS) int { var _ vos.ProcessFunc = W func init() { - addBinCmd("w", W) - addBinCmd("who", W) + mustAddBinCmd("w", W) + mustAddBinCmd("who", W) } diff --git a/commands/wc.go b/commands/wc.go index 513cf50..ac4a1ba 100644 --- a/commands/wc.go +++ b/commands/wc.go @@ -168,5 +168,5 @@ func Wc(virtOS vos.VOS) int { var _ vos.ProcessFunc = Wc func init() { - addBinCmd("wc", Wc) + mustAddBinCmd("wc", Wc) } diff --git a/commands/wget.go b/commands/wget.go index 4dd7cf5..5db203c 100644 --- a/commands/wget.go +++ b/commands/wget.go @@ -272,5 +272,5 @@ func (c *countWriter) UpdateOutput() { } func init() { - addBinCmd("wget", Wget) + mustAddBinCmd("wget", Wget) } diff --git a/commands/which.go b/commands/which.go index 2c4e5f4..f6cfca8 100644 --- a/commands/which.go +++ b/commands/which.go @@ -28,5 +28,5 @@ func Which(virtOS vos.VOS) int { var _ vos.ProcessFunc = Which func init() { - addBinCmd("which", Which) + mustAddBinCmd("which", Which) } diff --git a/commands/whoami.go b/commands/whoami.go index 128b742..006c3f5 100644 --- a/commands/whoami.go +++ b/commands/whoami.go @@ -26,5 +26,5 @@ func Whoami(virtOS vos.VOS) int { var _ vos.ProcessFunc = Whoami func init() { - addBinCmd("whoami", Whoami) + mustAddBinCmd("whoami", Whoami) }