summaryrefslogtreecommitdiff
path: root/eclass/user-info.eclass
diff options
context:
space:
mode:
authorV3n3RiX <venerix@koprulu.sector>2022-05-12 16:42:50 +0300
committerV3n3RiX <venerix@koprulu.sector>2022-05-12 16:42:50 +0300
commit752d6256e5204b958b0ef7905675a940b5e9172f (patch)
tree330d16e6362a49cbed8875a777fe641a43376cd3 /eclass/user-info.eclass
parent0c100b7dd2b30e75b799d806df4ef899fd98e1ea (diff)
gentoo resync : 12.05.2022
Diffstat (limited to 'eclass/user-info.eclass')
-rw-r--r--eclass/user-info.eclass35
1 files changed, 29 insertions, 6 deletions
diff --git a/eclass/user-info.eclass b/eclass/user-info.eclass
index 3838585ab6c1..5550e4f08eeb 100644
--- a/eclass/user-info.eclass
+++ b/eclass/user-info.eclass
@@ -23,6 +23,7 @@ _USER_INFO_ECLASS=1
# dscl (Mac OS X 10.5), and pw (FreeBSD) used in enewuser()/enewgroup().
#
# Supported databases: group passwd
+# Warning: This function can be used only in pkg_* phases when ROOT is valid.
egetent() {
local db=$1 key=$2
@@ -43,18 +44,31 @@ egetent() {
# lookup by uid/gid
local opts
if [[ ${key} == [[:digit:]]* ]] ; then
- [[ ${db} == "user" ]] && opts="-u" || opts="-g"
+ [[ ${db} == "user" ]] && opts=( -u ) || opts=( -g )
fi
+ # Handle different ROOT
+ [[ -n ${ROOT} ]] && opts+=( -R "${ROOT}" )
+
pw show ${db} ${opts} "${key}" -q
;;
*-openbsd*)
- grep "${key}:\*:" /etc/${db}
+ grep "${key}:\*:" "${EROOT}/etc/${db}"
;;
*)
- # ignore nscd output if we're not running as root
- type -p nscd >/dev/null && nscd -i "${db}" 2>/dev/null
- getent "${db}" "${key}"
+ # 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
+ type -p nscd >/dev/null && nscd -i "${db}" 2>/dev/null
+ getent "${db}" "${key}"
+ else
+ if [[ ${key} =~ ^[[:digit:]]+$ ]]; then
+ grep -E "^([^:]*:){2}${key}" "${ROOT}/etc/${db}"
+ else
+ grep "^${key}:" "${ROOT}/etc/${db}"
+ fi
+ fi
;;
esac
}
@@ -151,7 +165,16 @@ egetgroups() {
[[ $# -eq 1 ]] || die "usage: egetgroups <user>"
local egroups_arr
- read -r -a egroups_arr < <(id -G -n "$1")
+ 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")
+ fi
local g groups=${egroups_arr[0]}
# sort supplementary groups to make comparison possible