user

package
v0.0.0-...-28ebc5c Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GroupSerialize

func GroupSerialize(entries []GroupEntry) ([]byte, error)

GroupSerialize serializes the given group entries into the format expected at /etc/group.

func PasswdSerialize

func PasswdSerialize(entries []PasswdEntry) ([]byte, error)

PasswdSerialize serializes the given user entries into the format expected at /etc/passwd.

func ShadowEntryValidate

func ShadowEntryValidate(entry ShadowEntry) error

func ShadowSerialize

func ShadowSerialize(entries []ShadowEntry) ([]byte, error)

ShadowSerialize serializes the given shadow entries into the format expected at /etc/shadow.

Types

type AddUserOpt

type AddUserOpt struct {
	// contains filtered or unexported fields
}

AddUserOpt represents an option configuring an invocation to UpsertUser().

func OptCreateSkel

func OptCreateSkel() AddUserOpt

OptCreateSkel indicates that a skeleton homedir should be created based on /etc/skel.

func OptErrIfExists

func OptErrIfExists() AddUserOpt

OptErrIfExists will cause UpsertUser to fail if the user already exists.

func OptHomedir

func OptHomedir(dir string) AddUserOpt

OptHomedir configures the homedir for the user.

func OptNoUserGroup

func OptNoUserGroup() AddUserOpt

OptNoUserGroup indicates no user group should be created for any created user.

func OptShell

func OptShell(shell string) AddUserOpt

OptShell configures the shell for the user.

func OptSystemAccount

func OptSystemAccount() AddUserOpt

OptSystemAccount indicates any created user should use the system UID/GID ranges.

type Config

type Config struct {
	RootPath string
	// contains filtered or unexported fields
}

Config represents a static user/group configuration which can be mutated.

func ReadConfig

func ReadConfig(rootPath string) (*Config, error)

ReadConfig reads the static user/group configuration in the given filesystem root.

func (*Config) Flush

func (m *Config) Flush() error

Flush writes the config, including any modifications, to the filesystem.

func (*Config) SetPassword

func (m *Config) SetPassword(name string, pass ShadowPass) error

SetPassword sets the password on the account.

func (*Config) UpsertMembership

func (m *Config) UpsertMembership(user, group string) error

UpsertMembership adds the named user to the named group, if not already a member.

func (*Config) UpsertUser

func (m *Config) UpsertUser(name string, opts ...AddUserOpt) error

UpsertUser creates the given user if it does not exist, or updates the homedir, shell, and user info otherwise.

type GroupEntry

type GroupEntry struct {
	Name  string
	Pass  string
	ID    int
	Users []string
}

GroupEntry describes a group in an /etc/group file.

func ParseGroup

func ParseGroup(r io.Reader) ([]GroupEntry, error)

ParseGroup parses content formatted as a /etc/group file.

func (GroupEntry) String

func (g GroupEntry) String() string

type PasswdEntry

type PasswdEntry struct {
	Username  string
	Password  PasswdPass
	UID, GID  int
	UserInfo  string
	HomeDir   string
	ShellPath string
}

PasswdEntry represents a line in /etc/passwd.

func ParsePasswd

func ParsePasswd(r io.Reader) ([]PasswdEntry, error)

ParsePasswd parses content formatted as a /etc/passwd file.

func (*PasswdEntry) String

func (e *PasswdEntry) String() string

type PasswdPass

type PasswdPass struct {
	Mode PasswdPassMode
	Pass string
}

func (*PasswdPass) String

func (p *PasswdPass) String() string

type PasswdPassMode

type PasswdPassMode uint8
const (
	PassShadow PasswdPassMode = iota
	PassPlaintext
)

type ShadowEntry

type ShadowEntry struct {
	Username string
	Password ShadowPass

	LastChanged time.Time
	Expiry      time.Time

	MinChangeDays          int
	MaxChangeDays          int
	WarnBeforeMaxDays      int
	DisableAfterExpiryDays int
}

ShadowEntry describes an entry in /etc/shadow.

func ParseShadow

func ParseShadow(r io.Reader) ([]ShadowEntry, error)

ParseShadow parses content formatted as a /etc/shadow file.

func (*ShadowEntry) String

func (e *ShadowEntry) String() string

type ShadowPass

type ShadowPass struct {
	Mode      ShadowPassMode
	Encrypted string
}

ShadowPass represents the shadow configuration for a password field.

func ShadowHash

func ShadowHash(pw string) (ShadowPass, error)

ShadowHash computes the hash of the given password, returning a form which can be written into a shadow file.

func (*ShadowPass) String

func (p *ShadowPass) String() string

type ShadowPassMode

type ShadowPassMode uint8
const (
	PassEncrypted ShadowPassMode = iota
	PassNotRequired
	PassAccountDisabled
)

Valid password modes.

Jump to

Keyboard shortcuts

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