aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-05-02 22:57:34 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-05-02 22:57:34 +0200
commit28d64ae922e1104154c8de9d31d6235dbc93a10e (patch)
tree8b4c88ecaf4f21936f1ebe9b69c87338ec525dd3
parent6c2ef82cf1c433c783a4cd0876f122fc908ef2d6 (diff)
safePath
-rw-r--r--file/names.go25
-rw-r--r--main.go2
2 files changed, 24 insertions, 3 deletions
diff --git a/file/names.go b/file/names.go
index dd24617..7c714a8 100644
--- a/file/names.go
+++ b/file/names.go
@@ -2,6 +2,9 @@ package file
import (
"errors"
+ "os"
+ "os/user"
+ "path"
"path/filepath"
"strings"
)
@@ -34,7 +37,7 @@ func PubFile(comment string) (string, bool) {
if strings.HasPrefix(comment, verifyWith) {
file := comment[len(verifyWith):]
if strings.HasSuffix(file, ".pub") {
- return file, true
+ return FindFile(file), true
}
}
return "", false
@@ -43,3 +46,23 @@ func PubFile(comment string) (string, bool) {
func VerifyWith(encFile string) string {
return verifyWith + PubName(encFile)
}
+
+var safePath = []string{
+ "/etc/signify",
+ "~/.signify",
+ ".",
+}
+
+func FindFile(fname string) string {
+ usr, _ := user.Current()
+ for _, v := range safePath {
+ p := path.Join(v, fname)
+ if p[0] == '~' {
+ p = path.Join(usr.HomeDir, p[1:])
+ }
+ if _, err := os.Stat(p); err == nil {
+ return p
+ }
+ }
+ return fname
+}
diff --git a/main.go b/main.go
index d74c055..48942bd 100644
--- a/main.go
+++ b/main.go
@@ -8,8 +8,6 @@ import (
var ErrEZ = errors.New("can't combine -e and -z options")
-const safePath = "/etc/signify"
-
func usage() {
fmt.Print("Usage:")
fmt.Println("\tsignify -C [-q] -p pubkey -x sigfile [file ...]")