fortify: show system info when instance is not specified
This contains useful information not obtainable by external tools. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
c4d6651cae
commit
35b7142317
5
fst/info.go
Normal file
5
fst/info.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package fst
|
||||||
|
|
||||||
|
type Info struct {
|
||||||
|
User int `json:"user"`
|
||||||
|
}
|
27
main.go
27
main.go
@ -16,7 +16,6 @@ import (
|
|||||||
"git.gensokyo.uk/security/fortify/internal/app"
|
"git.gensokyo.uk/security/fortify/internal/app"
|
||||||
"git.gensokyo.uk/security/fortify/internal/fmsg"
|
"git.gensokyo.uk/security/fortify/internal/fmsg"
|
||||||
"git.gensokyo.uk/security/fortify/internal/linux"
|
"git.gensokyo.uk/security/fortify/internal/linux"
|
||||||
"git.gensokyo.uk/security/fortify/internal/state"
|
|
||||||
"git.gensokyo.uk/security/fortify/internal/system"
|
"git.gensokyo.uk/security/fortify/internal/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -128,24 +127,20 @@ func main() {
|
|||||||
// Ignore errors; set is set for ExitOnError.
|
// Ignore errors; set is set for ExitOnError.
|
||||||
_ = set.Parse(args[1:])
|
_ = set.Parse(args[1:])
|
||||||
|
|
||||||
var (
|
switch len(set.Args()) {
|
||||||
config *fst.Config
|
case 0: // system
|
||||||
instance *state.State
|
printShowSystem(short)
|
||||||
name string
|
case 1: // instance
|
||||||
)
|
name := set.Args()[0]
|
||||||
|
config, instance := tryShort(name)
|
||||||
if len(set.Args()) != 1 {
|
if config == nil {
|
||||||
|
config = tryPath(name)
|
||||||
|
}
|
||||||
|
printShowInstance(instance, config, short)
|
||||||
|
default:
|
||||||
fmsg.Fatal("show requires 1 argument")
|
fmsg.Fatal("show requires 1 argument")
|
||||||
} else {
|
|
||||||
name = set.Args()[0]
|
|
||||||
config, instance = tryShort(name)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if config == nil {
|
|
||||||
config = tryPath(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
printShow(instance, config, short)
|
|
||||||
fmsg.Exit(0)
|
fmsg.Exit(0)
|
||||||
case "app": // launch app from configuration file
|
case "app": // launch app from configuration file
|
||||||
if len(args) < 2 {
|
if len(args) < 2 {
|
||||||
|
37
print.go
37
print.go
@ -16,14 +16,37 @@ import (
|
|||||||
"git.gensokyo.uk/security/fortify/internal/state"
|
"git.gensokyo.uk/security/fortify/internal/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
func printShow(instance *state.State, config *fst.Config, short bool) {
|
func printShowSystem(short bool) {
|
||||||
if flagJSON {
|
info := new(fst.Info)
|
||||||
v := any(config)
|
|
||||||
if instance != nil {
|
|
||||||
v = instance
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user