userslocking

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2025 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package userslocking implements locking of the local user and group files (/etc/passwd, /etc/groups, /etc/shadow, /etc/gshadow) via the libc lckpwdf() function.

It is recommended by systemd to hold this lock when picking a new UID/GID to avoid races, even if the new user/group is not added to the local user/group files. See https://github.com/systemd/systemd/blob/main/docs/UIDS-GIDS.md.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrLock is the error when locking the database fails.
	ErrLock = errors.New("failed to lock the shadow password database")

	// ErrUnlock is the error when unlocking the database fails.
	ErrUnlock = errors.New("failed to unlock the shadow password database")

	// ErrLockTimeout is the error when unlocking the database fails because of timeout.
	ErrLockTimeout = fmt.Errorf("%w: timeout", ErrLock)
)

Functions

func WriteLock

func WriteLock() error

WriteLock locks for writing the the local user entries database by using the standard libc lckpwdf() function. While the database is locked read operations can happen, but no other process is allowed to write. Note that this call will block all the other processes trying to access the database in write mode, while it will return an error if called while the lock is already hold by this process.

func WriteUnlock

func WriteUnlock() error

WriteUnlock unlocks for writing the local user entries database by using the standard libc ulckpwdf() function. As soon as this function is called all the other waiting processes will be allowed to take the lock.

func Z_ForTests_OverrideLocking

func Z_ForTests_OverrideLocking()

Z_ForTests_OverrideLocking is a function to override the locking functions for testing purposes. It simulates the real behavior but without actual file locking. Use Z_ForTests_RestoreLocking once done with it.

nolint:revive,nolintlint // We want to use underscores in the function name here.

func Z_ForTests_RestoreLocking

func Z_ForTests_RestoreLocking()

Z_ForTests_RestoreLocking restores the locking overridden done by Z_ForTests_OverrideLocking.

nolint:revive,nolintlint // We want to use underscores in the function name here.

Types

This section is empty.

Jump to

Keyboard shortcuts

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