From 58c87f7e0e82e09eb6c8326dadb381fb329d3209 Mon Sep 17 00:00:00 2001 From: Russtopia Date: Mon, 18 May 2020 23:27:40 -0700 Subject: [PATCH 1/5] Update 'README.md' --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 084104f..3081c15 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ [![GoDoc](https://godoc.org/blitter.com/go/xs?status.svg)](https://godoc.org/blitter.com/go/xs) - # XS -- From 57b71e792513f7c4241c5c9165205e4751c98328 Mon Sep 17 00:00:00 2001 From: Russ Magee Date: Mon, 18 May 2020 23:59:33 -0700 Subject: [PATCH 2/5] FreeBSD note into README.md Signed-off-by: Russ Magee --- README.freebsd | 6 ------ README.md | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) delete mode 100644 README.freebsd diff --git a/README.freebsd b/README.freebsd deleted file mode 100644 index 968d79c..0000000 --- a/README.freebsd +++ /dev/null @@ -1,6 +0,0 @@ -## The Makefile(s) to build require GNU make (gmake). -## Please install and invoke build via: -## $ gmake -## eg., -## $ gmake clean all - diff --git a/README.md b/README.md index 3081c15..f6b8543 100644 --- a/README.md +++ b/README.md @@ -197,3 +197,9 @@ Example, tunnelling ssh through xs * [client side, term A] ```$ xs -T=6002:7002 user@server``` * [client side, term B] ```$ ssh user@localhost -p 6002``` + +### Building for FreeBSD + +The Makefile(s) to build require GNU make (gmake). +Please install and invoke build via: +```$ gmake clean all``` From 1addd188060d7521b5655835eaeb856af3796919 Mon Sep 17 00:00:00 2001 From: Russ Magee Date: Sun, 24 May 2020 21:15:28 -0700 Subject: [PATCH 3/5] Fixed GOOS=windows MSYSTEM=MSYS install Signed-off-by: Russ Magee --- Makefile | 63 ++++++++++++++++++++------------------------ go.mod | 2 +- go.sum | 2 ++ termmode_windows.go | 8 +++--- xs/mintty_wrapper.sh | 6 +++-- xs/xs.go | 5 +++- 6 files changed, 43 insertions(+), 43 deletions(-) diff --git a/Makefile b/Makefile index 7ea0b32..091d6a6 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ VERSION := 0.8.22 -.PHONY: lint vis clean common client server passwd subpkgs install uninstall reinstall +.PHONY: lint vis clean common client server subpkgs install uninstall reinstall ## Tag version of binaries with build info wrt. ## GO111MODULE(=on) and vendor/ setup vs. $GOPATH pkg builds @@ -26,12 +26,23 @@ BUILDOPTS :=$(BUILDOPTS)"$(GOBUILDOPTS) -ldflags \"-X main.version=$(VERSION)$(M #endif SUBPKGS = logger spinsult xsnet -TOOLS = xspasswd xs xsd +TOOLS = xs xsd SUBDIRS = $(LIBS) $(TOOLS) +ifeq ($(GOOS),) + GOOS=$(shell go env GOOS) +endif + +ifeq ($(GOOS),windows) +ifeq ($(MSYSTEM),MSYS) +WIN_MSYS=1 +endif +endif + + INSTPREFIX = /usr/local -all: common client server passwd +all: common client server clean: @echo "Make: $(MAKE)" @@ -60,21 +71,11 @@ client: common $(MAKE) BUILDOPTS=$(BUILDOPTS) -C xs -ifeq ($(MSYSTEM),) -ifneq ($(GOOS),windows) server: common +ifdef WIN_MSYS + echo "Build of xsd server for Windows not yet supported" $(MAKE) BUILDOPTS=$(BUILDOPTS) -C xsd -else - echo "Cross-build of xsd server for Windows not yet supported" endif -else -server: common - echo "xsd server not (yet) supported on Windows" -endif - - -passwd: common - $(MAKE) BUILDOPTS=$(BUILDOPTS) -C xspasswd vis: @which go-callvis >/dev/null 2>&1; \ @@ -83,38 +84,30 @@ vis: else \ $(MAKE) -C xs vis;\ $(MAKE) -C xsd vis;\ - $(MAKE) -C xspasswd vis; \ fi lint: - $(MAKE) -C xspasswd lint $(MAKE) -C xsd lint $(MAKE) -C xs lint reinstall: uninstall install install: - cp xs/xs $(INSTPREFIX)/bin -ifeq ($(MSYSTEM),) -ifneq ($(GOOS),windows) - cp xsd/xsd xspasswd/xspasswd $(INSTPREFIX)/sbin -else - mv $(INSTPREFIX)/bin/xs $(INSTPREFIX)/bin/_xs + echo "WIN_MSYS:" $(WIN_MSYS) +ifdef WIN_MSYS cp xs/mintty_wrapper.sh $(INSTPREFIX)/bin/xs - echo "Cross-build of xsd server for Windows not yet supported" -endif + cp xs/mintty_wrapper.sh $(INSTPREFIX)/bin/xc + cp xs/xs $(INSTPREFIX)/bin/_xs + cp xs/xs $(INSTPREFIX)/bin/_xc + echo "Install of xsd server for Windows not yet supported" else - echo "Cross-build of xsd server for Windows not yet supported" -endif + cp xs/xs $(INSTPREFIX)/bin cd $(INSTPREFIX)/bin && ln -s xs xc && cd - - +endif uninstall: - rm -f $(INSTPREFIX)/bin/xs $(INSTPREFIX)/bin/xc $(INSTPREFIX)/bin/_xs -ifeq ($(MSYSTEM),) -ifneq ($(GOOS),windows) - rm -f $(INSTPREFIX)/sbin/xsd $(INSTPREFIX)/sbin/xspasswd -else -endif -else + rm -f $(INSTPREFIX)/bin/xs $(INSTPREFIX)/bin/xc \ + $(INSTPREFIX)/bin/_xs $(INSTPREFIX)/bin/_xc +ifndef $(WIN_MSYS) + rm -f $(INSTPREFIX)/sbin/xsd endif diff --git a/go.mod b/go.mod index b0e6d29..6cf9e07 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 // indirect github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b // indirect - github.com/tjfoc/gmsm v1.3.0 // indirect + github.com/tjfoc/gmsm v1.3.1 // indirect github.com/xtaci/kcp-go v5.4.20+incompatible golang.org/x/crypto v0.0.0-20200423211502-4bdfaf469ed5 golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f diff --git a/go.sum b/go.sum index 21c90df..f04a5aa 100644 --- a/go.sum +++ b/go.sum @@ -42,6 +42,8 @@ github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b h1:fj5tQ8acgNUr6O8LE github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b/go.mod h1:5XA7W9S6mni3h5uvOC75dA3m9CCCaS83lltmc0ukdi4= github.com/tjfoc/gmsm v1.3.0 h1:i7c6Za/IlgBvnGxYpfD7L3TGuaS+v6oGcgq+J9/ecEA= github.com/tjfoc/gmsm v1.3.0/go.mod h1:HaUcFuY0auTiaHB9MHFGCPx5IaLhTUd2atbCFBQXn9w= +github.com/tjfoc/gmsm v1.3.1 h1:+k3IAlF81c31/TllJmIfuCYnjl8ziMdTWGWJcP9J1uo= +github.com/tjfoc/gmsm v1.3.1/go.mod h1:HaUcFuY0auTiaHB9MHFGCPx5IaLhTUd2atbCFBQXn9w= github.com/xtaci/kcp-go v1.0.1 h1:SEZn2Iick6ualQpV8yY9cXdDTgbfBHPIwJl7UvxfxLQ= github.com/xtaci/kcp-go v5.4.20+incompatible h1:TN1uey3Raw0sTz0Fg8GkfM0uH3YwzhnZWQ1bABv5xAg= github.com/xtaci/kcp-go v5.4.20+incompatible/go.mod h1:bN6vIwHQbfHaHtFpEssmWsN45a+AZwO7eyRCmEIbtvE= diff --git a/termmode_windows.go b/termmode_windows.go index 92ec2c3..c8931c9 100644 --- a/termmode_windows.go +++ b/termmode_windows.go @@ -27,7 +27,7 @@ type State struct { // MakeRaw put the terminal connected to the given file descriptor into raw // mode and returns the previous state of the terminal so that it can be // restored. -func MakeRaw(fd int) (*State, error) { +func MakeRaw(fd uintptr) (*State, error) { // This doesn't really work. The exec.Command() runs a sub-shell // so the stty mods don't affect the client process. cmd := exec.Command("stty", "-echo raw") @@ -37,13 +37,13 @@ func MakeRaw(fd int) (*State, error) { // GetState returns the current state of a terminal which may be useful to // restore the terminal after a signal. -func GetState(fd int) (*State, error) { +func GetState(fd uintptr) (*State, error) { return &State{}, nil } // Restore restores the terminal connected to the given file descriptor to a // previous state. -func Restore(fd int, state *State) error { +func Restore(fd uintptr, state *State) error { cmd := exec.Command("stty", "echo cooked") cmd.Run() return nil @@ -52,7 +52,7 @@ func Restore(fd int, state *State) error { // ReadPassword reads a line of input from a terminal without local echo. This // is commonly used for inputting passwords and other sensitive data. The slice // returned does not include the \n. -func ReadPassword(fd int) ([]byte, error) { +func ReadPassword(fd uintptr) ([]byte, error) { return readPasswordLine(passwordReader(fd)) } diff --git a/xs/mintty_wrapper.sh b/xs/mintty_wrapper.sh index cef7de8..9cba8ff 100755 --- a/xs/mintty_wrapper.sh +++ b/xs/mintty_wrapper.sh @@ -28,10 +28,12 @@ cleanup() { stty sane } +me="$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")" + if [ ${1}x == "-hx" ]; then - ./hkexsh -h + _${me} -h else stty -echo raw icrnl - ./hkexsh $@ + _${me} $@ fi diff --git a/xs/xs.go b/xs/xs.go index 78a4fbe..f86cb89 100755 --- a/xs/xs.go +++ b/xs/xs.go @@ -722,7 +722,10 @@ func main() { // Find out what program we are (shell or copier) myPath := strings.Split(os.Args[0], string(os.PathSeparator)) - if myPath[len(myPath)-1] != "xc" && myPath[len(myPath)-1] != "xc.exe" { + if myPath[len(myPath)-1] != "xc" && + myPath[len(myPath)-1] != "_xc" && + myPath[len(myPath)-1] != "xc.exe" && + myPath[len(myPath)-1] != "_xc.exe" { // xs accepts a command (-x) but not // a srcpath (-r) or dstpath (-t) flag.StringVar(&cmdStr, "x", "", "run <`command`> (if not specified, run interactive shell)") From f0a2bb02957ed2ae147263e3867f12a2708ad3aa Mon Sep 17 00:00:00 2001 From: Russ Magee Date: Wed, 3 Jun 2020 21:39:42 -0700 Subject: [PATCH 4/5] Updates to fix MSYSTEM=MSYS build and install targets Signed-off-by: Russ Magee --- Makefile | 3 ++- go.mod | 3 +-- go.sum | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 091d6a6..bbd5490 100644 --- a/Makefile +++ b/Makefile @@ -72,8 +72,9 @@ client: common server: common -ifdef WIN_MSYS +ifeq ($(MSYSTEM),MSYS) echo "Build of xsd server for Windows not yet supported" +else $(MAKE) BUILDOPTS=$(BUILDOPTS) -C xsd endif diff --git a/go.mod b/go.mod index 6cf9e07..090570b 100644 --- a/go.mod +++ b/go.mod @@ -11,8 +11,7 @@ require ( blitter.com/go/newhope v0.0.0-20200130200750-192fc08a8aae github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da github.com/jameskeane/bcrypt v0.0.0-20120420032655-c3cd44c1e20f - github.com/klauspost/cpuid v1.2.3 // indirect - github.com/klauspost/reedsolomon v1.9.4 // indirect + github.com/klauspost/reedsolomon v1.9.9 // indirect github.com/kr/pty v1.1.8 github.com/mattn/go-isatty v0.0.12 github.com/pkg/errors v0.9.1 // indirect diff --git a/go.sum b/go.sum index f04a5aa..0592509 100644 --- a/go.sum +++ b/go.sum @@ -25,8 +25,12 @@ github.com/jameskeane/bcrypt v0.0.0-20120420032655-c3cd44c1e20f h1:UWGE8Vi+1Agt0 github.com/jameskeane/bcrypt v0.0.0-20120420032655-c3cd44c1e20f/go.mod h1:u+9Snq0w+ZdYKi8BBoaxnEwWu0fY4Kvu9ByFpM51t1s= github.com/klauspost/cpuid v1.2.3 h1:CCtW0xUnWGVINKvE/WWOYKdsPV6mawAtvQuSl8guwQs= github.com/klauspost/cpuid v1.2.3/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= +github.com/klauspost/cpuid v1.2.4 h1:EBfaK0SWSwk+fgk6efYFWdzl8MwRWoOO1gkmiaTXPW4= +github.com/klauspost/cpuid v1.2.4/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/klauspost/reedsolomon v1.9.4 h1:FB9jDBGqUNyhUg4Gszz384ulFqVSc61Pdap+HRPgnSo= github.com/klauspost/reedsolomon v1.9.4/go.mod h1:CwCi+NUr9pqSVktrkN+Ondf06rkhYZ/pcNv7fu+8Un4= +github.com/klauspost/reedsolomon v1.9.9 h1:qCL7LZlv17xMixl55nq2/Oa1Y86nfO8EqDfv2GHND54= +github.com/klauspost/reedsolomon v1.9.9/go.mod h1:O7yFFHiQwDR6b2t63KPUpccPtNdp5ADgh1gg4fd12wo= github.com/kr/pty v1.1.8 h1:AkaSdXYQOWeaO3neb8EM634ahkXXe3jYbVh/F9lq+GI= github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= From 3522976ef789c864b76e389d442ad28494df60f6 Mon Sep 17 00:00:00 2001 From: Russ Magee Date: Thu, 4 Jun 2020 00:53:20 -0700 Subject: [PATCH 5/5] Correct implicit username for MSYS2 eg. xs @server.com Signed-off-by: Russ Magee --- xs/xs.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/xs/xs.go b/xs/xs.go index f86cb89..69afaa8 100755 --- a/xs/xs.go +++ b/xs/xs.go @@ -256,7 +256,7 @@ func buildCmdRemoteToLocal(copyQuiet bool, copyLimitBPS uint, destPath, files st cmd = xs.GetTool("tar") args = []string{"-xz", "-C", destPath} -} else { + } else { // TODO: Query remote side for total file/dir size bandwidthInBytesPerSec := " -L " + fmt.Sprintf("%d ", copyLimitBPS) displayOpts := " -pre " @@ -309,7 +309,7 @@ func buildCmdLocalToRemote(copyQuiet bool, copyLimitBPS uint, files string) (cap bandwidthInBytesPerSec := " -L " + fmt.Sprintf("%d", copyLimitBPS) displayOpts := " -pre " cmd = xs.GetTool("bash") - args = []string{"-c", xs.GetTool("tar")+" -cz -f /dev/stdout "} + args = []string{"-c", xs.GetTool("tar") + " -cz -f /dev/stdout "} files = strings.TrimSpace(files) // Awesome fact: tar actually can take multiple -C args, and // changes to the dest dir *as it sees each one*. This enables @@ -723,9 +723,9 @@ func main() { // Find out what program we are (shell or copier) myPath := strings.Split(os.Args[0], string(os.PathSeparator)) if myPath[len(myPath)-1] != "xc" && - myPath[len(myPath)-1] != "_xc" && - myPath[len(myPath)-1] != "xc.exe" && - myPath[len(myPath)-1] != "_xc.exe" { + myPath[len(myPath)-1] != "_xc" && + myPath[len(myPath)-1] != "xc.exe" && + myPath[len(myPath)-1] != "_xc.exe" { // xs accepts a command (-x) but not // a srcpath (-r) or dstpath (-t) flag.StringVar(&cmdStr, "x", "", "run <`command`> (if not specified, run interactive shell)") @@ -769,7 +769,7 @@ func main() { var uname string if remoteUser == "" { u, _ := user.Current() // nolint: gosec - uname = u.Username + uname = localUserName(u) } else { uname = remoteUser } @@ -1037,6 +1037,19 @@ func main() { exitWithStatus(int(rec.Status())) } +// currentUser returns the current username minus any OS-specific prefixes +// such as MS Windows workgroup prefixes (eg. workgroup\user). +func localUserName(u *user.User) string { + if u == nil { + log.Fatal("null User?!") + } + + // WinAPI: username may have CIFS prefix %USERDOMAIN%\ + userspec := strings.Split(u.Username, `\`) + username := userspec[len(userspec)-1] + return username +} + func restoreTermState(oldState *xs.State) { _ = xs.Restore(os.Stdin.Fd(), oldState) // nolint: errcheck,gosec }