Documentation ¶
Overview ¶
Package etcpwdparse provides straightforward functionality for loading an /etc/passwd file and doing lookups on its content.
Remember this only looks at an /etc/passwd type file, so will work best on Linux operating systems and wont pick up users from LDAP and other sources.
Example ¶
// load the cache from the /etc/passwd file cache, err := NewLoadedEtcPasswdCache() if err != nil { panic(err) } // look up the current user entry, _ := cache.LookupUserByUid(os.Getuid()) // print some result fmt.Printf("Your current user is %s and your homedir is %s\n", entry.Username(), entry.Homedir())
Output:
Index ¶
- type EtcPasswdCache
- func (e *EtcPasswdCache) AddEntry(entry EtcPasswdEntry)
- func (e *EtcPasswdCache) HomeDirForUsername(name string) (string, error)
- func (e *EtcPasswdCache) ListEntries() []*EtcPasswdEntry
- func (e *EtcPasswdCache) LoadDefault() error
- func (e *EtcPasswdCache) LoadFromPath(path string) error
- func (e *EtcPasswdCache) LookupUserByName(name string) (*EtcPasswdEntry, bool)
- func (e *EtcPasswdCache) LookupUserByUid(id int) (*EtcPasswdEntry, bool)
- func (e *EtcPasswdCache) UidForUsername(name string) (int, error)
- type EtcPasswdEntry
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EtcPasswdCache ¶
type EtcPasswdCache struct {
// contains filtered or unexported fields
}
EtcPasswdCache is an object that stores a set of entries from the passwd file and has quick lookup functions.
func NewEtcPasswdCache ¶
func NewEtcPasswdCache(ignoreBadLines bool) *EtcPasswdCache
NewEtcPasswdCache returns an empty passwd cache.
func NewLoadedEtcPasswdCache ¶
func NewLoadedEtcPasswdCache() (*EtcPasswdCache, error)
NewLoadedEtcPasswdCache returns a loaded passwd cache in a single call.
func (*EtcPasswdCache) AddEntry ¶
func (e *EtcPasswdCache) AddEntry(entry EtcPasswdEntry)
AddEntry adds an entry object to the cache object and links it into the lookup maps. Overrides any existing item in the lookup maps.
func (*EtcPasswdCache) HomeDirForUsername ¶
func (e *EtcPasswdCache) HomeDirForUsername(name string) (string, error)
HomeDirForUsername is a shortcut function to get the home directory for the given username. Useful when needing to store things in the home directory.
func (*EtcPasswdCache) ListEntries ¶
func (e *EtcPasswdCache) ListEntries() []*EtcPasswdEntry
ListEntries returns a slice containing references to all the entry objects
func (*EtcPasswdCache) LoadDefault ¶
func (e *EtcPasswdCache) LoadDefault() error
LoadDefault loads the struct from the /etc/passwd file
func (*EtcPasswdCache) LoadFromPath ¶
func (e *EtcPasswdCache) LoadFromPath(path string) error
LoadFromPath loads the struct from a file on disk and replaces the cached content.
func (*EtcPasswdCache) LookupUserByName ¶
func (e *EtcPasswdCache) LookupUserByName(name string) (*EtcPasswdEntry, bool)
LookupUserByName returns the entry for the given username
func (*EtcPasswdCache) LookupUserByUid ¶
func (e *EtcPasswdCache) LookupUserByUid(id int) (*EtcPasswdEntry, bool)
LookupUserByUid returns the entry for the given userid
func (*EtcPasswdCache) UidForUsername ¶
func (e *EtcPasswdCache) UidForUsername(name string) (int, error)
UidForUsername is a shortcut function to get the user id for the given username. Useful when needing to chown a file.
type EtcPasswdEntry ¶
type EtcPasswdEntry struct {
// contains filtered or unexported fields
}
EtcPasswdEntry is a parsed line from the etc passwd file. It contains all 7 parts of the structure. Remember that the password field is encrypted or refers to an item in an alternative authentication scheme.
func ParsePasswdLine ¶
func ParsePasswdLine(line string) (EtcPasswdEntry, error)
ParsePasswdLine is a function used to parse a 7 entry /etc/passwd line formatted line into a EtcPasswdEntry object.
func (*EtcPasswdEntry) Gid ¶
func (e *EtcPasswdEntry) Gid() int
Gid function returns the group id for the entry
func (*EtcPasswdEntry) Homedir ¶
func (e *EtcPasswdEntry) Homedir() string
Homedir function returns the home directory for the entry
func (*EtcPasswdEntry) Info ¶
func (e *EtcPasswdEntry) Info() string
Info function returns the info string for the entry
func (*EtcPasswdEntry) Password ¶
func (e *EtcPasswdEntry) Password() string
Password function returns the encrypted password string for the entry
func (*EtcPasswdEntry) Shell ¶
func (e *EtcPasswdEntry) Shell() string
Shell function returns the users shell
func (*EtcPasswdEntry) Uid ¶
func (e *EtcPasswdEntry) Uid() int
Uid function returns the user id for the entry
func (*EtcPasswdEntry) Username ¶
func (e *EtcPasswdEntry) Username() string
Username function returns the username string for the entry