Skip to content

Commit

Permalink
config: GetResWithName is now a member of ConfigurationParser
Browse files Browse the repository at this point in the history
    - access GetResWithName using my_config->GetResWithName at all daemons
  • Loading branch information
franku committed Aug 31, 2018
1 parent 7a5fb38 commit b53d741
Show file tree
Hide file tree
Showing 23 changed files with 50 additions and 48 deletions.
4 changes: 2 additions & 2 deletions core/src/console/console_conf.cc
Expand Up @@ -311,14 +311,14 @@ bool SaveResource(int type, ResourceItem *items, int pass)
if (pass == 2) {
switch (type) {
case R_CONSOLE:
if ((res = (UnionOfResources *)GetResWithName(R_CONSOLE, res_all.res_cons.name())) == NULL) {
if ((res = (UnionOfResources *)my_config->GetResWithName(R_CONSOLE, res_all.res_cons.name())) == NULL) {
Emsg1(M_ABORT, 0, _("Cannot find Console resource %s\n"), res_all.res_cons.name());
} else {
res->res_cons.tls_cert.allowed_certificate_common_names_ = res_all.res_cons.tls_cert.allowed_certificate_common_names_;
}
break;
case R_DIRECTOR:
if ((res = (UnionOfResources *)GetResWithName(R_DIRECTOR, res_all.res_dir.name())) == NULL) {
if ((res = (UnionOfResources *)my_config->GetResWithName(R_DIRECTOR, res_all.res_dir.name())) == NULL) {
Emsg1(M_ABORT, 0, _("Cannot find Director resource %s\n"), res_all.res_dir.name());
} else {
res->res_dir.tls_cert.allowed_certificate_common_names_ = res_all.res_dir.tls_cert.allowed_certificate_common_names_;
Expand Down
4 changes: 2 additions & 2 deletions core/src/dird/authenticate.cc
Expand Up @@ -200,7 +200,7 @@ bool AuthenticateFileDaemon(BareosSocket *fd, char *client_name)
bool auth_success = false;

UnbashSpaces(client_name);
client = (ClientResource *)GetResWithName(R_CLIENT, client_name);
client = (ClientResource *)my_config->GetResWithName(R_CLIENT, client_name);
if (client) {
if (IsConnectFromClientAllowed(client)) {
auth_success = fd->AuthenticateInboundConnection(
Expand Down Expand Up @@ -270,7 +270,7 @@ bool AuthenticateUserAgent(UaContext *uac)
NULL, "Console", "*UserAgent*", me->password, me);
} else {
UnbashSpaces(name);
cons = (ConsoleResource *)GetResWithName(R_CONSOLE, name);
cons = (ConsoleResource *)my_config->GetResWithName(R_CONSOLE, name);
if (cons) {
auth_success =
ua->AuthenticateInboundConnection(NULL, "Console", name, cons->password, cons);
Expand Down
5 changes: 3 additions & 2 deletions core/src/dird/bsr.cc
Expand Up @@ -30,6 +30,7 @@

#include "include/bareos.h"
#include "dird.h"
#include "dird/dird_globals.h"
#include "dird/ua_input.h"
#include "dird/ua_restore.h"
#include "dird/ua_server.h"
Expand Down Expand Up @@ -73,7 +74,7 @@ static bool GetStorageDevice(char *device, char *storage)
if (storage[0] == 0) {
return false;
}
store = (StorageResource *)GetResWithName(R_STORAGE, storage);
store = (StorageResource *)my_config->GetResWithName(R_STORAGE, storage);
if (!store) {
return false;
}
Expand Down Expand Up @@ -791,7 +792,7 @@ static inline bool IsOnSameStorage(JobControlRecord *jcr, char *new_one)
return true;
}

new_store = (StorageResource *)GetResWithName(R_STORAGE, new_one);
new_store = (StorageResource *)my_config->GetResWithName(R_STORAGE, new_one);
if (!new_store) {
Jmsg(jcr, M_WARNING, 0,
_("Could not get storage resource '%s'.\n"), new_one);
Expand Down
20 changes: 10 additions & 10 deletions core/src/dird/dird_conf.cc
Expand Up @@ -2417,7 +2417,7 @@ static bool UpdateResourcePointer(int type, ResourceItem *items)
*
* Find resource saved in pass 1
*/
if (!(res = (UnionOfResources *)GetResWithName(R_POOL, res_all.res_pool.name()))) {
if (!(res = (UnionOfResources *)my_config->GetResWithName(R_POOL, res_all.res_pool.name()))) {
Emsg1(M_ERROR, 0, _("Cannot find Pool resource %s\n"), res_all.res_pool.name());
return false;
} else {
Expand All @@ -2434,7 +2434,7 @@ static bool UpdateResourcePointer(int type, ResourceItem *items)
}
break;
case R_CONSOLE:
if (!(res = (UnionOfResources *)GetResWithName(R_CONSOLE, res_all.res_con.name()))) {
if (!(res = (UnionOfResources *)my_config->GetResWithName(R_CONSOLE, res_all.res_con.name()))) {
Emsg1(M_ERROR, 0, _("Cannot find Console resource %s\n"), res_all.res_con.name());
return false;
} else {
Expand All @@ -2443,7 +2443,7 @@ static bool UpdateResourcePointer(int type, ResourceItem *items)
}
break;
case R_DIRECTOR:
if (!(res = (UnionOfResources *)GetResWithName(R_DIRECTOR, res_all.res_dir.name()))) {
if (!(res = (UnionOfResources *)my_config->GetResWithName(R_DIRECTOR, res_all.res_dir.name()))) {
Emsg1(M_ERROR, 0, _("Cannot find Director resource %s\n"), res_all.res_dir.name());
return false;
} else {
Expand All @@ -2454,7 +2454,7 @@ static bool UpdateResourcePointer(int type, ResourceItem *items)
}
break;
case R_STORAGE:
if (!(res = (UnionOfResources *)GetResWithName(type, res_all.res_store.name()))) {
if (!(res = (UnionOfResources *)my_config->GetResWithName(type, res_all.res_store.name()))) {
Emsg1(M_ERROR, 0, _("Cannot find Storage resource %s\n"), res_all.res_dir.name());
return false;
} else {
Expand All @@ -2479,7 +2479,7 @@ static bool UpdateResourcePointer(int type, ResourceItem *items)
break;
case R_JOBDEFS:
case R_JOB:
if (!(res = (UnionOfResources *)GetResWithName(type, res_all.res_job.name()))) {
if (!(res = (UnionOfResources *)my_config->GetResWithName(type, res_all.res_job.name()))) {
Emsg1(M_ERROR, 0, _("Cannot find Job resource %s\n"), res_all.res_job.name());
return false;
} else {
Expand Down Expand Up @@ -2539,7 +2539,7 @@ static bool UpdateResourcePointer(int type, ResourceItem *items)
}
break;
case R_COUNTER:
if (!(res = (UnionOfResources *)GetResWithName(R_COUNTER, res_all.res_counter.name()))) {
if (!(res = (UnionOfResources *)my_config->GetResWithName(R_COUNTER, res_all.res_counter.name()))) {
Emsg1(M_ERROR, 0, _("Cannot find Counter resource %s\n"), res_all.res_counter.name());
return false;
} else {
Expand All @@ -2548,7 +2548,7 @@ static bool UpdateResourcePointer(int type, ResourceItem *items)
}
break;
case R_CLIENT:
if (!(res = (UnionOfResources *)GetResWithName(R_CLIENT, res_all.res_client.name()))) {
if (!(res = (UnionOfResources *)my_config->GetResWithName(R_CLIENT, res_all.res_client.name()))) {
Emsg1(M_ERROR, 0, _("Cannot find Client resource %s\n"), res_all.res_client.name());
return false;
} else {
Expand All @@ -2573,7 +2573,7 @@ static bool UpdateResourcePointer(int type, ResourceItem *items)
* in by run_conf.c during pass 2, so here we jam the pointer
* into the Schedule resource.
*/
if (!(res = (UnionOfResources *)GetResWithName(R_SCHEDULE, res_all.res_client.name()))) {
if (!(res = (UnionOfResources *)my_config->GetResWithName(R_SCHEDULE, res_all.res_client.name()))) {
Emsg1(M_ERROR, 0, _("Cannot find Schedule resource %s\n"), res_all.res_client.name());
return false;
} else {
Expand Down Expand Up @@ -3138,7 +3138,7 @@ static void StoreRunscriptTarget(LEX *lc, ResourceItem *item, int index, int pas
} else {
CommonResourceHeader *res;

if (!(res = GetResWithName(R_CLIENT, lc->str))) {
if (!(res = my_config->GetResWithName(R_CLIENT, lc->str))) {
scan_err3(lc, _("Could not find config Resource %s referenced on line %d : %s\n"),
lc->str, lc->line_no, lc->line);
}
Expand Down Expand Up @@ -3794,7 +3794,7 @@ bool GetTlsPskByFullyQualifiedResourceName(const char *fq_name_, std::string &ps
psk_return_value = me->password.value;
success = true;
} else {
ConsoleResource *res = reinterpret_cast<ConsoleResource*>(GetResWithName(R_CONSOLE, fq_name.c_str()));
ConsoleResource *res = reinterpret_cast<ConsoleResource*>(my_config->GetResWithName(R_CONSOLE, fq_name.c_str()));
if(res) {
psk_return_value = res->password.value;
success = true;
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/fd_cmds.cc
Expand Up @@ -1205,7 +1205,7 @@ void *HandleFiledConnection(ConnectionPool *connections, BareosSocket *fd,
ClientResource *client_resource;
Connection *connection = NULL;

client_resource = (ClientResource *)GetResWithName(R_CLIENT, client_name);
client_resource = (ClientResource *)my_config->GetResWithName(R_CLIENT, client_name);
if (!client_resource) {
Emsg1(M_WARNING, 0, "Client \"%s\" tries to connect, "
"but no matching resource is defined.\n", client_name);
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/getmsg.cc
Expand Up @@ -325,7 +325,7 @@ int BgetDirmsg(BareosSocket *bs, bool allow_any_message)
Emsg1(M_ERROR, 0, _("Malformed message: %s\n"), bs->msg);
} else {
UnbashSpaces(dev_name);
dev = (Device *)GetResWithName(R_DEVICE, dev_name.c_str());
dev = (Device *)my_config->GetResWithName(R_DEVICE, dev_name.c_str());
if (!dev) {
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/dird/migrate.cc
Expand Up @@ -293,7 +293,7 @@ static inline bool SetMigrationNextPool(JobControlRecord *jcr, PoolResource **re
/*
* Get the pool resource corresponding to the original job
*/
pool = (PoolResource *)GetResWithName(R_POOL, pr.Name);
pool = (PoolResource *)my_config->GetResWithName(R_POOL, pr.Name);
*retpool = pool;
if (!pool) {
Jmsg(jcr, M_FATAL, 0, _("Pool resource \"%s\" not found.\n"), pr.Name);
Expand Down Expand Up @@ -1131,8 +1131,8 @@ bool DoMigrationInit(JobControlRecord *jcr)
Dmsg5(dbglevel, "JobId=%d: Current: Name=%s JobId=%d Type=%c Level=%c\n",
(int)jcr->JobId, jcr->jr.Name, (int)jcr->jr.JobId, jcr->jr.JobType, jcr->jr.JobLevel);

job = (JobResource *)GetResWithName(R_JOB, jcr->jr.Name);
prev_job = (JobResource *)GetResWithName(R_JOB, jcr->previous_jr.Name);
job = (JobResource *)my_config->GetResWithName(R_JOB, jcr->jr.Name);
prev_job = (JobResource *)my_config->GetResWithName(R_JOB, jcr->previous_jr.Name);

if (!job) {
Jmsg(jcr, M_FATAL, 0, _("Job resource not found for \"%s\".\n"), jcr->jr.Name);
Expand Down
6 changes: 3 additions & 3 deletions core/src/dird/run_conf.cc
Expand Up @@ -248,7 +248,7 @@ void StoreRun(LEX *lc, ResourceItem *item, int index, int pass)
case 'n': /* NextPool */
token = LexGetToken(lc, BCT_NAME);
if (pass == 2) {
res = GetResWithName(R_POOL, lc->str);
res = my_config->GetResWithName(R_POOL, lc->str);
if (res == NULL) {
scan_err1(lc, _("Could not find specified Pool Resource: %s"),
lc->str);
Expand Down Expand Up @@ -279,7 +279,7 @@ void StoreRun(LEX *lc, ResourceItem *item, int index, int pass)
case 'S': /* Storage */
token = LexGetToken(lc, BCT_NAME);
if (pass == 2) {
res = GetResWithName(R_STORAGE, lc->str);
res = my_config->GetResWithName(R_STORAGE, lc->str);
if (res == NULL) {
scan_err1(lc, _("Could not find specified Storage Resource: %s"),
lc->str);
Expand All @@ -291,7 +291,7 @@ void StoreRun(LEX *lc, ResourceItem *item, int index, int pass)
case 'M': /* Messages */
token = LexGetToken(lc, BCT_NAME);
if (pass == 2) {
res = GetResWithName(R_MSGS, lc->str);
res = my_config->GetResWithName(R_MSGS, lc->str);
if (res == NULL) {
scan_err1(lc, _("Could not find specified Messages Resource: %s"),
lc->str);
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/scheduler.cc
Expand Up @@ -108,7 +108,7 @@ JobControlRecord *wait_for_next_job(char *one_shot_job_to_run)
/* Create scheduled jobs list */
jobs_to_run = New(dlist(next_job, &next_job->link));
if (one_shot_job_to_run) { /* one shot */
job = (JobResource *)GetResWithName(R_JOB, one_shot_job_to_run);
job = (JobResource *)my_config->GetResWithName(R_JOB, one_shot_job_to_run);
if (!job) {
Emsg1(M_ABORT, 0, _("Job %s not found\n"), one_shot_job_to_run);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/stats.cc
Expand Up @@ -168,7 +168,7 @@ void *statistics_thread(void *arg)

LockRes();
if ((current_store.c_str())[0]) {
store = (StorageResource *)GetResWithName(R_STORAGE, current_store.c_str());
store = (StorageResource *)my_config->GetResWithName(R_STORAGE, current_store.c_str());
} else {
store = NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/storage.cc
Expand Up @@ -460,7 +460,7 @@ bool SelectNextRstore(JobControlRecord *jcr, bootstrap_info &info)
return true; /* Same SD nothing to change */
}

if (!(ustore.store = (StorageResource *)GetResWithName(R_STORAGE,info.storage))) {
if (!(ustore.store = (StorageResource *)my_config->GetResWithName(R_STORAGE,info.storage))) {
Jmsg(jcr, M_FATAL, 0,
_("Could not get storage resource '%s'.\n"), info.storage);
jcr->setJobStatus(JS_ErrorTerminated);
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/testfind.cc
Expand Up @@ -143,7 +143,7 @@ main (int argc, char *const *argv)
}

jcr = new_jcr(sizeof(JobControlRecord), NULL);
jcr->res.fileset = (FilesetResource *)GetResWithName(R_FILESET, fileset_name);
jcr->res.fileset = (FilesetResource *)my_config->GetResWithName(R_FILESET, fileset_name);

if (jcr->res.fileset == NULL) {
fprintf(stderr, "%s: Fileset not found\n", fileset_name);
Expand Down
3 changes: 2 additions & 1 deletion core/src/dird/ua_acl.cc
Expand Up @@ -30,6 +30,7 @@

#include "include/bareos.h"
#include "dird.h"
#include "dird/dird_globals.h"
#include "lib/edit.h"

namespace directordaemon {
Expand Down Expand Up @@ -393,7 +394,7 @@ CommonResourceHeader *UaContext::GetResWithName(int rcode, const char *name, boo
}
}

return ::GetResWithName(rcode, name, lock);
return my_config->GetResWithName(rcode, name, lock);

bail_out:
return NULL;
Expand Down
4 changes: 2 additions & 2 deletions core/src/dird/ua_configure.cc
Expand Up @@ -292,7 +292,7 @@ static inline bool ConfigureAddResource(UaContext *ua, int first_parameter, Reso
return false;
}

if (GetResWithName(res_table->rcode, name.c_str())) {
if (my_config->GetResWithName(res_table->rcode, name.c_str())) {
ua->ErrorMsg("Resource \"%s\" with name \"%s\" already exists.\n", res_table->name, name.c_str());
return false;
}
Expand Down Expand Up @@ -324,7 +324,7 @@ static inline bool ConfigureAddResource(UaContext *ua, int first_parameter, Reso
* therefore we explicitly check the new resource here.
*/
if ((res_table->rcode == R_JOB) || (res_table->rcode == R_JOBDEFS)) {
res = (JobResource *)GetResWithName(res_table->rcode, name.c_str());
res = (JobResource *)my_config->GetResWithName(res_table->rcode, name.c_str());
PropagateJobdefs(res_table->rcode, res);
if (!ValidateResource(res_table->rcode, res_table->items, (BareosResource *)res)) {
ua->ErrorMsg("failed to create config resource \"%s\"\n", name.c_str());
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/ua_output.cc
Expand Up @@ -1608,7 +1608,7 @@ of_filter_state filterit(void *ctx, void *data, of_filter_tuple *tuple)
strlen(row[tuple->u.res_filter.column]) == 0) {
retval = OF_FILTER_STATE_UNKNOWN;
} else {
if (!GetResWithName(tuple->u.res_filter.restype,
if (!my_config->GetResWithName(tuple->u.res_filter.restype,
row[tuple->u.res_filter.column], false)) {
Dmsg2(200, "filterit: Filter on resource_type %d value %s, suppress output\n",
tuple->u.res_filter.restype, row[tuple->u.res_filter.column]);
Expand Down
6 changes: 3 additions & 3 deletions core/src/dird/ua_prune.cc
Expand Up @@ -634,21 +634,21 @@ static int JobSelectHandler(void *ctx, int num_fields, char **row)
/*
* If this job doesn't exist anymore in the configuration, delete it.
*/
if (GetResWithName(R_JOB, row[0], false) == NULL) {
if (my_config->GetResWithName(R_JOB, row[0], false) == NULL) {
return 0;
}

/*
* If this fileset doesn't exist anymore in the configuration, delete it.
*/
if (GetResWithName(R_FILESET, row[1], false) == NULL) {
if (my_config->GetResWithName(R_FILESET, row[1], false) == NULL) {
return 0;
}

/*
* If this client doesn't exist anymore in the configuration, delete it.
*/
if (GetResWithName(R_CLIENT, row[2], false) == NULL) {
if (my_config->GetResWithName(R_CLIENT, row[2], false) == NULL) {
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/filed/authenticate.cc
Expand Up @@ -116,7 +116,7 @@ bool AuthenticateDirector(JobControlRecord *jcr)
}

UnbashSpaces(dirname.c_str());
director = (DirectorResource *)GetResWithName(R_DIRECTOR, dirname.c_str());
director = (DirectorResource *)my_config->GetResWithName(R_DIRECTOR, dirname.c_str());

if (!director) {
char addr[64];
Expand Down
4 changes: 2 additions & 2 deletions core/src/filed/filed_conf.cc
Expand Up @@ -623,7 +623,7 @@ bool SaveResource(int type, ResourceItem *items, int pass)
/*
* Resources containing another resource
*/
if ((res = (UnionOfResources *)GetResWithName(R_DIRECTOR, res_all.res_dir.name())) == NULL) {
if ((res = (UnionOfResources *)my_config->GetResWithName(R_DIRECTOR, res_all.res_dir.name())) == NULL) {
Emsg1(M_ABORT, 0, _("Cannot find Director resource %s\n"), res_all.res_dir.name());
} else {
res->res_dir.tls_cert.allowed_certificate_common_names_ = res_all.res_dir.tls_cert.allowed_certificate_common_names_;
Expand All @@ -632,7 +632,7 @@ bool SaveResource(int type, ResourceItem *items, int pass)
}
break;
case R_CLIENT:
if ((res = (UnionOfResources *)GetResWithName(R_CLIENT, res_all.res_dir.name())) == NULL) {
if ((res = (UnionOfResources *)my_config->GetResWithName(R_CLIENT, res_all.res_dir.name())) == NULL) {
Emsg1(M_ABORT, 0, _("Cannot find Client resource %s\n"), res_all.res_dir.name());
} else {
res->res_client.plugin_names = res_all.res_client.plugin_names;
Expand Down
2 changes: 1 addition & 1 deletion core/src/lib/parse_conf.h
Expand Up @@ -458,6 +458,7 @@ class DLL_IMP_EXP ConfigurationParser {
const char *resourcetype, const char *name,
bool error_if_exits = false, bool create_directories = false);
CommonResourceHeader *GetNextRes(int rcode, CommonResourceHeader *res);
CommonResourceHeader *GetResWithName(int rcode, const char *name, bool lock = true);

private:
ConfigurationParser(const ConfigurationParser&) = delete;
Expand Down Expand Up @@ -492,7 +493,6 @@ DLL_IMP_EXP const char *datatype_to_description(int type);
/*
* Resource routines
*/
DLL_IMP_EXP CommonResourceHeader *GetResWithName(int rcode, const char *name, bool lock = true);
DLL_IMP_EXP void b_LockRes(const char *file, int line);
DLL_IMP_EXP void b_UnlockRes(const char *file, int line);
DLL_IMP_EXP void DumpResource(int type, CommonResourceHeader *res, void sendmsg(void *sock, const char *fmt, ...),
Expand Down
8 changes: 4 additions & 4 deletions core/src/lib/res.cc
Expand Up @@ -95,7 +95,7 @@ void b_UnlockRes(const char *file, int line)
/*
* Return resource of type rcode that matches name
*/
CommonResourceHeader *GetResWithName(int rcode, const char *name, bool lock)
CommonResourceHeader *ConfigurationParser::GetResWithName(int rcode, const char *name, bool lock)
{
CommonResourceHeader *res;
int rindex = rcode - my_config->r_first_;
Expand Down Expand Up @@ -575,7 +575,7 @@ static void StoreRes(LEX *lc, ResourceItem *item, int index, int pass)

LexGetToken(lc, BCT_NAME);
if (pass == 2) {
res = GetResWithName(item->code, lc->str);
res = my_config->GetResWithName(item->code, lc->str);
if (res == NULL) {
scan_err3(lc, _("Could not find config resource \"%s\" referenced on line %d: %s"),
lc->str, lc->line_no, lc->line);
Expand Down Expand Up @@ -629,7 +629,7 @@ static void StoreAlistRes(LEX *lc, ResourceItem *item, int index, int pass)

for (;;) {
LexGetToken(lc, BCT_NAME); /* scan next item */
res = GetResWithName(item->code, lc->str);
res = my_config->GetResWithName(item->code, lc->str);
if (res == NULL) {
scan_err3(lc, _("Could not find config Resource \"%s\" referenced on line %d : %s\n"),
item->name, lc->line_no, lc->line);
Expand Down Expand Up @@ -790,7 +790,7 @@ static void StoreDefs(LEX *lc, ResourceItem *item, int index, int pass)
LexGetToken(lc, BCT_NAME);
if (pass == 2) {
Dmsg2(900, "Code=%d name=%s\n", item->code, lc->str);
res = GetResWithName(item->code, lc->str);
res = my_config->GetResWithName(item->code, lc->str);
if (res == NULL) {
scan_err3(lc, _("Missing config Resource \"%s\" referenced on line %d : %s\n"),
lc->str, lc->line_no, lc->line);
Expand Down

0 comments on commit b53d741

Please sign in to comment.