未验证 提交 1a782d32 编写于 作者: A Alessandro Arzilli 提交者: GitHub

service/rpccommon: log error for conns rejected by --only-same-user (#2211)

* service/rpccommon: log error for conns rejected by --only-same-user

If no logger is enabled manually write to stderr instead.

Fixes #2209

* logflags: fix style complaints from DeepSource
上级 9a3c9eba
...@@ -16,6 +16,7 @@ import ( ...@@ -16,6 +16,7 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
var any = false
var debugger = false var debugger = false
var gdbWire = false var gdbWire = false
var lldbServerOutput = false var lldbServerOutput = false
...@@ -40,6 +41,11 @@ func makeLogger(flag bool, fields logrus.Fields) *logrus.Entry { ...@@ -40,6 +41,11 @@ func makeLogger(flag bool, fields logrus.Fields) *logrus.Entry {
return logger return logger
} }
// Any returns true if any logging is enabled.
func Any() bool {
return any
}
// GdbWire returns true if the gdbserial package should log all the packets // GdbWire returns true if the gdbserial package should log all the packets
// exchanged with the stub. // exchanged with the stub.
func GdbWire() bool { func GdbWire() bool {
...@@ -121,7 +127,7 @@ func WriteAPIListeningMessage(addr string) { ...@@ -121,7 +127,7 @@ func WriteAPIListeningMessage(addr string) {
writeListeningMessage("API", addr) writeListeningMessage("API", addr)
} }
func writeListeningMessage(server string, addr string) { func writeListeningMessage(server, addr string) {
msg := fmt.Sprintf("%s server listening at: %s", server, addr) msg := fmt.Sprintf("%s server listening at: %s", server, addr)
if logOut != nil { if logOut != nil {
fmt.Fprintln(logOut, msg) fmt.Fprintln(logOut, msg)
...@@ -135,7 +141,7 @@ var errLogstrWithoutLog = errors.New("--log-output specified without --log") ...@@ -135,7 +141,7 @@ var errLogstrWithoutLog = errors.New("--log-output specified without --log")
// Setup sets debugger flags based on the contents of logstr. // Setup sets debugger flags based on the contents of logstr.
// If logDest is not empty logs will be redirected to the file descriptor or // If logDest is not empty logs will be redirected to the file descriptor or
// file path specified by logDest. // file path specified by logDest.
func Setup(logFlag bool, logstr string, logDest string) error { func Setup(logFlag bool, logstr, logDest string) error {
if logDest != "" { if logDest != "" {
n, err := strconv.Atoi(logDest) n, err := strconv.Atoi(logDest)
if err == nil { if err == nil {
...@@ -159,6 +165,7 @@ func Setup(logFlag bool, logstr string, logDest string) error { ...@@ -159,6 +165,7 @@ func Setup(logFlag bool, logstr string, logDest string) error {
if logstr == "" { if logstr == "" {
logstr = "debugger" logstr = "debugger"
} }
any = true
v := strings.Split(logstr, ",") v := strings.Split(logstr, ",")
for _, logcmd := range v { for _, logcmd := range v {
// If adding another value, do make sure to // If adding another value, do make sure to
......
...@@ -11,6 +11,8 @@ import ( ...@@ -11,6 +11,8 @@ import (
"net" "net"
"os" "os"
"strings" "strings"
"github.com/go-delve/delve/pkg/logflags"
) )
// for testing // for testing
...@@ -108,7 +110,11 @@ func canAccept(listenAddr, remoteAddr net.Addr) bool { ...@@ -108,7 +110,11 @@ func canAccept(listenAddr, remoteAddr net.Addr) bool {
log.Printf("cannot check remote address: %v", err) log.Printf("cannot check remote address: %v", err)
} }
if !same { if !same {
if logflags.Any() {
log.Printf("closing connection from different user (%v): connections to localhost are only accepted from the same UNIX user for security reasons", addr) log.Printf("closing connection from different user (%v): connections to localhost are only accepted from the same UNIX user for security reasons", addr)
} else {
fmt.Fprintf(os.Stderr, "closing connection from different user (%v): connections to localhost are only accepted from the same UNIX user for security reasons", addr)
}
return false return false
} }
return true return true
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册