aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/app/share.dbus.go
blob: c80bbb92f2316d18f1446cf0da9731f94d575a9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package app

import (
	"path"

	"git.ophivana.moe/security/fortify/acl"
	"git.ophivana.moe/security/fortify/dbus"
	"git.ophivana.moe/security/fortify/internal/system"
)

const (
	dbusSessionBusAddress = "DBUS_SESSION_BUS_ADDRESS"
	dbusSystemBusAddress  = "DBUS_SYSTEM_BUS_ADDRESS"
)

func (seal *appSeal) shareDBus(config [2]*dbus.Config) error {
	if !seal.et.Has(system.EDBus) {
		return nil
	}

	// downstream socket paths
	sessionPath, systemPath := path.Join(seal.share, "bus"), path.Join(seal.share, "system_bus_socket")

	// configure dbus proxy
	if f, err := seal.sys.ProxyDBus(config[0], config[1], sessionPath, systemPath); err != nil {
		return err
	} else {
		seal.dbusMsg = f
	}

	// share proxy sockets
	sessionInner := path.Join(seal.sys.runtime, "bus")
	seal.sys.bwrap.SetEnv[dbusSessionBusAddress] = "unix:path=" + sessionInner
	seal.sys.bwrap.Bind(sessionPath, sessionInner)
	seal.sys.UpdatePerm(sessionPath, acl.Read, acl.Write)
	if config[1] != nil {
		systemInner := "/run/dbus/system_bus_socket"
		seal.sys.bwrap.SetEnv[dbusSystemBusAddress] = "unix:path=" + systemInner
		seal.sys.bwrap.Bind(systemPath, systemInner)
		seal.sys.UpdatePerm(systemPath, acl.Read, acl.Write)
	}

	return nil
}