forked from AdguardTeam/AdGuardHome
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull request: all: support setgid, setuid on unix
Updates AdguardTeam#2763. Squashed commit of the following: commit bd2077c Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Fri Jun 4 16:25:17 2021 +0300 all: move rlimit_nofile, imp docs commit ba95d4a Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Fri Jun 4 15:12:23 2021 +0300 all: support setgid, setuid on unix
- Loading branch information
Showing
14 changed files
with
283 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package aghos | ||
|
||
// SetGroup sets the effective group ID of the calling process. | ||
func SetGroup(groupName string) (err error) { | ||
return setGroup(groupName) | ||
} | ||
|
||
// SetUser sets the effective user ID of the calling process. | ||
func SetUser(userName string) (err error) { | ||
return setUser(userName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// +build darwin freebsd linux netbsd openbsd | ||
|
||
//go:build darwin || freebsd || linux || netbsd || openbsd | ||
|
||
package aghos | ||
|
||
import ( | ||
"fmt" | ||
"os/user" | ||
"strconv" | ||
"syscall" | ||
) | ||
|
||
func setGroup(groupName string) (err error) { | ||
g, err := user.LookupGroup(groupName) | ||
if err != nil { | ||
return fmt.Errorf("looking up group: %w", err) | ||
} | ||
|
||
gid, err := strconv.Atoi(g.Gid) | ||
if err != nil { | ||
return fmt.Errorf("parsing gid: %w", err) | ||
} | ||
|
||
err = syscall.Setgid(gid) | ||
if err != nil { | ||
return fmt.Errorf("setting gid: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func setUser(userName string) (err error) { | ||
u, err := user.Lookup(userName) | ||
if err != nil { | ||
return fmt.Errorf("looking up user: %w", err) | ||
} | ||
|
||
uid, err := strconv.Atoi(u.Uid) | ||
if err != nil { | ||
return fmt.Errorf("parsing uid: %w", err) | ||
} | ||
|
||
err = syscall.Setuid(uid) | ||
if err != nil { | ||
return fmt.Errorf("setting uid: %w", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// +build windows | ||
|
||
//go:build windows | ||
|
||
package aghos | ||
|
||
// TODO(a.garipov): Think of a way to implement these. Perhaps by using | ||
// syscall.CreateProcessAsUser or something from the golang.org/x/sys module. | ||
|
||
func setGroup(_ string) (err error) { | ||
return Unsupported("setgid") | ||
} | ||
|
||
func setUser(_ string) (err error) { | ||
return Unsupported("setuid") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
// +build windows | ||
|
||
//go:build windows | ||
|
||
package dhcpd | ||
|
||
import "fmt" | ||
import "github.com/AdguardTeam/AdGuardHome/internal/aghos" | ||
|
||
func CheckIfOtherDHCPServersPresentV4(ifaceName string) (bool, error) { | ||
return false, fmt.Errorf("not supported") | ||
return false, aghos.Unsupported("CheckIfOtherDHCPServersPresentV4") | ||
} | ||
|
||
func CheckIfOtherDHCPServersPresentV6(ifaceName string) (bool, error) { | ||
return false, fmt.Errorf("not supported") | ||
return false, aghos.Unsupported("CheckIfOtherDHCPServersPresentV6") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
// +build windows | ||
|
||
//go:build windows | ||
|
||
package dhcpd | ||
|
||
import ( | ||
"net" | ||
|
||
"github.com/AdguardTeam/golibs/errors" | ||
"github.com/AdguardTeam/AdGuardHome/internal/aghos" | ||
"golang.org/x/net/ipv4" | ||
) | ||
|
||
// Create a socket for receiving broadcast packets | ||
func newBroadcastPacketConn(bindAddr net.IP, port int, ifname string) (*ipv4.PacketConn, error) { | ||
return nil, errors.Error("newBroadcastPacketConn(): not supported on Windows") | ||
func newBroadcastPacketConn(_ net.IP, _ int, _ string) (*ipv4.PacketConn, error) { | ||
return nil, aghos.Unsupported("newBroadcastPacketConn") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.