mirror of
https://github.com/restic/rest-server.git
synced 2025-12-07 09:36:13 -08:00
Refuse writing the config in append-only mode
This commit is contained in:
22
handlers.go
22
handlers.go
@@ -206,22 +206,31 @@ func SaveConfig(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
bytes, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
f, err := os.OpenFile(cfg, os.O_CREATE|os.O_WRONLY|os.O_EXCL, 0600)
|
||||
if err != nil && os.IsExist(err) {
|
||||
if Config.Debug {
|
||||
log.Print(err)
|
||||
}
|
||||
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
||||
http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(cfg, bytes, 0600); err != nil {
|
||||
_, err = io.Copy(f, r.Body)
|
||||
if err != nil {
|
||||
if Config.Debug {
|
||||
log.Print(err)
|
||||
}
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
err = f.Close()
|
||||
if err != nil {
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
_ = r.Body.Close()
|
||||
}
|
||||
|
||||
// DeleteConfig removes a config.
|
||||
@@ -473,6 +482,11 @@ func SaveBlob(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
if os.IsExist(err) {
|
||||
http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if Config.Debug {
|
||||
log.Print(err)
|
||||
|
||||
Reference in New Issue
Block a user