user

Imports

Imports #

"errors"
"fmt"
"os"
"syscall"
"fmt"
"os"
"runtime"
"strconv"
"errors"
"fmt"
"internal/syscall/windows"
"internal/syscall/windows/registry"
"runtime"
"syscall"
"unsafe"
"fmt"
"strconv"
"unsafe"
"syscall"
"C"
"internal/syscall/unix"
"syscall"
"C"
"strconv"
"internal/syscall/unix"
"sync"
"errors"
"fmt"
"runtime"
"strconv"
"strings"
"syscall"
"unsafe"
"bufio"
"bytes"
"errors"
"fmt"
"io"
"os"
"strconv"
"bufio"
"bytes"
"errors"
"io"
"os"
"strconv"
"strings"

Constants & Variables

_C__SC_GETGR_R_SIZE_MAX const #

const _C__SC_GETGR_R_SIZE_MAX = unix.SC_GETGR_R_SIZE_MAX

_C__SC_GETGR_R_SIZE_MAX const #

const _C__SC_GETGR_R_SIZE_MAX = C._SC_GETGR_R_SIZE_MAX

_C__SC_GETPW_R_SIZE_MAX const #

const _C__SC_GETPW_R_SIZE_MAX = C._SC_GETPW_R_SIZE_MAX

_C__SC_GETPW_R_SIZE_MAX const #

const _C__SC_GETPW_R_SIZE_MAX = unix.SC_GETPW_R_SIZE_MAX

cache var #

cache of the current user

var cache struct{...}

colon var #

var colon = []byte{...}

groupBuffer var #

var groupBuffer = 0

groupBuffer var #

var groupBuffer = *ast.CallExpr

groupBuffer var #

var groupBuffer = 0

groupBuffer var #

var groupBuffer = 0

groupFile const #

const groupFile = "/etc/group"

groupImplemented var #

These may be set to false in init() for a particular platform and/or build flags to let the tests know to skip tests of some features.

var groupImplemented = true

groupListImplemented var #

These may be set to false in init() for a particular platform and/or build flags to let the tests know to skip tests of some features.

var groupListImplemented = true

maxBufferSize const #

const maxBufferSize = *ast.BinaryExpr

maxGroups const #

const maxGroups = 2048

userBuffer var #

unused variables (in this implementation) modified during test to exercise code paths in the cgo implementation.

var userBuffer = 0

userBuffer var #

unused variables (in this implementation) modified during test to exercise code paths in the cgo implementation.

var userBuffer = 0

userBuffer var #

var userBuffer = *ast.CallExpr

userBuffer var #

unused variables (in this implementation) modified during test to exercise code paths in the cgo implementation.

var userBuffer = 0

userFile const #

const userFile = "/etc/passwd"

userImplemented var #

These may be set to false in init() for a particular platform and/or build flags to let the tests know to skip tests of some features.

var userImplemented = true

Type Aliases

UnknownGroupError type #

UnknownGroupError is returned by [LookupGroup] when a group cannot be found.

type UnknownGroupError string

UnknownGroupIdError type #

UnknownGroupIdError is returned by [LookupGroupId] when a group cannot be found.

type UnknownGroupIdError string

UnknownUserError type #

UnknownUserError is returned by [Lookup] when a user cannot be found.

type UnknownUserError string

UnknownUserIdError type #

UnknownUserIdError is returned by [LookupId] when a user cannot be found.

type UnknownUserIdError int

_C_char type #

type _C_char C.char

_C_char type #

type _C_char byte

_C_gid_t type #

type _C_gid_t uint32

_C_gid_t type #

type _C_gid_t C.gid_t

_C_int type #

type _C_int C.int

_C_int type #

type _C_int int32

_C_long type #

type _C_long int64

_C_long type #

type _C_long C.long

_C_size_t type #

type _C_size_t uintptr

_C_size_t type #

type _C_size_t C.size_t

_C_struct_group type #

type _C_struct_group unix.Group

_C_struct_group type #

type _C_struct_group C.struct_group

_C_struct_passwd type #

type _C_struct_passwd unix.Passwd

_C_struct_passwd type #

