From: Steven Allen via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 71969@debbugs.gnu.org
Subject: bug#71969: [PATCH] Support interactive D-Bus authentication
Date: Sat, 06 Jul 2024 09:53:58 +0200 [thread overview]
Message-ID: <877cdzklbd.fsf@stebalien.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 313 bytes --]
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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Support-interactive-D-Bus-authentication.patch --]
[-- Type: text/x-patch, Size: 6529 bytes --]
From fa996a3363e9bcefb547c2a587d55b279d44c5dd Mon Sep 17 00:00:00 2001
From: Steven Allen <steven@stebalien.com>
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'.
\f
* 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).
+
\f
* 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
next reply other threads:[~2024-07-06 7:53 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-06 7:53 Steven Allen via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-07-06 11:54 ` bug#71969: [PATCH] Support interactive D-Bus authentication Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-06 14:53 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-06 14:57 ` Eli Zaretskii
2024-07-06 15:24 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-07 11:53 ` Steven Allen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-07 14:50 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-08 9:24 ` Steven Allen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-08 12:29 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-08 12:50 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-08 13:21 ` Steven Allen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-09 7:52 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-09 9:09 ` Steven Allen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-09 12:10 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-09 15:45 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-09 19:28 ` Steven Allen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-09 19:34 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-09 19:54 ` Steven Allen via Bug reports for GNU Emacs, the Swiss army knife of text editors
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=877cdzklbd.fsf@stebalien.com \
--to=bug-gnu-emacs@gnu.org \
--cc=71969@debbugs.gnu.org \
--cc=steven@stebalien.com \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).