repeater/internal/wifi/wpasupplicant/network.go
Pierre-Olivier Mercier 11ae69de56 wpasupplicant: Disable D-Bus auto-activation on all calls
Every method call and property access to fi.w1.wpa_supplicant1 used flag
0, leaving D-Bus service activation enabled. Any stray request — a startup
race before `service wpa_supplicant start` takes effect, or a leaked call
while the Ethernet uplink is the chosen path — would make the bus daemon
spawn `wpa_supplicant -u` from its .service file, bypassing repeater's own
launch of the daemon.

Route every interaction through callNoAutoStart/getPropNoAutoStart/
setPropNoAutoStart, which set dbus.FlagNoAutoStart. A leaked call now fails
cleanly with ServiceUnknown instead of resurrecting the daemon, leaving
repeater as the sole launcher.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 11:44:59 +08:00

65 lines
1.3 KiB
Go

package wpasupplicant
import (
"strings"
"github.com/godbus/dbus/v5"
)
// Network represents a wpa_supplicant Network configuration object
type Network struct {
path dbus.ObjectPath
conn *dbus.Conn
obj dbus.BusObject
}
// NewNetwork creates a new Network instance
func NewNetwork(conn *dbus.Conn, path dbus.ObjectPath) *Network {
return &Network{
path: path,
conn: conn,
obj: conn.Object(Service, path),
}
}
// GetPath returns the D-Bus object path for this network
func (n *Network) GetPath() dbus.ObjectPath {
return n.path
}
// GetProperties returns properties of the network configuration
func (n *Network) GetProperties() (map[string]dbus.Variant, error) {
prop, err := getPropNoAutoStart(n.obj, NetworkInterface+".Properties")
if err != nil {
return nil, err
}
props, ok := prop.Value().(map[string]dbus.Variant)
if !ok {
return nil, nil
}
return props, nil
}
// GetSSID returns the configured SSID, stripping the wrapping quotes
// that wpa_supplicant stores around string-form SSIDs.
func (n *Network) GetSSID() (string, error) {
props, err := n.GetProperties()
if err != nil {
return "", err
}
ssidVariant, ok := props["ssid"]
if !ok {
return "", nil
}
ssid, ok := ssidVariant.Value().(string)
if !ok {
return "", nil
}
// wpa_supplicant returns quoted SSIDs like "MyNetwork"
return strings.Trim(ssid, `"`), nil
}