mirror of
https://github.com/hanzoai/go-fuse.git
synced 2026-10-30 14:46:18 +00:00
OpenSymlinkAware is a symlink-aware Open/Openat2 wrapper that can be used for implementing symlink-safe operations. Change-Id: If2e50be8d1f217b2a4483a14c62d82d83d08ed94
16 lines
504 B
Go
16 lines
504 B
Go
//go:build !linux
|
|
|
|
package openat
|
|
|
|
import (
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
// TODO: This is insecure as O_NOFOLLOW only affects the final path component.
|
|
// See https://github.com/rfjakob/gocryptfs/issues/165 for how this could be handled.
|
|
func openatNoSymlinks(dirfd int, path string, flags int, mode uint32) (fd int, err error) {
|
|
// os/exec expects all fds to have O_CLOEXEC or it will leak them to subprocesses.
|
|
flags |= unix.O_NOFOLLOW | unix.O_CLOEXEC
|
|
return unix.Openat(dirfd, path, flags, mode)
|
|
}
|