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

Limits access to the USBGuard IPC interface. More...

#include <IPCServer.hpp>

Public Types

enum  Section : uint8_t {
  NONE = 0, DEVICES = 1, POLICY = 2, PARAMETERS = 3,
  EXCEPTIONS = 4, Section::ALL = 255
}
 Possible sections for which privileges can be specified. More...
 
enum  Privilege : uint8_t {
  Privilege::NONE = 0x00, LIST = 0x01, MODIFY = 0x02, LISTEN = 0x08,
  Privilege::ALL = 0xff
}
 Possible privileges and their hexadecimal values. More...
 

Public Member Functions

 AccessControl ()
 Constructs empty AccessControl object containing no privileges.
 
 AccessControl (const std::string &access_control_string)
 Constructs AccessControl object by loading access control from given access_control_string. More...
 
 AccessControl (Section section, Privilege privilege)
 Constructs AccessControl object with given privilege. More...
 
 AccessControl (const AccessControl &rhs)
 Constructs AccessControl object that is a copy of rhs. More...
 
AccessControloperator= (const AccessControl &rhs)
 Assignes insides of object rhs to this. More...
 
bool hasPrivilege (Section section, Privilege privilege) const
 Tests whether access control contains given privilege. More...
 
void setPrivilege (Section section, Privilege privilege)
 Inserts privilege into access control. More...
 
void clear ()
 Clears access control. More...
 
void load (std::istream &stream)
 Loads access control from given stream. More...
 
void save (std::ostream &stream) const
 Writes access control to given output stream. More...
 
void merge (const AccessControl &rhs)
 Merges all privileges of rhs with this. More...
 
void merge (const std::string &access_control_string)
 Merges all privileges contained in access_control_string with this. More...
 

Static Public Member Functions

static Section sectionFromString (const std::string &section_string)
 Returns section representation of given string. More...
 
static std::string sectionToString (const Section section)
 Returns string representation of given section. More...
 
static Privilege privilegeFromString (const std::string &privilege_string)
 Returns privilege representation of given string. More...
 
static std::string privilegeToString (const Privilege privilege)
 Returns string representation of given privilege. More...
 

Detailed Description

Limits access to the USBGuard IPC interface.

Available sections, privileges and their meaning:

-Devices -modify: change authorization state of devices including permanent changes (i.e. modification of device specific rules in the policy). -list : Ability to get a list of recognized devices and their attributes. -listen: Listen to device presence and device policy changes. -Policy -modify: Append rules to or remove any rules from the policy. -list : Ability to view the currently enforced policy. -Exceptions -listen: Receive exception messages. -Parameters -modify: Set values of run-time parameters.

There are also special sections and privileges NONE and ALL which can be used to represent none or all of the sections or privileges respectively.

Member Enumeration Documentation

◆ Privilege

Possible privileges and their hexadecimal values.

Enumerator
NONE 

Represents no priviliges.

ALL 

Represents all previous privileges except for NONE.

◆ Section

Possible sections for which privileges can be specified.

Enumerator
ALL 

Represents all previous sections except for NONE.

Constructor & Destructor Documentation

◆ AccessControl() [1/3]

usbguard::IPCServer::AccessControl::AccessControl ( const std::string &  access_control_string)

Constructs AccessControl object by loading access control from given access_control_string.

Parameters
access_control_stringString from which the access control should be loaded.
See also
load()

◆ AccessControl() [2/3]

usbguard::IPCServer::AccessControl::AccessControl ( Section  section,
Privilege  privilege 
)

Constructs AccessControl object with given privilege.

Parameters
sectionSection for which the privilege should be set.
privilegePrivilege to be set.
See also
setPrivilege()

◆ AccessControl() [3/3]

usbguard::IPCServer::AccessControl::AccessControl ( const AccessControl rhs)

Constructs AccessControl object that is a copy of rhs.

Parameters
rhsObject to copy.

Member Function Documentation

◆ clear()

void usbguard::IPCServer::AccessControl::clear ( )

Clears access control.

In other words, removes all priviledes for all sections from access control and leaves it empty.

◆ hasPrivilege()

bool usbguard::IPCServer::AccessControl::hasPrivilege ( Section  section,
Privilege  privilege 
) const

Tests whether access control contains given privilege.

Parameters
sectionSection for which the privilege should be tested.
privilegePrivilege to test.
Returns
True if access control contains given privilege.
Exceptions
USBGUARD_BUGIf section is either ALL or NONE.

◆ load()

void usbguard::IPCServer::AccessControl::load ( std::istream &  stream)

Loads access control from given stream.

Every line in given input stream is parsed for presence of tuple (Section, Privilege) which is then inserted into access control using setPrivilege().

Parameters
streamInput stream to parse for access control.
See also
setPrivilege()

◆ merge() [1/2]

void usbguard::IPCServer::AccessControl::merge ( const AccessControl rhs)

Merges all privileges of rhs with this.

Parameters
rhsObject whose privileges will be merged with this.

◆ merge() [2/2]

void usbguard::IPCServer::AccessControl::merge ( const std::string &  access_control_string)

Merges all privileges contained in access_control_string with this.

Parameters
access_control_stringString containing privileges that should be merged with this.

◆ operator=()

IPCServer::AccessControl & usbguard::IPCServer::AccessControl::operator= ( const AccessControl rhs)

Assignes insides of object rhs to this.

Parameters
rhsObject to assign.
Returns
This.

◆ privilegeFromString()

IPCServer::AccessControl::Privilege usbguard::IPCServer::AccessControl::privilegeFromString ( const std::string &  privilege_string)
static

Returns privilege representation of given string.

Parameters
privilege_stringString to parse.
Returns
Privilege.
Exceptions
runtime_errorIf given string is not a valid privilege.

◆ privilegeToString()

std::string usbguard::IPCServer::AccessControl::privilegeToString ( const Privilege  privilege)
static

Returns string representation of given privilege.

Parameters
privilegePrivilege to transform.
Returns
String representation of given Privilege.
Exceptions
runtime_errorIf given privilege is not a valid Privilege.

◆ save()

void usbguard::IPCServer::AccessControl::save ( std::ostream &  stream) const

Writes access control to given output stream.

Access control is saved in following format: <section>=<privilege1>[,<privilege2>[,<privilege3>]] where every section is on a separate line.

Parameters
streamStream to which this access control should be saved.

◆ sectionFromString()

IPCServer::AccessControl::Section usbguard::IPCServer::AccessControl::sectionFromString ( const std::string &  section_string)
static

Returns section representation of given string.

Parameters
section_stringString to parse.
Returns
Section.
Exceptions
runtime_errorIf given string is not a valid Section.

◆ sectionToString()

std::string usbguard::IPCServer::AccessControl::sectionToString ( const Section  section)
static

Returns string representation of given section.

Parameters
sectionSection to transform.
Returns
String representation of given Section.
Exceptions
runtime_errorIf given section is not a valid Section.

◆ setPrivilege()

void usbguard::IPCServer::AccessControl::setPrivilege ( Section  section,
Privilege  privilege 
)

Inserts privilege into access control.

Parameters
sectionSection for which the privilege should be set.
privilegePrivilede to be set.
Exceptions
USBGUARD_BUGIf section is NONE.

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