summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Kletzander <mkletzan@redhat.com>2015-11-27 14:24:38 +0100
committerCole Robinson <crobinso@redhat.com>2015-12-23 17:54:51 -0500
commitac3dbf5a68f9bbfb0d498a8937beeb2b99cd8321 (patch)
tree5bedeff85db26c7ad10c8f2151c84e4ef67091f2 /src
parentc0fa258b3df906bffd00e8b1ea825cb21eaa2579 (diff)
downloadlibvirt-ac3dbf5a68f9bbfb0d498a8937beeb2b99cd8321.tar.gz
systemd: Escape only needed characters for machined
Machine name escaping follows the same rules as serice name escape, except that '.' and '-' must not be escaped in machine names, due to a bug in systemd-machined. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1282846 Signed-off-by: Martin Kletzander <mkletzan@redhat.com> (cherry picked from commit 0e0149ce91d84f40b98acf4c4bb0da6e29b9c15c)
Diffstat (limited to 'src')
-rw-r--r--src/util/virsystemd.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
index 0c8f026437..438746ede5 100644
--- a/src/util/virsystemd.c
+++ b/src/util/virsystemd.c
@@ -38,8 +38,17 @@
VIR_LOG_INIT("util.systemd");
+/**
+ * virSystemdEscapeName:
+ *
+ * This function escapes various characters in @name and appends that
+ * escaped string to @buf, in order to comply with the requirements
+ * from systemd/machined. Parameter @full_escape decides whether to
+ * also escape dot as a first character and '-'.
+ */
static void virSystemdEscapeName(virBufferPtr buf,
- const char *name)
+ const char *name,
+ bool full_escape)
{
static const char hextable[16] = "0123456789abcdef";
@@ -57,7 +66,7 @@ static void virSystemdEscapeName(virBufferPtr buf,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
":-_.\\"
- if (*name == '.') {
+ if (full_escape && *name == '.') {
ESCAPE(*name);
name++;
}
@@ -65,7 +74,7 @@ static void virSystemdEscapeName(virBufferPtr buf,
while (*name) {
if (*name == '/')
virBufferAddChar(buf, '-');
- else if (*name == '-' ||
+ else if ((full_escape && *name == '-') ||
*name == '\\' ||
!strchr(VALID_CHARS, *name))
ESCAPE(*name);
@@ -85,9 +94,9 @@ char *virSystemdMakeScopeName(const char *name,
virBuffer buf = VIR_BUFFER_INITIALIZER;
virBufferAddLit(&buf, "machine-");
- virSystemdEscapeName(&buf, drivername);
+ virSystemdEscapeName(&buf, drivername, true);
virBufferAddLit(&buf, "\\x2d");
- virSystemdEscapeName(&buf, name);
+ virSystemdEscapeName(&buf, name, true);
virBufferAddLit(&buf, ".scope");
if (virBufferCheckError(&buf) < 0)
@@ -104,7 +113,7 @@ char *virSystemdMakeSliceName(const char *partition)
if (*partition == '/')
partition++;
- virSystemdEscapeName(&buf, partition);
+ virSystemdEscapeName(&buf, partition, true);
virBufferAddLit(&buf, ".slice");
if (virBufferCheckError(&buf) < 0)
@@ -130,7 +139,7 @@ char *virSystemdMakeMachineName(const char *name,
virBufferAsprintf(&buf, "%s-%s-", username, drivername);
}
- virSystemdEscapeName(&buf, name);
+ virSystemdEscapeName(&buf, name, false);
machinename = virBufferContentAndReset(&buf);
cleanup: