forked from tildetown/town
double validate username
parent
e5cf8a5521
commit
21e51a829f
|
@ -32,11 +32,20 @@ func quit(msg string) {
|
|||
}
|
||||
|
||||
func main() {
|
||||
username := os.Args[1]
|
||||
if username == "" {
|
||||
quit("expected username as argument")
|
||||
}
|
||||
|
||||
u, err := user.Current()
|
||||
if err != nil {
|
||||
quit(err.Error())
|
||||
}
|
||||
|
||||
if u.Username != username {
|
||||
quit("that's my purse; I don't know you")
|
||||
}
|
||||
|
||||
sshPath := path.Join("/home", u.Username, ".ssh")
|
||||
keyfilePath := path.Join(sshPath, keyfileName)
|
||||
|
||||
|
@ -44,7 +53,7 @@ func main() {
|
|||
quit(err.Error())
|
||||
}
|
||||
|
||||
_, err := os.Open(keyfileName)
|
||||
_, err = os.Open(keyfileName)
|
||||
if err == nil {
|
||||
quit(fmt.Sprintf("%s already exists", keyfileName))
|
||||
}
|
||||
|
|
|
@ -275,7 +275,7 @@ func createUser(data newUserData) (err error) {
|
|||
return fmt.Errorf("usermod failed: %w", err)
|
||||
}
|
||||
|
||||
cmd = exec.Command("sudo", "/town/bin/createkeyfile")
|
||||
cmd = exec.Command("sudo", "/town/bin/createkeyfile", data.Username)
|
||||
cmd.Stdin = bytes.NewBufferString(keyfileText(data))
|
||||
if err = cmd.Run(); err != nil {
|
||||
return fmt.Errorf("createkeyfile failed: %w", err)
|
||||
|
|
Loading…
Reference in New Issue