Ophestra Umiker
1906853382
In the past Wayland, X and PulseAudio are shared unconditionally. This can unnecessarily increase attack surface as some of these resources might not be needed at all. This commit moves all environment preparation code to the internal app package and selectively call them based on flags. An "enablements" bitfield is introduced tracking all enabled shares. This value is registered after successful child process launch and stored in launcher states. Code responsible for running the child process is isolated to its own app/run file and cleaned up. Launch method selection is also extensively cleaned up. The internal state/track readLaunchers function now takes uid as an argument. Launcher state is now printed using text/tabwriter and argv is only emitted when verbose. Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
74 lines
1.6 KiB
Go
74 lines
1.6 KiB
Go
package app
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/base64"
|
|
"encoding/gob"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
"syscall"
|
|
|
|
"git.ophivana.moe/cat/fortify/internal/state"
|
|
"git.ophivana.moe/cat/fortify/internal/util"
|
|
)
|
|
|
|
const launcherPayload = "FORTIFY_LAUNCHER_PAYLOAD"
|
|
|
|
func (a *App) launcherPayloadEnv() string {
|
|
r := &bytes.Buffer{}
|
|
enc := base64.NewEncoder(base64.StdEncoding, r)
|
|
|
|
if err := gob.NewEncoder(enc).Encode(a.command); err != nil {
|
|
state.Fatal("Error encoding launcher payload:", err)
|
|
}
|
|
|
|
_ = enc.Close()
|
|
return launcherPayload + "=" + r.String()
|
|
}
|
|
|
|
// Early hidden launcher path
|
|
func Early(printVersion bool) {
|
|
if printVersion {
|
|
if r, ok := os.LookupEnv(launcherPayload); ok {
|
|
dec := base64.NewDecoder(base64.StdEncoding, strings.NewReader(r))
|
|
|
|
var argv []string
|
|
if err := gob.NewDecoder(dec).Decode(&argv); err != nil {
|
|
fmt.Println("Error decoding launcher payload:", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
if err := os.Unsetenv(launcherPayload); err != nil {
|
|
fmt.Println("Error unsetting launcher payload:", err)
|
|
// not fatal, do not fail
|
|
}
|
|
|
|
var p string
|
|
|
|
if len(argv) > 0 {
|
|
if p, ok = util.Which(argv[0]); !ok {
|
|
fmt.Printf("Did not find '%s' in PATH\n", argv[0])
|
|
os.Exit(1)
|
|
}
|
|
} else {
|
|
if p, ok = os.LookupEnv("SHELL"); !ok {
|
|
fmt.Println("No command was specified and $SHELL was unset")
|
|
os.Exit(1)
|
|
}
|
|
|
|
argv = []string{p}
|
|
}
|
|
|
|
if err := syscall.Exec(p, argv, os.Environ()); err != nil {
|
|
fmt.Println("Error executing launcher payload:", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
// unreachable
|
|
os.Exit(1)
|
|
return
|
|
}
|
|
}
|
|
}
|