2015-09-08 00:54:24 +02:00
|
|
|
package pathfs_frontend
|
|
|
|
|
|
|
|
import (
|
2015-11-27 00:03:10 +01:00
|
|
|
"encoding/base64"
|
2015-11-25 22:17:42 +01:00
|
|
|
"fmt"
|
2015-09-08 00:54:24 +02:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2015-11-27 22:20:01 +01:00
|
|
|
"sync"
|
|
|
|
"syscall"
|
2015-09-08 00:54:24 +02:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/hanwen/go-fuse/fuse"
|
|
|
|
"github.com/hanwen/go-fuse/fuse/nodefs"
|
|
|
|
"github.com/hanwen/go-fuse/fuse/pathfs"
|
|
|
|
"github.com/rfjakob/gocryptfs/cryptfs"
|
|
|
|
)
|
|
|
|
|
|
|
|
type FS struct {
|
|
|
|
*cryptfs.CryptFS
|
2015-11-27 22:20:01 +01:00
|
|
|
pathfs.FileSystem // loopbackFileSystem, see go-fuse/fuse/pathfs/loopback.go
|
2015-11-28 16:52:57 +01:00
|
|
|
args Args // Stores configuration arguments
|
2015-11-27 21:48:58 +01:00
|
|
|
// dirIVLock: Lock()ed if any "gocryptfs.diriv" file is modified
|
|
|
|
// Readers must RLock() it to prevent them from seeing intermediate
|
|
|
|
// states
|
|
|
|
dirIVLock sync.RWMutex
|
2015-09-08 00:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Encrypted FUSE overlay filesystem
|
2015-11-28 16:52:57 +01:00
|
|
|
func NewFS(args Args) *FS {
|
2015-09-08 00:54:24 +02:00
|
|
|
return &FS{
|
2015-11-28 16:52:57 +01:00
|
|
|
CryptFS: cryptfs.NewCryptFS(args.Masterkey, args.OpenSSL, args.PlaintextNames),
|
|
|
|
FileSystem: pathfs.NewLoopbackFileSystem(args.Cipherdir),
|
|
|
|
args: args,
|
2015-09-08 00:54:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-27 00:03:10 +01:00
|
|
|
// GetBackingPath - get the absolute encrypted path of the backing file
|
2015-11-25 19:30:32 +01:00
|
|
|
// from the relative plaintext path "relPath"
|
2015-11-27 00:03:10 +01:00
|
|
|
func (fs *FS) getBackingPath(relPath string) (string, error) {
|
2015-11-28 16:52:57 +01:00
|
|
|
cPath, err := fs.encryptPath(relPath)
|
2015-11-27 00:03:10 +01:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2015-11-28 16:52:57 +01:00
|
|
|
cAbsPath := filepath.Join(fs.args.Cipherdir, cPath)
|
|
|
|
cryptfs.Debug.Printf("getBackingPath: %s + %s -> %s\n", fs.args.Cipherdir, relPath, cAbsPath)
|
|
|
|
return cAbsPath, nil
|
2015-09-08 00:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fs *FS) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse.Status) {
|
2015-09-16 19:32:37 +02:00
|
|
|
cryptfs.Debug.Printf("FS.GetAttr('%s')\n", name)
|
2015-11-03 22:25:29 +01:00
|
|
|
if fs.CryptFS.IsFiltered(name) {
|
|
|
|
return nil, fuse.EPERM
|
2015-11-03 00:00:13 +01:00
|
|
|
}
|
2015-11-27 00:03:10 +01:00
|
|
|
cName, err := fs.encryptPath(name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fuse.ToStatus(err)
|
|
|
|
}
|
2015-09-16 19:32:37 +02:00
|
|
|
a, status := fs.FileSystem.GetAttr(cName, context)
|
2015-09-08 00:54:24 +02:00
|
|
|
if a == nil {
|
2015-09-17 22:08:49 +02:00
|
|
|
cryptfs.Debug.Printf("FS.GetAttr failed: %s\n", status.String())
|
2015-09-08 00:54:24 +02:00
|
|
|
return a, status
|
|
|
|
}
|
2015-09-16 19:32:37 +02:00
|
|
|
if a.IsRegular() {
|
2015-11-01 12:11:36 +01:00
|
|
|
a.Size = fs.CipherSizeToPlainSize(a.Size)
|
2015-09-16 19:32:37 +02:00
|
|
|
} else if a.IsSymlink() {
|
|
|
|
target, _ := fs.Readlink(name, context)
|
|
|
|
a.Size = uint64(len(target))
|
|
|
|
}
|
2015-09-08 00:54:24 +02:00
|
|
|
return a, status
|
|
|
|
}
|
|
|
|
|
2015-09-13 22:09:48 +02:00
|
|
|
func (fs *FS) OpenDir(dirName string, context *fuse.Context) ([]fuse.DirEntry, fuse.Status) {
|
2015-09-16 19:32:37 +02:00
|
|
|
cryptfs.Debug.Printf("OpenDir(%s)\n", dirName)
|
2015-11-27 00:03:10 +01:00
|
|
|
cDirName, err := fs.encryptPath(dirName)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fuse.ToStatus(err)
|
|
|
|
}
|
2015-11-29 19:57:48 +01:00
|
|
|
// Read ciphertext directory
|
2015-11-27 00:03:10 +01:00
|
|
|
cipherEntries, status := fs.FileSystem.OpenDir(cDirName, context)
|
2015-11-29 19:57:48 +01:00
|
|
|
if cipherEntries == nil {
|
|
|
|
return nil, status
|
|
|
|
}
|
|
|
|
// Get DirIV (stays zero if DirIV if off)
|
|
|
|
cachedIV := make([]byte, cryptfs.DIRIV_LEN)
|
|
|
|
if fs.args.DirIV {
|
|
|
|
// Read the DirIV once and use it for all later name decryptions
|
|
|
|
cDirAbsPath := filepath.Join(fs.args.Cipherdir, cDirName)
|
|
|
|
cachedIV, err = fs.CryptFS.ReadDirIV(cDirAbsPath)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fuse.ToStatus(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Decrypt filenames
|
2015-09-08 00:54:24 +02:00
|
|
|
var plain []fuse.DirEntry
|
2015-11-29 19:57:48 +01:00
|
|
|
for i := range cipherEntries {
|
|
|
|
cName := cipherEntries[i].Name
|
|
|
|
if dirName == "" && cName == cryptfs.ConfDefaultName {
|
|
|
|
// silently ignore "gocryptfs.conf" in the top level dir
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if fs.args.DirIV && cName == cryptfs.DIRIV_FILENAME {
|
|
|
|
// silently ignore "gocryptfs.diriv" everywhere if dirIV is enabled
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
var name string
|
|
|
|
name, err = fs.CryptFS.DecryptName(cName, cachedIV)
|
|
|
|
if err != nil {
|
|
|
|
cryptfs.Warn.Printf("Invalid name \"%s\" in dir \"%s\": %s\n", cName, dirName, err)
|
|
|
|
continue
|
2015-09-08 00:54:24 +02:00
|
|
|
}
|
2015-11-29 19:57:48 +01:00
|
|
|
cipherEntries[i].Name = name
|
|
|
|
plain = append(plain, cipherEntries[i])
|
2015-09-08 00:54:24 +02:00
|
|
|
}
|
|
|
|
return plain, status
|
|
|
|
}
|
|
|
|
|
|
|
|
// We always need read access to do read-modify-write cycles
|
|
|
|
func (fs *FS) mangleOpenFlags(flags uint32) (newFlags int, writeOnly bool) {
|
|
|
|
newFlags = int(flags)
|
2015-10-04 14:36:20 +02:00
|
|
|
if newFlags&os.O_WRONLY > 0 {
|
2015-09-08 00:54:24 +02:00
|
|
|
writeOnly = true
|
|
|
|
newFlags = newFlags ^ os.O_WRONLY | os.O_RDWR
|
|
|
|
}
|
|
|
|
// We also cannot open the file in append mode, we need to seek back for RMW
|
|
|
|
newFlags = newFlags &^ os.O_APPEND
|
|
|
|
|
|
|
|
return newFlags, writeOnly
|
|
|
|
}
|
|
|
|
|
2015-11-03 00:00:13 +01:00
|
|
|
func (fs *FS) Open(path string, flags uint32, context *fuse.Context) (fuseFile nodefs.File, status fuse.Status) {
|
2015-11-14 17:16:17 +01:00
|
|
|
if fs.CryptFS.IsFiltered(path) {
|
2015-11-03 00:00:13 +01:00
|
|
|
return nil, fuse.EPERM
|
|
|
|
}
|
2015-09-08 00:54:24 +02:00
|
|
|
iflags, writeOnly := fs.mangleOpenFlags(flags)
|
2015-11-27 00:03:10 +01:00
|
|
|
cPath, err := fs.getBackingPath(path)
|
|
|
|
if err != nil {
|
2015-11-28 16:52:57 +01:00
|
|
|
cryptfs.Debug.Printf("Open: getBackingPath: %v\n", err)
|
2015-11-27 00:03:10 +01:00
|
|
|
return nil, fuse.ToStatus(err)
|
|
|
|
}
|
2015-11-28 16:52:57 +01:00
|
|
|
cryptfs.Debug.Printf("Open: %s\n", cPath)
|
2015-11-27 00:03:10 +01:00
|
|
|
f, err := os.OpenFile(cPath, iflags, 0666)
|
2015-09-08 00:54:24 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, fuse.ToStatus(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return NewFile(f, writeOnly, fs.CryptFS), fuse.OK
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fs *FS) Create(path string, flags uint32, mode uint32, context *fuse.Context) (fuseFile nodefs.File, code fuse.Status) {
|
2015-11-14 17:16:17 +01:00
|
|
|
if fs.CryptFS.IsFiltered(path) {
|
2015-11-03 22:25:29 +01:00
|
|
|
return nil, fuse.EPERM
|
2015-11-03 00:00:13 +01:00
|
|
|
}
|
2015-09-08 00:54:24 +02:00
|
|
|
iflags, writeOnly := fs.mangleOpenFlags(flags)
|
2015-11-27 00:03:10 +01:00
|
|
|
cPath, err := fs.getBackingPath(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fuse.ToStatus(err)
|
|
|
|
}
|
|
|
|
f, err := os.OpenFile(cPath, iflags|os.O_CREATE, os.FileMode(mode))
|
2015-09-08 00:54:24 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, fuse.ToStatus(err)
|
|
|
|
}
|
|
|
|
return NewFile(f, writeOnly, fs.CryptFS), fuse.OK
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fs *FS) Chmod(path string, mode uint32, context *fuse.Context) (code fuse.Status) {
|
2015-11-14 17:16:17 +01:00
|
|
|
if fs.CryptFS.IsFiltered(path) {
|
2015-11-03 22:25:29 +01:00
|
|
|
return fuse.EPERM
|
2015-11-03 00:00:13 +01:00
|
|
|
}
|
2015-11-27 00:03:10 +01:00
|
|
|
cPath, err := fs.encryptPath(path)
|
|
|
|
if err != nil {
|
|
|
|
return fuse.ToStatus(err)
|
|
|
|
}
|
|
|
|
return fs.FileSystem.Chmod(cPath, mode, context)
|
2015-09-08 00:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fs *FS) Chown(path string, uid uint32, gid uint32, context *fuse.Context) (code fuse.Status) {
|
2015-11-14 17:16:17 +01:00
|
|
|
if fs.CryptFS.IsFiltered(path) {
|
2015-11-03 22:25:29 +01:00
|
|
|
return fuse.EPERM
|
2015-11-03 00:00:13 +01:00
|
|
|
}
|
2015-11-27 00:03:10 +01:00
|
|
|
cPath, err := fs.encryptPath(path)
|
|
|
|
if err != nil {
|
|
|
|
return fuse.ToStatus(err)
|
|
|
|
}
|
|
|
|
return fs.FileSystem.Chown(cPath, uid, gid, context)
|
2015-09-18 22:22:11 +02:00
|
|
|
}
|
|
|
|
|
2015-11-27 00:03:10 +01:00
|
|
|
func (fs *FS) Mknod(path string, mode uint32, dev uint32, context *fuse.Context) (code fuse.Status) {
|
|
|
|
if fs.CryptFS.IsFiltered(path) {
|
2015-11-03 22:25:29 +01:00
|
|
|
return fuse.EPERM
|
2015-11-03 00:00:13 +01:00
|
|
|
}
|
2015-11-27 00:03:10 +01:00
|
|
|
cPath, err := fs.encryptPath(path)
|
|
|
|
if err != nil {
|
|
|
|
return fuse.ToStatus(err)
|
|
|
|
}
|
|
|
|
return fs.FileSystem.Mknod(cPath, mode, dev, context)
|
2015-09-08 00:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fs *FS) Truncate(path string, offset uint64, context *fuse.Context) (code fuse.Status) {
|
2015-11-01 01:32:33 +01:00
|
|
|
cryptfs.Warn.Printf("Truncate of a closed file is not supported, returning ENOSYS\n")
|
|
|
|
return fuse.ENOSYS
|
2015-09-08 00:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fs *FS) Utimens(path string, Atime *time.Time, Mtime *time.Time, context *fuse.Context) (code fuse.Status) {
|
2015-11-14 17:16:17 +01:00
|
|
|
if fs.CryptFS.IsFiltered(path) {
|
2015-11-03 22:25:29 +01:00
|
|
|
return fuse.EPERM
|
2015-11-03 00:00:13 +01:00
|
|
|
}
|
2015-11-27 00:03:10 +01:00
|
|
|
cPath, err := fs.encryptPath(path)
|
|
|
|
if err != nil {
|
|
|
|
return fuse.ToStatus(err)
|
|
|
|
}
|
|
|
|
return fs.FileSystem.Utimens(cPath, Atime, Mtime, context)
|
2015-09-08 00:54:24 +02:00
|
|
|
}
|
|
|
|
|
2015-11-27 00:03:10 +01:00
|
|
|
func (fs *FS) Readlink(path string, context *fuse.Context) (out string, status fuse.Status) {
|
|
|
|
cPath, err := fs.encryptPath(path)
|
|
|
|
if err != nil {
|
|
|
|
return "", fuse.ToStatus(err)
|
|
|
|
}
|
2015-11-28 16:47:30 +01:00
|
|
|
cTarget, status := fs.FileSystem.Readlink(cPath, context)
|
2015-09-09 19:32:59 +02:00
|
|
|
if status != fuse.OK {
|
|
|
|
return "", status
|
|
|
|
}
|
2015-11-28 16:52:57 +01:00
|
|
|
// Old filesystem: symlinks are encrypted like paths (CBC)
|
|
|
|
if !fs.args.DirIV {
|
|
|
|
target, err := fs.decryptPath(cTarget)
|
|
|
|
if err != nil {
|
|
|
|
cryptfs.Warn.Printf("Readlink: CBC decryption failed: %v", err)
|
|
|
|
return "", fuse.EIO
|
|
|
|
}
|
|
|
|
return target, fuse.OK
|
|
|
|
}
|
|
|
|
// Since gocryptfs v0.5 symlinks are encrypted like file contents (GCM)
|
2015-11-28 16:47:30 +01:00
|
|
|
cBinTarget, err := base64.URLEncoding.DecodeString(cTarget)
|
2015-09-09 19:32:59 +02:00
|
|
|
if err != nil {
|
2015-11-28 16:47:30 +01:00
|
|
|
cryptfs.Warn.Printf("Readlink: %v\n", err)
|
2015-09-09 19:32:59 +02:00
|
|
|
return "", fuse.EIO
|
|
|
|
}
|
2015-11-28 16:47:30 +01:00
|
|
|
target, err := fs.CryptFS.DecryptBlock([]byte(cBinTarget), 0, nil)
|
|
|
|
if err != nil {
|
|
|
|
cryptfs.Warn.Printf("Readlink: %v\n", err)
|
|
|
|
return "", fuse.EIO
|
|
|
|
}
|
|
|
|
return string(target), fuse.OK
|
2015-09-08 00:54:24 +02:00
|
|
|
}
|
|
|
|
|
2015-11-25 19:30:32 +01:00
|
|
|
func (fs *FS) Mkdir(relPath string, mode uint32, context *fuse.Context) (code fuse.Status) {
|
|
|
|
if fs.CryptFS.IsFiltered(relPath) {
|
2015-11-03 22:25:29 +01:00
|
|
|
return fuse.EPERM
|
2015-11-03 00:00:13 +01:00
|
|
|
}
|
2015-11-27 00:03:10 +01:00
|
|
|
encPath, err := fs.getBackingPath(relPath)
|
|
|
|
if err != nil {
|
|
|
|
return fuse.ToStatus(err)
|
|
|
|
}
|
2015-11-29 21:41:38 +01:00
|
|
|
// The new directory may take the place of an older one that is still in the cache
|
|
|
|
fs.CryptFS.DirIVCacheEnc.Clear()
|
2015-11-25 19:30:32 +01:00
|
|
|
// Create directory
|
2015-11-27 21:48:58 +01:00
|
|
|
fs.dirIVLock.Lock()
|
|
|
|
defer fs.dirIVLock.Unlock()
|
2015-11-27 00:03:10 +01:00
|
|
|
err = os.Mkdir(encPath, os.FileMode(mode))
|
2015-11-25 19:30:32 +01:00
|
|
|
if err != nil {
|
|
|
|
return fuse.ToStatus(err)
|
|
|
|
}
|
|
|
|
// Create gocryptfs.diriv inside
|
2015-11-27 23:34:55 +01:00
|
|
|
err = cryptfs.WriteDirIV(encPath)
|
2015-11-25 19:30:32 +01:00
|
|
|
if err != nil {
|
2015-11-25 22:17:42 +01:00
|
|
|
// This should not happen
|
2015-11-25 19:30:32 +01:00
|
|
|
cryptfs.Warn.Printf("Creating %s in dir %s failed: %v\n", cryptfs.DIRIV_FILENAME, encPath, err)
|
|
|
|
err2 := syscall.Rmdir(encPath)
|
|
|
|
if err2 != nil {
|
2015-11-25 22:17:42 +01:00
|
|
|
cryptfs.Warn.Printf("Mkdir: Rollback failed: %v\n", err2)
|
2015-11-25 19:30:32 +01:00
|
|
|
}
|
|
|
|
return fuse.ToStatus(err)
|
|
|
|
}
|
|
|
|
return fuse.OK
|
2015-09-08 00:54:24 +02:00
|
|
|
}
|
|
|
|
|
2015-11-27 00:03:10 +01:00
|
|
|
func (fs *FS) Unlink(path string, context *fuse.Context) (code fuse.Status) {
|
|
|
|
if fs.CryptFS.IsFiltered(path) {
|
2015-11-03 22:25:29 +01:00
|
|
|
return fuse.EPERM
|
2015-11-03 00:00:13 +01:00
|
|
|
}
|
2015-11-27 00:03:10 +01:00
|
|
|
cPath, err := fs.getBackingPath(path)
|
|
|
|
if err != nil {
|
|
|
|
return fuse.ToStatus(err)
|
2015-09-16 19:32:37 +02:00
|
|
|
}
|
2015-11-27 00:03:10 +01:00
|
|
|
return fuse.ToStatus(syscall.Unlink(cPath))
|
2015-09-08 00:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fs *FS) Rmdir(name string, context *fuse.Context) (code fuse.Status) {
|
2015-11-27 00:03:10 +01:00
|
|
|
encPath, err := fs.getBackingPath(name)
|
|
|
|
if err != nil {
|
|
|
|
return fuse.ToStatus(err)
|
|
|
|
}
|
2015-11-25 22:17:42 +01:00
|
|
|
|
|
|
|
// If the directory is not empty besides gocryptfs.diriv, do not even
|
|
|
|
// attempt the dance around gocryptfs.diriv.
|
|
|
|
fd, err := os.Open(encPath)
|
|
|
|
if err != nil {
|
|
|
|
return fuse.ToStatus(err)
|
|
|
|
}
|
|
|
|
defer fd.Close()
|
|
|
|
list, err := fd.Readdirnames(10)
|
|
|
|
if err != nil {
|
|
|
|
return fuse.ToStatus(err)
|
|
|
|
}
|
|
|
|
if len(list) > 1 {
|
|
|
|
return fuse.ToStatus(syscall.ENOTEMPTY)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move "gocryptfs.diriv" to the parent dir under name "gocryptfs.diriv.rmdir.INODENUMBER"
|
|
|
|
var st syscall.Stat_t
|
|
|
|
err = syscall.Fstat(int(fd.Fd()), &st)
|
|
|
|
if err != nil {
|
|
|
|
return fuse.ToStatus(err)
|
|
|
|
}
|
|
|
|
dirivPath := filepath.Join(encPath, cryptfs.DIRIV_FILENAME)
|
|
|
|
parentDir := filepath.Dir(encPath)
|
|
|
|
tmpName := fmt.Sprintf("gocryptfs.diriv.rmdir.%d", st.Ino)
|
|
|
|
tmpDirivPath := filepath.Join(parentDir, tmpName)
|
|
|
|
cryptfs.Debug.Printf("Rmdir: Renaming %s to %s\n", cryptfs.DIRIV_FILENAME, tmpDirivPath)
|
2015-11-29 21:41:38 +01:00
|
|
|
// The directory is in an inconsistent state between rename and rmdir. Protect against
|
|
|
|
// concurrent readers.
|
|
|
|
fs.dirIVLock.Lock()
|
2015-11-27 21:48:58 +01:00
|
|
|
defer fs.dirIVLock.Unlock()
|
2015-11-25 22:17:42 +01:00
|
|
|
err = os.Rename(dirivPath, tmpDirivPath)
|
|
|
|
if err != nil {
|
|
|
|
cryptfs.Warn.Printf("Rmdir: Renaming %s to %s failed: %v\n", cryptfs.DIRIV_FILENAME, tmpDirivPath, err)
|
|
|
|
return fuse.ToStatus(err)
|
|
|
|
}
|
|
|
|
// Actual Rmdir
|
|
|
|
err = syscall.Rmdir(encPath)
|
|
|
|
if err != nil {
|
|
|
|
// This can happen if another file in the directory was created in the
|
|
|
|
// meantime, undo the rename
|
|
|
|
err2 := os.Rename(tmpDirivPath, dirivPath)
|
|
|
|
if err2 != nil {
|
|
|
|
cryptfs.Warn.Printf("Rmdir: Rollback failed: %v\n", err2)
|
|
|
|
}
|
|
|
|
return fuse.ToStatus(err)
|
|
|
|
}
|
|
|
|
// Delete "gocryptfs.diriv.rmdir.INODENUMBER"
|
|
|
|
err = syscall.Unlink(tmpDirivPath)
|
|
|
|
if err != nil {
|
|
|
|
cryptfs.Warn.Printf("Rmdir: Could not clean up %s: %v\n", tmpName, err)
|
|
|
|
}
|
2015-11-29 21:41:38 +01:00
|
|
|
// The now-deleted directory may have been in the DirIV cache. Clear it.
|
|
|
|
fs.CryptFS.DirIVCacheEnc.Clear()
|
2015-11-25 22:17:42 +01:00
|
|
|
return fuse.OK
|
2015-09-08 00:54:24 +02:00
|
|
|
}
|
|
|
|
|
2015-11-27 00:03:10 +01:00
|
|
|
func (fs *FS) Symlink(target string, linkName string, context *fuse.Context) (code fuse.Status) {
|
|
|
|
cryptfs.Debug.Printf("Symlink(\"%s\", \"%s\")\n", target, linkName)
|
2015-11-14 17:16:17 +01:00
|
|
|
if fs.CryptFS.IsFiltered(linkName) {
|
2015-11-03 22:25:29 +01:00
|
|
|
return fuse.EPERM
|
2015-11-03 00:00:13 +01:00
|
|
|
}
|
2015-11-28 16:47:30 +01:00
|
|
|
cPath, err := fs.getBackingPath(linkName)
|
2015-11-27 00:03:10 +01:00
|
|
|
if err != nil {
|
|
|
|
return fuse.ToStatus(err)
|
|
|
|
}
|
2015-11-28 16:52:57 +01:00
|
|
|
// Old filesystem: symlinks are encrypted like paths (CBC)
|
|
|
|
if !fs.args.DirIV {
|
|
|
|
cTarget, err := fs.encryptPath(target)
|
|
|
|
if err != nil {
|
|
|
|
cryptfs.Warn.Printf("Symlink: BUG: we should not get an error here: %v\n", err)
|
|
|
|
return fuse.ToStatus(err)
|
|
|
|
}
|
|
|
|
err = os.Symlink(cTarget, cPath)
|
|
|
|
return fuse.ToStatus(err)
|
|
|
|
}
|
|
|
|
// Since gocryptfs v0.5 symlinks are encrypted like file contents (GCM)
|
2015-11-27 00:03:10 +01:00
|
|
|
cBinTarget := fs.CryptFS.EncryptBlock([]byte(target), 0, nil)
|
|
|
|
cTarget := base64.URLEncoding.EncodeToString(cBinTarget)
|
|
|
|
|
2015-11-28 16:47:30 +01:00
|
|
|
err = os.Symlink(cTarget, cPath)
|
|
|
|
cryptfs.Debug.Printf("Symlink: os.Symlink(%s, %s) = %v\n", cTarget, cPath, err)
|
|
|
|
return fuse.ToStatus(err)
|
2015-09-08 00:54:24 +02:00
|
|
|
}
|
|
|
|
|
2015-11-03 22:25:29 +01:00
|
|
|
func (fs *FS) Rename(oldPath string, newPath string, context *fuse.Context) (code fuse.Status) {
|
2015-11-14 17:16:17 +01:00
|
|
|
if fs.CryptFS.IsFiltered(newPath) {
|
2015-11-03 22:25:29 +01:00
|
|
|
return fuse.EPERM
|
2015-11-03 00:00:13 +01:00
|
|
|
}
|
2015-11-27 00:03:10 +01:00
|
|
|
cOldPath, err := fs.getBackingPath(oldPath)
|
|
|
|
if err != nil {
|
|
|
|
return fuse.ToStatus(err)
|
|
|
|
}
|
|
|
|
cNewPath, err := fs.getBackingPath(newPath)
|
|
|
|
if err != nil {
|
|
|
|
return fuse.ToStatus(err)
|
|
|
|
}
|
2015-11-29 21:41:38 +01:00
|
|
|
// The Rename may cause a directory to take the place of another directory.
|
|
|
|
// That directory may still be in the DirIV cache, clear it.
|
|
|
|
fs.CryptFS.DirIVCacheEnc.Clear()
|
|
|
|
|
2015-11-27 00:03:10 +01:00
|
|
|
return fs.FileSystem.Rename(cOldPath, cNewPath, context)
|
2015-09-08 00:54:24 +02:00
|
|
|
}
|
|
|
|
|
2015-11-27 00:03:10 +01:00
|
|
|
func (fs *FS) Link(oldPath string, newPath string, context *fuse.Context) (code fuse.Status) {
|
|
|
|
if fs.CryptFS.IsFiltered(newPath) {
|
2015-11-03 22:25:29 +01:00
|
|
|
return fuse.EPERM
|
2015-11-03 00:00:13 +01:00
|
|
|
}
|
2015-11-27 00:03:10 +01:00
|
|
|
cOldPath, err := fs.getBackingPath(oldPath)
|
|
|
|
if err != nil {
|
|
|
|
return fuse.ToStatus(err)
|
|
|
|
}
|
|
|
|
cNewPath, err := fs.getBackingPath(newPath)
|
|
|
|
if err != nil {
|
|
|
|
return fuse.ToStatus(err)
|
|
|
|
}
|
|
|
|
return fuse.ToStatus(os.Link(cOldPath, cNewPath))
|
2015-09-08 00:54:24 +02:00
|
|
|
}
|
|
|
|
|
2015-11-27 00:03:10 +01:00
|
|
|
func (fs *FS) Access(path string, mode uint32, context *fuse.Context) (code fuse.Status) {
|
|
|
|
if fs.CryptFS.IsFiltered(path) {
|
2015-11-03 22:25:29 +01:00
|
|
|
return fuse.EPERM
|
|
|
|
}
|
2015-11-27 00:03:10 +01:00
|
|
|
cPath, err := fs.getBackingPath(path)
|
|
|
|
if err != nil {
|
|
|
|
return fuse.ToStatus(err)
|
|
|
|
}
|
|
|
|
return fuse.ToStatus(syscall.Access(cPath, mode))
|
2015-09-08 00:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fs *FS) GetXAttr(name string, attr string, context *fuse.Context) ([]byte, fuse.Status) {
|
|
|
|
return nil, fuse.ENOSYS
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fs *FS) SetXAttr(name string, attr string, data []byte, flags int, context *fuse.Context) fuse.Status {
|
|
|
|
return fuse.ENOSYS
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fs *FS) ListXAttr(name string, context *fuse.Context) ([]string, fuse.Status) {
|
|
|
|
return nil, fuse.ENOSYS
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fs *FS) RemoveXAttr(name string, attr string, context *fuse.Context) fuse.Status {
|
|
|
|
return fuse.ENOSYS
|
|
|
|
}
|