mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-17 20:41:51 +00:00
``` $ gvt delete github.com/opencontainers/runc/libcontainer/cgroups $ gvt delete github.com/opencontainers/runc/libcontainer/configs $ gvt delete github.com/opencontainers/runc/libcontainer/system $ gvt delete github.com/opencontainers/runc/libcontainer/user $ gvt delete github.com/opencontainers/runc/libcontainer/utils $ gvt fetch --tag v1.0.0-rc5 github.com/opencontainers/runc/libcontainer 2018/07/23 17:08:18 Fetching: github.com/opencontainers/runc/libcontainer 2018/07/23 17:08:24 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/vishvananda/netlink 2018/07/23 17:08:24 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/golang.org/x/sys/unix 2018/07/23 17:08:24 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/cyphar/filepath-securejoin 2018/07/23 17:08:24 ·· Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/pkg/errors 2018/07/23 17:08:24 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/opencontainers/selinux/go-selinux/label 2018/07/23 17:08:25 ·· Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/opencontainers/selinux/go-selinux 2018/07/23 17:08:25 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/containerd/console 2018/07/23 17:08:25 ·· Fetching recursive dependency: github.com/opencontainers/runc/vendor/golang.org/x/sys/windows 2018/07/23 17:08:25 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/sirupsen/logrus 2018/07/23 17:08:25 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/godbus/dbus 2018/07/23 17:08:25 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/mrunalp/fileutils 2018/07/23 17:08:25 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/coreos/go-systemd/util 2018/07/23 17:08:25 ·· Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/coreos/pkg/dlopen 2018/07/23 17:08:25 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/golang/protobuf/proto 2018/07/23 17:08:25 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/syndtr/gocapability/capability 2018/07/23 17:08:25 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/coreos/go-systemd/dbus 2018/07/23 17:08:25 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/opencontainers/runtime-spec/specs-go 2018/07/23 17:08:25 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/seccomp/libseccomp-golang 2018/07/23 17:08:25 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/docker/go-units ```
96 lines
2.5 KiB
Go
96 lines
2.5 KiB
Go
package user
|
|
|
|
import (
|
|
"errors"
|
|
)
|
|
|
|
var (
|
|
// The current operating system does not provide the required data for user lookups.
|
|
ErrUnsupported = errors.New("user lookup: operating system does not provide passwd-formatted data")
|
|
// No matching entries found in file.
|
|
ErrNoPasswdEntries = errors.New("no matching entries in passwd file")
|
|
ErrNoGroupEntries = errors.New("no matching entries in group file")
|
|
)
|
|
|
|
func lookupUser(filter func(u User) bool) (User, error) {
|
|
// Get operating system-specific passwd reader-closer.
|
|
passwd, err := GetPasswd()
|
|
if err != nil {
|
|
return User{}, err
|
|
}
|
|
defer passwd.Close()
|
|
|
|
// Get the users.
|
|
users, err := ParsePasswdFilter(passwd, filter)
|
|
if err != nil {
|
|
return User{}, err
|
|
}
|
|
|
|
// No user entries found.
|
|
if len(users) == 0 {
|
|
return User{}, ErrNoPasswdEntries
|
|
}
|
|
|
|
// Assume the first entry is the "correct" one.
|
|
return users[0], nil
|
|
}
|
|
|
|
// LookupUser looks up a user by their username in /etc/passwd. If the user
|
|
// cannot be found (or there is no /etc/passwd file on the filesystem), then
|
|
// LookupUser returns an error.
|
|
func LookupUser(username string) (User, error) {
|
|
return lookupUser(func(u User) bool {
|
|
return u.Name == username
|
|
})
|
|
}
|
|
|
|
// LookupUid looks up a user by their user id in /etc/passwd. If the user cannot
|
|
// be found (or there is no /etc/passwd file on the filesystem), then LookupId
|
|
// returns an error.
|
|
func LookupUid(uid int) (User, error) {
|
|
return lookupUser(func(u User) bool {
|
|
return u.Uid == uid
|
|
})
|
|
}
|
|
|
|
func lookupGroup(filter func(g Group) bool) (Group, error) {
|
|
// Get operating system-specific group reader-closer.
|
|
group, err := GetGroup()
|
|
if err != nil {
|
|
return Group{}, err
|
|
}
|
|
defer group.Close()
|
|
|
|
// Get the users.
|
|
groups, err := ParseGroupFilter(group, filter)
|
|
if err != nil {
|
|
return Group{}, err
|
|
}
|
|
|
|
// No user entries found.
|
|
if len(groups) == 0 {
|
|
return Group{}, ErrNoGroupEntries
|
|
}
|
|
|
|
// Assume the first entry is the "correct" one.
|
|
return groups[0], nil
|
|
}
|
|
|
|
// LookupGroup looks up a group by its name in /etc/group. If the group cannot
|
|
// be found (or there is no /etc/group file on the filesystem), then LookupGroup
|
|
// returns an error.
|
|
func LookupGroup(groupname string) (Group, error) {
|
|
return lookupGroup(func(g Group) bool {
|
|
return g.Name == groupname
|
|
})
|
|
}
|
|
|
|
// LookupGid looks up a group by its group id in /etc/group. If the group cannot
|
|
// be found (or there is no /etc/group file on the filesystem), then LookupGid
|
|
// returns an error.
|
|
func LookupGid(gid int) (Group, error) {
|
|
return lookupGroup(func(g Group) bool {
|
|
return g.Gid == gid
|
|
})
|
|
}
|