Re: [gentoo-dev] [PATCH] user.eclass: Allocate next free UID or GID from 999 downwards.

2019-07-27 Thread Michał Górny
On Sat, 2019-07-27 at 10:40 +0200, Ulrich Müller wrote:
> Fixed UIDs and GIDs are mostly located in the low range, therefore
> going downwards from 999 to 101 will minimise collisions between fixed
> and dynamically allocated IDs.
> 
> Note that on Linux and other targets using "groupadd -r" from
> sys-apps/shadow, GIDs are already allocated that way implicitly.
> 
> Signed-off-by: Ulrich Müller 
> ---
>  eclass/user.eclass | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/eclass/user.eclass b/eclass/user.eclass
> index fdf98caa6099..6563a03a1505 100644
> --- a/eclass/user.eclass
> +++ b/eclass/user.eclass
> @@ -157,10 +157,10 @@ enewuser() {
>   euid="next"
>   fi
>   if [[ ${euid} == "next" ]] ; then
> - for ((euid = 101; euid <= 999; euid++)); do
> + for ((euid = 999; euid >= 101; euid--)); do
>   [[ -z $(egetent passwd ${euid}) ]] && break
>   done
> - [[ ${euid} -le 999 ]] || die "${FUNCNAME}: no free UID found"
> + [[ ${euid} -ge 101 ]] || die "${FUNCNAME}: no free UID found"
>   fi
>   opts+=( -u ${euid} )
>   einfo " - Userid: ${euid}"
> @@ -318,10 +318,10 @@ enewgroup() {
>   _enewgroup_next_gid() {
>   if [[ ${egid} == *[!0-9]* ]] ; then
>   # Non numeric
> - for ((egid = 101; egid <= 999; egid++)) ; do
> + for ((egid = 999; egid >= 101; egid--)) ; do
>   [[ -z $(egetent group ${egid}) ]] && break
>   done
> - [[ ${egid} -le 999 ]] || die "${FUNCNAME}: no free GID 
> found"
> + [[ ${egid} -ge 101 ]] || die "${FUNCNAME}: no free GID 
> found"
>   fi
>   }
>  

LGTM.

-- 
Best regards,
Michał Górny



signature.asc
Description: This is a digitally signed message part


[gentoo-dev] [PATCH] user.eclass: Allocate next free UID or GID from 999 downwards.

2019-07-27 Thread Ulrich Müller
Fixed UIDs and GIDs are mostly located in the low range, therefore
going downwards from 999 to 101 will minimise collisions between fixed
and dynamically allocated IDs.

Note that on Linux and other targets using "groupadd -r" from
sys-apps/shadow, GIDs are already allocated that way implicitly.

Signed-off-by: Ulrich Müller 
---
 eclass/user.eclass | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/eclass/user.eclass b/eclass/user.eclass
index fdf98caa6099..6563a03a1505 100644
--- a/eclass/user.eclass
+++ b/eclass/user.eclass
@@ -157,10 +157,10 @@ enewuser() {
euid="next"
fi
if [[ ${euid} == "next" ]] ; then
-   for ((euid = 101; euid <= 999; euid++)); do
+   for ((euid = 999; euid >= 101; euid--)); do
[[ -z $(egetent passwd ${euid}) ]] && break
done
-   [[ ${euid} -le 999 ]] || die "${FUNCNAME}: no free UID found"
+   [[ ${euid} -ge 101 ]] || die "${FUNCNAME}: no free UID found"
fi
opts+=( -u ${euid} )
einfo " - Userid: ${euid}"
@@ -318,10 +318,10 @@ enewgroup() {
_enewgroup_next_gid() {
if [[ ${egid} == *[!0-9]* ]] ; then
# Non numeric
-   for ((egid = 101; egid <= 999; egid++)) ; do
+   for ((egid = 999; egid >= 101; egid--)) ; do
[[ -z $(egetent group ${egid}) ]] && break
done
-   [[ ${egid} -le 999 ]] || die "${FUNCNAME}: no free GID 
found"
+   [[ ${egid} -ge 101 ]] || die "${FUNCNAME}: no free GID 
found"
fi
}
 
-- 
2.22.0


signature.asc
Description: PGP signature