USBGuard
Software framework that protects your computer against rogue USB devices by implementing basic whitelisting and blacklisting capabilities.
IPCClient.hpp
1 //
2 // Copyright (C) 2015 Red Hat, Inc.
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // Authors: Daniel Kopecek <dkopecek@redhat.com>
18 //
19 #pragma once
20 
21 #include "DeviceManager.hpp"
22 #include "Exception.hpp"
23 #include "Interface.hpp"
24 #include "Typedefs.hpp"
25 
26 #include <string>
27 #include <vector>
28 #include <memory>
29 
30 #include <cstdint>
31 
32 namespace usbguard
33 {
34  class IPCClientPrivate;
35 
40  class DLL_PUBLIC IPCClient : public Interface
41  {
42  public:
43 
52  IPCClient(bool connected = false);
53 
60  virtual ~IPCClient();
61 
71  void connect();
72 
78  void disconnect();
79 
87  bool isConnected() const;
88 
92  void wait();
93 
97  std::string setParameter(const std::string& name, const std::string& value) override;
98 
102  std::string getParameter(const std::string& name) override;
103 
107  uint32_t appendRule(const std::string& rule_spec, uint32_t parent_id, bool permanent) override;
108 
112  void removeRule(uint32_t id) override;
113 
117  const std::vector<Rule> listRules(const std::string& label) override;
118 
126  const std::vector<Rule> listRules()
127  {
128  return listRules("");
129  }
130 
134  uint32_t applyDevicePolicy(uint32_t id, Rule::Target target, bool permanent) override;
135 
139  const std::vector<Rule> listDevices(const std::string& query) override;
140 
148  const std::vector<Rule> listDevices()
149  {
150  return listDevices("match");
151  }
152 
156  virtual void IPCConnected() {}
157 
166  virtual void IPCDisconnected(bool exception_initiated, const IPCException& exception)
167  {
168  (void)exception_initiated;
169  (void)exception;
170  }
171 
179  virtual void DevicePresenceChanged(uint32_t id,
181  Rule::Target target,
182  const std::string& device_rule) override
183  {
184  (void)id;
185  (void)event;
186  (void)target;
187  (void)device_rule;
188  }
189 
197  virtual void DevicePolicyChanged(uint32_t id,
198  Rule::Target target_old,
199  Rule::Target target_new,
200  const std::string& device_rule,
201  uint32_t rule_id) override
202  {
203  (void)id;
204  (void)target_old;
205  (void)target_new;
206  (void)device_rule;
207  (void)rule_id;
208  }
209 
217  virtual void PropertyParameterChanged(const std::string& name,
218  const std::string& value_old,
219  const std::string& value_new) override
220  {
221  (void)name;
222  (void)value_old;
223  (void)value_new;
224  }
225 
232  virtual void ExceptionMessage(const std::string& context,
233  const std::string& object,
234  const std::string& reason) override
235  {
236  (void)context;
237  (void)object;
238  (void)reason;
239  }
240 
241  private:
242  std::unique_ptr<IPCClientPrivate> d_pointer;
243  };
244 
245 } /* namespace usbguard */
246 
247 /* vim: set ts=2 sw=2 et */
Target
Enumeration of possible rule targets.
Definition: Rule.hpp:86
const std::vector< Rule > listDevices()
List all devices recognized by USBGuard daemon.
Definition: IPCClient.hpp:148
Communicates with USBGuard service (IPCServer).
Definition: IPCClient.hpp:40
virtual void PropertyParameterChanged(const std::string &name, const std::string &value_old, const std::string &value_new) override
Defines algorithm to perform in the case that property parameter has been changed.
Definition: IPCClient.hpp:217
virtual void ExceptionMessage(const std::string &context, const std::string &object, const std::string &reason) override
Defines algorithm to perform in the case that exception has arose.
Definition: IPCClient.hpp:232
virtual void DevicePolicyChanged(uint32_t id, Rule::Target target_old, Rule::Target target_new, const std::string &device_rule, uint32_t rule_id) override
Defines algorithm to perform in the case that USB device authorization target has been changed.
Definition: IPCClient.hpp:197
const std::vector< Rule > listRules()
List the current rule set (policy) used by the USBGuard daemon.
Definition: IPCClient.hpp:126
virtual void IPCConnected()
Defines algorithm to perform in the case of IPC connection.
Definition: IPCClient.hpp:156
virtual void DevicePresenceChanged(uint32_t id, DeviceManager::EventType event, Rule::Target target, const std::string &device_rule) override
Defines algorithm to perform in the case that USB device presence has been changed.
Definition: IPCClient.hpp:179
virtual void IPCDisconnected(bool exception_initiated, const IPCException &exception)
Defines algorithm to perform in the case of IPC disconnection.
Definition: IPCClient.hpp:166
EventType
Type of event that took place on the device.
Definition: DeviceManager.hpp:51
Definition: Exception.hpp:140
Allows to receive signals and to communicate with the USBGuard daemon.
Definition: Interface.hpp:40