]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_select.c
update configure
[bacula/bacula] / bacula / src / dird / ua_select.c
index 060bdd66ea91976b970b7322d1968b4f09307b5f..5db0551d194fd43e2df86b4520d9cb5b8627cbbc 100644 (file)
@@ -1,26 +1,26 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2001-2007 Free Software Foundation Europe e.V.
+   Copyright (C) 2001-2009 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.
    This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
-   License as published by the Free Software Foundation plus additions
-   that are listed in the file LICENSE.
+   modify it under the terms of version three of the GNU Affero General Public
+   License as published by the Free Software Foundation and included
+   in the file LICENSE.
 
    This program is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
+   You should have received a copy of the GNU Affero General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Bacula® is a registered trademark of John Walker.
+   Bacula® is a registered trademark of Kern Sibbald.
    The licensor of Bacula is the Free Software Foundation Europe
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
@@ -31,7 +31,6 @@
  *
  *     Kern Sibbald, October MMI
  *
- *   Version  $Id$
  */
 
 #include "bacula.h"
@@ -244,6 +243,33 @@ CAT *get_catalog_resource(UAContext *ua)
 }
 
 
+/*
+ * Select a job to enable or disable   
+ */
+JOB *select_enable_disable_job_resource(UAContext *ua, bool enable)
+{
+   char name[MAX_NAME_LENGTH];
+   JOB *job;
+
+   LockRes();
+   start_prompt(ua, _("The defined Job resources are:\n"));
+   foreach_res(job, R_JOB) {
+      if (!acl_access_ok(ua, Job_ACL, job->name())) {
+         continue;
+      }
+      if (job->enabled == enable) {   /* Already enabled/disabled? */
+         continue;                    /* yes, skip */
+      }
+      add_prompt(ua, job->name());
+   }
+   UnlockRes();
+   if (do_prompt(ua, _("Job"), _("Select Job resource"), name, sizeof(name)) < 0) {
+      return NULL;
+   }
+   job = (JOB *)GetResWithName(R_JOB, name);
+   return job;
+}
+
 /*
  * Select a Job resource from prompt list
  */
@@ -267,6 +293,24 @@ JOB *select_job_resource(UAContext *ua)
    return job;
 }
 
+/* 
+ * Select a Restore Job resource from argument or prompt
+ */
+JOB *get_restore_job(UAContext *ua)
+{
+   JOB *job;
+   int i = find_arg_with_value(ua, "restore_job");
+   if (i >= 0 && acl_access_ok(ua, Job_ACL, ua->argv[i])) {
+      job = (JOB *)GetResWithName(R_JOB, ua->argv[i]);
+      if (job && job->JobType == JT_RESTORE) {
+         return job;
+      }
+      ua->error_msg(_("Error: Restore Job resource \"%s\" does not exist.\n"),
+                    ua->argv[i]);
+   }
+   return select_restore_job_resource(ua);
+}
+
 /*
  * Select a Restore Job resource from prompt list
  */
@@ -443,7 +487,7 @@ bool select_client_dbr(UAContext *ua, CLIENT_DBR *cr)
  *   returns: false on error
  *            true  on success and fills in POOL_DBR
  */
