pkg/utils: Add function to get the name of the sudoers group
https://github.com/containers/toolbox/pull/318
This commit is contained in:
parent
188c92c76e
commit
31f1b741c0
1 changed files with 19 additions and 0 deletions
|
@ -21,6 +21,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
"sort"
|
||||
"syscall"
|
||||
|
||||
|
@ -127,6 +128,24 @@ func GetEnvOptionsForPreservedVariables() []string {
|
|||
return envOptions
|
||||
}
|
||||
|
||||
// GetGroupForSudo returns the name of the sudoers group.
|
||||
//
|
||||
// Some distros call it 'sudo' (eg. Ubuntu) and some call it 'wheel' (eg. Fedora).
|
||||
func GetGroupForSudo() (string, error) {
|
||||
logrus.Debug("Looking up group for sudo")
|
||||
|
||||
groups := []string{"sudo", "wheel"}
|
||||
|
||||
for _, group := range groups {
|
||||
if _, err := user.LookupGroup(group); err == nil {
|
||||
logrus.Debugf("Group for sudo is %s", group)
|
||||
return group, nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", errors.New("group for sudo not found")
|
||||
}
|
||||
|
||||
// ShortID shortens provided id to first 12 characters.
|
||||
func ShortID(id string) string {
|
||||
if len(id) > idTruncLength {
|
||||
|
|
Loading…
Reference in a new issue