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:
parent
8a706dc11b
commit
fed29ab01f
@ -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
7
cmd.go
@ -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}
|
||||
|
Loading…
Reference in New Issue
Block a user