perms

package
v117.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeFilePrivate

func MakeFilePrivate(filename string) (bool, error)

MakeFilePrivate ensures that the given file is accessible only by its owner. A file is considered already private if no group or other bits are set in its mode (e.g. 0600, 0400, 0500); in that case this is a no-op and the returned bool is false. If the file had looser permissions, they are tightened to 0600 and the returned bool is true. An error is returned if the file cannot be opened, if it is not a regular file, if chmod is required but the file is owned by a different user, or if chmod fails.

The file is opened with O_NOFOLLOW and subsequent stat/chmod operations use the file descriptor rather than the path, to close the TOCTOU window where the path could be replaced between operations. O_NONBLOCK prevents a FIFO planted at the config path from blocking the open indefinitely; the regular-file check below then rejects it.

func ReadPrivateFile

func ReadPrivateFile(filename string) ([]byte, error)

Read a file, first verifying that it can only be read by the current user.

func WritePrivateFile

func WritePrivateFile(filename string, content []byte) error

Make a private file that is only readable by the current user.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL