1 |
In some setups where users are changed/managed not only via ebuilds, |
2 |
for example through configuration management systems, it could be |
3 |
problematic if acct-user.eclass will restore user/group settings |
4 |
to values set in ebuild. |
5 |
|
6 |
Setting ACCT_USER_NO_MODIFY to a non-zero value will allow system |
7 |
administrator to disable modification of any existing user. |
8 |
|
9 |
Note: Lock/unlock when acct-* package will be installed/removed |
10 |
will still happen. |
11 |
|
12 |
Signed-off-by: Thomas Deutschmann <whissi@g.o> |
13 |
--- |
14 |
|
15 |
v2: Keep current behavior; Add opt-out |
16 |
|
17 |
eclass/acct-user.eclass | 25 +++++++++++++++++++++++++ |
18 |
1 file changed, 25 insertions(+) |
19 |
|
20 |
diff --git a/eclass/acct-user.eclass b/eclass/acct-user.eclass |
21 |
index 47890e48409a..560ae6b0ac90 100644 |
22 |
--- a/eclass/acct-user.eclass |
23 |
+++ b/eclass/acct-user.eclass |
24 |
@@ -72,6 +72,11 @@ readonly ACCT_USER_NAME |
25 |
# Overlays should set this to -1 to dynamically allocate UID. Using -1 |
26 |
# in ::gentoo is prohibited by policy. |
27 |
|
28 |
+# @ECLASS-VARIABLE: ACCT_USER_ALREADY_EXISTS |
29 |
+# @INTERNAL |
30 |
+# @DESCRIPTION: |
31 |
+# Status variable which indicates if user already exists. |
32 |
+ |
33 |
# @ECLASS-VARIABLE: ACCT_USER_ENFORCE_ID |
34 |
# @DESCRIPTION: |
35 |
# If set to a non-null value, the eclass will require the user to have |
36 |
@@ -79,6 +84,12 @@ readonly ACCT_USER_NAME |
37 |
# the UID is taken by another user, the install will fail. |
38 |
: ${ACCT_USER_ENFORCE_ID:=} |
39 |
|
40 |
+# @ECLASS-VARIABLE: ACCT_USER_NO_MODIFY |
41 |
+# @DESCRIPTION: |
42 |
+# If set to a non-null value, the eclass will not make any changes |
43 |
+# to an already existing user. |
44 |
+: ${ACCT_USER_NO_MODIFY:=} |
45 |
+ |
46 |
# @ECLASS-VARIABLE: ACCT_USER_SHELL |
47 |
# @DESCRIPTION: |
48 |
# The shell to use for the user. If not specified, a 'nologin' variant |
49 |
@@ -344,6 +355,13 @@ acct-user_src_install() { |
50 |
acct-user_pkg_preinst() { |
51 |
debug-print-function ${FUNCNAME} "${@}" |
52 |
|
53 |
+ # check if user already exists |
54 |
+ ACCT_USER_ALREADY_EXISTS= |
55 |
+ if [[ -n $(egetent passwd "${ACCT_USER_NAME}") ]]; then |
56 |
+ ACCT_USER_ALREADY_EXISTS=yes |
57 |
+ fi |
58 |
+ readonly ACCT_USER_ALREADY_EXISTS |
59 |
+ |
60 |
local groups=${ACCT_USER_GROUPS[*]} |
61 |
enewuser ${ACCT_USER_ENFORCE_ID:+-F} -M "${ACCT_USER_NAME}" \ |
62 |
"${ACCT_USER_ID}" "${ACCT_USER_SHELL}" "${ACCT_USER_HOME}" \ |
63 |
@@ -379,6 +397,13 @@ acct-user_pkg_postinst() { |
64 |
return 0 |
65 |
fi |
66 |
|
67 |
+ if [[ -n ${ACCT_USER_NO_MODIFY} && -n ${ACCT_USER_ALREADY_EXISTS} ]] ; then |
68 |
+ eunlockuser "${ACCT_USER_NAME}" |
69 |
+ |
70 |
+ ewarn "User ${ACCT_USER_NAME} already exists; Not touching existing user due to set ACCT_USER_NO_MODIFY." |
71 |
+ return 0 |
72 |
+ fi |
73 |
+ |
74 |
# NB: eset* functions check current value |
75 |
esethome "${ACCT_USER_NAME}" "${ACCT_USER_HOME}" |
76 |
esetshell "${ACCT_USER_NAME}" "${ACCT_USER_SHELL}" |
77 |
-- |
78 |
2.30.0 |