Skip to content

Commit

Permalink
Remove duplicate id ranges returned by getsubu/gid for username/uid
Browse files Browse the repository at this point in the history
  • Loading branch information
i-do-cpp committed May 28, 2023
1 parent 0aa2657 commit bbc1b27
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pkg/parent/dynidtools/dynidtools.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ import (
"github.com/sirupsen/logrus"
)

func withoutDuplicates[T idtools.SubIDRange](sliceList []T) []T {
seenKeys := make(map[T]bool)
var list []T
for _, item := range sliceList {
if _, value := seenKeys[item]; !value {
seenKeys[item] = true
list = append(list, item)
}
}
return list
}

func GetSubIDRanges(uid int, username string) ([]idtools.SubIDRange, []idtools.SubIDRange, error) {
getsubidsExeName := "getsubids"
if v := os.Getenv("GETSUBIDS"); v != "" {
Expand Down Expand Up @@ -52,8 +64,8 @@ func GetSubIDRanges(uid int, username string) ([]idtools.SubIDRange, []idtools.S
}
}

u := append(uByUsername, uByUID...)
g := append(gByUsername, gByUID...)
u := withoutDuplicates(append(uByUsername, uByUID...))
g := withoutDuplicates(append(gByUsername, gByUID...))
return u, g, nil
}

Expand Down

0 comments on commit bbc1b27

Please sign in to comment.