]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_run.c
Start applying new FSFE copyright.
[bacula/bacula] / bacula / src / dird / ua_run.c
index 470cd5bd9630b9871833967a01c00a63e6f4b05a..9cd61ac258d050828e31832b3d65354d1d654ab5 100644 (file)
@@ -7,19 +7,32 @@
  *   Version $Id$
  */
 /*
-   Copyright (C) 2001-2005 Kern Sibbald
+   Bacula® - The Network Backup Solution
 
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License
-   version 2 as amended with additional clauses defined in the
-   file LICENSE in the main source directory.
+   Copyright (C) 2001-2006 Free Software Foundation Europe e.V.
 
-   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 
-   the file LICENSE for additional details.
+   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.
 
- */
+   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
+   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 ofJohn Walker.
+   The licensor of Bacula is the Free Software Foundation Europe
+   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+   Switzerland, email:ftf@fsfeurope.org.
+*/
 
 #include "bacula.h"
 #include "dird.h"
@@ -47,7 +60,7 @@ int run_cmd(UAContext *ua, const char *cmd)
    char *where, *fileset_name, *client_name, *bootstrap;
    const char *replace;
    char *when, *verify_job_name, *catalog_name;
-   char *migration_job_name;
+   char *previous_job_name;
    char *since = NULL;
    char *verify_list;
    bool cloned = false;
@@ -56,7 +69,7 @@ int run_cmd(UAContext *ua, const char *cmd)
    bool kw_ok;
    JOB *job = NULL;
    JOB *verify_job = NULL;
-   JOB *migration_job = NULL;
+   JOB *previous_job = NULL;
    STORE *store = NULL;
    CLIENT *client = NULL;
    FILESET *fileset = NULL;
@@ -104,7 +117,7 @@ int run_cmd(UAContext *ua, const char *cmd)
    bootstrap = NULL;
    replace = NULL;
    verify_job_name = NULL;
-   migration_job_name = NULL;
+   previous_job_name = NULL;
    catalog_name = NULL;
    verify_list = NULL;
 
@@ -113,8 +126,8 @@ int run_cmd(UAContext *ua, const char *cmd)
       kw_ok = false;
       /* Keep looking until we find a good keyword */
       for (j=0; !kw_ok && kw[j]; j++) {
-         if (strcasecmp(ua->argk[i], _(kw[j])) == 0) {
-            /* Note, yes and run have no value, so do not err */
+         if (strcasecmp(ua->argk[i], kw[j]) == 0) {
+            /* Note, yes and run have no value, so do not fail */
             if (!ua->argv[i] && j != YES_POS /*yes*/) {
                bsendmsg(ua, _("Value missing for keyword %s\n"), ua->argk[i]);
                return 1;
@@ -185,6 +198,10 @@ int run_cmd(UAContext *ua, const char *cmd)
                   return 0;
                }
                where = ua->argv[i];
+               if (!acl_access_ok(ua, Where_ACL, where)) {
+                  bsendmsg(ua, _("Forbidden \"where\" specified.\n"));
+                  return 0;
+               }
                kw_ok = true;
                break;
             case 10: /* bootstrap */
@@ -259,11 +276,11 @@ int run_cmd(UAContext *ua, const char *cmd)
                kw_ok = true;
                break;
             case 21: /* Migration Job */
-               if (migration_job_name) {
+               if (previous_job_name) {
                   bsendmsg(ua, _("Migration Job specified twice.\n"));
                   return 0;
                }
-               migration_job_name = ua->argv[i];
+               previous_job_name = ua->argv[i];
                kw_ok = true;
                break;
 
@@ -321,9 +338,9 @@ int run_cmd(UAContext *ua, const char *cmd)
    }
    if (!job) {
       return 0;
-   } else if (!acl_access_ok(ua, Job_ACL, job->hdr.name)) {
+   } else if (!acl_access_ok(ua, Job_ACL, job->name())) {
       bsendmsg(ua, _("No authorization. Job \"%s\".\n"),
-         job->hdr.name);
+         job->name());
       return 0;
    }
 
@@ -335,17 +352,17 @@ int run_cmd(UAContext *ua, const char *cmd)
          }
          store = select_storage_resource(ua);
       }
-   } else {
+   } else if (job->storage) {
       store = (STORE *)job->storage->first();           /* use default */
    }
    if (!store) {
       return 1;
-   } else if (!acl_access_ok(ua, Storage_ACL, store->hdr.name)) {
+   } else if (!acl_access_ok(ua, Storage_ACL, store->name())) {
       bsendmsg(ua, _("No authorization. Storage \"%s\".\n"),
-               store->hdr.name);
+               store->name());
       return 0;
    }
-   Dmsg1(800, "Using storage=%s\n", store->hdr.name);
+   Dmsg1(800, "Using storage=%s\n", store->name());
 
    if (pool_name) {
       pool = (POOL *)GetResWithName(R_POOL, pool_name);
@@ -360,12 +377,12 @@ int run_cmd(UAContext *ua, const char *cmd)
    }
    if (!pool) {
       return 0;
-   } else if (!acl_access_ok(ua, Pool_ACL, pool->hdr.name)) {
+   } else if (!acl_access_ok(ua, Pool_ACL, pool->name())) {
       bsendmsg(ua, _("No authorization. Pool \"%s\".\n"),
-               pool->hdr.name);
+               pool->name());
       return 0;
    }
-   Dmsg1(800, "Using pool\n", pool->hdr.name);
+   Dmsg1(800, "Using pool\n", pool->name());
 
    if (client_name) {
       client = (CLIENT *)GetResWithName(R_CLIENT, client_name);
@@ -380,12 +397,12 @@ int run_cmd(UAContext *ua, const char *cmd)
    }
    if (!client) {
       return 0;
-   } else if (!acl_access_ok(ua, Client_ACL, client->hdr.name)) {
+   } else if (!acl_access_ok(ua, Client_ACL, client->name())) {
       bsendmsg(ua, _("No authorization. Client \"%s\".\n"),
-               client->hdr.name);
+               client->name());
       return 0;
    }
-   Dmsg1(800, "Using client=%s\n", client->hdr.name);
+   Dmsg1(800, "Using client=%s\n", client->name());
 
    if (fileset_name) {
       fileset = (FILESET *)GetResWithName(R_FILESET, fileset_name);
@@ -398,9 +415,9 @@ int run_cmd(UAContext *ua, const char *cmd)
    }
    if (!fileset) {
       return 0;
-   } else if (!acl_access_ok(ua, FileSet_ACL, fileset->hdr.name)) {
+   } else if (!acl_access_ok(ua, FileSet_ACL, fileset->name())) {
       bsendmsg(ua, _("No authorization. FileSet \"%s\".\n"),
-               fileset->hdr.name);
+               fileset->name());
       return 0;
    }
 
@@ -414,14 +431,14 @@ int run_cmd(UAContext *ua, const char *cmd)
       verify_job = job->verify_job;
    }
 
-   if (migration_job_name) {
-      migration_job = (JOB *)GetResWithName(R_JOB, migration_job_name);
-      if (!migration_job) {
-         bsendmsg(ua, _("Migration Job \"%s\" not found.\n"), migration_job_name);
-         migration_job = select_job_resource(ua);
+   if (previous_job_name) {
+      previous_job = (JOB *)GetResWithName(R_JOB, previous_job_name);
+      if (!previous_job) {
+         bsendmsg(ua, _("Migration Job \"%s\" not found.\n"), previous_job_name);
+         previous_job = select_job_resource(ua);
       }
    } else {
-      migration_job = job->verify_job;
+      previous_job = job->verify_job;
    }
 
 
@@ -433,8 +450,8 @@ int run_cmd(UAContext *ua, const char *cmd)
    set_jcr_defaults(jcr, job);
 
    jcr->verify_job = verify_job;
-   jcr->migration_job = migration_job;
-   set_storage(jcr, store);
+   jcr->previous_job = previous_job;
+   set_rwstorage(jcr, store);
    jcr->client = client;
    jcr->fileset = fileset;
    jcr->pool = pool;
@@ -494,7 +511,7 @@ int run_cmd(UAContext *ua, const char *cmd)
 
    jcr->cloned = cloned;
 
-   if (find_arg(ua, N_("fdcalled")) > 0) {
+   if (find_arg(ua, NT_("fdcalled")) > 0) {
       jcr->file_bsock = dup_bsock(ua->UA_sock);
       ua->quit = true;
    }
@@ -513,11 +530,12 @@ try_again:
       }
    }
    if (jid) {
+      /* Note, this is also MigrateJobId */
       jcr->RestoreJobId = str_to_int64(jid);
    }
 
    /* Run without prompting? */
-   if (ua->batch || find_arg(ua, N_("yes")) > 0) {
+   if (ua->batch || find_arg(ua, NT_("yes")) > 0) {
       goto start_job;
    }
 
@@ -538,10 +556,10 @@ try_again:
 "When:     %s\n"
 "Priority: %d\n"),
                  _("Admin"),
-                 job->hdr.name,
-                 jcr->fileset->hdr.name,
-                 NPRT(jcr->client->hdr.name),
-                 NPRT(jcr->store->hdr.name),
+                 job->name(),
+                 jcr->fileset->name(),
+                 NPRT(jcr->client->name()),
+                 NPRT(jcr->wstore->name()),
                  bstrutime(dt, sizeof(dt), jcr->sched_time),
                  jcr->JobPriority);
       jcr->JobLevel = L_FULL;
@@ -559,18 +577,18 @@ try_again:
 "When:     %s\n"
 "Priority: %d\n"),
                  _("Backup"),
-                 job->hdr.name,
-                 jcr->fileset->hdr.name,
+                 job->name(),
+                 jcr->fileset->name(),
                  level_to_str(jcr->JobLevel),
-                 jcr->client->hdr.name,
-                 jcr->store->hdr.name,
-                 NPRT(jcr->pool->hdr.name),
+                 jcr->client->name(),
+                 jcr->wstore->name(),
+                 NPRT(jcr->pool->name()),
                  bstrutime(dt, sizeof(dt), jcr->sched_time),
                  jcr->JobPriority);
       } else {  /* JT_VERIFY */
          const char *Name;
          if (jcr->verify_job) {
-            Name = jcr->verify_job->hdr.name;
+            Name = jcr->verify_job->name();
          } else {
             Name = "";
          }
@@ -592,12 +610,12 @@ try_again:
 "When:        %s\n"
 "Priority:    %d\n"),
               _("Verify"),
-              job->hdr.name,
-              jcr->fileset->hdr.name,
+              job->name(),
+              jcr->fileset->name(),
               level_to_str(jcr->JobLevel),
-              jcr->client->hdr.name,
-              jcr->store->hdr.name,
-              NPRT(jcr->pool->hdr.name),
+              jcr->client->name(),
+              jcr->rstore->name(),
+              NPRT(jcr->pool->name()),
               Name,
               verify_list,
               bstrutime(dt, sizeof(dt), jcr->sched_time),
@@ -629,15 +647,15 @@ try_again:
                         "When:       %s\n"
                         "Catalog:    %s\n"
                         "Priority:   %d\n"),
-              job->hdr.name,
+              job->name(),
               NPRT(jcr->RestoreBootstrap),
               jcr->where?jcr->where:NPRT(job->RestoreWhere),
               replace,
-              jcr->fileset->hdr.name,
-              jcr->client->hdr.name,
-              jcr->store->hdr.name,
+              jcr->fileset->name(),
+              jcr->client->name(),
+              jcr->rstore->name(),
               bstrutime(dt, sizeof(dt), jcr->sched_time),
-              jcr->catalog->hdr.name,
+              jcr->catalog->name(),
               jcr->JobPriority);
       } else {
          bsendmsg(ua, _("Run Restore job\n"
@@ -651,42 +669,38 @@ try_again:
                        "When:       %s\n"
                        "Catalog:    %s\n"
                        "Priority:   %d\n"),
-              job->hdr.name,
+              job->name(),
               NPRT(jcr->RestoreBootstrap),
               jcr->where?jcr->where:NPRT(job->RestoreWhere),
               replace,
-              jcr->client->hdr.name,
-              jcr->store->hdr.name,
+              jcr->client->name(),
+              jcr->rstore->name(),
               jcr->RestoreJobId==0?"*None*":edit_uint64(jcr->RestoreJobId, ec1),
               bstrutime(dt, sizeof(dt), jcr->sched_time),
-              jcr->catalog->hdr.name,
+              jcr->catalog->name(),
               jcr->JobPriority);
       }
       break;
    case JT_MIGRATE:
       jcr->JobLevel = L_FULL;      /* default level */
-      bsendmsg(ua, _("Run Restore job\n"
+      bsendmsg(ua, _("Run Migration job\n"
                      "JobName:       %s\n"
                      "Bootstrap:     %s\n"
-                     "Where:         %s\n"
-                     "Replace:       %s\n"
                      "FileSet:       %s\n"
                      "Client:        %s\n"
                      "Storage:       %s\n"
-                     "Migration Job: %s\n"
+                     "JobId:         %s\n"
                      "When:          %s\n"
                      "Catalog:       %s\n"
                      "Priority:      %d\n"),
-           job->hdr.name,
+           job->name(),
            NPRT(jcr->RestoreBootstrap),
-           jcr->where?jcr->where:NPRT(job->RestoreWhere),
-           replace,
-           jcr->fileset->hdr.name,
-           jcr->client->hdr.name,
-           jcr->store->hdr.name,
-           jcr->migration_job->hdr.name,
+           jcr->fileset->name(),
+           jcr->client->name(),
+           jcr->wstore->name(),
+           jcr->MigrateJobId==0?"*None*":edit_uint64(jcr->MigrateJobId, ec1),
            bstrutime(dt, sizeof(dt), jcr->sched_time),
-           jcr->catalog->hdr.name,
+           jcr->catalog->name(),
            jcr->JobPriority);
       break;
    default:
@@ -788,7 +802,7 @@ try_again:
          /* Storage */
          store = select_storage_resource(ua);
          if (store) {
-            set_storage(jcr, store);
+            set_rwstorage(jcr, store);
             goto try_again;
          }
          break;
@@ -865,7 +879,7 @@ try_again:
          }
          if (ua->cmd[0] != 0) {
             jcr->RestoreBootstrap = bstrdup(ua->cmd);
-            fd = fopen(jcr->RestoreBootstrap, "r");
+            fd = fopen(jcr->RestoreBootstrap, "rb");
             if (!fd) {
                bsendmsg(ua, _("Warning cannot open %s: ERR=%s\n"),
                   jcr->RestoreBootstrap, strerror(errno));
@@ -930,6 +944,12 @@ try_again:
       Dmsg1(800, "Calling run_job job=%x\n", jcr->job);
 start_job:
       JobId = run_job(jcr);
+#if 0  
+      bsendmsg(ua, "<job director=\"console\" time=\"%u\" status=\"%c\" type=\"%c\" "
+              "jobid=\"%u\" job=\"%s\" level=\"%c\" finished=\"false\" priority=\"%u\"/>\n",
+               time(NULL), jcr->JobStatus, jcr->JobType, jcr->JobId,
+              jcr->Job, jcr->JobLevel, jcr->JobPriority);
+#endif
       free_jcr(jcr);                  /* release jcr */
       if (JobId == 0) {
          bsendmsg(ua, _("Job failed.\n"));