diff --git a/Makefile b/Makefile index 8e039da..2a85f24 100644 --- a/Makefile +++ b/Makefile @@ -2,15 +2,15 @@ NAME=sshfront OWNER=gliderlabs ARCH=$(shell uname -m) RMFLAG=--rm -VERSION=0.2.0 +VERSION=0.2.1 build: mkdir -p build/Linux && GOOS=linux CGO_ENABLED=0 go build -a \ - -ldflags "-X main.Version $(VERSION)" \ + -ldflags "-X main.Version=$(VERSION)" \ -installsuffix cgo \ -o build/Linux/$(NAME) mkdir -p build/Darwin && GOOS=darwin CGO_ENABLED=0 go build -a \ - -ldflags "-X main.Version $(VERSION)" \ + -ldflags "-X main.Version=$(VERSION)" \ -installsuffix cgo \ -o build/Darwin/$(NAME) diff --git a/README.md b/README.md index 88d0c8a..d9c4320 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # sshfront +[![CircleCI](https://img.shields.io/circleci/project/gliderlabs/sshfront/release.svg)](https://circleci.com/gh/gliderlabs/sshfront) +[![IRC Channel](https://img.shields.io/badge/irc-%23gliderlabs-blue.svg)](https://kiwiirc.com/client/irc.freenode.net/#gliderlabs) + A lightweight SSH server frontend where authentication and connections are controlled with command handlers / shell scripts. @@ -74,3 +77,4 @@ This project was made possible thanks to [Deis](http://deis.io) and [DigitalOcea ## License MIT + diff --git a/example/stdinecho b/example/stdinecho new file mode 100755 index 0000000..9a39433 --- /dev/null +++ b/example/stdinecho @@ -0,0 +1,3 @@ +#!/bin/bash +echo "Stdin:" +cat diff --git a/handlers.go b/handlers.go index ddfd53d..6818ccd 100644 --- a/handlers.go +++ b/handlers.go @@ -163,10 +163,16 @@ func (h *sshHandler) Exit(err error) error { return err } +type EnvVar struct { + Name, Value string +} + func (h *sshHandler) Request(req *ssh.Request) { switch req.Type { case "exec": h.handleExec(req) + case "env": + h.handleEnv(req) case "pty-req": h.handlePty(req) case "window-change": @@ -178,6 +184,14 @@ func (h *sshHandler) Request(req *ssh.Request) { } } +func (h *sshHandler) handleEnv(req *ssh.Request) { + var pair EnvVar + ssh.Unmarshal(req.Payload, &pair) + envvar := fmt.Sprintf("%s=%s", pair.Name, pair.Value) + h.Env = append(h.Env, envvar) + req.Reply(true, nil) +} + func (h *sshHandler) handleExec(req *ssh.Request) { h.Lock() defer h.Unlock() @@ -207,7 +221,10 @@ func (h *sshHandler) handleExec(req *ssh.Request) { h.channel.Close() return } - go io.Copy(stdinPipe, h.channel) + go func() { + defer stdinPipe.Close() + io.Copy(stdinPipe, h.channel) + }() if req.WantReply { req.Reply(true, nil)