I'm working on a project, implementing everything in C language. As a part of the project, we need to be able to control and configure firewalld
, firewall of the current system.
firewalld
is implemented in Python and an interface is available. However, we don't want to make Python calls from C or vice versa. firewalld
(e.g. firewall-cmd
) but we don't want to make such calls from C either.I recently started working on firewalld
, I don't know much about its internals. I've read that it uses D-Bus, I also don't know much about D-Bus.
libfirewall
.
However, it's been more than a year and a half since the last commit so it's not maintained. Other than libfirewall
, I don't know any firewalld interface in C.
libfirewall
a shot. It got me some problems when both compiling and running the examples and I still have problems to resolve. Is it worth to continue with libfirewall
? Should I use it?firewall-cmd
, and interacts with D-Bus in the same way and at the end allows us to control firewalld?
libdbus
and GDBus
have relatively good documentation although libdbus
requires good deal of effort. They even said "If you use this low-level API directly, you're signing up for some pain." in the documentation. In any case I'll be in need of examples or any kind of text demonstrating their usage.How should I approach this problem?
Yes, you can issue commands to firewalld via D-Bus. I haven't checked but expect that firewall-cmd
is itself implemented as a D-Bus client.
The D-Bus API is extensively documented: https://firewalld.org/documentation/man-pages/firewalld.dbus.html. The documentation should give you a rough idea what can be accomplished through the API. You could try the D-Bus debugger d-feet
to interact with firewalld without any code.
GDBus is definitely the easiest way use D-Bus from C but it's still not trivial and firewalld is a fairly complex API: Using it may require some expertise (completely depending on what you need to do).