Gentoo Archives: gentoo-dev

From: "Ulrich Müller" <ulm@g.o>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] [PATCH] user.eclass: Allocate next free UID or GID from 999 downwards.
Date: Sat, 27 Jul 2019 08:40:46
Message-Id: w6gwog3vpj8.fsf@kph.uni-mainz.de
1 Fixed UIDs and GIDs are mostly located in the low range, therefore
2 going downwards from 999 to 101 will minimise collisions between fixed
3 and dynamically allocated IDs.
4
5 Note that on Linux and other targets using "groupadd -r" from
6 sys-apps/shadow, GIDs are already allocated that way implicitly.
7
8 Signed-off-by: Ulrich Müller <ulm@g.o>
9 ---
10 eclass/user.eclass | 8 ++++----
11 1 file changed, 4 insertions(+), 4 deletions(-)
12
13 diff --git a/eclass/user.eclass b/eclass/user.eclass
14 index fdf98caa6099..6563a03a1505 100644
15 --- a/eclass/user.eclass
16 +++ b/eclass/user.eclass
17 @@ -157,10 +157,10 @@ enewuser() {
18 euid="next"
19 fi
20 if [[ ${euid} == "next" ]] ; then
21 - for ((euid = 101; euid <= 999; euid++)); do
22 + for ((euid = 999; euid >= 101; euid--)); do
23 [[ -z $(egetent passwd ${euid}) ]] && break
24 done
25 - [[ ${euid} -le 999 ]] || die "${FUNCNAME}: no free UID found"
26 + [[ ${euid} -ge 101 ]] || die "${FUNCNAME}: no free UID found"
27 fi
28 opts+=( -u ${euid} )
29 einfo " - Userid: ${euid}"
30 @@ -318,10 +318,10 @@ enewgroup() {
31 _enewgroup_next_gid() {
32 if [[ ${egid} == *[!0-9]* ]] ; then
33 # Non numeric
34 - for ((egid = 101; egid <= 999; egid++)) ; do
35 + for ((egid = 999; egid >= 101; egid--)) ; do
36 [[ -z $(egetent group ${egid}) ]] && break
37 done
38 - [[ ${egid} -le 999 ]] || die "${FUNCNAME}: no free GID found"
39 + [[ ${egid} -ge 101 ]] || die "${FUNCNAME}: no free GID found"
40 fi
41 }
42
43 --
44 2.22.0

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies