Resynced w/master

Signed-off-by: Russ Magee <rmagee@gmail.com>
This commit is contained in:
Russ Magee 2020-07-21 22:08:46 -07:00
commit 09055dffe6
6 changed files with 57 additions and 46 deletions

View File

@ -26,12 +26,23 @@ BUILDOPTS :=$(BUILDOPTS)"$(GOBUILDOPTS) -ldflags \"-X main.version=$(VERSION)$(M
#endif #endif
SUBPKGS = logger spinsult xsnet SUBPKGS = logger spinsult xsnet
TOOLS = xspasswd xs xsd TOOLS = xs xsd
SUBDIRS = $(LIBS) $(TOOLS) 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 INSTPREFIX = /usr/local
all: common client server passwd all: common client server
clean: clean:
@echo "Make: $(MAKE)" @echo "Make: $(MAKE)"
@ -60,21 +71,12 @@ client: common
$(MAKE) BUILDOPTS=$(BUILDOPTS) -C xs $(MAKE) BUILDOPTS=$(BUILDOPTS) -C xs
ifeq ($(MSYSTEM),)
ifneq ($(GOOS),windows)
server: common server: common
ifeq ($(MSYSTEM),MSYS)
echo "Build of xsd server for Windows not yet supported"
else
$(MAKE) BUILDOPTS=$(BUILDOPTS) -C xsd $(MAKE) BUILDOPTS=$(BUILDOPTS) -C xsd
else
echo "Cross-build of xsd server for Windows not yet supported"
endif endif
else
server: common
echo "xsd server not (yet) supported on Windows"
endif
passwd: common
$(MAKE) BUILDOPTS=$(BUILDOPTS) -C xspasswd
vis: vis:
@which go-callvis >/dev/null 2>&1; \ @which go-callvis >/dev/null 2>&1; \
@ -83,38 +85,30 @@ vis:
else \ else \
$(MAKE) -C xs vis;\ $(MAKE) -C xs vis;\
$(MAKE) -C xsd vis;\ $(MAKE) -C xsd vis;\
$(MAKE) -C xspasswd vis; \
fi fi
lint: lint:
$(MAKE) -C xspasswd lint
$(MAKE) -C xsd lint $(MAKE) -C xsd lint
$(MAKE) -C xs lint $(MAKE) -C xs lint
reinstall: uninstall install reinstall: uninstall install
install: install:
cp xs/xs $(INSTPREFIX)/bin echo "WIN_MSYS:" $(WIN_MSYS)
ifeq ($(MSYSTEM),) ifdef WIN_MSYS
ifneq ($(GOOS),windows)
cp xsd/xsd xspasswd/xspasswd $(INSTPREFIX)/sbin
else
mv $(INSTPREFIX)/bin/xs $(INSTPREFIX)/bin/_xs
cp xs/mintty_wrapper.sh $(INSTPREFIX)/bin/xs cp xs/mintty_wrapper.sh $(INSTPREFIX)/bin/xs
echo "Cross-build of xsd server for Windows not yet supported" cp xs/mintty_wrapper.sh $(INSTPREFIX)/bin/xc
endif cp xs/xs $(INSTPREFIX)/bin/_xs
cp xs/xs $(INSTPREFIX)/bin/_xc
echo "Install of xsd server for Windows not yet supported"
else else
echo "Cross-build of xsd server for Windows not yet supported" cp xs/xs $(INSTPREFIX)/bin
endif
cd $(INSTPREFIX)/bin && ln -s xs xc && cd - cd $(INSTPREFIX)/bin && ln -s xs xc && cd -
endif
uninstall: uninstall:
rm -f $(INSTPREFIX)/bin/xs $(INSTPREFIX)/bin/xc $(INSTPREFIX)/bin/_xs rm -f $(INSTPREFIX)/bin/xs $(INSTPREFIX)/bin/xc \
ifeq ($(MSYSTEM),) $(INSTPREFIX)/bin/_xs $(INSTPREFIX)/bin/_xc
ifneq ($(GOOS),windows) ifndef $(WIN_MSYS)
rm -f $(INSTPREFIX)/sbin/xsd $(INSTPREFIX)/sbin/xspasswd rm -f $(INSTPREFIX)/sbin/xsd
else
endif
else
endif endif

View File

@ -1,6 +0,0 @@
## The Makefile(s) to build require GNU make (gmake).
## Please install and invoke build via:
## $ gmake <targets>
## eg.,
## $ gmake clean all

View File

@ -1,6 +1,5 @@
[![GoDoc](https://godoc.org/blitter.com/go/xs?status.svg)](https://godoc.org/blitter.com/go/xs) [![GoDoc](https://godoc.org/blitter.com/go/xs?status.svg)](https://godoc.org/blitter.com/go/xs)
# XS # XS
-- --
@ -198,3 +197,9 @@ Example, tunnelling ssh through xs
* [client side, term A] ```$ xs -T=6002:7002 user@server``` * [client side, term A] ```$ xs -T=6002:7002 user@server```
* [client side, term B] ```$ ssh user@localhost -p 6002``` * [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```

View File

@ -37,7 +37,7 @@ func MakeRaw(fd uintptr) (*State, error) {
// GetState returns the current state of a terminal which may be useful to // GetState returns the current state of a terminal which may be useful to
// restore the terminal after a signal. // restore the terminal after a signal.
func GetState(fd int) (*State, error) { func GetState(fd uintptr) (*State, error) {
return &State{}, nil return &State{}, nil
} }

View File

@ -28,10 +28,12 @@ cleanup() {
stty sane stty sane
} }
me="$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")"
if [ ${1}x == "-hx" ]; then if [ ${1}x == "-hx" ]; then
./hkexsh -h _${me} -h
else else
stty -echo raw icrnl stty -echo raw icrnl
./hkexsh $@ _${me} $@
fi fi

View File

@ -722,7 +722,10 @@ func main() {
// Find out what program we are (shell or copier) // Find out what program we are (shell or copier)
myPath := strings.Split(os.Args[0], string(os.PathSeparator)) 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 // xs accepts a command (-x) but not
// a srcpath (-r) or dstpath (-t) // a srcpath (-r) or dstpath (-t)
flag.StringVar(&cmdStr, "x", "", "run <`command`> (if not specified, run interactive shell)") flag.StringVar(&cmdStr, "x", "", "run <`command`> (if not specified, run interactive shell)")
@ -766,7 +769,7 @@ func main() {
var uname string var uname string
if remoteUser == "" { if remoteUser == "" {
u, _ := user.Current() // nolint: gosec u, _ := user.Current() // nolint: gosec
uname = u.Username uname = localUserName(u)
} else { } else {
uname = remoteUser uname = remoteUser
} }
@ -1040,6 +1043,19 @@ func main() {
exitWithStatus(int(rec.Status())) 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) { func restoreTermState(oldState *xs.State) {
_ = xs.Restore(os.Stdin.Fd(), oldState) // nolint: errcheck,gosec _ = xs.Restore(os.Stdin.Fd(), oldState) // nolint: errcheck,gosec
} }