public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Subject: Re: [gentoo-dev] [PATCH 3/4] acct-user.eclass: use an eclass variable for the override variable name
Date: Thu, 09 May 2024 14:03:05 +0200	[thread overview]
Message-ID: <e0a8727c578443757f937006b5bfe52a90a5251b.camel@gentoo.org> (raw)
In-Reply-To: <20240509115745.5182-4-mjo@gentoo.org>

[-- Attachment #1: Type: text/plain, Size: 4686 bytes --]

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().
> 
> This commit relocates the computation of the "override name" subsequent
> to the definition of ACCT_USER_NAME="${PN}". In Gentoo, policy prohibits
> 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.
> 
> Signed-off-by: Michael Orlitzky <mjo@gentoo.org>
> ---
>  eclass/acct-user.eclass | 32 ++++++++++++++++++++++----------
>  1 file changed, 22 insertions(+), 10 deletions(-)
> 
> 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 usernames.
>  ACCT_USER_NAME=${PN}
>  
> +# @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=${ACCT_USER_NAME^^}
> +_OVERRIDE_NAME=${_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=${ACCT_USER_ID}
>  
>  	# check for the override
> -	local override_name=${ACCT_USER_NAME^^}
> -	local override_var=ACCT_USER_${override_name//-/_}_ID
> +	local override_var=ACCT_USER_${_OVERRIDE_NAME}_ID
>  	if [[ -n ${!override_var} ]]; then
>  		user_id=${!override_var}
>  		[[ ${user_id} -ge -1 ]] || die "${override_var}=${user_id} invalid!"
> @@ -274,11 +290,9 @@ acct-user_src_install() {
>  	local ACCT_USER_GROUPS=${ACCT_USER_GROUPS[*]}
>  
>  	# support make.conf overrides
> -	local override_name=${ACCT_USER_NAME^^}
> -	override_name=${override_name//-/_}
>  	local var
>  	for var in ACCT_USER_{ID,COMMENT,SHELL,HOME{,_OWNER,_PERMS},GROUPS}; do
> -		local var_name=ACCT_USER_${override_name}_${var#ACCT_USER_}
> +		local var_name=ACCT_USER_${_OVERRIDE_NAME}_${var#ACCT_USER_}
>  		if [[ -n ${!var_name} ]]; then
>  			ewarn "${var_name}=${!var_name} override in effect, support will not be provided."
>  		else
> @@ -286,7 +300,7 @@ acct-user_src_install() {
>  		fi
>  		declare -g "_${var}=${!var_name}"
>  	done
> -	var_name=ACCT_USER_${override_name}_GROUPS_ADD
> +	var_name=ACCT_USER_${_OVERRIDE_NAME}_GROUPS_ADD
>  	if [[ -n ${!var_name} ]]; then
>  		ewarn "${var_name}=${!var_name} override in effect, support will not be provided."
>  		_ACCT_USER_GROUPS+=" ${!var_name}"
> @@ -436,12 +450,10 @@ acct-user_pkg_postinst() {
>  		has "${g}" "${groups[@]}" || del_groups+="${del_groups:+, }${g}"
>  	done
>  	if [[ -n ${del_groups} ]]; then
> -		local override_name=${ACCT_USER_NAME^^}
> -		override_name=${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_migration#Override_user_groups"
>  	fi

-- 
Best regards,
Michał Górny


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 512 bytes --]

  reply	other threads:[~2024-05-09 12:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-09 11:57 [gentoo-dev] [PATCH 0/4] acct-{user,group}.eclass: make user/group names writable Michael Orlitzky
2024-05-09 11:57 ` [gentoo-dev] [PATCH 1/4] acct-user.eclass: make ACCT_USER_NAME writable Michael Orlitzky
2024-05-09 12:00   ` Michał Górny
2024-05-10  5:58     ` Ulrich Mueller
2024-05-09 11:57 ` [gentoo-dev] [PATCH 2/4] acct-group.eclass: make ACCT_GROUP_NAME writable Michael Orlitzky
2024-05-09 11:57 ` [gentoo-dev] [PATCH 3/4] acct-user.eclass: use an eclass variable for the override variable name Michael Orlitzky
2024-05-09 12:03   ` Michał Górny [this message]
2024-05-09 12:12     ` Michael Orlitzky
2024-05-09 12:41       ` Michał Górny
2024-05-09 11:57 ` [gentoo-dev] [PATCH 4/4] acct-group.eclass: " Michael Orlitzky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e0a8727c578443757f937006b5bfe52a90a5251b.camel@gentoo.org \
    --to=mgorny@gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox