Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] _virsh (Was: Re: zsh virsh completion)



Oliver Kiddle wrote on Thu, Jul 21, 2016 at 18:12:49 +0200:
> Marko Myllynen wrote:
> > +      _values servers ${=${(S)${${(f)$(sudo virt-admin srv-list)}##*--- }//[0-9]* }} && return 0
> 
> > +      _values servers ${=${${(f):-"$(sudo virt-admin srv-clients-list --server $srv)"}/ [a-z]*}//[^0-9]} && return 0
> 
> I have pushed the change but I've just noticed these two lines. I'm not
> sure it is a good idea to be running sudo within completion functions.
> That can trigger logging and is often denied when you're already root.
> And there may be alternatives like doas.
> 
> There's also another instance of this in Mandriva/Command/_rebootin.
> 
> Anyone, have any thoughts on how this should be handled? I'm inclined
> to think that users should have to specifically set a gain-root
> style to enable this. Or perhaps it could only trigger if you
> complete after sudo virt-admin.

In principle, I fully agree with you, with two differences:

First, in addition to 'zstyle -t … gain-root' and
'(( $+funcstack[(r)_sudo] ))' as the conditions for invoking sudo,
I think a third alternative is to use _call_program and let the user set
the 'command' style to '-sudo'.

Secondly, you don't touch on what we would do when the 'gain-root' style
is unset.  Given Marko's later email that virt-admin is not usable by
non-root users, perhaps we should do this:
.
    if (( EUID == 0 )); then
      # call 'virt-admin'
    elif The 'gain-root' or 'command' style is set; then
      # call virt-admin with sudo (or whatever the style prescribes)
    else
      _message "zsh: _libvirt: can't list completions because the 'gain-root' style is unset"
      return 1
    fi
.
?

The error message can also include the 'zstyle' incantation that sets
the style appropriately, to make it easier for the user.

Also, we should sanitize that $srv parameter before passing it to
a command run as root.  I'm not sure how virt-admin's command-line
parser works: is there any possibility for $srv to be tokenised as
anything other than the argument of the --server option?

Cheers,

Daniel

> Oliver



Messages sorted by: Reverse Date, Date, Thread, Author