1
0

Moved substituting user to a func for upload.

This commit is contained in:
Alexander Andreev 2022-02-07 22:04:00 +04:00
parent f3685c999e
commit 38ec161ae9
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 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 {
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() { func main() {
flag.Parse() flag.Parse()
@ -26,23 +46,10 @@ func main() {
log.Fatalln(err) log.Fatalln(err)
} }
// Substitute user to the one in config if err := substituteUser(config.User); err != nil {
dwu, err := user.Lookup(config.User)
if err != nil {
log.Fatalln(err) 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 { if *logToStdout {
config.Log.ToStdout = true config.Log.ToStdout = true
} }