USBGuard
Software framework that protects your computer against rogue USB devices by implementing basic whitelisting and blacklisting capabilities.
RuleCondition.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 //
19 #pragma once
20 
21 #include "Typedefs.hpp"
22 
23 #include <string>
24 #include <memory>
25 
26 namespace usbguard
27 {
28  class Interface;
29  class Rule;
30 
34  class DLL_PUBLIC RuleConditionBase
35  {
36  public:
45  RuleConditionBase(const std::string& identifier, const std::string& parameter, bool negated = false);
46 
54  RuleConditionBase(const std::string& identifier, bool negated = false);
55 
62 
68  virtual ~RuleConditionBase();
69 
75  virtual void init(Interface* const interface_ptr);
76 
80  virtual void fini();
81 
88  virtual bool update(const Rule& rule) = 0;
89 
95  virtual RuleConditionBase* clone() const = 0;
96 
107  bool evaluate(const Rule& rule);
108 
114  const std::string& identifier() const;
115 
121  const std::string& parameter() const;
122 
130  bool hasParameter() const;
131 
137  bool isNegated() const;
138 
148  const std::string toString() const;
149 
153  const std::string toRuleString() const;
154 
164  static RuleConditionBase* getImplementation(const std::string& condition_string);
165 
177  static RuleConditionBase* getImplementation(const std::string& identifier, const std::string& parameter, bool negated);
178 
179  private:
180  const std::string _identifier;
182  const std::string _parameter;
185  const bool _negated;
187  };
188 
192  class DLL_PUBLIC RuleCondition
193  {
194  public:
201  RuleCondition();
202 
212  RuleCondition(const std::string& condition_string);
213 
219  RuleCondition(const RuleCondition& rhs);
220 
227 
234  RuleCondition& operator=(const RuleCondition& rhs);
235 
242  RuleCondition& operator=(RuleCondition&& rhs);
243 
249  RuleConditionBase* operator->();
250 
256  RuleConditionBase& operator*();
257 
263  std::string toRuleString() const;
264  private:
265  std::unique_ptr<RuleConditionBase> _condition;
267  };
268 } /*namespace usbguard */
269 
270 /* vim: set ts=2 sw=2 et */
Determines whether USB device mathing specified criteria should be authorized, deauthorized or remove...
Definition: Rule.hpp:77
Wraps any type of rule condition.
Definition: RuleCondition.hpp:192
Base class for all specialized rule condition classes.
Definition: RuleCondition.hpp:34
Allows to receive signals and to communicate with the USBGuard daemon.
Definition: Interface.hpp:40