Skip to content

Commit

Permalink
Merge pull request #127 from mrunalp/update_user
Browse files Browse the repository at this point in the history
Pick latest changes to libcontainer/user package
  • Loading branch information
rhatdan committed Oct 10, 2015
2 parents bb472f0 + 60cabaf commit 8ecdb44
Show file tree
Hide file tree
Showing 2 changed files with 494 additions and 17 deletions.
39 changes: 22 additions & 17 deletions vendor/src/github.com/opencontainers/runc/libcontainer/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,21 +349,26 @@ func GetExecUser(userSpec string, defaults *ExecUser, passwd, group io.Reader) (
return user, nil
}

// GetAdditionalGroups looks up a list of groups by name or group id against
// against the given /etc/group formatted data. If a group name cannot be found,
// an error will be returned. If a group id cannot be found, it will be returned
// as-is.
// GetAdditionalGroups looks up a list of groups by name or group id
// against the given /etc/group formatted data. If a group name cannot
// be found, an error will be returned. If a group id cannot be found,
// or the given group data is nil, the id will be returned as-is
// provided it is in the legal range.
func GetAdditionalGroups(additionalGroups []string, group io.Reader) ([]int, error) {
groups, err := ParseGroupFilter(group, func(g Group) bool {
for _, ag := range additionalGroups {
if g.Name == ag || strconv.Itoa(g.Gid) == ag {
return true
var groups = []Group{}
if group != nil {
var err error
groups, err = ParseGroupFilter(group, func(g Group) bool {
for _, ag := range additionalGroups {
if g.Name == ag || strconv.Itoa(g.Gid) == ag {
return true
}
}
return false
})
if err != nil {
return nil, fmt.Errorf("Unable to find additional groups %v: %v", additionalGroups, err)
}
return false
})
if err != nil {
return nil, fmt.Errorf("Unable to find additional groups %v: %v", additionalGroups, err)
}

gidMap := make(map[int]struct{})
Expand Down Expand Up @@ -401,13 +406,13 @@ func GetAdditionalGroups(additionalGroups []string, group io.Reader) ([]int, err
return gids, nil
}

// Wrapper around GetAdditionalGroups that opens the groupPath given and gives
// it as an argument to GetAdditionalGroups.
// GetAdditionalGroupsPath is a wrapper around GetAdditionalGroups
// that opens the groupPath given and gives it as an argument to
// GetAdditionalGroups.
func GetAdditionalGroupsPath(additionalGroups []string, groupPath string) ([]int, error) {
group, err := os.Open(groupPath)
if err != nil {
return nil, fmt.Errorf("Failed to open group file: %v", err)
if err == nil {
defer group.Close()
}
defer group.Close()
return GetAdditionalGroups(additionalGroups, group)
}
Loading

0 comments on commit 8ecdb44

Please sign in to comment.