mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-15 08:56:58 +02:00
eclass/user-info: Sync with Gentoo
It's from Gentoo commit 0e7f86f5c50d3c71371e7c6d0385b78f481c3d32.
This commit is contained in:
parent
e83a5a73bf
commit
680e1e1834
@ -5,11 +5,11 @@
|
|||||||
# @MAINTAINER:
|
# @MAINTAINER:
|
||||||
# base-system@gentoo.org (Linux)
|
# base-system@gentoo.org (Linux)
|
||||||
# Michał Górny <mgorny@gentoo.org> (NetBSD)
|
# Michał Górny <mgorny@gentoo.org> (NetBSD)
|
||||||
# @SUPPORTED_EAPIS: 6 7 8
|
# @SUPPORTED_EAPIS: 7 8
|
||||||
# @BLURB: Read-only access to user and group information
|
# @BLURB: Read-only access to user and group information
|
||||||
|
|
||||||
case ${EAPI} in
|
case ${EAPI} in
|
||||||
6|7|8) ;;
|
7|8) ;;
|
||||||
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
|
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
@ -23,6 +23,7 @@ _USER_INFO_ECLASS=1
|
|||||||
# dscl (Mac OS X 10.5), and pw (FreeBSD) used in enewuser()/enewgroup().
|
# dscl (Mac OS X 10.5), and pw (FreeBSD) used in enewuser()/enewgroup().
|
||||||
#
|
#
|
||||||
# Supported databases: group passwd
|
# Supported databases: group passwd
|
||||||
|
# Warning: This function can be used only in pkg_* phases when ROOT is valid.
|
||||||
egetent() {
|
egetent() {
|
||||||
local db=$1 key=$2
|
local db=$1 key=$2
|
||||||
|
|
||||||
@ -43,18 +44,31 @@ egetent() {
|
|||||||
# lookup by uid/gid
|
# lookup by uid/gid
|
||||||
local opts
|
local opts
|
||||||
if [[ ${key} == [[:digit:]]* ]] ; then
|
if [[ ${key} == [[:digit:]]* ]] ; then
|
||||||
[[ ${db} == "user" ]] && opts="-u" || opts="-g"
|
[[ ${db} == "user" ]] && opts=( -u ) || opts=( -g )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Handle different ROOT
|
||||||
|
[[ -n ${ROOT} ]] && opts+=( -R "${ROOT}" )
|
||||||
|
|
||||||
pw show ${db} ${opts} "${key}" -q
|
pw show ${db} ${opts} "${key}" -q
|
||||||
;;
|
;;
|
||||||
*-openbsd*)
|
*-openbsd*)
|
||||||
grep "${key}:\*:" /etc/${db}
|
grep "${key}:\*:" "${EROOT}/etc/${db}"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
# getent does not support -R option, if we are working on a different
|
||||||
|
# ROOT than /, fallback to grep technique.
|
||||||
|
if [[ -z ${ROOT} ]]; then
|
||||||
# ignore nscd output if we're not running as root
|
# ignore nscd output if we're not running as root
|
||||||
type -p nscd >/dev/null && nscd -i "${db}" 2>/dev/null
|
type -p nscd >/dev/null && nscd -i "${db}" 2>/dev/null
|
||||||
getent "${db}" "${key}"
|
getent "${db}" "${key}"
|
||||||
|
else
|
||||||
|
if [[ ${key} =~ ^[[:digit:]]+$ ]]; then
|
||||||
|
grep -E "^([^:]*:){2}${key}" "${ROOT}/etc/${db}"
|
||||||
|
else
|
||||||
|
grep "^${key}:" "${ROOT}/etc/${db}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
@ -151,7 +165,16 @@ egetgroups() {
|
|||||||
[[ $# -eq 1 ]] || die "usage: egetgroups <user>"
|
[[ $# -eq 1 ]] || die "usage: egetgroups <user>"
|
||||||
|
|
||||||
local egroups_arr
|
local egroups_arr
|
||||||
|
if [[ -n "${ROOT}" ]]; then
|
||||||
|
local pgroup=$(egetent passwd "$1" | cut -d: -f1)
|
||||||
|
local sgroups=( $(grep -E ":([^:]*,)?$1(,[^:]*)?$" "${ROOT}/etc/group" | cut -d: -f1) )
|
||||||
|
|
||||||
|
# Remove primary group from list
|
||||||
|
sgroups=${sgroups#${pgroup}}
|
||||||
|
egroups_arr=( ${pgroup} ${sgroups[@]} )
|
||||||
|
else
|
||||||
read -r -a egroups_arr < <(id -G -n "$1")
|
read -r -a egroups_arr < <(id -G -n "$1")
|
||||||
|
fi
|
||||||
|
|
||||||
local g groups=${egroups_arr[0]}
|
local g groups=${egroups_arr[0]}
|
||||||
# sort supplementary groups to make comparison possible
|
# sort supplementary groups to make comparison possible
|
||||||
|
Loading…
Reference in New Issue
Block a user