Skip to content

Commit b47f727

Browse files
authored
Merge pull request #11 from gliderlabs/master
v0.2.1
2 parents f1a52bd + ff9cab1 commit b47f727

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ NAME=sshfront
22
OWNER=gliderlabs
33
ARCH=$(shell uname -m)
44
RMFLAG=--rm
5-
VERSION=0.2.0
5+
VERSION=0.2.1
66

77
build:
88
mkdir -p build/Linux && GOOS=linux CGO_ENABLED=0 go build -a \
9-
-ldflags "-X main.Version $(VERSION)" \
9+
-ldflags "-X main.Version=$(VERSION)" \
1010
-installsuffix cgo \
1111
-o build/Linux/$(NAME)
1212
mkdir -p build/Darwin && GOOS=darwin CGO_ENABLED=0 go build -a \
13-
-ldflags "-X main.Version $(VERSION)" \
13+
-ldflags "-X main.Version=$(VERSION)" \
1414
-installsuffix cgo \
1515
-o build/Darwin/$(NAME)
1616

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# sshfront
22

3+
[![CircleCI](https://img.shields.io/circleci/project/gliderlabs/sshfront/release.svg)](https://circleci.com/gh/gliderlabs/sshfront)
4+
[![IRC Channel](https://img.shields.io/badge/irc-%23gliderlabs-blue.svg)](https://kiwiirc.com/client/irc.freenode.net/#gliderlabs)
5+
36
A lightweight SSH server frontend where authentication and connections
47
are controlled with command handlers / shell scripts.
58

@@ -74,3 +77,4 @@ This project was made possible thanks to [Deis](http://deis.io) and [DigitalOcea
7477
## License
7578

7679
MIT
80+
<img src="https://ga-beacon.appspot.com/UA-58928488-2/sshfront/readme?pixel" />

example/stdinecho

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
echo "Stdin:"
3+
cat

handlers.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,16 @@ func (h *sshHandler) Exit(err error) error {
163163
return err
164164
}
165165

166+
type EnvVar struct {
167+
Name, Value string
168+
}
169+
166170
func (h *sshHandler) Request(req *ssh.Request) {
167171
switch req.Type {
168172
case "exec":
169173
h.handleExec(req)
174+
case "env":
175+
h.handleEnv(req)
170176
case "pty-req":
171177
h.handlePty(req)
172178
case "window-change":
@@ -178,6 +184,14 @@ func (h *sshHandler) Request(req *ssh.Request) {
178184
}
179185
}
180186

187+
func (h *sshHandler) handleEnv(req *ssh.Request) {
188+
var pair EnvVar
189+
ssh.Unmarshal(req.Payload, &pair)
190+
envvar := fmt.Sprintf("%s=%s", pair.Name, pair.Value)
191+
h.Env = append(h.Env, envvar)
192+
req.Reply(true, nil)
193+
}
194+
181195
func (h *sshHandler) handleExec(req *ssh.Request) {
182196
h.Lock()
183197
defer h.Unlock()
@@ -207,7 +221,10 @@ func (h *sshHandler) handleExec(req *ssh.Request) {
207221
h.channel.Close()
208222
return
209223
}
210-
go io.Copy(stdinPipe, h.channel)
224+
go func() {
225+
defer stdinPipe.Close()
226+
io.Copy(stdinPipe, h.channel)
227+
}()
211228

212229
if req.WantReply {
213230
req.Reply(true, nil)

0 commit comments

Comments
 (0)