userutils

package
v0.0.0-...-fc5b1e8 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RootUser          = "root"
	RootHomeDir       = "/root"
	UserHomeDirPrefix = "/home"

	ShadowFile                = "/etc/shadow"
	PasswdFile                = "/etc/passwd"
	GroupFile                 = "/etc/group"
	SSHDirectoryName          = ".ssh"
	SSHAuthorizedKeysFileName = "authorized_keys"
)

Variables

This section is empty.

Functions

func AddUser

func AddUser(username string, homeDir string, primaryGroup string, hashedPassword string, uid string, installChroot safechroot.ChrootInterface) error

func GetUserGroups

func GetUserGroups(rootDir string, username string) ([]string, error)

func HashPassword

func HashPassword(password string) (string, error)

func NameIsValid

func NameIsValid(name string) (err error)

NameIsValid returns an error if the User name is empty

func PasswordExpiresDaysIsValid

func PasswordExpiresDaysIsValid(passwordExpiresDays int64) error

PasswordExpiresDaysISValid returns an error if the expire days is not within bounds set by the chage -M command

func UIDIsValid

func UIDIsValid(uid int) error

UIDIsValid returns an error if the UID is outside bounds UIDs 1-999 are system users and 1000-60000 are normal users Bounds can be checked using: $grep -E '^UID_MIN|^UID_MAX' /etc/login.defs

func UpdateUserPassword

func UpdateUserPassword(installRoot, username, hashedPassword string) error

func UserExists

func UserExists(username string, installChroot safechroot.ChrootInterface) (bool, error)

func UserHomeDirectory

func UserHomeDirectory(installRoot string, username string) (string, error)

UserHomeDirectory returns the home directory for a user.

func UserSSHDirectory

func UserSSHDirectory(installRoot string, username string) (string, error)

UserSSHDirectory returns the path of the .ssh directory for a user.

Types

type GroupEntry

type GroupEntry struct {
	Name     string
	Password string
	GID      int
	UserList []string
}

func ReadGroupFile

func ReadGroupFile(rootDir string) ([]GroupEntry, error)

type PasswdEntry

type PasswdEntry struct {
	Name          string
	Uid           int
	Gid           int
	Description   string
	HomeDirectory string
	Shell         string
}

func GetPasswdFileEntryForUser

func GetPasswdFileEntryForUser(rootDir string, user string) (PasswdEntry, error)

func ReadPasswdFile

func ReadPasswdFile(rootDir string) ([]PasswdEntry, error)

type ShadowEntry

type ShadowEntry struct {
	Name                     string
	EncryptedPassword        string
	LastPasswordChange       *int
	MinPasswordAge           *int
	MaxPasswordAge           *int
	PasswordWarningPeriod    *int
	PasswordInactivityPeriod *int
	AccountExpirationDate    *int
}

func GetShadowFileEntryForUser

func GetShadowFileEntryForUser(rootDir string, user string) (ShadowEntry, error)

func ReadShadowFile

func ReadShadowFile(rootDir string) ([]ShadowEntry, error)

Jump to

Keyboard shortcuts

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