2020-05-09 19:11:06 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/rfjakob/gocryptfs/ctlsock"
|
|
|
|
)
|
|
|
|
|
2020-05-10 00:04:14 +02:00
|
|
|
func decryptPaths(socketPath string, sep0 bool) {
|
2020-05-09 19:11:06 +02:00
|
|
|
var req ctlsock.RequestStruct
|
2020-05-10 00:04:14 +02:00
|
|
|
transformPaths(socketPath, &req, &req.DecryptPath, sep0)
|
2020-05-09 19:11:06 +02:00
|
|
|
}
|
|
|
|
|
2020-05-10 00:04:14 +02:00
|
|
|
func encryptPaths(socketPath string, sep0 bool) {
|
2020-05-09 19:11:06 +02:00
|
|
|
var req ctlsock.RequestStruct
|
2020-05-10 00:04:14 +02:00
|
|
|
transformPaths(socketPath, &req, &req.EncryptPath, sep0)
|
2020-05-09 19:11:06 +02:00
|
|
|
}
|
|
|
|
|
2020-05-10 00:04:14 +02:00
|
|
|
func transformPaths(socketPath string, req *ctlsock.RequestStruct, in *string, sep0 bool) {
|
|
|
|
errorCount := 0
|
2020-05-09 19:11:06 +02:00
|
|
|
c, err := ctlsock.New(socketPath)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("fatal: %v\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2020-05-10 00:04:14 +02:00
|
|
|
line := 1
|
|
|
|
var separator byte = '\n'
|
|
|
|
if sep0 {
|
|
|
|
separator = '\000'
|
|
|
|
}
|
|
|
|
r := bufio.NewReader(os.Stdin)
|
golangci-lint: fix issues found by gosimple
Everything except the
if err2.Err == syscall.EOPNOTSUPP
case. Gets too confusing when collapsed into a single line.
Issues were:
$ golangci-lint run --disable-all --enable gosimple
mount.go:473:2: S1008: should use 'return strings.HasPrefix(v, "fusermount version")' instead of 'if strings.HasPrefix(v, "fusermount version") { return true }; return false' (gosimple)
if strings.HasPrefix(v, "fusermount version") {
^
cli_args.go:258:5: S1002: should omit comparison to bool constant, can be simplified to `args.forcedecode` (gosimple)
if args.forcedecode == true {
^
cli_args.go:263:6: S1002: should omit comparison to bool constant, can be simplified to `args.aessiv` (gosimple)
if args.aessiv == true {
^
cli_args.go:267:6: S1002: should omit comparison to bool constant, can be simplified to `args.reverse` (gosimple)
if args.reverse == true {
^
internal/stupidgcm/stupidgcm.go:227:6: S1002: should omit comparison to bool constant, can be simplified to `g.forceDecode` (gosimple)
if g.forceDecode == true {
^
gocryptfs-xray/xray_tests/xray_test.go:23:5: S1004: should use !bytes.Equal(out, expected) instead (gosimple)
if bytes.Compare(out, expected) != 0 {
^
gocryptfs-xray/xray_tests/xray_test.go:40:5: S1004: should use !bytes.Equal(out, expected) instead (gosimple)
if bytes.Compare(out, expected) != 0 {
^
gocryptfs-xray/paths_ctlsock.go:34:20: S1002: should omit comparison to bool constant, can be simplified to `!eof` (gosimple)
for eof := false; eof == false; line++ {
^
tests/reverse/xattr_test.go:19:2: S1008: should use 'return err2.Err != syscall.EOPNOTSUPP' instead of 'if err2.Err == syscall.EOPNOTSUPP { return false }; return true' (gosimple)
if err2.Err == syscall.EOPNOTSUPP {
^
internal/fusefrontend/node.go:459:45: S1002: should omit comparison to bool constant, can be simplified to `!nameFileAlreadyThere` (gosimple)
if nametransform.IsLongContent(cName2) && nameFileAlreadyThere == false {
^
tests/xattr/xattr_integration_test.go:221:2: S1008: should use 'return err2.Err != syscall.EOPNOTSUPP' instead of 'if err2.Err == syscall.EOPNOTSUPP { return false }; return true' (gosimple)
if err2.Err == syscall.EOPNOTSUPP {
^
tests/test_helpers/helpers.go:338:19: S1002: should omit comparison to bool constant, can be simplified to `open` (gosimple)
if err != nil && open == true {
^
tests/matrix/concurrency_test.go:121:7: S1004: should use !bytes.Equal(buf, content) instead (gosimple)
if bytes.Compare(buf, content) != 0 {
^
2021-08-19 07:51:47 +02:00
|
|
|
for eof := false; !eof; line++ {
|
2020-05-10 00:04:14 +02:00
|
|
|
val, err := r.ReadBytes(separator)
|
|
|
|
if len(val) == 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
// break the loop after we have processed the last val
|
|
|
|
eof = true
|
|
|
|
} else {
|
|
|
|
// drop trailing separator
|
|
|
|
val = val[:len(val)-1]
|
|
|
|
}
|
|
|
|
*in = string(val)
|
2020-05-09 19:11:06 +02:00
|
|
|
resp, err := c.Query(req)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "error at input line %d %q: %v\n", line, *in, err)
|
2020-05-10 00:04:14 +02:00
|
|
|
errorCount++
|
2020-05-09 19:11:06 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
if resp.WarnText != "" {
|
|
|
|
fmt.Fprintf(os.Stderr, "warning at input line %d %q: %v\n", line, *in, resp.WarnText)
|
|
|
|
}
|
2020-05-10 00:04:14 +02:00
|
|
|
fmt.Printf("%s%c", resp.Result, separator)
|
|
|
|
}
|
|
|
|
if errorCount == 0 {
|
|
|
|
os.Exit(0)
|
2020-05-09 19:11:06 +02:00
|
|
|
}
|
2020-05-10 00:04:14 +02:00
|
|
|
os.Exit(1)
|
2020-05-09 19:11:06 +02:00
|
|
|
}
|