mirror of
https://github.com/valitydev/osquery-1.git
synced 2024-11-07 18:08:53 +00:00
971bee4441
fbshipit-source-id: 8ffef5e6a393ac67ce56dcb74845402e43d964a0
61 lines
1.7 KiB
C++
61 lines
1.7 KiB
C++
/**
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under both the Apache 2.0 license (found in the
|
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
|
* in the COPYING file in the root directory of this source tree).
|
|
* You may select, at your option, one of the above-listed licenses.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
#include <unordered_map>
|
|
|
|
#include <gtest/gtest_prod.h>
|
|
|
|
#include <osquery/core.h>
|
|
#include <osquery/expected.h>
|
|
#include <osquery/killswitch.h>
|
|
#include <osquery/utils/mutex.h>
|
|
#include <osquery/plugins/plugin.h>
|
|
#include <osquery/query.h>
|
|
|
|
namespace osquery {
|
|
|
|
/**
|
|
* @brief Interface class for killswitch plugins.
|
|
*/
|
|
class KillswitchPlugin : public Plugin {
|
|
public:
|
|
/// Main entrypoint for killswitch plugin requests
|
|
virtual Status call(const PluginRequest& request,
|
|
PluginResponse& response) override;
|
|
|
|
protected:
|
|
void addCacheEntry(const std::string& key, bool value);
|
|
void setCache(const std::unordered_map<std::string, bool>& killswitchMap);
|
|
|
|
enum class ParseMapJSONError {
|
|
IncorrectKeyType = 1,
|
|
IncorrectValueType = 2,
|
|
UnknownParsingProblem = 3,
|
|
MissingKey = 4
|
|
};
|
|
static Expected<std::unordered_map<std::string, bool>, ParseMapJSONError>
|
|
parseMapJSON(const std::string& content);
|
|
|
|
private:
|
|
enum class IsEnabledError { NoKeyFound = 1 };
|
|
Expected<bool, IsEnabledError> isEnabled(const std::string& key);
|
|
std::unordered_map<std::string, bool> killswitchMap_;
|
|
mutable Mutex mutex_;
|
|
|
|
private:
|
|
FRIEND_TEST(KillswitchTests, test_killswitch_plugin);
|
|
FRIEND_TEST(KillswitchFilesystemTests,
|
|
test_killswitch_filesystem_plugin_legit);
|
|
};
|
|
} // namespace osquery
|