From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Brian Cully via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#58899: [PATCH v1] Add the "doas" alias to eshell. Date: Sun, 30 Oct 2022 12:42:41 -0400 Message-ID: <87pme92rge.fsf@ditto.jhoto.spork.org> Reply-To: Brian Cully Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22262"; mail-complaints-to="usenet@ciao.gmane.io" To: 58899@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Oct 30 17:44:14 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1opBPx-0005Zx-K1 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 30 Oct 2022 17:44:13 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1opBPn-0004Uy-GF; Sun, 30 Oct 2022 12:44:03 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1opBPm-0004Uo-36 for bug-gnu-emacs@gnu.org; Sun, 30 Oct 2022 12:44:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1opBPl-0006PP-S5 for bug-gnu-emacs@gnu.org; Sun, 30 Oct 2022 12:44:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1opBPl-0001ds-OG for bug-gnu-emacs@gnu.org; Sun, 30 Oct 2022 12:44:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Brian Cully Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 30 Oct 2022 16:44:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 58899 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16671482146267 (code B ref -1); Sun, 30 Oct 2022 16:44:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 30 Oct 2022 16:43:34 +0000 Original-Received: from localhost ([127.0.0.1]:38917 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1opBPK-0001d1-8S for submit@debbugs.gnu.org; Sun, 30 Oct 2022 12:43:34 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:53798) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1opBPI-0001ct-6Q for submit@debbugs.gnu.org; Sun, 30 Oct 2022 12:43:33 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1opBPI-0004G0-1A for bug-gnu-emacs@gnu.org; Sun, 30 Oct 2022 12:43:32 -0400 Original-Received: from coleridge.kublai.com ([166.84.7.167] helo=mail.spork.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1opBPG-0006Af-CO for bug-gnu-emacs@gnu.org; Sun, 30 Oct 2022 12:43:31 -0400 Original-Received: from ditto (ool-18b8e9e7.dyn.optonline.net [24.184.233.231]) by mail.spork.org (Postfix) with ESMTPSA id 412F8AE22 for ; Sun, 30 Oct 2022 12:42:42 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=spork.org; s=dkim; t=1667148163; bh=m98+cZU4LJMzqwGYtW2SS59Sx4LTcJezFKeonX5SQFI=; h=From:To:Subject:Date; b=A1UCmVR0PRWJsh19ElmtiHFXdtFH13Z4k0d6Kv4T3W5pguguOpBu1yqvOjF2YIOyX bXrQPsUMjHZOeh4ZEd/FTNtgky9xVTNueWgL4BaMkok9CAEMu0mAmU0XLFVY+PlRDI 2oe4lnIFSHLqE93WsWpFcs0c/I9gJmL9f8FdikY4= Received-SPF: pass client-ip=166.84.7.167; envelope-from=bjc@spork.org; helo=mail.spork.org X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: "bug-gnu-emacs" Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:246637 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable This patch adds a =E2=80=9Cdoas=E2=80=9D command alias to eshell for users = who prefer doas, similar to the existing =E2=80=9Csu=E2=80=9D and =E2=80=9Csudo=E2=80= =9D command aliases. I'm unsare whether to use =E2=80=9CTRAMP=E2=80=9D or =E2=80=9CTramp=E2=80= =9D spelling. The existing routines in the file use the former, but I've been informed the latter is correct. A future patch should make all spellings (at least within this module) consistent. Additionaly, I've added a function for calculating the remote-path for files accessed with doas. This function is currently limited to *only* doas, because I didn't want to mess with the other su and sudo functions, but there's no reason it can't be shared, and a future patch should implement that sharing if this patch is considered desirable. -bjc --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=v1-0001-Add-the-doas-alias-to-eshell.patch Content-Transfer-Encoding: quoted-printable >From d31226fd4867c4af8a77e2a90771c9c927f02f88 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Wed, 26 Oct 2022 21:10:21 -0400 Subject: [PATCH v1] Add the "doas" alias to eshell. * lisp/eshell/em-tramp.el (eshell/doas): new function. --- lisp/eshell/em-tramp.el | 47 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/lisp/eshell/em-tramp.el b/lisp/eshell/em-tramp.el index aebbc36e71..7969a88a2b 100644 --- a/lisp/eshell/em-tramp.el +++ b/lisp/eshell/em-tramp.el @@ -40,9 +40,10 @@ (defgroup eshell-tramp nil "This module defines commands that use TRAMP in a way that is not transparent to the user. So far, this includes only the - built-in su and sudo commands, which are not compatible with - the full, external su and sudo commands, and require the user - to understand how to use the TRAMP sudo method." + built-in su, sudo and doas commands, which are not compatible + with the full, external su, sudo, and doas commands, and + require the user to understand how to use the TRAMP sudo + method." :tag "TRAMP Eshell features" :group 'eshell-module)) =20 @@ -52,7 +53,7 @@ eshell-tramp-initialize (add-hook 'pcomplete-try-first-hook 'eshell-complete-host-reference nil t)) (setq-local eshell-complex-commands - (append '("su" "sudo") + (append '("su" "sudo" "doas") eshell-complex-commands))) =20 (autoload 'eshell-parse-command "esh-cmd") @@ -127,6 +128,44 @@ eshell/sudo =20 (put 'eshell/sudo 'eshell-no-numeric-conversions t) =20 +(defun eshell--doas-directory (directory &optional user) + "Return DIRECTORY wrapped with a doas method for USER." + (let ((user (or user "root")) + (dir (file-local-name (expand-file-name directory))) + (prefix (file-remote-p directory)) + (host (or (file-remote-p directory 'host) + tramp-default-host)) + (method (file-remote-p directory 'method)) + (ruser (file-remote-p directory 'user))) + (if (and prefix (or (not (string-equal method "doas")) + (not (string-equal ruser user)))) + (format "%s|doas:%s@%s:%s" + (substring prefix 0 -1) user host dir) + (format "/doas:%s@%s:%s" user host dir)))) + +(defun eshell/doas (&rest args) + "Call Tramp=E2=80=99s doas method with ARGS. + +Uses the system doas through Tramp's doas method." + (eshell-eval-using-options + "doas" args + '((?h "help" nil nil "show this usage screen") + (?u "user" t user "execute a command as another USER") + (?s "shell" nil shell "start a shell instead of executing COMMAND") + :show-usage + :parse-leading-options-only + :usage "[(-u | --user) USER] -s | COMMAND +Execute a COMMAND as the superuser or another USER.") + (let ((dir (eshell--doas-directory default-directory user))) + (if shell + (throw 'eshell-replace-command + (eshell-parse-command "cd" (list dir))) + (throw 'eshell-external + (let ((default-directory dir)) + (eshell-named-command (car args) (cdr args)))))))) + +(put 'eshell/doas 'eshell-no-numeric-conversions t) + (provide 'em-tramp) =20 ;; Local Variables: --=20 2.38.0 --=-=-=--