|
|
980768 |
From aad98b87513f9e277258c8bc9c3bc7db7a8442ba Mon Sep 17 00:00:00 2001
|
|
|
980768 |
From: Vojtech Trefny <vtrefny@redhat.com>
|
|
|
980768 |
Date: Thu, 18 Jan 2018 13:59:11 +0100
|
|
|
980768 |
Subject: [PATCH] Fix escaping mountpoint for the cleanup service
|
|
|
980768 |
|
|
|
980768 |
We need to use the 'systemd-escape' command -- it escapes more
|
|
|
980768 |
symbols and manually escaping only slashes isn't enough.
|
|
|
980768 |
|
|
|
980768 |
Resolves: rhbz#1384796
|
|
|
980768 |
(cherry picked from commit 4d982bb6b81afcd17b0a42b6c1256c22ff444ee5)
|
|
|
980768 |
---
|
|
|
980768 |
src/udiskslinuxfilesystem.c | 38 +++++++++++++++++++++++++++-----------
|
|
|
980768 |
1 file changed, 27 insertions(+), 11 deletions(-)
|
|
|
980768 |
|
|
|
980768 |
diff --git a/src/udiskslinuxfilesystem.c b/src/udiskslinuxfilesystem.c
|
|
|
980768 |
index 2910181..e2b7e18 100644
|
|
|
980768 |
--- a/src/udiskslinuxfilesystem.c
|
|
|
980768 |
+++ b/src/udiskslinuxfilesystem.c
|
|
|
980768 |
@@ -1144,10 +1144,11 @@ is_system_managed (UDisksBlock *block,
|
|
|
980768 |
|
|
|
980768 |
static void trigger_mpoint_cleanup (const gchar *mount_point)
|
|
|
980768 |
{
|
|
|
980768 |
- const gchar *argv[] = {"systemctl", "start", NULL, NULL};
|
|
|
980768 |
+ const gchar *service_argv[] = {"systemctl", "start", NULL, NULL};
|
|
|
980768 |
+ const gchar *escape_argv[] = {"systemd-escape", NULL, NULL};
|
|
|
980768 |
GError *error = NULL;
|
|
|
980768 |
gchar *escaped_mpoint = NULL;
|
|
|
980768 |
- gsize len = 0;
|
|
|
980768 |
+ size_t len = 0;
|
|
|
980768 |
|
|
|
980768 |
if (g_str_has_prefix (mount_point, "/"))
|
|
|
980768 |
mount_point++;
|
|
|
980768 |
@@ -1155,14 +1156,27 @@ static void trigger_mpoint_cleanup (const gchar *mount_point)
|
|
|
980768 |
udisks_warning ("Invalid mount point given to trigger_mpoint_cleanup(): %s",
|
|
|
980768 |
mount_point);
|
|
|
980768 |
|
|
|
980768 |
- /* start with the mount point without the leading '/' */
|
|
|
980768 |
- escaped_mpoint = g_strdup (mount_point);
|
|
|
980768 |
+ /* use 'systemd-escape' to escape the mountpoint */
|
|
|
980768 |
+ escape_argv[1] = g_strdup (mount_point);
|
|
|
980768 |
|
|
|
980768 |
- /* and replace all '/'s with '-'s */
|
|
|
980768 |
- for (gchar *letter = escaped_mpoint; *letter != '\0'; letter++, len++)
|
|
|
980768 |
+ if (!bd_utils_exec_and_capture_output (escape_argv, NULL, &escaped_mpoint, &error) && (error != NULL))
|
|
|
980768 |
{
|
|
|
980768 |
- if (*letter == '/')
|
|
|
980768 |
- *letter = '-';
|
|
|
980768 |
+ /* this is a best-effort mechanism, if it fails, just log warning and move
|
|
|
980768 |
+ on */
|
|
|
980768 |
+ udisks_warning ("Failed to setup systemd-based mount point cleanup: %s",
|
|
|
980768 |
+ error->message);
|
|
|
980768 |
+ g_clear_error (&error);
|
|
|
980768 |
+ goto out;
|
|
|
980768 |
+ }
|
|
|
980768 |
+
|
|
|
980768 |
+ /* remove leading/trailing whitespace */
|
|
|
980768 |
+ g_strstrip (escaped_mpoint);
|
|
|
980768 |
+
|
|
|
980768 |
+ len = strlen (escaped_mpoint);
|
|
|
980768 |
+ if (len <= 0)
|
|
|
980768 |
+ {
|
|
|
980768 |
+ udisks_warning ("Failed to setup systemd-based mount point cleanup");
|
|
|
980768 |
+ goto out;
|
|
|
980768 |
}
|
|
|
980768 |
|
|
|
980768 |
/* remove the potential trailing '-' (would happen if the given mount_point
|
|
|
980768 |
@@ -1170,9 +1184,9 @@ static void trigger_mpoint_cleanup (const gchar *mount_point)
|
|
|
980768 |
if (escaped_mpoint[len - 1] == '-')
|
|
|
980768 |
escaped_mpoint[len - 1] = '\0';
|
|
|
980768 |
|
|
|
980768 |
- argv[2] = g_strdup_printf ("clean-mount-point@%s", escaped_mpoint);
|
|
|
980768 |
+ service_argv[2] = g_strdup_printf ("clean-mount-point@%s", escaped_mpoint);
|
|
|
980768 |
|
|
|
980768 |
- if (!bd_utils_exec_and_report_error (argv, NULL, &error) && (error != NULL))
|
|
|
980768 |
+ if (!bd_utils_exec_and_report_error (service_argv, NULL, &error) && (error != NULL))
|
|
|
980768 |
{
|
|
|
980768 |
/* this is a best-effort mechanism, if it fails, just log warning and move
|
|
|
980768 |
on */
|
|
|
980768 |
@@ -1181,8 +1195,10 @@ static void trigger_mpoint_cleanup (const gchar *mount_point)
|
|
|
980768 |
g_clear_error (&error);
|
|
|
980768 |
}
|
|
|
980768 |
|
|
|
980768 |
+out:
|
|
|
980768 |
g_free (escaped_mpoint);
|
|
|
980768 |
- g_free ((gchar *) argv[2]);
|
|
|
980768 |
+ g_free ((gchar *) service_argv[2]);
|
|
|
980768 |
+ g_free ((gchar *) escape_argv[1]);
|
|
|
980768 |
}
|
|
|
980768 |
|
|
|
980768 |
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
980768 |
--
|
|
|
980768 |
1.8.3.1
|
|
|
980768 |
|