Skip to content

Commit

Permalink
jcr: moved ConnectionHandshakeMode to directordaemon namespace
Browse files Browse the repository at this point in the history
- renamed ConnectionHandshakeMode to ClientConnectionHandshakeMode
- created extra file
- move to namespace directordaemon
  • Loading branch information
franku committed Sep 23, 2018
1 parent 709f470 commit a5a3142
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 16 deletions.
3 changes: 2 additions & 1 deletion core/src/dird/authenticate.cc
Expand Up @@ -33,6 +33,7 @@
#include "include/bareos.h"
#include "dird.h"
#include "dird/fd_cmds.h"
#include "dird/client_connection_handshake_mode.h"
#include "dird/dird_globals.h"
#include "lib/bnet.h"
#include "lib/qualified_resource_name_type_converter.h"
Expand Down Expand Up @@ -131,7 +132,7 @@ bool AuthenticateWithFileDaemon(JobControlRecord *jcr)
BareosSocket *fd = jcr->file_bsock;
ClientResource *client = jcr->res.client;

if (jcr->connection_handshake_try_ == JobControlRecord::ConnectionHandshakeMode::kTlsFirst) {
if (jcr->connection_handshake_try_ == ClientConnectionHandshakeMode::kTlsFirst) {
std::string qualified_resource_name;
if (!my_config->GetQualifiedResourceNameTypeConverter()->ResourceToString(me->hdr.name, my_config->r_own_,
qualified_resource_name)) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/backup.cc
Expand Up @@ -567,7 +567,7 @@ bool DoNativeBackup(JobControlRecord *jcr)
}
} else {

if (jcr->connection_successful_handshake_ != JobControlRecord::ConnectionHandshakeMode::kTlsFirst) {
if (jcr->connection_successful_handshake_ != ClientConnectionHandshakeMode::kTlsFirst) {
tls_need = GetLocalTlsPolicyFromConfiguration(client);
} else {
tls_need = TlsConfigBase::BNET_TLS_AUTO;
Expand Down
29 changes: 29 additions & 0 deletions core/src/dird/client_connection_handshake_mode.h
@@ -0,0 +1,29 @@
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2018-2018 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
License as published by the Free Software Foundation and included
in the file LICENSE.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef BAREOS_DIR_CLIENT_CONNECTION_HANDSHAKE_MODE_H_
#define BAREOS_DIR_CLIENT_CONNECTION_HANDSHAKE_MODE_H_

namespace directordaemon {

enum class ClientConnectionHandshakeMode { kUndefined, kTlsFirst, kCleartextFirst, kFailed };

} /* namespace directordaemon */
#endif /* BAREOS_DIR_CLIENT_CONNECTION_HANDSHAKE_MODE_H_ */
1 change: 1 addition & 0 deletions core/src/dird/dird_conf.h
Expand Up @@ -279,6 +279,7 @@ class ClientResource: public TlsResource {
bool ndmp_use_lmdb; /* NDMP Protocol specific use LMDB for the FHDB or not */
int64_t max_bandwidth; /* Limit speed on this client */
runtime_client_status_t *rcs; /* Runtime Client Status */

ClientResource() : TlsResource() {}
};

Expand Down
18 changes: 9 additions & 9 deletions core/src/dird/fd_cmds.cc
Expand Up @@ -167,8 +167,8 @@ bool ConnectToFileDaemon(JobControlRecord *jcr, int retry_interval, int max_retr

/* try the connection mode in case a client that cannot do Tls
* immediately without cleartext md5-handshake first */
jcr->connection_handshake_try_ = JobControlRecord::ConnectionHandshakeMode::kTlsFirst;
jcr->connection_successful_handshake_ = JobControlRecord::ConnectionHandshakeMode::kUndefined;
jcr->connection_handshake_try_ = ClientConnectionHandshakeMode::kTlsFirst;
jcr->connection_successful_handshake_ = ClientConnectionHandshakeMode::kUndefined;

do { /* while (tcp_connect_failed ...) */
/* connect the tcp socket */
Expand All @@ -194,20 +194,20 @@ bool ConnectToFileDaemon(JobControlRecord *jcr, int retry_interval, int max_retr
* - if an old client cannot do tls- before md5-handshake
* */
switch(jcr->connection_handshake_try_) {
case JobControlRecord::ConnectionHandshakeMode::kTlsFirst:
case ClientConnectionHandshakeMode::kTlsFirst:
if (jcr->file_bsock) {
jcr->file_bsock->close();
delete jcr->file_bsock;
jcr->file_bsock = nullptr;
}
jcr->resetJobStatus(JS_Running);
jcr->connection_handshake_try_ = JobControlRecord::ConnectionHandshakeMode::kCleartextFirst;
jcr->connection_handshake_try_ = ClientConnectionHandshakeMode::kCleartextFirst;
break;
case JobControlRecord::ConnectionHandshakeMode::kCleartextFirst:
jcr->connection_handshake_try_ = JobControlRecord::ConnectionHandshakeMode::kFailed;
case ClientConnectionHandshakeMode::kCleartextFirst:
jcr->connection_handshake_try_ = ClientConnectionHandshakeMode::kFailed;
break;
case JobControlRecord::ConnectionHandshakeMode::kFailed:
default: /* should bei one of class ConnectionHandshakeMode */
case ClientConnectionHandshakeMode::kFailed:
default: /* should bei one of class ClientConnectionHandshakeMode */
ASSERT(false);
break;
}
Expand All @@ -218,7 +218,7 @@ bool ConnectToFileDaemon(JobControlRecord *jcr, int retry_interval, int max_retr
connect_tries--;
} while (!tcp_connect_failed && connect_tries
&& !success
&& jcr->connection_handshake_try_ != JobControlRecord::ConnectionHandshakeMode::kFailed);
&& jcr->connection_handshake_try_ != ClientConnectionHandshakeMode::kFailed);

if (!success) {
jcr->setJobStatus(JS_ErrorTerminated);
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/restore.cc
Expand Up @@ -292,7 +292,7 @@ static inline bool DoNativeRestoreBootstrap(JobControlRecord *jcr)
goto bail_out;
}

if (jcr->connection_successful_handshake_ != JobControlRecord::ConnectionHandshakeMode::kTlsFirst) {
if (jcr->connection_successful_handshake_ != ClientConnectionHandshakeMode::kTlsFirst) {
tls_need = GetLocalTlsPolicyFromConfiguration(client);
} else {
tls_need = TlsConfigBase::BNET_TLS_AUTO;
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/verify.cc
Expand Up @@ -360,7 +360,7 @@ bool DoVerify(JobControlRecord *jcr)
uint32_t tls_need = 0;
ClientResource *client = jcr->res.client;

if (jcr->connection_successful_handshake_ != JobControlRecord::ConnectionHandshakeMode::kTlsFirst) {
if (jcr->connection_successful_handshake_ != ClientConnectionHandshakeMode::kTlsFirst) {
tls_need = GetLocalTlsPolicyFromConfiguration(client);
} else {
tls_need = TlsConfigBase::BNET_TLS_AUTO;
Expand Down
6 changes: 3 additions & 3 deletions core/src/include/jcr.h
Expand Up @@ -42,6 +42,7 @@

#ifdef DIRECTOR_DAEMON
#include "cats/cats.h"
#include "dird/client_connection_handshake_mode.h"
#endif

namespace directordaemon {
Expand Down Expand Up @@ -453,9 +454,6 @@ class JobControlRecord {
POOLMEM *comment; /**< Comment for this Job */
int64_t max_bandwidth; /**< Bandwidth limit for this Job */
htable *path_list; /**< Directory list (used by findlib) */
enum class ConnectionHandshakeMode { kUndefined, kTlsFirst, kCleartextFirst, kFailed };
ConnectionHandshakeMode connection_handshake_try_;
ConnectionHandshakeMode connection_successful_handshake_;

/*
* Daemon specific part of JobControlRecord
Expand Down Expand Up @@ -534,6 +532,8 @@ class JobControlRecord {
bool RescheduleIncompleteJobs; /**< Set if incomplete can be rescheduled */
bool HasQuota; /**< Client has quota limits */
bool HasSelectedJobs; /**< Migration/Copy Job did actually select some JobIds */
directordaemon::ClientConnectionHandshakeMode connection_handshake_try_;
directordaemon::ClientConnectionHandshakeMode connection_successful_handshake_;
#endif /* DIRECTOR_DAEMON */

#ifdef FILE_DAEMON
Expand Down

0 comments on commit a5a3142

Please sign in to comment.