From 35b714231768d11b82e575701ca5c7a081e2c542 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Wed, 1 Jan 2025 19:28:58 +0900 Subject: fortify: show system info when instance is not specified This contains useful information not obtainable by external tools. Signed-off-by: Ophestra --- print.go | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'print.go') diff --git a/print.go b/print.go index 702f35ea..e78861fa 100644 --- a/print.go +++ b/print.go @@ -16,14 +16,37 @@ import ( "git.gensokyo.uk/security/fortify/internal/state" ) -func printShow(instance *state.State, config *fst.Config, short bool) { +func printShowSystem(short bool) { + info := new(fst.Info) + + // get fid by querying uid of aid 0 + if uid, err := os.Uid(0); err != nil { + fmsg.Fatalf("cannot obtain uid from fsu: %v", err) + } else { + info.User = (uid / 10000) - 100 + } + + if flagJSON { + printJSON(info) + return + } + + w := tabwriter.NewWriter(direct.Stdout, 0, 1, 4, ' ', 0) + + fmt.Fprintf(w, "User:\t%d\n", info.User) + + if err := w.Flush(); err != nil { + fmsg.Fatalf("cannot flush tabwriter: %v", err) + } +} + +func printShowInstance(instance *state.State, config *fst.Config, short bool) { if flagJSON { - v := any(config) if instance != nil { - v = instance + printJSON(instance) + } else { + printJSON(config) } - - printJSON(v) return } -- cgit v1.3.1