• [gentoo-dev] [PATCH 0/3] eclass: Fixing user/group creation when using

    From =?UTF-8?q?J=C3=A9r=C3=A9my=20Connat@21:1/5 to All on Fri Apr 15 15:50:01 2022
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit

    This is a series of patch aiming to fix a defect in acct-user/acct-group packages.

    Currently, when cross-compiling, users/groups are created in the host and not the targeted root.

    You can test this with the following commands:
    # mkdir /tmp/nroot
    # emerge --root=/tmp/nroot --sysroot=/ baselayout acct-user/postfix

    With the following patches, postfix user/group should be in /tmp/nroot/etc/{passwd,group}

    Jérémy Connat (3):
    eclass/user.eclass: Fixing user/group creation when using different
    ROOT
    eclass/user-info.eclass: Fixing user/group creation when using
    different ROOT
    eclass/acct-user.eclass: Fixing user/group creation when using
    different ROOT

    eclass/acct-user.eclass | 51 ++++++++++++----
    eclass/user-info.eclass | 35 +++++++++--
    eclass/user.eclass | 128 ++++++++++++++++++++++++++++++++++------
    3 files changed, 180 insertions(+), 34 deletions(-)

    --
    2.35.1

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?q?J=C3=A9r=C3=A9my=20Connat@21:1/5 to All on Fri Apr 15 15:50:01 2022
    Signed-off-by: Jérémy Connat <morderca@morderca.net>
    ---
    eclass/user-info.eclass | 35 +++++++++++++++++++++++++++++------
    1 file changed, 29 insertions(+), 6 deletions(-)

    diff --git a/eclass/user-info.eclass b/eclass/user-info.eclass
    index 3838585ab6c..5550e4f08ee 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}"
    ;;
    *)
  • From =?UTF-8?q?J=C3=A9r=C3=A9my=20Connat@21:1/5 to All on Fri Apr 15 15:50:01 2022
    Signed-off-by: Jérémy Connat <morderca@morderca.net>
    ---
    eclass/acct-user.eclass | 51 ++++++++++++++++++++++++++++++++---------
    1 file changed, 40 insertions(+), 11 deletions(-)

    diff --git a/eclass/acct-user.eclass b/eclass/acct-user.eclass
    index f2aaefc2ee3..c7c32086ad2 100644
    --- a/eclass/acct-user.eclass
    +++ b/eclass/acct-user.eclass
    @@ -195,8 +195,15 @@ eislocked() {
    *)
    # NB: 'no password' and 'locked' are indistinguishable
    # but we also expire the account which is more clear
    - [[ $(getent shadow "$1" | cut -d: -f2) == '!'* ]] &&
    - [[ $(getent shadow "$1" | cut -d: -f8) == 1 ]]
    + local shadow
    + if [[ -n "${ROOT}" ]]; then
    + shadow=$(grep "^$1:" "${ROOT}/etc/shadow")
    + else
    + shadow=$(getent shadow "$1")
    + fi
    +
    + [[ $( echo ${shadow} | cut -d: -f2) == '!'* ]] &&
    + [[ $(echo ${shadow} | cut -d: -f8) == 1 ]]
    ;;
    esac
    }
    @@ -223,14 +230,22 @@ elockuser() {
    eislocked "$1"
    [[ $? -eq 0 ]] && return 0

    + local opts
    + [[ -n ${ROOT} ]] && opts=( --prefix "${ROOT}" )
    +
    case ${CHOST} in
    *-freebsd*|*
  • From =?UTF-8?q?J=C3=A9r=C3=A9my=20Connat@21:1/5 to All on Fri Apr 15 15:50:01 2022
    When creating a user for another environement, user is created on the HOST and not the ROOT dir.
    Adding "-R <CHROOT_DIR>" for all user* / group* commands fix the issue.

    Signed-off-by: Jérémy Connat <morderca@morderca.net>
    ---
    eclass/user.eclass | 128 +++++++++++++++++++++++++++++++++++++++------
    1 file changed, 111 insertions(+), 17 deletions(-)

    diff --git a/eclass/user.eclass b/eclass/user.eclass
    index ff69be81c1e..aab549d0c47 100644
    --- a/eclass/user.eclass
    +++ b/eclass/user.eclass
    @@ -117,6 +117,9 @@ enewuser() {
    # options to pass to useradd
    local opts=()

    + # handle for ROOT != /
    + [[ -n ${ROOT} ]] && opts+=( --prefix "${ROOT}" )
    +
    # handle uid
    local euid=${1}; shift
    if [[ -n ${euid} && ${euid} != -1 ]] ; then
    @@ -207,13 +210,24 @@ enewuser() {
    ;;

    *-netbsd*)
    - useradd "${opts[@]}" "${euser}" || die
    + if [[ -n "${ROOT}" ]]; then
    + ewarn "NetBSD's usermod does not support --prefix option."
    + ewarn "Please use: \"useradd ${opts[@]} ${euser}\" in a chroot"
    + else
    + useradd "${opts[@]}" "${euser}" || die
    + fi
    ;;

    *-openbsd*)
    - # all ops the same, except the -g vs -g/-G ...
    - useradd -u ${euid} -s "${eshell}" \
    - -d "${ehome}" -g "${egroups}" "${euser}" || d