2024-09-22 00:29:36 +09:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"path"
|
|
|
|
|
2024-12-20 00:20:02 +09:00
|
|
|
"git.gensokyo.uk/security/fortify/acl"
|
|
|
|
"git.gensokyo.uk/security/fortify/internal/fmsg"
|
|
|
|
"git.gensokyo.uk/security/fortify/internal/linux"
|
|
|
|
"git.gensokyo.uk/security/fortify/internal/system"
|
2024-09-22 00:29:36 +09:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
term = "TERM"
|
|
|
|
display = "DISPLAY"
|
|
|
|
|
|
|
|
// https://manpages.debian.org/experimental/libwayland-doc/wl_display_connect.3.en.html
|
|
|
|
waylandDisplay = "WAYLAND_DISPLAY"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
ErrWayland = errors.New(waylandDisplay + " unset")
|
|
|
|
ErrXDisplay = errors.New(display + " unset")
|
|
|
|
)
|
|
|
|
|
2024-11-02 03:03:44 +09:00
|
|
|
func (seal *appSeal) shareDisplay(os linux.System) error {
|
2024-09-22 00:29:36 +09:00
|
|
|
// pass $TERM to launcher
|
|
|
|
if t, ok := os.LookupEnv(term); ok {
|
2024-10-16 01:38:59 +09:00
|
|
|
seal.sys.bwrap.SetEnv[term] = t
|
2024-09-22 00:29:36 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// set up wayland
|
2024-10-16 14:38:57 +09:00
|
|
|
if seal.et.Has(system.EWayland) {
|
2024-12-06 04:25:33 +09:00
|
|
|
var wp string
|
2024-09-22 00:29:36 +09:00
|
|
|
if wd, ok := os.LookupEnv(waylandDisplay); !ok {
|
2024-10-16 01:38:59 +09:00
|
|
|
return fmsg.WrapError(ErrWayland,
|
|
|
|
"WAYLAND_DISPLAY is not set")
|
2024-12-06 04:25:33 +09:00
|
|
|
} else {
|
|
|
|
wp = path.Join(seal.RuntimePath, wd)
|
|
|
|
}
|
|
|
|
|
|
|
|
w := path.Join(seal.sys.runtime, "wayland-0")
|
|
|
|
seal.sys.bwrap.SetEnv[waylandDisplay] = w
|
|
|
|
|
|
|
|
if seal.directWayland {
|
2024-10-10 12:44:08 +09:00
|
|
|
// hardlink wayland socket
|
|
|
|
wpi := path.Join(seal.shareLocal, "wayland")
|
2024-10-16 01:38:59 +09:00
|
|
|
seal.sys.Link(wp, wpi)
|
2024-10-15 02:15:55 +09:00
|
|
|
seal.sys.bwrap.Bind(wpi, w)
|
2024-09-22 00:29:36 +09:00
|
|
|
|
|
|
|
// ensure Wayland socket ACL (e.g. `/run/user/%d/wayland-%d`)
|
2024-10-16 14:38:57 +09:00
|
|
|
seal.sys.UpdatePermType(system.EWayland, wp, acl.Read, acl.Write, acl.Execute)
|
2024-10-11 02:01:03 +09:00
|
|
|
} else {
|
2024-12-06 04:25:33 +09:00
|
|
|
wc := path.Join(seal.SharePath, "wayland")
|
|
|
|
wt := path.Join(wc, seal.id)
|
|
|
|
seal.sys.Ensure(wc, 0711)
|
|
|
|
appID := seal.fid
|
|
|
|
if appID == "" {
|
|
|
|
// use instance ID in case app id is not set
|
|
|
|
appID = "moe.ophivana.fortify." + seal.id
|
|
|
|
}
|
|
|
|
seal.sys.Wayland(wt, wp, appID, seal.id)
|
|
|
|
seal.sys.bwrap.Bind(wt, w)
|
2024-09-22 00:29:36 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// set up X11
|
2024-10-16 14:38:57 +09:00
|
|
|
if seal.et.Has(system.EX11) {
|
2024-09-22 00:29:36 +09:00
|
|
|
// discover X11 and grant user permission via the `ChangeHosts` command
|
|
|
|
if d, ok := os.LookupEnv(display); !ok {
|
2024-10-16 01:38:59 +09:00
|
|
|
return fmsg.WrapError(ErrXDisplay,
|
|
|
|
"DISPLAY is not set")
|
2024-09-22 00:29:36 +09:00
|
|
|
} else {
|
2024-11-17 23:40:37 +09:00
|
|
|
seal.sys.ChangeHosts("#" + seal.sys.user.us)
|
2024-10-16 01:38:59 +09:00
|
|
|
seal.sys.bwrap.SetEnv[display] = d
|
2024-10-15 02:15:55 +09:00
|
|
|
seal.sys.bwrap.Bind("/tmp/.X11-unix", "/tmp/.X11-unix")
|
2024-09-22 00:29:36 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|