USBGuard
Software framework that protects your computer against rogue USB devices by implementing basic whitelisting and blacklisting capabilities.
Policy.hpp
1 //
2 // Copyright (C) 2017 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 // Radovan Sroka <rsroka@redhat.com>
19 //
20 #pragma once
21 
22 #include <string>
23 #include <vector>
24 
25 #include "RuleSet.hpp"
26 #include "Typedefs.hpp"
27 
28 namespace usbguard
29 {
30  class DLL_PUBLIC Policy
31  {
32  public:
33  enum class EventType {
34  Insert = 1,
35  Update = 2,
36  Remove = 3
37  };
38 
39  Policy();
40 
41  void setRuleSet(std::shared_ptr<RuleSet> ptr);
42  std::shared_ptr<RuleSet> getRuleSet();
43 
44  void setDefaultTarget(Rule::Target target);
45  Rule::Target getDefaultTarget() const;
46  void setDefaultAction(const std::string& action);
47  uint32_t appendRule(const Rule& rule, uint32_t parent_id = Rule::LastID);
48  uint32_t upsertRule(const Rule& match_rule, const Rule& new_rule, bool parent_insensitive = false);
49  std::shared_ptr<Rule> getRule(uint32_t id);
50  bool removeRule(uint32_t id);
51  std::shared_ptr<Rule> getFirstMatchingRule(std::shared_ptr<const Rule> device_rule, uint32_t from_id = 1) const;
52  std::vector<std::shared_ptr<const Rule>> getRules();
53  uint32_t assignID(std::shared_ptr<Rule> rule);
54  uint32_t assignID();
55 
63  static std::string eventTypeToString(EventType event);
64  private:
65 
66  std::shared_ptr<RuleSet> _ruleset_ptr;
67  };
68 } /* namespace usbguard */
69 
70 /* vim: set ts=2 sw=2 et */
Target
Enumeration of possible rule targets.
Definition: Rule.hpp:86
Definition: Policy.hpp:30
Determines whether USB device mathing specified criteria should be authorized, deauthorized or remove...
Definition: Rule.hpp:77
static const uint32_t LastID
Sequence number for specifying that the last rule in the ruleset should be used in context of the ope...
Definition: Rule.hpp:194