From b616f4e8634a677829a60f06f2834789cf84ce3d Mon Sep 17 00:00:00 2001 From: Christopher Swenson Date: Mon, 5 Dec 2022 09:47:09 -0800 Subject: [PATCH] Add additional notes about users and groups --- client.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/client.go b/client.go index 3778a390..33bc85a5 100644 --- a/client.go +++ b/client.go @@ -18,12 +18,14 @@ import ( "net" "os" "os/exec" + "os/user" "path/filepath" "runtime" "strconv" "strings" "sync" "sync/atomic" + "syscall" "time" "github.com/hashicorp/go-hclog" @@ -507,6 +509,27 @@ func additionalNotesAboutCommand(path string) string { notes += "\nAdditional notes about plugin:\n" notes += fmt.Sprintf(" Path: %s\n", path) notes += fmt.Sprintf(" Mode: %s\n", stat.Mode()) + statT, ok := stat.Sys().(*syscall.Stat_t) + if ok { + currentUsername := "?" + if u, err := user.LookupId(strconv.FormatUint(uint64(os.Getuid()), 10)); err == nil { + currentUsername = u.Username + } + currentGroup := "?" + if g, err := user.LookupGroupId(strconv.FormatUint(uint64(os.Getgid()), 10)); err == nil { + currentGroup = g.Name + } + username := "?" + if u, err := user.LookupId(strconv.FormatUint(uint64(statT.Uid), 10)); err == nil { + username = u.Username + } + group := "?" + if g, err := user.LookupGroupId(strconv.FormatUint(uint64(statT.Gid), 10)); err == nil { + group = g.Name + } + notes += fmt.Sprintf(" Owner: %d [%s] (current: %d [%s])\n", statT.Uid, username, os.Getuid(), currentUsername) + notes += fmt.Sprintf(" Group: %d [%s] (current: %d [%s])\n", statT.Gid, group, os.Getgid(), currentGroup) + } if elfFile, err := elf.Open(path); err == nil { notes += fmt.Sprintf(" ELF architecture: %s (current architecture: %s)\n", elfFile.Machine, runtime.GOARCH)