+ ua->error_msg(_("Unknown Job Type=%d\n"), jcr->get_JobType());
+ return false;
+ }
+ return true;
+}
+
+
+static bool scan_command_line_arguments(UAContext *ua, run_ctx &rc)
+{
+ bool kw_ok;
+ int i, j;
+ static const char *kw[] = { /* command line arguments */
+ "job", /* Used in a switch() */
+ "jobid", /* 1 */
+ "client", /* 2 */
+ "fd",
+ "fileset", /* 4 */
+ "level", /* 5 */
+ "storage", /* 6 */
+ "sd", /* 7 */
+ "regexwhere", /* 8 where string as a bregexp */
+ "where", /* 9 */
+ "bootstrap", /* 10 */
+ "replace", /* 11 */
+ "when", /* 12 */
+ "priority", /* 13 */
+ "yes", /* 14 -- if you change this change YES_POS too */
+ "verifyjob", /* 15 */
+ "files", /* 16 number of files to restore */
+ "catalog", /* 17 override catalog */
+ "since", /* 18 since */
+ "cloned", /* 19 cloned */
+ "verifylist", /* 20 verify output list */
+ "migrationjob", /* 21 migration job name */
+ "pool", /* 22 */
+ "backupclient", /* 23 */
+ "restoreclient", /* 24 */
+ "pluginoptions", /* 25 */
+ "spooldata", /* 26 */
+ NULL};
+
+#define YES_POS 14
+
+ rc.catalog_name = NULL;
+ rc.job_name = NULL;
+ rc.pool_name = NULL;
+ rc.store_name = NULL;
+ rc.client_name = NULL;
+ rc.restore_client_name = NULL;
+ rc.fileset_name = NULL;
+ rc.verify_job_name = NULL;
+ rc.previous_job_name = NULL;
+ rc.spool_data_set = 0;
+
+
+ for (i=1; i<ua->argc; i++) {
+ Dmsg2(800, "Doing arg %d = %s\n", i, ua->argk[i]);
+ 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 fail */
+ if (!ua->argv[i] && j != YES_POS /*yes*/) {
+ ua->send_msg(_("Value missing for keyword %s\n"), ua->argk[i]);
+ return false;
+ }
+ Dmsg1(800, "Got keyword=%s\n", NPRT(kw[j]));
+ switch (j) {
+ case 0: /* job */
+ if (rc.job_name) {
+ ua->send_msg(_("Job name specified twice.\n"));
+ return false;
+ }
+ rc.job_name = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 1: /* JobId */
+ if (rc.jid && !rc.mod) {
+ ua->send_msg(_("JobId specified twice.\n"));
+ return false;
+ }
+ rc.jid = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 2: /* client */
+ case 3: /* fd */
+ if (rc.client_name) {
+ ua->send_msg(_("Client specified twice.\n"));
+ return false;
+ }
+ rc.client_name = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 4: /* fileset */
+ if (rc.fileset_name) {
+ ua->send_msg(_("FileSet specified twice.\n"));
+ return false;
+ }
+ rc.fileset_name = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 5: /* level */
+ if (rc.level_name) {
+ ua->send_msg(_("Level specified twice.\n"));
+ return false;
+ }
+ rc.level_name = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 6: /* storage */
+ case 7: /* sd */
+ if (rc.store_name) {
+ ua->send_msg(_("Storage specified twice.\n"));
+ return false;
+ }
+ rc.store_name = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 8: /* regexwhere */
+ if ((rc.regexwhere || rc.where) && !rc.mod) {
+ ua->send_msg(_("RegexWhere or Where specified twice.\n"));
+ return false;
+ }
+ rc.regexwhere = ua->argv[i];
+ if (!acl_access_ok(ua, Where_ACL, rc.regexwhere)) {
+ ua->send_msg(_("No authorization for \"regexwhere\" specification.\n"));
+ return false;
+ }
+ kw_ok = true;
+ break;
+ case 9: /* where */
+ if ((rc.where || rc.regexwhere) && !rc.mod) {
+ ua->send_msg(_("Where or RegexWhere specified twice.\n"));
+ return false;
+ }
+ rc.where = ua->argv[i];
+ if (!acl_access_ok(ua, Where_ACL, rc.where)) {
+ ua->send_msg(_("No authoriztion for \"where\" specification.\n"));
+ return false;
+ }
+ kw_ok = true;
+ break;
+ case 10: /* bootstrap */
+ if (rc.bootstrap && !rc.mod) {
+ ua->send_msg(_("Bootstrap specified twice.\n"));
+ return false;
+ }
+ rc.bootstrap = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 11: /* replace */
+ if (rc.replace && !rc.mod) {
+ ua->send_msg(_("Replace specified twice.\n"));
+ return false;
+ }
+ rc.replace = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 12: /* When */
+ if (rc.when && !rc.mod) {
+ ua->send_msg(_("When specified twice.\n"));
+ return false;
+ }
+ rc.when = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 13: /* Priority */
+ if (rc.Priority && !rc.mod) {
+ ua->send_msg(_("Priority specified twice.\n"));
+ return false;
+ }
+ rc.Priority = atoi(ua->argv[i]);
+ if (rc.Priority <= 0) {
+ ua->send_msg(_("Priority must be positive nonzero setting it to 10.\n"));
+ rc.Priority = 10;
+ }
+ kw_ok = true;
+ break;
+ case 14: /* yes */
+ kw_ok = true;
+ break;
+ case 15: /* Verify Job */
+ if (rc.verify_job_name) {
+ ua->send_msg(_("Verify Job specified twice.\n"));
+ return false;
+ }
+ rc.verify_job_name = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 16: /* files */
+ rc.files = atoi(ua->argv[i]);
+ kw_ok = true;
+ break;
+
+ case 17: /* catalog */
+ rc.catalog_name = ua->argv[i];
+ kw_ok = true;
+ break;
+
+ case 18: /* since */
+ rc.since = ua->argv[i];
+ kw_ok = true;
+ break;
+
+ case 19: /* cloned */
+ rc. cloned = true;
+ kw_ok = true;
+ break;
+
+ case 20: /* write verify list output */
+ rc.verify_list = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 21: /* Migration Job */
+ if (rc.previous_job_name) {
+ ua->send_msg(_("Migration Job specified twice.\n"));
+ return false;
+ }
+ rc.previous_job_name = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 22: /* pool */
+ if (rc.pool_name) {
+ ua->send_msg(_("Pool specified twice.\n"));
+ return false;
+ }
+ rc.pool_name = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 23: /* backupclient */
+ if (rc.client_name) {
+ ua->send_msg(_("Client specified twice.\n"));
+ return 0;
+ }
+ rc.client_name = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 24: /* restoreclient */
+ if (rc.restore_client_name && !rc.mod) {
+ ua->send_msg(_("Restore Client specified twice.\n"));
+ return false;
+ }
+ rc.restore_client_name = ua->argv[i];
+ kw_ok = true;
+ break;
+ case 25: /* pluginoptions */
+ if (rc.plugin_options) {
+ ua->send_msg(_("Plugin Options specified twice.\n"));
+ return false;
+ }
+ rc.plugin_options = ua->argv[i];
+ if (!acl_access_ok(ua, PluginOptions_ACL, rc.plugin_options)) {
+ ua->send_msg(_("No authoriztion for \"PluginOptions\" specification.\n"));
+ return false;
+ }
+ kw_ok = true;
+ break;
+ case 26: /* spooldata */
+ if (rc.spool_data_set) {
+ ua->send_msg(_("Spool flag specified twice.\n"));
+ return false;
+ }
+ if (is_yesno(ua->argv[i], &rc.spool_data)) {
+ rc.spool_data_set = 1;
+ kw_ok = true;
+ } else {
+ ua->send_msg(_("Invalid spooldata flag.\n"));
+ }
+ break;
+ default:
+ break;
+ }
+ } /* end strcase compare */
+ } /* end keyword loop */
+ /*
+ * End of keyword for loop -- if not found, we got a bogus keyword
+ */
+ if (!kw_ok) {
+ Dmsg1(800, "%s not found\n", ua->argk[i]);
+ /*
+ * Special case for Job Name, it can be the first
+ * keyword that has no value.
+ */
+ if (!rc.job_name && !ua->argv[i]) {
+ rc.job_name = ua->argk[i]; /* use keyword as job name */
+ Dmsg1(800, "Set jobname=%s\n", rc.job_name);
+ } else {
+ ua->send_msg(_("Invalid keyword: %s\n"), ua->argk[i]);
+ return false;
+ }
+ }
+ } /* end argc loop */
+
+ Dmsg0(800, "Done scan.\n");
+
+ if (rc.catalog_name) {
+ rc.catalog = GetCatalogResWithName(rc.catalog_name);
+ if (rc.catalog == NULL) {
+ ua->error_msg(_("Catalog \"%s\" not found\n"), rc.catalog_name);
+ return false;
+ }
+ if (!acl_access_ok(ua, Catalog_ACL, rc.catalog->name())) {
+ ua->error_msg(_("No authorization. Catalog \"%s\".\n"), rc.catalog->name());
+ return false;
+ }
+ }
+ Dmsg1(800, "Using catalog=%s\n", NPRT(rc.catalog_name));
+
+ if (rc.job_name) {
+ /* Find Job */
+ rc.job = GetJobResWithName(rc.job_name);
+ if (!rc.job) {
+ if (*rc.job_name != 0) {
+ ua->send_msg(_("Job \"%s\" not found\n"), rc.job_name);
+ }
+ rc.job = select_job_resource(ua);
+ } else {
+ Dmsg1(800, "Found job=%s\n", rc.job_name);
+ }
+ } else if (!rc.job) {
+ ua->send_msg(_("A job name must be specified.\n"));
+ rc.job = select_job_resource(ua);
+ }
+ if (!rc.job) {
+ return false;
+ } else if (!acl_access_ok(ua, Job_ACL, rc.job->name())) {
+ ua->error_msg( _("No authorization. Job \"%s\".\n"), rc.job->name());
+ return false;
+ }
+
+ if (rc.pool_name) {
+ rc.pool = GetPoolResWithName(rc.pool_name);
+ if (!rc.pool) {
+ if (*rc.pool_name != 0) {
+ ua->warning_msg(_("Pool \"%s\" not found.\n"), rc.pool_name);
+ }
+ rc.pool = select_pool_resource(ua);
+ }
+ } else if (!rc.pool) {
+ rc.pool = rc.job->pool; /* use default */
+ }
+ if (!rc.pool) {
+ return false;
+ } else if (!acl_access_ok(ua, Pool_ACL, rc.pool->name())) {
+ ua->error_msg(_("No authorization. Pool \"%s\".\n"), rc.pool->name());