2014-12-18 18:50:47 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
*/
|
2015-02-05 00:54:44 +00:00
|
|
|
|
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
|
2014-12-03 23:14:02 +00:00
|
|
|
#include <osquery/core.h>
|
|
|
|
#include <osquery/database.h>
|
|
|
|
#include <osquery/devtools.h>
|
|
|
|
#include <osquery/events.h>
|
2015-02-04 03:55:16 +00:00
|
|
|
#include <osquery/extensions.h>
|
2015-02-05 01:53:27 +00:00
|
|
|
#include <osquery/filesystem.h>
|
2015-02-05 00:54:44 +00:00
|
|
|
#include <osquery/logger.h>
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2015-02-05 01:53:27 +00:00
|
|
|
const std::string kShellTemp = "/tmp/osquery";
|
|
|
|
|
2014-07-31 00:35:19 +00:00
|
|
|
int main(int argc, char *argv[]) {
|
2015-02-06 17:42:03 +00:00
|
|
|
// The shell is transient, rewrite config-loaded paths.
|
2015-02-05 01:53:27 +00:00
|
|
|
if (osquery::pathExists(kShellTemp).ok() ||
|
|
|
|
boost::filesystem::create_directory(kShellTemp)) {
|
|
|
|
osquery::FLAGS_db_path = kShellTemp + "/shell.db";
|
|
|
|
osquery::FLAGS_extensions_socket = kShellTemp + "/shell.em";
|
|
|
|
FLAGS_log_dir = kShellTemp;
|
2015-02-05 00:54:44 +00:00
|
|
|
}
|
|
|
|
|
2015-02-03 05:21:36 +00:00
|
|
|
// Parse/apply flags, start registry, load logger/config plugins.
|
2014-11-09 04:27:28 +00:00
|
|
|
osquery::initOsquery(argc, argv, osquery::OSQUERY_TOOL_SHELL);
|
2014-09-23 01:35:12 +00:00
|
|
|
|
2015-02-01 08:35:44 +00:00
|
|
|
// Start event threads.
|
2015-02-06 17:42:03 +00:00
|
|
|
osquery::attachEvents();
|
2014-09-23 01:35:12 +00:00
|
|
|
osquery::EventFactory::delay();
|
2015-02-05 00:54:44 +00:00
|
|
|
osquery::startExtensionManager();
|
2014-09-23 01:35:12 +00:00
|
|
|
|
2015-02-03 05:21:36 +00:00
|
|
|
// Virtual tables will be attached to the shell's in-memory SQLite DB.
|
2014-09-23 01:35:12 +00:00
|
|
|
int retcode = osquery::launchIntoShell(argc, argv);
|
|
|
|
|
2015-02-01 08:35:44 +00:00
|
|
|
// Finally shutdown.
|
|
|
|
osquery::shutdownOsquery();
|
2014-09-23 01:35:12 +00:00
|
|
|
return retcode;
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|