USBGuard
Software framework that protects your computer against rogue USB devices by implementing basic whitelisting and blacklisting capabilities.
Public Member Functions | List of all members
usbguard::IPCClient Class Reference

Communicates with USBGuard service (IPCServer). More...

#include <IPCClient.hpp>

Inheritance diagram for usbguard::IPCClient:
usbguard::Interface

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< RulelistRules (const std::string &label) override
 List the current rule set (policy) used by the USBGuard daemon. More...
 
const std::vector< RulelistRules ()
 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< RulelistDevices (const std::string &query) override
 List devices that match the specified query. More...
 
const std::vector< RulelistDevices ()
 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...
 

Detailed Description

Communicates with USBGuard service (IPCServer).

Constructor & Destructor Documentation

◆ IPCClient()

usbguard::IPCClient::IPCClient ( bool  connected = false)

Constructs IPC client.

Parameters
connectedIf this flag is set to true, then it tries to connect to USBGuard IPC service and starts IPC client main loop.
See also
connect()

◆ ~IPCClient()

usbguard::IPCClient::~IPCClient ( )
virtualdefault

Disconnects from an USBGuard IPC service and destructs this object.

See also
disconnect()

Member Function Documentation

◆ appendRule()

uint32_t usbguard::IPCClient::appendRule ( const std::string &  rule_spec,
uint32_t  parent_id,
bool  permanent 
)
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.

Parameters
rule_specThe rule that should be appended to the policy.
parent_idRule ID of the parent rule.
permanentDetermines whether the rule will be added to the policy file.
Returns
The rule ID assigned to the successfully appended rule.

Implements usbguard::Interface.

◆ applyDevicePolicy()

uint32_t usbguard::IPCClient::applyDevicePolicy ( uint32_t  id,
Rule::Target  target,
bool  permanent 
)
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.

Parameters
idDevice ID of the device to authorize.
targetDevice authorization target.
permanentBoolean flag specifying whether an allow rule should be appended to the policy.
Returns
If 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.

◆ connect()

void usbguard::IPCClient::connect ( )

Creates connection to an USBGuard IPC service.

Starts IPC client main loop.

Exceptions
ErrnoExceptionIf there is no service called "usbguard".
ExceptionIf we received bad file descriptor to poll.

◆ DevicePolicyChanged()

virtual void usbguard::IPCClient::DevicePolicyChanged ( uint32_t  id,
Rule::Target  target_old,
Rule::Target  target_new,
const std::string &  device_rule,
uint32_t  rule_id 
)
inlineoverridevirtual

Defines algorithm to perform in the case that USB device authorization target has been changed.

See also
DevicePolicyChanged()

Implements usbguard::Interface.

◆ DevicePresenceChanged()

virtual void usbguard::IPCClient::DevicePresenceChanged ( uint32_t  id,
DeviceManager::EventType  event,
Rule::Target  target,
const std::string &  device_rule 
)
inlineoverridevirtual

Defines algorithm to perform in the case that USB device presence has been changed.

See also
DevicePresenceChanged()

Implements usbguard::Interface.

◆ disconnect()

void usbguard::IPCClient::disconnect ( )

Disconnects from an USBGuard IPC service.

Stops IPC client main loop.

◆ ExceptionMessage()

virtual void usbguard::IPCClient::ExceptionMessage ( const std::string &  context,
const std::string &  object,
const std::string &  reason 
)
inlineoverridevirtual

Defines algorithm to perform in the case that exception has arose.

See also
ExceptionMessage()

Implements usbguard::Interface.

◆ getParameter()

std::string usbguard::IPCClient::getParameter ( const std::string &  name)
overridevirtual

Get value of a runtime parameter.

Parameters
nameName of runtime parameter.
Returns
Value of runtime parameter.

Implements usbguard::Interface.

◆ IPCDisconnected()

virtual void usbguard::IPCClient::IPCDisconnected ( bool  exception_initiated,
const IPCException exception 
)
inlinevirtual

Defines algorithm to perform in the case of IPC disconnection.

Parameters
exception_initiatedDetermines whether disconnection was caused by an exception.
exceptionException that caused the disconnection. Exception is valid only if exception_initiated is set to true.

◆ isConnected()

bool usbguard::IPCClient::isConnected ( ) const

Checks whether client is connected to USBGuard IPC service.

Returns
True if this client is connected to USBGuard IPC service, false otherwise.

◆ listDevices() [1/2]

const std::vector< Rule > usbguard::IPCClient::listDevices ( const std::string &  query)
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.

Parameters
queryQuery in the rule language syntax used to match devices.
Returns
Vector of device specific rules that match the query.

Implements usbguard::Interface.

◆ listDevices() [2/2]

const std::vector<Rule> usbguard::IPCClient::listDevices ( )
inline

List all devices recognized by USBGuard daemon.

Note
Left for compatibility.
Returns
Vector of device specific rules.

◆ listRules() [1/2]

const std::vector< Rule > usbguard::IPCClient::listRules ( const std::string &  label)
overridevirtual

List the current rule set (policy) used by the USBGuard daemon.

The rules are returned in the same order as they are evaluated.

Parameters
queryQuery used for matching rules.
Returns
Vector of rules.

Implements usbguard::Interface.

◆ listRules() [2/2]

const std::vector<Rule> usbguard::IPCClient::listRules ( )
inline

List the current rule set (policy) used by the USBGuard daemon.

The rules are returned in the same order as they are evaluated.

Returns
Vector of rules.

◆ PropertyParameterChanged()

virtual void usbguard::IPCClient::PropertyParameterChanged ( const std::string &  name,
const std::string &  value_old,
const std::string &  value_new 
)
inlineoverridevirtual

Defines algorithm to perform in the case that property parameter has been changed.

See also
PropertyParameterChanged()

Implements usbguard::Interface.

◆ removeRule()

void usbguard::IPCClient::removeRule ( uint32_t  id)
overridevirtual

Remove a rule from the current policy.

Parameters
idThe rule ID of the rule to be removed.

Implements usbguard::Interface.

◆ setParameter()

std::string usbguard::IPCClient::setParameter ( const std::string &  name,
const std::string &  value 
)
overridevirtual

Set value of a runtime parameter.

Parameters
nameName of runtime parameter.
valueValue of runtime parameter.
Returns
Previous value of runtime parameter.

Implements usbguard::Interface.


The documentation for this class was generated from the following files: