Skip to content

Commit

Permalink
beautify: clang-format of some files
Browse files Browse the repository at this point in the history
  • Loading branch information
franku committed Sep 5, 2018
1 parent c69de73 commit abf767a
Showing 1 changed file with 94 additions and 101 deletions.
195 changes: 94 additions & 101 deletions core/src/filed/authenticate.cc
Expand Up @@ -51,13 +51,10 @@ const int debuglevel = 50;
* 53 02Apr15 - Added setdebug timestamp
* 54 29Oct15 - Added getSecureEraseCmd
*/
static char OK_hello_compat[] =
"2000 OK Hello 5\n";
static char OK_hello[] =
"2000 OK Hello 54\n";
static char OK_hello_compat[] = "2000 OK Hello 5\n";
static char OK_hello[] = "2000 OK Hello 54\n";

static char Dir_sorry[] =
"2999 Authentication failed.\n";
static char Dir_sorry[] = "2999 Authentication failed.\n";

/**
* To prevent DOS attacks,
Expand All @@ -66,21 +63,21 @@ static char Dir_sorry[] =
*/
static inline void delay()
{
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

/*
* Single thread all failures to avoid DOS
*/
P(mutex);
Bmicrosleep(6, 0);
V(mutex);
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

/*
* Single thread all failures to avoid DOS
*/
P(mutex);
Bmicrosleep(6, 0);
V(mutex);
}

static inline void AuthenticateFailed(JobControlRecord *jcr, PoolMem &message)
{
Dmsg0(debuglevel, message.c_str());
Jmsg0(jcr, M_FATAL, 0, message.c_str());
delay();
Dmsg0(debuglevel, message.c_str());
Jmsg0(jcr, M_FATAL, 0, message.c_str());
delay();
}

/**
Expand All @@ -92,111 +89,107 @@ static inline void AuthenticateFailed(JobControlRecord *jcr, PoolMem &message)
*/
bool AuthenticateDirector(JobControlRecord *jcr)
{
BareosSocket *dir = jcr->dir_bsock;

PoolMem errormsg(PM_MESSAGE);
PoolMem dirname(PM_MESSAGE);
DirectorResource *director = NULL;

if (dir->message_length < 25 || dir->message_length > 500) {
char addr[64];
char *who = BnetGetPeer(dir, addr, sizeof(addr)) ? dir->who() : addr;
errormsg.bsprintf(_("Bad Hello command from Director at %s. Len=%d.\n"), who, dir->message_length);
AuthenticateFailed(jcr, errormsg);
return false;
}

if (sscanf(dir->msg, "Hello Director %s calling", dirname.check_size(dir->message_length)) != 1) {
char addr[64];
char *who = BnetGetPeer(dir, addr, sizeof(addr)) ? dir->who() : addr;
dir->msg[100] = 0;
errormsg.bsprintf(_("Bad Hello command from Director at %s: %s\n"), who, dir->msg);
AuthenticateFailed(jcr, errormsg);
return false;
}

UnbashSpaces(dirname.c_str());
director = (DirectorResource *)my_config->GetResWithName(R_DIRECTOR, dirname.c_str());

if (!director) {
char addr[64];
char *who = BnetGetPeer(dir, addr, sizeof(addr)) ? dir->who() : addr;
errormsg.bsprintf(
_("Connection from unknown Director %s at %s rejected.\n"), dirname.c_str(), who);
AuthenticateFailed(jcr, errormsg);
return false;
}

if (!director->conn_from_dir_to_fd) {
errormsg.bsprintf(_("Connection from Director %s rejected.\n"), dirname.c_str());
AuthenticateFailed(jcr, errormsg);
return false;
}

if (!dir->AuthenticateInboundConnection(
jcr, "Director", dirname.c_str(), director->password, director)) {
dir->fsend("%s", Dir_sorry);
errormsg.bsprintf(_("Unable to authenticate Director %s.\n"), dirname.c_str());
AuthenticateFailed(jcr, errormsg);
return false;
}

jcr->director = director;

return dir->fsend("%s", (me->compatible) ? OK_hello_compat : OK_hello);
BareosSocket *dir = jcr->dir_bsock;

PoolMem errormsg(PM_MESSAGE);
PoolMem dirname(PM_MESSAGE);
DirectorResource *director = NULL;

if (dir->message_length < 25 || dir->message_length > 500) {
char addr[64];
char *who = BnetGetPeer(dir, addr, sizeof(addr)) ? dir->who() : addr;
errormsg.bsprintf(_("Bad Hello command from Director at %s. Len=%d.\n"), who, dir->message_length);
AuthenticateFailed(jcr, errormsg);
return false;
}

if (sscanf(dir->msg, "Hello Director %s calling", dirname.check_size(dir->message_length)) != 1) {
char addr[64];
char *who = BnetGetPeer(dir, addr, sizeof(addr)) ? dir->who() : addr;
dir->msg[100] = 0;
errormsg.bsprintf(_("Bad Hello command from Director at %s: %s\n"), who, dir->msg);
AuthenticateFailed(jcr, errormsg);
return false;
}

UnbashSpaces(dirname.c_str());
director = (DirectorResource *)my_config->GetResWithName(R_DIRECTOR, dirname.c_str());

if (!director) {
char addr[64];
char *who = BnetGetPeer(dir, addr, sizeof(addr)) ? dir->who() : addr;
errormsg.bsprintf(_("Connection from unknown Director %s at %s rejected.\n"), dirname.c_str(), who);
AuthenticateFailed(jcr, errormsg);
return false;
}

if (!director->conn_from_dir_to_fd) {
errormsg.bsprintf(_("Connection from Director %s rejected.\n"), dirname.c_str());
AuthenticateFailed(jcr, errormsg);
return false;
}

if (!dir->AuthenticateInboundConnection(jcr, "Director", dirname.c_str(), director->password, director)) {
dir->fsend("%s", Dir_sorry);
errormsg.bsprintf(_("Unable to authenticate Director %s.\n"), dirname.c_str());
AuthenticateFailed(jcr, errormsg);
return false;
}

jcr->director = director;

return dir->fsend("%s", (me->compatible) ? OK_hello_compat : OK_hello);
}

/**
* Authenticate with a remote director.
*/
bool AuthenticateWithDirector(JobControlRecord *jcr, DirectorResource *director) {
return jcr->dir_bsock->AuthenticateOutboundConnection(
jcr, "Director", me->name(), director->password, director);
bool AuthenticateWithDirector(JobControlRecord *jcr, DirectorResource *director)
{
return jcr->dir_bsock->AuthenticateOutboundConnection(jcr, "Director", me->name(), director->password,
director);
}

/**
* Authenticate a remote storage daemon.
*/
bool AuthenticateStoragedaemon(JobControlRecord *jcr)
{
bool result = false;
BareosSocket *sd = jcr->store_bsock;
s_password password;

password.encoding = p_encoding_md5;
password.value = jcr->sd_auth_key;
result = sd->AuthenticateInboundConnection(jcr, "Storage daemon", jcr->client_name, password, me);

/*
* Destroy session key
*/
memset(jcr->sd_auth_key, 0, strlen(jcr->sd_auth_key));
if (!result) {
delay();
}

return result;
bool result = false;
BareosSocket *sd = jcr->store_bsock;
s_password password;

password.encoding = p_encoding_md5;
password.value = jcr->sd_auth_key;
result = sd->AuthenticateInboundConnection(jcr, "Storage daemon", jcr->client_name, password, me);

/*
* Destroy session key
*/
memset(jcr->sd_auth_key, 0, strlen(jcr->sd_auth_key));
if (!result) { delay(); }

return result;
}

/**
* Authenticate with a remote storage daemon.
*/
bool AuthenticateWithStoragedaemon(JobControlRecord *jcr)
{
bool result = false;
BareosSocket *sd = jcr->store_bsock;
s_password password;
bool result = false;
BareosSocket *sd = jcr->store_bsock;
s_password password;

password.encoding = p_encoding_md5;
password.value = jcr->sd_auth_key;
result = sd->AuthenticateOutboundConnection(
jcr, "Storage daemon", (char *) jcr->client_name, password, me);
password.encoding = p_encoding_md5;
password.value = jcr->sd_auth_key;
result = sd->AuthenticateOutboundConnection(jcr, "Storage daemon", (char *)jcr->client_name, password, me);

/*
* Destroy session key
*/
memset(jcr->sd_auth_key, 0, strlen(jcr->sd_auth_key));
/*
* Destroy session key
*/
memset(jcr->sd_auth_key, 0, strlen(jcr->sd_auth_key));

return result;
return result;
}
} /* namespace filedaemon */

0 comments on commit abf767a

Please sign in to comment.