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 ece1acae for ; Wed, 12 Feb 2020 23:29:08 +0000 (UTC) Received: (qmail 14412 invoked by alias); 12 Feb 2020 23:29:03 -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: 45423 Received: (qmail 12186 invoked by uid 1010); 12 Feb 2020 23:29:03 -0000 X-Qmail-Scanner-Diagnostics: from mail-yb1-f196.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.196):SA:0(-1.9/5.0):. Processed in 1.705102 secs); 12 Feb 2020 23:29:03 -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.196 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:date:references:to:in-reply-to:message-id; bh=ujhVUCWevuWWYFKruUpK6OxBOxHL8OLkVrEsbKe6K9Q=; b=bswYGBsOxgTp2HSvuaUTBIhsgOLQEmjnkCp2qNXsOKCo0L4kLbBJbr2ZVANEziMIIM DoxylnqRVC/M+C+yqIQbusPRwcnuY7NDyvb2gc8sv9qAZPaiTkNBXLTtjlHVa3L9+dM9 RzkMueca2B+SRRHdDLukC1Ds1ACHKuM0A9NAxNj1AS+srkIxHTbPu/NudV5iw447QdQh PgZ1HNj6PTRmn49j7QcW3Oos4o2GfxFeHmgiU3oC7WH9Ep+ajNDVv2c470uOffnHX+Xe e4ueQ9CsRJAXqmzV0r4YFhm7ly2mhVPpN/4rYNc9+JsCI5UKWdiSQ6ROLqD3e8UiD/ix ZS9g== X-Gm-Message-State: APjAAAWZ/e67uZAvEFOwKogbGMssA1abRP8k1FN609peAStSej8FCl1g zb/uGsF+jSe1ioceJeWjIx/sBtDRSMRGeA== X-Google-Smtp-Source: APXvYqwrjJHje+yT6zoRQmWBFIdqaVGx2VUl8UMLAQURaeaPJZgLOnoYhHjoCk6vQlWWaMmVF7Hcog== X-Received: by 2002:a25:410f:: with SMTP id o15mr3208873yba.117.1581550107390; Wed, 12 Feb 2020 15:28:27 -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: Re: [PATCH] Improve _su Date: Wed, 12 Feb 2020 17:28:25 -0600 References: <8CCEA689-98B4-4396-947E-A47AA7CDEE2E@dana.is> To: Zsh hackers list In-Reply-To: <8CCEA689-98B4-4396-947E-A47AA7CDEE2E@dana.is> Message-Id: <5CBC1D1A-833E-4DCD-ACE1-1756A2735ECC@dana.is> X-Mailer: Apple Mail (2.3445.104.11) On 12 Feb 2020, at 15:26, dana wrote: > I was looking at _su for workers/45410 and noticed a few things: Sorry, noticed more things: * Short options that take optargs should use -x+ form * $_comp_priv_prefix can be used to show util-linux group options * macOS doesn't support -c * OpenBSD supports adding a log-in method after the user name; it should = be removed before looking up the shell * OpenBSD log-in methods are listed in login.conf (though i think there = are others too) dana diff --git a/Completion/Unix/Command/_su b/Completion/Unix/Command/_su index 900905632..8233296a2 100644 --- a/Completion/Unix/Command/_su +++ b/Completion/Unix/Command/_su @@ -9,36 +9,44 @@ local shell usr (( $words[(i)-(l|-login)] < CURRENT )) || args=3D( '-[use a login = shell]' ) case $OSTYPE in linux*) + # Some of these options only apply to util-linux, not shadow-utils args=3D( -S $args - '(-c --command --session-command *)'{-c,--command=3D}'[pass = command to shell]:command string:_cmdstring' + '(-c --command --session-command *)'{-c+,--command=3D}'[pass = command to shell]:command string:_cmdstring' "(-c --command *)--session-command=3D[pass command to shell and = don't create a new session]:command string:_cmdstring" '(--fast -f)'{-f,--fast}'[pass -f to shell]' '(-l --login -m -p --preserve-environment)'{-l,--login}'[use a = login shell]' '(-l --login -m -p = --preserve-environment)'{-m,-p,--preserve-environment}"[don't reset = environment]" - '(-s --shell)'{-s,--shell=3D}'[run the specified = shell]:shell:->shells' + '(-s --shell)'{-s+,--shell=3D}'[run the specified = shell]:shell:->shells' '(-)--help[display help information]' '(-)--version[display version information]' ) - (( EUID )) || args+=3D( - '(-g --group)'{-g,--group=3D}'[specify primary = group]:group:_groups' - \*{-G,--supp-group=3D}'[specify supplemental = group]:group:_groups' + (( $#_comp_priv_prefix || EUID =3D=3D 0 )) && args+=3D( + '(-g --group)'{-g+,--group=3D}'[specify primary = group]:group:_groups' + \*{-G+,--supp-group=3D}'[specify supplemental = group]:group:_groups' ) first=3D"(--help --version)${first#???}" ;; *bsd*|darwin*|dragonfly*) args+=3D( - '-c[use settings from specified login class]:class' '-f[if the invoked shell is csh, prevent it from reading .cshrc]' '(-m)-l[use a login shell]' "(-l)-m[don't reset environment]" ) ;| + *bsd*|dragonfly*) + args+=3D( + '-c+[use settings from specified login class]:class' + ) + ;| freebsd*) args+=3D( '-s[set the MAC label]' ) ;; openbsd*) args+=3D( - '(-K)-a[specify authentication type]:authentication type' + # See login.conf(5) + '(-K)-a+[specify authentication type]:authentication type:( + activ chpass crypto lchpass passwd radius reject skey snk token = yubikey + )' '(-a)-K[shorthand for -a passwd]' - '-s[run the specified shell]:shell:->shells' + '-s+[run the specified shell]:shell:->shells' '-L[loop until login succeeds]' ) ;; @@ -58,12 +66,24 @@ fi _arguments $args ${(e)first} "*:shell arguments:=3D ->rest" && return =20 usr=3D${line[norm]/--/root} -if (( $#opt_args[(i)-(s|-shell)] )); then +# OpenBSD supports appending a log-in method to the user name, as in = usr:radius +[[ $OSTYPE =3D=3D openbsd* ]] && usr=3D${usr%:*} + +# 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)$(