1
0
mirror of https://github.com/google/gops.git synced 2024-11-24 08:22:25 +02:00

fix access control

This commit is contained in:
tuxpy 2018-04-30 22:58:23 +08:00
parent 8a706dc11b
commit fed29ab01f
3 changed files with 11 additions and 0 deletions

View File

@ -139,9 +139,13 @@ func listen(key string) {
}
if !verify(keyBuf, key) {
fmt.Fprintf(os.Stderr, "gops: access denied. client: %s\n", fd.RemoteAddr())
fd.Write([]byte{0}) // login failed
fd.Write([]byte("access denied. Please set right GOPS_KEY\n"))
fd.Close()
continue
} else {
fd.Write([]byte{1}) // login success
}
}

7
cmd.go
View File

@ -209,10 +209,17 @@ func cmdLazy(addr net.TCPAddr, c byte, params ...byte) (io.Reader, error) {
key := os.Getenv("GOPS_KEY")
if key != "" {
keyBuf := make([]byte, 64)
restBuf := make([]byte, 1)
copy(keyBuf, []byte(key))
if _, err := conn.Write(keyBuf); err != nil {
return nil, err
}
if _, err := conn.Read(restBuf); err != nil {
return nil, err
}
if restBuf[0] == 0 { // login failed.
return conn, nil
}
}
buf := []byte{c}

BIN
gops Executable file

Binary file not shown.