summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal/fusefrontend/fs.go2
-rw-r--r--internal/fusefrontend/openbackingdir_test.go19
-rw-r--r--internal/fusefrontend_reverse/rfs.go2
-rw-r--r--internal/syscallcompat/sys_common.go15
-rw-r--r--tests/reverse/correctness_test.go5
5 files changed, 30 insertions, 13 deletions
diff --git a/internal/fusefrontend/fs.go b/internal/fusefrontend/fs.go
index decd13f..096e663 100644
--- a/internal/fusefrontend/fs.go
+++ b/internal/fusefrontend/fs.go
@@ -626,7 +626,7 @@ func (fs *FS) Access(relPath string, mode uint32, context *fuse.Context) (code f
if err != nil {
return fuse.ToStatus(err)
}
- err = unix.Faccessat(dirfd, cName, mode, unix.AT_SYMLINK_NOFOLLOW)
+ err = syscallcompat.Faccessat(dirfd, cName, mode)
syscall.Close(dirfd)
return fuse.ToStatus(err)
}
diff --git a/internal/fusefrontend/openbackingdir_test.go b/internal/fusefrontend/openbackingdir_test.go
index 9c2358e..82cc74d 100644
--- a/internal/fusefrontend/openbackingdir_test.go
+++ b/internal/fusefrontend/openbackingdir_test.go
@@ -7,6 +7,7 @@ import (
"golang.org/x/sys/unix"
+ "github.com/rfjakob/gocryptfs/internal/syscallcompat"
"github.com/rfjakob/gocryptfs/tests/test_helpers"
)
@@ -45,11 +46,11 @@ func TestOpenBackingDir(t *testing.T) {
t.Fatal("cName should be .")
}
- err = unix.Faccessat(dirfd, cName, unix.R_OK, unix.AT_SYMLINK_NOFOLLOW)
+ err = syscallcompat.Faccessat(dirfd, cName, unix.R_OK)
if err != nil {
t.Error(err)
}
- err = unix.Faccessat(dirfd, ".", unix.R_OK, unix.AT_SYMLINK_NOFOLLOW)
+ err = syscallcompat.Faccessat(dirfd, ".", unix.R_OK)
if err != nil {
t.Error(err)
}
@@ -62,7 +63,7 @@ func TestOpenBackingDir(t *testing.T) {
if cName == "" {
t.Fatal("cName should not be empty")
}
- err = unix.Faccessat(dirfd, cName, unix.R_OK, unix.AT_SYMLINK_NOFOLLOW)
+ err = syscallcompat.Faccessat(dirfd, cName, unix.R_OK)
if err != nil {
t.Error(err)
}
@@ -75,7 +76,7 @@ func TestOpenBackingDir(t *testing.T) {
if cName == "" {
t.Fatal("cName should not be empty")
}
- err = unix.Faccessat(dirfd, cName, unix.R_OK, unix.AT_SYMLINK_NOFOLLOW)
+ err = syscallcompat.Faccessat(dirfd, cName, unix.R_OK)
if err != nil {
t.Error(err)
}
@@ -94,7 +95,7 @@ func TestOpenBackingDir(t *testing.T) {
if len(cName) >= 255 {
t.Fatalf("cName is too long: %q", cName)
}
- err = unix.Faccessat(dirfd, cName, unix.R_OK, unix.AT_SYMLINK_NOFOLLOW)
+ err = syscallcompat.Faccessat(dirfd, cName, unix.R_OK)
if err != nil {
t.Error(err)
}
@@ -125,11 +126,11 @@ func TestOpenBackingDirPlaintextNames(t *testing.T) {
if cName != "." {
t.Fatal("cName should be .")
}
- err = unix.Faccessat(dirfd, cName, unix.R_OK, unix.AT_SYMLINK_NOFOLLOW)
+ err = syscallcompat.Faccessat(dirfd, cName, unix.R_OK)
if err != nil {
t.Error(err)
}
- err = unix.Faccessat(dirfd, ".", unix.R_OK, unix.AT_SYMLINK_NOFOLLOW)
+ err = syscallcompat.Faccessat(dirfd, ".", unix.R_OK)
if err != nil {
t.Error(err)
}
@@ -142,7 +143,7 @@ func TestOpenBackingDirPlaintextNames(t *testing.T) {
if cName != "dir1" {
t.Fatalf("wrong cName: %q", cName)
}
- err = unix.Faccessat(dirfd, cName, unix.R_OK, unix.AT_SYMLINK_NOFOLLOW)
+ err = syscallcompat.Faccessat(dirfd, cName, unix.R_OK)
if err != nil {
t.Error(err)
}
@@ -155,7 +156,7 @@ func TestOpenBackingDirPlaintextNames(t *testing.T) {
if cName != "dir2" {
t.Fatalf("wrong cName: %q", cName)
}
- err = unix.Faccessat(dirfd, cName, unix.R_OK, unix.AT_SYMLINK_NOFOLLOW)
+ err = syscallcompat.Faccessat(dirfd, cName, unix.R_OK)
if err != nil {
t.Error(err)
}
diff --git a/internal/fusefrontend_reverse/rfs.go b/internal/fusefrontend_reverse/rfs.go
index 28b20f8..6ee10fc 100644
--- a/internal/fusefrontend_reverse/rfs.go
+++ b/internal/fusefrontend_reverse/rfs.go
@@ -255,7 +255,7 @@ func (rfs *ReverseFS) Access(relPath string, mode uint32, context *fuse.Context)
if err != nil {
return fuse.ToStatus(err)
}
- err = unix.Faccessat(dirfd, name, mode, unix.AT_SYMLINK_NOFOLLOW)
+ err = syscallcompat.Faccessat(dirfd, name, mode)
syscall.Close(dirfd)
return fuse.ToStatus(err)
}
diff --git a/internal/syscallcompat/sys_common.go b/internal/syscallcompat/sys_common.go
index aedc4da..b6bbdff 100644
--- a/internal/syscallcompat/sys_common.go
+++ b/internal/syscallcompat/sys_common.go
@@ -29,6 +29,21 @@ func Readlinkat(dirfd int, path string) (string, error) {
}
}
+// Faccessat exists both in Linux and in MacOS 10.10+, but the Linux version
+// DOES NOT support any flags. Emulate AT_SYMLINK_NOFOLLOW like glibc does.
+func Faccessat(dirfd int, path string, mode uint32) error {
+ var st unix.Stat_t
+ err := Fstatat(dirfd, path, &st, unix.AT_SYMLINK_NOFOLLOW)
+ if err != nil {
+ return err
+ }
+ if st.Mode&syscall.S_IFMT == syscall.S_IFLNK {
+ // Pretend that a symlink is always accessible
+ return nil
+ }
+ return unix.Faccessat(dirfd, path, mode, 0)
+}
+
// Openat wraps the Openat syscall.
func Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error) {
if flags&syscall.O_CREAT != 0 {
diff --git a/tests/reverse/correctness_test.go b/tests/reverse/correctness_test.go
index 77a9056..931be42 100644
--- a/tests/reverse/correctness_test.go
+++ b/tests/reverse/correctness_test.go
@@ -11,6 +11,7 @@ import (
"golang.org/x/sys/unix"
"github.com/rfjakob/gocryptfs/internal/ctlsock"
+ "github.com/rfjakob/gocryptfs/internal/syscallcompat"
"github.com/rfjakob/gocryptfs/tests/test_helpers"
)
@@ -158,12 +159,12 @@ func TestAccess(t *testing.T) {
}
for _, n := range names {
// Check if file exists - this should never fail
- err = unix.Faccessat(unix.AT_FDCWD, dirB+"/"+n, unix.F_OK, unix.AT_SYMLINK_NOFOLLOW)
+ err = syscallcompat.Faccessat(unix.AT_FDCWD, dirB+"/"+n, unix.F_OK)
if err != nil {
t.Errorf("%s: %v", n, err)
}
// Check if file is readable
- err = unix.Faccessat(unix.AT_FDCWD, dirB+"/"+n, unix.R_OK, unix.AT_SYMLINK_NOFOLLOW)
+ err = syscallcompat.Faccessat(unix.AT_FDCWD, dirB+"/"+n, unix.R_OK)
if err != nil {
t.Logf("%s: %v", n, err)
}