]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_cmds.c
- Fix the block listing bug pointed out by Arno.
[bacula/bacula] / bacula / src / dird / ua_cmds.c
index 2c90337aacc89088d51548a06875c03af0893692..1ecc80c8193ae11af06a331d56e2b02be8bcbade 100644 (file)
@@ -7,7 +7,7 @@
  *   Version $Id$
  */
 /*
-   Copyright (C) 2000-2005 Kern Sibbald
+   Copyright (C) 2000-2006 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
@@ -56,6 +56,8 @@ extern int update_cmd(UAContext *ua, const char *cmd);
 static int add_cmd(UAContext *ua, const char *cmd);
 static int create_cmd(UAContext *ua, const char *cmd);
 static int cancel_cmd(UAContext *ua, const char *cmd);
+static int enable_cmd(UAContext *ua, const char *cmd);
+static int disable_cmd(UAContext *ua, const char *cmd);
 static int setdebug_cmd(UAContext *ua, const char *cmd);
 static int trace_cmd(UAContext *ua, const char *cmd);
 static int var_cmd(UAContext *ua, const char *cmd);
@@ -91,6 +93,8 @@ static struct cmdstruct commands[] = {
  { N_("cancel"),     cancel_cmd,    _("cancel [<jobid=nnn> | <job=name>] -- cancel a job")},
  { N_("create"),     create_cmd,    _("create DB Pool from resource")},
  { N_("delete"),     delete_cmd,    _("delete [pool=<pool-name> | media volume=<volume-name>]")},
+ { N_("disable"),    disable_cmd,   _("disable <job=name> -- disable a job")},
+ { N_("enable"),     enable_cmd,    _("enable <job=name> -- enable a job")},
  { N_("estimate"),   estimate_cmd,  _("performs FileSet estimate, listing gives full listing")},
  { N_("exit"),       quit_cmd,      _("exit = quit")},
  { N_("gui"),        gui_cmd,       _("gui [on|off] -- non-interactive gui mode")},
@@ -218,7 +222,7 @@ static int add_cmd(UAContext *ua, const char *cmd)
       pr.MaxVols, pr.PoolType);
 
    while (pr.MaxVols > 0 && pr.NumVols >= pr.MaxVols) {
-      bsendmsg(ua, _("Pool already has maximum volumes = %d\n"), pr.MaxVols);
+      bsendmsg(ua, _("Pool already has maximum volumes=%d\n"), pr.MaxVols);
       for (;;) {
          if (!get_pint(ua, _("Enter new maximum (zero for unlimited): "))) {
             return 1;
@@ -402,12 +406,11 @@ static int cancel_cmd(UAContext *ua, const char *cmd)
       /* Count Jobs running */
       foreach_jcr(jcr) {
          if (jcr->JobId == 0) {      /* this is us */
-            free_jcr(jcr);
             continue;
          }
-         free_jcr(jcr);
          njobs++;
       }
+      endeach_jcr(jcr);
 
       if (njobs == 0) {
          bsendmsg(ua, _("No Jobs running.\n"));
@@ -417,13 +420,12 @@ static int cancel_cmd(UAContext *ua, const char *cmd)
       foreach_jcr(jcr) {
          char ed1[50];
          if (jcr->JobId == 0) {      /* this is us */
-            free_jcr(jcr);
             continue;
          }
          bsnprintf(buf, sizeof(buf), _("JobId=%s Job=%s"), edit_int64(jcr->JobId, ed1), jcr->Job);
          add_prompt(ua, buf);
-         free_jcr(jcr);
       }
+      endeach_jcr(jcr);
 
       if (do_prompt(ua, _("Job"),  _("Choose Job to cancel"), buf, sizeof(buf)) < 0) {
          return 1;
@@ -612,6 +614,49 @@ get_out:
 }
 
 
+static void do_en_disable_cmd(UAContext *ua, bool setting)
+{
+   JOB *job;
+   int i;
+
+   i = find_arg_with_value(ua, N_("job")); 
+   if (i < 0) { 
+      job = select_job_resource(ua);
+      if (!job) {
+         return;
+      }
+   } else {
+      LockRes();
+      job = (JOB *)GetResWithName(R_JOB, ua->argv[i]);
+      UnlockRes();
+   } 
+   if (!job) {
+      bsendmsg(ua, _("Job \"%s\" not found.\n"), ua->argv[i]);
+      return;
+   }
+
+   if (!acl_access_ok(ua, Job_ACL, job->hdr.name)) {
+      bsendmsg(ua, _("Illegal command from this console.\n"));
+      return;
+   }
+   job->enabled = setting;
+   bsendmsg(ua, _("Job \"%s\" %sabled\n"), job->hdr.name, setting?"en":"dis");
+   return;
+}
+
+static int enable_cmd(UAContext *ua, const char *cmd)
+{
+   do_en_disable_cmd(ua, true);
+   return 1;
+}
+
+static int disable_cmd(UAContext *ua, const char *cmd)
+{
+   do_en_disable_cmd(ua, false);
+   return 1;
+}
+
+
 static void do_storage_setdebug(UAContext *ua, STORE *store, int level, int trace_flag)
 {
    BSOCK *sd;
@@ -1192,9 +1237,11 @@ static void do_job_delete(UAContext *ua, JobId_t JobId)
 
    Mmsg(query, "DELETE FROM Job WHERE JobId=%s", edit_int64(JobId, ed1));
    db_sql_query(ua->db, query, NULL, (void *)NULL);
-   Mmsg(query, "DELETE FROM File WHERE JobId=%s", edit_int64(JobId, ed1));
+   Mmsg(query, "DELETE FROM MAC WHERE JobId=%s", ed1);
    db_sql_query(ua->db, query, NULL, (void *)NULL);
-   Mmsg(query, "DELETE FROM JobMedia WHERE JobId=%s", edit_int64(JobId, ed1));
+   Mmsg(query, "DELETE FROM File WHERE JobId=%s", ed1);
+   db_sql_query(ua->db, query, NULL, (void *)NULL);
+   Mmsg(query, "DELETE FROM JobMedia WHERE JobId=%s", ed1);
    db_sql_query(ua->db, query, NULL, (void *)NULL);
    free_pool_memory(query);
    bsendmsg(ua, _("Job %s and associated records deleted from the catalog.\n"), edit_int64(JobId, ed1));
@@ -1262,12 +1309,12 @@ static void do_mount_cmd(UAContext *ua, const char *command)
    if (!store) {
       return;
    }
+   set_storage(jcr, store);
    drive = get_storage_drive(ua, store);
 
    Dmsg3(120, "Found storage, MediaType=%s DevName=%s drive=%d\n",
       store->media_type, store->dev_name(), drive);
 
-   set_storage(jcr, store);
    if (!connect_to_storage_daemon(jcr, 10, SDConnectTimeout, 1)) {
       bsendmsg(ua, _("Failed to connect to Storage daemon.\n"));
       return;
@@ -1356,11 +1403,11 @@ int wait_cmd(UAContext *ua, const char *cmd)
       foreach_jcr(jcr) {
          if (jcr->JobId != 0) {
             running = true;
-            free_jcr(jcr);
             break;
          }
-         free_jcr(jcr);
       }
+      endeach_jcr(jcr);
+
       if (running) {
          bmicrosleep(1, 0);
       }
@@ -1402,10 +1449,10 @@ static int version_cmd(UAContext *ua, const char *cmd)
  * a "use catalog xxx" command, we simply find the first
  * catalog resource and open it.
  */
-int open_db(UAContext *ua)
+bool open_db(UAContext *ua)
 {
    if (ua->db) {
-      return 1;
+      return true;
    }
    if (!ua->catalog) {
       LockRes();
@@ -1413,7 +1460,11 @@ int open_db(UAContext *ua)
       UnlockRes();
       if (!ua->catalog) {
          bsendmsg(ua, _("Could not find a Catalog resource\n"));
-         return 0;
+         return false;
+      } else if (!acl_access_ok(ua, Catalog_ACL, ua->catalog->hdr.name)) {
+         bsendmsg(ua, _("You must specify a \"use <catalog-name>\" command before continuing.\n"));
+         ua->catalog = NULL;
+         return false;
       } else {
          bsendmsg(ua, _("Using default Catalog name=%s DB=%s\n"),
             ua->catalog->hdr.name, ua->catalog->db_name);
@@ -1434,11 +1485,11 @@ int open_db(UAContext *ua)
          bsendmsg(ua, "%s", db_strerror(ua->db));
       }
       close_db(ua);
-      return 0;
+      return false;
    }
    ua->jcr->db = ua->db;
    Dmsg1(150, "DB %s opened\n", ua->catalog->db_name);
-   return 1;
+   return true;
 }
 
 void close_db(UAContext *ua)