2024-09-22 00:29:36 +09:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"path"
|
|
|
|
|
2024-10-20 19:50:13 +09:00
|
|
|
"git.ophivana.moe/security/fortify/acl"
|
2024-10-23 21:46:21 +09:00
|
|
|
"git.ophivana.moe/security/fortify/internal"
|
2024-10-20 19:50:13 +09:00
|
|
|
"git.ophivana.moe/security/fortify/internal/fmsg"
|
|
|
|
"git.ophivana.moe/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-10-23 21:46:21 +09:00
|
|
|
func (seal *appSeal) shareDisplay(os internal.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-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-10-20 22:54:47 +09:00
|
|
|
} else if seal.wl == nil {
|
2024-10-10 12:44:08 +09:00
|
|
|
// hardlink wayland socket
|
2024-09-22 00:29:36 +09:00
|
|
|
wp := path.Join(seal.RuntimePath, wd)
|
2024-10-10 12:44:08 +09:00
|
|
|
wpi := path.Join(seal.shareLocal, "wayland")
|
2024-10-11 04:18:15 +09:00
|
|
|
w := path.Join(seal.sys.runtime, "wayland-0")
|
2024-10-16 01:38:59 +09:00
|
|
|
seal.sys.Link(wp, wpi)
|
|
|
|
seal.sys.bwrap.SetEnv[waylandDisplay] = w
|
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-10-20 22:54:47 +09:00
|
|
|
// set wayland socket path for mediation (e.g. `/run/user/%d/wayland-%d`)
|
|
|
|
seal.wl.Path = path.Join(seal.RuntimePath, wd)
|
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-10-16 01:38:59 +09:00
|
|
|
seal.sys.ChangeHosts(seal.sys.user.Username)
|
|
|
|
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
|
|
|
|
}
|