Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[build] Allow building without libdbusaccess. JB#48413
Some platforms may choose to rely on dbus-daemon policies
for access control.

Define environment variable HAVE_DBUSACCESS=0 to build without
libdbusaccess.
  • Loading branch information
monich committed Apr 13, 2021
1 parent 3e535e9 commit 79dcd62
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Makefile
Expand Up @@ -27,3 +27,6 @@ clean:
.DEFAULT:
@$(MAKE) -C src $@
@$(MAKE) -C tools $@

debian/%.install: debian/%.install.in
sed 's|@LIBDIR@|$(LIBDIR)|g' $< > $@
13 changes: 12 additions & 1 deletion plugins/Makefile
Expand Up @@ -6,7 +6,18 @@
# Required packages
#

PKGS = libdbusaccess libglibutil glib-2.0 gobject-2.0 gio-2.0 gio-unix-2.0
PKGS = libglibutil glib-2.0 gobject-2.0 gio-2.0 gio-unix-2.0

#
# libdbusaccess is optional
#

HAVE_DBUSACCESS ?= 1

ifneq ($(HAVE_DBUSACCESS),0)
PKGS += libdbusaccess
DEFINES += -DHAVE_DBUSACCESS
endif

#
# Default target
Expand Down
30 changes: 27 additions & 3 deletions plugins/settings/settings_plugin.c
Expand Up @@ -38,8 +38,10 @@

#include <gio/gio.h>

#ifdef HAVE_DBUSACCESS
#include <dbusaccess_policy.h>
#include <dbusaccess_peer.h>
#endif

#include <gutil_misc.h>

Expand All @@ -64,7 +66,9 @@ typedef struct settings_plugin {
NfcPlugin parent;
NfcManager* manager;
OrgSailfishosNfcSettings* iface;
#ifdef HAVE_DBUSACCESS
DAPolicy* policy;
#endif
char* storage_dir;
char* storage_file;
guint own_name_id;
Expand Down Expand Up @@ -92,6 +96,8 @@ G_DEFINE_TYPE(SettingsPlugin, settings_plugin, NFC_TYPE_PLUGIN)
#define SETTINGS_KEY_ENABLED "Enabled"
#define SETTINGS_KEY_ALWAYS_ON "AlwaysOn"

#ifdef HAVE_DBUSACCESS

typedef enum settings_error {
SETTINGS_ERROR_ACCESS_DENIED, /* AccessDenied */
SETTINGS_NUM_ERRORS
Expand Down Expand Up @@ -122,6 +128,8 @@ static const DA_ACTION settings_policy_actions[] = {
static const char settings_default_policy[] =
DA_POLICY_VERSION ";group(privileged)=allow";

#endif /* HAVE_DBUSACCESS */

static
GKeyFile*
settings_plugin_load_config(
Expand Down Expand Up @@ -218,6 +226,8 @@ settings_plugin_update_config(
g_key_file_unref(config);
}

#ifdef HAVE_DBUSACCESS

static
GQuark
settings_plugin_error_quark()
Expand All @@ -232,6 +242,10 @@ settings_plugin_error_quark()
return (GQuark)settings_error_quark_value;
}

/*
* Note: if settings_plugin_access_allowed() returns FALSE, it completes
* the call with error.
*/
static
gboolean
settings_plugin_access_allowed(
Expand All @@ -255,6 +269,14 @@ settings_plugin_access_allowed(
return FALSE;
}

#else

/* No access control (other than the one provided by dbus-daemon) */
#define settings_plugin_access_allowed(self,call,action,def) (TRUE)

#endif /* HAVE_DBUSACCESS */


static
void
settings_plugin_set_nfc_enabled(
Expand Down Expand Up @@ -294,9 +316,7 @@ settings_plugin_dbus_handle_get_interface_version(
GDBusMethodInvocation* call,
gpointer user_data)
{
SettingsPlugin* self = SETTINGS_PLUGIN(user_data);

if (settings_plugin_access_allowed(self, call,
if (settings_plugin_access_allowed(SETTINGS_PLUGIN(user_data), call,
SETTINGS_ACTION_GET_INTERFACE_VERSION,
SETTINGS_DEFAULT_ACCESS_GET_INTERFACE_VERSION)) {
org_sailfishos_nfc_settings_complete_get_interface_version(iface, call,
Expand Down Expand Up @@ -456,8 +476,10 @@ settings_plugin_init(
self->storage_dir = g_strdup(SETTINGS_STORAGE_DIR);
self->storage_file = g_build_filename(self->storage_dir,
SETTINGS_STORAGE_FILE, NULL);
#ifdef HAVE_DBUSACCESS
self->policy = da_policy_new_full(settings_default_policy,
settings_policy_actions);
#endif
}

static
Expand All @@ -467,7 +489,9 @@ settings_plugin_finalize(
{
SettingsPlugin* self = SETTINGS_PLUGIN(plugin);

#ifdef HAVE_DBUSACCESS
da_policy_unref(self->policy);
#endif
g_free(self->storage_dir);
g_free(self->storage_file);
G_OBJECT_CLASS(settings_plugin_parent_class)->finalize(plugin);
Expand Down
10 changes: 10 additions & 0 deletions src/Makefile
Expand Up @@ -11,6 +11,16 @@
PKGS = gio-unix-2.0 gio-2.0 libglibutil
LIB_PKGS = $(PKGS) libdbusaccess

#
# libdbusaccess is optional
#

HAVE_DBUSACCESS ?= 1

ifneq ($(HAVE_DBUSACCESS),0)
LIB_PKGS += libdbusaccess
endif

#
# Default target
#
Expand Down

0 comments on commit 79dcd62

Please sign in to comment.