remove changing user id first

This commit is contained in:
Hedy Li 2021-08-02 12:46:40 +08:00
parent 274db2f289
commit 87487d3e49
Signed by: hedy
GPG Key ID: B51B5A8D1B176372
1 changed files with 9 additions and 11 deletions

View File

@ -7,11 +7,9 @@ import (
"net"
"os"
"os/exec"
"os/user"
"path/filepath"
"strconv"
"strings"
"syscall"
"time"
)
@ -50,15 +48,15 @@ func handleCGI(conf *Config, req *Request, cgiPath string) (ok bool) {
}
// Manually change the uid/gid for the command, rather than the calling goroutine
// Fetch user info
user, err := user.Lookup(req.user)
if err == nil {
tmp, _ := strconv.ParseUint(user.Uid, 10, 32)
uid := uint32(tmp)
tmp, _ = strconv.ParseUint(user.Gid, 10, 32)
gid := uint32(tmp)
cmd.SysProcAttr = &syscall.SysProcAttr{}
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uid, Gid: gid}
}
// user, err := user.Lookup(req.user)
// if err == nil {
// tmp, _ := strconv.ParseUint(user.Uid, 10, 32)
// uid := uint32(tmp)
// tmp, _ = strconv.ParseUint(user.Gid, 10, 32)
// gid := uint32(tmp)
// cmd.SysProcAttr = &syscall.SysProcAttr{}
// cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uid, Gid: gid}
// }
// Fetch and check output
response, err := cmd.Output()