Merge pull request #16344 from dfr/vendor-dbus

vendor github.com/godbus/dbus/v5@4b691ce
This commit is contained in:
OpenShift Merge Robot
2022-10-31 09:28:04 -04:00
committed by GitHub
26 changed files with 111 additions and 108 deletions

2
go.mod
View File

@ -28,7 +28,7 @@ require (
github.com/docker/go-units v0.5.0
github.com/fsnotify/fsnotify v1.6.0
github.com/ghodss/yaml v1.0.0
github.com/godbus/dbus/v5 v5.1.0
github.com/godbus/dbus/v5 v5.1.1-0.20221029134443-4b691ce883d5
github.com/google/gofuzz v1.2.0
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/google/uuid v1.3.0

4
go.sum
View File

@ -426,8 +426,9 @@ github.com/godbus/dbus v0.0.0-20180201030542-885f9cc04c9c/go.mod h1:/YcGZj5zSblf
github.com/godbus/dbus v0.0.0-20190422162347-ade71ed3457e/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4=
github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/godbus/dbus/v5 v5.1.1-0.20221029134443-4b691ce883d5 h1:boOtwyhKoC3Aadiw5zbhU54YyCkm9EpZCSN6mOx0KLc=
github.com/godbus/dbus/v5 v5.1.1-0.20221029134443-4b691ce883d5/go.mod h1:fXoNnqaUvdKqjJmMGeiBgmRphUg+kO0MT4AhPOP6+Qg=
github.com/gogo/googleapis v1.2.0/go.mod h1:Njal3psf3qN6dwBtQfUmBZh2ybovJ0tlu3o/AC7HYjU=
github.com/gogo/googleapis v1.4.0/go.mod h1:5YRNX2z1oM5gXdAkurHa942MDgEJyk02w4OecKY87+c=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
@ -1224,6 +1225,7 @@ golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220909162455-aba9fc2a8ff2/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

7
vendor/github.com/godbus/dbus/v5/.golangci.yml generated vendored Normal file
View File

@ -0,0 +1,7 @@
# For documentation, see https://golangci-lint.run/usage/configuration/
linters:
enable:
- gofumpt
- unconvert
- unparam

View File

@ -34,6 +34,7 @@ gives a short overview over the basic usage.
- [iwd](https://github.com/shibumi/iwd) go bindings for the internet wireless daemon "iwd".
- [notify](https://github.com/esiqveland/notify) provides desktop notifications over dbus into a library.
- [playerbm](https://github.com/altdesktop/playerbm) a bookmark utility for media players.
- [rpic](https://github.com/stephenhu/rpic) lightweight web app and RESTful API for managing a Raspberry Pi
Please note that the API is considered unstable for now and may change without
further notice.

View File

@ -83,9 +83,9 @@ func (conn *Conn) Auth(methods []Auth) error {
}
switch status {
case AuthOk:
err, ok = conn.tryAuth(m, waitingForOk, in)
ok, err = conn.tryAuth(m, waitingForOk, in)
case AuthContinue:
err, ok = conn.tryAuth(m, waitingForData, in)
ok, err = conn.tryAuth(m, waitingForData, in)
default:
panic("dbus: invalid authentication status")
}
@ -125,21 +125,21 @@ func (conn *Conn) Auth(methods []Auth) error {
}
// tryAuth tries to authenticate with m as the mechanism, using state as the
// initial authState and in for reading input. It returns (nil, true) on
// success, (nil, false) on a REJECTED and (someErr, false) if some other
// initial authState and in for reading input. It returns (true, nil) on
// success, (false, nil) on a REJECTED and (false, someErr) if some other
// error occurred.
func (conn *Conn) tryAuth(m Auth, state authState, in *bufio.Reader) (error, bool) {
func (conn *Conn) tryAuth(m Auth, state authState, in *bufio.Reader) (bool, error) {
for {
s, err := authReadLine(in)
if err != nil {
return err, false
return false, err
}
switch {
case state == waitingForData && string(s[0]) == "DATA":
if len(s) != 2 {
err = authWriteLine(conn.transport, []byte("ERROR"))
if err != nil {
return err, false
return false, err
}
continue
}
@ -149,7 +149,7 @@ func (conn *Conn) tryAuth(m Auth, state authState, in *bufio.Reader) (error, boo
if len(data) != 0 {
err = authWriteLine(conn.transport, []byte("DATA"), data)
if err != nil {
return err, false
return false, err
}
}
if status == AuthOk {
@ -158,66 +158,66 @@ func (conn *Conn) tryAuth(m Auth, state authState, in *bufio.Reader) (error, boo
case AuthError:
err = authWriteLine(conn.transport, []byte("ERROR"))
if err != nil {
return err, false
return false, err
}
}
case state == waitingForData && string(s[0]) == "REJECTED":
return nil, false
return false, nil
case state == waitingForData && string(s[0]) == "ERROR":
err = authWriteLine(conn.transport, []byte("CANCEL"))
if err != nil {
return err, false
return false, err
}
state = waitingForReject
case state == waitingForData && string(s[0]) == "OK":
if len(s) != 2 {
err = authWriteLine(conn.transport, []byte("CANCEL"))
if err != nil {
return err, false
return false, err
}
state = waitingForReject
} else {
conn.uuid = string(s[1])
return nil, true
return true, nil
}
case state == waitingForData:
err = authWriteLine(conn.transport, []byte("ERROR"))
if err != nil {
return err, false
return false, err
}
case state == waitingForOk && string(s[0]) == "OK":
if len(s) != 2 {
err = authWriteLine(conn.transport, []byte("CANCEL"))
if err != nil {
return err, false
return false, err
}
state = waitingForReject
} else {
conn.uuid = string(s[1])
return nil, true
return true, nil
}
case state == waitingForOk && string(s[0]) == "DATA":
err = authWriteLine(conn.transport, []byte("DATA"))
if err != nil {
return err, false
return false, nil
}
case state == waitingForOk && string(s[0]) == "REJECTED":
return nil, false
return false, nil
case state == waitingForOk && string(s[0]) == "ERROR":
err = authWriteLine(conn.transport, []byte("CANCEL"))
if err != nil {
return err, false
return false, err
}
state = waitingForReject
case state == waitingForOk:
err = authWriteLine(conn.transport, []byte("ERROR"))
if err != nil {
return err, false
return false, err
}
case state == waitingForReject && string(s[0]) == "REJECTED":
return nil, false
return false, nil
case state == waitingForReject:
return errors.New("dbus: authentication protocol error"), false
return false, errors.New("dbus: authentication protocol error")
default:
panic("dbus: invalid auth state")
}

View File

@ -2,11 +2,8 @@ package dbus
import (
"context"
"errors"
)
var errSignature = errors.New("dbus: mismatched signature")
// Call represents a pending or completed method call.
type Call struct {
Destination string

View File

@ -76,7 +76,6 @@ func SessionBus() (conn *Conn, err error) {
func getSessionBusAddress(autolaunch bool) (string, error) {
if address := os.Getenv("DBUS_SESSION_BUS_ADDRESS"); address != "" && address != "autolaunch:" {
return address, nil
} else if address := tryDiscoverDbusSessionBusAddress(); address != "" {
os.Setenv("DBUS_SESSION_BUS_ADDRESS", address)
return address, nil
@ -630,7 +629,7 @@ func (conn *Conn) AddMatchSignal(options ...MatchOption) error {
// AddMatchSignalContext acts like AddMatchSignal but takes a context.
func (conn *Conn) AddMatchSignalContext(ctx context.Context, options ...MatchOption) error {
options = append([]MatchOption{withMatchType("signal")}, options...)
options = append([]MatchOption{withMatchTypeSignal()}, options...)
return conn.busObj.CallWithContext(
ctx,
"org.freedesktop.DBus.AddMatch", 0,
@ -645,7 +644,7 @@ func (conn *Conn) RemoveMatchSignal(options ...MatchOption) error {
// RemoveMatchSignalContext acts like RemoveMatchSignal but takes a context.
func (conn *Conn) RemoveMatchSignalContext(ctx context.Context, options ...MatchOption) error {
options = append([]MatchOption{withMatchType("signal")}, options...)
options = append([]MatchOption{withMatchTypeSignal()}, options...)
return conn.busObj.CallWithContext(
ctx,
"org.freedesktop.DBus.RemoveMatch", 0,
@ -740,9 +739,7 @@ type transport interface {
SendMessage(*Message) error
}
var (
transports = make(map[string]func(string) (transport, error))
)
var transports = make(map[string]func(string) (transport, error))
func getTransport(address string) (transport, error) {
var err error
@ -853,16 +850,19 @@ type nameTracker struct {
func newNameTracker() *nameTracker {
return &nameTracker{names: map[string]struct{}{}}
}
func (tracker *nameTracker) acquireUniqueConnectionName(name string) {
tracker.lck.Lock()
defer tracker.lck.Unlock()
tracker.unique = name
}
func (tracker *nameTracker) acquireName(name string) {
tracker.lck.Lock()
defer tracker.lck.Unlock()
tracker.names[name] = struct{}{}
}
func (tracker *nameTracker) loseName(name string) {
tracker.lck.Lock()
defer tracker.lck.Unlock()
@ -874,12 +874,14 @@ func (tracker *nameTracker) uniqueNameIsKnown() bool {
defer tracker.lck.RUnlock()
return tracker.unique != ""
}
func (tracker *nameTracker) isKnownName(name string) bool {
tracker.lck.RLock()
defer tracker.lck.RUnlock()
_, ok := tracker.names[name]
return ok || name == tracker.unique
}
func (tracker *nameTracker) listKnownNames() []string {
tracker.lck.RLock()
defer tracker.lck.RUnlock()
@ -941,17 +943,6 @@ func (tracker *callTracker) handleSendError(msg *Message, err error) {
}
}
// finalize was the only func that did not strobe Done
func (tracker *callTracker) finalize(sn uint32) {
tracker.lck.Lock()
defer tracker.lck.Unlock()
c, ok := tracker.calls[sn]
if ok {
delete(tracker.calls, sn)
c.ContextCancel()
}
}
func (tracker *callTracker) finalizeWithBody(sn uint32, sequence Sequence, body []interface{}) {
tracker.lck.Lock()
c, ok := tracker.calls[sn]

View File

@ -12,7 +12,6 @@ const defaultSystemBusAddress = "unix:path=/opt/local/var/run/dbus/system_bus_so
func getSessionBusPlatformAddress() (string, error) {
cmd := exec.Command("launchctl", "getenv", "DBUS_LAUNCHD_SESSION_BUS_SOCKET")
b, err := cmd.CombinedOutput()
if err != nil {
return "", err
}

View File

@ -1,3 +1,4 @@
//go:build !darwin
// +build !darwin
package dbus
@ -19,7 +20,6 @@ var execCommand = exec.Command
func getSessionBusPlatformAddress() (string, error) {
cmd := execCommand("dbus-launch")
b, err := cmd.CombinedOutput()
if err != nil {
return "", err
}

View File

@ -1,3 +1,4 @@
//go:build !windows && !solaris && !darwin
// +build !windows,!solaris,!darwin
package dbus

View File

@ -1,5 +1,3 @@
//+build windows
package dbus
import "os"

View File

@ -10,11 +10,8 @@ import (
var (
byteType = reflect.TypeOf(byte(0))
boolType = reflect.TypeOf(false)
uint8Type = reflect.TypeOf(uint8(0))
int16Type = reflect.TypeOf(int16(0))
uint16Type = reflect.TypeOf(uint16(0))
intType = reflect.TypeOf(int(0))
uintType = reflect.TypeOf(uint(0))
int32Type = reflect.TypeOf(int32(0))
uint32Type = reflect.TypeOf(uint32(0))
int64Type = reflect.TypeOf(int64(0))
@ -334,7 +331,7 @@ func (o ObjectPath) IsValid() bool {
}
// A UnixFD is a Unix file descriptor sent over the wire. See the package-level
// documentation for more information about Unix file descriptor passsing.
// documentation for more information about Unix file descriptor passing.
type UnixFD int32
// A UnixFDIndex is the representation of a Unix file descriptor in a message.

View File

@ -215,10 +215,6 @@ func (obj *exportedObj) LookupMethod(name string) (Method, bool) {
return nil, false
}
func (obj *exportedObj) isFallbackInterface() bool {
return false
}
func newExportedIntf(methods map[string]Method, includeSubtree bool) *exportedIntf {
return &exportedIntf{
methods: methods,

View File

@ -205,9 +205,7 @@ func (conn *Conn) handleCall(msg *Message) {
}
reply.Headers[FieldReplySerial] = MakeVariant(msg.serial)
reply.Body = make([]interface{}, len(ret))
for i := 0; i < len(ret); i++ {
reply.Body[i] = ret[i]
}
copy(reply.Body, ret)
reply.Headers[FieldSignature] = MakeVariant(SignatureOf(reply.Body...))
if err := reply.IsValid(); err != nil {

View File

@ -26,10 +26,10 @@ func WithMatchOption(key, value string) MatchOption {
return MatchOption{key, value}
}
// doesn't make sense to export this option because clients can only
// subscribe to messages with signal type.
func withMatchType(typ string) MatchOption {
return WithMatchOption("type", typ)
// It does not make sense to have a public WithMatchType function
// because clients can only subscribe to messages with signal type.
func withMatchTypeSignal() MatchOption {
return WithMatchOption("type", "signal")
}
// WithMatchSender sets sender match option.

View File

@ -158,7 +158,9 @@ func DecodeMessageWithFDs(rd io.Reader, fds []int) (msg *Message, err error) {
if err != nil {
return nil, err
}
binary.Read(bytes.NewBuffer(b), order, &hlength)
if err := binary.Read(bytes.NewBuffer(b), order, &hlength); err != nil {
return nil, err
}
if hlength+length+16 > 1<<27 {
return nil, InvalidMessageError("message is too long")
}
@ -265,12 +267,14 @@ func (msg *Message) EncodeToWithFDs(out io.Writer, order binary.ByteOrder) (fds
return
}
enc.align(8)
body.WriteTo(&buf)
if _, err := body.WriteTo(&buf); err != nil {
return nil, err
}
if buf.Len() > 1<<27 {
return make([]int, 0), InvalidMessageError("message is too long")
return nil, InvalidMessageError("message is too long")
}
if _, err := buf.WriteTo(out); err != nil {
return make([]int, 0), err
return nil, err
}
return enc.fds, nil
}

View File

@ -46,7 +46,7 @@ func (o *Object) CallWithContext(ctx context.Context, method string, flags Flags
// Deprecated: use (*Conn) AddMatchSignal instead.
func (o *Object) AddMatchSignal(iface, member string, options ...MatchOption) *Call {
base := []MatchOption{
withMatchType("signal"),
withMatchTypeSignal(),
WithMatchInterface(iface),
WithMatchMember(member),
}
@ -65,7 +65,7 @@ func (o *Object) AddMatchSignal(iface, member string, options ...MatchOption) *C
// Deprecated: use (*Conn) RemoveMatchSignal instead.
func (o *Object) RemoveMatchSignal(iface, member string, options ...MatchOption) *Call {
base := []MatchOption{
withMatchType("signal"),
withMatchTypeSignal(),
WithMatchInterface(iface),
WithMatchMember(member),
}

View File

@ -22,7 +22,7 @@ type Handler interface {
// of Interface lookup is up to the implementation of
// the ServerObject. The ServerObject implementation may
// choose to implement empty string as a valid interface
// represeting all methods or not per the D-Bus specification.
// representing all methods or not per the D-Bus specification.
type ServerObject interface {
LookupInterface(name string) (Interface, bool)
}

View File

@ -221,6 +221,9 @@ func validSingle(s string, depth *depthCounter) (err error, rem string) {
i++
rem = s[i+1:]
s = s[2:i]
if len(s) == 0 {
return SignatureError{Sig: s, Reason: "empty dict"}, ""
}
if err, _ = validSingle(s[:1], depth.EnterArray().EnterDictEntry()); err != nil {
return err, ""
}

View File

@ -1,3 +1,4 @@
//go:build !windows
// +build !windows
package dbus

View File

@ -1,3 +1,4 @@
//go:build !windows && !solaris
// +build !windows,!solaris
package dbus
@ -101,8 +102,12 @@ func (t *unixTransport) ReadMessage() (*Message, error) {
}
// csheader[4:8] -> length of message body, csheader[12:16] -> length of
// header fields (without alignment)
binary.Read(bytes.NewBuffer(csheader[4:8]), order, &blen)
binary.Read(bytes.NewBuffer(csheader[12:]), order, &hlen)
if err := binary.Read(bytes.NewBuffer(csheader[4:8]), order, &blen); err != nil {
return nil, err
}
if err := binary.Read(bytes.NewBuffer(csheader[12:]), order, &hlen); err != nil {
return nil, err
}
if hlen%8 != 0 {
hlen += 8 - (hlen % 8)
}
@ -119,7 +124,10 @@ func (t *unixTransport) ReadMessage() (*Message, error) {
if err != nil {
return nil, err
}
Store(vs, &headers)
err = Store(vs, &headers)
if err != nil {
return nil, err
}
for _, v := range headers {
if v.Field == byte(FieldUnixFDs) {
unixfds, _ = v.Variant.value.(uint32)

View File

@ -7,39 +7,41 @@
package dbus
/*
const int sizeofPtr = sizeof(void*);
#define _WANT_UCRED
#include <sys/types.h>
#include <sys/ucred.h>
*/
import "C"
import (
"io"
"os"
"syscall"
"unsafe"
"golang.org/x/sys/unix"
)
// http://golang.org/src/pkg/syscall/ztypes_linux_amd64.go
// https://golang.org/src/syscall/ztypes_freebsd_amd64.go
//
// Note: FreeBSD actually uses a 'struct cmsgcred' which starts with
// these fields and adds a list of the additional groups for the
// sender.
type Ucred struct {
Pid int32
Uid uint32
Euid uint32
Gid uint32
}
// http://golang.org/src/pkg/syscall/types_linux.go
// https://golang.org/src/syscall/types_freebsd.go
// https://github.com/freebsd/freebsd/blob/master/sys/sys/ucred.h
// https://github.com/freebsd/freebsd/blob/master/sys/sys/socket.h
//
// The cmsgcred structure contains the above four fields, followed by
// a uint16 count of additional groups, uint16 padding to align and a
// 16 element array of uint32 for the additional groups. The size is
// the same across all supported platforms.
const (
SizeofUcred = C.sizeof_struct_ucred
SizeofCmsgcred = 84 // 4*4 + 2*2 + 16*4
)
// http://golang.org/src/pkg/syscall/sockcmsg_unix.go
func cmsgAlignOf(salen int) int {
salign := C.sizeofPtr
salign := unix.SizeofPtr
return (salen + salign - 1) & ^(salign - 1)
}
@ -54,11 +56,11 @@ func cmsgData(h *syscall.Cmsghdr) unsafe.Pointer {
// for sending to another process. This can be used for
// authentication.
func UnixCredentials(ucred *Ucred) []byte {
b := make([]byte, syscall.CmsgSpace(SizeofUcred))
b := make([]byte, syscall.CmsgSpace(SizeofCmsgcred))
h := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
h.Level = syscall.SOL_SOCKET
h.Type = syscall.SCM_CREDS
h.SetLen(syscall.CmsgLen(SizeofUcred))
h.SetLen(syscall.CmsgLen(SizeofCmsgcred))
*((*Ucred)(cmsgData(h))) = *ucred
return b
}

View File

@ -417,7 +417,6 @@ func (b boolNode) Value(sig Signature) (interface{}, error) {
type arrayNode struct {
set sigSet
children []varNode
val interface{}
}
func (n arrayNode) Infer() (Signature, error) {
@ -574,7 +573,6 @@ type dictEntry struct {
type dictNode struct {
kset, vset sigSet
children []dictEntry
val interface{}
}
func (n dictNode) Infer() (Signature, error) {

2
vendor/modules.txt vendored
View File

@ -417,7 +417,7 @@ github.com/ghodss/yaml
# github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0
## explicit; go 1.13
github.com/go-task/slim-sprig
# github.com/godbus/dbus/v5 v5.1.0
# github.com/godbus/dbus/v5 v5.1.1-0.20221029134443-4b691ce883d5
## explicit; go 1.12
github.com/godbus/dbus/v5
# github.com/gogo/protobuf v1.3.2