fortify: show system info when instance is not specified
All checks were successful
Tests / Go tests (push) Successful in 38s
Nix / NixOS tests (push) Successful in 4m32s

This contains useful information not obtainable by external tools.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2025-01-01 19:28:58 +09:00
parent c4d6651cae
commit 35b7142317
3 changed files with 46 additions and 23 deletions

View File

@@ -16,14 +16,37 @@ import (
"git.gensokyo.uk/security/fortify/internal/state"
)
func printShow(instance *state.State, config *fst.Config, short bool) {
if flagJSON {
v := any(config)
if instance != nil {
v = instance
}
func printShowSystem(short bool) {
info := new(fst.Info)
printJSON(v)
// 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 {
if instance != nil {
printJSON(instance)
} else {
printJSON(config)
}
return
}