From: dana <dana@dana.is>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [PATCH] Improve _su
Date: Wed, 12 Feb 2020 15:26:21 -0600 [thread overview]
Message-ID: <8CCEA689-98B4-4396-947E-A47AA7CDEE2E@dana.is> (raw)
I was looking at _su for workers/45410 and noticed a few things:
* Fetching the user's shell often doesn't work on macOS, because normal users
don't appear in passwd; we can use Directory Service for this
* We try to use -s to set the shell even for implementations that don't
support that; we should skip those
* For the getent passwd case, we weren't escaping the user name before passing
it to eval
* For the non-getent passwd case, we were doing a prefix match on the user
name (i don't think that was intended?)
dana
diff --git a/Completion/Unix/Command/_su b/Completion/Unix/Command/_su
index 900905632..ea0beab94 100644
--- a/Completion/Unix/Command/_su
+++ b/Completion/Unix/Command/_su
@@ -58,12 +58,22 @@ fi
_arguments $args ${(e)first} "*:shell arguments:= ->rest" && return
usr=${line[norm]/--/root}
-if (( $#opt_args[(i)-(s|-shell)] )); then
+
+# Normal users generally don't appear in passwd on macOS; try the Directory
+# Service first
+if [[ $OSTYPE == darwin* ]] && (( $+commands[dscl] )); then
+ shell=${"$(
+ _call_program shells dscl . -read /Users/${(q)usr} UserShell
+ )"#UserShell: }
+fi
+
+[[ -z $shell ]] &&
+if (( ${#${(@M)args:#*-s\[*\]:*}} && $#opt_args[(i)-(s|-shell)] )); then
shell=${(v)opt_args[(i)-(s|-shell)]}
elif (( ${+commands[getent]} )); then
- shell="${$(_call_program shells getent passwd $usr)##*:}"
+ shell="${$(_call_program shells getent passwd ${(q)usr})##*:}"
else
- shell="${${(M@)${(@f)$(</etc/passwd)}:#$usr*}##*:}"
+ shell="${${(M@)${(@f)$(</etc/passwd)}:#${usr}:*}##*:}"
fi
case $state in
next reply other threads:[~2020-02-12 21:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-12 21:26 dana [this message]
2020-02-12 23:28 ` dana
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=8CCEA689-98B4-4396-947E-A47AA7CDEE2E@dana.is \
--to=dana@dana.is \
--cc=zsh-workers@zsh.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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).