mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 06:05:06 +03:00
Revert "Omit privileged setgroups(2) call to test set[ug]id(2) to same user"
3283407897 (step)
:5:19 shows that it works on Linux, so undo the hack. This reverts commit12acd710be
.
This commit is contained in:
parent
12acd710be
commit
6cdf74ca98
2 changed files with 10 additions and 8 deletions
|
@ -12,7 +12,7 @@ import (
|
|||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func chuser(input string, skipSetgroupsForTests ...any) error {
|
||||
func chuser(input string) error {
|
||||
givenUser, givenGroup, _ := strings.Cut(input, ":")
|
||||
|
||||
var (
|
||||
|
@ -43,10 +43,8 @@ func chuser(input string, skipSetgroupsForTests ...any) error {
|
|||
gid, _ = strconv.Atoi(usr.Gid)
|
||||
}
|
||||
|
||||
if len(skipSetgroupsForTests) == 0 {
|
||||
if err := unix.Setgroups([]int{gid}); err != nil {
|
||||
return fmt.Errorf("setgroups: %d: %v", gid, err)
|
||||
}
|
||||
if err := unix.Setgroups([]int{gid}); err != nil {
|
||||
return fmt.Errorf("setgroups: %d: %v", gid, err)
|
||||
}
|
||||
if err := unix.Setgid(gid); err != nil {
|
||||
return fmt.Errorf("setgid: %d: %v", gid, err)
|
||||
|
|
|
@ -44,14 +44,18 @@ func TestInvalidUserid (t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// Change to the current user by username and group ID.
|
||||
func TestCurrentUser (t *testing.T) {
|
||||
// Change to the current user by ID.
|
||||
func TestCurrentUserid (t *testing.T) {
|
||||
usr, err := user.Current()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err = chuser(usr.Username + ":" + usr.Gid, true /* skipSetGroupsForTests */); err != nil {
|
||||
if usr.Uid != "0" {
|
||||
t.Skip("setgroups(2): Only the superuser may set new groups.")
|
||||
}
|
||||
|
||||
if err = chuser(usr.Uid); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue