From 8f33794cb436d5d2eb2d81daa9b6cbf888f81510 Mon Sep 17 00:00:00 2001 From: Marco van Wieringen Date: Wed, 16 Apr 2014 19:20:14 +0200 Subject: [PATCH] Allow to disable client in client configuration Fixes #288: Disable client in client configuration --- src/dird/dird_conf.c | 1 + src/dird/dird_conf.h | 3 +- src/dird/protos.h | 1 + src/dird/scheduler.c | 15 ++++++--- src/dird/ua_cmds.c | 76 +++++++++++++++++++++++++++++++------------ src/dird/ua_dotcmds.c | 1 + src/dird/ua_output.c | 53 ++++++++++++++++++++++++++---- src/dird/ua_select.c | 30 +++++++++++++++-- src/dird/ua_status.c | 14 +++++--- 9 files changed, 155 insertions(+), 39 deletions(-) diff --git a/src/dird/dird_conf.c b/src/dird/dird_conf.c index 9e4dd184d97..fb89c028892 100644 --- a/src/dird/dird_conf.c +++ b/src/dird/dird_conf.c @@ -185,6 +185,7 @@ static RES_ITEM cli_items[] = { { "fdpassword", CFG_TYPE_AUTOPASSWORD, ITEM(res_client.password), 0, CFG_ITEM_ALIAS, NULL }, { "catalog", CFG_TYPE_RES, ITEM(res_client.catalog), R_CATALOG, 0, NULL }, { "passive", CFG_TYPE_BOOL, ITEM(res_client.passive), 0, CFG_ITEM_DEFAULT, "false" }, + { "enabled", CFG_TYPE_BOOL, ITEM(res_client.enabled), 0, CFG_ITEM_DEFAULT, "true" }, { "hardquota", CFG_TYPE_SIZE64, ITEM(res_client.HardQuota), 0, CFG_ITEM_DEFAULT, "0" }, { "softquota", CFG_TYPE_SIZE64, ITEM(res_client.SoftQuota), 0, CFG_ITEM_DEFAULT, "0" }, { "softquotagraceperiod", CFG_TYPE_TIME, ITEM(res_client.SoftQuotaGracePeriod), 0, CFG_ITEM_DEFAULT, "0" }, diff --git a/src/dird/dird_conf.h b/src/dird/dird_conf.h index 7dc514b4a68..8ebff5faba0 100644 --- a/src/dird/dird_conf.h +++ b/src/dird/dird_conf.h @@ -3,7 +3,7 @@ Copyright (C) 2000-2011 Free Software Foundation Europe e.V. Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2013 Bareos GmbH & Co. KG + Copyright (C) 2013-2014 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -298,6 +298,7 @@ class CLIENTRES: public BRSRES { alist *tls_allowed_cns; /* TLS Allowed Clients */ TLS_CONTEXT *tls_ctx; /* Shared TLS Context */ bool passive; /* Passive Client */ + bool enabled; /* Set if client is enabled */ bool tls_authenticate; /* Authenticated with TLS */ bool tls_enable; /* Enable TLS */ diff --git a/src/dird/protos.h b/src/dird/protos.h index 2664286a919..a60348a3087 100644 --- a/src/dird/protos.h +++ b/src/dird/protos.h @@ -291,6 +291,7 @@ JOBRES *select_job_resource(UAContext *ua); JOBRES *select_enable_disable_job_resource(UAContext *ua, bool enable); JOBRES *select_restore_job_resource(UAContext *ua); CLIENTRES *select_client_resource(UAContext *ua); +CLIENTRES *select_enable_disable_client_resource(UAContext *ua, bool enable); FILESETRES *select_fileset_resource(UAContext *ua); int select_pool_and_media_dbr(UAContext *ua, POOL_DBR *pr, MEDIA_DBR *mr); int select_media_dbr(UAContext *ua, MEDIA_DBR *mr); diff --git a/src/dird/scheduler.c b/src/dird/scheduler.c index 81234c7a977..240666625fc 100644 --- a/src/dird/scheduler.c +++ b/src/dird/scheduler.c @@ -3,7 +3,7 @@ Copyright (C) 2000-2011 Free Software Foundation Europe e.V. Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2013 Bareos GmbH & Co. KG + Copyright (C) 2013-2014 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -177,17 +177,22 @@ JCR *wait_for_next_job(char *one_shot_job_to_run) schedules_invalidated = true; } } + jcr = new_jcr(sizeof(JCR), dird_free_jcr); run = next_job->run; /* pick up needed values */ job = next_job->job; - if (job->enabled) { + + if (job->enabled && (!job->client || job->client->enabled)) { dump_job(next_job, _("Run job")); } + free(next_job); - if (!job->enabled) { + + if (!job->enabled || (job->client && !job->client->enabled)) { free_jcr(jcr); goto again; /* ignore this job */ } + run->last_run = now; /* mark as run now */ ASSERT(job); @@ -343,7 +348,9 @@ static void find_runs() LockRes(); foreach_res(job, R_JOB) { sched = job->schedule; - if (sched == NULL || !job->enabled) { /* scheduled? or enabled? */ + if (sched == NULL || + !job->enabled || + (job->client && !job->client->enabled)) { /* scheduled? or enabled? */ continue; /* no, skip this job */ } Dmsg1(dbglvl, "Got job: %s\n", job->hdr.name); diff --git a/src/dird/ua_cmds.c b/src/dird/ua_cmds.c index 1af509af03d..4bbf1be54f8 100644 --- a/src/dird/ua_cmds.c +++ b/src/dird/ua_cmds.c @@ -3,7 +3,7 @@ Copyright (C) 2000-2012 Free Software Foundation Europe e.V. Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2013 Bareos GmbH & Co. KG + Copyright (C) 2013-2014 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -111,10 +111,10 @@ static struct cmdstruct commands[] = { NT_("pool="), false }, { NT_("delete"), delete_cmd, _("Delete volume, pool or job"), NT_("volume= pool= jobid="), true }, - { NT_("disable"), disable_cmd, _("Disable a job"), - NT_("job="), true }, - { NT_("enable"), enable_cmd, _("Enable a job"), - NT_("job="), true }, + { NT_("disable"), disable_cmd, _("Disable a job/client"), + NT_("job= client="), true }, + { NT_("enable"), enable_cmd, _("Enable a job/client"), + NT_("job= client="), true }, { NT_("estimate"), estimate_cmd, _("Performs FileSet estimate, listing gives full listing"), NT_("fileset= client= level= accurate= job= listing"), true }, { NT_("exit"), quit_cmd, _("Terminate Bconsole session"), @@ -943,32 +943,66 @@ static int setip_cmd(UAContext *ua, const char *cmd) static void do_en_disable_cmd(UAContext *ua, bool setting) { - JOBRES *job; + CLIENTRES *client = NULL; + JOBRES *job = NULL; int i; - i = find_arg_with_value(ua, NT_("job")); - if (i < 0) { - job = select_enable_disable_job_resource(ua, setting); - if (!job) { + i = find_arg(ua, NT_("client")); + if (i >= 0) { + i = find_arg_with_value(ua, NT_("client")); + if (i >= 0) { + LockRes(); + client = GetClientResWithName(ua->argv[i]); + UnlockRes(); + } else { + client = select_enable_disable_client_resource(ua, setting); + if (!client) { + return; + } + } + + if (!client) { + ua->error_msg(_("Client \"%s\" not found.\n"), ua->argv[i]); return; } } else { - LockRes(); - job = GetJobResWithName(ua->argv[i]); - UnlockRes(); + i = find_arg_with_value(ua, NT_("job")); + if (i >= 0) { + LockRes(); + job = GetJobResWithName(ua->argv[i]); + UnlockRes(); + } else { + job = select_enable_disable_job_resource(ua, setting); + if (!job) { + return; + } + } + + if (!job) { + ua->error_msg(_("Job \"%s\" not found.\n"), ua->argv[i]); + return; + } } - if (!job) { - ua->error_msg(_("Job \"%s\" not found.\n"), ua->argv[i]); + + if (client) { + if (!acl_access_ok(ua, Client_ACL, client->name())) { + ua->error_msg(_("Unauthorized command from this console.\n")); + return; + } + + client->enabled = setting; + ua->send_msg(_("Client \"%s\" %sabled\n"), client->name(), setting ? "en" : "dis"); return; - } + } else if (job) { + if (!acl_access_ok(ua, Job_ACL, job->name())) { + ua->error_msg(_("Unauthorized command from this console.\n")); + return; + } - if (!acl_access_ok(ua, Job_ACL, job->name())) { - ua->error_msg(_("Unauthorized command from this console.\n")); + job->enabled = setting; + ua->send_msg(_("Job \"%s\" %sabled\n"), job->name(), setting ? "en" : "dis"); return; } - job->enabled = setting; - ua->send_msg(_("Job \"%s\" %sabled\n"), job->name(), setting?"en":"dis"); - return; } static int enable_cmd(UAContext *ua, const char *cmd) diff --git a/src/dird/ua_dotcmds.c b/src/dird/ua_dotcmds.c index 04556093b95..dd91fd85afb 100644 --- a/src/dird/ua_dotcmds.c +++ b/src/dird/ua_dotcmds.c @@ -1178,6 +1178,7 @@ static bool defaultscmd(UAContext *ua, const char *cmd) ua->send_msg("file_retention=%s", edit_uint64(client->FileRetention, ed1)); ua->send_msg("job_retention=%s", edit_uint64(client->JobRetention, ed1)); ua->send_msg("autoprune=%d", client->AutoPrune); + ua->send_msg("enabled=%d", client->enabled); ua->send_msg("catalog=%s", client->catalog->name()); } } else if (bstrcmp(ua->argk[1], "storage")) { diff --git a/src/dird/ua_output.c b/src/dird/ua_output.c index 4eceb79cdee..4291ec6d6a9 100644 --- a/src/dird/ua_output.c +++ b/src/dird/ua_output.c @@ -3,7 +3,7 @@ Copyright (C) 2000-2012 Free Software Foundation Europe e.V. Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2013 Bareos GmbH & Co. KG + Copyright (C) 2013-2014 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -98,10 +98,12 @@ static void show_disabled_jobs(UAContext *ua) { JOBRES *job; bool first = true; + foreach_res(job, R_JOB) { if (!acl_access_ok(ua, Job_ACL, job->name())) { continue; } + if (!job->enabled) { if (first) { first = false; @@ -110,11 +112,39 @@ static void show_disabled_jobs(UAContext *ua) ua->send_msg(" %s\n", job->name()); } } + if (first) { ua->send_msg(_("No disabled Jobs.\n")); } } +/* + * Enter with Resources locked + */ +static void show_disabled_clients(UAContext *ua) +{ + CLIENTRES *client; + bool first = true; + + foreach_res(client, R_CLIENT) { + if (!acl_access_ok(ua, Client_ACL, client->name())) { + continue; + } + + if (!client->enabled) { + if (first) { + first = false; + ua->send_msg(_("Disabled Clients:\n")); + } + ua->send_msg(" %s\n", client->name()); + } + } + + if (first) { + ua->send_msg(_("No disabled Clients.\n")); + } +} + struct showstruct { const char *res_name; int type; @@ -143,9 +173,11 @@ static struct showstruct avail_resources[] = { * Displays Resources * * show all - * show e.g. show directors - * show = e.g. show director=HeadMan - * show disabled shows disabled jobs + * show - e.g. show directors + * show = - e.g. show director=HeadMan + * show disabled - shows disabled jobs and clients + * show disabled jobs - shows disabled jobs + * show disabled clients - shows disabled clients * */ int show_cmd(UAContext *ua, const char *cmd) @@ -158,11 +190,20 @@ int show_cmd(UAContext *ua, const char *cmd) Dmsg1(20, "show: %s\n", ua->UA_sock->msg); LockRes(); - for (i=1; iargc; i++) { + for (i = 1; i < ua->argc; i++) { if (bstrcasecmp(ua->argk[i], _("disabled"))) { - show_disabled_jobs(ua); + if (((i + 1) < ua->argc) && bstrcasecmp(ua->argk[i + 1], NT_("jobs"))) { + show_disabled_jobs(ua); + } else if (((i + 1) < ua->argc) && bstrcasecmp(ua->argk[i + 1], NT_("clients"))) { + show_disabled_clients(ua); + } else { + show_disabled_jobs(ua); + show_disabled_clients(ua); + } + goto bail_out; } + type = 0; res_name = ua->argk[i]; if (!ua->argv[i]) { /* was a name given? */ diff --git a/src/dird/ua_select.c b/src/dird/ua_select.c index ee679f07183..5785fc99fbd 100644 --- a/src/dird/ua_select.c +++ b/src/dird/ua_select.c @@ -3,7 +3,7 @@ Copyright (C) 2001-2012 Free Software Foundation Europe e.V. Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2013 Bareos GmbH & Co. KG + Copyright (C) 2013-2014 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -233,7 +233,6 @@ CATRES *get_catalog_resource(UAContext *ua) return catalog; } - /* * Select a job to enable or disable */ @@ -348,6 +347,33 @@ CLIENTRES *select_client_resource(UAContext *ua) return client; } +/* + * Select a client to enable or disable + */ +CLIENTRES *select_enable_disable_client_resource(UAContext *ua, bool enable) +{ + char name[MAX_NAME_LENGTH]; + CLIENTRES *client; + + LockRes(); + start_prompt(ua, _("The defined Client resources are:\n")); + foreach_res(client, R_CLIENT) { + if (!acl_access_ok(ua, Client_ACL, client->name())) { + continue; + } + if (client->enabled == enable) { /* Already enabled/disabled? */ + continue; /* yes, skip */ + } + add_prompt(ua, client->name()); + } + UnlockRes(); + if (do_prompt(ua, _("Client"), _("Select Client resource"), name, sizeof(name)) < 0) { + return NULL; + } + client = (CLIENTRES *)GetResWithName(R_CLIENT, name); + return client; +} + /* * Get client resource, start by looking for * client= diff --git a/src/dird/ua_status.c b/src/dird/ua_status.c index 732ea69a68b..70863ac4327 100644 --- a/src/dird/ua_status.c +++ b/src/dird/ua_status.c @@ -663,7 +663,8 @@ static void do_scheduler_status(UAContext *ua) if (cnt++ == 0) { ua->send_msg("%s\n", sched->hdr.name); } - if (job->enabled) { + if (job->enabled && + (!job->client || job->client->enabled)) { ua->send_msg(" %s\n", job->name()); } else { ua->send_msg(" %s (disabled)\n", job->name()); @@ -873,8 +874,7 @@ static int compare_by_runtime_priority(void *item1, void *item2) } /* - * Find all jobs to be run in roughly the - * next 24 hours. + * Find all jobs to be run in roughly the next 24 hours. */ static void list_scheduled_jobs(UAContext *ua) { @@ -900,10 +900,14 @@ static void list_scheduled_jobs(UAContext *ua) } } - /* Loop through all jobs */ + /* + * Loop through all jobs + */ LockRes(); foreach_res(job, R_JOB) { - if (!acl_access_ok(ua, Job_ACL, job->name()) || !job->enabled) { + if (!acl_access_ok(ua, Job_ACL, job->name()) || + !job->enabled || + (job->client && !job->client->enabled)) { continue; } for (run = NULL; (run = find_next_run(run, job, runtime, days)); ) {