USBGuard
Software framework that protects your computer against rogue USB devices by implementing basic whitelisting and blacklisting capabilities.
|
Communicates with USBGuard service (IPCServer). More...
#include <IPCClient.hpp>
Public Member Functions | |
IPCClient (bool connected=false) | |
Constructs IPC client. More... | |
virtual | ~IPCClient () |
Disconnects from an USBGuard IPC service and destructs this object. More... | |
void | connect () |
Creates connection to an USBGuard IPC service. More... | |
void | disconnect () |
Disconnects from an USBGuard IPC service. More... | |
bool | isConnected () const |
Checks whether client is connected to USBGuard IPC service. More... | |
void | wait () |
Wait for IPC client main loop to finish its work. | |
std::string | setParameter (const std::string &name, const std::string &value) override |
Set value of a runtime parameter. More... | |
std::string | getParameter (const std::string &name) override |
Get value of a runtime parameter. More... | |
uint32_t | appendRule (const std::string &rule_spec, uint32_t parent_id, bool permanent) override |
Append a new rule to the current policy. More... | |
void | removeRule (uint32_t id) override |
Remove a rule from the current policy. More... | |
const std::vector< Rule > | listRules (const std::string &label) override |
List the current rule set (policy) used by the USBGuard daemon. More... | |
const std::vector< Rule > | listRules () |
List the current rule set (policy) used by the USBGuard daemon. More... | |
uint32_t | applyDevicePolicy (uint32_t id, Rule::Target target, bool permanent) override |
Apply an authorization target to a device. More... | |
const std::vector< Rule > | listDevices (const std::string &query) override |
List devices that match the specified query. More... | |
const std::vector< Rule > | listDevices () |
List all devices recognized by USBGuard daemon. More... | |
virtual void | IPCConnected () |
Defines algorithm to perform in the case of IPC connection. | |
virtual void | IPCDisconnected (bool exception_initiated, const IPCException &exception) |
Defines algorithm to perform in the case of IPC disconnection. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
Communicates with USBGuard service (IPCServer).
usbguard::IPCClient::IPCClient | ( | bool | connected = false | ) |
Constructs IPC client.
connected | If this flag is set to true, then it tries to connect to USBGuard IPC service and starts IPC client main loop. |
|
virtualdefault |
Disconnects from an USBGuard IPC service and destructs this object.
|
overridevirtual |
Append a new rule to the current policy.
Using the parent_id
parameter, the rule can be inserted anywhere in the policy, not only at the end. When the rule is successfully appended, the ID assigned to the new rule is returned.
rule_spec | The rule that should be appended to the policy. |
parent_id | Rule ID of the parent rule. |
permanent | Determines whether the rule will be added to the policy file. |
Implements usbguard::Interface.
|
overridevirtual |
Apply an authorization target to a device.
If the permanent
flag is set to true, a rule will be appended to the policy or an existing device rule will be modified in order to permanently store the authorization decision. Successful execution of this method will cause the DevicePolicyChanged signal to be broadcasted if the device authorization target was different then the applied target.
id | Device ID of the device to authorize. |
target | Device authorization target. |
permanent | Boolean flag specifying whether an allow rule should be appended to the policy. |
permanent
was set to true, the method will return an ID of the rule that was modified or created because of this request. Implements usbguard::Interface.
void usbguard::IPCClient::connect | ( | ) |
Creates connection to an USBGuard IPC service.
Starts IPC client main loop.
ErrnoException | If there is no service called "usbguard". |
Exception | If we received bad file descriptor to poll. |
|
inlineoverridevirtual |
Defines algorithm to perform in the case that USB device authorization target has been changed.
Implements usbguard::Interface.
|
inlineoverridevirtual |
Defines algorithm to perform in the case that USB device presence has been changed.
Implements usbguard::Interface.
void usbguard::IPCClient::disconnect | ( | ) |
Disconnects from an USBGuard IPC service.
Stops IPC client main loop.
|
inlineoverridevirtual |
Defines algorithm to perform in the case that exception has arose.
Implements usbguard::Interface.
|
overridevirtual |
Get value of a runtime parameter.
name | Name of runtime parameter. |
Implements usbguard::Interface.
|
inlinevirtual |
Defines algorithm to perform in the case of IPC disconnection.
exception_initiated | Determines whether disconnection was caused by an exception. |
exception | Exception that caused the disconnection. Exception is valid only if exception_initiated is set to true. |
bool usbguard::IPCClient::isConnected | ( | ) | const |
Checks whether client is connected to USBGuard IPC service.
|
overridevirtual |
List devices that match the specified query.
The query uses the rule language syntax and the devices are returned as device specific rules. The target in each rule represents the current authorization state of the device. Order of the returned devices is not defined and should not be relied upon.
query | Query in the rule language syntax used to match devices. |
Implements usbguard::Interface.
|
inline |
List all devices recognized by USBGuard daemon.
|
overridevirtual |
List the current rule set (policy) used by the USBGuard daemon.
The rules are returned in the same order as they are evaluated.
query | Query used for matching rules. |
Implements usbguard::Interface.
|
inline |
List the current rule set (policy) used by the USBGuard daemon.
The rules are returned in the same order as they are evaluated.
|
inlineoverridevirtual |
Defines algorithm to perform in the case that property parameter has been changed.
Implements usbguard::Interface.
|
overridevirtual |
Remove a rule from the current policy.
id | The rule ID of the rule to be removed. |
Implements usbguard::Interface.
|
overridevirtual |
Set value of a runtime parameter.
name | Name of runtime parameter. |
value | Value of runtime parameter. |
Implements usbguard::Interface.