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