aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra Umiker <cat@ophivana.moe>2024-11-05 12:57:03 +0900
committerOphestra Umiker <cat@ophivana.moe>2024-11-05 12:57:03 +0900
commit89bafd0c229afe15bf4f9d78cd49bfcb1f765030 (patch)
treeeac9cabb0224a967fb1b95c1eae6cdcd29e278ec
parent861bb1274febf985e205dc96c9c895d3beff3527 (diff)
fortify: root check before command handling
Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
-rw-r--r--main.go13
1 files changed, 6 insertions, 7 deletions
diff --git a/main.go b/main.go
index b8bb0916..1e3e2ee3 100644
--- a/main.go
+++ b/main.go
@@ -35,6 +35,11 @@ func main() {
// not fatal: this program runs as the privileged user
}
+ if os.Geteuid() == 0 {
+ fmsg.Fatal("this program must not run as root")
+ panic("unreachable")
+ }
+
flag.CommandLine.Usage = func() {
fmt.Println()
fmt.Println("Usage:\tfortify [-v] COMMAND [OPTIONS]")
@@ -54,19 +59,13 @@ func main() {
_, _ = fmt.Fprintf(w, "\t%s\t%s\n", c[0], c[1])
}
if err := w.Flush(); err != nil {
- fmsg.Fatalf("cannot print help: %v", err)
+ fmt.Printf("fortify: cannot write command list: %v\n", err)
}
fmt.Println()
}
flag.Parse()
fmsg.SetVerbose(flagVerbose)
- // root check
- if os.Geteuid() == 0 {
- fmsg.Fatal("this program must not run as root")
- panic("unreachable")
- }
-
args := flag.Args()
if len(args) == 0 {
flag.CommandLine.Usage()