Skip to content

Commit

Permalink
Add shell attribute to User (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
aelsabbahy committed Jun 9, 2016
1 parent 917b0aa commit 8662b7c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 5 deletions.
3 changes: 2 additions & 1 deletion integration-tests/goss/centos6/goss-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
"groups": [
"apache"
],
"home": "/var/www"
"home": "/var/www",
"shell": "/sbin/nologin"
},
"foobar": {
"exists": false
Expand Down
3 changes: 2 additions & 1 deletion integration-tests/goss/precise/goss-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
"groups": [
"www-data"
],
"home": "/var/www"
"home": "/var/www",
"shell": "/bin/sh"
}
},
"group": {
Expand Down
3 changes: 2 additions & 1 deletion integration-tests/goss/wheezy/goss-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
"groups": [
"www-data"
],
"home": "/var/www"
"home": "/var/www",
"shell": "/bin/sh"
}
},
"group": {
Expand Down
9 changes: 9 additions & 0 deletions resource/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type User struct {
GID matcher `json:"gid,omitempty" yaml:"gid,omitempty"`
Groups matcher `json:"groups,omitempty" yaml:"groups,omitempty"`
Home matcher `json:"home,omitempty" yaml:"home,omitempty"`
Shell matcher `json:"shell,omitempty" yaml:"shell,omitempty"`
}

func (u *User) ID() string { return u.Username }
Expand Down Expand Up @@ -45,6 +46,9 @@ func (u *User) Validate(sys *system.System) []TestResult {
if u.Groups != nil {
results = append(results, ValidateValue(u, "groups", u.Groups, sysuser.Groups))
}
if u.Shell != nil {
results = append(results, ValidateValue(u, "shell", u.Shell, sysuser.Shell))
}

return results
}
Expand Down Expand Up @@ -76,5 +80,10 @@ func NewUser(sysUser system.User, config util.Config) (*User, error) {
u.Home = home
}
}
if !contains(config.IgnoreList, "shell") {
if shell, err := sysUser.Shell(); err == nil {
u.Shell = shell
}
}
return u, nil
}
4 changes: 2 additions & 2 deletions system/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ type System struct {
NewProcess func(string, *System, util2.Config) Process
NewGossfile func(string, *System, util2.Config) Gossfile
dbus *dbus.Conn
ports map[string][]GOnetstat.Process
dbusOnce sync.Once
ports map[string][]GOnetstat.Process
portsOnce sync.Once
procOnce sync.Once
procMap map[string][]ps.Process
procOnce sync.Once
}

func (s *System) Ports() map[string][]GOnetstat.Process {
Expand Down
10 changes: 10 additions & 0 deletions system/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type User interface {
GID() (int, error)
Groups() ([]string, error)
Home() (string, error)
Shell() (string, error)
}

type DefUser struct {
Expand Down Expand Up @@ -64,6 +65,15 @@ func (u *DefUser) Home() (string, error) {
return user.Home, nil
}

func (u *DefUser) Shell() (string, error) {
user, err := user.LookupUser(u.username)
if err != nil {
return "", err
}

return user.Shell, nil
}

func (u *DefUser) Groups() ([]string, error) {
user, err := user.LookupUser(u.username)
if err != nil {
Expand Down

0 comments on commit 8662b7c

Please sign in to comment.