traefik/acme/localStore_unix.go

29 lines
462 B
Go
Raw Normal View History

2017-02-04 20:21:17 +00:00
// +build !windows
package acme
import (
"fmt"
"os"
)
2018-03-05 19:54:04 +00:00
// Check file permissions and content size
func checkFile(name string) (bool, error) {
2017-02-04 20:21:17 +00:00
f, err := os.Open(name)
if err != nil {
2018-03-05 19:54:04 +00:00
return false, err
2017-02-04 20:21:17 +00:00
}
defer f.Close()
2018-03-05 19:54:04 +00:00
2017-02-04 20:21:17 +00:00
fi, err := f.Stat()
if err != nil {
2018-03-05 19:54:04 +00:00
return false, err
2017-02-04 20:21:17 +00:00
}
2018-03-05 19:54:04 +00:00
2017-02-04 20:21:17 +00:00
if fi.Mode().Perm()&0077 != 0 {
2018-03-05 19:54:04 +00:00
return false, fmt.Errorf("permissions %o for %s are too open, please use 600", fi.Mode().Perm(), name)
2017-02-04 20:21:17 +00:00
}
2018-03-05 19:54:04 +00:00
return fi.Size() > 0, nil
2017-02-04 20:21:17 +00:00
}