summaryrefslogtreecommitdiff
path: root/osutil/isolate.go
diff options
context:
space:
mode:
Diffstat (limited to 'osutil/isolate.go')
-rw-r--r--osutil/isolate.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/osutil/isolate.go b/osutil/isolate.go
index d4b64fb6..387df905 100644
--- a/osutil/isolate.go
+++ b/osutil/isolate.go
@@ -4,6 +4,8 @@ package osutil
import (
"os/exec"
+ "os/user"
+ "strconv"
"syscall"
)
@@ -11,3 +13,27 @@ import (
func IsolateProcess(cmd *exec.Cmd) {
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true, Pgid: 0}
}
+
+func ExecuteFromUser(cmd *exec.Cmd, u string) error {
+ usr, err := user.Lookup(u)
+ if err != nil {
+ return err
+ }
+
+ usrI32, err := strconv.Atoi(usr.Uid)
+ if err != nil {
+ return err
+ }
+
+ grI32, err := strconv.Atoi(usr.Gid)
+ if err != nil {
+ return err
+ }
+
+ cmd.SysProcAttr.Credential = &syscall.Credential{
+ Uid: uint32(usrI32),
+ Gid: uint32(grI32),
+ }
+
+ return nil
+}