From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id e4094dfa for ; Wed, 12 Feb 2020 21:27:08 +0000 (UTC) Received: (qmail 1434 invoked by alias); 12 Feb 2020 21:27:00 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45421 Received: (qmail 29056 invoked by uid 1010); 12 Feb 2020 21:27:00 -0000 X-Qmail-Scanner-Diagnostics: from mail-yb1-f170.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.1/25718. spamassassin: 3.4.2. Clear:RC:0(209.85.219.170):SA:0(-1.9/5.0):. Processed in 1.984097 secs); 12 Feb 2020 21:27:00 -0000 X-Envelope-From: dana@dana.is X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.219.170 as permitted sender) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:message-id:date:to; bh=NtPNu9cZ35h5zBjwzhUSTJxyXZkIhQgBB784akQoJMQ=; b=eFKaW7VPH9ANm62cR5CnLm4zpmMrZb+F0iJ2iVTWV6uxZ9xzOe6pDxYHJ7iYMgyiun 33jfYhKlYGocS9nz61LUDgRFh7q+SZTmUYjCwY1JFqE3yACG2golyxTcTfe583bUDOgR nJ+Oa5ky1sZwmTw8evvTHGGVUD8FQKA4veCYoME2qovO5ykCGPTHIG/wWcxpdUS8DRwf dfIG5oppsRi2QcB2PixjzM9Wao/G7K9q4dl4QYAJkrvseO24UmkhKkLLTMuFHHtU2OV+ 1Ce3hXpoYmWINuogQErtJ/6fbYVAsKLcMbrhVAYaj4WpBwaslVbyqJd812EaCmFDo7Ew Dqsw== X-Gm-Message-State: APjAAAUak86LqojwFKWp9ZiJNZKp5xzqhvnzOhLRZ9iCmm8wQyPgxkCh kmIVVGsAOFA8bPeTrJu3U4J1Pl5MugSxuA== X-Google-Smtp-Source: APXvYqy1cie7yKdNE2pp2KWitkNiICCgTKCK8lQG+qbdQFo/rMmDw4VlM1aaiYsUNh8sfyRFCY6gug== X-Received: by 2002:a25:820b:: with SMTP id q11mr13156347ybk.70.1581542784669; Wed, 12 Feb 2020 13:26:24 -0800 (PST) From: dana Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: [PATCH] Improve _su Message-Id: <8CCEA689-98B4-4396-947E-A47AA7CDEE2E@dana.is> Date: Wed, 12 Feb 2020 15:26:21 -0600 To: Zsh hackers list X-Mailer: Apple Mail (2.3445.104.11) 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:=3D ->rest" && return =20 usr=3D${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 =3D=3D darwin* ]] && (( $+commands[dscl] )); then + shell=3D${"$( + _call_program shells dscl . -read /Users/${(q)usr} UserShell + )"#UserShell: } +fi + +[[ -z $shell ]] && +if (( ${#${(@M)args:#*-s\[*\]:*}} && $#opt_args[(i)-(s|-shell)] )); = then shell=3D${(v)opt_args[(i)-(s|-shell)]} elif (( ${+commands[getent]} )); then - shell=3D"${$(_call_program shells getent passwd $usr)##*:}" + shell=3D"${$(_call_program shells getent passwd ${(q)usr})##*:}" else - shell=3D"${${(M@)${(@f)$(