summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorAnita Zhang <the.anitazha@gmail.com>2019-10-04 16:03:04 -0700
committerAnita Zhang <the.anitazha@gmail.com>2019-10-07 12:02:12 -0700
commite23d911664b4fd86eb2c24b64233cb9f23cffdd1 (patch)
tree8ab06f0dd7a626ed1ca9603240c37a9ca2e9cf5f /src/basic
parent0490b44031f0406ad053e150349666605b22ab15 (diff)
downloadsystemd-e23d911664b4fd86eb2c24b64233cb9f23cffdd1.tar.gz
core: disallow using '-.service' as a service name
-.service.d will become a special top level drop in so don't let it be a usable service name (otherwise the interaction gets complicated).
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/special.h4
-rw-r--r--src/basic/unit-name.c25
-rw-r--r--src/basic/unit-name.h2
3 files changed, 31 insertions, 0 deletions
diff --git a/src/basic/special.h b/src/basic/special.h
index add1c1d507..6475501078 100644
--- a/src/basic/special.h
+++ b/src/basic/special.h
@@ -105,3 +105,7 @@
/* The root directory. */
#define SPECIAL_ROOT_MOUNT "-.mount"
+
+/* Used to apply settings to all services through drop-ins.
+ * Should not exist as an actual service. */
+#define SPECIAL_ROOT_SERVICE "-.service"
diff --git a/src/basic/unit-name.c b/src/basic/unit-name.c
index 4226f3014d..ecbf5ae7f5 100644
--- a/src/basic/unit-name.c
+++ b/src/basic/unit-name.c
@@ -665,6 +665,31 @@ good:
return 0;
}
+bool service_unit_name_is_valid(const char *name) {
+ _cleanup_free_ char *prefix = NULL, *s = NULL;
+ const char *e, *service_name = name;
+
+ if (!unit_name_is_valid(name, UNIT_NAME_ANY))
+ return false;
+
+ e = endswith(name, ".service");
+ if (!e)
+ return false;
+
+ /* If it's a template or instance, get the prefix as a service name. */
+ if (unit_name_is_valid(name, UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE)) {
+ assert_se(unit_name_to_prefix(name, &prefix) == 0);
+ assert_se(s = strjoin(prefix, ".service"));
+ service_name = s;
+ }
+
+ /* Reject reserved service name(s). */
+ if (streq(service_name, SPECIAL_ROOT_SERVICE))
+ return false;
+
+ return true;
+}
+
int slice_build_parent_slice(const char *slice, char **ret) {
char *s, *dash;
int r;
diff --git a/src/basic/unit-name.h b/src/basic/unit-name.h
index 2e060ff3e8..ddcfc1b349 100644
--- a/src/basic/unit-name.h
+++ b/src/basic/unit-name.h
@@ -58,6 +58,8 @@ static inline int unit_name_mangle(const char *name, UnitNameMangle flags, char
return unit_name_mangle_with_suffix(name, flags, ".service", ret);
}
+bool service_unit_name_is_valid(const char *name);
+
int slice_build_parent_slice(const char *slice, char **ret);
int slice_build_subslice(const char *slice, const char *name, char **subslice);
bool slice_name_is_valid(const char *name);