GParted should have a privileged DBUS backend
GParted should have a privileged backend
In modern Linux world the intended way to do operations that need privileged access rights is to have separate privileged DBUS services and invoke them over the wire with DBUS. This increases security because privileged actions are done in separate processes and also because DBUS is very security oriented.
There are two or more DBUS daemons running: one for a system bus and one for each session bus (i.e the specific desktop login) The application sends requests to the dbus daemon and it delivers the request to the service. When things are done DBUS gives back the results to the application. A DBUS service can provide
- Methods
- Signals
- Properties
How do you use DBUS at an application level?
There is libdbus. But for Glib/Gtk applications it is preferable to use GDBUS in GIO/GLib.
Gtkmm applications can make use of GIOmm wrappers.
How do you write a DBUS service?
DBUS services are applications (usually in /usr/bin). Some examples are
- /usr/bin/jackdbus
- /usr/bin/devhelp --gapplication-service
- /usr/lib/glib-pacrunner
They are accompanied by textual .service files in /usr/share/dbus-1/services/.
For example, org.jackaudio.service contains:
[D-BUS Service]
Name=org.jackaudio.service
Exec=/usr/bin/jackdbus auto
At startup a DBUS service registers interfaces with methods+arguments, signals+arguments, properties. For arguments and properties, DBUS understands the following data types:
- Integer (signed/unsigned, 16/32/64)
- Double (64 bit IEEE 754 floating point)
- Boolean
- Byte
- String (UTF-8 encoded)
- Array (all elements of the array of the same type)
- Struct
- Map (one type for key and one type for values)
These are the types that are sent over the wire. DBUS uses a binary protocol.
On top of that, the GDBus layer can transport every GVariant data type, which may be really great. I still have to do some research, but it may be that GIOmm wrappers can directly marshall many C++ types (integrals, floating point, bool, Glib::ustring and maybe containers like std::vector)
Final thoughts
This is becoming important now that Wayland is taking place because Wayland forbids root graphical applications. Whilst there are workarounds for XWayland apps, you really cannot have XWayland-free graphical applications running as root
DBus:
[1] Get on the D-BUS: https://www.linuxjournal.com/article/7744
[2] D-Bus API Design Guidelines: https://dbus.freedesktop.org/doc/dbus-api-design.html
[4] Offical DBUS Tutorial: https://dbus.freedesktop.org/doc/dbus-tutorial.html
GDBus bindings:
[5] Aleksander Morgado (video): https://youtu.be/egj4UMPaylk
[6] Aleksander Morgado (presentation) https://aleksander.es/data/GNOMEASIA2014%20-%20Introduction%20to%20DBus.pdf
Polkit:
[7] Why Polkit: https://www.collabora.com/about-us/blog/2015/06/08/why-polkit-(or,-how-to-mount-a-disk-on-modern-linux)