mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-29 14:45:07 +03:00
move setuid/setgid into separate functions in platform-dependent files
This commit is contained in:
parent
70b9274ddc
commit
b299d7e36b
3 changed files with 36 additions and 4 deletions
|
@ -376,12 +376,18 @@ func run(args yggArgs, ctx context.Context, done chan struct{}) {
|
|||
// Lower permissions from root to something else, if the user wants to
|
||||
if syscall.Getuid() == 0 {
|
||||
if args.rungid > 0 {
|
||||
fmt.Println("Dropping gid to ", args.rungid)
|
||||
syscall.Setgid(args.rungid)
|
||||
logger.Infoln("Setting gid to:", args.rungid)
|
||||
if err := setgid(args.rungid); err != nil {
|
||||
logger.Errorln("Failed to set gid:", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
if args.runuid > 0 {
|
||||
fmt.Println("Dropping uid to ", args.rungid)
|
||||
syscall.Setuid(args.runuid)
|
||||
logger.Infoln("Setting uid to:", args.runuid)
|
||||
if err := setuid(args.runuid); err != nil {
|
||||
logger.Errorln("Failed to set uid:", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.Infof("Your public key is %s", hex.EncodeToString(public[:]))
|
||||
|
|
13
cmd/yggdrasil/setids_other.go
Normal file
13
cmd/yggdrasil/setids_other.go
Normal file
|
@ -0,0 +1,13 @@
|
|||
// +build !linux,!darwin,!freebsd,!openbsd
|
||||
|
||||
package main
|
||||
|
||||
import "errors"
|
||||
|
||||
func setuid(uid int) error {
|
||||
return errors.New("setting uid not supported on this platform")
|
||||
}
|
||||
|
||||
func setgid(gid int) error {
|
||||
return errors.New("setting gid not supported on this platform")
|
||||
}
|
13
cmd/yggdrasil/setids_posix.go
Normal file
13
cmd/yggdrasil/setids_posix.go
Normal file
|
@ -0,0 +1,13 @@
|
|||
// +build linux darwin freebsd openbsd
|
||||
|
||||
package main
|
||||
|
||||
import "syscall"
|
||||
|
||||
func setuid(uid int) error {
|
||||
return syscall.Setuid(uid)
|
||||
}
|
||||
|
||||
func setgid(gid int) error {
|
||||
return syscall.Setgid(gid)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue