-/*
- *
- * Bacula Director -- User Agent Commands
- *
- * Kern Sibbald, September MM
- *
- * Version $Id$
- */
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
(FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
Switzerland, email:ftf@fsfeurope.org.
*/
-
+/*
+ *
+ * Bacula Director -- User Agent Commands
+ *
+ * Kern Sibbald, September MM
+ *
+ * Version $Id$
+ */
+
#include "bacula.h"
#include "dird.h"
{
unsigned int i;
int len, stat;
+ bool ok = false;
bool found = false;
+ BSOCK *user = ua->UA_sock;
stat = 1;
!acl_access_ok(ua, Command_ACL, ua->argk[0], len)) {
break;
}
- stat = (*commands[i].func)(ua, cmd); /* go execute command */
+ if (ua->api) user->signal(BNET_CMD_BEGIN);
+ ok = (*commands[i].func)(ua, cmd); /* go execute command */
found = true;
break;
}
}
if (!found) {
- bnet_fsend(ua->UA_sock, _("%s: is an invalid command.\n"), ua->argk[0]);
+ user->fsend(_("%s: is an invalid command.\n"), ua->argk[0]);
}
- return stat;
+ if (ua->api) user->signal(ok?BNET_CMD_OK:BNET_CMD_FAILED);
+ return ok;
}
/*
mr->Recycle = pr->Recycle;
mr->VolRetention = pr->VolRetention;
mr->VolUseDuration = pr->VolUseDuration;
+ mr->RecyclePoolId = pr->RecyclePoolId;
mr->MaxVolJobs = pr->MaxVolJobs;
mr->MaxVolFiles = pr->MaxVolFiles;
mr->MaxVolBytes = pr->MaxVolBytes;
JCR *jcr = NULL;
char JobName[MAX_NAME_LENGTH];
- if (!open_client_db(ua)) {
- return 1;
- }
-
for (i=1; i<ua->argc; i++) {
if (strcasecmp(ua->argk[i], NT_("jobid")) == 0) {
uint32_t JobId;
}
}
- /* If we still do not have a jcr,
- * throw up a list and ask the user to select one.
- */
- if (!jcr) {
+ if (jcr) {
+ if (jcr->job && !acl_access_ok(ua, Job_ACL, jcr->job->name())) {
+ bsendmsg(ua, _("Unauthorized command from this console.\n"));
+ return 1;
+ }
+ } else {
+ /*
+ * If we still do not have a jcr,
+ * throw up a list and ask the user to select one.
+ */
char buf[1000];
+ int tjobs = 0; /* total # number jobs */
/* Count Jobs running */
foreach_jcr(jcr) {
if (jcr->JobId == 0) { /* this is us */
continue;
}
- njobs++;
+ tjobs++; /* count of all jobs */
+ if (!acl_access_ok(ua, Job_ACL, jcr->job->name())) {
+ continue; /* skip not authorized */
+ }
+ njobs++; /* count of authorized jobs */
}
endeach_jcr(jcr);
- if (njobs == 0) {
- bsendmsg(ua, _("No Jobs running.\n"));
+ if (njobs == 0) { /* no authorized */
+ if (tjobs == 0) {
+ bsendmsg(ua, _("No Jobs running.\n"));
+ } else {
+ bsendmsg(ua, _("None of your jobs are running.\n"));
+ }
return 1;
}
+
start_prompt(ua, _("Select Job:\n"));
foreach_jcr(jcr) {
char ed1[50];
if (jcr->JobId == 0) { /* this is us */
continue;
}
+ if (!acl_access_ok(ua, Job_ACL, jcr->job->name())) {
+ continue; /* skip not authorized */
+ }
bsnprintf(buf, sizeof(buf), _("JobId=%s Job=%s"), edit_int64(jcr->JobId, ed1), jcr->Job);
add_prompt(ua, buf);
}
sscanf(buf, "JobId=%d Job=%127s", &njobs, JobName);
jcr = get_jcr_by_full_name(JobName);
if (!jcr) {
- bsendmsg(ua, _("Job %s not found.\n"), JobName);
+ bsendmsg(ua, _("Job \"%s\" not found.\n"), JobName);
return 1;
}
}
* the setting of MaxVols and NumVols slightly differently
* depending on if we are creating the Pool or we are
* simply bringing it into agreement with the resource (updage).
+ *
+ * Caution : RecyclePoolId isn't setup in this function.
+ * You can use set_pooldbr_recyclepoolid();
+ *
*/
void set_pooldbr_from_poolres(POOL_DBR *pr, POOL *pool, e_pool_op op)
{
}
}
+/* set/update Pool.RecyclePoolId in Catalog */
+int update_pool_recyclepool(JCR *jcr, B_DB *db, POOL *pool)
+{
+ POOL_DBR pr;
+
+ if (!pool->RecyclePool) {
+ return 1;
+ }
+
+ memset(&pr, 0, sizeof(POOL_DBR));
+ bstrncpy(pr.Name, pool->name(), sizeof(pr.Name));
+
+ if (!db_get_pool_record(jcr, db, &pr)) {
+ return -1; /* not exists in database */
+ }
+
+ set_pooldbr_from_poolres(&pr, pool, POOL_OP_UPDATE);
+
+ if (!set_pooldbr_recyclepoolid(jcr, db, &pr, pool)) {
+ return -1; /* error */
+ }
+
+ if (!db_update_pool_record(jcr, db, &pr)) {
+ return -1; /* error */
+ }
+ return 1;
+}
+
+/* set POOL_DBR.RecyclePoolId from Pool resource
+ * works with set_pooldbr_from_poolres
+ */
+bool set_pooldbr_recyclepoolid(JCR *jcr, B_DB *db, POOL_DBR *pr, POOL *pool)
+{
+ POOL_DBR rpool;
+ bool ret = true;
+
+ if (pool->RecyclePool) {
+ memset(&rpool, 0, sizeof(POOL_DBR));
+
+ bstrncpy(rpool.Name, pool->RecyclePool->name(), sizeof(rpool.Name));
+ if (db_get_pool_record(jcr, db, &rpool)) {
+ pr->RecyclePoolId = rpool.PoolId;
+ } else {
+ Jmsg(jcr, M_WARNING, 0,
+ _("Can't set %s RecyclePool to %s, %s is not in database.\n" \
+ "Try to update it with 'update pool=%s'\n"),
+ pool->name(), rpool.Name, rpool.Name,pool->name());
+
+ ret = false;
+ }
+ } else { /* no RecyclePool used, set it to 0 */
+ pr->RecyclePoolId = 0;
+ }
+ return ret;
+}
+
/*
* Create a pool record from a given Pool resource
int quit_cmd(UAContext *ua, const char *cmd)
{
- ua->quit = TRUE;
+ ua->quit = true;
return 1;
}
* This call explicitly checks for a catalog=xxx and
* if given, opens that catalog. It also checks for
* client=xxx and if found, opens the catalog
- * corresponding to that client.
+ * corresponding to that client. If we still don't
+ * have a catalog, look for a Job keyword and get the
+ * catalog from its client record.
*/
bool open_client_db(UAContext *ua)
{
int i;
CAT *catalog;
CLIENT *client;
+ JOB *job;
/* Try for catalog keyword */
i = find_arg_with_value(ua, NT_("catalog"));
if (i >= 0) {
if (!acl_access_ok(ua, Catalog_ACL, ua->argv[i])) {
- bsendmsg(ua, _("No authorization for catalog \"%s\"\n"), ua->argv[i]);
+ bsendmsg(ua, _("No authorization for Catalog \"%s\"\n"), ua->argv[i]);
return false;
}
catalog = (CAT *)GetResWithName(R_CATALOG, ua->argv[i]);
/* Try for client keyword */
i = find_arg_with_value(ua, NT_("client"));
if (i >= 0) {
- if (!acl_access_ok(ua, Catalog_ACL, ua->argv[i])) {
- bsendmsg(ua, _("No authorization for client \"%s\"\n"), ua->argv[i]);
+ if (!acl_access_ok(ua, Client_ACL, ua->argv[i])) {
+ bsendmsg(ua, _("No authorization for Client \"%s\"\n"), ua->argv[i]);
return false;
}
client = (CLIENT *)GetResWithName(R_CLIENT, ua->argv[i]);
if (client) {
- if (ua->catalog && ua->catalog != client->catalog) {
+ catalog = client->catalog;
+ if (ua->catalog && ua->catalog != catalog) {
+ close_db(ua);
+ }
+ if (!acl_access_ok(ua, Catalog_ACL, catalog->name())) {
+ bsendmsg(ua, _("No authorization for Catalog \"%s\"\n"), catalog->name());
+ return false;
+ }
+ ua->catalog = catalog;
+ return open_db(ua);
+ }
+ }
+
+ /* Try for Job keyword */
+ i = find_arg_with_value(ua, NT_("job"));
+ if (i >= 0) {
+ if (!acl_access_ok(ua, Job_ACL, ua->argv[i])) {
+ bsendmsg(ua, _("No authorization for Job \"%s\"\n"), ua->argv[i]);
+ return false;
+ }
+ job = (JOB *)GetResWithName(R_JOB, ua->argv[i]);
+ if (job) {
+ catalog = job->client->catalog;
+ if (ua->catalog && ua->catalog != catalog) {
close_db(ua);
}
- ua->catalog = client->catalog;
+ if (!acl_access_ok(ua, Catalog_ACL, catalog->name())) {
+ bsendmsg(ua, _("No authorization for Catalog \"%s\"\n"), catalog->name());
+ return false;
+ }
+ ua->catalog = catalog;
return open_db(ua);
}
}
+
return open_db(ua);
}
-
-
/*
* Open the catalog database.
*/