syscallcompat: drop Faccessat AT_SYMLINK_NOFOLLOW helper
unix.Faccessat has added support for AT_SYMLINK_NOFOLLOW in July 2018,
bd9dbc187b (diff-341484dbbe3180cd7a31ef2ad2d679b6)
which means we no longer need our own helper.
Closes https://github.com/rfjakob/gocryptfs/issues/347
This commit is contained in:
parent
8c09df03aa
commit
0805a63df1
@ -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 = syscallcompat.Faccessat(dirfd, cName, mode)
|
||||
err = unix.Faccessat(dirfd, cName, mode, unix.AT_SYMLINK_NOFOLLOW)
|
||||
syscall.Close(dirfd)
|
||||
return fuse.ToStatus(err)
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/rfjakob/gocryptfs/internal/syscallcompat"
|
||||
"github.com/rfjakob/gocryptfs/tests/test_helpers"
|
||||
)
|
||||
|
||||
@ -46,11 +45,11 @@ func TestOpenBackingDir(t *testing.T) {
|
||||
t.Fatal("cName should be .")
|
||||
}
|
||||
|
||||
err = syscallcompat.Faccessat(dirfd, cName, unix.R_OK)
|
||||
err = unix.Faccessat(dirfd, cName, unix.R_OK, unix.AT_SYMLINK_NOFOLLOW)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
err = syscallcompat.Faccessat(dirfd, ".", unix.R_OK)
|
||||
err = unix.Faccessat(dirfd, ".", unix.R_OK, unix.AT_SYMLINK_NOFOLLOW)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -63,7 +62,7 @@ func TestOpenBackingDir(t *testing.T) {
|
||||
if cName == "" {
|
||||
t.Fatal("cName should not be empty")
|
||||
}
|
||||
err = syscallcompat.Faccessat(dirfd, cName, unix.R_OK)
|
||||
err = unix.Faccessat(dirfd, cName, unix.R_OK, unix.AT_SYMLINK_NOFOLLOW)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -76,7 +75,7 @@ func TestOpenBackingDir(t *testing.T) {
|
||||
if cName == "" {
|
||||
t.Fatal("cName should not be empty")
|
||||
}
|
||||
err = syscallcompat.Faccessat(dirfd, cName, unix.R_OK)
|
||||
err = unix.Faccessat(dirfd, cName, unix.R_OK, unix.AT_SYMLINK_NOFOLLOW)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -95,7 +94,7 @@ func TestOpenBackingDir(t *testing.T) {
|
||||
if len(cName) >= 255 {
|
||||
t.Fatalf("cName is too long: %q", cName)
|
||||
}
|
||||
err = syscallcompat.Faccessat(dirfd, cName, unix.R_OK)
|
||||
err = unix.Faccessat(dirfd, cName, unix.R_OK, unix.AT_SYMLINK_NOFOLLOW)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -126,11 +125,11 @@ func TestOpenBackingDirPlaintextNames(t *testing.T) {
|
||||
if cName != "." {
|
||||
t.Fatal("cName should be .")
|
||||
}
|
||||
err = syscallcompat.Faccessat(dirfd, cName, unix.R_OK)
|
||||
err = unix.Faccessat(dirfd, cName, unix.R_OK, unix.AT_SYMLINK_NOFOLLOW)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
err = syscallcompat.Faccessat(dirfd, ".", unix.R_OK)
|
||||
err = unix.Faccessat(dirfd, ".", unix.R_OK, unix.AT_SYMLINK_NOFOLLOW)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -143,7 +142,7 @@ func TestOpenBackingDirPlaintextNames(t *testing.T) {
|
||||
if cName != "dir1" {
|
||||
t.Fatalf("wrong cName: %q", cName)
|
||||
}
|
||||
err = syscallcompat.Faccessat(dirfd, cName, unix.R_OK)
|
||||
err = unix.Faccessat(dirfd, cName, unix.R_OK, unix.AT_SYMLINK_NOFOLLOW)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -156,7 +155,7 @@ func TestOpenBackingDirPlaintextNames(t *testing.T) {
|
||||
if cName != "dir2" {
|
||||
t.Fatalf("wrong cName: %q", cName)
|
||||
}
|
||||
err = syscallcompat.Faccessat(dirfd, cName, unix.R_OK)
|
||||
err = unix.Faccessat(dirfd, cName, unix.R_OK, unix.AT_SYMLINK_NOFOLLOW)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -255,7 +255,7 @@ func (rfs *ReverseFS) Access(relPath string, mode uint32, context *fuse.Context)
|
||||
if err != nil {
|
||||
return fuse.ToStatus(err)
|
||||
}
|
||||
err = syscallcompat.Faccessat(dirfd, name, mode)
|
||||
err = unix.Faccessat(dirfd, name, mode, unix.AT_SYMLINK_NOFOLLOW)
|
||||
syscall.Close(dirfd)
|
||||
return fuse.ToStatus(err)
|
||||
}
|
||||
|
@ -29,21 +29,6 @@ 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 {
|
||||
|
@ -11,7 +11,6 @@ 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"
|
||||
)
|
||||
|
||||
@ -159,12 +158,12 @@ func TestAccess(t *testing.T) {
|
||||
}
|
||||
for _, n := range names {
|
||||
// Check if file exists - this should never fail
|
||||
err = syscallcompat.Faccessat(unix.AT_FDCWD, dirB+"/"+n, unix.F_OK)
|
||||
err = unix.Faccessat(unix.AT_FDCWD, dirB+"/"+n, unix.F_OK, unix.AT_SYMLINK_NOFOLLOW)
|
||||
if err != nil {
|
||||
t.Errorf("%s: %v", n, err)
|
||||
}
|
||||
// Check if file is readable
|
||||
err = syscallcompat.Faccessat(unix.AT_FDCWD, dirB+"/"+n, unix.R_OK)
|
||||
err = unix.Faccessat(unix.AT_FDCWD, dirB+"/"+n, unix.R_OK, unix.AT_SYMLINK_NOFOLLOW)
|
||||
if err != nil {
|
||||
t.Logf("%s: %v", n, err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user