aboutsummaryrefslogtreecommitdiffhomepage
path: root/cmd/fshim/ipc/payload.go
blob: 1aaddb1fc574a346be7d5814935da719cb4cd215 (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
package shim0

import (
	"encoding/gob"
	"errors"
	"net"

	"git.ophivana.moe/security/fortify/helper/bwrap"
	"git.ophivana.moe/security/fortify/internal/fmsg"
)

const Env = "FORTIFY_SHIM"

type Payload struct {
	// child full argv
	Argv []string
	// bwrap, target full exec path
	Exec [2]string
	// bwrap config
	Bwrap *bwrap.Config
	// whether to pass wayland fd
	WL bool

	// verbosity pass through
	Verbose bool
}

func (p *Payload) Serve(conn *net.UnixConn, wl *Wayland) error {
	if err := gob.NewEncoder(conn).Encode(*p); err != nil {
		return fmsg.WrapErrorSuffix(err,
			"cannot stream shim payload:")
	}

	if wl != nil {
		if err := wl.WriteUnix(conn); err != nil {
			return errors.Join(err, conn.Close())
		}
	}

	return fmsg.WrapErrorSuffix(conn.Close(),
		"cannot close setup connection:")
}