-bool get_pool_dbr(UAContext *ua, POOL_DBR *pr, char *argk)
+bool get_pool_dbr(UAContext *ua, POOL_DBR *pr, const char *argk)
 {
    if (pr->Name[0]) {                 /* If name already supplied */
       if (db_get_pool_record(ua->jcr, ua->db, pr) &&
@@ -462,7 +506,7 @@ bool get_pool_dbr(UAContext *ua, POOL_DBR *pr, char *argk)
  * Select a Pool record from catalog
  * argk can be pool, recyclepool, scratchpool etc..
  */
-bool select_pool_dbr(UAContext *ua, POOL_DBR *pr, char *argk)
+bool select_pool_dbr(UAContext *ua, POOL_DBR *pr, const char *argk)
 {
    POOL_DBR opr;
    char name[MAX_NAME_LENGTH];
@@ -494,6 +538,9 @@ bool select_pool_dbr(UAContext *ua, POOL_DBR *pr, char *argk)
    }
 
    start_prompt(ua, _("Defined Pools:\n"));
+   if (bstrcmp(argk, NT_("recyclepool"))) {
+      add_prompt(ua, _("*None*"));
+   }
    for (i=0; i < num_pools; i++) {
       opr.PoolId = ids[i];
       if (!db_get_pool_record(ua->jcr, ua->db, &opr) ||
@@ -506,13 +553,21 @@ bool select_pool_dbr(UAContext *ua, POOL_DBR *pr, char *argk)
    if (do_prompt(ua, _("Pool"),  _("Select the Pool"), name, sizeof(name)) < 0) {
       return false;
    }
-   memset(&opr, 0, sizeof(opr));
-   bstrncpy(opr.Name, name, sizeof(opr.Name));
 
-   if (!db_get_pool_record(ua->jcr, ua->db, &opr)) {
-      ua->error_msg(_("Could not find Pool \"%s\": ERR=%s"), name, db_strerror(ua->db));
-      return false;
+   memset(&opr, 0, sizeof(opr));
+   /* *None* is only returned when selecting a recyclepool, and in that case
+    * the calling code is only interested in opr.Name, so then we can leave
+    * pr as all zero.
+    */
+   if (!bstrcmp(name, _("*None*"))) {
+     bstrncpy(opr.Name, name, sizeof(opr.Name));
+
+     if (!db_get_pool_record(ua->jcr, ua->db, &opr)) {
+        ua->error_msg(_("Could not find Pool \"%s\": ERR=%s"), name, db_strerror(ua->db));
+        return false;
+     }
    }
+
    memcpy(pr, &opr, sizeof(opr));
    return true;
 }
@@ -543,37 +598,53 @@ int select_pool_and_media_dbr(UAContext *ua, POOL_DBR *pr, MEDIA_DBR *mr)
 int select_media_dbr(UAContext *ua, MEDIA_DBR *mr)
 {
    int i;
+   int ret = 0;
+   POOLMEM *err = get_pool_memory(PM_FNAME);
+   *err=0;
 
    memset(mr, 0, sizeof(MEDIA_DBR));
 
    i = find_arg_with_value(ua, "volume");
    if (i >= 0) {
-      bstrncpy(mr->VolumeName, ua->argv[i], sizeof(mr->VolumeName));
+      if (is_name_valid(ua->argv[i], &err)) {
+         bstrncpy(mr->VolumeName, ua->argv[i], sizeof(mr->VolumeName));
+      } else {
+         goto bail_out;
+      }
    }
    if (mr->VolumeName[0] == 0) {
       POOL_DBR pr;
       memset(&pr, 0, sizeof(pr));
       /* Get the pool from pool=<pool-name> */
       if (!get_pool_dbr(ua, &pr)) {
-         return 0;
+         goto bail_out;
       }
       mr->PoolId = pr.PoolId;
       db_list_media_records(ua->jcr, ua->db, mr, prtit, ua, HORZ_LIST);
-      if (!get_cmd(ua, _("Enter MediaId or Volume name: "))) {
-         return 0;
+      if (!get_cmd(ua, _("Enter *MediaId or Volume name: "))) {
+         goto bail_out;
       }
-      if (is_a_number(ua->cmd)) {
-         mr->MediaId = str_to_int64(ua->cmd);
-      } else {
+      if (ua->cmd[0] == '*' && is_a_number(ua->cmd+1)) {
+         mr->MediaId = str_to_int64(ua->cmd+1);
+      } else if (is_name_valid(ua->cmd, &err)) {
          bstrncpy(mr->VolumeName, ua->cmd, sizeof(mr->VolumeName));
+      } else {
+         goto bail_out;
       }
    }
 
    if (!db_get_media_record(ua->jcr, ua->db, mr)) {
-      ua->error_msg("%s", db_strerror(ua->db));
-      return 0;
+      pm_strcpy(err, db_strerror(ua->db));
+      goto bail_out;
    }
-   return 1;
+   ret = 1;
+
+bail_out:
+   if (!ret && *err) {
+      ua->error_msg("%s", err);
+   }
+   free_pool_memory(err);
+   return ret;
 }
 
 
@@ -751,7 +822,13 @@ int do_prompt(UAContext *ua, const char *automsg, const char *msg,
    }
    /* If running non-interactive, bail out */
    if (ua->batch) {
-      ua->send_msg(_("Cannot select %s in batch mode.\n"), automsg);
+      /* First print the choices he wanted to make */
+      ua->send_msg(ua->prompt[0]);
+      for (i=1; i < ua->num_prompts; i++) {
+         ua->send_msg("%6d: %s\n", i, ua->prompt[i]);
+      }
+      /* Now print error message */
+      ua->send_msg(_("Your request has multiple choices for \"%s\". Selection is not possible in batch mode.\n"), automsg);
       item = -1;
       goto done;
    }
@@ -1002,7 +1079,7 @@ bool get_level_from_name(JCR *jcr, const char *level_name)
    bool found = false;
    for (int i=0; joblevels[i].level_name; i++) {
       if (strcasecmp(level_name, joblevels[i].level_name) == 0) {
-         jcr->JobLevel = joblevels[i].level;
+         jcr->setJobLevel(joblevels[i].level);
          found = true;
          break;
       }