1
0

Removed user substituting and chrooting. It must be made within systemd unit file.

This commit is contained in:
Alexander Andreev 2022-03-29 18:12:37 +04:00
parent f7d2618c8c
commit c60b403e00
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F

View File

@ -8,36 +8,13 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"os" "os"
"os/user"
"path" "path"
"strconv"
"syscall"
"time" "time"
) )
var configPath *string = flag.String("conf", "config.yaml", "path to configuration file") var configPath *string = flag.String("conf", "config.yaml", "path to configuration file")
var logToStdout *bool = flag.Bool("log-stdout", false, "write logs to stdout") var logToStdout *bool = flag.Bool("log-stdout", false, "write logs to stdout")
func substituteUser(username string) error {
u, err := user.Lookup(username)
if err != nil {
return err
}
uid, err := strconv.Atoi(u.Uid)
if err != nil {
return err
}
if os.Getuid() != uid {
if err := syscall.Setuid(uid); err != nil {
return err
}
}
return nil
}
func main() { func main() {
flag.Parse() flag.Parse()
@ -46,16 +23,6 @@ func main() {
log.Fatalln(err) log.Fatalln(err)
} }
if config.Chroot != "" {
if err := syscall.Chroot(config.Chroot); err != nil {
log.Fatalln("failed to chroot:", err)
}
}
if err := substituteUser(config.User); err != nil {
log.Fatalln(err)
}
if *logToStdout { if *logToStdout {
config.Log.ToStdout = true config.Log.ToStdout = true
} }