Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] compaudit: avoid defining a global getent fallback
- X-seq: zsh-workers 55236
- From: "Daniel Shahaf" <d.s@xxxxxxxxxxxxxxxxxx>
- To: "Xichen Zeng" <xichenzr@xxxxxxxxx>, zsh-workers@xxxxxxx
- Subject: Re: [PATCH] compaudit: avoid defining a global getent fallback
- Date: Sun, 01 Nov 2026 07:04:13 +0000
- Archived-at: <https://zsh.org/workers/55236>
- Dkim2-signature: i=1; m=1; t=1793516734; d=daniel.shahaf.name; mf=PGQuc0BkYW5pZWwuc2hhaGFmLm5hbWU+; rt=PHpzaC13b3JrZXJzQHpzaC5vcmc+; s=fm1:rsa-sha256:ef/ucXaOFLAkdUe5PrtDAh2Oav2PpScNyoI5dkn0MZfTa/A YIfTfbXpV6JqqH+Mu1BzOEuUhFb2Qa1gyweYlCCSK1rdzSjFs/mkgmzQygaQhZUp oZ3i1x5odbyK2GduHih5cuu8IZVtErCNOP8rLMpK2Z31MZl0e6IysNOTWw1pjvoG E8yvMAZDUITOBeZO7WTCByoidw7wl9xuwope/hEtBun0WWKsnvUae3402uPMHwMO 59A76xB23p8ewhTXKcfGiDioNpbJfbo+U/Yj9/mmTaXW4wnpaQO3cTdiyzu35yNU hISR9cj9bJHwtiC9TfurwYbIwr0sPT8HxfFTItw==;
- Feedback-id: i425e4195:Fastmail
- In-reply-to: <eeb3e2dc-51fc-46f1-b833-90740ed3a34e@gmail.com>
- List-id: <zsh-workers.zsh.org>
- Message-instance: m=1; h=sha256:2FKHqdKYmMnC0wo22Uig88talX9YrKciXTqQJidvXuU=:UbC+t2UnQg3oaB4aV7DcUxP3+1y9bVo4ENzqc9YXuUI=;
- References: <eeb3e2dc-51fc-46f1-b833-90740ed3a34e@gmail.com>
Xichen Zeng wrote on Sat, 31 Oct 2026 03:38 +00:00:
> On systems without an external getent command, compaudit defines a
> global getent fallback function. This function remains after compaudit
> returns and overwrites any existing user-defined function of the same name.
Agreed that's a problem: compaudit shouldn't be in the business of
shadowing system commands or clobbering user-defined functions.
Quick review below.
> +++ b/Completion/compaudit
> @@ -15,16 +15,6 @@ compaudit() { # Define and then call
> emulate -L zsh
> setopt extendedglob
>
> -[[ -n $commands[getent] ]] || getent() {
> - if [[ $1 = hosts ]]; then
> - sed 's/#.*//' /etc/$1 | grep -w $2
> - elif [[ $2 = <-> ]]; then
> - grep ":$2:[^:]*$" /etc/$1
> - else
> - grep "^$2:" /etc/$1
> - fi
> -}
> -
> # The positional parameters are the directories to check, else fpath.
> if (( $# )); then
> local _compdir=''
> @@ -132,12 +122,19 @@ _i_wdirs=( ${^fpath}(N-f:g+w:,-f:o+w:,-^${_i_owners})
> # that this has not happened, and pick the best group.
>
> if (( $#_i_wdirs )); then
> - local GROUP GROUPMEM _i_pw _i_gid
> + local GROUP GROUPMEM _i_pw _i_gid _i_group
> if ((UID == EUID )); then
> - getent group $LOGNAME | IFS=: read GROUP _i_pw _i_gid GROUPMEM
> + _i_group=$LOGNAME
This introduces an assumption that $LOGNAME is a valid group name (or
number), which is not correct on all systems. E.g., it's not correct on
www.zsh.org.
> else
> - getent group $EGID | IFS=: read GROUP _i_pw _i_gid GROUPMEM
> + _i_group=$EGID
So, the type of $_i_group is "either group name (string) or group
number". It'd be nice to avoid this, if possible, but I wouldn't
consider it a merge blocker.
> fi
> + if [[ -n $commands[getent] ]]; then
> + getent group "$_i_group"
Shouldn't this codepath also be taken when a «getent» function is defined?
> + elif [[ $_i_group = <-> ]]; then
> + grep ":$_i_group:[^:]*$" /etc/group
If this were new code, I would suggest to:
- Use braces here in case we ever define a «:[» modifier.
- Count fields from the start of the line, rather than from the end.
However, both of these are preexisting issues from the wrapper function
this patch removes.
> + else
> + grep "^$_i_group:" /etc/group
> + fi | IFS=: read GROUP _i_pw _i_gid GROUPMEM
>
> if [[ $GROUP == $LOGNAME && ( -z $GROUPMEM || $GROUPMEM == $LOGNAME ) ]]
> then
Have you considered renaming the local «getent» function to, e.g.,
_compaudit_internal__getent, and then update the callsites to use that?
Cheers,
Daniel
Messages sorted by:
Reverse Date,
Date,
Thread,
Author