Skip to content

Commit

Permalink
stored/filed: for job connections added R_JOB tls client hello
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
franku committed Sep 7, 2018
1 parent 0a207db commit 37e292d
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 27 deletions.
2 changes: 1 addition & 1 deletion core/src/filed/dir_cmd.cc
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/filed/filed_conf.cc
Expand Up @@ -264,7 +264,7 @@ static void ParseConfigCb(LEX *lc, ResourceItem *item, int index, int pass)
static void ConfigReadyCallback(ConfigurationParser &my_config)
{
std::map<int, std::string> 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);
}

Expand Down
3 changes: 2 additions & 1 deletion core/src/filed/filed_conf.h
Expand Up @@ -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 */
};

/*
Expand Down
2 changes: 1 addition & 1 deletion core/src/include/jcr.h
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions core/src/lib/jcr.cc
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions core/src/lib/qualified_resource_name_type_converter.h
Expand Up @@ -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<int, std::string> type_name_relation_map_;
const std::map<std::string, int> 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_ */
34 changes: 21 additions & 13 deletions core/src/lib/res.cc
Expand Up @@ -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<TlsResource *>(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<TlsResource *>(config->GetResWithName(r_type, name.c_str()));
if (tls) {
psk = tls->password.value;
return true;
}
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/stored/stored_conf.cc
Expand Up @@ -519,7 +519,7 @@ static void ParseConfigCb(LEX *lc, ResourceItem *item, int index, int pass)
static void ConfigReadyCallback(ConfigurationParser &my_config)
{
std::map<int, std::string> 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);
Expand Down
4 changes: 2 additions & 2 deletions core/src/stored/stored_conf.h
Expand Up @@ -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 {
Expand Down

0 comments on commit 37e292d

Please sign in to comment.