2011-05-20 02:18:15 +02:00
|
|
|
// Copyright 2011 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// Package user allows user account lookups by name or id.
|
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
2016-07-22 20:15:38 +02:00
|
|
|
var (
|
|
|
|
userImplemented = true // set to false by lookup_stubs.go's init
|
|
|
|
groupImplemented = true // set to false by lookup_stubs.go's init
|
|
|
|
)
|
2011-09-16 17:47:21 +02:00
|
|
|
|
2011-05-20 02:18:15 +02:00
|
|
|
// User represents a user account.
|
|
|
|
type User struct {
|
2017-01-14 01:05:42 +01:00
|
|
|
// Uid is the user ID.
|
|
|
|
// On POSIX systems, this is a decimal number representing the uid.
|
|
|
|
// On Windows, this is a security identifier (SID) in a string format.
|
|
|
|
// On Plan 9, this is the contents of /dev/user.
|
|
|
|
Uid string
|
|
|
|
// Gid is the primary group ID.
|
|
|
|
// On POSIX systems, this is a decimal number representing the gid.
|
|
|
|
// On Windows, this is a SID in a string format.
|
|
|
|
// On Plan 9, this is the contents of /dev/user.
|
|
|
|
Gid string
|
|
|
|
// Username is the login name.
|
2011-05-20 02:18:15 +02:00
|
|
|
Username string
|
2017-01-14 01:05:42 +01:00
|
|
|
// Name is the user's real or display name.
|
|
|
|
// It might be blank.
|
|
|
|
// On POSIX systems, this is the first (or only) entry in the GECOS field
|
|
|
|
// list.
|
|
|
|
// On Windows, this is the user's display name.
|
|
|
|
// On Plan 9, this is the contents of /dev/user.
|
|
|
|
Name string
|
|
|
|
// HomeDir is the path to the user's home directory (if they have one).
|
|
|
|
HomeDir string
|
2011-05-20 02:18:15 +02:00
|
|
|
}
|
|
|
|
|
2016-07-22 20:15:38 +02:00
|
|
|
// Group represents a grouping of users.
|
|
|
|
//
|
2017-01-14 01:05:42 +01:00
|
|
|
// On POSIX systems Gid contains a decimal number representing the group ID.
|
2016-07-22 20:15:38 +02:00
|
|
|
type Group struct {
|
|
|
|
Gid string // group ID
|
|
|
|
Name string // group name
|
|
|
|
}
|
|
|
|
|
2017-01-14 01:05:42 +01:00
|
|
|
// UnknownUserIdError is returned by LookupId when a user cannot be found.
|
2011-05-20 02:18:15 +02:00
|
|
|
type UnknownUserIdError int
|
|
|
|
|
2011-12-03 03:17:34 +01:00
|
|
|
func (e UnknownUserIdError) Error() string {
|
2011-05-20 02:18:15 +02:00
|
|
|
return "user: unknown userid " + strconv.Itoa(int(e))
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnknownUserError is returned by Lookup when
|
|
|
|
// a user cannot be found.
|
|
|
|
type UnknownUserError string
|
|
|
|
|
2011-12-03 03:17:34 +01:00
|
|
|
func (e UnknownUserError) Error() string {
|
2011-05-20 02:18:15 +02:00
|
|
|
return "user: unknown user " + string(e)
|
|
|
|
}
|
2016-07-22 20:15:38 +02:00
|
|
|
|
|
|
|
// UnknownGroupIdError is returned by LookupGroupId when
|
|
|
|
// a group cannot be found.
|
|
|
|
type UnknownGroupIdError string
|
|
|
|
|
|
|
|
func (e UnknownGroupIdError) Error() string {
|
|
|
|
return "group: unknown groupid " + string(e)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnknownGroupError is returned by LookupGroup when
|
|
|
|
// a group cannot be found.
|
|
|
|
type UnknownGroupError string
|
|
|
|
|
|
|
|
func (e UnknownGroupError) Error() string {
|
|
|
|
return "group: unknown group " + string(e)
|
|
|
|
}
|