X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fdird%2Fua_select.c;h=99df0d3a73a9827eed515bf4ef7cea5398424eff;hb=b8b2ed2a6db4fb8436647d438185a364951375fc;hp=4a324783176eff75ab808d8111c055aa9b93a8f9;hpb=1c240bb2e921e2be1af878bb48c4f4b5a37db2a8;p=bacula%2Fbacula diff --git a/bacula/src/dird/ua_select.c b/bacula/src/dird/ua_select.c index 4a32478317..99df0d3a73 100644 --- a/bacula/src/dird/ua_select.c +++ b/bacula/src/dird/ua_select.c @@ -84,6 +84,12 @@ int find_arg_keyword(UAContext *ua, char **list) return -1; } +/* + * Given one keyword, find the first one that + * is in the argument list. + * Returns: argk index (always gt 0) + * -1 if not found + */ int find_arg(UAContext *ua, char *keyword) { for (int i=1; iargc; i++) { @@ -138,12 +144,14 @@ int do_keyword_prompt(UAContext *ua, char *msg, char **list) STORE *select_storage_resource(UAContext *ua) { char name[MAX_NAME_LENGTH]; - STORE *store = NULL; + STORE *store; start_prompt(ua, _("The defined Storage resources are:\n")); LockRes(); - while ((store = (STORE *)GetNextRes(R_STORAGE, (RES *)store))) { - add_prompt(ua, store->hdr.name); + foreach_res(store, R_STORAGE) { + if (acl_access_ok(ua, Storage_ACL, store->hdr.name)) { + add_prompt(ua, store->hdr.name); + } } UnlockRes(); do_prompt(ua, _("Storage"), _("Select Storage resource"), name, sizeof(name)); @@ -157,12 +165,14 @@ STORE *select_storage_resource(UAContext *ua) FILESET *select_fileset_resource(UAContext *ua) { char name[MAX_NAME_LENGTH]; - FILESET *fs = NULL; + FILESET *fs; start_prompt(ua, _("The defined FileSet resources are:\n")); LockRes(); - while ((fs = (FILESET *)GetNextRes(R_FILESET, (RES *)fs))) { - add_prompt(ua, fs->hdr.name); + foreach_res(fs, R_FILESET) { + if (acl_access_ok(ua, FileSet_ACL, fs->hdr.name)) { + add_prompt(ua, fs->hdr.name); + } } UnlockRes(); do_prompt(ua, _("FileSet"), _("Select FileSet resource"), name, sizeof(name)); @@ -182,15 +192,19 @@ CAT *get_catalog_resource(UAContext *ua) for (i=1; iargc; i++) { if (strcasecmp(ua->argk[i], _("catalog")) == 0 && ua->argv[i]) { - catalog = (CAT *)GetResWithName(R_CATALOG, ua->argv[i]); - break; + if (acl_access_ok(ua, Catalog_ACL, ua->argv[i])) { + catalog = (CAT *)GetResWithName(R_CATALOG, ua->argv[i]); + break; + } } } if (!catalog) { start_prompt(ua, _("The defined Catalog resources are:\n")); LockRes(); - while ((catalog = (CAT *)GetNextRes(R_CATALOG, (RES *)catalog))) { - add_prompt(ua, catalog->hdr.name); + foreach_res(catalog, R_CATALOG) { + if (acl_access_ok(ua, Catalog_ACL, catalog->hdr.name)) { + add_prompt(ua, catalog->hdr.name); + } } UnlockRes(); do_prompt(ua, _("Catalog"), _("Select Catalog resource"), name, sizeof(name)); @@ -206,12 +220,14 @@ CAT *get_catalog_resource(UAContext *ua) JOB *select_job_resource(UAContext *ua) { char name[MAX_NAME_LENGTH]; - JOB *job = NULL; + JOB *job; start_prompt(ua, _("The defined Job resources are:\n")); LockRes(); - while ( (job = (JOB *)GetNextRes(R_JOB, (RES *)job)) ) { - add_prompt(ua, job->hdr.name); + foreach_res(job, R_JOB) { + if (acl_access_ok(ua, Job_ACL, job->hdr.name)) { + add_prompt(ua, job->hdr.name); + } } UnlockRes(); do_prompt(ua, _("Job"), _("Select Job resource"), name, sizeof(name)); @@ -225,12 +241,12 @@ JOB *select_job_resource(UAContext *ua) JOB *select_restore_job_resource(UAContext *ua) { char name[MAX_NAME_LENGTH]; - JOB *job = NULL; + JOB *job; start_prompt(ua, _("The defined Restore Job resources are:\n")); LockRes(); - while ( (job = (JOB *)GetNextRes(R_JOB, (RES *)job)) ) { - if (job->JobType == JT_RESTORE) { + foreach_res(job, R_JOB) { + if (job->JobType == JT_RESTORE && acl_access_ok(ua, Job_ACL, job->hdr.name)) { add_prompt(ua, job->hdr.name); } } @@ -248,12 +264,14 @@ JOB *select_restore_job_resource(UAContext *ua) CLIENT *select_client_resource(UAContext *ua) { char name[MAX_NAME_LENGTH]; - CLIENT *client = NULL; + CLIENT *client; start_prompt(ua, _("The defined Client resources are:\n")); LockRes(); - while ( (client = (CLIENT *)GetNextRes(R_CLIENT, (RES *)client)) ) { - add_prompt(ua, client->hdr.name); + foreach_res(client, R_CLIENT) { + if (acl_access_ok(ua, Client_ACL, client->hdr.name)) { + add_prompt(ua, client->hdr.name); + } } UnlockRes(); do_prompt(ua, _("Client"), _("Select Client (File daemon) resource"), name, sizeof(name)); @@ -272,7 +290,11 @@ CLIENT *get_client_resource(UAContext *ua) int i; for (i=1; iargc; i++) { - if (strcasecmp(ua->argk[i], _("client")) == 0 && ua->argv[i]) { + if ((strcasecmp(ua->argk[i], _("client")) == 0 || + strcasecmp(ua->argk[i], _("fd")) == 0) && ua->argv[i]) { + if (!acl_access_ok(ua, Client_ACL, ua->argv[i])) { + break; + } client = (CLIENT *)GetResWithName(R_CLIENT, ua->argv[i]); if (client) { return client; @@ -305,10 +327,14 @@ int get_client_dbr(UAContext *ua, CLIENT_DBR *cr) bsendmsg(ua, _("Could not find Client %s: ERR=%s"), cr->Name, db_strerror(ua->db)); } for (i=1; iargc; i++) { - if (strcasecmp(ua->argk[i], _("client")) == 0 && ua->argv[i]) { + if ((strcasecmp(ua->argk[i], _("client")) == 0 || + strcasecmp(ua->argk[i], _("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)) { - bsendmsg(ua, _("Could not find Client %s: ERR=%s"), ua->argv[i], + bsendmsg(ua, _("Could not find Client \"%s\": ERR=%s"), ua->argv[i], db_strerror(ua->db)); cr->ClientId = 0; break; @@ -348,7 +374,8 @@ int select_client_dbr(UAContext *ua, CLIENT_DBR *cr) 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)) { + if (!db_get_client_record(ua->jcr, ua->db, &ocr) || + !acl_access_ok(ua, Client_ACL, ocr.Name)) { continue; } add_prompt(ua, ocr.Name); @@ -361,7 +388,7 @@ int select_client_dbr(UAContext *ua, CLIENT_DBR *cr) bstrncpy(ocr.Name, name, sizeof(ocr.Name)); if (!db_get_client_record(ua->jcr, ua->db, &ocr)) { - bsendmsg(ua, _("Could not find Client %s: ERR=%s"), name, db_strerror(ua->db)); + bsendmsg(ua, _("Could not find Client \"%s\": ERR=%s"), name, db_strerror(ua->db)); return 0; } memcpy(cr, &ocr, sizeof(ocr)); @@ -383,10 +410,11 @@ int select_client_dbr(UAContext *ua, CLIENT_DBR *cr) int get_pool_dbr(UAContext *ua, POOL_DBR *pr) { if (pr->Name[0]) { /* If name already supplied */ - if (db_get_pool_record(ua->jcr, ua->db, pr)) { + if (db_get_pool_record(ua->jcr, ua->db, pr) && + acl_access_ok(ua, Pool_ACL, pr->Name)) { return pr->PoolId; } - bsendmsg(ua, _("Could not find Pool %s: ERR=%s"), pr->Name, db_strerror(ua->db)); + bsendmsg(ua, _("Could not find Pool \"%s\": ERR=%s"), pr->Name, db_strerror(ua->db)); } if (!select_pool_dbr(ua, pr)) { /* try once more */ return 0; @@ -405,10 +433,11 @@ int select_pool_dbr(UAContext *ua, POOL_DBR *pr) uint32_t *ids; for (i=1; iargc; i++) { - if (strcasecmp(ua->argk[i], _("pool")) == 0 && ua->argv[i]) { + if (strcasecmp(ua->argk[i], _("pool")) == 0 && ua->argv[i] && + acl_access_ok(ua, Pool_ACL, ua->argv[i])) { bstrncpy(pr->Name, ua->argv[i], sizeof(pr->Name)); if (!db_get_pool_record(ua->jcr, ua->db, pr)) { - bsendmsg(ua, _("Could not find Pool %s: ERR=%s"), ua->argv[i], + bsendmsg(ua, _("Could not find Pool \"%s\": ERR=%s"), ua->argv[i], db_strerror(ua->db)); pr->PoolId = 0; break; @@ -430,7 +459,8 @@ int select_pool_dbr(UAContext *ua, POOL_DBR *pr) start_prompt(ua, _("Defined Pools:\n")); for (i=0; i < num_pools; i++) { opr.PoolId = ids[i]; - if (!db_get_pool_record(ua->jcr, ua->db, &opr)) { + if (!db_get_pool_record(ua->jcr, ua->db, &opr) || + !acl_access_ok(ua, Pool_ACL, opr.Name)) { continue; } add_prompt(ua, opr.Name); @@ -443,7 +473,7 @@ int select_pool_dbr(UAContext *ua, POOL_DBR *pr) bstrncpy(opr.Name, name, sizeof(opr.Name)); if (!db_get_pool_record(ua->jcr, ua->db, &opr)) { - bsendmsg(ua, _("Could not find Pool %s: ERR=%s"), name, db_strerror(ua->db)); + bsendmsg(ua, _("Could not find Pool \"%s\": ERR=%s"), name, db_strerror(ua->db)); return 0; } memcpy(pr, &opr, sizeof(opr)); @@ -465,6 +495,10 @@ int select_pool_and_media_dbr(UAContext *ua, POOL_DBR *pr, MEDIA_DBR *mr) bsendmsg(ua, "%s", db_strerror(ua->db)); return 0; } + if (!acl_access_ok(ua, Pool_ACL, pr->Name)) { + bsendmsg(ua, _("No access to Pool \"%s\"\n"), pr->Name); + return 0; + } return 1; } @@ -512,12 +546,14 @@ int select_media_dbr(UAContext *ua, MEDIA_DBR *mr) POOL *select_pool_resource(UAContext *ua) { char name[MAX_NAME_LENGTH]; - POOL *pool = NULL; + POOL *pool; start_prompt(ua, _("The defined Pool resources are:\n")); LockRes(); - while ((pool = (POOL *)GetNextRes(R_POOL, (RES *)pool))) { - add_prompt(ua, pool->hdr.name); + foreach_res(pool, R_POOL) { + if (acl_access_ok(ua, Pool_ACL, pool->hdr.name)) { + add_prompt(ua, pool->hdr.name); + } } UnlockRes(); do_prompt(ua, _("Pool"), _("Select Pool resource"), name, sizeof(name)); @@ -537,12 +573,12 @@ POOL *get_pool_resource(UAContext *ua) int i; i = find_arg_with_value(ua, "pool"); - if (i >= 0) { + if (i >= 0 && acl_access_ok(ua, Pool_ACL, ua->argv[i])) { pool = (POOL *)GetResWithName(R_POOL, ua->argv[i]); if (pool) { return pool; } - bsendmsg(ua, _("Error: Pool resource %s does not exist.\n"), ua->argv[i]); + bsendmsg(ua, _("Error: Pool resource \"%s\" does not exist.\n"), ua->argv[i]); } return select_pool_resource(ua); } @@ -585,12 +621,12 @@ int get_job_dbr(UAContext *ua, JOB_DBR *jr) jr->JobId = 0; bstrncpy(jr->Job, ua->argv[i], sizeof(jr->Job)); } else if (strcasecmp(ua->argk[i], _("jobid")) == 0 && ua->argv[i]) { - jr->JobId = atoi(ua->argv[i]); + jr->JobId = str_to_int64(ua->argv[i]); } else { continue; } if (!db_get_job_record(ua->jcr, ua->db, jr)) { - bsendmsg(ua, _("Could not find Job %s: ERR=%s"), ua->argv[i], + bsendmsg(ua, _("Could not find Job \"%s\": ERR=%s"), ua->argv[i], db_strerror(ua->db)); jr->JobId = 0; break; @@ -730,27 +766,29 @@ STORE *get_storage_resource(UAContext *ua, int use_default) for (i=1; iargc; i++) { if (use_default && !ua->argv[i]) { + /* Ignore scan and barcode(s) keywords */ + if (strncasecmp("scan", ua->argk[i], 4) == 0 || + strncasecmp("barcode", ua->argk[i], 7) == 0) { + continue; + } /* Default argument is storage */ if (store_name) { bsendmsg(ua, _("Storage name given twice.\n")); return NULL; } - /* Ignore barcode(s) keywords */ - if (strncasecmp("barcode", ua->argk[i], 7) == 0) { - continue; - } store_name = ua->argk[i]; if (*store_name == '?') { *store_name = 0; break; } } else { - if (strcasecmp(ua->argk[i], _("storage")) == 0) { + if (strcasecmp(ua->argk[i], _("storage")) == 0 || + strcasecmp(ua->argk[i], _("sd")) == 0) { store_name = ua->argv[i]; break; } else if (strcasecmp(ua->argk[i], _("jobid")) == 0) { - jobid = atoi(ua->argv[i]); + jobid = str_to_int64(ua->argv[i]); if (jobid <= 0) { bsendmsg(ua, _("Expecting jobid=nn command, got: %s\n"), ua->argk[i]); return NULL; @@ -765,7 +803,7 @@ STORE *get_storage_resource(UAContext *ua, int use_default) } else if (strcasecmp(ua->argk[i], _("job")) == 0) { if (!(jcr=get_jcr_by_partial_name(ua->argv[i]))) { - bsendmsg(ua, _("Job %s is not running.\n"), ua->argv[i]); + bsendmsg(ua, _("Job \"%s\" is not running.\n"), ua->argv[i]); return NULL; } store = jcr->store; @@ -774,13 +812,19 @@ STORE *get_storage_resource(UAContext *ua, int use_default) } } } - + if (store && !acl_access_ok(ua, Storage_ACL, store->hdr.name)) { + store = NULL; + } + if (!store && store_name) { store = (STORE *)GetResWithName(R_STORAGE, store_name); if (!store) { - bsendmsg(ua, "Storage resource %s: not found\n", store_name); + bsendmsg(ua, "Storage resource \"%s\": not found\n", store_name); } } + if (store && !acl_access_ok(ua, Storage_ACL, store->hdr.name)) { + store = NULL; + } /* No keywords found, so present a selection list */ if (!store) { store = select_storage_resource(ua); @@ -810,7 +854,7 @@ int get_media_type(UAContext *ua, char *MediaType, int max_media) start_prompt(ua, _("Media Types defined in conf file:\n")); LockRes(); - for (store = NULL; (store = (STORE *)GetNextRes(R_STORAGE, (RES *)store)); ) { + foreach_res(store, R_STORAGE) { add_prompt(ua, store->media_type); } UnlockRes();