Compare commits
14 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
719dcf8435 | ||
|
|
901ba1d863 | ||
|
|
6795657ee4 | ||
|
|
df8129750a | ||
|
|
9be11e87e0 | ||
|
|
f070fc95da | ||
|
|
e52eb71c2b | ||
|
|
e4ebf2c787 | ||
|
|
0430052afd | ||
|
|
184a9a509d | ||
|
|
197243d20e | ||
|
|
575482e8d4 | ||
|
|
3c88d522fc | ||
|
|
7931e58a64 |
6 changed files with 424 additions and 171 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,2 +1,4 @@
|
|||
/usbguard-notifier-0.0.5.tar.gz
|
||||
/usbguard-notifier-0.0.6.tar.gz
|
||||
/usbguard-notifier-0.1.0.tar.gz
|
||||
/usbguard-notifier-0.1.1.tar.gz
|
||||
|
|
|
|||
12
0001-gcc13.patch
Normal file
12
0001-gcc13.patch
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
diff --git a/src/Serializer.hpp b/src/Serializer.hpp
|
||||
index c90a57e..d38991a 100644
|
||||
--- a/src/Serializer.hpp
|
||||
+++ b/src/Serializer.hpp
|
||||
@@ -20,6 +20,7 @@
|
||||
#ifndef SERIALIZER_HPP
|
||||
#define SERIALIZER_HPP
|
||||
|
||||
+#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
366
remove-catch.patch
Normal file
366
remove-catch.patch
Normal file
|
|
@ -0,0 +1,366 @@
|
|||
diff --git a/Makefile.am b/Makefile.am
|
||||
index 64f899e..3625717 100644
|
||||
--- a/Makefile.am
|
||||
+++ b/Makefile.am
|
||||
@@ -20,7 +20,6 @@
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
CLEANFILES =
|
||||
|
||||
-SUBDIRS = src/Tests/
|
||||
bin_PROGRAMS = usbguard-notifier
|
||||
if NOTIFIER_CLI_ENABLED
|
||||
bin_PROGRAMS += \
|
||||
@@ -31,8 +30,7 @@ EXTRA_DIST = \
|
||||
src/BuildConfig.h.in \
|
||||
README.md \
|
||||
LICENSE \
|
||||
- CHANGELOG.md \
|
||||
- src/ThirdParty/Catch2/single_include/catch2
|
||||
+ CHANGELOG.md
|
||||
|
||||
usbguard_notifier_SOURCES = \
|
||||
src/usbguard-icon.hpp \
|
||||
diff --git a/configure.ac b/configure.ac
|
||||
index 3728e4c..a867ee6 100644
|
||||
--- a/configure.ac
|
||||
+++ b/configure.ac
|
||||
@@ -127,31 +127,6 @@ AC_SUBST(SYSTEMD_UNIT_DIR, $systemd_unit_dir)
|
||||
AC_DEFINE([SYSTEMD_SUPPORT_ENABLED], [1], [Enable systemd support int the project])
|
||||
AM_CONDITIONAL([SYSTEMD_SUPPORT_ENABLED], [test "x$systemd" = xyes ])
|
||||
|
||||
-# Catch C++ library
|
||||
-AC_ARG_WITH([bundled-catch], AS_HELP_STRING([--with-bundled-catch],
|
||||
- [Build using the bundled Catch library]),
|
||||
- [with_bundled_catch=$withval], [with_bundled_catch=no])
|
||||
-if test "x$with_bundled_catch" = xyes; then
|
||||
- catch_CFLAGS="-I\$(top_srcdir)/src/ThirdParty/Catch2/single_include/catch2"
|
||||
- catch_LIBS=""
|
||||
- AC_MSG_NOTICE([Using bundled Catch library])
|
||||
- catch_summary="bundled; $catch_CFLAGS $catch_LIBS"
|
||||
-else
|
||||
- SAVE_CPPFLAGS=$CPPFLAGS
|
||||
- CPPFLAGS="-std=c++11 $CPPFLAGS -I/usr/include/catch"
|
||||
- AC_LANG_PUSH([C++])
|
||||
- AC_CHECK_HEADER([catch.hpp], [], [AC_MSG_FAILURE(catch.hpp not found or not
|
||||
- usable. Re-run with --with-bundled-catch to use the bundled library.)])
|
||||
- AC_LANG_POP
|
||||
- catch_CFLAGS="-I/usr/include/catch"
|
||||
- catch_LIBS=""
|
||||
- CPPFLAGS=$SAVE_CPPFLAGS
|
||||
- catch_summary="system-wide;
|
||||
- $catch_CFLAGS $catch_LIBS"
|
||||
-fi
|
||||
-AC_SUBST([catch_CFLAGS])
|
||||
-AC_SUBST([catch_LIBS])
|
||||
-
|
||||
CXXFLAGS_DEBUG="-g -O2"
|
||||
AC_ARG_ENABLE(
|
||||
[debug-build],
|
||||
@@ -184,7 +159,6 @@ AM_CONDITIONAL([CUSTOM_USBGUARD_DEVEL_ENABLED], [test "x$custom_usbguard_devel_e
|
||||
|
||||
AC_CONFIG_FILES([
|
||||
Makefile
|
||||
- src/Tests/Makefile
|
||||
])
|
||||
|
||||
AC_OUTPUT
|
||||
@@ -194,7 +168,6 @@ echo "============== MACROS ================="
|
||||
echo " systemd: $systemd_unit_dir"
|
||||
echo ""
|
||||
echo "========== LINKER OPTIONS ============="
|
||||
-echo " Catch: $catch_summary"
|
||||
echo " libnotify: $libnotify_summary"
|
||||
echo " libusbguard: $libusbguard_summary"
|
||||
echo " librsvg: $librsvg_summary"
|
||||
diff --git a/src/Tests/Makefile.am b/src/Tests/Makefile.am
|
||||
deleted file mode 100644
|
||||
index 54c1765..0000000
|
||||
--- a/src/Tests/Makefile.am
|
||||
+++ /dev/null
|
||||
@@ -1,45 +0,0 @@
|
||||
-##
|
||||
-## Copyright (C) 2019 Red Hat, Inc.
|
||||
-##
|
||||
-## This program is free software: you can redistribute it and/or modify
|
||||
-## it under the terms of the GNU General Public License as published by
|
||||
-## the Free Software Foundation, either version 2 of the License, or
|
||||
-## (at your option) any later version.
|
||||
-##
|
||||
-## 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 General Public License for more details.
|
||||
-##
|
||||
-## You should have received a copy of the GNU General Public License
|
||||
-## along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
-##
|
||||
-## Author(s): Zoltán Fridrich <zfridric@redhat.com>
|
||||
-##
|
||||
-
|
||||
-AM_CPPFLAGS = \
|
||||
- -I$(top_srcdir)/src \
|
||||
- @catch_CFLAGS@ \
|
||||
- -fPIC
|
||||
-
|
||||
-EXTRA_DIST = \
|
||||
- $(top_srcdir)/src/ThirdParty/Catch2
|
||||
-
|
||||
-TESTS_ENVIRONMENT = \
|
||||
- builddir=$(top_builddir) \
|
||||
- srcdir=$(top_srcdir) \
|
||||
- abs_top_srcdir=$(abs_top_srcdir)
|
||||
-
|
||||
-TESTS = \
|
||||
- test-unit
|
||||
-
|
||||
-check_PROGRAMS = \
|
||||
- test-unit
|
||||
-
|
||||
-test_unit_SOURCES=\
|
||||
- main.cpp \
|
||||
- Unit/test_notifier_cli.cpp \
|
||||
- ../NotifierCLI.hpp \
|
||||
- ../NotifierCLI.cpp \
|
||||
- ../Serializer.hpp \
|
||||
- ../Serializer.cpp
|
||||
diff --git a/src/Tests/Unit/test_notifier_cli.cpp b/src/Tests/Unit/test_notifier_cli.cpp
|
||||
deleted file mode 100644
|
||||
index d77cd71..0000000
|
||||
--- a/src/Tests/Unit/test_notifier_cli.cpp
|
||||
+++ /dev/null
|
||||
@@ -1,227 +0,0 @@
|
||||
-#include "NotifierCLI.hpp"
|
||||
-
|
||||
-#include <catch.hpp>
|
||||
-
|
||||
-using namespace usbguardNotifier;
|
||||
-
|
||||
-TEST_CASE("Notifier CLI", "[CLI]")
|
||||
-{
|
||||
- SECTION("Construct empty") {
|
||||
- CLI::map e;
|
||||
- CLI cli(e);
|
||||
- REQUIRE(cli.getDb().empty());
|
||||
- REQUIRE(cli.getIterator() == cli.getDb().cend());
|
||||
- }
|
||||
- CLI::map db = {
|
||||
- { 1, {}},
|
||||
- { 2, {}},
|
||||
- { 3, {}},
|
||||
- { 4, {}},
|
||||
- { 5, {}},
|
||||
- { 6, {}},
|
||||
- { 7, {}},
|
||||
- { 8, {}},
|
||||
- { 9, {}}
|
||||
- };
|
||||
- CLI cli(db);
|
||||
-
|
||||
- SECTION("Construct non-empty") {
|
||||
- REQUIRE(cli.getDb() == db);
|
||||
- REQUIRE(cli.getIterator() == cli.getDb().cbegin());
|
||||
- }
|
||||
-
|
||||
- SECTION("Jump") {
|
||||
- cli.jump("2");
|
||||
- REQUIRE(cli.getIterator() == db.find(2));
|
||||
- cli.jump("0");
|
||||
- REQUIRE(cli.getIterator() == db.find(2));
|
||||
- cli.jump("-1");
|
||||
- REQUIRE(cli.getIterator() == db.find(2));
|
||||
- cli.jump("10");
|
||||
- REQUIRE(cli.getIterator() == db.find(2));
|
||||
- cli.jump("9");
|
||||
- REQUIRE(cli.getIterator() == db.find(9));
|
||||
- cli.jump("9");
|
||||
- REQUIRE(cli.getIterator() == db.find(9));
|
||||
- cli.jump("1");
|
||||
- REQUIRE(cli.getIterator() == db.find(1));
|
||||
- }
|
||||
-
|
||||
- SECTION("Next") {
|
||||
- cli.jump("1");
|
||||
- REQUIRE(cli.getIterator() == cli.getDb().cbegin());
|
||||
-
|
||||
- cli.next("");
|
||||
- REQUIRE(cli.getIterator() == db.find(2));
|
||||
- cli.next("");
|
||||
- REQUIRE(cli.getIterator() == db.find(3));
|
||||
- cli.next("");
|
||||
- REQUIRE(cli.getIterator() == db.find(4));
|
||||
- cli.next("");
|
||||
- REQUIRE(cli.getIterator() == db.find(5));
|
||||
- cli.next("");
|
||||
- REQUIRE(cli.getIterator() == db.find(6));
|
||||
- cli.next("");
|
||||
- REQUIRE(cli.getIterator() == db.find(7));
|
||||
- cli.next("");
|
||||
- REQUIRE(cli.getIterator() == db.find(8));
|
||||
- cli.next("");
|
||||
- REQUIRE(cli.getIterator() == db.find(9));
|
||||
- cli.next("");
|
||||
- REQUIRE(cli.getIterator() == db.find(9));
|
||||
- }
|
||||
-
|
||||
- SECTION("Previous") {
|
||||
- cli.jump("9");
|
||||
- REQUIRE(cli.getIterator() == cli.getDb().find(9));
|
||||
-
|
||||
- cli.previous("");
|
||||
- REQUIRE(cli.getIterator() == db.find(8));
|
||||
- cli.previous("");
|
||||
- REQUIRE(cli.getIterator() == db.find(7));
|
||||
- cli.previous("");
|
||||
- REQUIRE(cli.getIterator() == db.find(6));
|
||||
- cli.previous("");
|
||||
- REQUIRE(cli.getIterator() == db.find(5));
|
||||
- cli.previous("");
|
||||
- REQUIRE(cli.getIterator() == db.find(4));
|
||||
- cli.previous("");
|
||||
- REQUIRE(cli.getIterator() == db.find(3));
|
||||
- cli.previous("");
|
||||
- REQUIRE(cli.getIterator() == db.find(2));
|
||||
- cli.previous("");
|
||||
- REQUIRE(cli.getIterator() == db.find(1));
|
||||
- cli.previous("");
|
||||
- REQUIRE(cli.getIterator() == db.find(1));
|
||||
- }
|
||||
-
|
||||
- SECTION("Execute - jump") {
|
||||
- cli.execute("jump", "2");
|
||||
- REQUIRE(cli.getIterator() == db.find(2));
|
||||
- cli.execute("jump", "0");
|
||||
- REQUIRE(cli.getIterator() == db.find(2));
|
||||
- cli.execute("jump", "-1");
|
||||
- REQUIRE(cli.getIterator() == db.find(2));
|
||||
- cli.execute("jump", "10");
|
||||
- REQUIRE(cli.getIterator() == db.find(2));
|
||||
- cli.execute("jump", "9");
|
||||
- REQUIRE(cli.getIterator() == db.find(9));
|
||||
- cli.execute("jump", "9");
|
||||
- REQUIRE(cli.getIterator() == db.find(9));
|
||||
- cli.execute("jump", "1");
|
||||
- REQUIRE(cli.getIterator() == db.find(1));
|
||||
- }
|
||||
-
|
||||
- SECTION("Execute - next") {
|
||||
- cli.execute("jump", "1");
|
||||
- REQUIRE(cli.getIterator() == cli.getDb().cbegin());
|
||||
-
|
||||
- cli.execute("next", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(2));
|
||||
- cli.execute("next", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(3));
|
||||
- cli.execute("next", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(4));
|
||||
- cli.execute("next", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(5));
|
||||
- cli.execute("next", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(6));
|
||||
- cli.execute("next", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(7));
|
||||
- cli.execute("next", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(8));
|
||||
- cli.execute("next", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(9));
|
||||
- cli.execute("next", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(9));
|
||||
- }
|
||||
-
|
||||
- SECTION("Execute - previous") {
|
||||
- cli.execute("jump", "9");
|
||||
- REQUIRE(cli.getIterator() == cli.getDb().find(9));
|
||||
-
|
||||
- cli.execute("previous", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(8));
|
||||
- cli.execute("previous", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(7));
|
||||
- cli.execute("previous", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(6));
|
||||
- cli.execute("previous", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(5));
|
||||
- cli.execute("previous", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(4));
|
||||
- cli.execute("previous", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(3));
|
||||
- cli.execute("previous", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(2));
|
||||
- cli.execute("previous", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(1));
|
||||
- cli.execute("previous", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(1));
|
||||
- }
|
||||
-
|
||||
- SECTION("Execute short - j") {
|
||||
- cli.execute("j", "2");
|
||||
- REQUIRE(cli.getIterator() == db.find(2));
|
||||
- cli.execute("j", "0");
|
||||
- REQUIRE(cli.getIterator() == db.find(2));
|
||||
- cli.execute("j", "-1");
|
||||
- REQUIRE(cli.getIterator() == db.find(2));
|
||||
- cli.execute("j", "10");
|
||||
- REQUIRE(cli.getIterator() == db.find(2));
|
||||
- cli.execute("j", "9");
|
||||
- REQUIRE(cli.getIterator() == db.find(9));
|
||||
- cli.execute("j", "9");
|
||||
- REQUIRE(cli.getIterator() == db.find(9));
|
||||
- cli.execute("j", "1");
|
||||
- REQUIRE(cli.getIterator() == db.find(1));
|
||||
- }
|
||||
-
|
||||
- SECTION("Execute short - n") {
|
||||
- cli.execute("j", "1");
|
||||
- REQUIRE(cli.getIterator() == cli.getDb().cbegin());
|
||||
-
|
||||
- cli.execute("n", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(2));
|
||||
- cli.execute("n", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(3));
|
||||
- cli.execute("n", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(4));
|
||||
- cli.execute("n", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(5));
|
||||
- cli.execute("n", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(6));
|
||||
- cli.execute("n", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(7));
|
||||
- cli.execute("n", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(8));
|
||||
- cli.execute("n", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(9));
|
||||
- cli.execute("n", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(9));
|
||||
- }
|
||||
-
|
||||
- SECTION("Execute short - p") {
|
||||
- cli.execute("j", "9");
|
||||
- REQUIRE(cli.getIterator() == cli.getDb().find(9));
|
||||
-
|
||||
- cli.execute("p", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(8));
|
||||
- cli.execute("p", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(7));
|
||||
- cli.execute("p", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(6));
|
||||
- cli.execute("p", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(5));
|
||||
- cli.execute("p", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(4));
|
||||
- cli.execute("p", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(3));
|
||||
- cli.execute("p", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(2));
|
||||
- cli.execute("p", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(1));
|
||||
- cli.execute("p", "");
|
||||
- REQUIRE(cli.getIterator() == db.find(1));
|
||||
- }
|
||||
-}
|
||||
diff --git a/src/Tests/main.cpp b/src/Tests/main.cpp
|
||||
deleted file mode 100644
|
||||
index b3143fb..0000000
|
||||
--- a/src/Tests/main.cpp
|
||||
+++ /dev/null
|
||||
@@ -1,2 +0,0 @@
|
||||
-#define CATCH_CONFIG_MAIN
|
||||
-#include <catch.hpp>
|
||||
2
sources
2
sources
|
|
@ -1 +1 @@
|
|||
SHA512 (usbguard-notifier-0.0.6.tar.gz) = 25402ff336ed89c92a2c7824e97a25c59570f6240e2e9c97fd37dabc25ed49ebe7dc051982f4aaff181eb835677ec29cd4e4dfe9efc11f07583ff5cfb92630b0
|
||||
SHA512 (usbguard-notifier-0.1.1.tar.gz) = 5540739301f4f4c83f7443b740cf7345be7928f3ed697878094dee1752eac7dedfab9eb652856bfa555be9bfa24687c4b74194afa022973848af13328f0ca1ba
|
||||
|
|
|
|||
|
|
@ -1,156 +0,0 @@
|
|||
diff --git a/src/Notifier.cpp b/src/Notifier.cpp
|
||||
index a98ca31..6653b93 100644
|
||||
--- a/src/Notifier.cpp
|
||||
+++ b/src/Notifier.cpp
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
+#include <chrono>
|
||||
|
||||
#include <usbguard/DeviceManager.hpp>
|
||||
#include <usbguard/Rule.hpp>
|
||||
@@ -41,6 +42,14 @@ Notifier::Notifier(const std::string& app_name) :
|
||||
_ser.setFileName(path);
|
||||
}
|
||||
|
||||
+Notifier::~Notifier()
|
||||
+{
|
||||
+ for (auto t : _countdownThreads) {
|
||||
+ t->join();
|
||||
+ delete t;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
void Notifier::DevicePolicyChanged(
|
||||
uint32_t id,
|
||||
usbguard::Rule::Target target_old,
|
||||
@@ -53,6 +62,20 @@ void Notifier::DevicePolicyChanged(
|
||||
|
||||
const std::string target_old_str = Rule::targetToString(target_old);
|
||||
const std::string target_new_str = Rule::targetToString(target_new);
|
||||
+
|
||||
+ DevicePresenceInfo info = getDevicePresenceObject(id);
|
||||
+ if (info.isInitialized) {
|
||||
+ if (info.target == target_old ||
|
||||
+ device_rule.substr(target_new_str.size()) == info.device_rule.substr(target_old_str.size())) {
|
||||
+ info.target = target_new;
|
||||
+ sendDevicePresenceNotification(info);
|
||||
+ return;
|
||||
+ } else {
|
||||
+ NOTIFIER_LOG() << "DevicePolicyChanged and DevicePresenceChanged " <<
|
||||
+ "with same id do not share the same rule.";
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
Rule rule = Rule::fromString(device_rule);
|
||||
|
||||
std::ostringstream body;
|
||||
@@ -70,7 +93,7 @@ void Notifier::DevicePolicyChanged(
|
||||
}
|
||||
|
||||
void Notifier::DevicePresenceChanged(
|
||||
- uint32_t /*id*/,
|
||||
+ uint32_t id,
|
||||
usbguard::DeviceManager::EventType event,
|
||||
usbguard::Rule::Target target,
|
||||
const std::string& device_rule)
|
||||
@@ -78,9 +101,41 @@ void Notifier::DevicePresenceChanged(
|
||||
using namespace usbguard;
|
||||
NOTIFIER_LOG() << "Device presence changed signal";
|
||||
|
||||
- const std::string event_str = DeviceManager::eventTypeToString(event);
|
||||
- const std::string target_str = Rule::targetToString(target);
|
||||
- Rule rule = Rule::fromString(device_rule);
|
||||
+ _deviceNotifications.emplace(std::make_pair(id, DevicePresenceInfo(event, target, device_rule)));
|
||||
+ std::thread* t = new std::thread( [this, id] { sendDevicePresenceCountdownCallback(id); } );
|
||||
+ _countdownThreads.push_back(t);
|
||||
+}
|
||||
+
|
||||
+Notifier::DevicePresenceInfo Notifier::getDevicePresenceObject(uint32_t id)
|
||||
+{
|
||||
+ DevicePresenceInfo info;
|
||||
+ _mtx.lock();
|
||||
+ auto it = _deviceNotifications.find(id);
|
||||
+ if (it != _deviceNotifications.end()) {
|
||||
+ info = it->second;
|
||||
+ _deviceNotifications.erase(it);
|
||||
+ }
|
||||
+ _mtx.unlock();
|
||||
+ return info;
|
||||
+}
|
||||
+
|
||||
+void Notifier::sendDevicePresenceCountdownCallback(uint32_t id)
|
||||
+{
|
||||
+ std::this_thread::sleep_for(std::chrono::milliseconds(_kMillisecondsDevicePolicyWait));
|
||||
+
|
||||
+ DevicePresenceInfo info = getDevicePresenceObject(id);
|
||||
+ if (info.isInitialized) {
|
||||
+ sendDevicePresenceNotification(info);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+void Notifier::sendDevicePresenceNotification(DevicePresenceInfo& info)
|
||||
+{
|
||||
+ using namespace usbguard;
|
||||
+
|
||||
+ const std::string event_str = DeviceManager::eventTypeToString(info.event);
|
||||
+ const std::string target_str = Rule::targetToString(info.target);
|
||||
+ Rule rule = Rule::fromString(info.device_rule);
|
||||
|
||||
std::ostringstream body;
|
||||
body << event_str << ' ' << rule.getName() << ": " << target_str;
|
||||
diff --git a/src/Notifier.hpp b/src/Notifier.hpp
|
||||
index 92f5c03..e420adb 100644
|
||||
--- a/src/Notifier.hpp
|
||||
+++ b/src/Notifier.hpp
|
||||
@@ -26,6 +26,9 @@
|
||||
#include <usbguard/ConfigFile.hpp>
|
||||
#include <usbguard/IPCClient.hpp>
|
||||
|
||||
+#include <thread>
|
||||
+#include <mutex>
|
||||
+
|
||||
namespace usbguardNotifier
|
||||
{
|
||||
|
||||
@@ -33,6 +36,7 @@ class Notifier : public usbguard::IPCClient
|
||||
{
|
||||
public:
|
||||
explicit Notifier(const std::string& app_name);
|
||||
+ ~Notifier();
|
||||
|
||||
void DevicePolicyChanged(
|
||||
uint32_t id,
|
||||
@@ -53,8 +57,31 @@ class Notifier : public usbguard::IPCClient
|
||||
const std::string& value_new);
|
||||
*/
|
||||
private:
|
||||
+ struct DevicePresenceInfo {
|
||||
+ bool isInitialized = false;
|
||||
+ usbguard::DeviceManager::EventType event;
|
||||
+ usbguard::Rule::Target target;
|
||||
+ std::string device_rule;
|
||||
+
|
||||
+ DevicePresenceInfo(const usbguard::DeviceManager::EventType& e,
|
||||
+ const usbguard::Rule::Target& t,
|
||||
+ const std::string& r): isInitialized(true), event(e), target(t), device_rule(r) {}
|
||||
+
|
||||
+ DevicePresenceInfo() : event(), target(), device_rule() {}
|
||||
+ };
|
||||
+
|
||||
+ DevicePresenceInfo getDevicePresenceObject(uint32_t id);
|
||||
+
|
||||
+ void sendDevicePresenceCountdownCallback(uint32_t id);
|
||||
+
|
||||
+ void sendDevicePresenceNotification(DevicePresenceInfo& info);
|
||||
+
|
||||
notify::Notify _lib;
|
||||
Serializer _ser;
|
||||
+ std::map<uint32_t, DevicePresenceInfo> _deviceNotifications;
|
||||
+ std::mutex _mtx;
|
||||
+ std::vector<std::thread*> _countdownThreads;
|
||||
+ const int _kMillisecondsDevicePolicyWait = 500;
|
||||
};
|
||||
|
||||
} // namespace usbguardNotifier
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
Name: usbguard-notifier
|
||||
Version: 0.0.6
|
||||
Release: 6%{?dist}
|
||||
Version: 0.1.1
|
||||
Release: 4%{?dist}
|
||||
Summary: A tool for detecting usbguard policy and device presence changes
|
||||
|
||||
License: GPLv2+
|
||||
License: GPL-2.0-or-later
|
||||
URL: https://github.com/Cropi/%{name}
|
||||
Source0: https://github.com/Cropi/usbguard-notifier/releases/download/%{name}-%{version}/%{name}-%{version}.tar.gz
|
||||
Patch0: remove-catch.patch
|
||||
|
||||
Requires: systemd
|
||||
|
||||
|
|
@ -16,20 +17,15 @@ BuildRequires: usbguard-devel
|
|||
BuildRequires: librsvg2-devel
|
||||
BuildRequires: libnotify-devel
|
||||
BuildRequires: asciidoc
|
||||
BuildRequires: catch1-devel
|
||||
BuildRequires: execstack
|
||||
BuildRequires: systemd-rpm-macros
|
||||
|
||||
Patch0: usbguard-notifier-rhbz1972505-merge-notifications.patch
|
||||
|
||||
%description
|
||||
USBGuard Notifier software framework detects usbguard policy modifications
|
||||
as well as device presence changes and displays them as pop-up notifications.
|
||||
|
||||
%prep
|
||||
%setup -q
|
||||
|
||||
%patch0 -p1 -b .merge-notifications
|
||||
%patch -P 0 -p1
|
||||
|
||||
%build
|
||||
mkdir -p ./m4
|
||||
|
|
@ -39,19 +35,14 @@ export CXXFLAGS="$RPM_OPT_FLAGS"
|
|||
|
||||
%configure \
|
||||
--disable-silent-rules \
|
||||
--without-bundled-catch \
|
||||
--enable-debug-build
|
||||
|
||||
%set_build_flags
|
||||
make %{?_smp_mflags}
|
||||
|
||||
%check
|
||||
make check
|
||||
|
||||
%install
|
||||
make install INSTALL='install -p' DESTDIR=%{buildroot}
|
||||
execstack -c %{buildroot}%{_bindir}/usbguard-notifier
|
||||
execstack -c %{buildroot}%{_bindir}/usbguard-notifier-cli
|
||||
|
||||
%post
|
||||
%systemd_user_post %{name}.service
|
||||
|
|
@ -73,6 +64,44 @@ execstack -c %{buildroot}%{_bindir}/usbguard-notifier-cli
|
|||
|
||||
|
||||
%changelog
|
||||
* Fri Jul 17 2026 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.1-4
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_45_Mass_Rebuild
|
||||
|
||||
* Sat Jan 17 2026 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.1-3
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_44_Mass_Rebuild
|
||||
|
||||
* Fri Jul 25 2025 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.1-2
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_43_Mass_Rebuild
|
||||
|
||||
* Thu Apr 24 2025 Attila Lakatos <alakatos@redhat.com> - 0.1.1-1
|
||||
- Rebase to 0.1.1
|
||||
- Remove catch dependency
|
||||
resolves: rhbz#2270438
|
||||
|
||||
* Sun Jan 19 2025 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.0-6
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_42_Mass_Rebuild
|
||||
|
||||
* Sat Jul 20 2024 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.0-5
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild
|
||||
|
||||
* Sat Jan 27 2024 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.0-4
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild
|
||||
|
||||
* Sat Jul 22 2023 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.0-3
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild
|
||||
|
||||
* Sat Jan 21 2023 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.0-2
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild
|
||||
|
||||
* Tue Dec 20 2022 Attila Lakatos <alakatos@redhat.com> - 0.1.0-1
|
||||
- Rebase to 0.1.0
|
||||
|
||||
* Sat Jul 23 2022 Fedora Release Engineering <releng@fedoraproject.org> - 0.0.6-8
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild
|
||||
|
||||
* Sat Jan 22 2022 Fedora Release Engineering <releng@fedoraproject.org> - 0.0.6-7
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild
|
||||
|
||||
* Fri Jul 23 2021 Fedora Release Engineering <releng@fedoraproject.org> - 0.0.6-6
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue