summaryrefslogtreecommitdiff
path: root/osutil
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-04-15 20:16:46 +0300
committerValery Piashchynski <[email protected]>2020-04-15 20:16:46 +0300
commit6625950ac6f382f6a46bc52bf17908ef13bdc429 (patch)
tree486bdfd86f8f1c0a269cd9dfdf46c1f73943524e /osutil
parentcc9c74665a9cabcfb006ab6b7a9beafb95ff7316 (diff)
Add user to worker
Diffstat (limited to 'osutil')
-rw-r--r--osutil/isolate.go26
-rw-r--r--osutil/isolate_win.go2
2 files changed, 27 insertions, 1 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
+}
diff --git a/osutil/isolate_win.go b/osutil/isolate_win.go
index ca7fca20..4a965f42 100644
--- a/osutil/isolate_win.go
+++ b/osutil/isolate_win.go
@@ -10,4 +10,4 @@ import (
// IsolateProcess change gpid for the process to avoid bypassing signals to php processes.
func IsolateProcess(cmd *exec.Cmd) {
cmd.SysProcAttr = &syscall.SysProcAttr{CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP}
-}
+} \ No newline at end of file