Documentation ¶
Index ¶
- Constants
- func Chown(f *os.File, uid UserID, gid GroupID) error
- func ChownPath(path string, uid UserID, gid GroupID) error
- func Fchown(fd int, uid UserID, gid GroupID) error
- func FchownAt(dirfd uintptr, path string, uid UserID, gid GroupID, flags int) error
- func FcntlGetFl(fd int) (int, error)
- func MockRunAsUidGidRestoreUidError(err error) (restore func())
- func RunAsUidGid(uid UserID, gid GroupID, f func() error) error
- type GroupID
- type UserID
Constants ¶
const FlagID = 1<<32 - 1
FlagID can be passed to chown-ish functions to mean "no change", and can be returned from getuid-ish functions to mean "not found".
const O_PATH = 0x200000
As of Go 1.9, the O_PATH constant does not seem to be declared uniformly over all archtiectures.
Variables ¶
This section is empty.
Functions ¶
func FcntlGetFl ¶
func MockRunAsUidGidRestoreUidError ¶
func MockRunAsUidGidRestoreUidError(err error) (restore func())
MockRunAsUidGidRestoreUidError mocks an error from the calls that restore the original euid/egid. Only ever use this in tests.
func RunAsUidGid ¶
RunAsUidGid starts a goroutine, pins it to the OS thread, sets euid and egid, and runs the function; after the function returns, it restores euid and egid.
A caveat is that any go-routine started within RunAsUidGid() will run with the original uid/gid and *not* with the passed uid/gid.
Note that on the *kernel* level the user/group ID are per-thread attributes. However POSIX require all thread to share the same credentials. This is why this code uses RawSyscall() and not the syscall.Setreuid() or similar helper.
This function does not add any security (it's not privilidge dropping), but it's useful to e.g. manipulate files with the right uids/gids.
If restoring the original euid and egid fails this function will let the os-thread die otherwise it will be reused by the runtime.
Types ¶
type GroupID ¶
type GroupID uint32
GroupID is the type of the system's group identifiers (in C, gid_t).
type UserID ¶
type UserID uint32
UserID is the type of the system's user identifiers (in C, uid_t).
We give it its own explicit type so you don't have to remember that it's a uint32 (which lead to the bug this package fixes in the first place)
func Getuid ¶
func Getuid() UserID
uid_t is an unsigned 32-bit integer in linux right now. so syscall.Gete?[ug]id are wrong, and break in 32 bits (see https://github.com/golang/go/issues/22739)