Skip to content

Commit

Permalink
Small changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Wurm committed Jan 2, 2019
1 parent 6a87627 commit 1c14de4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
19 changes: 12 additions & 7 deletions providers/windows/process_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ import (
"github.com/pkg/errors"
syswin "golang.org/x/sys/windows"

"github.com/elastic/go-sysinfo/types"
windows "github.com/elastic/go-windows"

"github.com/elastic/go-sysinfo/types"
)

var (
Expand Down Expand Up @@ -244,30 +245,34 @@ func (p *process) Info() (types.ProcessInfo, error) {
func (p *process) User() (types.UserInfo, error) {
handle, err := p.open()
if err != nil {
return types.UserInfo{}, err
return types.UserInfo{}, errors.Wrap(err, "OpenProcess failed")
}
defer syscall.CloseHandle(handle)

var accessToken syswin.Token
syswin.OpenProcessToken(syswin.Handle(handle), syscall.TOKEN_QUERY, &accessToken)
err = syswin.OpenProcessToken(syswin.Handle(handle), syscall.TOKEN_QUERY, &accessToken)
if err != nil {
return types.UserInfo{}, errors.Wrap(err, "OpenProcessToken failed")
}
defer accessToken.Close()

tokenUser, err := accessToken.GetTokenUser()
if err != nil {
return types.UserInfo{}, errors.Wrapf(err, "GetTokenUser failed for PID %v", p.pid)
return types.UserInfo{}, errors.Wrap(err, "GetTokenUser failed")
}

sid, err := tokenUser.User.Sid.String()
if err != nil {
return types.UserInfo{}, errors.Wrapf(err, "failed to look up user SID for PID %v", p.pid)
return types.UserInfo{}, errors.Wrap(err, "failed to look up user SID")
}

tokenGroup, err := accessToken.GetTokenPrimaryGroup()
if err != nil {
return types.UserInfo{}, errors.Wrapf(err, "GetTokenPrimaryGroup failed for PID %v", p.pid)
return types.UserInfo{}, errors.Wrap(err, "GetTokenPrimaryGroup failed")
}
gsid, err := tokenGroup.PrimaryGroup.String()
if err != nil {
return types.UserInfo{}, errors.Wrapf(err, "failed to look up primary group SID for PID %v", p.pid)
return types.UserInfo{}, errors.Wrap(err, "failed to look up primary group SID")
}

return types.UserInfo{
Expand Down
6 changes: 4 additions & 2 deletions types/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ type ProcessInfo struct {
type UserInfo struct {
// Uid is the user ID.
// On Linux and Darwin (macOS) this is the real user ID.
// On Windows, this is a security identifier (SID).
// On Windows, this is the security identifier (SID) of the
// user account of the process access token.
Uid string `json:"uid"`

// On Linux and Darwin (macOS) this is the effective user ID.
Expand All @@ -54,7 +55,8 @@ type UserInfo struct {

// Gid is the primary group ID.
// On Linux and Darwin (macOS) this is the real group ID.
// On Windows, this is a security identifier (SID).
// On Windows, this is the security identifier (SID) of the
// primary group of the process access token.
Gid string `json:"gid"`

// On Linux and Darwin (macOS) this is the effective group ID.
Expand Down

0 comments on commit 1c14de4

Please sign in to comment.