diff options
author | Hans Petter Jansson <hpj@cl.no> | 2016-06-17 04:00:04 +0200 |
---|---|---|
committer | Hans Petter Jansson <hpj@cl.no> | 2016-06-17 04:00:04 +0200 |
commit | 5e8047d0d7a622dfd19dba0310ad58d8b4e2f16b (patch) | |
tree | 04ef5bc03ab9a55493fabbecd741215f34814446 | |
parent | ec0949091f7a771c852c0314108f9aa4b2a25575 (diff) | |
download | desktop-file-utils-5e8047d0d7a622dfd19dba0310ad58d8b4e2f16b.tar.gz |
validate: Ensure DBusActivatable filenames conform to reverse-DNS notation.
https://bugs.freedesktop.org/show_bug.cgi?id=66904
-rw-r--r-- | src/validate.c | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/src/validate.c b/src/validate.c index 7403c18..f2e8a06 100644 --- a/src/validate.c +++ b/src/validate.c @@ -211,6 +211,10 @@ handle_actions_key (kf_validator *kf, const char *locale_key, const char *value); static gboolean +handle_dbus_activatable_key (kf_validator *kf, + const char *locale_key, + const char *value); +static gboolean handle_dev_key (kf_validator *kf, const char *locale_key, const char *value); @@ -313,7 +317,7 @@ static DesktopKeyDefinition registered_desktop_keys[] = { * specified) */ { DESKTOP_STRING_LIST_TYPE, "Actions", FALSE, FALSE, FALSE, handle_actions_key }, - { DESKTOP_BOOLEAN_TYPE, "DBusActivatable", FALSE, FALSE, FALSE, NULL }, + { DESKTOP_BOOLEAN_TYPE, "DBusActivatable", FALSE, FALSE, FALSE, handle_dbus_activatable_key }, /* Keys reserved for KDE */ @@ -1790,6 +1794,46 @@ handle_actions_key (kf_validator *kf, return retval; } +/* + If the file describes a D-Bus activatable service, the filename must be in + * reverse-DNS notation, i.e. contain at least two dots including the dot + * in ".desktop". + * Checked. + */ +static gboolean +handle_dbus_activatable_key (kf_validator *kf, + const char *locale_key, + const char *value) +{ + gchar *basename_utf8; + gchar *basename; + const gchar *p = NULL; + gboolean retval = TRUE; + + /* If DBusActivatable=false, don't check */ + if (strcmp (value, "true") && strcmp (value, "1")) + return TRUE; + + basename = g_path_get_basename (kf->filename); + basename_utf8 = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL); + if (!basename_utf8) + goto out; + + p = g_utf8_strchr (basename_utf8, -1, '.'); + if (!p) + goto out; + p = g_utf8_strchr (p + 1, -1, '.'); + +out: + if (!p) { + print_fatal (kf, "DBusActivatable filename must conform to reverse-DNS notation\n"); + retval = FALSE; + } + + g_free (basename_utf8); + g_free (basename); + return retval; +} + /* + The device to mount. (probably implies an absolute path) * Checked. */ |