accounts

package
v0.0.0-...-507ffb6 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package accounts sets up accounts and their groups for windows and linux.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddUserToGroup

func AddUserToGroup(ctx context.Context, u *User, g *Group) error

AddUserToGroup adds the user to the named group. Returns the wrapped run error if the command failed.

func CreateGroup

func CreateGroup(ctx context.Context, groupName string) error

CreateGroup creates a group with the given group name. Returns the wrapped run error if the command failed.

func CreateUser

func CreateUser(ctx context.Context, u *User) error

CreateUser creates a user with the given username. Depending on user configuration, options such as UID and GID may be ignored. If accurate information about the created user is important the caller should call FindUser after creation. Returns the wrapped run error if the command failed.

func DelUser

func DelUser(ctx context.Context, u *User) error

DelUser removes the user from the OS. Returns the wrapped run error if the command failed.

func ListGoogleUsers

func ListGoogleUsers(ctx context.Context) ([]string, error)

ListGoogleUsers lists users created by the guest agent. See googleUsersFile comment for details. Returns wrapped os errors on failure.

func RemoveUserFromGroup

func RemoveUserFromGroup(ctx context.Context, u *User, g *Group) error

RemoveUserFromGroup removes the user from the named group. Returns the run error if the command failed.

Types

type Group

type Group struct {
	// Name is the name of the group.
	Name string
	// GID is the group id of the group.
	GID string
	// Members is the list of members of the group.
	Members []string
}

Group is the common representation of a group across platforms. Redefining this structure - rather than using users.Group - makes the code more simplified avoiding one more level of indirection - the cost of converting between the two types is low (only a few places in the code).

func FindGroup

func FindGroup(ctx context.Context, groupName string) (*Group, error)

FindGroup gets the information of the group, returning ErrGroupNotExist if the group does not exist on the system. Returns the wrappe run error if the command failed.

Any group returned by this function is guaranteed to have a valid GID - a call to ValidateUnixGID() will never return an error.

func (*Group) UnixGID

func (g *Group) UnixGID() int

UnixGID returns the GID of the group as an integer.

func (*Group) ValidateUnixGID

func (g *Group) ValidateUnixGID() error

ValidateUnixGID validates the GID of the group - it determines if the set values are valid integers.

type User

type User struct {
	// Username is the username of the user.
	Username string
	// Password is the password of the user, it's meant to be used only for
	// windows - specifically for the windows password reset feature.
	Password string
	// UID is the user id of the user.
	UID string
	// GID is the group id of the user.
	GID string
	// Name is the full name of the user.
	Name string
	// HomeDir is the home directory of the user.
	HomeDir string
	// Shell is the shell of the user. It's meant to be used only for linux.
	Shell string
	// contains filtered or unexported fields
}

User is the common representation of a user across platforms.

func FindUser

func FindUser(ctx context.Context, username string) (*User, error)

FindUser gets the information of the user, returning user.UnkownUserError if the user does not exist on the system or the wrapped run error if the user list could not be obtained.

Any user returned by this function is guaranteed to have a valid UID and GID - a call to ValidateUnixIDS() will never return an error.

func (*User) SetPassword

func (u *User) SetPassword(context.Context, string) error

SetPassword sets the users password. This is unimplemented on unix.

func (*User) UnixGID

func (u *User) UnixGID() int

UnixGID returns the GID of the user as an integer.

func (*User) UnixUID

func (u *User) UnixUID() int

UnixUID returns the UID of the user as an integer.

func (*User) ValidateUnixIDS

func (u *User) ValidateUnixIDS() error

ValidateUnixIDS validates the UID and GID of the user - it determines if the set values are valid integers.

Jump to

Keyboard shortcuts

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