vendor github.com/godbus/dbus/v5@4b691ce

This pulls in https://github.com/godbus/dbus/pull/332 allowing dbus to
build without cgo on FreeBSD. This will allow freebsd targets in the cross
build.

[NO NEW TESTS NEEDED]

Signed-off-by: Doug Rabson <dfr@rabson.org>
This commit is contained in:
Doug Rabson
2022-10-29 16:03:29 +01:00
parent a263069568
commit 0d505f20ff
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/docker/go-units v0.5.0
github.com/fsnotify/fsnotify v1.6.0 github.com/fsnotify/fsnotify v1.6.0
github.com/ghodss/yaml v1.0.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/gofuzz v1.2.0
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/google/uuid v1.3.0 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 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.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/godbus/dbus/v5 v5.0.4/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.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.2.0/go.mod h1:Njal3psf3qN6dwBtQfUmBZh2ybovJ0tlu3o/AC7HYjU=
github.com/gogo/googleapis v1.4.0/go.mod h1:5YRNX2z1oM5gXdAkurHa942MDgEJyk02w4OecKY87+c= 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= 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-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-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-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-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-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220909162455-aba9fc2a8ff2/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". - [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. - [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. - [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 Please note that the API is considered unstable for now and may change without
further notice. further notice.

View File

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

View File

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

View File

