fix: gpg encrypted key not detected correctly
This commit is contained in:
parent
0f558b3314
commit
668627c467
12
util/util.go
12
util/util.go
|
@ -5,7 +5,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/bitfield/script"
|
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
"golang.org/x/text/cases"
|
"golang.org/x/text/cases"
|
||||||
"golang.org/x/text/language"
|
"golang.org/x/text/language"
|
||||||
|
@ -104,17 +103,14 @@ func ReadCredentialFile(uuid string, dirs []string) (string, error) {
|
||||||
return string(keyText), nil
|
return string(keyText), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This has to be refactored at some point...
|
||||||
func isPgpEncrypted(path string) (bool, error) {
|
func isPgpEncrypted(path string) (bool, error) {
|
||||||
output, err := RunCommand("file", nil, path)
|
_, err := RunCommand("gpg2", nil, "--list-only", "--list-packets", path)
|
||||||
if err != nil {
|
return err == nil, nil
|
||||||
return false, errors.Wrap(err, 0)
|
|
||||||
}
|
|
||||||
l, err := script.Echo(string(output)).Match("PGP").Match("encrypted").CountLines()
|
|
||||||
return l > 0, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func readPgpEncryptedFile(path string) ([]byte, error) {
|
func readPgpEncryptedFile(path string) ([]byte, error) {
|
||||||
output, err := RunCommand("gpg", nil, "--decrypt", path)
|
output, err := RunCommand("gpg2", nil, "--decrypt", path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WrapPrefix(err, fmt.Sprintf("failed to read pgp encrypted file %q", path), 0)
|
return nil, errors.WrapPrefix(err, fmt.Sprintf("failed to read pgp encrypted file %q", path), 0)
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,10 +75,10 @@ func (d *Dataset) loadPermissions() error {
|
||||||
return errors.WrapPrefix(err, fmt.Sprintf("cannot obtain permission list for zfs dataset %s", d.Name), 0)
|
return errors.WrapPrefix(err, fmt.Sprintf("cannot obtain permission list for zfs dataset %s", d.Name), 0)
|
||||||
}
|
}
|
||||||
pattern := regexp.MustCompile(`^\s*user ` + currentUser.Username + ` ([\w-]+(,[\w-]+)*)$`)
|
pattern := regexp.MustCompile(`^\s*user ` + currentUser.Username + ` ([\w-]+(,[\w-]+)*)$`)
|
||||||
script.Echo(string(output)).FilterLine(func(line string) string {
|
_ = script.Echo(string(output)).FilterLine(func(line string) string {
|
||||||
match := pattern.FindStringSubmatch(line)
|
match := pattern.FindStringSubmatch(line)
|
||||||
if match != nil {
|
if match != nil {
|
||||||
for _, perm := range strings.Split(match[1], ",") {
|
for perm := range strings.SplitSeq(match[1], ",") {
|
||||||
switch perm {
|
switch perm {
|
||||||
case "mount":
|
case "mount":
|
||||||
permissions.Mount = true
|
permissions.Mount = true
|
||||||
|
|
Loading…
Reference in New Issue