shim: get rid of insane launch condition

Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
This commit is contained in:
Ophestra Umiker 2024-10-13 12:09:38 +09:00
parent e4536b87ad
commit b470941911
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q
5 changed files with 16 additions and 15 deletions

View File

@ -57,8 +57,8 @@ func (a *app) commandBuilderMachineCtl(shimEnv string) (args []string) {
} }
} }
// both license and version flags need to be set to activate shim path // launch fortify as shim
innerCommand.WriteString("exec " + a.seal.sys.executable + " -V -license") innerCommand.WriteString("exec " + a.seal.sys.executable + " shim")
// append inner command // append inner command
args = append(args, innerCommand.String()) args = append(args, innerCommand.String())

View File

@ -26,7 +26,7 @@ func (a *app) commandBuilderSudo(shimEnv string) (args []string) {
args = append(args, shimEnv) args = append(args, shimEnv)
// -- $@ // -- $@
args = append(args, "--", a.seal.sys.executable, "-V", "--license") // magic for shim.Try() args = append(args, "--", a.seal.sys.executable, "shim")
return return
} }

View File

@ -3,6 +3,7 @@ package shim
import ( import (
"encoding/gob" "encoding/gob"
"errors" "errors"
"flag"
"fmt" "fmt"
"net" "net"
"os" "os"
@ -148,3 +149,13 @@ func receiveWLfd(conn *net.UnixConn) (int, error) {
return fds[0], nil return fds[0], nil
} }
} }
// Try runs shim and stops execution if FORTIFY_SHIM is set.
func Try() {
if args := flag.Args(); len(args) == 1 && args[0] == "shim" {
if s, ok := os.LookupEnv(EnvShim); ok {
shim(s)
panic("unreachable")
}
}
}

View File

@ -80,11 +80,3 @@ func ServeConfig(socket string, payload *Payload, wl string, done chan struct{})
return ws, nil return ws, nil
} }
} }
// Try runs shim and stops execution if FORTIFY_SHIM is set.
func Try() {
if s, ok := os.LookupEnv(EnvShim); ok {
shim(s)
}
panic("unreachable")
}

View File

@ -35,10 +35,8 @@ func main() {
verbose.Println("system booted with systemd as init system") verbose.Println("system booted with systemd as init system")
} }
// launcher payload early exit // shim early exit
if printVersion && printLicense { shim.Try()
shim.Try()
}
// version/license/template command early exit // version/license/template command early exit
tryVersion() tryVersion()