GNU bug report logs -
#68074
eshell sudo/doas does not work for aliases
Previous Next
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 68074 in the body.
You can then email your comments to 68074 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#68074
; Package
emacs
.
(Thu, 28 Dec 2023 04:14:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Alfonso Sanchez-Beato <alfonsosanchezbeato <at> yahoo.es>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Thu, 28 Dec 2023 04:14:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
sudo/doas does not give the expected permissions when using an eshell alias:
When no alias has been defined:
~ $ which cp
eshell/cp is a native-compiled Lisp function in ‘em-unix.el’.
~ $ touch test
~ $ cp test /boot/efi/
Opening output file: Permission denied, /boot/efi/test
~ $ sudo cp test /boot/efi/
~ $ echo $?
0
But after defining the alias:
~ $ alias cp '*cp $*'
~ $ which cp
cp is an alias, defined as "*cp $*"
~ $ sudo cp test /boot/efi/
/usr/bin/cp: cannot stat '/boot/efi/test': Permission denied
I have attached a patch with a possible fix.
[0001-lisp-eshell-em-alias.el-eshell-maybe-replace-by-alia.patch (text/x-patch, attachment)]
Added tag(s) patch.
Request was from
Stefan Kangas <stefankangas <at> gmail.com>
to
control <at> debbugs.gnu.org
.
(Wed, 10 Jan 2024 17:33:03 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#68074
; Package
emacs
.
(Thu, 11 Jan 2024 21:01:02 GMT)
Full text and
rfc822 format available.
Message #10 received at 68074 <at> debbugs.gnu.org (full text, mbox):
Alfonso Sanchez-Beato <alfonsosanchezbeato <at> yahoo.es> writes:
> sudo/doas does not give the expected permissions when using an eshell alias:
>
> When no alias has been defined:
>
> ~ $ which cp
> eshell/cp is a native-compiled Lisp function in ‘em-unix.el’.
> ~ $ touch test
> ~ $ cp test /boot/efi/
> Opening output file: Permission denied, /boot/efi/test
> ~ $ sudo cp test /boot/efi/
> ~ $ echo $?
> 0
>
> But after defining the alias:
>
> ~ $ alias cp '*cp $*'
> ~ $ which cp
> cp is an alias, defined as "*cp $*"
> ~ $ sudo cp test /boot/efi/
> /usr/bin/cp: cannot stat '/boot/efi/test': Permission denied
>
> I have attached a patch with a possible fix.
Jim, could you take a look at this patch please?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#68074
; Package
emacs
.
(Thu, 11 Jan 2024 21:16:01 GMT)
Full text and
rfc822 format available.
Message #13 received at 68074 <at> debbugs.gnu.org (full text, mbox):
On 1/11/2024 1:00 PM, Stefan Kangas wrote:
> Alfonso Sanchez-Beato <alfonsosanchezbeato <at> yahoo.es> writes:
>
>> sudo/doas does not give the expected permissions when using an eshell alias:
[snip]
>> I have attached a patch with a possible fix.
>
> Jim, could you take a look at this patch please?
I've been meaning to look at this in detail, but haven't had time. My
gut feeling though is that we shouldn't have a special case in this code
for when the alias starts with "cd". I'll have to do some testing with
aliases and sudo in order to have a more-helpful answer though.
At a guess, I think a better place to add code for this is likely in
em-tramp.el.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#68074
; Package
emacs
.
(Thu, 25 Jan 2024 02:44:02 GMT)
Full text and
rfc822 format available.
Message #16 received at 68074 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On 1/11/2024 1:15 PM, Jim Porter wrote:
> I've been meaning to look at this in detail, but haven't had time. My
> gut feeling though is that we shouldn't have a special case in this code
> for when the alias starts with "cd". I'll have to do some testing with
> aliases and sudo in order to have a more-helpful answer though.
>
> At a guess, I think a better place to add code for this is likely in
> em-tramp.el.
After letting this percolate in my brain for a few weeks, the answer
revealed itself to me: the functions in "em-tramp.el" shouldn't throw
'eshell-external', they should throw 'eshell-replace-command'. That
allows for a two-step command replacement in this case. First,
'eshell/sudo' (or 'eshell/doas') will do its replacement. Then, Eshell
will evaluate that and call the inner command, which will do another
replacement to expand the alias.
Alfonso, does the attached patch work for you? If so, I'll merge it to
master.
[0001-Fix-command-replacement-with-the-Eshell-builtin-vers.patch (text/plain, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#68074
; Package
emacs
.
(Fri, 26 Jan 2024 23:54:01 GMT)
Full text and
rfc822 format available.
Message #19 received at 68074 <at> debbugs.gnu.org (full text, mbox):
En jueves, 25 de enero de 2024, 02:43:46 GMT, Jim Porter <jporterbugs <at> gmail.com> escribió:
On 1/11/2024 1:15 PM, Jim Porter wrote:
>> I've been meaning to look at this in detail, but haven't had time. My
>> gut feeling though is that we shouldn't have a special case in this code
>> for when the alias starts with "cd". I'll have to do some testing with
>> aliases and sudo in order to have a more-helpful answer though.
>>
>> At a guess, I think a better place to add code for this is likely in
>> em-tramp.el.
> After letting this percolate in my brain for a few weeks, the answer
> revealed itself to me: the functions in "em-tramp.el" shouldn't throw
> 'eshell-external', they should throw 'eshell-replace-command'. That
> allows for a two-step command replacement in this case. First,
> 'eshell/sudo' (or 'eshell/doas') will do its replacement. Then, Eshell
> will evaluate that and call the inner command, which will do another
> replacement to expand the alias.
> Alfonso, does the attached patch work for you? If so, I'll merge it to
> master.
Unfortunately that does not seem to be the case, I see an error saying "Invalid function" after applying on top of current master:
$ which cp
cp is an alias, defined as "*cp $*"
$ touch foo
$ eshell/sudo cp foo /
Invalid function: "foo"
[1] $
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#68074
; Package
emacs
.
(Sat, 27 Jan 2024 00:29:02 GMT)
Full text and
rfc822 format available.
Message #22 received at 68074 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On 1/26/2024 3:53 PM, Alfonso Sanchez-Beato via Bug reports for GNU
Emacs, the Swiss army knife of text editors wrote:
> Unfortunately that does not seem to be the case, I see an error saying "Invalid function" after applying on top of current master:
Oops, I messed up the quoting. How about this?
[0001-Fix-command-replacement-with-the-Eshell-builtin-vers.patch (text/plain, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#68074
; Package
emacs
.
(Sat, 27 Jan 2024 01:20:01 GMT)
Full text and
rfc822 format available.
Message #25 received at 68074 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On 1/26/2024 4:27 PM, Jim Porter wrote:
> On 1/26/2024 3:53 PM, Alfonso Sanchez-Beato via Bug reports for GNU
> Emacs, the Swiss army knife of text editors wrote:
>> Unfortunately that does not seem to be the case, I see an error saying
>> "Invalid function" after applying on top of current master:
>
> Oops, I messed up the quoting. How about this?
... actually, this is a more-complete patch. I'm not 100% sure about
this part though:
',(car args)
That (usually) creates something like (quote "command"), but it's safer
than not quoting (the CAR of 'args' can be anything, really...)
[0001-Fix-command-replacement-with-the-Eshell-builtin-vers.patch (text/plain, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#68074
; Package
emacs
.
(Sat, 27 Jan 2024 08:47:02 GMT)
Full text and
rfc822 format available.
Message #28 received at 68074 <at> debbugs.gnu.org (full text, mbox):
En sábado, 27 de enero de 2024, 01:19:32 GMT, Jim Porter <jporterbugs <at> gmail.com> escribió:
On 1/26/2024 4:27 PM, Jim Porter wrote:
>> On 1/26/2024 3:53 PM, Alfonso Sanchez-Beato via Bug reports for GNU
>> Emacs, the Swiss army knife of text editors wrote:
>>> Unfortunately that does not seem to be the case, I see an error saying
>>> "Invalid function" after applying on top of current master:
>>
>> Oops, I messed up the quoting. How about this?
> ... actually, this is a more-complete patch. I'm not 100% sure about
> this part though:
>
> ',(car args)
>
> That (usually) creates something like (quote "command"), but it's safer
> than not quoting (the CAR of 'args' can be anything, really...)
This last patch works nicely, thanks a lot! It works also in cases where my patch was not, like:
$ eshell/sudo VAR=val <alias> ...
Reply sent
to
Jim Porter <jporterbugs <at> gmail.com>
:
You have taken responsibility.
(Sat, 27 Jan 2024 20:26:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Alfonso Sanchez-Beato <alfonsosanchezbeato <at> yahoo.es>
:
bug acknowledged by developer.
(Sat, 27 Jan 2024 20:26:02 GMT)
Full text and
rfc822 format available.
Message #33 received at 68074-done <at> debbugs.gnu.org (full text, mbox):
On 1/27/2024 12:46 AM, Alfonso Sanchez-Beato via Bug reports for GNU
Emacs, the Swiss army knife of text editors wrote:
>
> En sábado, 27 de enero de 2024, 01:19:32 GMT, Jim Porter <jporterbugs <at> gmail.com> escribió:
>> ... actually, this is a more-complete patch. I'm not 100% sure about
>> this part though:
>>
>> ',(car args)
>>
>> That (usually) creates something like (quote "command"), but it's safer
I thought about this some more and the extraneous quoting is fine in my
opinion. Eshell already does that quite a bit in 'eshell-do-eval', so
what's one more case?
> This last patch works nicely, thanks a lot! It works also in cases where my patch was not, like:
>
> $ eshell/sudo VAR=val <alias> ...
Wait, that works?! (After trying it out locally, so it does!)
Looking at the code, I see why now: 'eshell-named-command' calls
'eshell-prepare-command-hook', and that hook is where we handle local
variables. However, I truly didn't expect that; I thought the local
variable handling occurred in an earlier phase. The more you know...
Anyway, since this works even better than I'd expected, I've now merged
my patch to the master branch as 3c680968e49. Closing this bug now.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sun, 25 Feb 2024 12:24:10 GMT)
Full text and
rfc822 format available.
This bug report was last modified 1 year and 115 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.