From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Steven Allen via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#71969: [PATCH] Support interactive D-Bus authentication Date: Sat, 06 Jul 2024 09:53:58 +0200 Message-ID: <877cdzklbd.fsf@stebalien.com> Reply-To: Steven Allen 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="11752"; mail-complaints-to="usenet@ciao.gmane.io" To: 71969@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jul 06 09:55:06 2024 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 1sQ0G9-0002pd-LX for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 06 Jul 2024 09:55:06 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQ0G4-0001We-TS; Sat, 06 Jul 2024 03:55:00 -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 1sQ0G3-0001WE-2x for bug-gnu-emacs@gnu.org; Sat, 06 Jul 2024 03:54:59 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sQ0G2-0001YV-R8 for bug-gnu-emacs@gnu.org; Sat, 06 Jul 2024 03:54:58 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sQ0G6-0005nt-8q for bug-gnu-emacs@gnu.org; Sat, 06 Jul 2024 03:55:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Steven Allen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 06 Jul 2024 07:55:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 71969 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.172025245422222 (code B ref -1); Sat, 06 Jul 2024 07:55:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 6 Jul 2024 07:54:14 +0000 Original-Received: from localhost ([127.0.0.1]:45530 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sQ0FJ-0005mL-FU for submit@debbugs.gnu.org; Sat, 06 Jul 2024 03:54:14 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:37548) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sQ0FH-0005mD-FS for submit@debbugs.gnu.org; Sat, 06 Jul 2024 03:54:12 -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 1sQ0FD-0001QU-JZ for bug-gnu-emacs@gnu.org; Sat, 06 Jul 2024 03:54:07 -0400 Original-Received: from fhigh5-smtp.messagingengine.com ([103.168.172.156]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sQ0FB-0001Tk-7C for bug-gnu-emacs@gnu.org; Sat, 06 Jul 2024 03:54:07 -0400 Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfhigh.nyi.internal (Postfix) with ESMTP id E31531140323 for ; Sat, 6 Jul 2024 03:54:01 -0400 (EDT) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Sat, 06 Jul 2024 03:54:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stebalien.com; h=cc:content-type:content-type:date:date:from:from:in-reply-to :message-id:mime-version:reply-to:subject:subject:to:to; s=fm1; t=1720252441; x=1720338841; bh=/FjzX4G7yDhf4rp9HpwPZoW9CRpM/yC3 X5XJjjUef/A=; b=FTUY0j6dr7c0D2R4Yr8IezMxyEabb3aaR8fDkOe0GSgva6/i EeDzOs9FfzbH82jyRrkjJFXORL0bgtruRposMJlI0REPgaLKnuhZAojF76dCUwEf BAvs2DEX56b/arwkrRQbkNQncdFzpjIsCU+bOHI5b+7lvNrPIB+rz/g7EpThABjy d5EpR9wzybpMU9HPw4oDfmDD553ETeT6kB8QWBe4fSm/r2zrnrrORE2GWFJ+nnnH n99ood8hUZhotrfTYDLKqlyPXmVd90r4c5TCSa+Io0x+uaMES+kyQTH7Wz9In2xl VivJhDZI1p5AaHFjxPjQ7mr6eGJI5vHmjdhoiw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1720252441; x=1720338841; bh=/FjzX4G7yDhf4rp9HpwPZoW9CRpM/yC3X5X JjjUef/A=; b=FaUmdmwtISRhq5/DFxyPHwTMo+7hoacR6K3AeTD7zGQjyhXCayL jRUZC3eFzpYBk9rssFIYkO9bu9Va8zxYQzjgl79XjWidl6q8Oii/iHbgfmaTzRid Aq+VGsRyYFepwPPWbTN8Zq2x5BclhnakMnPvWccvZmJEqBRBt+3s32JcJ1L1piSg UI++c/3U6b+ICClI3GrYXXx440rlj/YXNRNX4pzj97tTF1XXhJW43qkl69GJY/Sv 0BZbC4TmZOVfn0qhQT/RCzDZCWLVC62YspcIUyID/r2yj9q1sZpESR1UzDOJc13y y6YUTnIrwT946+YSErrxyMSO4j8Phj2MYpQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddvgdduvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkgggtsehmtderredttd dtnecuhfhrohhmpefuthgvvhgvnhcutehllhgvnhcuoehsthgvvhgvnhesshhtvggsrghl ihgvnhdrtghomheqnecuggftrfgrthhtvghrnhepkefffffgveethedtieffleffgeekvd eiieegheeftdetjeekfefhvedttdekfeffnecuvehluhhsthgvrhfuihiivgeptdenucfr rghrrghmpehmrghilhhfrhhomhepshhtvghvvghnsehsthgvsggrlhhivghnrdgtohhm X-ME-Proxy: Feedback-ID: ie8a146a7:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Sat, 6 Jul 2024 03:54:01 -0400 (EDT) Received-SPF: pass client-ip=103.168.172.156; envelope-from=steven@stebalien.com; helo=fhigh5-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-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: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:288472 Archived-At: --=-=-= Content-Type: text/plain When invoking D-Bus methods, let the user enable interactive authorization by passing an :authenticate t parameter. This makes it possible to D-Bus methods that require polkit authorization. Alternatively, we could allow interactive authorization unconditionally, but I'd prefer to leave it up to the caller. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Support-interactive-D-Bus-authentication.patch >From fa996a3363e9bcefb547c2a587d55b279d44c5dd Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 4 Jul 2024 20:45:07 +0200 Subject: [PATCH] Support interactive D-Bus authentication When invoking D-Bus methods, let the user enable interactive authorization by passing an :authenticate t parameter. This makes it possible to D-Bus methods that require polkit authorization. * src/dbusbind.c (dbus-message-internal): Allow interactive authorization by passing :authenticate t. * lisp/net/dbus.el (dbus-call-method-asynchronously): Document the new parameter. * doc/misc/dbus.texi (Synchronous Methods, Asynchronous Methods): Document the new parameter. --- doc/misc/dbus.texi | 12 ++++++++++-- etc/NEWS | 6 ++++++ lisp/net/dbus.el | 8 ++++++++ src/dbusbind.c | 26 ++++++++++++++++++++------ 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/doc/misc/dbus.texi b/doc/misc/dbus.texi index e5d867acd40..9bde8cbc76b 100644 --- a/doc/misc/dbus.texi +++ b/doc/misc/dbus.texi @@ -1208,7 +1208,7 @@ Synchronous Methods be called, and a reply message returning the resulting output parameters from the object. -@defun dbus-call-method bus service path interface method &optional :timeout timeout &rest args +@defun dbus-call-method bus service path interface method &optional :timeout timeout :authenticate auth &rest args @anchor{dbus-call-method} This function calls @var{method} on the D-Bus @var{bus}. @var{bus} is either the keyword @code{:system} or the keyword @code{:session}. @@ -1223,6 +1223,10 @@ Synchronous Methods call doesn't return in time, a D-Bus error is raised (@pxref{Errors and Events}). +If the parameter @code{:authenticate} is given and the following +@var{auth} is non-nil, the invoked method may interactively prompt the +user for authorization. The default is @code{nil}. + The remaining arguments @var{args} are passed to @var{method} as arguments. They are converted into D-Bus types as described in @ref{Type Conversion}. @@ -1302,7 +1306,7 @@ Asynchronous Methods @cindex method calls, asynchronous @cindex asynchronous method calls -@defun dbus-call-method-asynchronously bus service path interface method handler &optional :timeout timeout &rest args +@defun dbus-call-method-asynchronously bus service path interface method handler &optional :timeout timeout :authenticate auth &rest args This function calls @var{method} on the D-Bus @var{bus} asynchronously. @var{bus} is either the keyword @code{:system} or the keyword @code{:session}. @@ -1321,6 +1325,10 @@ Asynchronous Methods no reply message in time, a D-Bus error is raised (@pxref{Errors and Events}). +If the parameter @code{:authenticate} is given and the following +@var{auth} is non-nil, the invoked method may interactively prompt the +user for authorization. The default is @code{nil}. + The remaining arguments @var{args} are passed to @var{method} as arguments. They are converted into D-Bus types as described in @ref{Type Conversion}. diff --git a/etc/NEWS b/etc/NEWS index 3d2b86cfb6a..fd6e3737eb8 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -79,6 +79,12 @@ levels that SHR cycles through when calling 'shr-zoom-image'. * Lisp Changes in Emacs 31.1 ++++ +*** Support interactive D-Bus authentication +A new ':authenticate t' parameter has been added to 'dbus-call-method' +and 'dbus-call-method-asynchronously' to allow the invoked D-Bus method +to interactively authenticate the user (e.g., via polkit). + * Changes in Emacs 31.1 on Non-Free Operating Systems diff --git a/lisp/net/dbus.el b/lisp/net/dbus.el index dd5f0e88859..749a12b5368 100644 --- a/lisp/net/dbus.el +++ b/lisp/net/dbus.el @@ -297,6 +297,10 @@ dbus-call-method method call must return. The default value is 25,000. If the method call doesn't return in time, a D-Bus error is raised. +If the parameter `:authenticate' is given and the following AUTH +is non-nil, the invoked method may interactively prompt the user +for authorization. The default is nil. + All other arguments ARGS are passed to METHOD as arguments. They are converted into D-Bus types via the following rules: @@ -427,6 +431,10 @@ dbus-call-method-asynchronously method call must return. The default value is 25,000. If the method call doesn't return in time, a D-Bus error is raised. +If the parameter `:authenticate' is given and the following AUTH +is non-nil, the invoked method may interactively prompt the user +for authorization. The default is nil. + All other arguments ARGS are passed to METHOD as arguments. They are converted into D-Bus types via the following rules: diff --git a/src/dbusbind.c b/src/dbusbind.c index 35ce03c7911..6037112cfe7 100644 --- a/src/dbusbind.c +++ b/src/dbusbind.c @@ -1314,7 +1314,7 @@ DEFUN ("dbus-message-internal", Fdbus_message_internal, Sdbus_message_internal, `dbus-call-method', `dbus-call-method-asynchronously': (dbus-message-internal dbus-message-type-method-call BUS SERVICE PATH INTERFACE METHOD HANDLER - &optional :timeout TIMEOUT &rest ARGS) + &optional :timeout TIMEOUT :authenticate AUTH &rest ARGS) `dbus-send-signal': (dbus-message-internal @@ -1512,12 +1512,23 @@ DEFUN ("dbus-message-internal", Fdbus_message_internal, Sdbus_message_internal, XD_SIGNAL1 (build_string ("Unable to create an error message")); } - /* Check for timeout parameter. */ - if ((count + 2 <= nargs) && EQ (args[count], QCtimeout)) + while ((count + 2 <= nargs)) { - CHECK_FIXNAT (args[count+1]); - timeout = min (XFIXNAT (args[count+1]), INT_MAX); - count = count+2; + /* Check for timeout parameter. */ + if (EQ (args[count], QCtimeout)) + { + CHECK_FIXNAT (args[count+1]); + timeout = min (XFIXNAT (args[count+1]), INT_MAX); + count = count+2; + } + /* Check for authenticate parameter. */ + else if (EQ (args[count], QCauthenticate)) + { + dbus_message_set_allow_interactive_authorization + (dmessage, NILP (args[count+1]) ? FALSE : TRUE); + count = count+2; + } + else break; } /* Initialize parameter list of message. */ @@ -1895,6 +1906,9 @@ syms_of_dbusbind (void) /* Lisp symbol for method call timeout. */ DEFSYM (QCtimeout, ":timeout"); + /* Lisp symbol for method interactive authentication. */ + DEFSYM (QCauthenticate, ":authenticate"); + /* Lisp symbols of D-Bus types. */ DEFSYM (QCbyte, ":byte"); DEFSYM (QCboolean, ":boolean"); -- 2.45.2 --=-=-=--