Skip to content

Allow interaction authorization#313

Open
unfamiliarS wants to merge 1 commit into
hypfvieh:masterfrom
unfamiliarS:allow-interaction-autorization
Open

Allow interaction authorization#313
unfamiliarS wants to merge 1 commit into
hypfvieh:masterfrom
unfamiliarS:allow-interaction-autorization

Conversation

@unfamiliarS

Copy link
Copy Markdown

I'm using this library to create a GUI shell for managing systemd daemons, and some issues emerged during development. When sending a DBus request to execute file system commands (such as EnableUnitFiles and DisableUnitFiles, see the systemd DBus API for more details: https://www.freedesktop.org/software/systemd/man/latest/org.freedesktop.systemd1.html), the graphical user login window wouldn't appear, and an error would immediately be thrown:

org.freedesktop.dbus.exceptions.DBusExecutionException: Interactive authentication required.
        at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486)
        at org.freedesktop.dbus.messages.Error.getException(Error.java:113)
        at org.freedesktop.dbus.messages.Error.throwException(Error.java:138)
        at org.freedesktop.dbus.RemoteInvocationHandler.executeRemoteMethod(RemoteInvocationHandler.java:241)
        at org.freedesktop.dbus.RemoteInvocationHandler.executeRemoteMethod(RemoteInvocationHandler.java:254)
        at org.freedesktop.dbus.RemoteInvocationHandler.executeRemoteMethod(RemoteInvocationHandler.java:156)
        at org.freedesktop.dbus.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:99)
        at jdk.proxy1/jdk.proxy1.$Proxy21.disableUnitFiles(Unknown Source)
        at de.thjom.java.systemd.Manager.disableUnitFiles(Manager.java:200)
        at com.shavarushka.models.sysd_commands.commands.DisableUnitCommand.execute(DisableUnitCommand.java:67)
        at com.shavarushka.controllers.SysdActionsC.lambda$18(SysdActionsC.java:199)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
        at java.base/java.lang.Thread.run(Thread.java:1583)

I read the DBus specification (https://dbus.freedesktop.org/doc/dbus-specification.html) and found a solution: add the 0x4 byte to the message header, which tells the receiving end to wait for authorization.

The code I'm proposing allows you to mark DBus methods in your client code that should allow interactive authorization. For example, here's how I use it:

    @DBusMemberName(value = "DisableUnitFiles")
    @MethodAllowInteractiveAutorization
    List<UnitFileChange> disableUnitFiles(List<String> names, boolean runtime);

    @DBusMemberName(value = "EnableUnitFiles")
    @MethodAllowInteractiveAutorization(value = true)
    Pair<Boolean, List<UnitFileChange>> enableUnitFiles(List<String> names, boolean runtime, boolean force);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant