author | Olivier Brunel
<jjk@jjacky.com> 2015-08-14 17:22:58 UTC |
committer | Olivier Brunel
<jjk@jjacky.com> 2015-08-14 17:22:58 UTC |
parent | 849f7c5bac5bbac0cb62b9a2173e37c688aa070e |
src/libanopa/deps-lib/anopa | +1 | -0 |
src/libanopa/enable_service.c | +2 | -13 |
src/libanopa/service.c | +3 | -0 |
src/libanopa/service_internal.h | +2 | -0 |
src/libanopa/service_name.c | +37 | -0 |
diff --git a/src/libanopa/deps-lib/anopa b/src/libanopa/deps-lib/anopa index 7ca4d1c..95eb75b 100644 --- a/src/libanopa/deps-lib/anopa +++ b/src/libanopa/deps-lib/anopa @@ -12,6 +12,7 @@ output.o progress.o sa_sources.o service.o +service_name.o service_start.o service_stop.o services.o diff --git a/src/libanopa/enable_service.c b/src/libanopa/enable_service.c index 12e50f7..daa82e1 100644 --- a/src/libanopa/enable_service.c +++ b/src/libanopa/enable_service.c @@ -38,6 +38,7 @@ #include <anopa/copy_file.h> #include <anopa/scan_dir.h> #include <anopa/err.h> +#include "service_internal.h" static int copy_from_source (const char *name, @@ -56,18 +57,6 @@ copy_dir (const char *src, const char *instance); -static int -is_valid_service_name (const char *name, int len) -{ - if (len <= 0) - return 0; - if (name[0] == '@' || name[len - 1] == '@') - return 0; - if (byte_chr (name, len, '/') < len) - return 0; - return 1; -} - static int copy_log (const char *name, const char *cfg, mode_t mode, aa_warn_fn warn_fn) { @@ -580,7 +569,7 @@ aa_enable_service (const char *_name, l_name -= r; } - if (!is_valid_service_name (name, l_name)) + if (!_is_valid_service_name (name, l_name)) return -ERR_INVALID_NAME; if (*_name == '/') diff --git a/src/libanopa/service.c b/src/libanopa/service.c index 0a82095..83a053c 100644 --- a/src/libanopa/service.c +++ b/src/libanopa/service.c @@ -93,6 +93,9 @@ get_new_service (const char *name) }; struct stat st; + if (!_is_valid_service_name (name, strlen (name))) + return -ERR_INVALID_NAME; + if (stat (name, &st) < 0) { if (errno == ENOENT) diff --git a/src/libanopa/service_internal.h b/src/libanopa/service_internal.h index 14bda36..e173bb3 100644 --- a/src/libanopa/service_internal.h +++ b/src/libanopa/service_internal.h @@ -37,6 +37,8 @@ struct it_data aa_load_fail_cb lf_cb; }; +extern int _is_valid_service_name (const char *name, int len); + extern int _it_start_needs (direntry *d, void *data); extern int _it_start_wants (direntry *d, void *data); extern int _it_start_after (direntry *d, void *data); diff --git a/src/libanopa/service_name.c b/src/libanopa/service_name.c new file mode 100644 index 0000000..32bad28 --- /dev/null +++ b/src/libanopa/service_name.c @@ -0,0 +1,37 @@ +/* + * anopa - Copyright (C) 2015 Olivier Brunel + * + * service_name.c + * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * + * This file is part of anopa. + * + * anopa is free software: you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * anopa is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * anopa. If not, see http://www.gnu.org/licenses/ + */ + +#include <skalibs/bytestr.h> + +int +_is_valid_service_name (const char *name, int len) +{ + if (len <= 0) + return 0; + if (name[0] == '.') + return 0; + if (name[0] == '@' || name[len - 1] == '@') + return 0; + if (byte_chr (name, len, '/') < len) + return 0; + return 1; +}