golf and also securing

trunk
vilmibm 2023-03-04 00:33:01 +00:00
parent 872d2ade23
commit 9444954bc6
1 changed files with 2 additions and 11 deletions

View File

@ -53,22 +53,13 @@ func main() {
quit(err.Error())
}
_, err = os.Open(keyfilePath)
if err == nil {
quit(fmt.Sprintf("%s already exists", keyfilePath))
}
f, err := os.Create(keyfilePath)
f, err := os.OpenFile(keyfilePath, os.O_CREATE|os.O_EXCL|os.O_RDWR, 0600)
if err != nil {
quit(err.Error())
quit(fmt.Sprintf("failed to open %s: %s", keyfilePath, err.Error()))
}
defer f.Close()
if err = os.Chmod(keyfilePath, os.FileMode(0600)); err != nil {
quit(err.Error())
}
stdin := make([]byte, 90000) // arbitrary limit
n, err := os.Stdin.Read(stdin)