diff options
author | Felipe Sateler <fsateler@debian.org> | 2015-06-27 21:00:32 -0300 |
---|---|---|
committer | Felipe Sateler <fsateler@debian.org> | 2015-06-29 16:07:49 -0300 |
commit | 264581a2f1599a27de577549dc75fccefef6a579 (patch) | |
tree | 164ac6c5d432d99cbcd753b39a43cd6c8dc76c02 /src | |
parent | 2c09a745eba5f463e12b498a2f62a5036253c55c (diff) |
sysv-generator: escape names when translating from sysv name
While the LSB suggests only [A-Za-z0-9], that doesn't prevent admins
from doing the wrong thing. Lets not generate invalid names in
that case.
Diffstat (limited to 'src')
-rw-r--r-- | src/sysv-generator/sysv-generator.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/sysv-generator/sysv-generator.c b/src/sysv-generator/sysv-generator.c index c9dd3b6302..0d246b1835 100644 --- a/src/sysv-generator/sysv-generator.c +++ b/src/sysv-generator/sysv-generator.c @@ -241,19 +241,21 @@ static bool usage_contains_reload(const char *line) { static char *sysv_translate_name(const char *name) { char *r; + _cleanup_free_ char *c; - r = new(char, strlen(name) + strlen(".service") + 1); - if (!r) - return NULL; + c = strdup(name); + if (!c) + return NULL; - if (endswith(name, ".sh")) - /* Drop .sh suffix */ - strcpy(stpcpy(r, name) - 3, ".service"); - else - /* Normal init script name */ - strcpy(stpcpy(r, name), ".service"); + r = endswith(c, ".sh"); + if (r) { + *r = '\0'; + } - return r; + if (unit_name_mangle(c, UNIT_NAME_NOGLOB, &r) >= 0) + return r; + else + return NULL; } static int sysv_translate_facility(const char *name, const char *filename, char **_r) { |