mirror of
https://github.com/valitydev/osquery-1.git
synced 2024-11-07 09:58:54 +00:00
Merge pull request #854 from theopolis/osqueryi_tmp
[Fix #852] Use a user-specific temporary dir for shell state
This commit is contained in:
commit
dd354c279d
@ -8,10 +8,12 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <pwd.h>
|
||||
#include <syslog.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <boost/algorithm/string/trim.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <osquery/config.h>
|
||||
#include <osquery/core.h>
|
||||
@ -112,6 +114,28 @@ Initializer::Initializer(int argc, char* argv[], ToolType tool)
|
||||
FLAGS_logger_plugin = STR(OSQUERY_DEFAULT_LOGGER_PLUGIN);
|
||||
#endif
|
||||
|
||||
if (tool == OSQUERY_TOOL_SHELL) {
|
||||
// The shell is transient, rewrite config-loaded paths.
|
||||
osquery::FLAGS_disable_logging = true;
|
||||
|
||||
// Get the caller's home dir for temporary storage/state management.
|
||||
auto user = getpwuid(getuid());
|
||||
std::string homedir;
|
||||
if (getenv("HOME") != nullptr) {
|
||||
homedir = std::string(getenv("HOME")) + "/.osquery";
|
||||
} else if (user != nullptr || user->pw_dir != nullptr) {
|
||||
homedir = std::string(user->pw_dir) + "/.osquery";
|
||||
} else {
|
||||
homedir = "/tmp/osquery";
|
||||
}
|
||||
|
||||
if (osquery::pathExists(homedir).ok() ||
|
||||
boost::filesystem::create_directory(homedir)) {
|
||||
osquery::FLAGS_database_path = homedir + "/shell.db";
|
||||
osquery::FLAGS_extensions_socket = homedir + "/shell.em";
|
||||
}
|
||||
}
|
||||
|
||||
// Set version string from CMake build
|
||||
GFLAGS_NAMESPACE::SetVersionString(OSQUERY_VERSION);
|
||||
|
||||
|
@ -13,8 +13,6 @@
|
||||
#include <osquery/core.h>
|
||||
#include <osquery/scheduler.h>
|
||||
|
||||
#include "osquery/core/watcher.h"
|
||||
|
||||
const std::string kWatcherWorkerName = "osqueryd: worker";
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
@ -8,26 +8,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <osquery/core.h>
|
||||
#include <osquery/database.h>
|
||||
#include <osquery/devtools.h>
|
||||
#include <osquery/extensions.h>
|
||||
#include <osquery/filesystem.h>
|
||||
#include <osquery/logger.h>
|
||||
|
||||
const std::string kShellTemp = "/tmp/osquery";
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
// The shell is transient, rewrite config-loaded paths.
|
||||
if (osquery::pathExists(kShellTemp).ok() ||
|
||||
boost::filesystem::create_directory(kShellTemp)) {
|
||||
osquery::FLAGS_database_path = kShellTemp + "/shell.db";
|
||||
osquery::FLAGS_extensions_socket = kShellTemp + "/shell.em";
|
||||
osquery::FLAGS_disable_logging = true;
|
||||
}
|
||||
|
||||
// Parse/apply flags, start registry, load logger/config plugins.
|
||||
osquery::Initializer runner(argc, argv, osquery::OSQUERY_TOOL_SHELL);
|
||||
runner.start();
|
||||
|
Loading…
Reference in New Issue
Block a user