- if (strcasecmp(ua->argk[i], _("pool")) == 0 && ua->argv[i]) {
- strcpy(pr->Name, ua->argv[i]);
- if (!db_get_pool_record(ua->db, pr)) {
- bsendmsg(ua, _("Could not find Pool %s: ERR=%s"), ua->argv[i],
- db_strerror(ua->db));
- pr->PoolId = 0;
- break;
- }
- return pr->PoolId;
- }
- }
- if (!select_pool_dbr(ua, pr)) { /* try once more */
+ if ((strcasecmp(ua->argk[i], NT_("client")) == 0 ||
+ strcasecmp(ua->argk[i], NT_("fd")) == 0) && ua->argv[i]) {
+ if (!acl_access_ok(ua, Client_ACL, ua->argv[i])) {
+ break;
+ }
+ bstrncpy(cr->Name, ua->argv[i], sizeof(cr->Name));
+ if (!db_get_client_record(ua->jcr, ua->db, cr)) {
+ ua->error_msg(_("Could not find Client \"%s\": ERR=%s"), ua->argv[i],
+ db_strerror(ua->db));
+ cr->ClientId = 0;
+ break;
+ }
+ return 1;
+ }
+ }
+ if (!select_client_dbr(ua, cr)) { /* try once more by proposing a list */
+ return 0;
+ }
+ return 1;
+}
+
+/*
+ * Select a Client record from the catalog
+ * Returns 1 on success
+ * 0 on failure
+ */
+bool select_client_dbr(UAContext *ua, CLIENT_DBR *cr)
+{
+ CLIENT_DBR ocr;
+ char name[MAX_NAME_LENGTH];
+ int num_clients, i;
+ uint32_t *ids;
+
+
+ cr->ClientId = 0;
+ if (!db_get_client_ids(ua->jcr, ua->db, &num_clients, &ids)) {
+ ua->error_msg(_("Error obtaining client ids. ERR=%s\n"), db_strerror(ua->db));
+ return 0;
+ }
+ if (num_clients <= 0) {
+ ua->error_msg(_("No clients defined. You must run a job before using this command.\n"));
+ return 0;
+ }
+
+ start_prompt(ua, _("Defined Clients:\n"));
+ for (i=0; i < num_clients; i++) {
+ ocr.ClientId = ids[i];
+ if (!db_get_client_record(ua->jcr, ua->db, &ocr) ||
+ !acl_access_ok(ua, Client_ACL, ocr.Name)) {
+ continue;
+ }
+ add_prompt(ua, ocr.Name);
+ }
+ free(ids);
+ if (do_prompt(ua, _("Client"), _("Select the Client"), name, sizeof(name)) < 0) {