ctlsock: create exported ctlsock client library
The former interal ctlsock server package is renamed to ctlsocksrv.
This commit is contained in:
parent
3ef563493a
commit
16221facb9
26
ctlsock/ctlsock.go
Normal file
26
ctlsock/ctlsock.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// Package ctlsock is a Go library that can be used to query the
|
||||||
|
// gocryptfs control socket interface. This interface can be
|
||||||
|
// activated by passing `-ctlsock /tmp/my.sock` to gocryptfs on the
|
||||||
|
// command line.
|
||||||
|
package ctlsock
|
||||||
|
|
||||||
|
// RequestStruct is sent by a client
|
||||||
|
type RequestStruct struct {
|
||||||
|
EncryptPath string
|
||||||
|
DecryptPath string
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResponseStruct is sent by the server in response to a request
|
||||||
|
type ResponseStruct struct {
|
||||||
|
// Result is the resulting decrypted or encrypted path. Empty on error.
|
||||||
|
Result string
|
||||||
|
// ErrNo is the error number as defined in errno.h.
|
||||||
|
// 0 means success and -1 means that the error number is not known
|
||||||
|
// (look at ErrText in this case).
|
||||||
|
ErrNo int32
|
||||||
|
// ErrText is a detailed error message.
|
||||||
|
ErrText string
|
||||||
|
// WarnText contains warnings that may have been encountered while
|
||||||
|
// processing the message.
|
||||||
|
WarnText string
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
// Package ctlsock implements the control socket interface that can be
|
// Package ctlsocksrv implements the control socket interface that can be
|
||||||
// activated by passing "-ctlsock" on the command line.
|
// activated by passing "-ctlsock" on the command line.
|
||||||
package ctlsock
|
package ctlsocksrv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@ -11,6 +11,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/rfjakob/gocryptfs/ctlsock"
|
||||||
"github.com/rfjakob/gocryptfs/internal/tlog"
|
"github.com/rfjakob/gocryptfs/internal/tlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,27 +21,6 @@ type Interface interface {
|
|||||||
DecryptPath(string) (string, error)
|
DecryptPath(string) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RequestStruct is sent by a client
|
|
||||||
type RequestStruct struct {
|
|
||||||
EncryptPath string
|
|
||||||
DecryptPath string
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResponseStruct is sent by us as response to a request
|
|
||||||
type ResponseStruct struct {
|
|
||||||
// Result is the resulting decrypted or encrypted path. Empty on error.
|
|
||||||
Result string
|
|
||||||
// ErrNo is the error number as defined in errno.h.
|
|
||||||
// 0 means success and -1 means that the error number is not known
|
|
||||||
// (look at ErrText in this case).
|
|
||||||
ErrNo int32
|
|
||||||
// ErrText is a detailed error message.
|
|
||||||
ErrText string
|
|
||||||
// WarnText contains warnings that may have been encountered while
|
|
||||||
// processing the message.
|
|
||||||
WarnText string
|
|
||||||
}
|
|
||||||
|
|
||||||
type ctlSockHandler struct {
|
type ctlSockHandler struct {
|
||||||
fs Interface
|
fs Interface
|
||||||
socket *net.UnixListener
|
socket *net.UnixListener
|
||||||
@ -97,7 +77,7 @@ func (ch *ctlSockHandler) handleConnection(conn *net.UnixConn) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
data := buf[:n]
|
data := buf[:n]
|
||||||
var in RequestStruct
|
var in ctlsock.RequestStruct
|
||||||
err = json.Unmarshal(data, &in)
|
err = json.Unmarshal(data, &in)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tlog.Warn.Printf("ctlsock: JSON Unmarshal error: %#v", err)
|
tlog.Warn.Printf("ctlsock: JSON Unmarshal error: %#v", err)
|
||||||
@ -110,7 +90,7 @@ func (ch *ctlSockHandler) handleConnection(conn *net.UnixConn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// handleRequest handles an already-unmarshaled JSON request
|
// handleRequest handles an already-unmarshaled JSON request
|
||||||
func (ch *ctlSockHandler) handleRequest(in *RequestStruct, conn *net.UnixConn) {
|
func (ch *ctlSockHandler) handleRequest(in *ctlsock.RequestStruct, conn *net.UnixConn) {
|
||||||
var err error
|
var err error
|
||||||
var inPath, outPath, clean, warnText string
|
var inPath, outPath, clean, warnText string
|
||||||
// You cannot perform both decryption and encryption in one request
|
// You cannot perform both decryption and encryption in one request
|
||||||
@ -153,7 +133,7 @@ func (ch *ctlSockHandler) handleRequest(in *RequestStruct, conn *net.UnixConn) {
|
|||||||
|
|
||||||
// sendResponse sends a JSON response message
|
// sendResponse sends a JSON response message
|
||||||
func sendResponse(conn *net.UnixConn, err error, result string, warnText string) {
|
func sendResponse(conn *net.UnixConn, err error, result string, warnText string) {
|
||||||
msg := ResponseStruct{
|
msg := ctlsock.ResponseStruct{
|
||||||
Result: result,
|
Result: result,
|
||||||
WarnText: warnText,
|
WarnText: warnText,
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package ctlsock
|
package ctlsocksrv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
@ -1,4 +1,4 @@
|
|||||||
package ctlsock
|
package ctlsocksrv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
@ -7,13 +7,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/rfjakob/gocryptfs/internal/ctlsock"
|
"github.com/rfjakob/gocryptfs/internal/ctlsocksrv"
|
||||||
"github.com/rfjakob/gocryptfs/internal/nametransform"
|
"github.com/rfjakob/gocryptfs/internal/nametransform"
|
||||||
"github.com/rfjakob/gocryptfs/internal/syscallcompat"
|
"github.com/rfjakob/gocryptfs/internal/syscallcompat"
|
||||||
"github.com/rfjakob/gocryptfs/internal/tlog"
|
"github.com/rfjakob/gocryptfs/internal/tlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ ctlsock.Interface = &FS{} // Verify that interface is implemented.
|
var _ ctlsocksrv.Interface = &FS{} // Verify that interface is implemented.
|
||||||
|
|
||||||
// EncryptPath implements ctlsock.Backend
|
// EncryptPath implements ctlsock.Backend
|
||||||
//
|
//
|
||||||
|
@ -6,11 +6,11 @@ import (
|
|||||||
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
"github.com/rfjakob/gocryptfs/internal/ctlsock"
|
"github.com/rfjakob/gocryptfs/internal/ctlsocksrv"
|
||||||
"github.com/rfjakob/gocryptfs/internal/pathiv"
|
"github.com/rfjakob/gocryptfs/internal/pathiv"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ ctlsock.Interface = &ReverseFS{} // Verify that interface is implemented.
|
var _ ctlsocksrv.Interface = &ReverseFS{} // Verify that interface is implemented.
|
||||||
|
|
||||||
// EncryptPath implements ctlsock.Backend.
|
// EncryptPath implements ctlsock.Backend.
|
||||||
// This is used for the control socket and for the "-exclude" logic.
|
// This is used for the control socket and for the "-exclude" logic.
|
||||||
|
8
mount.go
8
mount.go
@ -29,7 +29,7 @@ import (
|
|||||||
"github.com/rfjakob/gocryptfs/internal/configfile"
|
"github.com/rfjakob/gocryptfs/internal/configfile"
|
||||||
"github.com/rfjakob/gocryptfs/internal/contentenc"
|
"github.com/rfjakob/gocryptfs/internal/contentenc"
|
||||||
"github.com/rfjakob/gocryptfs/internal/cryptocore"
|
"github.com/rfjakob/gocryptfs/internal/cryptocore"
|
||||||
"github.com/rfjakob/gocryptfs/internal/ctlsock"
|
"github.com/rfjakob/gocryptfs/internal/ctlsocksrv"
|
||||||
"github.com/rfjakob/gocryptfs/internal/exitcodes"
|
"github.com/rfjakob/gocryptfs/internal/exitcodes"
|
||||||
"github.com/rfjakob/gocryptfs/internal/fusefrontend"
|
"github.com/rfjakob/gocryptfs/internal/fusefrontend"
|
||||||
"github.com/rfjakob/gocryptfs/internal/fusefrontend_reverse"
|
"github.com/rfjakob/gocryptfs/internal/fusefrontend_reverse"
|
||||||
@ -222,11 +222,11 @@ func setOpenFileLimit() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ctlsockFs satisfies both the pathfs.FileSystem and the ctlsock.Interface
|
// ctlsockFs satisfies both the pathfs.FileSystem and the ctlsocksrv.Interface
|
||||||
// interfaces
|
// interfaces
|
||||||
type ctlsockFs interface {
|
type ctlsockFs interface {
|
||||||
pathfs.FileSystem
|
pathfs.FileSystem
|
||||||
ctlsock.Interface
|
ctlsocksrv.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
// initFuseFrontend - initialize gocryptfs/fusefrontend
|
// initFuseFrontend - initialize gocryptfs/fusefrontend
|
||||||
@ -331,7 +331,7 @@ func initFuseFrontend(args *argContainer) (pfs pathfs.FileSystem, wipeKeys func(
|
|||||||
// We have opened the socket early so that we cannot fail here after
|
// We have opened the socket early so that we cannot fail here after
|
||||||
// asking the user for the password
|
// asking the user for the password
|
||||||
if args._ctlsockFd != nil {
|
if args._ctlsockFd != nil {
|
||||||
go ctlsock.Serve(args._ctlsockFd, fs)
|
go ctlsocksrv.Serve(args._ctlsockFd, fs)
|
||||||
}
|
}
|
||||||
return fs, func() { cCore.Wipe() }
|
return fs, func() { cCore.Wipe() }
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/rfjakob/gocryptfs/internal/ctlsock"
|
"github.com/rfjakob/gocryptfs/ctlsock"
|
||||||
"github.com/rfjakob/gocryptfs/tests/test_helpers"
|
"github.com/rfjakob/gocryptfs/tests/test_helpers"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
"github.com/rfjakob/gocryptfs/internal/ctlsock"
|
"github.com/rfjakob/gocryptfs/ctlsock"
|
||||||
"github.com/rfjakob/gocryptfs/internal/syscallcompat"
|
"github.com/rfjakob/gocryptfs/internal/syscallcompat"
|
||||||
"github.com/rfjakob/gocryptfs/tests/test_helpers"
|
"github.com/rfjakob/gocryptfs/tests/test_helpers"
|
||||||
)
|
)
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/rfjakob/gocryptfs/internal/ctlsock"
|
"github.com/rfjakob/gocryptfs/ctlsock"
|
||||||
"github.com/rfjakob/gocryptfs/tests/test_helpers"
|
"github.com/rfjakob/gocryptfs/tests/test_helpers"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/rfjakob/gocryptfs/internal/ctlsock"
|
"github.com/rfjakob/gocryptfs/ctlsock"
|
||||||
"github.com/rfjakob/gocryptfs/internal/nametransform"
|
"github.com/rfjakob/gocryptfs/internal/nametransform"
|
||||||
"github.com/rfjakob/gocryptfs/tests/test_helpers"
|
"github.com/rfjakob/gocryptfs/tests/test_helpers"
|
||||||
)
|
)
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rfjakob/gocryptfs/internal/ctlsock"
|
"github.com/rfjakob/gocryptfs/ctlsock"
|
||||||
"github.com/rfjakob/gocryptfs/internal/nametransform"
|
"github.com/rfjakob/gocryptfs/internal/nametransform"
|
||||||
"github.com/rfjakob/gocryptfs/internal/syscallcompat"
|
"github.com/rfjakob/gocryptfs/internal/syscallcompat"
|
||||||
)
|
)
|
||||||
@ -362,7 +362,7 @@ func QueryCtlSock(t *testing.T, socketPath string, req ctlsock.RequestStruct) (r
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
buf := make([]byte, ctlsock.ReadBufSize)
|
buf := make([]byte, 5000)
|
||||||
n, err := conn.Read(buf)
|
n, err := conn.Read(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user