type _C_struct_passwd C.struct_passwd

_C_uid_t type #

type _C_uid_t uint32

_C_uid_t type #

type _C_uid_t C.uid_t

bufferKind type #

type bufferKind _C_int

lineFunc type #

lineFunc returns a value, an error, or (nil, nil) to skip the row.

type lineFunc func(line []byte) (v any, err error)

Structs

Group struct #

Group represents a grouping of users. On POSIX systems Gid contains a decimal number representing the group ID.

type Group struct {
Gid string
Name string
}

User struct #

User represents a user account.

type User struct {
Uid string
Gid string
Username string
Name string
HomeDir string
}

Functions

Current function #

Current returns the current user. The first call will cache the current user information. Subsequent calls will return the cached value and will not reflect changes to the current user.

func Current() (*User, error)

Error method #

func (e UnknownGroupError) Error() string

Error method #

func (e UnknownGroupIdError) Error() string

Error method #

func (e UnknownUserError) Error() string

Error method #

func (e UnknownUserIdError) Error() string

GroupIds method #

GroupIds returns the list of group IDs that the user is a member of.

func (u *User) GroupIds() ([]string, error)

Lookup function #

Lookup looks up a user by username. If the user cannot be found, the returned error is of type [UnknownUserError].

func Lookup(username string) (*User, error)

LookupGroup function #

LookupGroup looks up a group by name. If the group cannot be found, the returned error is of type [UnknownGroupError].

func LookupGroup(name string) (*Group, error)

LookupGroupId function #

LookupGroupId looks up a group by groupid. If the group cannot be found, the returned error is of type [UnknownGroupIdError].

func LookupGroupId(gid string) (*Group, error)

LookupId function #

LookupId looks up a user by userid. If the user cannot be found, the returned error is of type [UnknownUserIdError].

func LookupId(uid string) (*User, error)

_C_GoString function #

func _C_GoString(p *_C_char) string

_C_GoString function #

func _C_GoString(p *_C_char) string

_C_getgrgid_r function #

func _C_getgrgid_r(gid _C_gid_t, buf *_C_char, size _C_size_t) (grp _C_struct_group, found bool, errno syscall.Errno)

_C_getgrgid_r function #

func _C_getgrgid_r(gid _C_gid_t, buf *_C_char, size _C_size_t) (grp _C_struct_group, found bool, errno syscall.Errno)

_C_getgrnam_r function #

func _C_getgrnam_r(name *_C_char, buf *_C_char, size _C_size_t) (grp _C_struct_group, found bool, errno syscall.Errno)

_C_getgrnam_r function #

func _C_getgrnam_r(name *_C_char, buf *_C_char, size _C_size_t) (grp _C_struct_group, found bool, errno syscall.Errno)

_C_getpwnam_r function #

func _C_getpwnam_r(name *_C_char, buf *_C_char, size _C_size_t) (pwd _C_struct_passwd, found bool, errno syscall.Errno)

_C_getpwnam_r function #

func _C_getpwnam_r(name *_C_char, buf *_C_char, size _C_size_t) (pwd _C_struct_passwd, found bool, errno syscall.Errno)

_C_getpwuid_r function #

func _C_getpwuid_r(uid _C_uid_t, buf *_C_char, size _C_size_t) (pwd _C_struct_passwd, found bool, errno syscall.Errno)

_C_getpwuid_r function #

func _C_getpwuid_r(uid _C_uid_t, buf *_C_char, size _C_size_t) (pwd _C_struct_passwd, found bool, errno syscall.Errno)

_C_gr_gid function #

func _C_gr_gid(g *_C_struct_group) _C_gid_t

_C_gr_gid function #

func _C_gr_gid(g *_C_struct_group) _C_gid_t

_C_gr_name function #

func _C_gr_name(g *_C_struct_group) *_C_char

_C_gr_name function #

func _C_gr_name(g *_C_struct_group) *_C_char

_C_pw_dir function #

func _C_pw_dir(p *_C_struct_passwd) *_C_char

_C_pw_dir function #

func _C_pw_dir(p *_C_struct_passwd) *_C_char

_C_pw_gecos function #

