all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alfonso Sanchez-Beato via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 68074@debbugs.gnu.org
Subject: bug#68074: eshell sudo/doas does not work for aliases
Date: Wed, 27 Dec 2023 21:12:26 +0000 (UTC)	[thread overview]
Message-ID: <31356544.8861481.1703711546895@mail.yahoo.com> (raw)
In-Reply-To: 31356544.8861481.1703711546895.ref@mail.yahoo.com

[-- Attachment #1: Type: text/plain, Size: 585 bytes --]

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.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-eshell-em-alias.el-eshell-maybe-replace-by-alia.patch --]
[-- Type: text/x-patch, Size: 2022 bytes --]

From 25e12e5912e2ef5bcab359eca5a10e973cb35937 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alfonso=20S=C3=A1nchez-Beato?=
 <alfonsosanchezbeato@yahoo.es>
Date: Wed, 27 Dec 2023 21:50:29 +0100
Subject: [PATCH] * lisp/eshell/em-alias.el (eshell-maybe-replace-by-alias):
 Fix using tramp with alias.

Previously calls that involved using tramp with an alias where not working as
expected because the default-directory set in em-tramp.el was forgotten after
eshell-replace-command was thrown in eshell-maybe-replace-by-alias.
---
 lisp/eshell/em-alias.el | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/lisp/eshell/em-alias.el b/lisp/eshell/em-alias.el
index 841982c3425..7fff920ed7b 100644
--- a/lisp/eshell/em-alias.el
+++ b/lisp/eshell/em-alias.el
@@ -222,12 +222,17 @@ This is useful after manually editing the contents of the file."
 	       (member command eshell-prevent-alias-expansion))
     (let ((alias (eshell-lookup-alias command)))
       (if alias
-	  (throw 'eshell-replace-command
-		 `(let ((eshell-command-name ',eshell-last-command-name)
+          (let ((vars `((eshell-command-name ',eshell-last-command-name)
                         (eshell-command-arguments ',eshell-last-arguments)
                         (eshell-prevent-alias-expansion
-                         ',(cons command eshell-prevent-alias-expansion)))
-                    ,(eshell-parse-command (nth 1 alias))))))))
+                         ',(cons command eshell-prevent-alias-expansion)))))
+            ;; Set default-directory as it might have been set by sudo/doas, unless
+            ;; we want to change it permanently.
+            (if (not (string-prefix-p (car (split-string (nth 1 alias) " ")) "cd"))
+                (push `(default-directory ',default-directory) vars))
+	    (throw 'eshell-replace-command
+		   `(let ,vars
+                      ,(eshell-parse-command (nth 1 alias)))))))))
 
 (defun eshell-alias-completions (name)
   "Find all possible completions for NAME.
-- 
2.34.1


       reply	other threads:[~2023-12-27 21:12 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <31356544.8861481.1703711546895.ref@mail.yahoo.com>
2023-12-27 21:12 ` Alfonso Sanchez-Beato via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-01-11 21:00   ` bug#68074: eshell sudo/doas does not work for aliases Stefan Kangas
2024-01-11 21:15     ` Jim Porter
2024-01-25  2:43       ` Jim Porter
2024-01-26 23:53         ` Alfonso Sanchez-Beato via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-27  0:27           ` Jim Porter
2024-01-27  1:19             ` Jim Porter
2024-01-27  8:46               ` Alfonso Sanchez-Beato via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-27 20:24                 ` Jim Porter

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=31356544.8861481.1703711546895@mail.yahoo.com \
    --to=bug-gnu-emacs@gnu.org \
    --cc=68074@debbugs.gnu.org \
    --cc=alfonsosanchezbeato@yahoo.es \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.