Moved substituting user to a func for upload.
This commit is contained in:
parent
f3685c999e
commit
38ec161ae9
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user