From 37e292d13e2ab9f40a1904e843609b2439c9f6f4 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Fri, 7 Sep 2018 15:01:31 +0200 Subject: [PATCH] stored/filed: for job connections added R_JOB tls client hello - added R_JOB as resource so the resource name converter can convert the string into r_type - using ASCII Record Separator 0x1e to separate data fields in the Client Hello indentity --- core/src/filed/dir_cmd.cc | 2 +- core/src/filed/filed_conf.cc | 2 +- core/src/filed/filed_conf.h | 3 +- core/src/include/jcr.h | 2 +- core/src/lib/jcr.cc | 6 ++-- .../qualified_resource_name_type_converter.h | 8 ++--- core/src/lib/res.cc | 34 ++++++++++++------- core/src/stored/stored_conf.cc | 2 +- core/src/stored/stored_conf.h | 4 +-- 9 files changed, 36 insertions(+), 27 deletions(-) diff --git a/core/src/filed/dir_cmd.cc b/core/src/filed/dir_cmd.cc index a6c61fae4de..49ff16a7c5f 100644 --- a/core/src/filed/dir_cmd.cc +++ b/core/src/filed/dir_cmd.cc @@ -1590,7 +1590,7 @@ static bool StorageCmd(JobControlRecord *jcr) jcr->store_bsock = sd; if (!my_config->GetQualifiedResourceNameTypeConverter()->ResourceToString( - jcr->client_name, my_config->r_own_, jcr->JobId, qualified_resource_name)) { + jcr->Job, R_JOB, jcr->JobId, qualified_resource_name)) { goto bail_out; } diff --git a/core/src/filed/filed_conf.cc b/core/src/filed/filed_conf.cc index 7db17b022ca..446fa705f4e 100644 --- a/core/src/filed/filed_conf.cc +++ b/core/src/filed/filed_conf.cc @@ -264,7 +264,7 @@ static void ParseConfigCb(LEX *lc, ResourceItem *item, int index, int pass) static void ConfigReadyCallback(ConfigurationParser &my_config) { std::map map{ - {R_DIRECTOR, "R_DIRECTOR"}, {R_CLIENT, "R_CLIENT"}, {R_STORAGE, "R_STORAGE"}, {R_MSGS, "R_MSGS"}}; + {R_DIRECTOR, "R_DIRECTOR"}, {R_CLIENT, "R_CLIENT"}, {R_STORAGE, "R_STORAGE"}, {R_MSGS, "R_MSGS"}, {R_JOB, "R_JOB"}}; my_config.InitializeQualifiedResourceNameTypeConverter(map); } diff --git a/core/src/filed/filed_conf.h b/core/src/filed/filed_conf.h index d5d7731487b..8f03943b151 100644 --- a/core/src/filed/filed_conf.h +++ b/core/src/filed/filed_conf.h @@ -41,8 +41,9 @@ enum { R_CLIENT, R_MSGS, R_STORAGE, + R_JOB, R_FIRST = R_DIRECTOR, - R_LAST = R_STORAGE /* keep this updated */ + R_LAST = R_JOB /* keep this updated */ }; /* diff --git a/core/src/include/jcr.h b/core/src/include/jcr.h index d3c23049f1b..a6a3661231f 100644 --- a/core/src/include/jcr.h +++ b/core/src/include/jcr.h @@ -681,7 +681,7 @@ DLL_IMP_EXP extern JobControlRecord *get_jcr_by_id(uint32_t JobId); DLL_IMP_EXP extern JobControlRecord *get_jcr_by_session(uint32_t SessionId, uint32_t SessionTime); DLL_IMP_EXP extern JobControlRecord *get_jcr_by_partial_name(char *Job); DLL_IMP_EXP extern JobControlRecord *get_jcr_by_full_name(char *Job); -DLL_IMP_EXP extern const char *jcr_get_authenticate_key_by_client_name(const char *client_name); +DLL_IMP_EXP extern const char *JcrGetAuthenticateKey(uint32_t job_id, const char *unified_job_name); DLL_IMP_EXP extern JobControlRecord *get_next_jcr(JobControlRecord *jcr); DLL_IMP_EXP extern void SetJcrJobStatus(JobControlRecord *jcr, int JobStatus); DLL_IMP_EXP extern int DLL_IMP_EXP num_jobs_run; diff --git a/core/src/lib/jcr.cc b/core/src/lib/jcr.cc index f794187a956..7cdf64ac7fa 100644 --- a/core/src/lib/jcr.cc +++ b/core/src/lib/jcr.cc @@ -828,15 +828,15 @@ JobControlRecord *get_jcr_by_full_name(char *Job) return jcr; } -const char *jcr_get_authenticate_key_by_client_name(const char *client_name) +const char *JcrGetAuthenticateKey(uint32_t job_id, const char *unified_job_name) { - if (!client_name) { return nullptr; } + if (!unified_job_name) { return nullptr; } JobControlRecord *jcr; const char *auth_key; foreach_jcr(jcr) { - if (bstrcmp(jcr->client_name, client_name)) { + if (bstrcmp(jcr->Job, unified_job_name)) { auth_key = jcr->sd_auth_key; Dmsg3(debuglevel, "Inc get_jcr jid=%u UseCount=%d Job=%s\n", jcr->JobId, jcr->UseCount(), jcr->Job); break; diff --git a/core/src/lib/qualified_resource_name_type_converter.h b/core/src/lib/qualified_resource_name_type_converter.h index 8d736f2faa3..b0b9c2e4cac 100644 --- a/core/src/lib/qualified_resource_name_type_converter.h +++ b/core/src/lib/qualified_resource_name_type_converter.h @@ -34,13 +34,13 @@ class QualifiedResourceNameTypeConverter { std::string &out) const; bool StringToResource(std::string &name_of_resource, int &r_type, int &job_id, const std::string &in) const; -private: + std::string ResourceTypeToString(const int &type) const; + int StringToResourceType(const std::string &) const; + + private: static constexpr char record_separator_ = 0x1e; const std::map type_name_relation_map_; const std::map name_type_relation_map_; - - std::string ResourceTypeToString(const int &type) const; - int StringToResourceType(const std::string &) const; }; #endif /* BAREOS_LIB_QUALIFIED_RESOURCE_NAME_TYPE_CONVERTER_H_ */ diff --git a/core/src/lib/res.cc b/core/src/lib/res.cc index eefedaa103f..3152a500772 100644 --- a/core/src/lib/res.cc +++ b/core/src/lib/res.cc @@ -147,20 +147,28 @@ bool ConfigurationParser::GetTlsPskByFullyQualifiedResourceName(ConfigurationPar std::string fq_name(fq_name_buffer); free(fq_name_buffer); + QualifiedResourceNameTypeConverter *c = config->GetQualifiedResourceNameTypeConverter(); + if (!c) { return false; } + int r_type; - int job_id; - std::string name; - bool ok = config->GetQualifiedResourceNameTypeConverter()->StringToResource(name, r_type, job_id, fq_name_in); - if (!ok || r_type < 0) { return false; } - TlsResource *tls = reinterpret_cast(config->GetResWithName(r_type, name.c_str())); - if (tls) { - psk = tls->password.value; - return true; - } - const char *psk_cstr = jcr_get_authenticate_key_by_client_name(name.c_str()); - if (psk_cstr) { - psk = psk_cstr; - return true; + int job_id = -1; + std::string name; /* either unique job name or client name */ + + bool ok = c->StringToResource(name, r_type, job_id, fq_name_in); + if (!ok) { return false; } + + if (job_id > 0 && fq_name.find("R_JOB") != std::string::npos) { + const char *psk_cstr = JcrGetAuthenticateKey(job_id, name.c_str()); + if (psk_cstr) { + psk = psk_cstr; + return true; + } + } else { + TlsResource *tls = reinterpret_cast(config->GetResWithName(r_type, name.c_str())); + if (tls) { + psk = tls->password.value; + return true; + } } return false; } diff --git a/core/src/stored/stored_conf.cc b/core/src/stored/stored_conf.cc index 4ea7385d5fa..73c91c906ab 100644 --- a/core/src/stored/stored_conf.cc +++ b/core/src/stored/stored_conf.cc @@ -519,7 +519,7 @@ static void ParseConfigCb(LEX *lc, ResourceItem *item, int index, int pass) static void ConfigReadyCallback(ConfigurationParser &my_config) { std::map map{ - {R_DIRECTOR, "R_DIRECTOR"}, {R_CLIENT, "R_CLIENT"}, /* needed for client name conversion */ + {R_DIRECTOR, "R_DIRECTOR"}, {R_JOB, "R_JOB"}, /* needed for client name conversion */ {R_NDMP, "R_NDMP"}, {R_STORAGE, "R_STORAGE"}, {R_MSGS, "R_MSGS"}, {R_DEVICE, "R_DEVICE"}, {R_AUTOCHANGER, "R_AUTOCHANGER"}}; my_config.InitializeQualifiedResourceNameTypeConverter(map); diff --git a/core/src/stored/stored_conf.h b/core/src/stored/stored_conf.h index e35e3902bd9..69a21371138 100644 --- a/core/src/stored/stored_conf.h +++ b/core/src/stored/stored_conf.h @@ -44,9 +44,9 @@ enum { R_DEVICE, R_MSGS, R_AUTOCHANGER, - R_CLIENT, /* needed for client name conversion */ + R_JOB, /* needed for Job name conversion */ R_FIRST = R_DIRECTOR, - R_LAST = R_CLIENT /* keep this updated */ + R_LAST = R_JOB /* keep this updated */ }; enum {