diff --git a/cmd/rest-server/main.go b/cmd/rest-server/main.go index 12fd6b66..91946933 100644 --- a/cmd/rest-server/main.go +++ b/cmd/rest-server/main.go @@ -206,6 +206,7 @@ func (app *restServerApp) runRoot(_ *cobra.Command, _ []string) error { // run server in background go func() { + var err error if !enabledTLS { err = srv.Serve(listener) } else { diff --git a/handlers.go b/handlers.go index 5938edd2..ba96b30a 100644 --- a/handlers.go +++ b/handlers.go @@ -51,7 +51,7 @@ func httpDefaultError(w http.ResponseWriter, code int) { http.Error(w, http.StatusText(code), code) } -// ServeHTTP makes this server an http.Handler. It handlers the administrative +// ServeHTTP makes this server an http.Handler. It handles the administrative // part of the request (figuring out the filesystem location, performing // authentication, etc) and then passes it on to repo.Handler for actual // REST API processing. diff --git a/htpasswd.go b/htpasswd.go index ad67a1e3..430c991f 100644 --- a/htpasswd.go +++ b/htpasswd.go @@ -123,7 +123,7 @@ func (h *HtpasswdFile) expiryTimer() { var zeros [sha256.Size]byte // try to wipe expired cache entries for user, entry := range h.cache { - if entry.expiry.After(now) { + if now.After(entry.expiry) { copy(entry.verifier, zeros[:]) delete(h.cache, user) } @@ -251,7 +251,6 @@ func (h *HtpasswdFile) Validate(user string, password string) bool { isValid := isMatchingHashAndPassword(hashedPassword, password) if !isValid { - log.Printf("Invalid htpasswd entry for %s.", user) return false } diff --git a/quota/quota.go b/quota/quota.go index 8437f651..ee243c6f 100644 --- a/quota/quota.go +++ b/quota/quota.go @@ -70,7 +70,7 @@ func (m *Manager) WrapWriter(req *http.Request, w io.Writer) (io.Writer, int, er if contentLenStr := req.Header.Get("Content-Length"); contentLenStr != "" { contentLen, err := strconv.ParseInt(contentLenStr, 10, 64) if err != nil { - return nil, http.StatusLengthRequired, err + return nil, http.StatusBadRequest, err } if currentSize+contentLen > m.maxRepoSize { err := fmt.Errorf("incoming blob (%d bytes) would exceed maximum size of repository (%d bytes)", diff --git a/repo/repo.go b/repo/repo.go index 0e38bb6a..137e02d0 100644 --- a/repo/repo.go +++ b/repo/repo.go @@ -305,11 +305,15 @@ func (h *Handler) saveConfig(w http.ResponseWriter, r *http.Request) { cfg := h.getSubPath("config") f, err := os.OpenFile(cfg, os.O_CREATE|os.O_WRONLY|os.O_EXCL, h.opt.fileMode) - if err != nil && os.IsExist(err) { + if err != nil { if h.opt.Debug { log.Print(err) } - httpDefaultError(w, http.StatusForbidden) + if os.IsExist(err) { + httpDefaultError(w, http.StatusForbidden) + } else { + h.internalServerError(w, err) + } return } @@ -807,7 +811,7 @@ func (h *Handler) internalServerError(w http.ResponseWriter, err error) { httpDefaultError(w, http.StatusInternalServerError) } -// internalServerError is called to report an error that occurred while +// fileAccessError is called to report an error that occurred while // accessing a file. If the does not exist, the corresponding http status code // will be returned to the client. All other errors are passed on to // internalServerError