Skip to content

Commit

Permalink
Allow to disable client in client configuration
Browse files Browse the repository at this point in the history
Fixes #288: Disable client in client configuration
  • Loading branch information
Marco van Wieringen committed Feb 17, 2015
1 parent 5a78151 commit 2cc4be3
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 39 deletions.
1 change: 1 addition & 0 deletions src/dird/dird_conf.c
Expand Up @@ -205,6 +205,7 @@ static RES_ITEM cli_items[] = {
{ "fdpassword", store_clearpassword, ITEM(res_client.password), 0, 0, NULL },
{ "catalog", store_res, ITEM(res_client.catalog), R_CATALOG, 0, NULL },
{ "passive", store_bool, ITEM(res_client.passive), 0, ITEM_DEFAULT, "false" },
{ "enabled", store_bool, ITEM(res_client.enabled), 0, ITEM_DEFAULT, "true" },
{ "hardquota", store_size64, ITEM(res_client.HardQuota), 0, ITEM_DEFAULT, "0" },
{ "softquota", store_size64, ITEM(res_client.SoftQuota), 0, ITEM_DEFAULT, "0" },
{ "softquotagraceperiod", store_time, ITEM(res_client.SoftQuotaGracePeriod), 0, ITEM_DEFAULT, "0" },
Expand Down
3 changes: 2 additions & 1 deletion src/dird/dird_conf.h
Expand Up @@ -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
Expand Down Expand Up @@ -287,6 +287,7 @@ class CLIENTRES {
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 */
bool tls_require; /* Require TLS */
Expand Down
1 change: 1 addition & 0 deletions src/dird/protos.h
Expand Up @@ -289,6 +289,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);
Expand Down
15 changes: 11 additions & 4 deletions src/dird/scheduler.c
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
76 changes: 55 additions & 21 deletions src/dird/ua_cmds.c
Expand Up @@ -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
Expand Down Expand Up @@ -110,10 +110,10 @@ static struct cmdstruct commands[] = {
NT_("pool=<pool-name>"), false },
{ NT_("delete"), delete_cmd, _("Delete volume, pool or job"),
NT_("volume=<vol-name> pool=<pool-name> jobid=<jobid>"), true },
{ NT_("disable"), disable_cmd, _("Disable a job"),
NT_("job=<job-name>"), true },
{ NT_("enable"), enable_cmd, _("Enable a job"),
NT_("job=<job-name>"), true },
{ NT_("disable"), disable_cmd, _("Disable a job/client"),
NT_("job=<job-name> client=<client-name>"), true },
{ NT_("enable"), enable_cmd, _("Enable a job/client"),
NT_("job=<job-name> client=<client-name>"), true },
{ NT_("estimate"), estimate_cmd, _("Performs FileSet estimate, listing gives full listing"),
NT_("fileset=<fileset-name> client=<client-name> level=<level> accurate=<yes/no> job=<job-name> listing"), true },
{ NT_("exit"), quit_cmd, _("Terminate Bconsole session"),
Expand Down Expand Up @@ -932,32 +932,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)
Expand Down
1 change: 1 addition & 0 deletions src/dird/ua_dotcmds.c
Expand Up @@ -1170,6 +1170,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")) {
Expand Down
53 changes: 47 additions & 6 deletions src/dird/ua_output.c
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -142,9 +172,11 @@ static struct showstruct avail_resources[] = {
* Displays Resources
*
* show all
* show <resource-keyword-name> e.g. show directors
* show <resource-keyword-name>=<name> e.g. show director=HeadMan
* show disabled shows disabled jobs
* show <resource-keyword-name> - e.g. show directors
* show <resource-keyword-name>=<name> - 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)
Expand All @@ -157,11 +189,20 @@ int show_cmd(UAContext *ua, const char *cmd)
Dmsg1(20, "show: %s\n", ua->UA_sock->msg);

LockRes();
for (i=1; i<ua->argc; 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? */
Expand Down
30 changes: 28 additions & 2 deletions src/dird/ua_select.c
Expand Up @@ -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
Expand Down Expand Up @@ -233,7 +233,6 @@ CATRES *get_catalog_resource(UAContext *ua)
return catalog;
}


/*
* Select a job to enable or disable
*/
Expand Down Expand Up @@ -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=<client-name>
Expand Down
14 changes: 9 additions & 5 deletions src/dird/ua_status.c
Expand Up @@ -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());
Expand Down Expand Up @@ -870,8 +871,7 @@ static int my_compare(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)
{
Expand All @@ -897,10 +897,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)); ) {
Expand Down

0 comments on commit 2cc4be3

Please sign in to comment.