fix using rsync if running sftpgo as non-root user (#1535)

Signed-off-by: Jerome Küttner <j.kuettner@mittwald.de>
This commit is contained in:
JK 2024-04-15 12:52:08 +02:00 committed by GitHub
parent e315e48c39
commit 2bbd8b3a5f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -18,12 +18,14 @@
package sftpd package sftpd
import ( import (
"os"
"os/exec" "os/exec"
"syscall" "syscall"
) )
func wrapCmd(cmd *exec.Cmd, uid, gid int) *exec.Cmd { func wrapCmd(cmd *exec.Cmd, uid, gid int) *exec.Cmd {
if uid > 0 || gid > 0 { isCurrentUser := os.Getuid() == uid && os.Getgid() == gid
if (uid > 0 || gid > 0) && !isCurrentUser {
cmd.SysProcAttr = &syscall.SysProcAttr{} cmd.SysProcAttr = &syscall.SysProcAttr{}
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)} cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)}
} }