1 |
Signed-off-by: Jérémy Connat <morderca@××××××××.net> |
2 |
--- |
3 |
eclass/acct-user.eclass | 51 ++++++++++++++++++++++++++++++++--------- |
4 |
1 file changed, 40 insertions(+), 11 deletions(-) |
5 |
|
6 |
diff --git a/eclass/acct-user.eclass b/eclass/acct-user.eclass |
7 |
index f2aaefc2ee3..c7c32086ad2 100644 |
8 |
--- a/eclass/acct-user.eclass |
9 |
+++ b/eclass/acct-user.eclass |
10 |
@@ -195,8 +195,15 @@ eislocked() { |
11 |
*) |
12 |
# NB: 'no password' and 'locked' are indistinguishable |
13 |
# but we also expire the account which is more clear |
14 |
- [[ $(getent shadow "$1" | cut -d: -f2) == '!'* ]] && |
15 |
- [[ $(getent shadow "$1" | cut -d: -f8) == 1 ]] |
16 |
+ local shadow |
17 |
+ if [[ -n "${ROOT}" ]]; then |
18 |
+ shadow=$(grep "^$1:" "${ROOT}/etc/shadow") |
19 |
+ else |
20 |
+ shadow=$(getent shadow "$1") |
21 |
+ fi |
22 |
+ |
23 |
+ [[ $( echo ${shadow} | cut -d: -f2) == '!'* ]] && |
24 |
+ [[ $(echo ${shadow} | cut -d: -f8) == 1 ]] |
25 |
;; |
26 |
esac |
27 |
} |
28 |
@@ -223,14 +230,22 @@ elockuser() { |
29 |
eislocked "$1" |
30 |
[[ $? -eq 0 ]] && return 0 |
31 |
|
32 |
+ local opts |
33 |
+ [[ -n ${ROOT} ]] && opts=( --prefix "${ROOT}" ) |
34 |
+ |
35 |
case ${CHOST} in |
36 |
*-freebsd*|*-dragonfly*) |
37 |
- pw lock "$1" || die "Locking account $1 failed" |
38 |
- pw user mod "$1" -e 1 || die "Expiring account $1 failed" |
39 |
+ pw lock "${opts[@]}" "$1" || die "Locking account $1 failed" |
40 |
+ pw user mod "${opts[@]}" "$1" -e 1 || die "Expiring account $1 failed" |
41 |
;; |
42 |
|
43 |
*-netbsd*) |
44 |
- usermod -e 1 -C yes "$1" || die "Locking account $1 failed" |
45 |
+ if [[ -n "${ROOT}" ]]; then |
46 |
+ ewarn "NetBSD's usermod does not support --prefix <dir> option." |
47 |
+ ewarn "Please use: usermod ${opts[@]} -e 1 -C yes \"$1\" in a chroot" |
48 |
+ else |
49 |
+ usermod "${opts[@]}" -e 1 -C yes "$1" || die "Locking account $1 failed" |
50 |
+ fi |
51 |
;; |
52 |
|
53 |
*-openbsd*) |
54 |
@@ -238,7 +253,7 @@ elockuser() { |
55 |
;; |
56 |
|
57 |
*) |
58 |
- usermod -e 1 -L "$1" || die "Locking account $1 failed" |
59 |
+ usermod "${opts[@]}" -e 1 -L "$1" || die "Locking account $1 failed" |
60 |
;; |
61 |
esac |
62 |
|
63 |
@@ -266,14 +281,22 @@ eunlockuser() { |
64 |
eislocked "$1" |
65 |
[[ $? -eq 1 ]] && return 0 |
66 |
|
67 |
+ local opts |
68 |
+ [[ -n ${ROOT} ]] && opts=( --prefix "${ROOT}" ) |
69 |
+ |
70 |
case ${CHOST} in |
71 |
*-freebsd*|*-dragonfly*) |
72 |
- pw user mod "$1" -e 0 || die "Unexpiring account $1 failed" |
73 |
- pw unlock "$1" || die "Unlocking account $1 failed" |
74 |
+ pw user mod "${opts[@]}" "$1" -e 0 || die "Unexpiring account $1 failed" |
75 |
+ pw unlock "${opts[@]}" "$1" || die "Unlocking account $1 failed" |
76 |
;; |
77 |
|
78 |
*-netbsd*) |
79 |
- usermod -e 0 -C no "$1" || die "Unlocking account $1 failed" |
80 |
+ if [[ -n "${ROOT}" ]]; then |
81 |
+ ewarn "NetBSD's usermod does not support --prefix <dir> option." |
82 |
+ ewarn "Please use: \"usermod ${opts[@]} -e 0 -C no $1\" in a chroot" |
83 |
+ else |
84 |
+ usermod "${opts[@]}" -e 0 -C no "$1" || die "Unlocking account $1 failed" |
85 |
+ fi |
86 |
;; |
87 |
|
88 |
*-openbsd*) |
89 |
@@ -282,7 +305,7 @@ eunlockuser() { |
90 |
|
91 |
*) |
92 |
# silence warning if account does not have a password |
93 |
- usermod -e "" -U "$1" 2>/dev/null || die "Unlocking account $1 failed" |
94 |
+ usermod "${opts[@]}" -e "" -U "$1" 2>/dev/null || die "Unlocking account $1 failed" |
95 |
;; |
96 |
esac |
97 |
|
98 |
@@ -418,7 +441,13 @@ acct-user_pkg_preinst() { |
99 |
# default ownership to user:group |
100 |
if [[ -z ${_ACCT_USER_HOME_OWNER} ]]; then |
101 |
local group_array=( ${_ACCT_USER_GROUPS} ) |
102 |
- _ACCT_USER_HOME_OWNER=${ACCT_USER_NAME}:${group_array[0]} |
103 |
+ if [[ -n "${ROOT}" ]]; then |
104 |
+ local euid=$(egetent passwd ${ACCT_USER_NAME} | cut -d: -f3) |
105 |
+ local egid=$(egetent passwd ${ACCT_USER_NAME} | cut -d: -f4) |
106 |
+ _ACCT_USER_HOME_OWNER=${euid}:${egid} |
107 |
+ else |
108 |
+ _ACCT_USER_HOME_OWNER=${ACCT_USER_NAME}:${group_array[0]} |
109 |
+ fi |
110 |
fi |
111 |
# Path might be missing due to INSTALL_MASK, etc. |
112 |
# https://bugs.gentoo.org/691478 |
113 |
-- |
114 |
2.35.1 |