From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id C6A67158064 for ; Thu, 9 May 2024 12:03:13 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 2D225E2B07; Thu, 9 May 2024 12:03:10 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 8009AE2AD5 for ; Thu, 9 May 2024 12:03:09 +0000 (UTC) Message-ID: Subject: Re: [gentoo-dev] [PATCH 3/4] acct-user.eclass: use an eclass variable for the override variable name From: =?UTF-8?Q?Micha=C5=82_G=C3=B3rny?= To: gentoo-dev@lists.gentoo.org Date: Thu, 09 May 2024 14:03:05 +0200 In-Reply-To: <20240509115745.5182-4-mjo@gentoo.org> References: <20240509115745.5182-1-mjo@gentoo.org> <20240509115745.5182-4-mjo@gentoo.org> Organization: Gentoo Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-wAx5Ti1kpDUMSrLGcpWP" User-Agent: Evolution 3.52.1 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 X-Archives-Salt: cbd82bd3-9acf-45d1-a60f-238501243413 X-Archives-Hash: dd378d78ef88c5ea02a0f26455f45715 --=-wAx5Ti1kpDUMSrLGcpWP Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, 2024-05-09 at 07:57 -0400, Michael Orlitzky wrote: > If (after upcasing and replacing hyphens by underscores) ACCT_USER_NAME > is set to something that isn't valid in a bash variable name, the eclass > will crash: it uses ACCT_USER_NAME to construct the make.conf override > variables in pkg_pretend() and src_install(). >=20 > This commit relocates the computation of the "override name" subsequent > to the definition of ACCT_USER_NAME=3D"${PN}". In Gentoo, policy prohibit= s > redefinition of that variable; so nothing is changed. But in an overlay, > this allows the ebuild to define ACCT_USER_NAME to something that would > not be valid in a bash variable at the expense of violating expectations > about the override variable names. >=20 > Signed-off-by: Michael Orlitzky > --- > eclass/acct-user.eclass | 32 ++++++++++++++++++++++---------- > 1 file changed, 22 insertions(+), 10 deletions(-) >=20 > diff --git a/eclass/acct-user.eclass b/eclass/acct-user.eclass > index a4fe5e9f5e34..fb3ccd2044da 100644 > --- a/eclass/acct-user.eclass > +++ b/eclass/acct-user.eclass > @@ -64,6 +64,23 @@ inherit user-info > # package naming restrictions would prohibit some otherwise-valid userna= mes. > ACCT_USER_NAME=3D${PN} > =20 > +# @ECLASS_VARIABLE: _OVERRIDE_NAME This is not prefixed correctly. > +# @INTERNAL > +# @DESCRIPTION: > +# A version of the user name suitable for use in a bash variable. This > +# is used to construct the names of the make.conf override variables and > +# it will always be uppercase $PN with the hyphens replaced by > +# underscores. It is defined once, here, so that in an overlay the > +# ebuild may set ACCT_USER_NAME to something other than $PN without > +# affecting the name of the override variable. This is necessary if the > +# username in question would lead to an invalid bash variable > +# name. Doing so does violate expectations with respect to the override > +# naming convention, but (a) your warranty is already void if you are > +# changing ACCT_USER_NAME or using make.conf overrides, and (b) you > +# shouldn't need make.conf overrides in an overlay. > +_OVERRIDE_NAME=3D${ACCT_USER_NAME^^} > +_OVERRIDE_NAME=3D${_OVERRIDE_NAME//-/_} Any reason not to just use PN directly below? After all, you need to sanitize it anyway. > + > # @ECLASS_VARIABLE: ACCT_USER_ID > # @REQUIRED > # @DESCRIPTION: > @@ -231,8 +248,7 @@ acct-user_pkg_pretend() { > local user_id=3D${ACCT_USER_ID} > =20 > # check for the override > - local override_name=3D${ACCT_USER_NAME^^} > - local override_var=3DACCT_USER_${override_name//-/_}_ID > + local override_var=3DACCT_USER_${_OVERRIDE_NAME}_ID > if [[ -n ${!override_var} ]]; then > user_id=3D${!override_var} > [[ ${user_id} -ge -1 ]] || die "${override_var}=3D${user_id} invalid!" > @@ -274,11 +290,9 @@ acct-user_src_install() { > local ACCT_USER_GROUPS=3D${ACCT_USER_GROUPS[*]} > =20 > # support make.conf overrides > - local override_name=3D${ACCT_USER_NAME^^} > - override_name=3D${override_name//-/_} > local var > for var in ACCT_USER_{ID,COMMENT,SHELL,HOME{,_OWNER,_PERMS},GROUPS}; do > - local var_name=3DACCT_USER_${override_name}_${var#ACCT_USER_} > + local var_name=3DACCT_USER_${_OVERRIDE_NAME}_${var#ACCT_USER_} > if [[ -n ${!var_name} ]]; then > ewarn "${var_name}=3D${!var_name} override in effect, support will no= t be provided." > else > @@ -286,7 +300,7 @@ acct-user_src_install() { > fi > declare -g "_${var}=3D${!var_name}" > done > - var_name=3DACCT_USER_${override_name}_GROUPS_ADD > + var_name=3DACCT_USER_${_OVERRIDE_NAME}_GROUPS_ADD > if [[ -n ${!var_name} ]]; then > ewarn "${var_name}=3D${!var_name} override in effect, support will not= be provided." > _ACCT_USER_GROUPS+=3D" ${!var_name}" > @@ -436,12 +450,10 @@ acct-user_pkg_postinst() { > has "${g}" "${groups[@]}" || del_groups+=3D"${del_groups:+, }${g}" > done > if [[ -n ${del_groups} ]]; then > - local override_name=3D${ACCT_USER_NAME^^} > - override_name=3D${override_name//-/_} > ewarn "Removing user ${ACCT_USER_NAME} from group(s): ${del_groups}" > ewarn "To retain the user's group membership in the local system" > - ewarn "config, override with ACCT_USER_${override_name}_GROUPS or" > - ewarn "ACCT_USER_${override_name}_GROUPS_ADD in make.conf." > + ewarn "config, override with ACCT_USER_${_OVERRIDE_NAME}_GROUPS or" > + ewarn "ACCT_USER_${_OVERRIDE_NAME}_GROUPS_ADD in make.conf." > ewarn "Documentation reference:" > ewarn "https://wiki.gentoo.org/wiki/Practical_guide_to_the_GLEP_81_mig= ration#Override_user_groups" > fi --=20 Best regards, Micha=C5=82 G=C3=B3rny --=-wAx5Ti1kpDUMSrLGcpWP Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- iQFGBAABCgAwFiEEx2qEUJQJjSjMiybFY5ra4jKeJA4FAmY8u3kSHG1nb3JueUBn ZW50b28ub3JnAAoJEGOa2uIyniQO+GoIAIKkBP6Pud91l3OmK0MjZkqYcNeu00fo +afEZYnt1P4t6lMzLil1PNdWWcKZMoUMGRBRkgTJc5LNEuyIpOA+iFlNpKxtLcUj A0xzBkdvhiA9yfV2qITRqpzD17nk22iFuElRsP6Wm/pkxonOVZpOOEUqWQyNlMAA VoqCS5PBcf+BJWQct2r8SF2QAN7WCJ6adkoifS+TA377xIHRitWeSYGs6H7LL0py IGABi4hIxp+xSfO1wwZh+aR8YGfzImJENWp7HBL8gJaPwLm257UKFnJEDnAl9DOD ehzEJmbScr7zVJSZ6qWaC5dMK7I+P2uOkQstrGvcrgHCAcKuLbQVyn0= =5+lG -----END PGP SIGNATURE----- --=-wAx5Ti1kpDUMSrLGcpWP--