]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Adapt delete command to work with restricted consoles
authorEric Bollengier <eric@baculasystems.com>
Fri, 17 Mar 2023 15:00:21 +0000 (16:00 +0100)
committerEric Bollengier <eric@baculasystems.com>
Tue, 2 May 2023 07:07:18 +0000 (09:07 +0200)
bacula/src/dird/ua_cmds.c

index 7c105ed7f2447baf2e637e4b10d7800c8321c91f..6feffd20ee345093da5a08717208ce84c36b842a 100644 (file)
@@ -2146,6 +2146,7 @@ static void delete_job(UAContext *ua)
    int JobId;               /* not JobId_t because it's unsigned and not compatible with sellist */
    char buf[256];
    sellist sl;
+   POOL_MEM lst;
 
    int i = find_arg_with_value(ua, NT_("jobid"));
    if (i >= 0) {
@@ -2162,6 +2163,9 @@ static void delete_job(UAContext *ua)
          }
       }
 
+      db_get_jobids(ua->jcr, ua->db, sl.get_expanded_list(), lst.handle(), false);
+      sl.set_string(lst.c_str(), true);
+
       foreach_sellist(JobId, &sl) {
          do_job_delete(ua, JobId);
       }
@@ -2170,8 +2174,9 @@ static void delete_job(UAContext *ua)
       return;
 
    } else {
-      JobId = ua->int64_val;
-      do_job_delete(ua, JobId);
+      db_get_jobids(ua->jcr, ua->db, edit_uint64(ua->int64_val, buf), lst.handle(), false);
+      JobId = str_to_uint64(lst.c_str());
+      do_job_delete(ua, JobId); /* JobId is safe */
    }
 }
 
@@ -2184,6 +2189,11 @@ static void do_job_delete(UAContext *ua, JobId_t JobId)
    edit_int64(JobId, ed1);
    bool skip_job = false;
 
+   if (!JobId) {
+      ua->send_msg(_("Invalid JobId, Job may not exist or be accessible\n"));
+      return;
+   }
+
    JCR *jcr;
    foreach_jcr(jcr) {
       if (jcr->JobId == JobId) {
@@ -2196,7 +2206,7 @@ static void do_job_delete(UAContext *ua, JobId_t JobId)
    if (skip_job) {
       ua->send_msg(_("Skipping JobId=%s, job is still running!\n"), ed1);
    } else {
-      purge_jobs_from_catalog(ua, ed1);
+      purge_jobs_from_catalog(ua, ed1); /* JobId is safe */
       ua->send_msg(_("JobId=%s and associated records deleted from the catalog.\n"), ed1);
    }
 }