config-check command in osqueryd

This addresses #585
This commit is contained in:
mike@arpaia.co 2015-01-21 12:56:25 -08:00
parent 9f937a9bc0
commit 10d5aabd36
3 changed files with 33 additions and 5 deletions

View File

@ -127,6 +127,15 @@ class Config {
*/
Status getMD5(std::string& hashString);
/**
* @brief Check to ensure that the config is accessible and properly
* formatted
*
* @return an instance of osquery::Status, indicating the success or failure
* of the operation.
*/
static osquery::Status checkConfig();
private:
/**
* @brief Default constructor.
@ -173,7 +182,6 @@ class Config {
* @return an instance of osquery::Status, indicating the success or failure
* of the operation.
*/
static osquery::Status genConfig(std::string& conf);
private:

View File

@ -138,4 +138,9 @@ Status Config::getMD5(std::string& hash_string) {
return Status(0, "OK");
}
Status Config::checkConfig() {
OsqueryConfig c;
return genConfig(c);
}
}

View File

@ -26,9 +26,24 @@ DEFINE_osquery_flag(bool, daemonize, false, "Run as daemon (osqueryd only).");
}
#endif
namespace osquery {
DEFINE_osquery_flag(bool,
config_check,
false,
"Check the format and accessibility of the daemon");
}
int main(int argc, char* argv[]) {
osquery::initOsquery(argc, argv, osquery::OSQUERY_TOOL_DAEMON);
if (osquery::FLAGS_config_check) {
auto s = osquery::Config::checkConfig();
if (!s.ok()) {
std::cerr << "Error reading config: " << s.toString() << "\n";
}
return s.getCode();
}
#ifndef __APPLE__
// OSX uses launchd to daemonize.
if (osquery::FLAGS_daemonize) {