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