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