1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
// Copyright (c) 2018-2019, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
package user
import (
"github.com/sylabs/singularity/v4/pkg/util/namespaces"
)
// User represents a Unix user account information.
type User struct {
Name string
UID uint32
GID uint32
Gecos string
Dir string
Shell string
}
// Group represents a Unix group information.
type Group struct {
Name string
GID uint32
}
// GetPwUID returns a pointer to User structure associated with user uid.
func GetPwUID(uid uint32) (*User, error) {
return lookupUnixUid(int(uid))
}
// GetPwNam returns a pointer to User structure associated with user name.
func GetPwNam(name string) (*User, error) {
return lookupUser(name)
}
// GetGrGID returns a pointer to Group structure associated with group gid.
func GetGrGID(gid uint32) (*Group, error) {
return lookupUnixGid(int(gid))
}
// GetGrNam returns a pointer to Group structure associated with group name.
func GetGrNam(name string) (*Group, error) {
return lookupGroup(name)
}
// Current returns a pointer to User structure associated with current user.
func Current() (*User, error) {
return current()
}
// CurrentOriginal returns a pointer to User structure associated with the
// original current user, if current user is inside a user namespace with a
// custom user mappings, it will returns information about the original user
// otherwise it returns information about the current user
func CurrentOriginal() (*User, error) {
uid, err := namespaces.HostUID()
if err != nil {
return nil, err
}
return GetPwUID(uint32(uid))
}
|