|
| 1 | +From aa19993dc833771333149829fb36c79709f4dff4 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Marek Blaha < [email protected]> |
| 3 | +Date: Mon, 12 Feb 2024 09:40:02 +0100 |
| 4 | +Subject: [PATCH] dnfdaemon: Limit number of simultaneously active sessions |
| 5 | + |
| 6 | +Signed-off-by: Azure Linux Security Servicing Account < [email protected]> |
| 7 | +Upstream-reference: https://github.com/rpm-software-management/dnf5/commit/c090ffeb79da57b88d51da6ee76f02f6512c7d91.patch |
| 8 | +--- |
| 9 | + dnf5daemon-server/session_manager.cpp | 12 ++++++++++++ |
| 10 | + 1 file changed, 12 insertions(+) |
| 11 | + |
| 12 | +diff --git a/dnf5daemon-server/session_manager.cpp b/dnf5daemon-server/session_manager.cpp |
| 13 | +index 57c036b..d60d7ca 100644 |
| 14 | +--- a/dnf5daemon-server/session_manager.cpp |
| 15 | ++++ b/dnf5daemon-server/session_manager.cpp |
| 16 | +@@ -26,11 +26,15 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>. |
| 17 | + #include <sdbus-c++/sdbus-c++.h> |
| 18 | + |
| 19 | + #include <iostream> |
| 20 | ++#include <numeric> |
| 21 | + #include <random> |
| 22 | + #include <sstream> |
| 23 | + #include <string> |
| 24 | + #include <thread> |
| 25 | + |
| 26 | ++// TODO(mblaha): Make this constant configurable |
| 27 | ++const int MAX_SESSIONS = 3; |
| 28 | ++ |
| 29 | + SessionManager::SessionManager() { |
| 30 | + connection = sdbus::createSystemBusConnection(dnfdaemon::DBUS_NAME); |
| 31 | + dbus_register(); |
| 32 | +@@ -98,6 +102,14 @@ sdbus::MethodReply SessionManager::open_session(sdbus::MethodCall & call) { |
| 33 | + if (!active) { |
| 34 | + throw sdbus::Error(dnfdaemon::ERROR, "Cannot open new session."); |
| 35 | + } |
| 36 | ++ // limit number of simultaneously opened sessions |
| 37 | ++ const int num_sessions = std::accumulate( |
| 38 | ++ sessions.begin(), sessions.end(), 0, [](int sum, const auto & sender) { return sum + sender.second.size(); }); |
| 39 | ++ if (num_sessions >= MAX_SESSIONS) { |
| 40 | ++ auto reply = call.createErrorReply(sdbus::Error( |
| 41 | ++ dnfdaemon::ERROR, "Cannot open new session - maximal number of simultaneously opened sessions achieved.")); |
| 42 | ++ return reply; |
| 43 | ++ } |
| 44 | + |
| 45 | + auto sender = call.getSender(); |
| 46 | + dnfdaemon::KeyValueMap configuration; |
| 47 | +-- |
| 48 | +2.45.4 |
| 49 | + |
0 commit comments