oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package provider
2
3import (
4 "os"
5 "path/filepath"
6
7 "golang.org/x/sys/unix"
8)
9
10// openNoLinks opens path refusing a symbolic link in any component
11// (openat2 RESOLVE_NO_SYMLINKS and RESOLVE_NO_MAGICLINKS).
12func openNoLinks(path string, flags int) (int, error) {
13 return unix.Openat2(unix.AT_FDCWD, path, &unix.OpenHow{Flags: uint64(flags), Resolve: unix.RESOLVE_NO_SYMLINKS | unix.RESOLVE_NO_MAGICLINKS})
14}
15
16// OpenBeneath opens rel beneath the open directory dir: no symbolic link
17// in any component, nothing that leaves dir (openat2 RESOLVE_BENEATH).
18// A runner reads what a model could write in (a runtime home) through it.
19func OpenBeneath(dir *os.File, rel string, flags int) (*os.File, error) {
20 fd, err := unix.Openat2(int(dir.Fd()), rel, &unix.OpenHow{Flags: uint64(flags | unix.O_CLOEXEC), Resolve: unix.RESOLVE_BENEATH | unix.RESOLVE_NO_SYMLINKS | unix.RESOLVE_NO_MAGICLINKS})
21 if err != nil {
22 return nil, err
23 }
24 return os.NewFile(uintptr(fd), filepath.Join(dir.Name(), rel)), nil
25}
26