diff options
Diffstat (limited to 'core/src/dird/fd_cmds.cc')
-rw-r--r-- | core/src/dird/fd_cmds.cc | 165 |
1 files changed, 84 insertions, 81 deletions
diff --git a/core/src/dird/fd_cmds.cc b/core/src/dird/fd_cmds.cc index 422d3effa..1fc1c9ee4 100644 --- a/core/src/dird/fd_cmds.cc +++ b/core/src/dird/fd_cmds.cc @@ -35,12 +35,12 @@ #include "cats/cats.h" #include "dird.h" #include "dird/dird_globals.h" -#include "dird/jcr_private.h" +#include "dird/director_jcr_impl.h" #include "findlib/find.h" #include "dird/authenticate.h" #include "dird/fd_cmds.h" #include "dird/getmsg.h" -#include "dird/jcr_private.h" +#include "dird/director_jcr_impl.h" #include "dird/msgchan.h" #include "dird/run_on_incoming_connect_interval.h" #include "dird/scheduler.h" @@ -128,21 +128,21 @@ static bool connect_outbound_to_file_daemon(JobControlRecord* jcr, if (!IsConnectingToClientAllowed(jcr)) { Dmsg1(120, "Connection to client \"%s\" is not allowed.\n", - jcr->impl->res.client->resource_name_); + jcr->dir_impl->res.client->resource_name_); return false; } fd = new BareosSocketTCP; - heart_beat = get_heartbeat_interval(jcr->impl->res.client); + heart_beat = get_heartbeat_interval(jcr->dir_impl->res.client); char name[MAX_NAME_LENGTH + 100]; bstrncpy(name, _("Client: "), sizeof(name)); - bstrncat(name, jcr->impl->res.client->resource_name_, sizeof(name)); + bstrncat(name, jcr->dir_impl->res.client->resource_name_, sizeof(name)); fd->SetSourceAddress(me->DIRsrc_addr); if (!fd->connect(jcr, retry_interval, max_retry_time, heart_beat, name, - jcr->impl->res.client->address, NULL, - jcr->impl->res.client->FDport, verbose)) { + jcr->dir_impl->res.client->address, NULL, + jcr->dir_impl->res.client->FDport, verbose)) { delete fd; fd = NULL; jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated); @@ -160,9 +160,9 @@ static void OutputMessageForConnectionTry(JobControlRecord* jcr, UaContext* ua) { std::string m; - if (jcr->impl->res.client->connection_successful_handshake_ + if (jcr->dir_impl->res.client->connection_successful_handshake_ == ClientConnectionHandshakeMode::kUndefined - || jcr->impl->res.client->connection_successful_handshake_ + || jcr->dir_impl->res.client->connection_successful_handshake_ == ClientConnectionHandshakeMode::kFailed) { m = "Probing client protocol... (result will be saved until config reload)"; } else { @@ -190,11 +190,11 @@ static void SendInfoChosenCipher(JobControlRecord* jcr, UaContext* ua) static void SendInfoSuccess(JobControlRecord* jcr, UaContext* ua) { std::string m; - if (jcr->impl->res.client->connection_successful_handshake_ + if (jcr->dir_impl->res.client->connection_successful_handshake_ == ClientConnectionHandshakeMode::kUndefined) { m = "\r\v"; } - switch (jcr->impl->connection_handshake_try_) { + switch (jcr->dir_impl->connection_handshake_try_) { case ClientConnectionHandshakeMode::kTlsFirst: m += " Handshake: Immediate TLS,"; break; @@ -227,7 +227,7 @@ bool ConnectToFileDaemon(JobControlRecord* jcr, { if (!IsConnectingToClientAllowed(jcr) && !IsConnectFromClientAllowed(jcr)) { Emsg1(M_WARNING, 0, _("Connecting to %s is not allowed.\n"), - jcr->impl->res.client->resource_name_); + jcr->dir_impl->res.client->resource_name_); return false; } bool success = false; @@ -239,22 +239,22 @@ bool ConnectToFileDaemon(JobControlRecord* jcr, * in case there is a client that cannot do Tls immediately then * fall back to cleartext md5-handshake */ OutputMessageForConnectionTry(jcr, ua); - if (jcr->impl->res.client->connection_successful_handshake_ + if (jcr->dir_impl->res.client->connection_successful_handshake_ == ClientConnectionHandshakeMode::kUndefined - || jcr->impl->res.client->connection_successful_handshake_ + || jcr->dir_impl->res.client->connection_successful_handshake_ == ClientConnectionHandshakeMode::kFailed) { - if (jcr->impl->res.client->IsTlsConfigured()) { - jcr->impl->connection_handshake_try_ + if (jcr->dir_impl->res.client->IsTlsConfigured()) { + jcr->dir_impl->connection_handshake_try_ = ClientConnectionHandshakeMode::kTlsFirst; } else { - jcr->impl->connection_handshake_try_ + jcr->dir_impl->connection_handshake_try_ = ClientConnectionHandshakeMode::kCleartextFirst; } jcr->is_passive_client_connection_probing = true; } else { /* if there is a stored mode from a previous connection then use this */ - jcr->impl->connection_handshake_try_ - = jcr->impl->res.client->connection_successful_handshake_; + jcr->dir_impl->connection_handshake_try_ + = jcr->dir_impl->res.client->connection_successful_handshake_; jcr->is_passive_client_connection_probing = false; } @@ -280,14 +280,14 @@ bool ConnectToFileDaemon(JobControlRecord* jcr, SendInfoSuccess(jcr, ua); SendInfoChosenCipher(jcr, ua); jcr->is_passive_client_connection_probing = false; - jcr->impl->res.client->connection_successful_handshake_ - = jcr->impl->connection_handshake_try_; + jcr->dir_impl->res.client->connection_successful_handshake_ + = jcr->dir_impl->connection_handshake_try_; } else { /* authentication failed due to * - tls mismatch or * - if an old client cannot do tls- before md5-handshake * */ - switch (jcr->impl->connection_handshake_try_) { + switch (jcr->dir_impl->connection_handshake_try_) { case ClientConnectionHandshakeMode::kTlsFirst: if (jcr->file_bsock) { jcr->file_bsock->close(); @@ -295,11 +295,11 @@ bool ConnectToFileDaemon(JobControlRecord* jcr, jcr->file_bsock = nullptr; } jcr->setJobStatus(JS_Running); - jcr->impl->connection_handshake_try_ + jcr->dir_impl->connection_handshake_try_ = ClientConnectionHandshakeMode::kCleartextFirst; break; case ClientConnectionHandshakeMode::kCleartextFirst: - jcr->impl->connection_handshake_try_ + jcr->dir_impl->connection_handshake_try_ = ClientConnectionHandshakeMode::kFailed; break; case ClientConnectionHandshakeMode::kFailed: @@ -310,11 +310,11 @@ bool ConnectToFileDaemon(JobControlRecord* jcr, } } else { Jmsg(jcr, M_FATAL, 0, "\nFailed to connect to client \"%s\".\n", - jcr->impl->res.client->resource_name_); + jcr->dir_impl->res.client->resource_name_); } connect_tries--; } while (!tcp_connect_failed && connect_tries && !success - && jcr->impl->connection_handshake_try_ + && jcr->dir_impl->connection_handshake_try_ != ClientConnectionHandshakeMode::kFailed); if (!success) { jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated); } @@ -328,7 +328,7 @@ int SendJobInfoToFileDaemon(JobControlRecord* jcr) if (jcr->sd_auth_key == NULL) { jcr->sd_auth_key = strdup("dummy"); } - if (jcr->impl->res.client->connection_successful_handshake_ + if (jcr->dir_impl->res.client->connection_successful_handshake_ == ClientConnectionHandshakeMode::kTlsFirst) { /* client protocol onwards Bareos 18.2 */ TlsPolicy tls_policy = kBnetTlsUnknown; @@ -341,10 +341,10 @@ int SendJobInfoToFileDaemon(JobControlRecord* jcr) break; default: StorageResource* storage = nullptr; - if (jcr->impl->res.write_storage) { - storage = jcr->impl->res.write_storage; - } else if (jcr->impl->res.read_storage) { - storage = jcr->impl->res.read_storage; + if (jcr->dir_impl->res.write_storage) { + storage = jcr->dir_impl->res.write_storage; + } else if (jcr->dir_impl->res.read_storage) { + storage = jcr->dir_impl->res.read_storage; } else { Jmsg(jcr, M_FATAL, 0, _("No read or write storage defined\n")); jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated); @@ -360,16 +360,16 @@ int SendJobInfoToFileDaemon(JobControlRecord* jcr) fd->fsend(jobcmdssl, edit_int64(jcr->JobId, ed1), jcr->Job, jcr->VolSessionId, jcr->VolSessionTime, jcr->sd_auth_key, tls_policy); - } else { /* jcr->impl_->res.client->connection_successful_handshake_ != + } else { /* jcr->dir_impl_->res.client->connection_successful_handshake_ != ClientConnectionHandshakeMode::kTlsFirst */ /* client protocol before Bareos 18.2 */ char ed1[30]; fd->fsend(jobcmd, edit_int64(jcr->JobId, ed1), jcr->Job, jcr->VolSessionId, jcr->VolSessionTime, jcr->sd_auth_key); - } /* if (jcr->impl_->res.client->connection_successful_handshake_ == + } /* if (jcr->dir_impl_->res.client->connection_successful_handshake_ == ClientConnectionHandshakeMode::kTlsFirst) */ - if (!jcr->impl->keep_sd_auth_key && !bstrcmp(jcr->sd_auth_key, "dummy")) { + if (!jcr->dir_impl->keep_sd_auth_key && !bstrcmp(jcr->sd_auth_key, "dummy")) { memset(jcr->sd_auth_key, 0, strlen(jcr->sd_auth_key)); } @@ -378,16 +378,17 @@ int SendJobInfoToFileDaemon(JobControlRecord* jcr) Dmsg1(110, "<filed: %s", fd->msg); if (!bstrncmp(fd->msg, OKjob, strlen(OKjob))) { Jmsg(jcr, M_FATAL, 0, _("File daemon \"%s\" rejected Job command: %s\n"), - jcr->impl->res.client->resource_name_, fd->msg); + jcr->dir_impl->res.client->resource_name_, fd->msg); jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated); return 0; } else if (jcr->db) { ClientDbRecord cr; - bstrncpy(cr.Name, jcr->impl->res.client->resource_name_, sizeof(cr.Name)); - cr.AutoPrune = jcr->impl->res.client->AutoPrune; - cr.FileRetention = jcr->impl->res.client->FileRetention; - cr.JobRetention = jcr->impl->res.client->JobRetention; + bstrncpy(cr.Name, jcr->dir_impl->res.client->resource_name_, + sizeof(cr.Name)); + cr.AutoPrune = jcr->dir_impl->res.client->AutoPrune; + cr.FileRetention = jcr->dir_impl->res.client->FileRetention; + cr.JobRetention = jcr->dir_impl->res.client->JobRetention; bstrncpy(cr.Uname, fd->msg + strlen(OKjob) + 1, sizeof(cr.Uname)); if (!jcr->db->UpdateClientRecord(jcr, &cr)) { Jmsg(jcr, M_WARNING, 0, _("Error updating Client record. ERR=%s\n"), @@ -412,8 +413,8 @@ bool SendPreviousRestoreObjects(JobControlRecord* jcr) switch (JobLevel) { case L_DIFFERENTIAL: case L_INCREMENTAL: - if (jcr->impl->previous_jr.JobId > 0) { - if (!SendRestoreObjects(jcr, jcr->impl->previous_jr.JobId, false)) { + if (jcr->dir_impl->previous_jr.JobId > 0) { + if (!SendRestoreObjects(jcr, jcr->dir_impl->previous_jr.JobId, false)) { return false; } } @@ -429,7 +430,7 @@ bool SendBwlimitToFd(JobControlRecord* jcr, const char* Job) { BareosSocket* fd = jcr->file_bsock; - if (jcr->impl->FDVersion >= FD_VERSION_4) { + if (jcr->dir_impl->FDVersion >= FD_VERSION_4) { fd->fsend(bandwidthcmd, jcr->max_bandwidth, Job); if (!response(jcr, fd, OKBandwidth, "Bandwidth", DISPLAY_ERROR)) { jcr->max_bandwidth = 0; /* can't set bandwidth limit */ @@ -445,29 +446,29 @@ bool SendSecureEraseReqToFd(JobControlRecord* jcr) int32_t n; BareosSocket* fd = jcr->file_bsock; - if (!jcr->impl->FDSecureEraseCmd) { - jcr->impl->FDSecureEraseCmd = GetPoolMemory(PM_NAME); + if (!jcr->dir_impl->FDSecureEraseCmd) { + jcr->dir_impl->FDSecureEraseCmd = GetPoolMemory(PM_NAME); } - if (jcr->impl->FDVersion > FD_VERSION_53) { + if (jcr->dir_impl->FDVersion > FD_VERSION_53) { fd->fsend(getSecureEraseCmd); while ((n = BgetDirmsg(fd)) >= 0) { - jcr->impl->FDSecureEraseCmd = CheckPoolMemorySize( - jcr->impl->FDSecureEraseCmd, fd->message_length); - if (sscanf(fd->msg, OKgetSecureEraseCmd, jcr->impl->FDSecureEraseCmd) + jcr->dir_impl->FDSecureEraseCmd = CheckPoolMemorySize( + jcr->dir_impl->FDSecureEraseCmd, fd->message_length); + if (sscanf(fd->msg, OKgetSecureEraseCmd, jcr->dir_impl->FDSecureEraseCmd) == 1) { Dmsg1(400, "Got FD Secure Erase Cmd: %s\n", - jcr->impl->FDSecureEraseCmd); + jcr->dir_impl->FDSecureEraseCmd); break; } else { Jmsg(jcr, M_WARNING, 0, _("Unexpected Client Secure Erase Cmd: %s\n"), fd->msg); - PmStrcpy(jcr->impl->FDSecureEraseCmd, "*None*"); + PmStrcpy(jcr->dir_impl->FDSecureEraseCmd, "*None*"); return false; } } } else { - PmStrcpy(jcr->impl->FDSecureEraseCmd, "*None*"); + PmStrcpy(jcr->dir_impl->FDSecureEraseCmd, "*None*"); } return true; @@ -481,7 +482,7 @@ static void SendSinceTime(JobControlRecord* jcr) stime = StrToUtime(jcr->starttime_string); fd->fsend(levelcmd, "", NT_("since_utime "), edit_uint64(stime, ed1), 0, - NT_("prev_job="), jcr->impl->PrevJob); + NT_("prev_job="), jcr->dir_impl->PrevJob); while (BgetDirmsg(fd) >= 0) { /* allow him to poll us to sync clocks */ Jmsg(jcr, M_INFO, 0, "%s\n", fd->msg); @@ -538,9 +539,9 @@ bool SendLevelCommand(JobControlRecord* jcr) // Send either an Included or an Excluded list to FD static bool SendFileset(JobControlRecord* jcr) { - FilesetResource* fileset = jcr->impl->res.fileset; + FilesetResource* fileset = jcr->dir_impl->res.fileset; BareosSocket* fd = jcr->file_bsock; - StorageResource* store = jcr->impl->res.write_storage; + StorageResource* store = jcr->dir_impl->res.write_storage; int num; bool include = true; @@ -775,8 +776,9 @@ static bool SendListItem(JobControlRecord* jcr, bool SendIncludeList(JobControlRecord* jcr) { BareosSocket* fd = jcr->file_bsock; - if (jcr->impl->res.fileset->new_include) { - fd->fsend(filesetcmd, jcr->impl->res.fileset->enable_vss ? " vss=1" : ""); + if (jcr->dir_impl->res.fileset->new_include) { + fd->fsend(filesetcmd, + jcr->dir_impl->res.fileset->enable_vss ? " vss=1" : ""); return SendFileset(jcr); } return true; @@ -820,18 +822,18 @@ int SendRunscriptsCommands(JobControlRecord* jcr) bool has_before_jobs = false; // See if there are any runscripts that need to be ran on the client. - if (!HaveClientRunscripts(jcr->impl->res.job->RunScripts)) { return 1; } + if (!HaveClientRunscripts(jcr->dir_impl->res.job->RunScripts)) { return 1; } Dmsg0(120, "dird: sending runscripts to fd\n"); msg = GetPoolMemory(PM_FNAME); ehost = GetPoolMemory(PM_FNAME); - foreach_alist (cmd, jcr->impl->res.job->RunScripts) { + foreach_alist (cmd, jcr->dir_impl->res.job->RunScripts) { if (!cmd->target.empty()) { ehost = edit_job_codes(jcr, ehost, cmd->target.c_str(), ""); Dmsg2(200, "dird: runscript %s -> %s\n", cmd->target.c_str(), ehost); - if (bstrcmp(ehost, jcr->impl->res.client->resource_name_)) { + if (bstrcmp(ehost, jcr->dir_impl->res.client->resource_name_)) { PmStrcpy(msg, cmd->command.c_str()); BashSpaces(msg); @@ -897,15 +899,15 @@ static int RestoreObjectHandler(void* ctx, int, char** row) if (jcr->IsJobCanceled()) { return 1; } // Old File Daemon doesn't handle restore objects - if (jcr->impl->FDVersion < FD_VERSION_3) { + if (jcr->dir_impl->FDVersion < FD_VERSION_3) { Jmsg(jcr, M_WARNING, 0, _("Client \"%s\" may not be used to restore " "this job. Please upgrade your client.\n"), - jcr->impl->res.client->resource_name_); + jcr->dir_impl->res.client->resource_name_); return 1; } - if (jcr->impl->FDVersion + if (jcr->dir_impl->FDVersion < FD_VERSION_5) { /* Old version without PluginName */ fd->fsend("restoreobject JobId=%s %s,%s,%s,%s,%s,%s\n", row[0], row[1], row[2], row[3], row[4], row[5], row[6]); @@ -949,9 +951,9 @@ bool SendPluginOptions(JobControlRecord* jcr) const char* plugin_options; POOLMEM* msg; - if (jcr->impl->plugin_options) { + if (jcr->dir_impl->plugin_options) { msg = GetPoolMemory(PM_FNAME); - PmStrcpy(msg, jcr->impl->plugin_options); + PmStrcpy(msg, jcr->dir_impl->plugin_options); BashSpaces(msg); fd->fsend(pluginoptionscmd, msg); @@ -962,11 +964,11 @@ bool SendPluginOptions(JobControlRecord* jcr) return false; } } - if (jcr->impl->res.job && jcr->impl->res.job->FdPluginOptions - && jcr->impl->res.job->FdPluginOptions->size()) { + if (jcr->dir_impl->res.job && jcr->dir_impl->res.job->FdPluginOptions + && jcr->dir_impl->res.job->FdPluginOptions->size()) { Dmsg2(200, "dird: sendpluginoptions found FdPluginOptions in res.job\n"); foreach_alist_index (i, plugin_options, - jcr->impl->res.job->FdPluginOptions) { + jcr->dir_impl->res.job->FdPluginOptions) { PmStrcpy(cur_plugin_options, plugin_options); BashSpaces(cur_plugin_options.c_str()); @@ -1063,8 +1065,8 @@ int GetAttributesAndPutInCatalog(JobControlRecord* jcr) PoolMem digest(PM_MESSAGE); fd = jcr->file_bsock; - jcr->impl->jr.FirstIndex = 1; - jcr->impl->FileIndex = 0; + jcr->dir_impl->jr.FirstIndex = 1; + jcr->dir_impl->FileIndex = 0; // Start transaction allocates jcr->attr and jcr->ar if needed jcr->db->StartTransaction(jcr); /* start transaction if not already open */ @@ -1111,15 +1113,15 @@ int GetAttributesAndPutInCatalog(JobControlRecord* jcr) } // Any cached attr is flushed so we can reuse jcr->attr and jcr->ar - fn = jcr->impl->fname - = CheckPoolMemorySize(jcr->impl->fname, fd->message_length); + fn = jcr->dir_impl->fname + = CheckPoolMemorySize(jcr->dir_impl->fname, fd->message_length); while (*p != 0) { *fn++ = *p++; /* copy filename */ } *fn = *p++; /* term filename and point p to attribs */ PmStrcpy(jcr->attr, p); /* save attributes */ jcr->JobFiles++; - jcr->impl->FileIndex = file_index; + jcr->dir_impl->FileIndex = file_index; ar->attr = jcr->attr; - ar->fname = jcr->impl->fname; + ar->fname = jcr->dir_impl->fname; ar->FileIndex = file_index; ar->Stream = stream; ar->link = NULL; @@ -1131,7 +1133,8 @@ int GetAttributesAndPutInCatalog(JobControlRecord* jcr) ar->DeltaSeq = 0; jcr->cached_attribute = true; - Dmsg2(debuglevel, "dird<filed: stream=%d %s\n", stream, jcr->impl->fname); + Dmsg2(debuglevel, "dird<filed: stream=%d %s\n", stream, + jcr->dir_impl->fname); Dmsg1(debuglevel, "dird<filed: attr=%s\n", ar->attr); jcr->FileId = ar->FileId; } else if (CryptoDigestStreamType(stream) != CRYPTO_DIGEST_NONE) { @@ -1143,9 +1146,9 @@ int GetAttributesAndPutInCatalog(JobControlRecord* jcr) * it (or not) When we get a new STREAM_UNIX_ATTRIBUTES, we known that we * can add file to the catalog At the end, we have to add the last file */ - if (jcr->impl->FileIndex != (uint32_t)file_index) { + if (jcr->dir_impl->FileIndex != (uint32_t)file_index) { Jmsg3(jcr, M_ERROR, 0, _("%s index %d not same as attributes %d\n"), - stream_to_ascii(stream), file_index, jcr->impl->FileIndex); + stream_to_ascii(stream), file_index, jcr->dir_impl->FileIndex); continue; } @@ -1157,8 +1160,8 @@ int GetAttributesAndPutInCatalog(JobControlRecord* jcr) Dmsg4(debuglevel, "stream=%d DigestLen=%d Digest=%s type=%d\n", stream, strlen(digest.c_str()), digest.c_str(), ar->DigestType); } - jcr->impl->jr.JobFiles = jcr->JobFiles = file_index; - jcr->impl->jr.LastIndex = file_index; + jcr->dir_impl->jr.JobFiles = jcr->JobFiles = file_index; + jcr->dir_impl->jr.LastIndex = file_index; } if (IsBnetError(fd)) { @@ -1188,7 +1191,7 @@ bool CancelFileDaemonJob(UaContext* ua, JobControlRecord* jcr) { BareosSocket* fd; - ua->jcr->impl->res.client = jcr->impl->res.client; + ua->jcr->dir_impl->res.client = jcr->dir_impl->res.client; if (!ConnectToFileDaemon(ua->jcr, 10, me->FDConnectTimeout, true, ua)) { ua->ErrorMsg(_("\nFailed to connect to File daemon.\n")); return false; @@ -1212,7 +1215,7 @@ void DoNativeClientStatus(UaContext* ua, ClientResource* client, char* cmd) BareosSocket* fd; // Connect to File daemon - ua->jcr->impl->res.client = client; + ua->jcr->dir_impl->res.client = client; // Try to connect for 15 seconds if (!ua->api) { @@ -1255,7 +1258,7 @@ void DoClientResolve(UaContext* ua, ClientResource* client) BareosSocket* fd; // Connect to File daemon - ua->jcr->impl->res.client = client; + ua->jcr->dir_impl->res.client = client; // Try to connect for 15 seconds if (!ua->api) { |