Files
Jakob Unterwurzacher 68f4c21890 Add internal/openat.OpenSymlinkAware
OpenSymlinkAware is a symlink-aware Open/Openat2 wrapper
that can be used for implementing symlink-safe operations.

Change-Id: If2e50be8d1f217b2a4483a14c62d82d83d08ed94
2025-03-24 13:45:30 +01:00

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)
}