Compare commits
1 commit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb58fe0526 |
4 changed files with 7 additions and 166 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
|||
/usbguard-notifier-0.0.5.tar.gz
|
||||
/usbguard-notifier-0.0.6.tar.gz
|
||||
/usbguard-notifier-0.1.0.tar.gz
|
||||
|
|
|
|||
2
sources
2
sources
|
|
@ -1 +1 @@
|
|||
SHA512 (usbguard-notifier-0.0.6.tar.gz) = 25402ff336ed89c92a2c7824e97a25c59570f6240e2e9c97fd37dabc25ed49ebe7dc051982f4aaff181eb835677ec29cd4e4dfe9efc11f07583ff5cfb92630b0
|
||||
SHA512 (usbguard-notifier-0.1.0.tar.gz) = b3414dbbbc2877e6ad29c8848942f8266293d6d3ba861724a61198af85d6db4cf5f1b0d0eb4af2a973288737b7b03614e9ebe39d0287a06fbe66be9e1d39d84a
|
||||
|
|
|
|||
|
|
@ -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,6 +1,6 @@
|
|||
Name: usbguard-notifier
|
||||
Version: 0.0.6
|
||||
Release: 8%{?dist}
|
||||
Version: 0.1.0
|
||||
Release: 1%{?dist}
|
||||
Summary: A tool for detecting usbguard policy and device presence changes
|
||||
|
||||
License: GPLv2+
|
||||
|
|
@ -17,11 +17,8 @@ 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.
|
||||
|
|
@ -29,8 +26,6 @@ as well as device presence changes and displays them as pop-up notifications.
|
|||
%prep
|
||||
%setup -q
|
||||
|
||||
%patch0 -p1 -b .merge-notifications
|
||||
|
||||
%build
|
||||
mkdir -p ./m4
|
||||
autoreconf -i -f -v --no-recursive ./
|
||||
|
|
@ -50,8 +45,6 @@ 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 +66,9 @@ execstack -c %{buildroot}%{_bindir}/usbguard-notifier-cli
|
|||
|
||||
|
||||
%changelog
|
||||
* 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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue