-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
helper.h
101 lines (81 loc) · 2.73 KB
/
helper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed in accordance with the terms specified in
* the LICENSE file found in the root directory of this source tree.
*/
#include <unordered_set>
#include <boost/variant.hpp>
#include <gtest/gtest.h>
#include <osquery/sql/sqlite_util.h>
namespace osquery {
namespace table_tests {
class IntMinMaxCheck final {
public:
explicit IntMinMaxCheck(int64_t min, int64_t max) : min_(min), max_(max){};
bool operator()(const std::string& string) const;
private:
const int64_t min_;
const int64_t max_;
};
class SpecificValuesCheck final {
public:
explicit SpecificValuesCheck(std::initializer_list<std::string> list)
: set_(list) {}
bool operator()(const std::string& string) const;
private:
const std::unordered_set<std::string> set_;
};
class CronValuesCheck final {
public:
explicit CronValuesCheck(int64_t min,
int64_t max,
std::unordered_set<std::string> values = {})
: min_(min), max_(max), values_(std::move(values)){};
bool operator()(const std::string& string) const;
private:
const int64_t min_;
const int64_t max_;
const std::unordered_set<std::string> values_;
};
bool verifyIpAddress(std::string const& value);
bool verifyEmptyStringOrIpAddress(std::string const& value);
bool verifyMacAddress(std::string const& value);
bool verifyUidGid(std::string const& value);
enum {
NormalType = 0 << 0,
IntType = 1 << 1,
NonEmpty = 1 << 2,
NonNull = 1 << 3,
NonZero = 1 << 4,
FileOnDisk = 1 << 5,
DirectoryOnDisk = 1 << 6,
ValidUUID = 1 << 7,
MD5 = 1 << 8,
SHA256 = 1 << 9,
SHA1 = 1 << 10,
Bool = 1 << 11,
EmptyOk = 1 << 12,
NullOk = 1 << 13,
NonNegativeInt = IntType | NonEmpty | NonNull | (1 << 12),
NonNegativeOrErrorInt = IntType | NonEmpty | NonNull | (1 << 13),
NonEmptyString = NonEmpty | NormalType | NonNull,
IntOrEmpty = IntType | EmptyOk | NullOk,
};
using CustomCheckerType = std::function<bool(const std::string&)>;
using ValidationDataType = boost::variant<int, CustomCheckerType>;
using ValidationMap = std::unordered_map<std::string, ValidationDataType>;
QueryData execute_query(std::string query);
void validate_row(const Row& row, const ValidationMap& validation_map);
void validate_rows(const std::vector<Row>& rows,
const ValidationMap& validation_map);
bool validate_value_using_flags(const std::string& value, int flags);
void validate_container_rows(
const std::string& table_name,
ValidationMap& validation_map,
const std::string& sql_constraints = std::string());
bool is_valid_hex(const std::string& value);
void setUpEnvironment();
} // namespace table_tests
} // namespace osquery