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::Interface Class Referenceabstract

Allows to receive signals and to communicate with the USBGuard daemon. More...

#include <Interface.hpp>

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

Public Member Functions

virtual std::string setParameter (const std::string &name, const std::string &value)=0
 Set value of a runtime parameter. More...
 
virtual std::string getParameter (const std::string &name)=0
 Get value of a runtime parameter. More...
 
virtual uint32_t appendRule (const std::string &rule_spec, uint32_t parent_id, bool permanent)=0
 Append a new rule to the current policy. More...
 
virtual void removeRule (uint32_t id)=0
 Remove a rule from the current policy. More...
 
virtual const std::vector< RulelistRules (const std::string &query)=0
 List the current rule set (policy) used by the USBGuard daemon. More...
 
virtual uint32_t applyDevicePolicy (uint32_t id, Rule::Target target, bool permanent)=0
 Apply an authorization target to a device. More...
 
virtual const std::vector< RulelistDevices (const std::string &query)=0
 List devices that match the specified query. More...
 
virtual void DevicePresenceChanged (uint32_t id, DeviceManager::EventType event, Rule::Target target, const std::string &device_rule)=0
 Notify that a USB device was already present when USBGuard was started. More...
 
virtual void DevicePolicyChanged (uint32_t id, Rule::Target target_old, Rule::Target target_new, const std::string &device_rule, uint32_t rule_id)=0
 Notify about a change of a USB device authorization target. More...
 
virtual void PropertyParameterChanged (const std::string &name, const std::string &value_old, const std::string &value_new)=0
 Notify about a change of a property parameter. More...
 
virtual void ExceptionMessage (const std::string &context, const std::string &object, const std::string &reason)=0
 Notify about an exception. More...
 

Detailed Description

Allows to receive signals and to communicate with the USBGuard daemon.

Member Function Documentation

◆ appendRule()

virtual uint32_t usbguard::Interface::appendRule ( const std::string &  rule_spec,
uint32_t  parent_id,
bool  permanent 
)
pure virtual

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.

Implemented in usbguard::IPCClient.

◆ applyDevicePolicy()

virtual uint32_t usbguard::Interface::applyDevicePolicy ( uint32_t  id,
Rule::Target  target,
bool  permanent 
)
pure virtual

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.

Implemented in usbguard::IPCClient.

◆ DevicePolicyChanged()

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

Notify about a change of a USB device authorization target.

The device attribute dictionary contains the following attributes:

  • id (the USB device ID in the form VID:PID)
  • name
  • serial
  • via-port
  • hash
  • parent-hash
  • with-interface
Parameters
idID of the device.
target_oldPrevious authorization target.
target_newCurrent authorization target.
device_ruleDevice specific rule.
rule_idRule ID of the matched rule. Otherwise a reserved rule ID value is used.

Implemented in usbguard::IPCServer, and usbguard::IPCClient.

◆ DevicePresenceChanged()

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

Notify that a USB device was already present when USBGuard was started.

The device attribute dictionary contains the following attributes:

  • id (the USB device ID in the form VID:PID)
  • name
  • serial
  • via-port
  • hash
  • parent-hash
  • with-interface

The USB interface types are represented as strings of the form AA:BB:CC, where AA, BB and CC are hexadecimal numbers representing the class, subclass and protocol of the interface as defined by the USB standard.

Parameters
idID of the device.
eventType of the presence change event.
targetThe current authorization target of the device.
device_ruleDevice specific rule.

Implemented in usbguard::IPCServer, and usbguard::IPCClient.

◆ ExceptionMessage()

virtual void usbguard::Interface::ExceptionMessage ( const std::string &  context,
const std::string &  object,
const std::string &  reason 
)
pure virtual

Notify about an exception.

Parameters
contextDescription or identifier of the exception context.
objectDescription or identifier of the object which caused the exception.
reasonReason explaining why the exception was generated.

Implemented in usbguard::IPCServer, and usbguard::IPCClient.

◆ getParameter()

virtual std::string usbguard::Interface::getParameter ( const std::string &  name)
pure virtual

Get value of a runtime parameter.

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

Implemented in usbguard::IPCClient.

◆ listDevices()

virtual const std::vector<Rule> usbguard::Interface::listDevices ( const std::string &  query)
pure virtual

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.

Implemented in usbguard::IPCClient.

◆ listRules()

virtual const std::vector<Rule> usbguard::Interface::listRules ( const std::string &  query)
pure virtual

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.

Implemented in usbguard::IPCClient.

◆ PropertyParameterChanged()

virtual void usbguard::Interface::PropertyParameterChanged ( const std::string &  name,
const std::string &  value_old,
const std::string &  value_new 
)
pure virtual

Notify about a change of a property parameter.

Parameters
namePolicy name.
value_oldPrevious policy value.
value_newCurrent policy value.

Implemented in usbguard::IPCServer, and usbguard::IPCClient.

◆ removeRule()

virtual void usbguard::Interface::removeRule ( uint32_t  id)
pure virtual

Remove a rule from the current policy.

Parameters
idThe rule ID of the rule to be removed.

Implemented in usbguard::IPCClient.

◆ setParameter()

virtual std::string usbguard::Interface::setParameter ( const std::string &  name,
const std::string &  value 
)
pure virtual

Set value of a runtime parameter.

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

Implemented in usbguard::IPCClient.


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