From 18112f177818be492725a1f5d17e5c9ccc396992 Mon Sep 17 00:00:00 2001 From: Marco van Wieringen Date: Sat, 20 Jun 2015 17:40:03 +0200 Subject: [PATCH] Switch programs to use config class derived from BRSRES --- src/console/console.c | 23 +++++----- src/console/console_conf.c | 34 ++++++++++----- src/console/console_conf.h | 10 ++--- src/dird/dird_conf.c | 64 ++++++++++++++-------------- src/filed/authenticate.c | 2 +- src/filed/dir_cmd.c | 2 +- src/filed/filed.c | 24 +++++------ src/filed/filed_conf.c | 14 +++--- src/filed/filed_conf.h | 10 ++--- src/filed/fileset.c | 2 +- src/qt-console/bat_conf.cpp | 7 ++- src/qt-console/bat_conf.h | 23 ++-------- src/qt-console/main.cpp | 4 +- src/qt-tray-monitor/authenticate.cpp | 6 +-- src/qt-tray-monitor/tray_conf.cpp | 12 +++--- src/qt-tray-monitor/tray_conf.h | 37 ++++++---------- src/stored/askdir.c | 6 +-- src/stored/authenticate.c | 2 +- src/stored/autochanger.c | 8 ++-- src/stored/bcopy.c | 2 +- src/stored/bextract.c | 2 +- src/stored/bls.c | 2 +- src/stored/bscan.c | 2 +- src/stored/btape.c | 2 +- src/stored/butil.c | 4 +- src/stored/dev.c | 6 +-- src/stored/dir_cmd.c | 16 +++---- src/stored/job.c | 6 +-- src/stored/reserve.c | 43 +++++++++---------- src/stored/sd_plugins.c | 4 +- src/stored/sd_stats.c | 4 +- src/stored/spool.c | 2 +- src/stored/status.c | 15 ++++--- src/stored/stored.c | 22 +++++----- src/stored/stored_conf.c | 21 +++++---- src/stored/stored_conf.h | 19 +++------ 36 files changed, 220 insertions(+), 242 deletions(-) diff --git a/src/console/console.c b/src/console/console.c index d4820132eb3..013214c69cc 100644 --- a/src/console/console.c +++ b/src/console/console.c @@ -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; } } @@ -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: "), @@ -1046,7 +1045,7 @@ static bool select_director(const char *director, DIRRES **ret_dir, CONRES **ret LockRes(); for (i=0; idirector && bstrcmp(cons->director, dir->hdr.name)) { + if (cons->director && bstrcmp(cons->director, dir->name())) { break; } cons = NULL; @@ -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(); } @@ -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: @@ -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; } @@ -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: @@ -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; } @@ -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; @@ -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; } } @@ -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; } } diff --git a/src/console/console_conf.c b/src/console/console_conf.c index 161cd380ff5..c1ed02525a6 100644 --- a/src/console/console_conf.c +++ b/src/console/console_conf.c @@ -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). */ @@ -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) { @@ -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); @@ -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()); } } } diff --git a/src/console/console_conf.h b/src/console/console_conf.h index 00830af980e..89e2d9a6189 100644 --- a/src/console/console_conf.h +++ b/src/console/console_conf.h @@ -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 */ @@ -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 */ diff --git a/src/dird/dird_conf.c b/src/dird/dird_conf.c index 3cb49941db6..5c53584fd4a 100644 --- a/src/dird/dird_conf.c +++ b/src/dird/dird_conf.c @@ -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()); } @@ -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()); } @@ -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) @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; } @@ -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]); } @@ -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); } } } @@ -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; /* @@ -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); } } diff --git a/src/filed/authenticate.c b/src/filed/authenticate.c index d164bf997c8..75c0831cff2 100644 --- a/src/filed/authenticate.c +++ b/src/filed/authenticate.c @@ -97,7 +97,7 @@ static inline bool two_way_authenticate(int rcode, BSOCK *bs, JCR* jcr) } unbash_spaces(dirname); foreach_res(director, R_DIRECTOR) { - if (bstrcmp(director->hdr.name, dirname)) + if (bstrcmp(director->name(), dirname)) break; } if (!director) { diff --git a/src/filed/dir_cmd.c b/src/filed/dir_cmd.c index b21e7b2764e..9dda0bd58fe 100644 --- a/src/filed/dir_cmd.c +++ b/src/filed/dir_cmd.c @@ -1191,7 +1191,7 @@ static bool bootstrap_cmd(JCR *jcr) free_bootstrap(jcr); P(bsr_mutex); bsr_uniq++; - Mmsg(fname, "%s/%s.%s.%d.bootstrap", me->working_directory, me->hdr.name, + Mmsg(fname, "%s/%s.%s.%d.bootstrap", me->working_directory, me->name(), jcr->Job, bsr_uniq); V(bsr_mutex); Dmsg1(400, "bootstrap=%s\n", fname); diff --git a/src/filed/filed.c b/src/filed/filed.c index fbf0a6be6af..fc770645ddf 100644 --- a/src/filed/filed.c +++ b/src/filed/filed.c @@ -358,7 +358,7 @@ static bool check_resources() configfile); OK = false; } - my_name_is(0, NULL, me->hdr.name); + my_name_is(0, NULL, me->name()); if (!me->messages) { me->messages = (MSGSRES *)GetNextRes(R_MSGS, NULL); if (!me->messages) { @@ -402,7 +402,7 @@ static bool check_resources() if (!me->tls_ctx) { Emsg2(M_FATAL, 0, _("Failed to initialize TLS context for File daemon \"%s\" in %s.\n"), - me->hdr.name, configfile); + me->name(), configfile); OK = false; } @@ -425,7 +425,7 @@ static bool check_resources() if ((me->pki_encrypt || me->pki_sign) && !me->pki_keypair_file) { Emsg2(M_FATAL, 0, _("\"PKI Key Pair\" must be defined for File" " daemon \"%s\" in %s if either \"PKI Sign\" or" - " \"PKI Encrypt\" are enabled.\n"), me->hdr.name, configfile); + " \"PKI Encrypt\" are enabled.\n"), me->name(), configfile); OK = false; } @@ -440,13 +440,13 @@ static bool check_resources() } else { if (!crypto_keypair_load_cert(me->pki_keypair, me->pki_keypair_file)) { Emsg2(M_FATAL, 0, _("Failed to load public certificate for File" - " daemon \"%s\" in %s.\n"), me->hdr.name, configfile); + " daemon \"%s\" in %s.\n"), me->name(), configfile); OK = false; } if (!crypto_keypair_load_key(me->pki_keypair, me->pki_keypair_file, NULL, NULL)) { Emsg2(M_FATAL, 0, _("Failed to load private key for File" - " daemon \"%s\" in %s.\n"), me->hdr.name, configfile); + " daemon \"%s\" in %s.\n"), me->name(), configfile); OK = false; } } @@ -476,14 +476,14 @@ static bool check_resources() if (crypto_keypair_has_key(filepath)) { if (!crypto_keypair_load_key(keypair, filepath, NULL, NULL)) { Emsg3(M_FATAL, 0, _("Failed to load private key from file %s for File" - " daemon \"%s\" in %s.\n"), filepath, me->hdr.name, configfile); + " daemon \"%s\" in %s.\n"), filepath, me->name(), configfile); OK = false; } } } else { Emsg3(M_FATAL, 0, _("Failed to load trusted signer certificate" - " from file %s for File daemon \"%s\" in %s.\n"), filepath, me->hdr.name, configfile); + " from file %s for File daemon \"%s\" in %s.\n"), filepath, me->name(), configfile); OK = false; } } @@ -514,7 +514,7 @@ static bool check_resources() me->pki_recipients->append(keypair); } else { Emsg3(M_FATAL, 0, _("Failed to load master key certificate" - " from file %s for File daemon \"%s\" in %s.\n"), filepath, me->hdr.name, configfile); + " from file %s for File daemon \"%s\" in %s.\n"), filepath, me->name(), configfile); OK = false; } } @@ -549,13 +549,13 @@ static bool check_resources() if (!director->tls_certfile && need_tls) { Emsg2(M_FATAL, 0, _("\"TLS Certificate\" file not defined for Director \"%s\" in %s.\n"), - director->hdr.name, configfile); + director->name(), configfile); OK = false; } if (!director->tls_keyfile && need_tls) { Emsg2(M_FATAL, 0, _("\"TLS Key\" file not defined for Director \"%s\" in %s.\n"), - director->hdr.name, configfile); + director->name(), configfile); OK = false; } @@ -564,7 +564,7 @@ static bool check_resources() " or \"TLS CA Certificate Dir\" are defined for Director \"%s\" in %s." " At least one CA certificate store is required" " when using \"TLS Verify Peer\".\n"), - director->hdr.name, configfile); + director->name(), configfile); OK = false; } @@ -586,7 +586,7 @@ static bool check_resources() if (!director->tls_ctx) { Emsg2(M_FATAL, 0, _("Failed to initialize TLS context for Director \"%s\" in %s.\n"), - director->hdr.name, configfile); + director->name(), configfile); OK = false; } diff --git a/src/filed/filed_conf.c b/src/filed/filed_conf.c index b76eed69d9b..900dcc9e3c4 100644 --- a/src/filed/filed_conf.c +++ b/src/filed/filed_conf.c @@ -425,8 +425,8 @@ void save_resource(int type, RES_ITEM *items, int pass) /* * Resources containing another resource */ - if ((res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.hdr.name)) == NULL) { - Emsg1(M_ABORT, 0, _("Cannot find Director resource %s\n"), res_all.res_dir.hdr.name); + 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; res->res_dir.allowed_script_dirs = res_all.res_dir.allowed_script_dirs; @@ -434,8 +434,8 @@ void save_resource(int type, RES_ITEM *items, int pass) } break; case R_CLIENT: - if ((res = (URES *)GetResWithName(R_CLIENT, res_all.res_dir.hdr.name)) == NULL) { - Emsg1(M_ABORT, 0, _("Cannot find Client resource %s\n"), res_all.res_dir.hdr.name); + if ((res = (URES *)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; res->res_client.pki_signing_key_files = res_all.res_client.pki_signing_key_files; @@ -483,15 +483,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; Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type), - res->res_dir.hdr.name); + res->res_dir.name()); } } } diff --git a/src/filed/filed_conf.h b/src/filed/filed_conf.h index caa1612d3e4..1ee91441e53 100644 --- a/src/filed/filed_conf.h +++ b/src/filed/filed_conf.h @@ -48,9 +48,8 @@ enum { }; /* Definition of the contents of each Resource */ -struct DIRRES { - RES hdr; - +class DIRRES : public BRSRES { +public: s_password password; /* Director password */ char *address; /* Director address or zero */ bool monitor; /* Have only access to status and .status functions */ @@ -72,9 +71,8 @@ struct DIRRES { TLS_CONTEXT *tls_ctx; /* Shared TLS Context */ }; -struct CLIENTRES { - RES hdr; - +class CLIENTRES : public BRSRES { +public: dlist *FDaddrs; dlist *FDsrc_addr; /* Address to source connections from */ char *working_directory; diff --git a/src/filed/fileset.c b/src/filed/fileset.c index 6e4a3cfa86f..554569be75f 100644 --- a/src/filed/fileset.c +++ b/src/filed/fileset.c @@ -40,7 +40,7 @@ extern "C" char *job_code_callback_filed(JCR *jcr, const char* param) switch (param[0]) { case 'D': if (jcr->director) { - return jcr->director->hdr.name; + return jcr->director->name(); } break; } diff --git a/src/qt-console/bat_conf.cpp b/src/qt-console/bat_conf.cpp index fb1d2faa378..dfbaf379dae 100644 --- a/src/qt-console/bat_conf.cpp +++ b/src/qt-console/bat_conf.cpp @@ -346,15 +346,14 @@ void save_resource(int type, RES_ITEM *items, int pass) */ for (last=next=res_head[rindex]; next; next=next->next) { last = next; - if (strcmp(next->name, res->dir_res.hdr.name) == 0) { + if (strcmp(next->name, res->dir_res.name()) == 0) { Emsg2(M_ERROR_TERM, 0, _("Attempt to define second %s resource named \"%s\" is not permitted.\n"), - resources[rindex].name, res->dir_res.hdr.name); + resources[rindex].name, res->dir_res.name()); } } last->next = (RES *)res; - Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type), - res->dir_res.hdr.name); + Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type), res->dir_res.name()); } } } diff --git a/src/qt-console/bat_conf.h b/src/qt-console/bat_conf.h index d30f68ed1bf..d0f14988e17 100644 --- a/src/qt-console/bat_conf.h +++ b/src/qt-console/bat_conf.h @@ -48,11 +48,9 @@ enum { R_BACKUP }; - /* Definition of the contents of each Resource */ -class DIRRES { +class DIRRES : public BRSRES { public: - RES hdr; uint32_t DIRport; /* UA server port */ char *address; /* UA server address */ s_password password; /* UA server password */ @@ -70,22 +68,15 @@ class DIRRES { utime_t heartbeat_interval; /* Dir heartbeat interval */ TLS_CONTEXT *tls_ctx; /* Shared TLS Context */ - - /* Methods */ - char *name() const; }; -inline char *DIRRES::name() const { return hdr.name; } - - -struct CONFONTRES { - RES hdr; +class CONFONTRES : public BRSRES { +public: char *fontface; /* Console Font specification */ }; -class CONRES { +class CONRES : public BRSRES { public: - RES hdr; s_password password; /* UA server password */ bool tls_authenticate; /* Authenticate with tls */ bool tls_enable; /* Enable TLS on all connections */ @@ -101,14 +92,8 @@ class CONRES { utime_t heartbeat_interval; /* Cons heartbeat interval */ TLS_CONTEXT *tls_ctx; /* Shared TLS Context */ - - /* Methods */ - char *name() const; }; -inline char *CONRES::name() const { return hdr.name; } - - /* Define the Union of all the above * resource structure definitions. */ diff --git a/src/qt-console/main.cpp b/src/qt-console/main.cpp index b64137f7e77..aac33cc043f 100644 --- a/src/qt-console/main.cpp +++ b/src/qt-console/main.cpp @@ -222,7 +222,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; } } @@ -251,7 +251,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; } } diff --git a/src/qt-tray-monitor/authenticate.cpp b/src/qt-tray-monitor/authenticate.cpp index 35a28589812..de02eb981f6 100644 --- a/src/qt-tray-monitor/authenticate.cpp +++ b/src/qt-tray-monitor/authenticate.cpp @@ -62,7 +62,7 @@ static bool authenticate_director(JCR *jcr) bool compatible = true; char bashed_name[MAX_NAME_LENGTH]; - bstrncpy(bashed_name, monitor->hdr.name, sizeof(bashed_name)); + bstrncpy(bashed_name, monitor->name(), sizeof(bashed_name)); bash_spaces(bashed_name); /* @@ -118,7 +118,7 @@ static bool authenticate_storage_daemon(JCR *jcr, STORERES* store) /* * Send my name to the Storage daemon then do authentication */ - bstrncpy(dirname, monitor->hdr.name, sizeof(dirname)); + bstrncpy(dirname, monitor->name(), sizeof(dirname)); bash_spaces(dirname); /* @@ -175,7 +175,7 @@ static bool authenticate_file_daemon(JCR *jcr, CLIENTRES* client) /* * Send my name to the File daemon then do authentication */ - bstrncpy(dirname, monitor->hdr.name, sizeof(dirname)); + bstrncpy(dirname, monitor->name(), sizeof(dirname)); bash_spaces(dirname); /* diff --git a/src/qt-tray-monitor/tray_conf.cpp b/src/qt-tray-monitor/tray_conf.cpp index 71f9b832557..686579e449a 100644 --- a/src/qt-tray-monitor/tray_conf.cpp +++ b/src/qt-tray-monitor/tray_conf.cpp @@ -337,8 +337,8 @@ void save_resource(int type, RES_ITEM *items, int pass) memcpy(res, &res_all, resources[rindex].size); 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_monitor.hdr.name, rindex); + Dmsg3(900, "Inserting first %s res: %s index=%d\n", + res_to_str(type), res->res_monitor.name(), rindex); } else { RES *next, *last; /* @@ -346,15 +346,15 @@ void save_resource(int type, RES_ITEM *items, int pass) */ for (last = next = res_head[rindex]; next; next=next->next) { last = next; - if (strcmp(next->name, res->res_monitor.hdr.name) == 0) { + if (strcmp(next->name, res->res_monitor.name()) == 0) { Emsg2(M_ERROR_TERM, 0, _("Attempt to define second %s resource named \"%s\" is not permitted.\n"), - resources[rindex].name, res->res_monitor.hdr.name); + resources[rindex].name, res->res_monitor.name()); } } last->next = (RES *)res; - Dmsg4(900, "Inserting %s res: %s index=%d pass=%d\n", res_to_str(type), - res->res_monitor.hdr.name, rindex, pass); + Dmsg4(900, "Inserting %s res: %s index=%d pass=%d\n", + res_to_str(type), res->res_monitor.name(), rindex, pass); } } } diff --git a/src/qt-tray-monitor/tray_conf.h b/src/qt-tray-monitor/tray_conf.h index 72905b98cb6..b529c0fbf28 100644 --- a/src/qt-tray-monitor/tray_conf.h +++ b/src/qt-tray-monitor/tray_conf.h @@ -58,24 +58,20 @@ enum { }; /* - * Director Resource - * + * Director Resource */ -struct DIRRES { - RES hdr; - +class DIRRES : public BRSRES { +public: uint32_t DIRport; /* UA server port */ char *address; /* UA server address */ bool enable_ssl; /* Use SSL */ }; /* - * Tray Monitor Resource - * + * Tray Monitor Resource */ -struct MONITORRES { - RES hdr; - +class MONITORRES : public BRSRES { +public: bool require_ssl; /* Require SSL for all connections */ MSGSRES *messages; /* Daemon message handler */ s_password password; /* UA server password */ @@ -86,12 +82,10 @@ struct MONITORRES { }; /* - * Client Resource - * + * Client Resource */ -struct CLIENTRES { - RES hdr; - +class CLIENTRES : public BRSRES { +public: uint32_t FDport; /* Where File daemon listens */ char *address; s_password password; @@ -99,21 +93,18 @@ struct CLIENTRES { }; /* - * Store Resource - * + * Store Resource */ -struct STORERES { - RES hdr; - +class STORERES : public BRSRES { +public: uint32_t SDport; /* port where Directors connect */ char *address; s_password password; bool enable_ssl; /* Use SSL */ }; -struct CONFONTRES { - RES hdr; - +class CONFONTRES : public BRSRES { +public: char *fontface; /* Console Font specification */ }; diff --git a/src/stored/askdir.c b/src/stored/askdir.c index e1737a23934..8ccef7fbe77 100644 --- a/src/stored/askdir.c +++ b/src/stored/askdir.c @@ -83,7 +83,7 @@ bool SD_DCR::dir_update_device(JCR *jcr, DEVICE *dev) DEVRES *device = dev->device; bool ok; - pm_strcpy(dev_name, device->hdr.name); + pm_strcpy(dev_name, device->name()); bash_spaces(dev_name); if (dev->is_labeled()) { pm_strcpy(VolumeName, dev->VolHdr.VolumeName); @@ -94,7 +94,7 @@ bool SD_DCR::dir_update_device(JCR *jcr, DEVICE *dev) pm_strcpy(MediaType, device->media_type); bash_spaces(MediaType); if (device->changer_res) { - pm_strcpy(ChangerName, device->changer_res->hdr.name); + pm_strcpy(ChangerName, device->changer_res->name()); bash_spaces(ChangerName); } else { pm_strcpy(ChangerName, "*"); @@ -121,7 +121,7 @@ bool SD_DCR::dir_update_changer(JCR *jcr, AUTOCHANGER *changer) DEVRES *device; bool ok; - pm_strcpy(dev_name, changer->hdr.name); + pm_strcpy(dev_name, changer->name()); bash_spaces(dev_name); device = (DEVRES *)changer->device->first(); pm_strcpy(MediaType, device->media_type); diff --git a/src/stored/authenticate.c b/src/stored/authenticate.c index 87f15ef8729..adc929b28ee 100644 --- a/src/stored/authenticate.c +++ b/src/stored/authenticate.c @@ -80,7 +80,7 @@ static inline bool two_way_authenticate(int rcode, BSOCK *bs, JCR* jcr) director = NULL; unbash_spaces(dirname); foreach_res(director, rcode) { - if (bstrcmp(director->hdr.name, dirname)) { + if (bstrcmp(director->name(), dirname)) { break; } } diff --git a/src/stored/autochanger.c b/src/stored/autochanger.c index f2728dab8e3..eccc41e0ae0 100644 --- a/src/stored/autochanger.c +++ b/src/stored/autochanger.c @@ -58,13 +58,13 @@ bool init_autochangers() if (!device->changer_name) { Jmsg(NULL, M_ERROR, 0, _("No Changer Name given for device %s. Cannot continue.\n"), - device->hdr.name); + device->name()); OK = false; } if (!device->changer_command) { Jmsg(NULL, M_ERROR, 0, _("No Changer Command given for device %s. Cannot continue.\n"), - device->hdr.name); + device->name()); OK = false; } } @@ -323,7 +323,7 @@ static void lock_changer(DCR *dcr) AUTOCHANGERRES *changer_res = dcr->device->changer_res; if (changer_res) { int errstat; - Dmsg1(200, "Locking changer %s\n", changer_res->hdr.name); + Dmsg1(200, "Locking changer %s\n", changer_res->name()); if ((errstat=rwl_writelock(&changer_res->changer_lock)) != 0) { berrno be; Jmsg(dcr->jcr, M_ERROR_TERM, 0, _("Lock failure on autochanger. ERR=%s\n"), @@ -337,7 +337,7 @@ static void unlock_changer(DCR *dcr) AUTOCHANGERRES *changer_res = dcr->device->changer_res; if (changer_res) { int errstat; - Dmsg1(200, "Unlocking changer %s\n", changer_res->hdr.name); + Dmsg1(200, "Unlocking changer %s\n", changer_res->name()); if ((errstat=rwl_writeunlock(&changer_res->changer_lock)) != 0) { berrno be; Jmsg(dcr->jcr, M_ERROR_TERM, 0, _("Unlock failure on autochanger. ERR=%s\n"), diff --git a/src/stored/bcopy.c b/src/stored/bcopy.c index 44a630ff623..d00d9d3b0ee 100644 --- a/src/stored/bcopy.c +++ b/src/stored/bcopy.c @@ -173,7 +173,7 @@ int main (int argc, char *argv[]) if (DirectorName) { foreach_res(director, R_DIRECTOR) { - if (bstrcmp(director->hdr.name, DirectorName)) { + if (bstrcmp(director->name(), DirectorName)) { break; } } diff --git a/src/stored/bextract.c b/src/stored/bextract.c index 6cad5dc718f..25c29184d47 100644 --- a/src/stored/bextract.c +++ b/src/stored/bextract.c @@ -205,7 +205,7 @@ int main (int argc, char *argv[]) if (DirectorName) { foreach_res(director, R_DIRECTOR) { - if (bstrcmp(director->hdr.name, DirectorName)) { + if (bstrcmp(director->name(), DirectorName)) { break; } } diff --git a/src/stored/bls.c b/src/stored/bls.c index 93ac452064b..242bd05dd35 100644 --- a/src/stored/bls.c +++ b/src/stored/bls.c @@ -216,7 +216,7 @@ int main (int argc, char *argv[]) if (DirectorName) { foreach_res(director, R_DIRECTOR) { - if (bstrcmp(director->hdr.name, DirectorName)) { + if (bstrcmp(director->name(), DirectorName)) { break; } } diff --git a/src/stored/bscan.c b/src/stored/bscan.c index 7e61dee9e0d..e7b82669139 100644 --- a/src/stored/bscan.c +++ b/src/stored/bscan.c @@ -268,7 +268,7 @@ int main (int argc, char *argv[]) if (DirectorName) { foreach_res(director, R_DIRECTOR) { - if (bstrcmp(director->hdr.name, DirectorName)) { + if (bstrcmp(director->name(), DirectorName)) { break; } } diff --git a/src/stored/btape.c b/src/stored/btape.c index 52629a47443..a6f651ff8bd 100644 --- a/src/stored/btape.c +++ b/src/stored/btape.c @@ -264,7 +264,7 @@ int main(int margc, char *margv[]) if (DirectorName) { foreach_res(director, R_DIRECTOR) { - if (bstrcmp(director->hdr.name, DirectorName)) { + if (bstrcmp(director->name(), DirectorName)) { break; } } diff --git a/src/stored/butil.c b/src/stored/butil.c index 35ff91c67a5..b556e2c4bf6 100644 --- a/src/stored/butil.c +++ b/src/stored/butil.c @@ -252,8 +252,8 @@ static DEVRES *find_device_res(char *device_name, bool readonly) } } foreach_res(device, R_DEVICE) { - Dmsg2(900, "Compare %s and %s\n", device->hdr.name, device_name); - if (bstrcmp(device->hdr.name, device_name)) { + Dmsg2(900, "Compare %s and %s\n", device->name(), device_name); + if (bstrcmp(device->name(), device_name)) { found = true; break; } diff --git a/src/stored/dev.c b/src/stored/dev.c index cdd8589f849..a15c64dc587 100644 --- a/src/stored/dev.c +++ b/src/stored/dev.c @@ -249,12 +249,12 @@ static inline DEVICE *m_init_dev(JCR *jcr, DEVRES *device, bool new_init) dev->dev_options = get_memory(strlen(device->device_options) + 1); pm_strcpy(dev->dev_options, device->device_options); } - dev->prt_name = get_memory(strlen(device->device_name) + strlen(device->hdr.name) + 20); + dev->prt_name = get_memory(strlen(device->device_name) + strlen(device->name()) + 20); /* * We edit "Resource-name" (physical-name) */ - Mmsg(dev->prt_name, "\"%s\" (%s)", device->hdr.name, device->device_name); + Mmsg(dev->prt_name, "\"%s\" (%s)", device->name(), device->device_name); Dmsg1(400, "Allocate dev=%s\n", dev->print_name()); copy_bits(CAP_MAX, device->cap_bits, dev->capabilities); @@ -1187,7 +1187,7 @@ ssize_t DEVICE::write(const void *buf, size_t len) */ const char *DEVICE::name() const { - return device->hdr.name; + return device->name(); } /* diff --git a/src/stored/dir_cmd.c b/src/stored/dir_cmd.c index d4109c72dad..e7238f7ab03 100644 --- a/src/stored/dir_cmd.c +++ b/src/stored/dir_cmd.c @@ -791,7 +791,7 @@ static DCR *find_device(JCR *jcr, POOL_MEM &devname, int drive, BLOCKSIZES *bloc unbash_spaces(devname); foreach_res(device, R_DEVICE) { /* Find resource, and make sure we were able to open it */ - if (bstrcmp(device->hdr.name, devname.c_str())) { + if (bstrcmp(device->name(), devname.c_str())) { if (!device->dev) { device->dev = init_dev(jcr, device); } @@ -801,7 +801,7 @@ static DCR *find_device(JCR *jcr, POOL_MEM &devname, int drive, BLOCKSIZES *bloc devname.c_str()); continue; } - Dmsg1(20, "Found device %s\n", device->hdr.name); + Dmsg1(20, "Found device %s\n", device->name()); found = true; break; } @@ -809,10 +809,10 @@ static DCR *find_device(JCR *jcr, POOL_MEM &devname, int drive, BLOCKSIZES *bloc if (!found) { foreach_res(changer, R_AUTOCHANGER) { /* Find resource, and make sure we were able to open it */ - if (bstrcmp(devname.c_str(), changer->hdr.name)) { + if (bstrcmp(devname.c_str(), changer->name())) { /* Try each device in this AutoChanger */ foreach_alist(device, changer->device) { - Dmsg1(100, "Try changer device %s\n", device->hdr.name); + Dmsg1(100, "Try changer device %s\n", device->name()); if (!device->dev) { device->dev = init_dev(jcr, device); } @@ -820,7 +820,7 @@ static DCR *find_device(JCR *jcr, POOL_MEM &devname, int drive, BLOCKSIZES *bloc Dmsg1(100, "Device %s could not be opened. Skipped\n", devname.c_str()); Jmsg(jcr, M_WARNING, 0, _("\n" " Device \"%s\" in changer \"%s\" requested by DIR could not be opened or does not exist.\n"), - device->hdr.name, devname.c_str()); + device->name(), devname.c_str()); continue; } if (!device->dev->autoselect) { @@ -828,7 +828,7 @@ static DCR *find_device(JCR *jcr, POOL_MEM &devname, int drive, BLOCKSIZES *bloc continue; /* device is not available */ } if (drive < 0 || drive == (int)device->dev->drive_index) { - Dmsg1(20, "Found changer device %s\n", device->hdr.name); + Dmsg1(20, "Found changer device %s\n", device->name()); found = true; break; } @@ -841,7 +841,7 @@ static DCR *find_device(JCR *jcr, POOL_MEM &devname, int drive, BLOCKSIZES *bloc } if (found) { - Dmsg1(100, "Found device %s\n", device->hdr.name); + Dmsg1(100, "Found device %s\n", device->name()); dcr = New(SD_DCR); setup_new_dcr_device(jcr, dcr, device->dev, blocksizes); dcr->set_will_write(); @@ -1208,7 +1208,7 @@ static inline bool get_bootstrap_file(JCR *jcr, BSOCK *sock) } P(bsr_mutex); bsr_uniq++; - Mmsg(fname, "%s/%s.%s.%d.bootstrap", me->working_directory, me->hdr.name, + Mmsg(fname, "%s/%s.%s.%d.bootstrap", me->working_directory, me->name(), jcr->Job, bsr_uniq); V(bsr_mutex); Dmsg1(400, "bootstrap=%s\n", fname); diff --git a/src/stored/job.c b/src/stored/job.c index 90aaf749d20..1d924bc9993 100644 --- a/src/stored/job.c +++ b/src/stored/job.c @@ -401,7 +401,7 @@ bool query_cmd(JCR *jcr) unbash_spaces(dev_name); foreach_res(device, R_DEVICE) { /* Find resource, and make sure we were able to open it */ - if (bstrcmp(dev_name.c_str(), device->hdr.name)) { + if (bstrcmp(dev_name.c_str(), device->name())) { if (!device->dev) { device->dev = init_dev(jcr, device); } @@ -418,8 +418,8 @@ bool query_cmd(JCR *jcr) } } foreach_res(changer, R_AUTOCHANGER) { - /* Find resource, and make sure we were able to open it */ - if (bstrcmp(dev_name.c_str(), changer->hdr.name)) { + /*Find resource, and make sure we were able to open it */ + if (bstrcmp(dev_name.c_str(), changer->name())) { if (!changer->device || changer->device->size() == 0) { continue; /* no devices */ } diff --git a/src/stored/reserve.c b/src/stored/reserve.c index 5ae62704bda..a1106b69a62 100644 --- a/src/stored/reserve.c +++ b/src/stored/reserve.c @@ -399,11 +399,11 @@ static bool is_vol_in_autochanger(RCTX &rctx, VOLRES *vol) /* * Find resource, and make sure we were able to open it */ - if (bstrcmp(rctx.device_name, changer->hdr.name)) { - Dmsg1(dbglvl, "Found changer device %s\n", vol->dev->device->hdr.name); + if (bstrcmp(rctx.device_name, changer->name())) { + Dmsg1(dbglvl, "Found changer device %s\n", vol->dev->device->name()); return true; } - Dmsg1(dbglvl, "Incorrect changer device %s\n", changer->hdr.name); + Dmsg1(dbglvl, "Incorrect changer device %s\n", changer->name()); return false; } @@ -469,9 +469,9 @@ bool find_suitable_device_for_job(JCR *jcr, RCTX &rctx) if (!is_vol_in_autochanger(rctx, vol) || !vol->dev->autoselect) { continue; } - } else if (!bstrcmp(device_name, vol->dev->device->hdr.name)) { + } else if (!bstrcmp(device_name, vol->dev->device->name())) { Dmsg2(dbglvl, "device=%s not suitable want %s\n", - vol->dev->device->hdr.name, device_name); + vol->dev->device->name(), device_name); continue; } @@ -559,19 +559,18 @@ int search_res_for_device(RCTX &rctx) */ foreach_res(changer, R_AUTOCHANGER) { Dmsg2(dbglvl, "Try match changer res=%s, wanted %s\n", - changer->hdr.name, rctx.device_name); + changer->name(), rctx.device_name); /* * Find resource, and make sure we were able to open it */ - if (bstrcmp(rctx.device_name, changer->hdr.name)) { + if (bstrcmp(rctx.device_name, changer->name())) { /* * Try each device in this AutoChanger */ foreach_alist(rctx.device, changer->device) { - Dmsg1(dbglvl, "Try changer device %s\n", rctx.device->hdr.name); + Dmsg1(dbglvl, "Try changer device %s\n", rctx.device->name()); if (!rctx.device->autoselect) { - Dmsg1(100, "Device %s not autoselect skipped.\n", - rctx.device->hdr.name); + Dmsg1(100, "Device %s not autoselect skipped.\n", rctx.device->name()); continue; /* Device is not available */ } status = reserve_device(rctx); @@ -584,10 +583,10 @@ int search_res_for_device(RCTX &rctx) */ if (rctx.store->append == SD_APPEND) { Dmsg2(dbglvl, "Device %s reserved=%d for append.\n", - rctx.device->hdr.name, rctx.jcr->dcr->dev->num_reserved()); + rctx.device->name(), rctx.jcr->dcr->dev->num_reserved()); } else { Dmsg2(dbglvl, "Device %s reserved=%d for read.\n", - rctx.device->hdr.name, rctx.jcr->read_dcr->dev->num_reserved()); + rctx.device->name(), rctx.jcr->read_dcr->dev->num_reserved()); } return status; } @@ -600,12 +599,12 @@ int search_res_for_device(RCTX &rctx) if (!rctx.autochanger_only) { foreach_res(rctx.device, R_DEVICE) { Dmsg2(dbglvl, "Try match res=%s wanted %s\n", - rctx.device->hdr.name, rctx.device_name); + rctx.device->name(), rctx.device_name); /* * Find resource, and make sure we were able to open it */ - if (bstrcmp(rctx.device_name, rctx.device->hdr.name)) { + if (bstrcmp(rctx.device_name, rctx.device->name())) { status = reserve_device(rctx); if (status != 1) { /* Try another device */ continue; @@ -615,10 +614,10 @@ int search_res_for_device(RCTX &rctx) */ if (rctx.store->append == SD_APPEND) { Dmsg2(dbglvl, "Device %s reserved=%d for append.\n", - rctx.device->hdr.name, rctx.jcr->dcr->dev->num_reserved()); + rctx.device->name(), rctx.jcr->dcr->dev->num_reserved()); } else { Dmsg2(dbglvl, "Device %s reserved=%d for read.\n", - rctx.device->hdr.name, rctx.jcr->read_dcr->dev->num_reserved()); + rctx.device->name(), rctx.jcr->read_dcr->dev->num_reserved()); } return status; } @@ -631,7 +630,7 @@ int search_res_for_device(RCTX &rctx) if (me->device_reserve_by_mediatype) { foreach_res(rctx.device, R_DEVICE) { Dmsg3(dbglvl, "Try match res=%s, mediatype=%s wanted mediatype=%s\n", - rctx.device->hdr.name, rctx.store->media_type, rctx.store->media_type); + rctx.device->name(), rctx.store->media_type, rctx.store->media_type); if (bstrcmp(rctx.store->media_type, rctx.device->media_type)) { status = reserve_device(rctx); @@ -644,10 +643,10 @@ int search_res_for_device(RCTX &rctx) */ if (rctx.store->append == SD_APPEND) { Dmsg2(dbglvl, "Device %s reserved=%d for append.\n", - rctx.device->hdr.name, rctx.jcr->dcr->dev->num_reserved()); + rctx.device->name(), rctx.jcr->dcr->dev->num_reserved()); } else { Dmsg2(dbglvl, "Device %s reserved=%d for read.\n", - rctx.device->hdr.name, rctx.jcr->read_dcr->dev->num_reserved()); + rctx.device->name(), rctx.jcr->read_dcr->dev->num_reserved()); } return status; } @@ -686,7 +685,7 @@ static int reserve_device(RCTX &rctx) if (rctx.device->changer_res) { Jmsg(rctx.jcr, M_WARNING, 0, _("\n" " Device \"%s\" in changer \"%s\" requested by DIR could not be opened or does not exist.\n"), - rctx.device->hdr.name, rctx.device_name); + rctx.device->name(), rctx.device_name); } else { Jmsg(rctx.jcr, M_WARNING, 0, _("\n" " Device \"%s\" requested by DIR could not be opened or does not exist.\n"), @@ -696,7 +695,7 @@ static int reserve_device(RCTX &rctx) } rctx.suitable_device = true; - Dmsg1(dbglvl, "try reserve %s\n", rctx.device->hdr.name); + Dmsg1(dbglvl, "try reserve %s\n", rctx.device->name()); if (rctx.store->append) { setup_new_dcr_device(rctx.jcr, rctx.jcr->dcr, rctx.device->dev, NULL); @@ -803,7 +802,7 @@ static int reserve_device(RCTX &rctx) if (rctx.notify_dir) { POOL_MEM dev_name; BSOCK *dir = rctx.jcr->dir_bsock; - pm_strcpy(dev_name, rctx.device->hdr.name); + pm_strcpy(dev_name, rctx.device->name()); bash_spaces(dev_name); ok = dir->fsend(OK_device, dev_name.c_str()); /* Return real device name */ Dmsg1(dbglvl, ">dird: %s", dir->msg); diff --git a/src/stored/sd_plugins.c b/src/stored/sd_plugins.c index 7cd950f45d3..2bb78dd3b46 100644 --- a/src/stored/sd_plugins.c +++ b/src/stored/sd_plugins.c @@ -668,7 +668,7 @@ static bRC bareosGetValue(bpContext *ctx, bsdrVariable var, void *value) break; case bsdVarStorage: if (jcr->dcr && jcr->dcr->device) { - *((char **)value) = jcr->dcr->device->hdr.name; + *((char **)value) = jcr->dcr->device->name(); Dmsg1(dbglvl, "sd-plugin: return bsdVarStorage=%s\n", NPRT(*((char **)value))); } else { ret = bRC_Error; @@ -826,7 +826,7 @@ static void bareosUpdateTapeAlert(DCR *dcr, uint64_t flags) utime_t now; now = (utime_t)time(NULL); - update_device_tapealert(dcr->device->hdr.name, flags, now); + update_device_tapealert(dcr->device->name(), flags, now); } static DEV_RECORD *bareosNewRecord(bool with_data) diff --git a/src/stored/sd_stats.c b/src/stored/sd_stats.c index 5b25f633790..9f0d6f432b1 100644 --- a/src/stored/sd_stats.c +++ b/src/stored/sd_stats.c @@ -293,7 +293,7 @@ void update_job_statistics(JCR *jcr, utime_t now) job_stat->JobFiles = jcr->JobFiles; job_stat->JobBytes = jcr->JobBytes; if (jcr->dcr) { - job_stat->DevName = bstrdup(jcr->dcr->device->hdr.name); + job_stat->DevName = bstrdup(jcr->dcr->device->name()); } else { job_stat->DevName = bstrdup("unknown"); } @@ -371,7 +371,7 @@ void *statistics_thread_runner(void *arg) dev = device->dev; if (dev && dev->initiated) { - update_device_statistics(device->hdr.name, dev, now); + update_device_statistics(device->name(), dev, now); } } } diff --git a/src/stored/spool.c b/src/stored/spool.c index 91c49cc538f..431593b9d98 100644 --- a/src/stored/spool.c +++ b/src/stored/spool.c @@ -146,7 +146,7 @@ static void make_unique_data_spool_filename(DCR *dcr, POOLMEM **name) dir = working_directory; } Mmsg(name, "%s/%s.data.%u.%s.%s.spool", dir, my_name, dcr->jcr->JobId, - dcr->jcr->Job, dcr->device->hdr.name); + dcr->jcr->Job, dcr->device->name()); } diff --git a/src/stored/status.c b/src/stored/status.c index 8d5a9c0e1ad..d7552ce23e4 100644 --- a/src/stored/status.c +++ b/src/stored/status.c @@ -135,15 +135,20 @@ static void list_resources(STATUS_PKT *sp) #ifdef xxxx static find_device(char *devname) { + bool found; + DEVRES *device; + AUTOCHANGERRES *changer; + foreach_res(device, R_DEVICE) { - if (strcasecmp(device->hdr.name, devname) == 0) { + if (strcasecmp(device->name(), devname) == 0) { found = true; break; } } + if (!found) { foreach_res(changer, R_AUTOCHANGER) { - if (strcasecmp(changer->hdr.name, devname) == 0) { + if (strcasecmp(changer->name(), devname) == 0) { break; } } @@ -167,7 +172,7 @@ static void list_devices(JCR *jcr, STATUS_PKT *sp) } foreach_res(changer, R_AUTOCHANGER) { - len = Mmsg(msg, _("Autochanger \"%s\" with devices:\n"), changer->hdr.name); + len = Mmsg(msg, _("Autochanger \"%s\" with devices:\n"), changer->name()); sendit(msg, len, sp); foreach_alist(device, changer->device) { @@ -175,7 +180,7 @@ static void list_devices(JCR *jcr, STATUS_PKT *sp) len = Mmsg(msg, " %s\n", device->dev->print_name()); sendit(msg, len, sp); } else { - len = Mmsg(msg, " %s\n", device->hdr.name); + len = Mmsg(msg, " %s\n", device->name()); sendit(msg, len, sp); } } @@ -265,7 +270,7 @@ static void list_devices(JCR *jcr, STATUS_PKT *sp) sendit(msg, len, sp); send_blocked_status(dev, sp); } else { - len = Mmsg(msg, _("\nDevice \"%s\" is not open or does not exist.\n"), device->hdr.name); + len = Mmsg(msg, _("\nDevice \"%s\" is not open or does not exist.\n"), device->name()); sendit(msg, len, sp); } } diff --git a/src/stored/stored.c b/src/stored/stored.c index 45b4b6e0f0c..787f6d1caa9 100644 --- a/src/stored/stored.c +++ b/src/stored/stored.c @@ -3,7 +3,7 @@ Copyright (C) 2000-2012 Free Software Foundation Europe e.V. Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2014 Bareos GmbH & Co. KG + Copyright (C) 2013-2015 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -256,7 +256,7 @@ int main (int argc, char *argv[]) terminate_stored(0); } - my_name_is(0, (char **)NULL, me->hdr.name); /* Set our real name */ + my_name_is(0, (char **)NULL, me->name()); /* Set our real name */ if (!foreground) { daemon_start(); /* become daemon */ @@ -394,13 +394,13 @@ static int check_resources() if (!store->tls_certfile && tls_needed) { Jmsg(NULL, M_FATAL, 0, _("\"TLS Certificate\" file not defined for Storage \"%s\" in %s.\n"), - store->hdr.name, configfile); + store->name(), configfile); OK = false; } if (!store->tls_keyfile && tls_needed) { Jmsg(NULL, M_FATAL, 0, _("\"TLS Key\" file not defined for Storage \"%s\" in %s.\n"), - store->hdr.name, configfile); + store->name(), configfile); OK = false; } @@ -409,7 +409,7 @@ static int check_resources() " or \"TLS CA Certificate Dir\" are defined for Storage \"%s\" in %s." " At least one CA certificate store is required" " when using \"TLS Verify Peer\".\n"), - store->hdr.name, configfile); + store->name(), configfile); OK = false; } @@ -431,7 +431,7 @@ static int check_resources() if (!store->tls_ctx) { Jmsg(NULL, M_FATAL, 0, _("Failed to initialize TLS context for Storage \"%s\" in %s.\n"), - store->hdr.name, configfile); + store->name(), configfile); OK = false; } @@ -451,13 +451,13 @@ static int check_resources() if (!director->tls_certfile && tls_needed) { Jmsg(NULL, M_FATAL, 0, _("\"TLS Certificate\" file not defined for Director \"%s\" in %s.\n"), - director->hdr.name, configfile); + director->name(), configfile); OK = false; } if (!director->tls_keyfile && tls_needed) { Jmsg(NULL, M_FATAL, 0, _("\"TLS Key\" file not defined for Director \"%s\" in %s.\n"), - director->hdr.name, configfile); + director->name(), configfile); OK = false; } @@ -466,7 +466,7 @@ static int check_resources() " or \"TLS CA Certificate Dir\" are defined for Director \"%s\" in %s." " At least one CA certificate store is required" " when using \"TLS Verify Peer\".\n"), - director->hdr.name, configfile); + director->name(), configfile); OK = false; } @@ -488,7 +488,7 @@ static int check_resources() if (!director->tls_ctx) { Jmsg(NULL, M_FATAL, 0, _("Failed to initialize TLS context for Director \"%s\" in %s.\n"), - director->hdr.name, configfile); + director->name(), configfile); OK = false; } @@ -501,7 +501,7 @@ static int check_resources() foreach_res(device, R_DEVICE) { if (device->drive_crypto_enabled && bit_is_set(CAP_LABEL, device->cap_bits)) { Jmsg(NULL, M_FATAL, 0, _("LabelMedia enabled is incompatible with tape crypto on Device \"%s\" in %s.\n"), - device->hdr.name, configfile); + device->name(), configfile); OK = false; } } diff --git a/src/stored/stored_conf.c b/src/stored/stored_conf.c index 5a8d19c6b46..3fe1f9f04d3 100644 --- a/src/stored/stored_conf.c +++ b/src/stored/stored_conf.c @@ -509,7 +509,6 @@ void free_resource(RES *sres, int type) free(res->res_dir.hdr.desc); } - switch (type) { case R_DIRECTOR: if (res->res_dir.password.value) { @@ -750,15 +749,15 @@ void save_resource(int type, RES_ITEM *items, int pass) /* * Resources containing a resource or an alist */ - if ((res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.hdr.name)) == NULL) { - 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())) == NULL) { + Emsg1(M_ERROR_TERM, 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; case R_STORAGE: - if ((res = (URES *)GetResWithName(R_STORAGE, res_all.res_dir.hdr.name)) == NULL) { - Emsg1(M_ERROR_TERM, 0, _("Cannot find Storage resource %s\n"), res_all.res_dir.hdr.name); + if ((res = (URES *)GetResWithName(R_STORAGE, res_all.res_store.name())) == NULL) { + Emsg1(M_ERROR_TERM, 0, _("Cannot find Storage resource %s\n"), res_all.res_store.name()); } else { res->res_store.plugin_names = res_all.res_store.plugin_names; res->res_store.messages = res_all.res_store.messages; @@ -767,8 +766,8 @@ void save_resource(int type, RES_ITEM *items, int pass) } break; case R_AUTOCHANGER: - if ((res = (URES *)GetResWithName(type, res_all.res_changer.hdr.name)) == NULL) { - Emsg1(M_ERROR_TERM, 0, _("Cannot find AutoChanger resource %s\n"), res_all.res_changer.hdr.name); + if ((res = (URES *)GetResWithName(type, res_all.res_changer.name())) == NULL) { + Emsg1(M_ERROR_TERM, 0, _("Cannot find AutoChanger resource %s\n"), res_all.res_changer.name()); } else { /* * We must explicitly copy the device alist pointer @@ -798,6 +797,7 @@ void save_resource(int type, RES_ITEM *items, int pass) free(res_all.res_dir.hdr.name); res_all.res_dir.hdr.name = NULL; } + if (res_all.res_dir.hdr.desc) { free(res_all.res_dir.hdr.desc); res_all.res_dir.hdr.desc = NULL; @@ -821,15 +821,14 @@ 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; - 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()); } } } diff --git a/src/stored/stored_conf.h b/src/stored/stored_conf.h index c327f08555a..4276676e1be 100644 --- a/src/stored/stored_conf.h +++ b/src/stored/stored_conf.h @@ -20,10 +20,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + /* * Resource codes -- they must be sequential for indexing */ - enum { R_DIRECTOR = 3001, R_NDMP, @@ -44,10 +44,8 @@ enum { }; /* Definition of the contents of each Resource */ -class DIRRES { +class DIRRES : public BRSRES { public: - RES hdr; - s_password password; /* Director password */ char *address; /* Director IP address or zero */ bool monitor; /* Have only access to status and .status functions */ @@ -80,10 +78,8 @@ class NDMPRES { }; /* Storage daemon "global" definitions */ -class STORES { +class STORES : public BRSRES { public: - RES hdr; - dlist *SDaddrs; dlist *SDsrc_addr; /* Address to source connections from */ dlist *NDMPaddrs; @@ -132,10 +128,8 @@ class STORES { TLS_CONTEXT *tls_ctx; /* Shared TLS Context */ }; -class AUTOCHANGERRES { +class AUTOCHANGERRES : public BRSRES { public: - RES hdr; - alist *device; /* List of DEVRES device pointers */ char *changer_name; /* Changer device name */ char *changer_command; /* Changer command -- external program */ @@ -143,10 +137,8 @@ class AUTOCHANGERRES { }; /* Device specific definitions */ -class DEVRES { +class DEVRES : public BRSRES { public: - RES hdr; - char *media_type; /* User assigned media type */ char *device_name; /* Archive device name */ char *device_options; /* Device specific option string */ @@ -213,4 +205,3 @@ union URES { void init_sd_config(CONFIG *config, const char *configfile, int exit_code); bool print_config_schema_json(POOL_MEM &buffer); -