X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fdird%2Fua_cmds.c;h=6952b3b9bdf41f5a5555ee93d58906a20014a68c;hb=6e637fce30a1fdbc2da43552f513f529db4d4e87;hp=917910f4b8700b06dd639304182996190e3ea04a;hpb=ab54e24ec150b9593621e898207605a94f135b29;p=bacula%2Fbacula diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c index 917910f4b8..6952b3b9bd 100644 --- a/bacula/src/dird/ua_cmds.c +++ b/bacula/src/dird/ua_cmds.c @@ -7,8 +7,8 @@ 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. + 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 @@ -40,9 +40,6 @@ /* Imported subroutines */ /* Imported variables */ -extern int r_first; -extern int r_last; -extern struct s_res resources[]; extern jobq_t job_queue; /* job queue */ @@ -116,8 +113,8 @@ static struct cmdstruct commands[] = { { NT_("list"), list_cmd, _("list [pools | jobs | jobtotals | media | files ]; from catalog")}, { NT_("label"), label_cmd, _("label a tape")}, { NT_("llist"), llist_cmd, _("full or long list like list command")}, - { NT_("memory"), memory_cmd, _("print current memory usage")}, { NT_("messages"), messagescmd, _("messages")}, + { NT_("memory"), memory_cmd, _("print current memory usage")}, { NT_("mount"), mount_cmd, _("mount ")}, { NT_("prune"), prunecmd, _("prune expired records from catalog")}, { NT_("purge"), purgecmd, _("purge records from catalog")}, @@ -149,19 +146,18 @@ static struct cmdstruct commands[] = { /* * Execute a command from the UA */ -int do_a_command(UAContext *ua, const char *cmd) +bool do_a_command(UAContext *ua) { unsigned int i; - int len, stat; + int len; bool ok = false; bool found = false; BSOCK *user = ua->UA_sock; - stat = 1; Dmsg1(900, "Command: %s\n", ua->UA_sock->msg); if (ua->argc == 0) { - return 1; + return false; } while (ua->jcr->wstorage->size()) { @@ -177,13 +173,14 @@ int do_a_command(UAContext *ua, const char *cmd) break; } if (ua->api) user->signal(BNET_CMD_BEGIN); - ok = (*commands[i].func)(ua, cmd); /* go execute command */ + ok = (*commands[i].func)(ua, ua->cmd); /* go execute command */ found = true; break; } } if (!found) { - user->fsend(_("%s: is an invalid command.\n"), ua->argk[0]); + ua->error_msg(_("%s: is an invalid command.\n"), ua->argk[0]); + ok = false; } if (ua->api) user->signal(ok?BNET_CMD_OK:BNET_CMD_FAILED); return ok; @@ -244,12 +241,10 @@ static int add_cmd(UAContext *ua, const char *cmd) while (pr.MaxVols > 0 && pr.NumVols >= pr.MaxVols) { ua->warning_msg(_("Pool already has maximum volumes=%d\n"), pr.MaxVols); - for (;;) { - if (!get_pint(ua, _("Enter new maximum (zero for unlimited): "))) { - return 1; - } - pr.MaxVols = ua->pint32_val; + if (!get_pint(ua, _("Enter new maximum (zero for unlimited): "))) { + return 1; } + pr.MaxVols = ua->pint32_val; } /* Get media type */ @@ -277,27 +272,30 @@ static int add_cmd(UAContext *ua, const char *cmd) } break; } -getVolName: - if (num == 0) { - if (!get_cmd(ua, _("Enter Volume name: "))) { - return 1; + + for (;;) { + if (num == 0) { + if (!get_cmd(ua, _("Enter Volume name: "))) { + return 1; + } + } else { + if (!get_cmd(ua, _("Enter base volume name: "))) { + return 1; + } } - } else { - if (!get_cmd(ua, _("Enter base volume name: "))) { - return 1; + /* Don't allow | in Volume name because it is the volume separator character */ + if (!is_volume_name_legal(ua, ua->cmd)) { + continue; } - } - /* Don't allow | in Volume name because it is the volume separator character */ - if (!is_volume_name_legal(ua, ua->cmd)) { - goto getVolName; - } - if (strlen(ua->cmd) >= MAX_NAME_LENGTH-10) { - ua->warning_msg(_("Volume name too long.\n")); - goto getVolName; - } - if (strlen(ua->cmd) == 0) { - ua->warning_msg(_("Volume name must be at least one character long.\n")); - goto getVolName; + if (strlen(ua->cmd) >= MAX_NAME_LENGTH-10) { + ua->warning_msg(_("Volume name too long.\n")); + continue; + } + if (strlen(ua->cmd) == 0) { + ua->warning_msg(_("Volume name must be at least one character long.\n")); + continue; + } + break; } bstrncpy(name, ua->cmd, sizeof(name)); @@ -478,10 +476,19 @@ static int cancel_cmd(UAContext *ua, const char *cmd) if (do_prompt(ua, _("Job"), _("Choose Job to cancel"), buf, sizeof(buf)) < 0) { return 1; } - if (njobs == 1) { - if (!get_yesno(ua, _("Confirm cancel (yes/no): ")) || ua->pint32_val == 0) { + if (ua->api && njobs == 1) { + char nbuf[1000]; + bsnprintf(nbuf, sizeof(nbuf), _("Cancel: %s\n\n%s"), buf, + _("Confirm cancel?")); + if (!get_yesno(ua, nbuf) || ua->pint32_val == 0) { return 1; } + } else { + if (njobs == 1) { + if (!get_yesno(ua, _("Confirm cancel (yes/no): ")) || ua->pint32_val == 0) { + return 1; + } + } } sscanf(buf, "JobId=%d Job=%127s", &njobs, JobName); jcr = get_jcr_by_full_name(JobName); @@ -700,7 +707,7 @@ static int setip_cmd(UAContext *ua, const char *cmd) return 1; } LockRes(); - client = (CLIENT *)GetResWithName(R_CLIENT, ua->cons->name()); + client = GetClientResWithName(ua->cons->name()); if (!client) { ua->error_msg(_("Client \"%s\" not found.\n"), ua->cons->name()); @@ -733,7 +740,7 @@ static void do_en_disable_cmd(UAContext *ua, bool setting) } } else { LockRes(); - job = (JOB *)GetResWithName(R_JOB, ua->argv[i]); + job = GetJobResWithName(ua->argv[i]); UnlockRes(); } if (!job) { @@ -949,7 +956,7 @@ static int setdebug_cmd(UAContext *ua, const char *cmd) strcasecmp(ua->argk[i], "fd") == 0) { client = NULL; if (ua->argv[i]) { - client = (CLIENT *)GetResWithName(R_CLIENT, ua->argv[i]); + client = GetClientResWithName(ua->argv[i]); if (client) { do_client_setdebug(ua, client, level, trace_flag); return 1; @@ -967,7 +974,7 @@ static int setdebug_cmd(UAContext *ua, const char *cmd) strcasecmp(ua->argk[i], NT_("sd")) == 0) { store = NULL; if (ua->argv[i]) { - store = (STORE *)GetResWithName(R_STORAGE, ua->argv[i]); + store = GetStoreResWithName(ua->argv[i]); if (store) { do_storage_setdebug(ua, store, level, trace_flag); return 1; @@ -1071,14 +1078,22 @@ static int estimate_cmd(UAContext *ua, const char *cmd) if (strcasecmp(ua->argk[i], NT_("client")) == 0 || strcasecmp(ua->argk[i], NT_("fd")) == 0) { if (ua->argv[i]) { - client = (CLIENT *)GetResWithName(R_CLIENT, ua->argv[i]); + client = GetClientResWithName(ua->argv[i]); + if (!client) { + ua->error_msg(_("Client \"%s\" not found.\n"), ua->argv[i]); + return 1; + } continue; } } if (strcasecmp(ua->argk[i], NT_("job")) == 0) { if (ua->argv[i]) { - job = (JOB *)GetResWithName(R_JOB, ua->argv[i]); - if (job && !acl_access_ok(ua, Job_ACL, job->name())) { + job = GetJobResWithName(ua->argv[i]); + if (!job) { + ua->error_msg(_("Job \"%s\" not found.\n"), ua->argv[i]); + return 1; + } + if (!acl_access_ok(ua, Job_ACL, job->name())) { ua->error_msg(_("No authorization for Job \"%s\"\n"), job->name()); return 1; } @@ -1087,8 +1102,12 @@ static int estimate_cmd(UAContext *ua, const char *cmd) } if (strcasecmp(ua->argk[i], NT_("fileset")) == 0) { if (ua->argv[i]) { - fileset = (FILESET *)GetResWithName(R_FILESET, ua->argv[i]); - if (fileset && !acl_access_ok(ua, FileSet_ACL, fileset->name())) { + fileset = GetFileSetResWithName(ua->argv[i]); + if (!fileset) { + ua->error_msg(_("Fileset \"%s\" not found.\n"), ua->argv[i]); + return 1; + } + if (!acl_access_ok(ua, FileSet_ACL, fileset->name())) { ua->error_msg(_("No authorization for FileSet \"%s\"\n"), fileset->name()); return 1; } @@ -1112,7 +1131,7 @@ static int estimate_cmd(UAContext *ua, const char *cmd) } } if (!job) { - job = (JOB *)GetResWithName(R_JOB, ua->argk[1]); + job = GetJobResWithName(ua->argk[1]); if (!job) { ua->error_msg(_("No job specified.\n")); return 1; @@ -1131,7 +1150,11 @@ static int estimate_cmd(UAContext *ua, const char *cmd) jcr->client = client; jcr->fileset = fileset; close_db(ua); - ua->catalog = client->catalog; + if (job->pool->catalog) { + ua->catalog = job->pool->catalog; + } else { + ua->catalog = client->catalog; + } if (!open_db(ua)) { return 1; @@ -1151,7 +1174,7 @@ static int estimate_cmd(UAContext *ua, const char *cmd) get_level_since_time(ua->jcr, since, sizeof(since)); ua->send_msg(_("Connecting to Client %s at %s:%d\n"), - job->client->name(), job->client->address, job->client->FDport); + jcr->client->name(), jcr->client->address, jcr->client->FDport); if (!connect_to_file_daemon(jcr, 1, 15, 0)) { ua->error_msg(_("Failed to connect to Client.\n")); return 1; @@ -1364,6 +1387,7 @@ static void do_job_delete(UAContext *ua, JobId_t JobId) static int delete_volume(UAContext *ua) { MEDIA_DBR mr; + char buf[1000]; if (!select_media_dbr(ua, &mr)) { return 1; @@ -1372,7 +1396,9 @@ static int delete_volume(UAContext *ua) "and all Jobs saved on that volume from the Catalog\n"), mr.VolumeName); - if (!get_yesno(ua, _("Are you sure you want to delete this Volume? (yes/no): "))) { + bsnprintf(buf, sizeof(buf), _("Are you sure you want to delete Volume \"%s\"? (yes/no): "), + mr.VolumeName); + if (!get_yesno(ua, buf)) { return 1; } if (ua->pint32_val) { @@ -1387,13 +1413,16 @@ static int delete_volume(UAContext *ua) static int delete_pool(UAContext *ua) { POOL_DBR pr; + char buf[200]; memset(&pr, 0, sizeof(pr)); if (!get_pool_dbr(ua, &pr)) { return 1; } - if (!get_yesno(ua, _("Are you sure you want to delete this Pool? (yes/no): "))) { + bsnprintf(buf, sizeof(buf), _("Are you sure you want to delete Pool \"%s\"? (yes/no): "), + pr.Name); + if (!get_yesno(ua, buf)) { return 1; } if (ua->pint32_val) { @@ -1405,7 +1434,7 @@ static int delete_pool(UAContext *ua) int memory_cmd(UAContext *ua, const char *cmd) { list_dir_status_header(ua); - sm_dump(false); + sm_dump(false, true); return 1; } @@ -1424,10 +1453,10 @@ static void do_mount_cmd(UAContext *ua, const char *command) Dmsg2(120, "%s: %s\n", command, ua->UA_sock->msg); store.store = get_storage_resource(ua, true/*arg is storage*/); - pm_strcpy(store.store_source, _("unknown source")); if (!store.store) { return; } + pm_strcpy(store.store_source, _("unknown source")); set_wstorage(jcr, &store); drive = get_storage_drive(ua, store.store); if (strcmp(command, "mount") == 0) { @@ -1538,7 +1567,8 @@ int wait_cmd(UAContext *ua, const char *cmd) { JCR *jcr; - /* no args + /* + * no args * Wait until no job is running */ if (ua->argc == 1) { @@ -1606,7 +1636,7 @@ int wait_cmd(UAContext *ua, const char *cmd) } /* - * We wait the end of job + * We wait the end of a specific job */ bmicrosleep(0, 200000); /* let job actually start */ @@ -1695,12 +1725,32 @@ int qhelp_cmd(UAContext *ua, const char *cmd) return 1; } +#if 1 static int version_cmd(UAContext *ua, const char *cmd) { ua->send_msg(_("%s Version: %s (%s) %s %s %s\n"), my_name, VERSION, BDATE, HOST_OS, DISTNAME, DISTVER); return 1; } +#else +/* + * Test code -- turned on only for debug testing + */ +static int version_cmd(UAContext *ua, const char *cmd) +{ + dbid_list ids; + POOL_MEM query(PM_MESSAGE); + open_db(ua); + Mmsg(query, "select MediaId from Media,Pool where Pool.PoolId=Media.PoolId and Pool.Name='Full'"); + db_get_query_dbids(ua->jcr, ua->db, query, ids); + ua->send_msg("num_ids=%d max_ids=%d tot_ids=%d\n", ids.num_ids, ids.max_ids, ids.tot_ids); + for (int i=0; i < ids.num_ids; i++) { + ua->send_msg("id=%d\n", ids.DBId[i]); + } + close_db(ua); + return 1; +} +#endif /* * This call explicitly checks for a catalog=xxx and @@ -1724,7 +1774,7 @@ bool open_client_db(UAContext *ua) ua->error_msg(_("No authorization for Catalog \"%s\"\n"), ua->argv[i]); return false; } - catalog = (CAT *)GetResWithName(R_CATALOG, ua->argv[i]); + catalog = GetCatalogResWithName(ua->argv[i]); if (catalog) { if (ua->catalog && ua->catalog != catalog) { close_db(ua); @@ -1741,7 +1791,7 @@ bool open_client_db(UAContext *ua) ua->error_msg(_("No authorization for Client \"%s\"\n"), ua->argv[i]); return false; } - client = (CLIENT *)GetResWithName(R_CLIENT, ua->argv[i]); + client = GetClientResWithName(ua->argv[i]); if (client) { catalog = client->catalog; if (ua->catalog && ua->catalog != catalog) { @@ -1763,7 +1813,7 @@ bool open_client_db(UAContext *ua) ua->error_msg(_("No authorization for Job \"%s\"\n"), ua->argv[i]); return false; } - job = (JOB *)GetResWithName(R_JOB, ua->argv[i]); + job = GetJobResWithName(ua->argv[i]); if (job) { catalog = job->client->catalog; if (ua->catalog && ua->catalog != catalog) { @@ -1800,8 +1850,9 @@ bool open_db(UAContext *ua) ua->jcr->catalog = ua->catalog; - Dmsg0(150, "Open database\n"); - ua->db = db_init_database(ua->jcr, ua->catalog->db_name, ua->catalog->db_user, + Dmsg0(100, "UA Open database\n"); + ua->db = db_init(ua->jcr, ua->catalog->db_driver, ua->catalog->db_name, + ua->catalog->db_user, ua->catalog->db_password, ua->catalog->db_address, ua->catalog->db_port, ua->catalog->db_socket, ua->catalog->mult_db_connections);