func _C_pw_gecos(p *_C_struct_passwd) *_C_char

_C_pw_gecos function #

func _C_pw_gecos(p *_C_struct_passwd) *_C_char

_C_pw_gid function #

func _C_pw_gid(p *_C_struct_passwd) _C_gid_t

_C_pw_gid function #

func _C_pw_gid(p *_C_struct_passwd) _C_gid_t

_C_pw_gidp function #

func _C_pw_gidp(p *_C_struct_passwd) *_C_gid_t

_C_pw_gidp function #

func _C_pw_gidp(p *_C_struct_passwd) *_C_gid_t

_C_pw_name function #

func _C_pw_name(p *_C_struct_passwd) *_C_char

_C_pw_name function #

func _C_pw_name(p *_C_struct_passwd) *_C_char

_C_pw_uid function #

func _C_pw_uid(p *_C_struct_passwd) _C_uid_t

_C_pw_uid function #

func _C_pw_uid(p *_C_struct_passwd) _C_uid_t

_C_pw_uidp function #

func _C_pw_uidp(p *_C_struct_passwd) *_C_uid_t

_C_pw_uidp function #

func _C_pw_uidp(p *_C_struct_passwd) *_C_uid_t

_C_sysconf function #

func _C_sysconf(key _C_int) _C_long

_C_sysconf function #

func _C_sysconf(key _C_int) _C_long

buildGroup function #

func buildGroup(grp *_C_struct_group) *Group

buildUser function #

func buildUser(pwd *_C_struct_passwd) *User

current function #

func current() (*User, error)

current function #

func current() (*User, error)

current function #

func current() (*User, error)

current function #

func current() (*User, error)

currentGID function #

func currentGID() string

currentUID function #

func currentUID() string

findGroupId function #

func findGroupId(id string, r io.Reader) (*Group, error)

findGroupName function #

func findGroupName(name string, r io.Reader) (*Group, error)

findHomeDirInRegistry function #

findHomeDirInRegistry finds the user home path based on the uid.

func findHomeDirInRegistry(uid string) (dir string, e error)

findUserId function #

func findUserId(uid string, r io.Reader) (*User, error)

findUsername function #

func findUsername(name string, r io.Reader) (*User, error)

getCurrentToken function #

getCurrentToken returns the current thread token, or the process token if the thread doesn't have a token.

func getCurrentToken() (t syscall.Token, isProcessToken bool, err error)

getGroupList function #

func getGroupList(name *_C_char, userGID _C_gid_t, gids *_C_gid_t, n *_C_int) _C_int

getGroupList function #

func getGroupList(name *_C_char, userGID _C_gid_t, gids *_C_gid_t, n *_C_int) _C_int

getProfilesDirectory function #

getProfilesDirectory retrieves the path to the root directory where user profiles are stored.

func getProfilesDirectory() (string, error)

groupRetry function #

groupRetry retries getGroupList with much larger size for n. The result is stored in gids.

func groupRetry(username string, name []byte, userGID _C_gid_t, gids *[]_C_gid_t, n *_C_int) error

init function #

func init()

init function #

func init()

initialSize method #

func (k bufferKind) initialSize() _C_size_t

isDomainJoined function #

func isDomainJoined() (bool, error)

isServiceAccount function #

func isServiceAccount(sid *syscall.SID) bool

isSizeReasonable function #

func isSizeReasonable(sz int64) bool

isValidGroupAccountType function #

func isValidGroupAccountType(sidType uint32) bool

isValidUserAccountType function #

func isValidUserAccountType(sid *syscall.SID, sidType uint32) bool

listGroups function #

func listGroups(u *User) ([]string, error)

listGroups function #

func listGroups(*User) ([]string, error)

listGroups function #

func listGroups(u *User) ([]string, error)

listGroups function #

func listGroups(*User) ([]string, error)

listGroups function #

func listGroups(user *User) ([]string, error)

listGroupsForUsernameAndDomain function #

listGroupsForUsernameAndDomain accepts username and domain and retrieves a SID list of the local groups where this user is a member.

func listGroupsForUsernameAndDomain(username string, domain string) ([]string, error)

listGroupsFromReader function #

