mirror of
https://github.com/restic/rest-server.git
synced 2025-10-19 07:33:21 +00:00
Update with changes from github.com/restic/restic tree
Uncompilable right now, due to bad import paths.
This commit is contained in:
parent
07fae00e7d
commit
80196e6df6
5 changed files with 122 additions and 31 deletions
27
htpasswd.go
27
htpasswd.go
|
@ -1,3 +1,5 @@
|
|||
// +build go1.4
|
||||
|
||||
package main
|
||||
|
||||
/*
|
||||
|
@ -30,18 +32,23 @@ import (
|
|||
"encoding/csv"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"restic/fs"
|
||||
)
|
||||
|
||||
// lookup passwords in a htpasswd file
|
||||
// The entries must have been created with -s for SHA encryption
|
||||
|
||||
// HtpasswdFile is a map for usernames to passwords.
|
||||
type HtpasswdFile struct {
|
||||
Users map[string]string
|
||||
}
|
||||
|
||||
// NewHtpasswdFromFile reads the users and passwords from a htpasswd
|
||||
// file and returns them. If an error is encountered, it is returned, together
|
||||
// with a nil-Pointer for the HtpasswdFile.
|
||||
func NewHtpasswdFromFile(path string) (*HtpasswdFile, error) {
|
||||
r, err := os.Open(path)
|
||||
r, err := fs.Open(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -49,13 +56,16 @@ func NewHtpasswdFromFile(path string) (*HtpasswdFile, error) {
|
|||
return NewHtpasswd(r)
|
||||
}
|
||||
|
||||
// NewHtpasswd reads the users and passwords from a htpasswd
|
||||
// datastream in file and returns them. If an error is encountered,
|
||||
// it is returned, together with a nil-Pointer for the HtpasswdFile.
|
||||
func NewHtpasswd(file io.Reader) (*HtpasswdFile, error) {
|
||||
csv_reader := csv.NewReader(file)
|
||||
csv_reader.Comma = ':'
|
||||
csv_reader.Comment = '#'
|
||||
csv_reader.TrimLeadingSpace = true
|
||||
cr := csv.NewReader(file)
|
||||
cr.Comma = ':'
|
||||
cr.Comment = '#'
|
||||
cr.TrimLeadingSpace = true
|
||||
|
||||
records, err := csv_reader.ReadAll()
|
||||
records, err := cr.ReadAll()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -66,6 +76,9 @@ func NewHtpasswd(file io.Reader) (*HtpasswdFile, error) {
|
|||
return h, nil
|
||||
}
|
||||
|
||||
// Validate returns true if password matches the stored password
|
||||
// for user. If no password for user is stored, or the password
|
||||
// is wrong, false is returned.
|
||||
func (h *HtpasswdFile) Validate(user string, password string) bool {
|
||||
realPassword, exists := h.Users[user]
|
||||
if !exists {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue