localentries

package
v0.5.2 Latest Latest
Warning

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

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

Documentation

Overview

Package localentries provides functions to access the local user and group database.

Package localentries provides functions to access local passwd entries.

Package localentries provides functions to retrieve passwd and group entries and to update the groups of a user.

Index

Constants

View Source
const GroupFile = "/etc/group"

GroupFile is the default local group file.

Variables

View Source
var ErrGroupNotFound = errors.New("group not found")

ErrGroupNotFound is returned when a group is not found.

View Source
var ErrUserNotFound = errors.New("user not found")

ErrUserNotFound is returned when a user is not found.

Functions

func Clean

func Clean(args ...Option) (err error)

Clean removes all unexistent users from the local groups.

func CleanUser

func CleanUser(user string, args ...Option) (err error)

CleanUser removes the user from all local groups.

func Update

func Update(username string, newGroups []string, oldGroups []string, args ...Option) (err error)

Update synchronizes for the given user the local group list with the current group list from UserInfo.

func Z_ForTests_RestoreDefaultOptions

func Z_ForTests_RestoreDefaultOptions()

Z_ForTests_RestoreDefaultOptions restores the defaultOptions to their original values.

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

func Z_ForTests_SetGpasswdCmd

func Z_ForTests_SetGpasswdCmd(gpasswdCmd []string)

Z_ForTests_SetGpasswdCmd sets the gpasswdCmd for the defaultOptions. Tests using this can't be run in parallel. Call Z_ForTests_RestoreDefaultOptions to restore the original value.

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

func Z_ForTests_SetGroupPath

func Z_ForTests_SetGroupPath(groupPath string)

Z_ForTests_SetGroupPath sets the groupPath for the defaultOptions. Tests using this can't be run in parallel. Call Z_ForTests_RestoreDefaultOptions to restore the original value.

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

Types

type Group

type Group struct {
	Name   string
	GID    uint32
	Passwd string
}

Group represents a group entry.

func GetGroupByName

func GetGroupByName(name string) (Group, error)

GetGroupByName returns the group with the given name.

func GetGroupEntries

func GetGroupEntries() ([]Group, error)

GetGroupEntries returns all group entries.

type Option

type Option func(*options)

Option represents an optional function to override UpdateLocalGroups default values.

type Passwd

type Passwd struct {
	Name  string
	UID   uint32
	Gecos string
}

Passwd represents a passwd entry.

func GetPasswdByName

func GetPasswdByName(name string) (Passwd, error)

GetPasswdByName returns the user with the given name.

func GetPasswdEntries

func GetPasswdEntries() ([]Passwd, error)

GetPasswdEntries returns all passwd entries.

Directories

Path Synopsis
Package localgrouptestutils export users test functionalities used by other packages to change cmdline and group file.
Package localgrouptestutils export users test functionalities used by other packages to change cmdline and group file.

Jump to

Keyboard shortcuts

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