hst/dbus: validate interface strings
All checks were successful
Test / Create distribution (push) Successful in 33s
Test / Sandbox (push) Successful in 2m12s
Test / Hakurei (push) Successful in 3m3s
Test / Hpkg (push) Successful in 3m58s
Test / Sandbox (race detector) (push) Successful in 4m24s
Test / Hakurei (race detector) (push) Successful in 5m11s
Test / Flake checks (push) Successful in 1m22s
All checks were successful
Test / Create distribution (push) Successful in 33s
Test / Sandbox (push) Successful in 2m12s
Test / Hakurei (push) Successful in 3m3s
Test / Hpkg (push) Successful in 3m58s
Test / Sandbox (race detector) (push) Successful in 4m24s
Test / Hakurei (race detector) (push) Successful in 5m11s
Test / Flake checks (push) Successful in 1m22s
This is relocated to hst to validate early. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
92
hst/dbus.go
92
hst/dbus.go
@@ -1,5 +1,27 @@
|
||||
package hst
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// BadInterfaceError is returned when Interface fails an undocumented check in xdg-dbus-proxy,
|
||||
// which would have cause a silent failure.
|
||||
type BadInterfaceError struct {
|
||||
// Interface is the offending interface string.
|
||||
Interface string
|
||||
// Segment is passed through from the [BusConfig.CheckInterfaces] argument.
|
||||
Segment string
|
||||
}
|
||||
|
||||
func (e *BadInterfaceError) Message() string { return e.Error() }
|
||||
func (e *BadInterfaceError) Error() string {
|
||||
if e == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return "bad interface string " + strconv.Quote(e.Interface) + " in " + e.Segment + " bus configuration"
|
||||
}
|
||||
|
||||
// BusConfig configures the xdg-dbus-proxy process.
|
||||
type BusConfig struct {
|
||||
// See set 'see' policy for NAME (--see=NAME)
|
||||
@@ -14,6 +36,74 @@ type BusConfig struct {
|
||||
// Broadcast set RULE for broadcasts from NAME (--broadcast=NAME=RULE)
|
||||
Broadcast map[string]string `json:"broadcast"`
|
||||
|
||||
Log bool `json:"log,omitempty"`
|
||||
// Log turn on logging (--log)
|
||||
Log bool `json:"log,omitempty"`
|
||||
// Filter enable filtering (--filter)
|
||||
Filter bool `json:"filter"`
|
||||
}
|
||||
|
||||
// Interfaces iterates over all interface strings specified in [BusConfig].
|
||||
func (c *BusConfig) Interfaces(yield func(string) bool) {
|
||||
if c == nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, iface := range c.See {
|
||||
if !yield(iface) {
|
||||
return
|
||||
}
|
||||
}
|
||||
for _, iface := range c.Talk {
|
||||
if !yield(iface) {
|
||||
return
|
||||
}
|
||||
}
|
||||
for _, iface := range c.Own {
|
||||
if !yield(iface) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
for iface := range c.Call {
|
||||
if !yield(iface) {
|
||||
return
|
||||
}
|
||||
}
|
||||
for iface := range c.Broadcast {
|
||||
if !yield(iface) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CheckInterfaces checks for invalid interface strings based on an undocumented check in xdg-dbus-error,
|
||||
// returning [BadInterfaceError] if one is encountered.
|
||||
func (c *BusConfig) CheckInterfaces(segment string) error {
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
for iface := range c.Interfaces {
|
||||
/*
|
||||
xdg-dbus-proxy fails without output when this condition is not met:
|
||||
char *dot = strrchr (filter->interface, '.');
|
||||
if (dot != NULL)
|
||||
{
|
||||
*dot = 0;
|
||||
if (strcmp (dot + 1, "*") != 0)
|
||||
filter->member = g_strdup (dot + 1);
|
||||
}
|
||||
|
||||
trim ".*" since they are removed before searching for '.':
|
||||
if (g_str_has_suffix (name, ".*"))
|
||||
{
|
||||
name[strlen (name) - 2] = 0;
|
||||
wildcard = TRUE;
|
||||
}
|
||||
*/
|
||||
if strings.IndexByte(strings.TrimSuffix(iface, ".*"), '.') == -1 {
|
||||
return &BadInterfaceError{iface, segment}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user