Skip to content

Commit

Permalink
Switch programs to use config class derived from BRSRES
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco van Wieringen committed Jun 22, 2015
1 parent 4bb54d0 commit 18112f1
Show file tree
Hide file tree
Showing 36 changed files with 220 additions and 242 deletions.
23 changes: 11 additions & 12 deletions src/console/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ static bool select_director(const char *director, DIRRES **ret_dir, CONRES **ret
if (director) { /* Command line choice overwrite the no choose option */
LockRes();
foreach_res(dir, R_DIRECTOR) {
if (bstrcmp(dir->hdr.name, director)) {
if (bstrcmp(dir->name(), director)) {
break;
}
}
Expand All @@ -1011,8 +1011,7 @@ static bool select_director(const char *director, DIRRES **ret_dir, CONRES **ret
LockRes();
numdir = 0;
foreach_res(dir, R_DIRECTOR) {
senditf( _("%2d: %s at %s:%d\n"), 1+numdir++, dir->hdr.name,
dir->address, dir->DIRport);
senditf( _("%2d: %s at %s:%d\n"), 1+numdir++, dir->name(), dir->address, dir->DIRport);
}
UnlockRes();
if (get_cmd(stdin, _("Select Director by entering a number: "),
Expand Down Expand Up @@ -1046,7 +1045,7 @@ static bool select_director(const char *director, DIRRES **ret_dir, CONRES **ret
LockRes();
for (i=0; i<numcon; i++) {
cons = (CONRES *)GetNextRes(R_CONSOLE, (RES *)cons);
if (cons->director && bstrcmp(cons->director, dir->hdr.name)) {
if (cons->director && bstrcmp(cons->director, dir->name())) {
break;
}
cons = NULL;
Expand Down Expand Up @@ -1237,7 +1236,7 @@ int main(int argc, char *argv[])
if (list_directors) {
LockRes();
foreach_res(dir, R_DIRECTOR) {
senditf("%s\n", dir->hdr.name);
senditf("%s\n", dir->name());
}
UnlockRes();
}
Expand Down Expand Up @@ -1266,7 +1265,7 @@ int main(int argc, char *argv[])
/*
* Generate passphrase prompt
*/
bsnprintf(errmsg, errmsg_len, "Passphrase for Console \"%s\" TLS private key: ", cons->hdr.name);
bsnprintf(errmsg, errmsg_len, "Passphrase for Console \"%s\" TLS private key: ", cons->name());

/*
* Initialize TLS context:
Expand All @@ -1285,7 +1284,7 @@ int main(int argc, char *argv[])
cons->tls_verify_peer);

if (!cons->tls_ctx) {
senditf(_("Failed to initialize TLS context for Console \"%s\".\n"), cons->hdr.name);
senditf(_("Failed to initialize TLS context for Console \"%s\".\n"), cons->name());
terminate_console(0);
return 1;
}
Expand All @@ -1301,7 +1300,7 @@ int main(int argc, char *argv[])
/*
* Generate passphrase prompt
*/
bsnprintf(errmsg, errmsg_len, "Passphrase for Director \"%s\" TLS private key: ", dir->hdr.name);
bsnprintf(errmsg, errmsg_len, "Passphrase for Director \"%s\" TLS private key: ", dir->name());

/*
* Initialize TLS context:
Expand All @@ -1319,7 +1318,7 @@ int main(int argc, char *argv[])
dir->tls_verify_peer);

if (!dir->tls_ctx) {
senditf(_("Failed to initialize TLS context for Director \"%s\".\n"), dir->hdr.name);
senditf(_("Failed to initialize TLS context for Director \"%s\".\n"), dir->name());
terminate_console(0);
return 1;
}
Expand Down Expand Up @@ -1348,7 +1347,7 @@ int main(int argc, char *argv[])
* If cons == NULL, default console will be used
*/
if (cons) {
name = cons->hdr.name;
name = cons->name();
ASSERT(cons->password.encoding == p_encoding_md5);
password = cons->password.value;
tls_ctx = cons->tls_ctx;
Expand Down Expand Up @@ -1491,7 +1490,7 @@ static int check_resources()
Emsg2(M_FATAL, 0, _("Neither \"TLS CA Certificate\""
" or \"TLS CA Certificate Dir\" are defined for Director \"%s\" in %s."
" At least one CA certificate store is required.\n"),
director->hdr.name, configfile);
director->name(), configfile);
OK = false;
}
}
Expand Down Expand Up @@ -1523,7 +1522,7 @@ static int check_resources()
if ((!cons->tls_ca_certfile && !cons->tls_ca_certdir) && tls_needed) {
Emsg2(M_FATAL, 0, _("Neither \"TLS CA Certificate\""
" or \"TLS CA Certificate Dir\" are defined for Console \"%s\" in %s.\n"),
cons->hdr.name, configfile);
cons->name(), configfile);
OK = false;
}
}
Expand Down
34 changes: 24 additions & 10 deletions src/console/console_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ void free_resource(RES *sres, int type)
}
}

/* Save the new resource by chaining it into the head list for
/*
* Save the new resource by chaining it into the head list for
* the resource. If this is pass 2, we update any resource
* pointers (currently only in the Job resource).
*/
Expand All @@ -278,24 +279,36 @@ void save_resource(int type, RES_ITEM *items, int pass)
}
}

/* During pass 2, we looked up pointers to all the resources
/*
* During pass 2, we looked up pointers to all the resources
* referrenced in the current resource, , now we
* must copy their address from the static record to the allocated
* record.
*/
if (pass == 2) {
switch (type) {
/* Resources not containing a resource */
case R_CONSOLE:
if ((res = (URES *)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_allowed_cns = res_all.res_cons.tls_allowed_cns;
}
break;
case R_DIRECTOR:
if ((res = (URES *)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_allowed_cns = res_all.res_dir.tls_allowed_cns;
}
break;

default:
Emsg1(M_ERROR, 0, _("Unknown resource type %d\n"), type);
error = 1;
break;
}
/* Note, the resoure name was already saved during pass 1,

/*
* Note, the resoure name was already saved during pass 1,
* so here, we can just release it.
*/
if (res_all.res_dir.hdr.name) {
Expand All @@ -309,7 +322,9 @@ void save_resource(int type, RES_ITEM *items, int pass)
return;
}

/* Common */
/*
* Common
*/
if (!error) {
res = (URES *)malloc(resources[rindex].size);
memcpy(res, &res_all, resources[rindex].size);
Expand All @@ -319,15 +334,14 @@ void save_resource(int type, RES_ITEM *items, int pass)
RES *next, *last;
for (last=next=res_head[rindex]; next; next=next->next) {
last = next;
if (bstrcmp(next->name, res->res_dir.hdr.name)) {
if (bstrcmp(next->name, res->res_dir.name())) {
Emsg2(M_ERROR_TERM, 0,
_("Attempt to define second %s resource named \"%s\" is not permitted.\n"),
resources[rindex].name, res->res_dir.hdr.name);
resources[rindex].name, res->res_dir.name());
}
}
last->next = (RES *)res;
Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type),
res->res_dir.hdr.name);
Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type), res->res_dir.name());
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/console/console_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ enum {
/* Definition of the contents of each Resource */

/* Console "globals" */
struct CONRES {
RES hdr;

class CONRES : public BRSRES {
public:
char *rc_file; /* startup file */
char *history_file; /* command history file */
s_password password; /* UA server password */
Expand All @@ -76,9 +75,8 @@ struct CONRES {
};

/* Director */
struct DIRRES {
RES hdr;

class DIRRES : public BRSRES {
public:
uint32_t DIRport; /* UA server port */
char *address; /* UA server address */
s_password password; /* UA server password */
Expand Down
64 changes: 32 additions & 32 deletions src/dird/dird_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2189,7 +2189,7 @@ void dump_resource(int type, RES *ures,
sendit(sock, "%s", buf.c_str());
break;
case R_CLIENT:
if (!ua || acl_access_ok(ua, Client_ACL, res->res_client.hdr.name)) {
if (!ua || acl_access_ok(ua, Client_ACL, res->res_client.name())) {
res->res_client.print_config(buf, hide_sensitive_data);
sendit(sock, "%s", buf.c_str());
}
Expand All @@ -2199,39 +2199,39 @@ void dump_resource(int type, RES *ures,
sendit(sock, "%s", buf.c_str());
break;
case R_STORAGE:
if (!ua || acl_access_ok(ua, Storage_ACL, res->res_store.hdr.name)) {
if (!ua || acl_access_ok(ua, Storage_ACL, res->res_store.name())) {
res->res_store.print_config(buf, hide_sensitive_data);
sendit(sock, "%s", buf.c_str());
}
break;
case R_CATALOG:
if (!ua || acl_access_ok(ua, Catalog_ACL, res->res_cat.hdr.name)) {
if (!ua || acl_access_ok(ua, Catalog_ACL, res->res_cat.name())) {
res->res_cat.print_config(buf, hide_sensitive_data);
sendit(sock, "%s", buf.c_str());
}
break;
case R_JOBDEFS:
case R_JOB:
if (!ua || acl_access_ok(ua, Job_ACL, res->res_job.hdr.name)) {
if (!ua || acl_access_ok(ua, Job_ACL, res->res_job.name())) {
res->res_job.print_config(buf, hide_sensitive_data);
sendit(sock, "%s", buf.c_str());
}
break;
case R_FILESET: {
if (!ua || acl_access_ok(ua, FileSet_ACL, res->res_fs.hdr.name)) {
if (!ua || acl_access_ok(ua, FileSet_ACL, res->res_fs.name())) {
res->res_fs.print_config(buf, hide_sensitive_data);
sendit(sock, "%s", buf.c_str());
}
break;
}
case R_SCHEDULE:
if (!ua || acl_access_ok(ua, Schedule_ACL, res->res_sch.hdr.name)) {
if (!ua || acl_access_ok(ua, Schedule_ACL, res->res_sch.name())) {
res->res_sch.print_config(buf, hide_sensitive_data);
sendit(sock, "%s", buf.c_str());
}
break;
case R_POOL:
if (!ua || acl_access_ok(ua, Pool_ACL, res->res_pool.hdr.name)) {
if (!ua || acl_access_ok(ua, Pool_ACL, res->res_pool.name())) {
res->res_pool.print_config(buf, hide_sensitive_data);
sendit(sock, "%s", buf.c_str());
}
Expand Down Expand Up @@ -2716,8 +2716,8 @@ void save_resource(int type, RES_ITEM *items, int pass)
*
* Find resource saved in pass 1
*/
if (!(res = (URES *)GetResWithName(R_POOL, res_all.res_con.hdr.name))) {
Emsg1(M_ERROR_TERM, 0, _("Cannot find Pool resource %s\n"), res_all.res_con.hdr.name);
if (!(res = (URES *)GetResWithName(R_POOL, res_all.res_pool.name()))) {
Emsg1(M_ERROR_TERM, 0, _("Cannot find Pool resource %s\n"), res_all.res_pool.name());
} else {
/*
* Explicitly copy resource pointers from this pass (res_all)
Expand All @@ -2732,16 +2732,16 @@ void save_resource(int type, RES_ITEM *items, int pass)
}
break;
case R_CONSOLE:
if (!(res = (URES *)GetResWithName(R_CONSOLE, res_all.res_con.hdr.name))) {
Emsg1(M_ERROR_TERM, 0, _("Cannot find Console resource %s\n"), res_all.res_con.hdr.name);
if (!(res = (URES *)GetResWithName(R_CONSOLE, res_all.res_con.name()))) {
Emsg1(M_ERROR_TERM, 0, _("Cannot find Console resource %s\n"), res_all.res_con.name());
} else {
res->res_con.tls_allowed_cns = res_all.res_con.tls_allowed_cns;
res->res_con.profiles = res_all.res_con.profiles;
}
break;
case R_DIRECTOR:
if (!(res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.hdr.name))) {
Emsg1(M_ERROR_TERM, 0, _("Cannot find Director resource %s\n"), res_all.res_dir.hdr.name);
if (!(res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.name()))) {
Emsg1(M_ERROR_TERM, 0, _("Cannot find Director resource %s\n"), res_all.res_dir.name());
} else {
res->res_dir.plugin_names = res_all.res_dir.plugin_names;
res->res_dir.messages = res_all.res_dir.messages;
Expand All @@ -2750,8 +2750,8 @@ void save_resource(int type, RES_ITEM *items, int pass)
}
break;
case R_STORAGE:
if (!(res = (URES *)GetResWithName(type, res_all.res_store.hdr.name))) {
Emsg1(M_ERROR_TERM, 0, _("Cannot find Storage resource %s\n"), res_all.res_dir.hdr.name);
if (!(res = (URES *)GetResWithName(type, res_all.res_store.name()))) {
Emsg1(M_ERROR_TERM, 0, _("Cannot find Storage resource %s\n"), res_all.res_dir.name());
} else {
res->res_store.paired_storage = res_all.res_store.paired_storage;

Expand All @@ -2763,8 +2763,8 @@ void save_resource(int type, RES_ITEM *items, int pass)
break;
case R_JOBDEFS:
case R_JOB:
if (!(res = (URES *)GetResWithName(type, res_all.res_dir.hdr.name))) {
Emsg1(M_ERROR_TERM, 0, _("Cannot find Job resource %s\n"), res_all.res_dir.hdr.name);
if (!(res = (URES *)GetResWithName(type, res_all.res_job.name()))) {
Emsg1(M_ERROR_TERM, 0, _("Cannot find Job resource %s\n"), res_all.res_job.name());
} else {
res->res_job.messages = res_all.res_job.messages;
res->res_job.schedule = res_all.res_job.schedule;
Expand Down Expand Up @@ -2817,16 +2817,16 @@ void save_resource(int type, RES_ITEM *items, int pass)
}
break;
case R_COUNTER:
if (!(res = (URES *)GetResWithName(R_COUNTER, res_all.res_counter.hdr.name))) {
Emsg1(M_ERROR_TERM, 0, _("Cannot find Counter resource %s\n"), res_all.res_counter.hdr.name);
if (!(res = (URES *)GetResWithName(R_COUNTER, res_all.res_counter.name()))) {
Emsg1(M_ERROR_TERM, 0, _("Cannot find Counter resource %s\n"), res_all.res_counter.name());
} else {
res->res_counter.Catalog = res_all.res_counter.Catalog;
res->res_counter.WrapCounter = res_all.res_counter.WrapCounter;
}
break;
case R_CLIENT:
if (!(res = (URES *)GetResWithName(R_CLIENT, res_all.res_client.hdr.name))) {
Emsg1(M_ERROR_TERM, 0, _("Cannot find Client resource %s\n"), res_all.res_client.hdr.name);
if (!(res = (URES *)GetResWithName(R_CLIENT, res_all.res_client.name()))) {
Emsg1(M_ERROR_TERM, 0, _("Cannot find Client resource %s\n"), res_all.res_client.name());
} else {
if (res_all.res_client.catalog) {
res->res_client.catalog = res_all.res_client.catalog;
Expand All @@ -2846,8 +2846,8 @@ void save_resource(int type, RES_ITEM *items, int pass)
* in by run_conf.c during pass 2, so here we jam the pointer
* into the Schedule resource.
*/
if (!(res = (URES *)GetResWithName(R_SCHEDULE, res_all.res_client.hdr.name))) {
Emsg1(M_ERROR_TERM, 0, _("Cannot find Schedule resource %s\n"), res_all.res_client.hdr.name);
if (!(res = (URES *)GetResWithName(R_SCHEDULE, res_all.res_client.name()))) {
Emsg1(M_ERROR_TERM, 0, _("Cannot find Schedule resource %s\n"), res_all.res_client.name());
} else {
res->res_sch.run = res_all.res_sch.run;
}
Expand Down Expand Up @@ -2884,10 +2884,10 @@ void save_resource(int type, RES_ITEM *items, int pass)
if (!res_head[rindex]) {
res_head[rindex] = (RES *)res; /* store first entry */
Dmsg3(900, "Inserting first %s res: %s index=%d\n", res_to_str(type),
res->res_dir.hdr.name, rindex);
res->res_dir.name(), rindex);
} else {
RES *next, *last;
if (!res->res_dir.hdr.name) {
if (!res->res_dir.name()) {
Emsg1(M_ERROR_TERM, 0, _("Name item is required in %s resource, but not found.\n"),
resources[rindex]);
}
Expand All @@ -2896,15 +2896,15 @@ void save_resource(int type, RES_ITEM *items, int pass)
*/
for (last = next = res_head[rindex]; next; next = next->next) {
last = next;
if (bstrcmp(next->name, res->res_dir.hdr.name)) {
if (bstrcmp(next->name, res->res_dir.name())) {
Emsg2(M_ERROR_TERM, 0,
_("Attempt to define second %s resource named \"%s\" is not permitted.\n"),
resources[rindex].name, res->res_dir.hdr.name);
resources[rindex].name, res->res_dir.name());
}
}
last->next = (RES *)res;
Dmsg4(900, _("Inserting %s res: %s index=%d pass=%d\n"), res_to_str(type),
res->res_dir.hdr.name, rindex, pass);
res->res_dir.name(), rindex, pass);
}
}
}
Expand Down Expand Up @@ -3067,8 +3067,8 @@ static void store_device(LEX *lc, RES_ITEM *item, int index, int pass)
memset(res, 0, resources[rindex].size);
res->res_dev.hdr.name = bstrdup(lc->str);
res_head[rindex] = (RES *)res; /* store first entry */
Dmsg3(900, "Inserting first %s res: %s index=%d\n", res_to_str(R_DEVICE),
res->res_dir.hdr.name, rindex);
Dmsg3(900, "Inserting first %s res: %s index=%d\n",
res_to_str(R_DEVICE), res->res_dir.name(), rindex);
} else {
RES *next;
/*
Expand All @@ -3085,8 +3085,8 @@ static void store_device(LEX *lc, RES_ITEM *item, int index, int pass)
memset(res, 0, resources[rindex].size);
res->res_dev.hdr.name = bstrdup(lc->str);
next->next = (RES *)res;
Dmsg4(900, "Inserting %s res: %s index=%d pass=%d\n", res_to_str(R_DEVICE),
res->res_dir.hdr.name, rindex, pass);
Dmsg4(900, "Inserting %s res: %s index=%d pass=%d\n",
res_to_str(R_DEVICE), res->res_dir.name(), rindex, pass);
}
}

Expand Down

0 comments on commit 18112f1

Please sign in to comment.