Skip to content

Commit

Permalink
Merge pull request #1487
Browse files Browse the repository at this point in the history
dird: show current and allowed console connections
  • Loading branch information
BareosBot committed Aug 4, 2023
2 parents 136248f + 13f86da commit 73d372d
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -79,6 +79,7 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https:
- cats: postgresql introduce pl/sql lstat_decode() function [PR #1466]
- bsmtp: make mailhost and port message info a debug message [PR #1507]
- dird: cats: abort purge when there are no eligible jobids [PR #1512]
- dird: show current and allowed console connections [PR #1487]

### Removed
- remove no longer used pkglists [PR #1335]
Expand Down Expand Up @@ -202,6 +203,7 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https:
[PR #1477]: https://github.com/bareos/bareos/pull/1477
[PR #1479]: https://github.com/bareos/bareos/pull/1479
[PR #1484]: https://github.com/bareos/bareos/pull/1484
[PR #1487]: https://github.com/bareos/bareos/pull/1487
[PR #1488]: https://github.com/bareos/bareos/pull/1488
[PR #1490]: https://github.com/bareos/bareos/pull/1490
[PR #1493]: https://github.com/bareos/bareos/pull/1493
Expand Down
1 change: 1 addition & 0 deletions core/src/dird/CMakeLists.txt
Expand Up @@ -37,6 +37,7 @@ set(DIRD_OBJECTS_SRCS
catreq.cc
check_catalog.cc
consolidate.cc
console_connection_lease.cc
dbcheck_utils.cc
dird_globals.cc
dir_plugins.cc
Expand Down
36 changes: 16 additions & 20 deletions core/src/dird/authenticate_console.cc
Expand Up @@ -37,6 +37,7 @@
#include "lib/util.h"
#include "lib/version.h"
#include "include/version_numbers.h"
#include "console_connection_lease.h"

namespace directordaemon {

Expand Down Expand Up @@ -354,19 +355,6 @@ static void LogErrorMessage(std::string console_name, UaContext* ua)
ua->UA_sock->port());
}

static bool NumberOfConsoleConnectionsExceeded()
{
JobControlRecord* jcr;
unsigned int cnt = 0;

foreach_jcr (jcr) {
if (jcr->is_JobType(JT_CONSOLE)) { cnt++; }
}
endeach_jcr(jcr);

return (cnt >= me->MaxConsoleConnections) ? true : false;
}

static bool GetConsoleNameAndVersion(BareosSocket* ua_sock,
std::string& name_out,
BareosVersionNumber& version_out)
Expand Down Expand Up @@ -407,13 +395,7 @@ static ConsoleAuthenticator* CreateConsoleAuthenticator(UaContext* ua)

bool AuthenticateConsole(UaContext* ua)
{
if (NumberOfConsoleConnectionsExceeded()) {
Emsg0(M_ERROR, 0,
_("Number of console connections exceeded "
"MaximumConsoleConnections\n"));
return false;
}

auto num_leases = ConsoleConnectionLease::get_num_leases();
std::unique_ptr<ConsoleAuthenticator> console_authenticator(
CreateConsoleAuthenticator(ua));
if (!console_authenticator) { return false; }
Expand All @@ -424,7 +406,21 @@ bool AuthenticateConsole(UaContext* ua)
LogErrorMessage(console_authenticator->console_name_, ua);
return false;
}
if (num_leases > me->MaxConsoleConnections) {
Emsg0(M_INFO, 0,
_("Number of console connections exceeded\n"
"Maximum: %u, Current: %zu\n"),
me->MaxConsoleConnections, num_leases);
}
} else {
if (num_leases > me->MaxConsoleConnections) {
Emsg0(M_ERROR, 0,
_("Number of console connections exceeded "
"Maximum :%u, Current: %zu\n"),
me->MaxConsoleConnections, num_leases);
return false;
}

console_authenticator->AuthenticateNamedConsole();
if (!console_authenticator->auth_success_) {
LogErrorMessage(console_authenticator->console_name_, ua);
Expand Down
23 changes: 23 additions & 0 deletions core/src/dird/console_connection_lease.cc
@@ -0,0 +1,23 @@
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2023-2023 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.
*/
#include "console_connection_lease.h"

std::atomic<std::size_t> ConsoleConnectionLease::num_leases{0};
35 changes: 35 additions & 0 deletions core/src/dird/console_connection_lease.h
@@ -0,0 +1,35 @@
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2023-2023 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_DIRD_CONSOLE_CONNECTION_LEASE_H_
#define BAREOS_DIRD_CONSOLE_CONNECTION_LEASE_H_

#include <atomic>

class ConsoleConnectionLease {
static std::atomic<std::size_t> num_leases;

public:
ConsoleConnectionLease() { num_leases++; }
~ConsoleConnectionLease() { num_leases--; }
static std::size_t get_num_leases() { return num_leases; }
};
#endif // BAREOS_DIRD_CONSOLE_CONNECTION_LEASE_H_
5 changes: 3 additions & 2 deletions core/src/dird/ua_server.cc
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
Copyright (C) 2013-2022 Bareos GmbH & Co. KG
Copyright (C) 2013-2023 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
Expand Down Expand Up @@ -43,7 +43,7 @@
#include "lib/parse_conf.h"
#include "lib/thread_specific_data.h"
#include "dird/jcr_util.h"

#include "console_connection_lease.h"

namespace directordaemon {

Expand Down Expand Up @@ -91,6 +91,7 @@ void* HandleUserAgentClientRequest(BareosSocket* user_agent_socket)
ua->UA_sock = user_agent_socket;
SetJcrInThreadSpecificData(nullptr);

ConsoleConnectionLease lease; // obtain lease to count connections
bool success = AuthenticateConsole(ua);

if (!success) { ua->quit = true; }
Expand Down

0 comments on commit 73d372d

Please sign in to comment.