serve restic: Disallow overwriting files in append-only mode - Fixes #2195

* Disallow overwriting files in append-only mode
* Add tests for append-only mode
This commit is contained in:
Alexander Neumann
2018-04-04 14:49:13 +01:00
committed by Nick Craig-Wood
parent 1dea99ab20
commit 5b8977a053
2 changed files with 202 additions and 0 deletions
+10
View File
@@ -316,6 +316,16 @@ func (s *server) getObject(w http.ResponseWriter, r *http.Request, remote string
// postObject posts an object to the repository
func (s *server) postObject(w http.ResponseWriter, r *http.Request, remote string) {
if appendOnly {
// make sure the file does not exist yet
_, err := s.f.NewObject(remote)
if err == nil {
fs.Errorf(remote, "Post request: file already exists, refusing to overwrite in append-only mode")
http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
return
}
}
// fs.Debugf(s.f, "content length = %d", r.ContentLength)
if r.ContentLength >= 0 {
// Size known use Put