From ca944e3bf5acccd25f00e454840e79dbecb938f6 Mon Sep 17 00:00:00 2001 From: Joerg Steffens Date: Fri, 19 Aug 2016 18:12:49 +0200 Subject: [PATCH] configure add: deny adding a director resource Only a single director resource is allowed per director. --- src/dird/dird_conf.c | 6 +++++- src/dird/ua_configure.c | 16 +++++++++++----- src/lib/parse_conf.c | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/dird/dird_conf.c b/src/dird/dird_conf.c index b44c73c5179..4940af90aa5 100644 --- a/src/dird/dird_conf.c +++ b/src/dird/dird_conf.c @@ -1023,7 +1023,11 @@ const char *get_configure_usage_string() * subcommand: add */ for (int r = 0; resources[r].name; r++) { - if (resources[r].items) { + /* + * Only one Director is allowed. + * If the resource have not items, there is no need to add it. + */ + if ((resources[r].rcode != R_DIRECTOR) && (resources[r].items)) { configure_usage_string->strcat("add "); resourcename.strcpy(resources[r].name); resourcename.toLower(); diff --git a/src/dird/ua_configure.c b/src/dird/ua_configure.c index 192fdc7b293..dfcf3f881b2 100644 --- a/src/dird/ua_configure.c +++ b/src/dird/ua_configure.c @@ -349,14 +349,20 @@ static inline bool configure_add(UAContext *ua, int resource_type_parameter) RES_TABLE *res_table = NULL; res_table = my_config->get_resource_table(ua->argk[resource_type_parameter]); - if (res_table) { - ua->send->object_start("configure"); - result = configure_add_resource(ua, resource_type_parameter+1, res_table); - ua->send->object_end("configure"); - } else { + if (!res_table) { ua->error_msg(_("invalid resource type %s.\n"), ua->argk[resource_type_parameter]); + return false; } + if (res_table->rcode == R_DIRECTOR) { + ua->error_msg(_("Only one Director resource allowed.\n")); + return false; + } + + ua->send->object_start("configure"); + result = configure_add_resource(ua, resource_type_parameter+1, res_table); + ua->send->object_end("configure"); + return result; } diff --git a/src/lib/parse_conf.c b/src/lib/parse_conf.c index 89a5e1d05b6..61c61176da0 100644 --- a/src/lib/parse_conf.c +++ b/src/lib/parse_conf.c @@ -169,7 +169,7 @@ bool CONFIG::parse_config_file(const char *cf, void *caller_ctx, LEX_ERROR_HANDL * Make two passes. The first builds the name symbol table, * and the second picks up the items. */ - Dmsg0(900, "Enter parse_config()\n"); + Dmsg1(900, "Enter parse_config_file(%s)\n", cf); for (pass = 1; pass <= 2; pass++) { Dmsg1(900, "parse_config pass %d\n", pass); if ((lc = lex_open_file(lc, cf, scan_error, scan_warning)) == NULL) {