func listGroupsFromReader(u *User, r io.Reader) ([]string, error)

lookupFullName function #

func lookupFullName(domain string, username string, domainAndUser string) (string, error)

lookupFullNameDomain function #

func lookupFullNameDomain(domainAndUser string) (string, error)

lookupFullNameServer function #

func lookupFullNameServer(servername string, username string) (string, error)

lookupGroup function #

func lookupGroup(groupname string) (*Group, error)

lookupGroup function #

func lookupGroup(groupname string) (*Group, error)

lookupGroup function #

func lookupGroup(string) (*Group, error)

lookupGroup function #

func lookupGroup(groupname string) (*Group, error)

lookupGroup function #

func lookupGroup(groupname string) (*Group, error)

lookupGroupId function #

func lookupGroupId(string) (*Group, error)

lookupGroupId function #

func lookupGroupId(gid string) (*Group, error)

lookupGroupId function #

func lookupGroupId(id string) (*Group, error)

lookupGroupId function #

func lookupGroupId(gid string) (*Group, error)

lookupGroupId function #

func lookupGroupId(string) (*Group, error)

lookupGroupName function #

lookupGroupName accepts the name of a group and retrieves the group SID.

func lookupGroupName(groupname string) (string, error)

lookupUnixGid function #

func lookupUnixGid(gid int) (*Group, error)

lookupUnixUid function #

func lookupUnixUid(uid int) (*User, error)

lookupUser function #

func lookupUser(string) (*User, error)

lookupUser function #

func lookupUser(username string) (*User, error)

lookupUser function #

func lookupUser(username string) (*User, error)

lookupUser function #

func lookupUser(username string) (*User, error)

lookupUser function #

func lookupUser(username string) (*User, error)

lookupUserId function #

func lookupUserId(uid string) (*User, error)

lookupUserId function #

func lookupUserId(uid string) (*User, error)

lookupUserId function #

func lookupUserId(uid string) (*User, error)

lookupUserId function #

func lookupUserId(string) (*User, error)

lookupUserId function #

func lookupUserId(uid string) (*User, error)

lookupUserPrimaryGroup function #

lookupUserPrimaryGroup obtains the primary group SID for a user using this method: https://support.microsoft.com/en-us/help/297951/how-to-use-the-primarygroupid-attribute-to-find-the-primary-group-for The method follows this formula: domainRID + "-" + primaryGroupRID

func lookupUserPrimaryGroup(username string, domain string) (string, error)

lookupUsernameAndDomain function #

lookupUsernameAndDomain obtains the username and domain for usid.

func lookupUsernameAndDomain(usid *syscall.SID) (username string, domain string, sidType uint32, e error)

matchGroupIndexValue function #

func matchGroupIndexValue(value string, idx int) lineFunc

matchUserIndexValue function #

returns a *User for a row if that row's has the given value at the given index.

func matchUserIndexValue(value string, idx int) lineFunc

newUser function #

func newUser(uid string, gid string, dir string, username string, domain string) (*User, error)

newUserFromSid function #

func newUserFromSid(usid *syscall.SID) (*User, error)

readColonFile function #

readColonFile parses r as an /etc/group or /etc/passwd style file, running fn for each row. readColonFile returns a value, an error, or (nil, nil) if the end of the file is reached without a match. readCols is the minimum number of colon-separated fields that will be passed to fn; in a long line additional fields may be silently discarded.

func readColonFile(r io.Reader, fn lineFunc, readCols int) (v any, err error)

retryWithBuffer function #

retryWithBuffer repeatedly calls f(), increasing the size of the buffer each time, until f succeeds, fails with a non-ERANGE error, or the buffer exceeds a reasonable limit.

func retryWithBuffer(kind bufferKind, f func([]byte) syscall.Errno) error

runAsProcessOwner function #

runAsProcessOwner runs f in the context of the current process owner, that is, removing any impersonation that may be in effect before calling f, and restoring the impersonation afterwards.

func runAsProcessOwner(f func() error) error

structPasswdForNegativeTest function #

Because we can't use cgo in tests:

func structPasswdForNegativeTest() _C_struct_passwd

Generated with Arrow