@ -76,7 +76,6 @@ func SessionBus() (conn *Conn, err error) {
func getSessionBusAddress(autolaunch bool) (string, error) { func getSessionBusAddress(autolaunch bool) (string, error) {
if address := os.Getenv("DBUS_SESSION_BUS_ADDRESS"); address != "" && address != "autolaunch:" { if address := os.Getenv("DBUS_SESSION_BUS_ADDRESS"); address != "" && address != "autolaunch:" {
return address, nil return address, nil
} else if address := tryDiscoverDbusSessionBusAddress(); address != "" { } else if address := tryDiscoverDbusSessionBusAddress(); address != "" {
os.Setenv("DBUS_SESSION_BUS_ADDRESS", address) os.Setenv("DBUS_SESSION_BUS_ADDRESS", address)
return address, nil return address, nil
@ -630,7 +629,7 @@ func (conn *Conn) AddMatchSignal(options ...MatchOption) error {
// AddMatchSignalContext acts like AddMatchSignal but takes a context. // AddMatchSignalContext acts like AddMatchSignal but takes a context.
func (conn *Conn) AddMatchSignalContext(ctx context.Context, options ...MatchOption) error { 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( return conn.busObj.CallWithContext(
ctx, ctx,
"org.freedesktop.DBus.AddMatch", 0, "org.freedesktop.DBus.AddMatch", 0,
@ -645,7 +644,7 @@ func (conn *Conn) RemoveMatchSignal(options ...MatchOption) error {
// RemoveMatchSignalContext acts like RemoveMatchSignal but takes a context. // RemoveMatchSignalContext acts like RemoveMatchSignal but takes a context.
func (conn *Conn) RemoveMatchSignalContext(ctx context.Context, options ...MatchOption) error { 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( return conn.busObj.CallWithContext(
ctx, ctx,
"org.freedesktop.DBus.RemoveMatch", 0, "org.freedesktop.DBus.RemoveMatch", 0,
@ -740,9 +739,7 @@ type transport interface {
SendMessage(*Message) error SendMessage(*Message) error
} }
var ( var transports = make(map[string]func(string) (transport, error))
transports = make(map[string]func(string) (transport, error))
)
func getTransport(address string) (transport, error) { func getTransport(address string) (transport, error) {
var err error var err error
@ -853,16 +850,19 @@ type nameTracker struct {
func newNameTracker() *nameTracker { func newNameTracker() *nameTracker {
return &nameTracker{names: map[string]struct{}{}} return &nameTracker{names: map[string]struct{}{}}
} }
func (tracker *nameTracker) acquireUniqueConnectionName(name string) { func (tracker *nameTracker) acquireUniqueConnectionName(name string) {
tracker.lck.Lock() tracker.lck.Lock()
defer tracker.lck.Unlock() defer tracker.lck.Unlock()
tracker.unique = name tracker.unique = name
} }
func (tracker *nameTracker) acquireName(name string) { func (tracker *nameTracker) acquireName(name string) {
tracker.lck.Lock() tracker.lck.Lock()
defer tracker.lck.Unlock() defer tracker.lck.Unlock()
tracker.names[name] = struct{}{} tracker.names[name] = struct{}{}
} }
func (tracker *nameTracker) loseName(name string) { func (tracker *nameTracker) loseName(name string) {
tracker.lck.Lock() tracker.lck.Lock()
defer tracker.lck.Unlock() defer tracker.lck.Unlock()
@ -874,12 +874,14 @@ func (tracker *nameTracker) uniqueNameIsKnown() bool {
defer tracker.lck.RUnlock() defer tracker.lck.RUnlock()
return tracker.unique != "" return tracker.unique != ""
} }
func (tracker *nameTracker) isKnownName(name string) bool { func (tracker *nameTracker) isKnownName(name string) bool {
tracker.lck.RLock() tracker.lck.RLock()
defer tracker.lck.RUnlock() defer tracker.lck.RUnlock()
_, ok := tracker.names[name] _, ok := tracker.names[name]
return ok || name == tracker.unique return ok || name == tracker.unique
} }
func (tracker *nameTracker) listKnownNames() []string { func (tracker *nameTracker) listKnownNames() []string {
tracker.lck.RLock() tracker.lck.RLock()
defer tracker.lck.RUnlock() 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{}) { func (tracker *callTracker) finalizeWithBody(sn uint32, sequence Sequence, body []interface{}) {
tracker.lck.Lock() tracker.lck.Lock()
c, ok := tracker.calls[sn] 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) { func getSessionBusPlatformAddress() (string, error) {
cmd := exec.Command("launchctl", "getenv", "DBUS_LAUNCHD_SESSION_BUS_SOCKET") cmd := exec.Command("launchctl", "getenv", "DBUS_LAUNCHD_SESSION_BUS_SOCKET")
b, err := cmd.CombinedOutput() b, err := cmd.CombinedOutput()
if err != nil { if err != nil {
return "", err return "", err
} }

View File

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

View File

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

View File

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

View File

@ -10,11 +10,8 @@ import (
var ( var (
byteType = reflect.TypeOf(byte(0)) byteType = reflect.TypeOf(byte(0))
boolType = reflect.TypeOf(false) boolType = reflect.TypeOf(false)
uint8Type = reflect.TypeOf(uint8(0))
int16Type = reflect.TypeOf(int16(0)) int16Type = reflect.TypeOf(int16(0))
uint16Type = reflect.TypeOf(uint16(0)) uint16Type = reflect.TypeOf(uint16(0))
intType = reflect.TypeOf(int(0))
uintType = reflect.TypeOf(uint(0))
int32Type = reflect.TypeOf(int32(0)) int32Type = reflect.TypeOf(int32(0))
uint32Type = reflect.TypeOf(uint32(0)) uint32Type = reflect.TypeOf(uint32(0))
int64Type = reflect.TypeOf(int64(0)) int64Type = reflect.TypeOf(int64(0))
@ -85,7 +82,7 @@ func storeBase(dest, src reflect.Value) error {
func setDest(dest, src reflect.Value) error { func setDest(dest, src reflect.Value) error {
if !isVariant(src.Type()) && isVariant(dest.Type()) { if !isVariant(src.Type()) && isVariant(dest.Type()) {
//special conversion for dbus.Variant // special conversion for dbus.Variant
dest.Set(reflect.ValueOf(MakeVariant(src.Interface()))) dest.Set(reflect.ValueOf(MakeVariant(src.Interface())))
return nil return nil
} }
@ -166,8 +163,8 @@ func storeMapIntoVariant(dest, src reflect.Value) error {
func storeMapIntoInterface(dest, src reflect.Value) error { func storeMapIntoInterface(dest, src reflect.Value) error {
var dv reflect.Value var dv reflect.Value
if isVariant(src.Type().Elem()) { if isVariant(src.Type().Elem()) {
//Convert variants to interface{} recursively when converting // Convert variants to interface{} recursively when converting
//to interface{} // to interface{}
dv = reflect.MakeMap( dv = reflect.MakeMap(
reflect.MapOf(src.Type().Key(), interfaceType)) reflect.MapOf(src.Type().Key(), interfaceType))
} else { } else {
@ -200,7 +197,7 @@ func storeMapIntoMap(dest, src reflect.Value) error {
func storeSlice(dest, src reflect.Value) error { func storeSlice(dest, src reflect.Value) error {
switch { switch {
case src.Type() == interfacesType && dest.Kind() == reflect.Struct: case src.Type() == interfacesType && dest.Kind() == reflect.Struct:
//The decoder always decodes structs as slices of interface{} // The decoder always decodes structs as slices of interface{}
return storeStruct(dest, src) return storeStruct(dest, src)
case !kindsAreCompatible(dest.Type(), src.Type()): case !kindsAreCompatible(dest.Type(), src.Type()):
return fmt.Errorf( return fmt.Errorf(
@ -260,8 +257,8 @@ func storeSliceIntoVariant(dest, src reflect.Value) error {
func storeSliceIntoInterface(dest, src reflect.Value) error { func storeSliceIntoInterface(dest, src reflect.Value) error {
var dv reflect.Value var dv reflect.Value
if isVariant(src.Type().Elem()) { if isVariant(src.Type().Elem()) {
//Convert variants to interface{} recursively when converting // Convert variants to interface{} recursively when converting
//to interface{} // to interface{}
dv = reflect.MakeSlice(reflect.SliceOf(interfaceType), dv = reflect.MakeSlice(reflect.SliceOf(interfaceType),
src.Len(), src.Cap()) src.Len(), src.Cap())
} else { } else {
@ -334,7 +331,7 @@ func (o ObjectPath) IsValid() bool {
} }
// A UnixFD is a Unix file descriptor sent over the wire. See the package-level // 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 type UnixFD int32
// A UnixFDIndex is the representation of a Unix file descriptor in a message. // A UnixFDIndex is the representation of a Unix file descriptor in a message.

View File

@ -205,9 +205,9 @@ func (dec *decoder) decode(s string, depth int) interface{} {
// Even for empty arrays, the correct padding must be included // Even for empty arrays, the correct padding must be included
align := alignment(typeFor(s[1:])) align := alignment(typeFor(s[1:]))
if len(s) > 1 && s[1] == '(' { if len(s) > 1 && s[1] == '(' {
//Special case for arrays of structs // Special case for arrays of structs
//structs decode as a slice of interface{} values // structs decode as a slice of interface{} values
//but the dbus alignment does not match this // but the dbus alignment does not match this
align = 8 align = 8
} }
dec.align(align) dec.align(align)

View File

@ -148,7 +148,7 @@ func (m exportedMethod) Call(args ...interface{}) ([]interface{}, error) {
out[i] = val.Interface() out[i] = val.Interface()
} }
if nilErr || err == nil { if nilErr || err == nil {
//concrete type to interface nil is a special case // concrete type to interface nil is a special case
return out, nil return out, nil
} }
return out, err return out, err
@ -215,10 +215,6 @@ func (obj *exportedObj) LookupMethod(name string) (Method, bool) {
return nil, false return nil, false
} }
func (obj *exportedObj) isFallbackInterface() bool {
return false
}
func newExportedIntf(methods map[string]Method, includeSubtree bool) *exportedIntf { func newExportedIntf(methods map[string]Method, includeSubtree bool) *exportedIntf {
return &exportedIntf{ return &exportedIntf{
methods: methods, methods: methods,

View File

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

View File

@ -26,10 +26,10 @@ func WithMatchOption(key, value string) MatchOption {
return MatchOption{key, value} return MatchOption{key, value}
} }
// doesn't make sense to export this option because clients can only // It does not make sense to have a public WithMatchType function
// subscribe to messages with signal type. // because clients can only subscribe to messages with signal type.
func withMatchType(typ string) MatchOption { func withMatchTypeSignal() MatchOption {
return WithMatchOption("type", typ) return WithMatchOption("type", "signal")
} }
// WithMatchSender sets sender match option. // 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 { if err != nil {
return nil, err 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 { if hlength+length+16 > 1<<27 {
return nil, InvalidMessageError("message is too long") return nil, InvalidMessageError("message is too long")
} }
@ -265,12 +267,14 @@ func (msg *Message) EncodeToWithFDs(out io.Writer, order binary.ByteOrder) (fds
return return
} }
enc.align(8) enc.align(8)
body.WriteTo(&buf) if _, err := body.WriteTo(&buf); err != nil {
return nil, err
}
if buf.Len() > 1<<27 { 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 { if _, err := buf.WriteTo(out); err != nil {
return make([]int, 0), err return nil, err
} }
return enc.fds, nil 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. // Deprecated: use (*Conn) AddMatchSignal instead.
func (o *Object) AddMatchSignal(iface, member string, options ...MatchOption) *Call { func (o *Object) AddMatchSignal(iface, member string, options ...MatchOption) *Call {
base := []MatchOption{ base := []MatchOption{
withMatchType("signal"), withMatchTypeSignal(),
WithMatchInterface(iface), WithMatchInterface(iface),
WithMatchMember(member), WithMatchMember(member),
} }
@ -65,7 +65,7 @@ func (o *Object) AddMatchSignal(iface, member string, options ...MatchOption) *C
// Deprecated: use (*Conn) RemoveMatchSignal instead. // Deprecated: use (*Conn) RemoveMatchSignal instead.
func (o *Object) RemoveMatchSignal(iface, member string, options ...MatchOption) *Call { func (o *Object) RemoveMatchSignal(iface, member string, options ...MatchOption) *Call {
base := []MatchOption{ base := []MatchOption{
withMatchType("signal"), withMatchTypeSignal(),
WithMatchInterface(iface), WithMatchInterface(iface),
WithMatchMember(member), WithMatchMember(member),
} }

View File

@ -93,7 +93,7 @@ func (scd *sequentialSignalChannelData) bufferSignals() {
var queue []*Signal var queue []*Signal
for { for {
if len(queue) == 0 { if len(queue) == 0 {
signal, ok := <- scd.in signal, ok := <-scd.in
if !ok { if !ok {
return return
} }

View File

@ -22,7 +22,7 @@ type Handler interface {
// of Interface lookup is up to the implementation of // of Interface lookup is up to the implementation of
// the ServerObject. The ServerObject implementation may // the ServerObject. The ServerObject implementation may
// choose to implement empty string as a valid interface // 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 { type ServerObject interface {
LookupInterface(name string) (Interface, bool) LookupInterface(name string) (Interface, bool)
} }

View File

@ -221,6 +221,9 @@ func validSingle(s string, depth *depthCounter) (err error, rem string) {
i++ i++
rem = s[i+1:] rem = s[i+1:]
s = s[2:i] 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 { if err, _ = validSingle(s[:1], depth.EnterArray().EnterDictEntry()); err != nil {
return err, "" return err, ""
} }

View File

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

View File

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

View File

@ -7,39 +7,41 @@
package dbus package dbus
/*
const int sizeofPtr = sizeof(void*);
#define _WANT_UCRED
#include <sys/types.h>
#include <sys/ucred.h>
*/
import "C"
import ( import (
"io" "io"
"os" "os"
"syscall" "syscall"
"unsafe" "unsafe"
"golang.org/x/sys/unix"
) )
// http://golang.org/src/pkg/syscall/ztypes_linux_amd64.go // http://golang.org/src/pkg/syscall/ztypes_linux_amd64.go
// https://golang.org/src/syscall/ztypes_freebsd_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 { type Ucred struct {
Pid int32 Pid int32
Uid uint32 Uid uint32
Gid uint32 Euid uint32
Gid uint32
} }
// http://golang.org/src/pkg/syscall/types_linux.go // https://github.com/freebsd/freebsd/blob/master/sys/sys/socket.h
// https://golang.org/src/syscall/types_freebsd.go //
// https://github.com/freebsd/freebsd/blob/master/sys/sys/ucred.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 ( const (
SizeofUcred = C.sizeof_struct_ucred SizeofCmsgcred = 84 // 4*4 + 2*2 + 16*4
) )
// http://golang.org/src/pkg/syscall/sockcmsg_unix.go // http://golang.org/src/pkg/syscall/sockcmsg_unix.go
func cmsgAlignOf(salen int) int { func cmsgAlignOf(salen int) int {
salign := C.sizeofPtr salign := unix.SizeofPtr
return (salen + salign - 1) & ^(salign - 1) 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 // for sending to another process. This can be used for
// authentication. // authentication.
func UnixCredentials(ucred *Ucred) []byte { 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 := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
h.Level = syscall.SOL_SOCKET h.Level = syscall.SOL_SOCKET
h.Type = syscall.SCM_CREDS h.Type = syscall.SCM_CREDS
h.SetLen(syscall.CmsgLen(SizeofUcred)) h.SetLen(syscall.CmsgLen(SizeofCmsgcred))
*((*Ucred)(cmsgData(h))) = *ucred *((*Ucred)(cmsgData(h))) = *ucred
return b return b
} }

View File

@ -417,7 +417,6 @@ func (b boolNode) Value(sig Signature) (interface{}, error) {
type arrayNode struct { type arrayNode struct {
set sigSet set sigSet
children []varNode children []varNode
val interface{}
} }
func (n arrayNode) Infer() (Signature, error) { func (n arrayNode) Infer() (Signature, error) {
@ -574,7 +573,6 @@ type dictEntry struct {
type dictNode struct { type dictNode struct {
kset, vset sigSet kset, vset sigSet
children []dictEntry children []dictEntry
val interface{}
} }
func (n dictNode) Infer() (Signature, error) { 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 # github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0
## explicit; go 1.13 ## explicit; go 1.13
github.com/go-task/slim-sprig 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 ## explicit; go 1.12
github.com/godbus/dbus/v5 github.com/godbus/dbus/v5
# github.com/gogo/protobuf v1.3.2 # github.com/gogo/protobuf v1.3.2