1
0

Moved substituting user to a func for upload-clear.

This commit is contained in:
Alexander Andreev 2022-02-07 22:04:40 +04:00
parent 38ec161ae9
commit ed3b0080a3
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F

View File

@ -18,6 +18,26 @@ import (
var configPath *string = flag.String("conf", "config.yaml", "path to configuration file")
var logToStdout *bool = flag.Bool("log-stdout", false, "write logs to stdout")
func substituteUser(username string) error {
dwu, err := user.Lookup(username)
if err != nil {
return err
}
dwuid, err := strconv.Atoi(dwu.Uid)
if err != nil {
return err
}
if os.Getuid() != dwuid {
if err := syscall.Setuid(dwuid); err != nil {
return err
}
}
return nil
}
func main() {
flag.Parse()
@ -26,23 +46,10 @@ func main() {
log.Fatalln(err)
}
// Substitute user to the one in config
dwu, err := user.Lookup(config.User)
if err != nil {
if err := substituteUser(config.User); err != nil {
log.Fatalln(err)
}
dwuid, err := strconv.Atoi(dwu.Uid)
if err != nil {
log.Fatalln(err)
}
if os.Getuid() != dwuid {
if err := syscall.Setuid(dwuid); err != nil {
log.Fatalln(err)
}
}
if *logToStdout {
config.Log.ToStdout = true
}