add newline to keyfile if needed

trunk
vilmibm 2023-11-01 20:59:49 +00:00
parent 69ad6a384a
commit 9bb456bc17
2 changed files with 10 additions and 4 deletions

View File

@ -76,12 +76,13 @@ func main() {
quit(fmt.Sprintf("file contents look wrong: %s", string(stdin)), 8) quit(fmt.Sprintf("file contents look wrong: %s", string(stdin)), 8)
} }
n, err = f.Write(stdin) _, err = f.Write(stdin)
if err != nil { if err != nil {
quit(err.Error(), 9) quit(err.Error(), 9)
} else if n == 0 {
quit("wrote nothing to keyfile", 10)
} }
_, err = f.WriteString("\n")
} }
/* /*

View File

@ -7,6 +7,7 @@ import (
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
"strings"
"time" "time"
"git.tilde.town/tildetown/town/invites" "git.tilde.town/tildetown/town/invites"
@ -205,12 +206,16 @@ func createUser(data newUserData) (err error) {
} }
func keyfileText(data newUserData) string { func keyfileText(data newUserData) string {
pkey := data.PubKey
if !strings.HasSuffix(pkey, "\n") {
pkey += "\n"
}
header := `########## GREETINGS! ########## header := `########## GREETINGS! ##########
# This file was automatically generated by tilde.town when # This file was automatically generated by tilde.town when
# your account was created. You can edit it if you want, but we # your account was created. You can edit it if you want, but we
# recommend adding stuff to ~/.ssh/authorized_keys instead.` # recommend adding stuff to ~/.ssh/authorized_keys instead.`
return fmt.Sprintf("%s\n%s", header, data.PubKey) return fmt.Sprintf("%s\n%s", header, pkey)
} }
func main() { func main() {