diff --git a/Makefile b/Makefile index 1106e38..22470f6 100644 --- a/Makefile +++ b/Makefile @@ -27,3 +27,6 @@ clean: .DEFAULT: @$(MAKE) -C src $@ @$(MAKE) -C tools $@ + +debian/%.install: debian/%.install.in + sed 's|@LIBDIR@|$(LIBDIR)|g' $< > $@ diff --git a/plugins/Makefile b/plugins/Makefile index 20ae6f0..f4d2d14 100644 --- a/plugins/Makefile +++ b/plugins/Makefile @@ -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 diff --git a/plugins/settings/settings_plugin.c b/plugins/settings/settings_plugin.c index 9110a3a..4f811e9 100644 --- a/plugins/settings/settings_plugin.c +++ b/plugins/settings/settings_plugin.c @@ -38,8 +38,10 @@ #include +#ifdef HAVE_DBUSACCESS #include #include +#endif #include @@ -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; @@ -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 @@ -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( @@ -218,6 +226,8 @@ settings_plugin_update_config( g_key_file_unref(config); } +#ifdef HAVE_DBUSACCESS + static GQuark settings_plugin_error_quark() @@ -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( @@ -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( @@ -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, @@ -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 @@ -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); diff --git a/src/Makefile b/src/Makefile index 4d0cbc8..a5264e7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -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 #