2014-07-31 00:35:19 +00:00
|
|
|
/*
|
|
|
|
** 2001 September 15
|
|
|
|
**
|
|
|
|
** The author disclaims copyright to this source code. In place of
|
|
|
|
** a legal notice, here is a blessing:
|
|
|
|
**
|
|
|
|
** May you do good and not evil.
|
|
|
|
** May you find forgiveness for yourself and forgive others.
|
|
|
|
** May you share freely, never taking more than you give.
|
|
|
|
**
|
|
|
|
*************************************************************************
|
|
|
|
** This file contains code to implement the "sqlite" command line
|
|
|
|
** utility for accessing SQLite databases.
|
|
|
|
*/
|
2014-09-26 03:34:26 +00:00
|
|
|
|
2017-10-30 05:25:49 +00:00
|
|
|
#include <csignal>
|
|
|
|
#include <cstdio>
|
2016-07-25 18:58:55 +00:00
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#include <io.h>
|
|
|
|
#else
|
2015-04-27 01:54:27 +00:00
|
|
|
#include <sys/resource.h>
|
2016-03-05 17:29:51 +00:00
|
|
|
#include <sys/time.h>
|
2016-07-25 18:58:55 +00:00
|
|
|
#endif
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2016-10-12 05:16:21 +00:00
|
|
|
#include <linenoise.h>
|
2015-03-19 03:47:35 +00:00
|
|
|
#include <sqlite3.h>
|
|
|
|
|
|
|
|
#include <boost/algorithm/string/predicate.hpp>
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2016-05-12 16:22:05 +00:00
|
|
|
#include <osquery/config.h>
|
2015-05-24 01:52:42 +00:00
|
|
|
#include <osquery/database.h>
|
2015-03-19 03:47:35 +00:00
|
|
|
#include <osquery/filesystem.h>
|
2014-12-03 23:14:02 +00:00
|
|
|
#include <osquery/flags.h>
|
2016-05-12 16:22:05 +00:00
|
|
|
#include <osquery/packs.h>
|
2014-12-03 23:14:02 +00:00
|
|
|
|
2017-01-07 20:21:35 +00:00
|
|
|
#include "osquery/core/process.h"
|
2015-03-18 19:01:58 +00:00
|
|
|
#include "osquery/devtools/devtools.h"
|
2016-09-02 22:04:03 +00:00
|
|
|
#include "osquery/filesystem/fileops.h"
|
2015-02-03 05:21:36 +00:00
|
|
|
#include "osquery/sql/virtual_table.h"
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2016-03-05 04:41:06 +00:00
|
|
|
#if defined(SQLITE_ENABLE_WHERETRACE)
|
|
|
|
extern int sqlite3WhereTrace;
|
|
|
|
#endif
|
|
|
|
|
2016-07-25 18:58:55 +00:00
|
|
|
namespace fs = boost::filesystem;
|
|
|
|
|
2016-10-30 23:23:22 +00:00
|
|
|
DECLARE_string(flagfile);
|
|
|
|
|
2014-12-07 01:22:48 +00:00
|
|
|
namespace osquery {
|
2015-03-19 03:47:35 +00:00
|
|
|
|
|
|
|
/// Define flags used by the shell. They are parsed by the drop-in shell.
|
2015-04-27 23:40:05 +00:00
|
|
|
SHELL_FLAG(bool, csv, false, "Set output mode to 'csv'");
|
|
|
|
SHELL_FLAG(bool, json, false, "Set output mode to 'json'");
|
|
|
|
SHELL_FLAG(bool, line, false, "Set output mode to 'line'");
|
|
|
|
SHELL_FLAG(bool, list, false, "Set output mode to 'list'");
|
|
|
|
SHELL_FLAG(string, separator, "|", "Set output field separator, default '|'");
|
2015-12-16 02:18:54 +00:00
|
|
|
SHELL_FLAG(bool, header, true, "Toggle column headers true/false");
|
2016-05-12 16:22:05 +00:00
|
|
|
SHELL_FLAG(string, pack, "", "Run all queries in a pack");
|
2015-04-27 23:40:05 +00:00
|
|
|
|
|
|
|
/// Define short-hand shell switches.
|
|
|
|
SHELL_FLAG(bool, L, false, "List all table names");
|
|
|
|
SHELL_FLAG(string, A, "", "Select all from a table");
|
2016-03-09 00:41:19 +00:00
|
|
|
|
|
|
|
DECLARE_string(nullvalue);
|
2016-08-29 19:37:04 +00:00
|
|
|
DECLARE_string(extensions_socket);
|
2016-10-30 23:23:22 +00:00
|
|
|
DECLARE_string(tls_hostname);
|
|
|
|
DECLARE_string(logger_plugin);
|
|
|
|
DECLARE_string(logger_path);
|
|
|
|
DECLARE_string(logger_tls_endpoint);
|
|
|
|
DECLARE_string(distributed_plugin);
|
|
|
|
DECLARE_string(config_plugin);
|
|
|
|
DECLARE_string(config_path);
|
|
|
|
DECLARE_string(config_tls_endpoint);
|
|
|
|
DECLARE_string(database_path);
|
2017-10-30 05:25:49 +00:00
|
|
|
} // namespace osquery
|
2014-12-07 01:22:48 +00:00
|
|
|
|
2015-05-10 02:48:28 +00:00
|
|
|
static char zHelp[] =
|
|
|
|
"Welcome to the osquery shell. Please explore your OS!\n"
|
|
|
|
"You are connected to a transient 'in-memory' virtual database.\n"
|
|
|
|
"\n"
|
2016-10-30 23:23:22 +00:00
|
|
|
".all [TABLE] Select all from a table\n"
|
|
|
|
".bail ON|OFF Stop after hitting an error\n"
|
|
|
|
".echo ON|OFF Turn command echo on or off\n"
|
|
|
|
".exit Exit this program\n"
|
|
|
|
".features List osquery's features and their statuses\n"
|
|
|
|
".headers ON|OFF Turn display of headers on or off\n"
|
|
|
|
".help Show this message\n"
|
|
|
|
".mode MODE Set output mode where MODE is one of:\n"
|
|
|
|
" csv Comma-separated values\n"
|
|
|
|
" column Left-aligned columns see .width\n"
|
|
|
|
" line One value per line\n"
|
|
|
|
" list Values delimited by .separator string\n"
|
|
|
|
" pretty Pretty printed SQL results (default)\n"
|
|
|
|
".nullvalue STR Use STRING in place of NULL values\n"
|
|
|
|
".print STR... Print literal STRING\n"
|
|
|
|
".quit Exit this program\n"
|
|
|
|
".schema [TABLE] Show the CREATE statements\n"
|
|
|
|
".separator STR Change separator used by output mode\n"
|
|
|
|
".socket Show the osquery extensions socket path\n"
|
|
|
|
".show Show the current values for various settings\n"
|
|
|
|
".summary Alias for the show meta command\n"
|
|
|
|
".tables [TABLE] List names of tables\n"
|
|
|
|
".width [NUM1]+ Set column widths for \"column\" mode\n";
|
2015-05-10 02:48:28 +00:00
|
|
|
|
|
|
|
static char zTimerHelp[] =
|
|
|
|
".timer ON|OFF Turn the CPU timer measurement on or off\n";
|
|
|
|
|
2015-08-30 05:08:01 +00:00
|
|
|
// Allowed modes
|
|
|
|
#define MODE_Line 0 // One column per line. Blank line between records
|
|
|
|
#define MODE_Column 1 // One record per line in neat columns
|
|
|
|
#define MODE_List 2 // One record per line with a separator
|
|
|
|
#define MODE_Semi 3 // Same as MODE_List but append ";" to each line
|
|
|
|
#define MODE_Csv 4 // Quote strings, numbers are plain
|
|
|
|
#define MODE_Pretty 5 // Pretty print the SQL results
|
2015-05-10 02:48:28 +00:00
|
|
|
|
2016-08-29 19:37:04 +00:00
|
|
|
static const char* modeDescr[] = {
|
2015-05-10 02:48:28 +00:00
|
|
|
"line", "column", "list", "semi", "csv", "pretty",
|
|
|
|
};
|
|
|
|
|
2015-08-30 05:08:01 +00:00
|
|
|
// ctype macros that work with signed characters
|
2017-10-30 05:25:49 +00:00
|
|
|
#define IsSpace(X) isspace((unsigned char)(X))
|
|
|
|
#define IsDigit(X) isdigit((unsigned char)(X))
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2015-08-30 05:08:01 +00:00
|
|
|
// True if the timer is enabled
|
2014-07-31 00:35:19 +00:00
|
|
|
static int enableTimer = 0;
|
|
|
|
|
2015-08-30 05:08:01 +00:00
|
|
|
// Return the current wall-clock time
|
2017-10-30 05:25:49 +00:00
|
|
|
static sqlite3_int64 timeOfDay() {
|
|
|
|
static sqlite3_vfs* clockVfs = nullptr;
|
2014-07-31 00:35:19 +00:00
|
|
|
sqlite3_int64 t;
|
2017-10-30 05:25:49 +00:00
|
|
|
if (clockVfs == nullptr) {
|
|
|
|
clockVfs = sqlite3_vfs_find(nullptr);
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2017-10-30 05:25:49 +00:00
|
|
|
if (clockVfs->iVersion >= 1 && clockVfs->xCurrentTimeInt64 != nullptr) {
|
2014-07-31 00:35:19 +00:00
|
|
|
clockVfs->xCurrentTimeInt64(clockVfs, &t);
|
2014-08-15 07:25:30 +00:00
|
|
|
} else {
|
2014-07-31 00:35:19 +00:00
|
|
|
double r;
|
|
|
|
clockVfs->xCurrentTime(clockVfs, &r);
|
2017-10-30 05:25:49 +00:00
|
|
|
t = static_cast<sqlite3_int64>(r * 86400000.0);
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2015-08-30 05:08:01 +00:00
|
|
|
// Saved resource information for the beginning of an operation
|
2016-07-25 18:58:55 +00:00
|
|
|
#ifdef WIN32
|
2016-07-25 22:35:34 +00:00
|
|
|
struct rusage {
|
|
|
|
FILETIME ru_utime;
|
|
|
|
FILETIME ru_stime;
|
|
|
|
};
|
2016-07-25 18:58:55 +00:00
|
|
|
#endif
|
|
|
|
|
2016-07-25 22:35:34 +00:00
|
|
|
static struct rusage sBegin; // CPU time at start
|
2015-08-30 05:08:01 +00:00
|
|
|
static sqlite3_int64 iBegin; // Wall-clock time at start
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2017-10-30 05:25:49 +00:00
|
|
|
static void beginTimer() {
|
|
|
|
if (enableTimer != 0) {
|
2016-07-25 18:58:55 +00:00
|
|
|
#ifdef WIN32
|
2016-07-25 22:35:34 +00:00
|
|
|
FILETIME ftCreation, ftExit;
|
2016-08-29 19:37:04 +00:00
|
|
|
::GetProcessTimes(::GetCurrentProcess(),
|
|
|
|
&ftCreation,
|
|
|
|
&ftExit,
|
|
|
|
&sBegin.ru_stime,
|
|
|
|
&sBegin.ru_utime);
|
2016-07-25 18:58:55 +00:00
|
|
|
#else
|
2014-07-31 00:35:19 +00:00
|
|
|
getrusage(RUSAGE_SELF, &sBegin);
|
2016-07-25 18:58:55 +00:00
|
|
|
#endif
|
|
|
|
|
2014-07-31 00:35:19 +00:00
|
|
|
iBegin = timeOfDay();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-30 05:08:01 +00:00
|
|
|
// Return the difference of two time_structs in seconds
|
2016-07-25 18:58:55 +00:00
|
|
|
#ifdef WIN32
|
2016-08-29 19:37:04 +00:00
|
|
|
static double timeDiff(FILETIME* pStart, FILETIME* pEnd) {
|
2016-07-25 22:35:34 +00:00
|
|
|
ULARGE_INTEGER start, end;
|
|
|
|
|
|
|
|
start.HighPart = pStart->dwHighDateTime;
|
|
|
|
start.LowPart = pStart->dwLowDateTime;
|
|
|
|
|
|
|
|
end.HighPart = pEnd->dwHighDateTime;
|
|
|
|
end.LowPart = pEnd->dwLowDateTime;
|
|
|
|
|
|
|
|
// start, end are in units of 100 nanoseconds
|
|
|
|
return (end.QuadPart - start.QuadPart) * 0.0000001;
|
2016-07-25 18:58:55 +00:00
|
|
|
}
|
|
|
|
#else
|
2016-08-29 19:37:04 +00:00
|
|
|
static double timeDiff(struct timeval* pStart, struct timeval* pEnd) {
|
2014-08-15 07:25:30 +00:00
|
|
|
return (pEnd->tv_usec - pStart->tv_usec) * 0.000001 +
|
2017-10-30 05:25:49 +00:00
|
|
|
static_cast<double>(pEnd->tv_sec - pStart->tv_sec);
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
2016-07-25 18:58:55 +00:00
|
|
|
#endif
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2015-08-30 05:08:01 +00:00
|
|
|
// End the timer and print the results.
|
2017-10-30 05:25:49 +00:00
|
|
|
static void endTimer() {
|
|
|
|
if (enableTimer != 0) {
|
2014-07-31 00:35:19 +00:00
|
|
|
sqlite3_int64 iEnd = timeOfDay();
|
2017-10-30 05:25:49 +00:00
|
|
|
struct rusage sEnd {};
|
2016-07-25 18:58:55 +00:00
|
|
|
|
2016-07-25 22:35:34 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
FILETIME ftCreation, ftExit;
|
2016-08-29 19:37:04 +00:00
|
|
|
::GetProcessTimes(::GetCurrentProcess(),
|
|
|
|
&ftCreation,
|
|
|
|
&ftExit,
|
|
|
|
&sEnd.ru_stime,
|
|
|
|
&sEnd.ru_utime);
|
2016-07-25 18:58:55 +00:00
|
|
|
#else
|
2014-07-31 00:35:19 +00:00
|
|
|
getrusage(RUSAGE_SELF, &sEnd);
|
2016-07-25 22:35:34 +00:00
|
|
|
#endif
|
|
|
|
|
2016-08-29 19:37:04 +00:00
|
|
|
printf("Run Time: real %.3f user %f sys %f\n",
|
|
|
|
(iEnd - iBegin) * 0.001,
|
2014-08-15 07:25:30 +00:00
|
|
|
timeDiff(&sBegin.ru_utime, &sEnd.ru_utime),
|
|
|
|
timeDiff(&sBegin.ru_stime, &sEnd.ru_stime));
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define BEGIN_TIMER beginTimer()
|
|
|
|
#define END_TIMER endTimer()
|
|
|
|
#define HAS_TIMER 1
|
|
|
|
|
2015-08-30 05:08:01 +00:00
|
|
|
// If the following flag is set, then command execution stops
|
|
|
|
// at an error if we are not interactive.
|
2014-07-31 00:35:19 +00:00
|
|
|
static int bail_on_error = 0;
|
|
|
|
|
2015-08-30 05:08:01 +00:00
|
|
|
// Treat stdin as an interactive input if the following variable
|
|
|
|
// is true. Otherwise, assume stdin is connected to a file or pipe.
|
2016-09-02 22:04:03 +00:00
|
|
|
static bool stdin_is_interactive = true;
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2015-08-30 05:08:01 +00:00
|
|
|
// True if an interrupt (Control-C) has been received.
|
2014-07-31 00:35:19 +00:00
|
|
|
static volatile int seenInterrupt = 0;
|
|
|
|
|
2016-10-30 23:23:22 +00:00
|
|
|
static char mainPrompt[26]; // First line prompt. default: "sqlite> "
|
|
|
|
static char continuePrompt[26]; // Continuation prompt. default: " ...> "
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2015-08-30 05:08:01 +00:00
|
|
|
// A global char* and an SQL function to access its current value
|
|
|
|
// from within an SQL statement. This program used to use the
|
|
|
|
// sqlite_exec_printf() API to substitue a string into an SQL statement.
|
|
|
|
// The correct way to do this with sqlite3 is to use the bind API, but
|
|
|
|
// since the shell is built around the callback paradigm it would be a lot
|
|
|
|
// of work. Instead just use this hack, which is quite harmless.
|
2017-10-30 05:25:49 +00:00
|
|
|
static const char* zShellStatic = nullptr;
|
2016-09-02 22:04:03 +00:00
|
|
|
void shellstaticFunc(sqlite3_context* context,
|
2017-11-09 21:21:22 +00:00
|
|
|
int argc,
|
2016-09-02 22:04:03 +00:00
|
|
|
sqlite3_value** /* argv */) {
|
2014-08-15 07:25:30 +00:00
|
|
|
assert(0 == argc);
|
|
|
|
assert(zShellStatic);
|
2014-07-31 00:35:19 +00:00
|
|
|
sqlite3_result_text(context, zShellStatic, -1, SQLITE_STATIC);
|
|
|
|
}
|
|
|
|
|
2016-10-30 23:23:22 +00:00
|
|
|
/*
|
|
|
|
** Output text to the console in a font that attracts extra attention.
|
|
|
|
*/
|
|
|
|
static void print_bold(const char* zText) {
|
|
|
|
if (stdin_is_interactive) {
|
|
|
|
printf("\033[1m");
|
|
|
|
}
|
|
|
|
printf("%s", zText);
|
|
|
|
if (stdin_is_interactive) {
|
|
|
|
printf("\033[0m");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-31 00:35:19 +00:00
|
|
|
/*
|
|
|
|
** This routine reads a line of text from FILE in, stores
|
|
|
|
** the text in memory obtained from malloc() and returns a pointer
|
|
|
|
** to the text. NULL is returned at end of file, or if malloc()
|
|
|
|
** fails.
|
|
|
|
**
|
|
|
|
** If zLine is not NULL then it is a malloced buffer returned from
|
|
|
|
** a previous call to this routine that may be reused.
|
|
|
|
*/
|
2016-08-29 19:37:04 +00:00
|
|
|
static char* local_getline(char* zLine, FILE* in) {
|
2015-05-13 06:46:02 +00:00
|
|
|
int nLine = ((zLine == nullptr) ? 0 : 100);
|
2014-07-31 00:35:19 +00:00
|
|
|
int n = 0;
|
|
|
|
|
2017-10-30 05:25:49 +00:00
|
|
|
while (true) {
|
2014-08-15 07:25:30 +00:00
|
|
|
if (n + 100 > nLine) {
|
|
|
|
nLine = nLine * 2 + 100;
|
2017-10-30 05:25:49 +00:00
|
|
|
auto zLine_new = reinterpret_cast<char*>(realloc(zLine, nLine));
|
2015-05-13 06:46:02 +00:00
|
|
|
if (zLine_new == nullptr) {
|
|
|
|
free(zLine);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
zLine = zLine_new;
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
2017-10-30 05:25:49 +00:00
|
|
|
if (fgets(&zLine[n], nLine - n, in) == nullptr) {
|
2014-08-15 07:25:30 +00:00
|
|
|
if (n == 0) {
|
2014-07-31 00:35:19 +00:00
|
|
|
free(zLine);
|
2015-05-13 06:46:02 +00:00
|
|
|
return nullptr;
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
|
|
|
zLine[n] = 0;
|
|
|
|
break;
|
|
|
|
}
|
2017-10-30 05:25:49 +00:00
|
|
|
while (zLine[n] != 0) {
|
2014-08-15 07:25:30 +00:00
|
|
|
n++;
|
2015-05-13 06:46:02 +00:00
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
if (n > 0 && zLine[n - 1] == '\n') {
|
2014-07-31 00:35:19 +00:00
|
|
|
n--;
|
2015-05-13 06:46:02 +00:00
|
|
|
if (n > 0 && zLine[n - 1] == '\r') {
|
2014-08-15 07:25:30 +00:00
|
|
|
n--;
|
2015-05-13 06:46:02 +00:00
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
zLine[n] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return zLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Retrieve a single line of input text.
|
|
|
|
**
|
|
|
|
** If in==0 then read from standard input and prompt before each line.
|
|
|
|
** If isContinuation is true, then a continuation prompt is appropriate.
|
|
|
|
** If isContinuation is zero, then the main prompt should be used.
|
|
|
|
**
|
|
|
|
** If zPrior is not NULL then it is a buffer from a prior call to this
|
|
|
|
** routine that can be reused.
|
|
|
|
**
|
|
|
|
** The result is stored in space obtained from malloc() and must either
|
|
|
|
** be freed by the caller or else passed back into this routine via the
|
|
|
|
** zPrior argument for reuse.
|
|
|
|
*/
|
2016-08-29 19:37:04 +00:00
|
|
|
static char* one_input_line(FILE* in, char* zPrior, int isContinuation) {
|
|
|
|
char* zResult;
|
2017-10-30 05:25:49 +00:00
|
|
|
if (in != nullptr) {
|
2014-07-31 00:35:19 +00:00
|
|
|
zResult = local_getline(zPrior, in);
|
2014-08-15 07:25:30 +00:00
|
|
|
} else {
|
2017-10-30 05:25:49 +00:00
|
|
|
char* zPrompt = isContinuation != 0 ? continuePrompt : mainPrompt;
|
2014-07-31 00:35:19 +00:00
|
|
|
free(zPrior);
|
2016-07-25 18:58:55 +00:00
|
|
|
zResult = linenoise(zPrompt);
|
2017-10-30 05:25:49 +00:00
|
|
|
if ((zResult != nullptr) && (*zResult != 0)) {
|
2016-07-25 18:58:55 +00:00
|
|
|
linenoiseHistoryAdd(zResult);
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
|
|
|
return zResult;
|
|
|
|
}
|
|
|
|
|
2014-10-31 00:58:51 +00:00
|
|
|
/*
|
|
|
|
** Pretty print structure
|
|
|
|
*/
|
|
|
|
struct prettyprint_data {
|
2015-03-18 19:01:58 +00:00
|
|
|
osquery::QueryData results;
|
|
|
|
std::vector<std::string> columns;
|
|
|
|
std::map<std::string, size_t> lengths;
|
2014-10-31 00:58:51 +00:00
|
|
|
};
|
|
|
|
|
2014-07-31 00:35:19 +00:00
|
|
|
/*
|
|
|
|
** An pointer to an instance of this structure is passed from
|
|
|
|
** the main program to the callback. This is used to communicate
|
|
|
|
** state and mode information.
|
|
|
|
*/
|
|
|
|
struct callback_data {
|
2014-08-15 07:25:30 +00:00
|
|
|
int echoOn; /* True to echo input commands */
|
|
|
|
int cnt; /* Number of records displayed so far */
|
2016-08-29 19:37:04 +00:00
|
|
|
FILE* out; /* Write results here */
|
|
|
|
FILE* traceOut; /* Output for sqlite3_trace() */
|
2014-08-15 07:25:30 +00:00
|
|
|
int mode; /* An output mode setting */
|
|
|
|
int showHeader; /* True to show column names in List or Column mode */
|
2016-08-29 19:37:04 +00:00
|
|
|
char* zDestTable; /* Name of destination table when MODE_Insert */
|
2014-08-15 07:25:30 +00:00
|
|
|
char separator[20]; /* Separator character for MODE_List */
|
|
|
|
int colWidth[100]; /* Requested width of each column when in column mode*/
|
|
|
|
int actualWidth[100]; /* Actual width of each column */
|
|
|
|
char nullvalue[20]; /* The text to print when a NULL comes back from
|
|
|
|
** the database */
|
2014-07-31 00:35:19 +00:00
|
|
|
char outfile[FILENAME_MAX]; /* Filename for *out */
|
2016-08-29 19:37:04 +00:00
|
|
|
char* zFreeOnClose; /* Filename to free when closing */
|
|
|
|
sqlite3_stmt* pStmt; /* Current statement if any. */
|
|
|
|
FILE* pLog; /* Write log output here */
|
|
|
|
int* aiIndent; /* Array of indents used in MODE_Explain */
|
2014-08-15 07:25:30 +00:00
|
|
|
int nIndent; /* Size of array aiIndent[] */
|
|
|
|
int iIndent; /* Index of current op in aiIndent[] */
|
2014-09-26 03:34:26 +00:00
|
|
|
|
|
|
|
/* Additional attributes to be used in pretty mode */
|
2016-08-29 19:37:04 +00:00
|
|
|
struct prettyprint_data* prettyPrint;
|
2014-07-31 00:35:19 +00:00
|
|
|
};
|
|
|
|
|
2015-08-30 05:08:01 +00:00
|
|
|
// Number of elements in an array
|
2017-10-30 05:25:49 +00:00
|
|
|
#define ArraySize(X) (int)(sizeof(X) / sizeof((X)[0]))
|
2014-07-31 00:35:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Compute a string length that is limited to what can be stored in
|
|
|
|
** lower 30 bits of a 32-bit signed integer.
|
|
|
|
*/
|
2016-08-29 19:37:04 +00:00
|
|
|
static int strlen30(const char* z) {
|
|
|
|
const char* z2 = z;
|
2017-10-30 05:25:49 +00:00
|
|
|
while (*z2 != 0) {
|
2014-08-15 07:25:30 +00:00
|
|
|
z2++;
|
|
|
|
}
|
2017-10-30 05:25:49 +00:00
|
|
|
return 0x3fffffff & static_cast<int>(z2 - z);
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** A callback for the sqlite3_log() interface.
|
|
|
|
*/
|
2016-08-29 19:37:04 +00:00
|
|
|
static void shellLog(void* pArg, int iErrCode, const char* zMsg) {
|
2017-10-30 05:25:49 +00:00
|
|
|
auto* p = reinterpret_cast<struct callback_data*>(pArg);
|
|
|
|
if (p->pLog == nullptr) {
|
2014-08-15 07:25:30 +00:00
|
|
|
return;
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
fprintf(p->pLog, "(%d) %s\n", iErrCode, zMsg);
|
|
|
|
fflush(p->pLog);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Output the given string as a quoted according to C or TCL quoting rules.
|
|
|
|
*/
|
2016-08-29 19:37:04 +00:00
|
|
|
static void output_c_string(FILE* out, const char* z) {
|
2014-07-31 00:35:19 +00:00
|
|
|
unsigned int c;
|
|
|
|
fputc('"', out);
|
2014-08-15 07:25:30 +00:00
|
|
|
while ((c = *(z++)) != 0) {
|
|
|
|
if (c == '\\') {
|
2014-07-31 00:35:19 +00:00
|
|
|
fputc(c, out);
|
|
|
|
fputc(c, out);
|
2014-08-15 07:25:30 +00:00
|
|
|
} else if (c == '"') {
|
2014-07-31 00:35:19 +00:00
|
|
|
fputc('\\', out);
|
|
|
|
fputc('"', out);
|
2014-08-15 07:25:30 +00:00
|
|
|
} else if (c == '\t') {
|
2014-07-31 00:35:19 +00:00
|
|
|
fputc('\\', out);
|
|
|
|
fputc('t', out);
|
2014-08-15 07:25:30 +00:00
|
|
|
} else if (c == '\n') {
|
2014-07-31 00:35:19 +00:00
|
|
|
fputc('\\', out);
|
|
|
|
fputc('n', out);
|
2014-08-15 07:25:30 +00:00
|
|
|
} else if (c == '\r') {
|
2014-07-31 00:35:19 +00:00
|
|
|
fputc('\\', out);
|
|
|
|
fputc('r', out);
|
2017-10-30 05:25:49 +00:00
|
|
|
} else if (isprint(c & 0xff) == 0) {
|
|
|
|
fprintf(out, R"(\%03o)", c & 0xff);
|
2014-08-15 07:25:30 +00:00
|
|
|
} else {
|
2014-07-31 00:35:19 +00:00
|
|
|
fputc(c, out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fputc('"', out);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** If a field contains any character identified by a 1 in the following
|
|
|
|
** array, then the string must be quoted for CSV.
|
|
|
|
*/
|
|
|
|
static const char needCsvQuote[] = {
|
2016-05-12 16:22:05 +00:00
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
2014-09-21 21:29:28 +00:00
|
|
|
};
|
2014-07-31 00:35:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Output a single term of CSV. Actually, p->separator is used for
|
|
|
|
** the separator, which may or may not be a comma. p->nullvalue is
|
|
|
|
** the null value. Strings are quoted if necessary.
|
|
|
|
*/
|
2016-08-29 19:37:04 +00:00
|
|
|
static void output_csv(struct callback_data* p, const char* z, int bSep) {
|
|
|
|
FILE* out = p->out;
|
2017-10-30 05:25:49 +00:00
|
|
|
if (z == nullptr) {
|
2014-08-15 07:25:30 +00:00
|
|
|
fprintf(out, "%s", p->nullvalue);
|
|
|
|
} else {
|
2014-07-31 00:35:19 +00:00
|
|
|
int i;
|
|
|
|
int nSep = strlen30(p->separator);
|
2017-10-30 05:25:49 +00:00
|
|
|
for (i = 0; z[i] != 0; i++) {
|
|
|
|
if ((needCsvQuote[((unsigned char*)z)[i]] != 0) ||
|
2014-08-15 07:25:30 +00:00
|
|
|
(z[i] == p->separator[0] &&
|
|
|
|
(nSep == 1 || memcmp(z, p->separator, nSep) == 0))) {
|
2014-07-31 00:35:19 +00:00
|
|
|
i = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
if (i == 0) {
|
2014-07-31 00:35:19 +00:00
|
|
|
putc('"', out);
|
2017-10-30 05:25:49 +00:00
|
|
|
for (i = 0; z[i] != 0; i++) {
|
2015-08-30 05:08:01 +00:00
|
|
|
if (z[i] == '"') {
|
2014-08-15 07:25:30 +00:00
|
|
|
putc('"', out);
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
putc(z[i], out);
|
|
|
|
}
|
|
|
|
putc('"', out);
|
2014-08-15 07:25:30 +00:00
|
|
|
} else {
|
2014-07-31 00:35:19 +00:00
|
|
|
fprintf(out, "%s", z);
|
|
|
|
}
|
|
|
|
}
|
2017-10-30 05:25:49 +00:00
|
|
|
if (bSep != 0) {
|
2014-07-31 00:35:19 +00:00
|
|
|
fprintf(p->out, "%s", p->separator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SIGINT
|
|
|
|
/*
|
|
|
|
** This routine runs when the user presses Ctrl-C
|
|
|
|
*/
|
2016-02-12 06:04:53 +00:00
|
|
|
static void interrupt_handler(int signal) {
|
|
|
|
if (signal == SIGINT) {
|
2016-03-20 23:05:13 +00:00
|
|
|
seenInterrupt = 1;
|
2016-02-12 06:04:53 +00:00
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
** This is the callback routine that the shell
|
|
|
|
** invokes for each row of a query result.
|
|
|
|
*/
|
2014-08-15 07:25:30 +00:00
|
|
|
static int shell_callback(
|
2017-10-30 05:25:49 +00:00
|
|
|
void* pArg, int nArg, char** azArg, char** azCol, int* /*aiType*/) {
|
2014-07-31 00:35:19 +00:00
|
|
|
int i;
|
2017-10-30 05:25:49 +00:00
|
|
|
auto* p = reinterpret_cast<struct callback_data*>(pArg);
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2014-08-15 07:25:30 +00:00
|
|
|
switch (p->mode) {
|
2014-09-26 03:34:26 +00:00
|
|
|
case MODE_Pretty: {
|
2017-10-30 05:25:49 +00:00
|
|
|
if (p->prettyPrint->columns.empty()) {
|
2014-09-26 03:34:26 +00:00
|
|
|
for (i = 0; i < nArg; i++) {
|
2015-03-18 19:01:58 +00:00
|
|
|
p->prettyPrint->columns.push_back(std::string(azCol[i]));
|
2014-09-26 03:34:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
osquery::Row r;
|
2015-08-30 05:08:01 +00:00
|
|
|
for (i = 0; i < nArg; ++i) {
|
2016-03-09 00:41:19 +00:00
|
|
|
if (azCol[i] != nullptr) {
|
|
|
|
r[std::string(azCol[i])] = (azArg[i] == nullptr)
|
|
|
|
? osquery::FLAGS_nullvalue
|
|
|
|
: std::string(azArg[i]);
|
2015-03-18 19:01:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
osquery::computeRowLengths(r, p->prettyPrint->lengths);
|
|
|
|
p->prettyPrint->results.push_back(r);
|
2014-09-26 03:34:26 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
case MODE_Line: {
|
|
|
|
int w = 5;
|
2017-10-30 05:25:49 +00:00
|
|
|
if (azArg == nullptr) {
|
2014-07-31 00:35:19 +00:00
|
|
|
break;
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
for (i = 0; i < nArg; i++) {
|
2017-10-30 05:25:49 +00:00
|
|
|
int len = strlen30(azCol[i] != nullptr ? azCol[i] : "");
|
2015-08-30 05:08:01 +00:00
|
|
|
if (len > w) {
|
2014-08-15 07:25:30 +00:00
|
|
|
w = len;
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
2015-08-30 05:08:01 +00:00
|
|
|
if (p->cnt++ > 0) {
|
2014-08-15 07:25:30 +00:00
|
|
|
fprintf(p->out, "\n");
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
for (i = 0; i < nArg; i++) {
|
|
|
|
fprintf(p->out,
|
|
|
|
"%*s = %s\n",
|
|
|
|
w,
|
|
|
|
azCol[i],
|
2017-10-30 05:25:49 +00:00
|
|
|
azArg[i] != nullptr ? azArg[i] : p->nullvalue);
|
2014-08-15 07:25:30 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MODE_Column: {
|
|
|
|
if (p->cnt++ == 0) {
|
|
|
|
for (i = 0; i < nArg; i++) {
|
2015-08-30 05:08:01 +00:00
|
|
|
int w;
|
2014-08-15 07:25:30 +00:00
|
|
|
if (i < ArraySize(p->colWidth)) {
|
|
|
|
w = p->colWidth[i];
|
|
|
|
} else {
|
|
|
|
w = 0;
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
if (w == 0) {
|
2017-10-30 05:25:49 +00:00
|
|
|
w = strlen30(azCol[i] != nullptr ? azCol[i] : "");
|
2015-08-30 05:08:01 +00:00
|
|
|
if (w < 10) {
|
2014-08-15 07:25:30 +00:00
|
|
|
w = 10;
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2017-10-30 05:25:49 +00:00
|
|
|
int n = strlen30((azArg != nullptr) && (azArg[i] != nullptr)
|
|
|
|
? azArg[i]
|
|
|
|
: p->nullvalue);
|
2015-08-30 05:08:01 +00:00
|
|
|
if (w < n) {
|
2014-08-15 07:25:30 +00:00
|
|
|
w = n;
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
if (i < ArraySize(p->actualWidth)) {
|
|
|
|
p->actualWidth[i] = w;
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
2017-10-30 05:25:49 +00:00
|
|
|
if (p->showHeader != 0) {
|
2014-08-15 07:25:30 +00:00
|
|
|
if (w < 0) {
|
|
|
|
fprintf(p->out,
|
|
|
|
"%*.*s%s",
|
|
|
|
-w,
|
|
|
|
-w,
|
|
|
|
azCol[i],
|
|
|
|
i == nArg - 1 ? "\n" : " ");
|
|
|
|
} else {
|
|
|
|
fprintf(p->out,
|
|
|
|
"%-*.*s%s",
|
|
|
|
w,
|
|
|
|
w,
|
|
|
|
azCol[i],
|
|
|
|
i == nArg - 1 ? "\n" : " ");
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
}
|
2017-10-30 05:25:49 +00:00
|
|
|
if (p->showHeader != 0) {
|
2014-08-15 07:25:30 +00:00
|
|
|
for (i = 0; i < nArg; i++) {
|
|
|
|
int w;
|
|
|
|
if (i < ArraySize(p->actualWidth)) {
|
|
|
|
w = p->actualWidth[i];
|
2015-08-30 05:08:01 +00:00
|
|
|
if (w < 0) {
|
2014-08-15 07:25:30 +00:00
|
|
|
w = -w;
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
} else {
|
|
|
|
w = 10;
|
|
|
|
}
|
|
|
|
fprintf(p->out,
|
|
|
|
"%-*.*s%s",
|
|
|
|
w,
|
|
|
|
w,
|
|
|
|
"-----------------------------------"
|
|
|
|
"----------------------------------------------------------",
|
|
|
|
i == nArg - 1 ? "\n" : " ");
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-30 05:25:49 +00:00
|
|
|
if (azArg == nullptr) {
|
2014-08-15 07:25:30 +00:00
|
|
|
break;
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
for (i = 0; i < nArg; i++) {
|
|
|
|
int w;
|
|
|
|
if (i < ArraySize(p->actualWidth)) {
|
|
|
|
w = p->actualWidth[i];
|
|
|
|
} else {
|
|
|
|
w = 10;
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
2017-10-30 05:25:49 +00:00
|
|
|
if (i == 1 && (p->aiIndent != nullptr) && (p->pStmt != nullptr)) {
|
2014-08-15 07:25:30 +00:00
|
|
|
if (p->iIndent < p->nIndent) {
|
|
|
|
fprintf(p->out, "%*.s", p->aiIndent[p->iIndent], "");
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
p->iIndent++;
|
|
|
|
}
|
|
|
|
if (w < 0) {
|
|
|
|
fprintf(p->out,
|
|
|
|
"%*.*s%s",
|
|
|
|
-w,
|
|
|
|
-w,
|
2017-10-30 05:25:49 +00:00
|
|
|
azArg[i] != nullptr ? azArg[i] : p->nullvalue,
|
2014-08-15 07:25:30 +00:00
|
|
|
i == nArg - 1 ? "\n" : " ");
|
|
|
|
} else {
|
|
|
|
fprintf(p->out,
|
|
|
|
"%-*.*s%s",
|
|
|
|
w,
|
|
|
|
w,
|
2017-10-30 05:25:49 +00:00
|
|
|
azArg[i] != nullptr ? azArg[i] : p->nullvalue,
|
2014-08-15 07:25:30 +00:00
|
|
|
i == nArg - 1 ? "\n" : " ");
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MODE_Semi:
|
|
|
|
case MODE_List: {
|
2017-10-30 05:25:49 +00:00
|
|
|
if (p->cnt++ == 0 && (p->showHeader != 0)) {
|
2014-08-15 07:25:30 +00:00
|
|
|
for (i = 0; i < nArg; i++) {
|
|
|
|
fprintf(p->out, "%s%s", azCol[i], i == nArg - 1 ? "\n" : p->separator);
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
}
|
2017-10-30 05:25:49 +00:00
|
|
|
if (azArg == nullptr) {
|
2014-07-31 00:35:19 +00:00
|
|
|
break;
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
for (i = 0; i < nArg; i++) {
|
2016-08-29 19:37:04 +00:00
|
|
|
char* z = azArg[i];
|
2017-10-30 05:25:49 +00:00
|
|
|
if (z == nullptr) {
|
2014-08-15 07:25:30 +00:00
|
|
|
z = p->nullvalue;
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
fprintf(p->out, "%s", z);
|
|
|
|
if (i < nArg - 1) {
|
|
|
|
fprintf(p->out, "%s", p->separator);
|
|
|
|
} else if (p->mode == MODE_Semi) {
|
|
|
|
fprintf(p->out, ";\n");
|
|
|
|
} else {
|
|
|
|
fprintf(p->out, "\n");
|
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MODE_Csv: {
|
2017-10-30 05:25:49 +00:00
|
|
|
if (p->cnt++ == 0 && (p->showHeader != 0)) {
|
2014-08-15 07:25:30 +00:00
|
|
|
for (i = 0; i < nArg; i++) {
|
2017-10-30 05:25:49 +00:00
|
|
|
output_csv(p,
|
|
|
|
azCol[i] != nullptr ? azCol[i] : "",
|
|
|
|
static_cast<int>(i < nArg - 1));
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
fprintf(p->out, "\n");
|
|
|
|
}
|
2017-10-30 05:25:49 +00:00
|
|
|
if (azArg == nullptr) {
|
2014-07-31 00:35:19 +00:00
|
|
|
break;
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
for (i = 0; i < nArg; i++) {
|
2017-10-30 05:25:49 +00:00
|
|
|
output_csv(p, azArg[i], static_cast<int>(i < nArg - 1));
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
fprintf(p->out, "\n");
|
|
|
|
break;
|
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Set the destination table field of the callback_data structure to
|
|
|
|
** the name of the table given. Escape any quote characters in the
|
|
|
|
** table name.
|
|
|
|
*/
|
2016-08-29 19:37:04 +00:00
|
|
|
static void set_table_name(struct callback_data* p, const char* zName) {
|
2014-07-31 00:35:19 +00:00
|
|
|
int i, n;
|
|
|
|
int needQuote;
|
2016-08-29 19:37:04 +00:00
|
|
|
char* z;
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2017-10-30 05:25:49 +00:00
|
|
|
if (p->zDestTable != nullptr) {
|
2014-07-31 00:35:19 +00:00
|
|
|
free(p->zDestTable);
|
2017-10-30 05:25:49 +00:00
|
|
|
p->zDestTable = nullptr;
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
2015-08-30 05:08:01 +00:00
|
|
|
|
2017-10-30 05:25:49 +00:00
|
|
|
if (zName == nullptr) {
|
2014-08-15 07:25:30 +00:00
|
|
|
return;
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 05:25:49 +00:00
|
|
|
needQuote = static_cast<int>(
|
|
|
|
(isalpha(static_cast<unsigned char>(*zName)) == 0) && *zName != '_');
|
|
|
|
for (i = n = 0; zName[i] != 0; i++, n++) {
|
|
|
|
if ((isalnum(static_cast<unsigned char>(zName[i])) == 0) &&
|
|
|
|
zName[i] != '_') {
|
2014-07-31 00:35:19 +00:00
|
|
|
needQuote = 1;
|
2015-08-30 05:08:01 +00:00
|
|
|
if (zName[i] == '\'') {
|
2014-08-15 07:25:30 +00:00
|
|
|
n++;
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-30 05:25:49 +00:00
|
|
|
if (needQuote != 0) {
|
2014-08-15 07:25:30 +00:00
|
|
|
n += 2;
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2017-10-30 05:25:49 +00:00
|
|
|
z = p->zDestTable = reinterpret_cast<char*>(malloc(n + 1));
|
|
|
|
if (z == nullptr) {
|
2014-08-15 07:25:30 +00:00
|
|
|
fprintf(stderr, "Error: out of memory\n");
|
2014-07-31 00:35:19 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
n = 0;
|
2017-10-30 05:25:49 +00:00
|
|
|
if (needQuote != 0) {
|
2014-08-15 07:25:30 +00:00
|
|
|
z[n++] = '\'';
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2017-10-30 05:25:49 +00:00
|
|
|
for (i = 0; zName[i] != 0; i++) {
|
2014-07-31 00:35:19 +00:00
|
|
|
z[n++] = zName[i];
|
2015-08-30 05:08:01 +00:00
|
|
|
if (zName[i] == '\'') {
|
2014-08-15 07:25:30 +00:00
|
|
|
z[n++] = '\'';
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
2017-10-30 05:25:49 +00:00
|
|
|
if (needQuote != 0) {
|
2014-08-15 07:25:30 +00:00
|
|
|
z[n++] = '\'';
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
z[n] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Allocate space and save off current error string.
|
|
|
|
*/
|
2016-08-29 19:37:04 +00:00
|
|
|
static char* save_err_msg(sqlite3* db) {
|
2014-08-15 07:25:30 +00:00
|
|
|
int nErrMsg = 1 + strlen30(sqlite3_errmsg(db));
|
2017-10-30 05:25:49 +00:00
|
|
|
auto* zErrMsg = reinterpret_cast<char*>(sqlite3_malloc(nErrMsg));
|
|
|
|
if (zErrMsg != nullptr) {
|
2014-07-31 00:35:19 +00:00
|
|
|
memcpy(zErrMsg, sqlite3_errmsg(db), nErrMsg);
|
|
|
|
}
|
|
|
|
return zErrMsg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Execute a statement or set of statements. Print
|
|
|
|
** any result rows/columns depending on the current mode
|
|
|
|
** set via the supplied callback.
|
|
|
|
**
|
|
|
|
** This is very similar to SQLite's built-in sqlite3_exec()
|
|
|
|
** function except it takes a slightly different callback
|
|
|
|
** and callback data argument.
|
|
|
|
*/
|
|
|
|
static int shell_exec(
|
2016-08-29 19:37:04 +00:00
|
|
|
const char* zSql, /* SQL to be evaluated */
|
|
|
|
int (*xCallback)(void*, int, char**, char**, int*), /* Callback function */
|
2014-08-15 07:25:30 +00:00
|
|
|
/* (not the same as sqlite3_exec) */
|
2016-08-29 19:37:04 +00:00
|
|
|
struct callback_data* pArg, /* Pointer to struct callback_data */
|
|
|
|
char** pzErrMsg /* Error msg written here */
|
2014-08-15 07:25:30 +00:00
|
|
|
) {
|
2015-04-27 01:54:27 +00:00
|
|
|
// Grab a lock on the managed DB instance.
|
|
|
|
auto dbc = osquery::SQLiteDBManager::get();
|
2016-02-05 03:12:48 +00:00
|
|
|
auto db = dbc->db();
|
2015-04-27 01:54:27 +00:00
|
|
|
|
2016-08-29 19:37:04 +00:00
|
|
|
sqlite3_stmt* pStmt = nullptr; /* Statement to execute. */
|
2014-08-15 07:25:30 +00:00
|
|
|
int rc = SQLITE_OK; /* Return Code */
|
2014-07-31 00:35:19 +00:00
|
|
|
int rc2;
|
2016-08-29 19:37:04 +00:00
|
|
|
const char* zLeftover; /* Tail of unprocessed SQL */
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2017-10-30 05:25:49 +00:00
|
|
|
if (pzErrMsg != nullptr) {
|
2015-04-27 23:40:05 +00:00
|
|
|
*pzErrMsg = nullptr;
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 05:25:49 +00:00
|
|
|
while ((zSql[0] != 0) && (SQLITE_OK == rc)) {
|
2017-10-21 18:19:57 +00:00
|
|
|
auto lock(dbc->attachLock());
|
|
|
|
|
2016-10-24 15:25:38 +00:00
|
|
|
/* A lock for attaching virtual tables, but also the SQL object states. */
|
2014-07-31 00:35:19 +00:00
|
|
|
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
|
2014-08-15 07:25:30 +00:00
|
|
|
if (SQLITE_OK != rc) {
|
2017-10-30 05:25:49 +00:00
|
|
|
if (pzErrMsg != nullptr) {
|
2014-07-31 00:35:19 +00:00
|
|
|
*pzErrMsg = save_err_msg(db);
|
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
} else {
|
2017-10-30 05:25:49 +00:00
|
|
|
if (pStmt == nullptr) {
|
2014-07-31 00:35:19 +00:00
|
|
|
/* this happens for a comment or white-space */
|
|
|
|
zSql = zLeftover;
|
2015-08-30 05:08:01 +00:00
|
|
|
while (IsSpace(zSql[0])) {
|
2014-08-15 07:25:30 +00:00
|
|
|
zSql++;
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* save off the prepared statment handle and reset row count */
|
2017-10-30 05:25:49 +00:00
|
|
|
if (pArg != nullptr) {
|
2014-07-31 00:35:19 +00:00
|
|
|
pArg->pStmt = pStmt;
|
|
|
|
pArg->cnt = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* echo the sql statement if echo on */
|
2017-10-30 05:25:49 +00:00
|
|
|
if ((pArg != nullptr) && (pArg->echoOn != 0)) {
|
2016-08-29 19:37:04 +00:00
|
|
|
const char* zStmtSql = sqlite3_sql(pStmt);
|
2017-10-30 05:25:49 +00:00
|
|
|
fprintf(pArg->out, "%s\n", zStmtSql != nullptr ? zStmtSql : zSql);
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* perform the first step. this will tell us if we
|
|
|
|
** have a result set or not and how wide it is.
|
|
|
|
*/
|
|
|
|
rc = sqlite3_step(pStmt);
|
|
|
|
/* if we have a result set... */
|
2014-08-15 07:25:30 +00:00
|
|
|
if (SQLITE_ROW == rc) {
|
2014-07-31 00:35:19 +00:00
|
|
|
/* if we have a callback... */
|
2017-10-30 05:25:49 +00:00
|
|
|
if (xCallback != nullptr) {
|
2014-07-31 00:35:19 +00:00
|
|
|
/* allocate space for col name ptr, value ptr, and type */
|
|
|
|
int nCol = sqlite3_column_count(pStmt);
|
2016-08-29 19:37:04 +00:00
|
|
|
void* pData = sqlite3_malloc(3 * nCol * sizeof(const char*) + 1);
|
2017-10-30 05:25:49 +00:00
|
|
|
if (pData == nullptr) {
|
2014-07-31 00:35:19 +00:00
|
|
|
rc = SQLITE_NOMEM;
|
2014-08-15 07:25:30 +00:00
|
|
|
} else {
|
2017-10-30 05:25:49 +00:00
|
|
|
auto** azCols =
|
|
|
|
reinterpret_cast<char**>(pData); /* Names of result columns */
|
2016-08-29 19:37:04 +00:00
|
|
|
char** azVals = &azCols[nCol]; /* Results */
|
2017-10-30 05:25:49 +00:00
|
|
|
auto* aiTypes =
|
|
|
|
reinterpret_cast<int*>(&azVals[nCol]); /* Result types */
|
2015-08-30 05:08:01 +00:00
|
|
|
int i;
|
2016-08-29 19:37:04 +00:00
|
|
|
assert(sizeof(int) <= sizeof(char*));
|
2014-07-31 00:35:19 +00:00
|
|
|
/* save off ptrs to column names */
|
2014-08-15 07:25:30 +00:00
|
|
|
for (i = 0; i < nCol; i++) {
|
2017-10-30 05:25:49 +00:00
|
|
|
azCols[i] = const_cast<char*>(sqlite3_column_name(pStmt, i));
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
do {
|
2014-07-31 00:35:19 +00:00
|
|
|
/* extract the data and data types */
|
2014-08-15 07:25:30 +00:00
|
|
|
for (i = 0; i < nCol; i++) {
|
2015-08-30 05:08:01 +00:00
|
|
|
aiTypes[i] = sqlite3_column_type(pStmt, i);
|
2016-08-29 19:37:04 +00:00
|
|
|
azVals[i] = (char*)sqlite3_column_text(pStmt, i);
|
2017-10-30 05:25:49 +00:00
|
|
|
if ((azVals[i] == nullptr) && (aiTypes[i] != SQLITE_NULL)) {
|
2014-07-31 00:35:19 +00:00
|
|
|
rc = SQLITE_NOMEM;
|
|
|
|
break; /* from for */
|
|
|
|
}
|
|
|
|
} /* end for */
|
|
|
|
|
|
|
|
/* if data and types extracted successfully... */
|
2014-08-15 07:25:30 +00:00
|
|
|
if (SQLITE_ROW == rc) {
|
2014-07-31 00:35:19 +00:00
|
|
|
/* call the supplied callback with the result row data */
|
2017-10-30 05:25:49 +00:00
|
|
|
if (xCallback(pArg, nCol, azVals, azCols, aiTypes) != 0) {
|
2014-07-31 00:35:19 +00:00
|
|
|
rc = SQLITE_ABORT;
|
2014-08-15 07:25:30 +00:00
|
|
|
} else {
|
2014-07-31 00:35:19 +00:00
|
|
|
rc = sqlite3_step(pStmt);
|
|
|
|
}
|
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
} while (SQLITE_ROW == rc);
|
2014-07-31 00:35:19 +00:00
|
|
|
sqlite3_free(pData);
|
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
} else {
|
|
|
|
do {
|
2014-07-31 00:35:19 +00:00
|
|
|
rc = sqlite3_step(pStmt);
|
2014-08-15 07:25:30 +00:00
|
|
|
} while (rc == SQLITE_ROW);
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Finalize the statement just executed. If this fails, save a
|
|
|
|
** copy of the error message. Otherwise, set zSql to point to the
|
|
|
|
** next statement to execute. */
|
|
|
|
rc2 = sqlite3_finalize(pStmt);
|
2015-08-30 05:08:01 +00:00
|
|
|
if (rc != SQLITE_NOMEM) {
|
2014-08-15 07:25:30 +00:00
|
|
|
rc = rc2;
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
if (rc == SQLITE_OK) {
|
2014-07-31 00:35:19 +00:00
|
|
|
zSql = zLeftover;
|
2015-08-30 05:08:01 +00:00
|
|
|
while (IsSpace(zSql[0])) {
|
2014-08-15 07:25:30 +00:00
|
|
|
zSql++;
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2017-10-30 05:25:49 +00:00
|
|
|
} else if (pzErrMsg != nullptr) {
|
2014-07-31 00:35:19 +00:00
|
|
|
*pzErrMsg = save_err_msg(db);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clear saved stmt handle */
|
2017-10-30 05:25:49 +00:00
|
|
|
if (pArg != nullptr) {
|
2015-04-27 23:40:05 +00:00
|
|
|
pArg->pStmt = nullptr;
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} /* end while */
|
2016-02-25 01:58:58 +00:00
|
|
|
dbc->clearAffectedTables();
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2017-10-30 05:25:49 +00:00
|
|
|
if ((pArg != nullptr) && pArg->mode == MODE_Pretty) {
|
2014-12-07 01:22:48 +00:00
|
|
|
if (osquery::FLAGS_json) {
|
2015-03-18 19:01:58 +00:00
|
|
|
osquery::jsonPrint(pArg->prettyPrint->results);
|
2014-12-07 01:22:48 +00:00
|
|
|
} else {
|
2015-03-18 19:01:58 +00:00
|
|
|
osquery::prettyPrint(pArg->prettyPrint->results,
|
|
|
|
pArg->prettyPrint->columns,
|
|
|
|
pArg->prettyPrint->lengths);
|
2014-12-07 01:22:48 +00:00
|
|
|
}
|
2015-03-18 19:01:58 +00:00
|
|
|
pArg->prettyPrint->results.clear();
|
|
|
|
pArg->prettyPrint->columns.clear();
|
|
|
|
pArg->prettyPrint->lengths.clear();
|
2014-09-26 03:34:26 +00:00
|
|
|
}
|
|
|
|
|
2014-07-31 00:35:19 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Forward reference */
|
2016-08-29 19:37:04 +00:00
|
|
|
static int process_input(struct callback_data* p, FILE* in);
|
2014-07-31 00:35:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Do C-language style dequoting.
|
|
|
|
**
|
|
|
|
** \t -> tab
|
|
|
|
** \n -> newline
|
|
|
|
** \r -> carriage return
|
|
|
|
** \" -> "
|
|
|
|
** \NNN -> ascii character NNN in octal
|
|
|
|
** \\ -> backslash
|
|
|
|
*/
|
2016-08-29 19:37:04 +00:00
|
|
|
static void resolve_backslashes(char* z) {
|
2014-07-31 00:35:19 +00:00
|
|
|
int i, j;
|
|
|
|
char c;
|
2014-08-15 07:25:30 +00:00
|
|
|
for (i = j = 0; (c = z[i]) != 0; i++, j++) {
|
|
|
|
if (c == '\\') {
|
2014-07-31 00:35:19 +00:00
|
|
|
c = z[++i];
|
2014-08-15 07:25:30 +00:00
|
|
|
if (c == 'n') {
|
2014-07-31 00:35:19 +00:00
|
|
|
c = '\n';
|
2014-08-15 07:25:30 +00:00
|
|
|
} else if (c == 't') {
|
2014-07-31 00:35:19 +00:00
|
|
|
c = '\t';
|
2014-08-15 07:25:30 +00:00
|
|
|
} else if (c == 'r') {
|
2014-07-31 00:35:19 +00:00
|
|
|
c = '\r';
|
2014-08-15 07:25:30 +00:00
|
|
|
} else if (c == '\\') {
|
2014-07-31 00:35:19 +00:00
|
|
|
c = '\\';
|
2014-08-15 07:25:30 +00:00
|
|
|
} else if (c >= '0' && c <= '7') {
|
2014-07-31 00:35:19 +00:00
|
|
|
c -= '0';
|
2014-08-15 07:25:30 +00:00
|
|
|
if (z[i + 1] >= '0' && z[i + 1] <= '7') {
|
2014-07-31 00:35:19 +00:00
|
|
|
i++;
|
2014-08-15 07:25:30 +00:00
|
|
|
c = (c << 3) + z[i] - '0';
|
|
|
|
if (z[i + 1] >= '0' && z[i + 1] <= '7') {
|
2014-07-31 00:35:19 +00:00
|
|
|
i++;
|
2014-08-15 07:25:30 +00:00
|
|
|
c = (c << 3) + z[i] - '0';
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
z[j] = c;
|
|
|
|
}
|
|
|
|
z[j] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Return the value of a hexadecimal digit. Return -1 if the input
|
|
|
|
** is not a hex digit.
|
|
|
|
*/
|
2014-08-15 07:25:30 +00:00
|
|
|
static int hexDigitValue(char c) {
|
2015-08-30 05:08:01 +00:00
|
|
|
if (c >= '0' && c <= '9') {
|
2014-08-15 07:25:30 +00:00
|
|
|
return c - '0';
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
|
|
|
if (c >= 'a' && c <= 'f') {
|
2014-08-15 07:25:30 +00:00
|
|
|
return c - 'a' + 10;
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
|
|
|
if (c >= 'A' && c <= 'F') {
|
2014-08-15 07:25:30 +00:00
|
|
|
return c - 'A' + 10;
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Interpret zArg as an integer value, possibly with suffixes.
|
|
|
|
*/
|
2016-08-29 19:37:04 +00:00
|
|
|
static sqlite3_int64 integerValue(const char* zArg) {
|
2014-07-31 00:35:19 +00:00
|
|
|
sqlite3_int64 v = 0;
|
2014-08-15 07:25:30 +00:00
|
|
|
static const struct {
|
2016-08-29 19:37:04 +00:00
|
|
|
char* zSuffix;
|
2014-08-15 07:25:30 +00:00
|
|
|
int iMult;
|
2014-09-21 21:29:28 +00:00
|
|
|
} aMult[] = {
|
2016-08-29 19:37:04 +00:00
|
|
|
{(char*)"KiB", 1024},
|
|
|
|
{(char*)"MiB", 1024 * 1024},
|
|
|
|
{(char*)"GiB", 1024 * 1024 * 1024},
|
|
|
|
{(char*)"KB", 1000},
|
|
|
|
{(char*)"MB", 1000000},
|
|
|
|
{(char*)"GB", 1000000000},
|
|
|
|
{(char*)"K", 1000},
|
|
|
|
{(char*)"M", 1000000},
|
|
|
|
{(char*)"G", 1000000000},
|
2016-02-25 01:58:58 +00:00
|
|
|
};
|
2014-07-31 00:35:19 +00:00
|
|
|
int i;
|
|
|
|
int isNeg = 0;
|
2014-08-15 07:25:30 +00:00
|
|
|
if (zArg[0] == '-') {
|
2014-07-31 00:35:19 +00:00
|
|
|
isNeg = 1;
|
|
|
|
zArg++;
|
2014-08-15 07:25:30 +00:00
|
|
|
} else if (zArg[0] == '+') {
|
2014-07-31 00:35:19 +00:00
|
|
|
zArg++;
|
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
if (zArg[0] == '0' && zArg[1] == 'x') {
|
2014-07-31 00:35:19 +00:00
|
|
|
int x;
|
|
|
|
zArg += 2;
|
2014-08-15 07:25:30 +00:00
|
|
|
while ((x = hexDigitValue(zArg[0])) >= 0) {
|
|
|
|
v = (v << 4) + x;
|
2014-07-31 00:35:19 +00:00
|
|
|
zArg++;
|
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
} else {
|
|
|
|
while (IsDigit(zArg[0])) {
|
|
|
|
v = v * 10 + zArg[0] - '0';
|
2014-07-31 00:35:19 +00:00
|
|
|
zArg++;
|
|
|
|
}
|
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
for (i = 0; i < ArraySize(aMult); i++) {
|
|
|
|
if (sqlite3_stricmp(aMult[i].zSuffix, zArg) == 0) {
|
2014-07-31 00:35:19 +00:00
|
|
|
v *= aMult[i].iMult;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-10-30 05:25:49 +00:00
|
|
|
return isNeg != 0 ? -v : v;
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Interpret zArg as either an integer or a boolean value. Return 1 or 0
|
|
|
|
** for TRUE and FALSE. Return the integer value if appropriate.
|
|
|
|
*/
|
2016-08-29 19:37:04 +00:00
|
|
|
static int booleanValue(char* zArg) {
|
2014-07-31 00:35:19 +00:00
|
|
|
int i;
|
2014-08-15 07:25:30 +00:00
|
|
|
if (zArg[0] == '0' && zArg[1] == 'x') {
|
|
|
|
for (i = 2; hexDigitValue(zArg[i]) >= 0; i++) {
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; zArg[i] >= '0' && zArg[i] <= '9'; i++) {
|
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
2015-08-30 05:08:01 +00:00
|
|
|
if (i > 0 && zArg[i] == 0) {
|
2017-10-30 05:25:49 +00:00
|
|
|
return static_cast<int>(integerValue(zArg) & 0xffffffff);
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
if (sqlite3_stricmp(zArg, "on") == 0 || sqlite3_stricmp(zArg, "yes") == 0) {
|
2014-07-31 00:35:19 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
if (sqlite3_stricmp(zArg, "off") == 0 || sqlite3_stricmp(zArg, "no") == 0) {
|
2014-07-31 00:35:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2016-08-29 19:37:04 +00:00
|
|
|
fprintf(
|
|
|
|
stderr, "ERROR: Not a boolean value: \"%s\". Assuming \"no\".\n", zArg);
|
2014-07-31 00:35:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-08-29 19:37:04 +00:00
|
|
|
inline void meta_tables(int nArg, char** azArg) {
|
2017-01-07 20:21:35 +00:00
|
|
|
auto tables = osquery::RegistryFactory::get().names("table");
|
2015-05-10 02:48:28 +00:00
|
|
|
std::sort(tables.begin(), tables.end());
|
2016-08-29 19:37:04 +00:00
|
|
|
for (const auto& table_name : tables) {
|
2015-05-10 02:48:28 +00:00
|
|
|
if (nArg == 1 || table_name.find(azArg[1]) == 0) {
|
|
|
|
printf(" => %s\n", table_name.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-29 19:37:04 +00:00
|
|
|
inline void meta_schema(int nArg, char** azArg) {
|
2017-01-07 20:21:35 +00:00
|
|
|
for (const auto& table : osquery::RegistryFactory::get().names("table")) {
|
|
|
|
if (nArg > 1 && table.find(azArg[1]) != 0) {
|
2015-05-10 02:48:28 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
osquery::PluginResponse response;
|
2016-10-18 07:15:38 +00:00
|
|
|
auto status = osquery::Registry::call(
|
2017-01-07 20:21:35 +00:00
|
|
|
"table", table, {{"action", "columns"}}, response);
|
2016-10-18 07:15:38 +00:00
|
|
|
if (status.ok()) {
|
|
|
|
fprintf(stdout,
|
|
|
|
"CREATE TABLE %s%s;\n",
|
2017-01-07 20:21:35 +00:00
|
|
|
table.c_str(),
|
2016-10-18 07:15:38 +00:00
|
|
|
osquery::columnDefinition(response, true).c_str());
|
|
|
|
}
|
2015-05-10 02:48:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-30 23:23:22 +00:00
|
|
|
inline void meta_features(struct callback_data* p) {
|
2017-08-03 03:20:19 +00:00
|
|
|
auto results = osquery::SQL(
|
2016-10-30 23:23:22 +00:00
|
|
|
"select * from osquery_flags where (name like 'disable_%' or name like "
|
|
|
|
"'enable_%') and type = 'bool'");
|
|
|
|
for (const auto& flag : results.rows()) {
|
|
|
|
fprintf(
|
|
|
|
p->out, "%s: %s\n", flag.at("name").c_str(), flag.at("value").c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void meta_version(struct callback_data* p) {
|
|
|
|
fprintf(p->out, "osquery %s\n", osquery::kVersion.c_str());
|
|
|
|
fprintf(p->out, "using SQLite %s\n", sqlite3_libversion());
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void meta_show(struct callback_data* p) {
|
|
|
|
// The show/summary meta command is provided to help with general debugging.
|
|
|
|
// All of this information is 'duplicate', and can be found with better
|
|
|
|
// detail within osquery virtual tables.
|
|
|
|
print_bold("osquery");
|
|
|
|
printf(
|
|
|
|
" - being built, with love, at Facebook\n"
|
|
|
|
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
|
|
|
|
meta_version(p);
|
|
|
|
|
|
|
|
fprintf(p->out, "\nGeneral settings:\n");
|
|
|
|
fprintf(p->out, "%13.13s: %s\n", "Flagfile", FLAGS_flagfile.c_str());
|
|
|
|
// Show helpful config-related settings.
|
|
|
|
fprintf(
|
|
|
|
p->out, "%13.13s: %s", "Config", osquery::FLAGS_config_plugin.c_str());
|
|
|
|
if (osquery::FLAGS_config_plugin == "filesystem") {
|
|
|
|
fprintf(p->out, " (%s)\n", osquery::FLAGS_config_path.c_str());
|
|
|
|
} else if (osquery::FLAGS_config_plugin == "tls") {
|
|
|
|
fprintf(p->out,
|
|
|
|
" (%s%s)\n",
|
|
|
|
osquery::FLAGS_tls_hostname.c_str(),
|
|
|
|
osquery::FLAGS_config_tls_endpoint.c_str());
|
|
|
|
} else {
|
|
|
|
fprintf(p->out, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show helpful logger-related settings.
|
|
|
|
fprintf(
|
|
|
|
p->out, "%13.13s: %s", "Logger", osquery::FLAGS_logger_plugin.c_str());
|
|
|
|
if (osquery::FLAGS_logger_plugin == "filesystem") {
|
|
|
|
fprintf(p->out, " (%s)\n", osquery::FLAGS_logger_path.c_str());
|
|
|
|
} else if (osquery::FLAGS_logger_plugin == "tls") {
|
|
|
|
fprintf(p->out,
|
|
|
|
" (%s%s)\n",
|
|
|
|
osquery::FLAGS_tls_hostname.c_str(),
|
|
|
|
osquery::FLAGS_logger_tls_endpoint.c_str());
|
|
|
|
} else {
|
|
|
|
fprintf(p->out, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(p->out,
|
|
|
|
"%13.13s: %s\n",
|
|
|
|
"Distributed",
|
|
|
|
osquery::FLAGS_distributed_plugin.c_str());
|
|
|
|
|
2017-01-07 20:21:35 +00:00
|
|
|
auto database = osquery::RegistryFactory::get().getActive("database");
|
2016-10-30 23:23:22 +00:00
|
|
|
fprintf(p->out, "%13.13s: %s", "Database", database.c_str());
|
|
|
|
if (database == "rocksdb") {
|
|
|
|
fprintf(p->out, " (%s)\n", osquery::FLAGS_database_path.c_str());
|
|
|
|
} else {
|
|
|
|
fprintf(p->out, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
auto results = osquery::SQL::selectAllFrom("osquery_extensions");
|
|
|
|
std::vector<std::string> extensions;
|
|
|
|
for (const auto& extension : results) {
|
|
|
|
extensions.push_back(extension.at("name"));
|
|
|
|
}
|
|
|
|
fprintf(p->out,
|
|
|
|
"%13.13s: %s\n",
|
|
|
|
"Extensions",
|
|
|
|
osquery::join(extensions, ", ").c_str());
|
|
|
|
|
|
|
|
fprintf(p->out,
|
|
|
|
"%13.13s: %s\n",
|
|
|
|
"Socket",
|
|
|
|
osquery::FLAGS_extensions_socket.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(p->out, "\nShell settings:\n");
|
2017-10-30 05:25:49 +00:00
|
|
|
fprintf(p->out, "%13.13s: %s\n", "echo", p->echoOn != 0 ? "on" : "off");
|
|
|
|
fprintf(
|
|
|
|
p->out, "%13.13s: %s\n", "headers", p->showHeader != 0 ? "on" : "off");
|
2016-10-30 23:23:22 +00:00
|
|
|
fprintf(p->out, "%13.13s: %s\n", "mode", modeDescr[p->mode]);
|
|
|
|
fprintf(p->out, "%13.13s: ", "nullvalue");
|
|
|
|
output_c_string(p->out, p->nullvalue);
|
|
|
|
fprintf(p->out, "\n");
|
|
|
|
fprintf(p->out,
|
|
|
|
"%13.13s: %s\n",
|
|
|
|
"output",
|
2017-10-30 05:25:49 +00:00
|
|
|
strlen30(p->outfile) != 0 ? p->outfile : "stdout");
|
2016-10-30 23:23:22 +00:00
|
|
|
fprintf(p->out, "%13.13s: ", "separator");
|
|
|
|
output_c_string(p->out, p->separator);
|
|
|
|
fprintf(p->out, "\n");
|
|
|
|
fprintf(p->out, "%13.13s: ", "width");
|
|
|
|
for (int i = 0; i < ArraySize(p->colWidth) && p->colWidth[i] != 0; i++) {
|
|
|
|
fprintf(p->out, "%d ", p->colWidth[i]);
|
|
|
|
}
|
|
|
|
fprintf(p->out, "\n");
|
|
|
|
|
|
|
|
{
|
|
|
|
fprintf(p->out, "\nNon-default flags/options:\n");
|
2017-10-14 04:03:59 +00:00
|
|
|
auto results = osquery::SQL(
|
2016-10-30 23:23:22 +00:00
|
|
|
"select * from osquery_flags where default_value <> value");
|
|
|
|
for (const auto& flag : results.rows()) {
|
|
|
|
fprintf(p->out,
|
|
|
|
" %s: %s\n",
|
|
|
|
flag.at("name").c_str(),
|
|
|
|
flag.at("value").c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-31 00:35:19 +00:00
|
|
|
/*
|
2015-03-19 03:47:35 +00:00
|
|
|
** If an input line begins with "." then invoke this routine to
|
|
|
|
** process that line.
|
|
|
|
**
|
|
|
|
** Return 1 on error, 2 to exit, and 0 otherwise.
|
2014-07-31 00:35:19 +00:00
|
|
|
*/
|
2016-08-29 19:37:04 +00:00
|
|
|
static int do_meta_command(char* zLine, struct callback_data* p) {
|
2015-03-19 03:47:35 +00:00
|
|
|
int i = 1;
|
|
|
|
int nArg = 0;
|
|
|
|
int n, c;
|
|
|
|
int rc = 0;
|
2016-08-29 19:37:04 +00:00
|
|
|
char* azArg[50];
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2015-03-19 03:47:35 +00:00
|
|
|
/* Parse the input line into tokens.
|
|
|
|
*/
|
2017-10-30 05:25:49 +00:00
|
|
|
while ((zLine[i] != 0) && nArg < ArraySize(azArg)) {
|
2015-03-19 03:47:35 +00:00
|
|
|
while (IsSpace(zLine[i])) {
|
|
|
|
i++;
|
2014-08-15 07:25:30 +00:00
|
|
|
}
|
2015-08-30 05:08:01 +00:00
|
|
|
if (zLine[i] == 0) {
|
2014-08-15 07:25:30 +00:00
|
|
|
break;
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
if (zLine[i] == '\'' || zLine[i] == '"') {
|
2014-07-31 00:35:19 +00:00
|
|
|
int delim = zLine[i++];
|
|
|
|
azArg[nArg++] = &zLine[i];
|
2017-10-30 05:25:49 +00:00
|
|
|
while ((zLine[i] != 0) && zLine[i] != delim) {
|
2015-08-30 05:08:01 +00:00
|
|
|
if (zLine[i] == '\\' && delim == '"' && zLine[i + 1] != 0) {
|
2014-08-15 07:25:30 +00:00
|
|
|
i++;
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
i++;
|
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
if (zLine[i] == delim) {
|
2014-07-31 00:35:19 +00:00
|
|
|
zLine[i++] = 0;
|
|
|
|
}
|
2015-08-30 05:08:01 +00:00
|
|
|
if (delim == '"') {
|
2014-08-15 07:25:30 +00:00
|
|
|
resolve_backslashes(azArg[nArg - 1]);
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
} else {
|
2014-07-31 00:35:19 +00:00
|
|
|
azArg[nArg++] = &zLine[i];
|
2017-10-30 05:25:49 +00:00
|
|
|
while ((zLine[i] != 0) && !IsSpace(zLine[i])) {
|
2014-08-15 07:25:30 +00:00
|
|
|
i++;
|
|
|
|
}
|
2017-10-30 05:25:49 +00:00
|
|
|
if (zLine[i] != 0) {
|
2014-08-15 07:25:30 +00:00
|
|
|
zLine[i++] = 0;
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
resolve_backslashes(azArg[nArg - 1]);
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Process the input line.
|
|
|
|
*/
|
2015-08-30 05:08:01 +00:00
|
|
|
if (nArg == 0) {
|
2014-08-15 07:25:30 +00:00
|
|
|
return 0; /* no tokens, no error */
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
n = strlen30(azArg[0]);
|
|
|
|
c = azArg[0][0];
|
2015-04-27 23:40:05 +00:00
|
|
|
if (c == 'a' && strncmp(azArg[0], "all", n) == 0 && nArg == 2) {
|
2017-10-30 05:25:49 +00:00
|
|
|
struct callback_data data {};
|
2015-04-27 23:40:05 +00:00
|
|
|
memcpy(&data, p, sizeof(data));
|
|
|
|
auto query = std::string("SELECT * FROM ") + azArg[1];
|
|
|
|
rc = shell_exec(query.c_str(), shell_callback, &data, nullptr);
|
|
|
|
if (rc != SQLITE_OK) {
|
|
|
|
fprintf(stderr, "Error querying table: %s\n", azArg[1]);
|
|
|
|
}
|
2016-02-07 03:20:25 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2016-08-29 19:37:04 +00:00
|
|
|
if (c == 's' && strncmp(azArg[0], "socket", n) == 0 && nArg == 1) {
|
|
|
|
fprintf(p->out, "%s\n", osquery::FLAGS_extensions_socket.c_str());
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2016-02-07 03:20:25 +00:00
|
|
|
// A meta command may act on the database, grab a lock and instance.
|
|
|
|
auto dbc = osquery::SQLiteDBManager::get();
|
|
|
|
auto db = dbc->db();
|
|
|
|
|
|
|
|
if (c == 'b' && n >= 3 && strncmp(azArg[0], "bail", n) == 0 && nArg > 1 &&
|
|
|
|
nArg < 3) {
|
2014-07-31 00:35:19 +00:00
|
|
|
bail_on_error = booleanValue(azArg[1]);
|
2014-08-15 07:25:30 +00:00
|
|
|
} else if (c == 'e' && strncmp(azArg[0], "echo", n) == 0 && nArg > 1 &&
|
|
|
|
nArg < 3) {
|
2014-07-31 00:35:19 +00:00
|
|
|
p->echoOn = booleanValue(azArg[1]);
|
2014-08-15 07:25:30 +00:00
|
|
|
} else if (c == 'e' && strncmp(azArg[0], "exit", n) == 0) {
|
2017-10-30 05:25:49 +00:00
|
|
|
if (nArg > 1 && (rc = static_cast<int>(integerValue(azArg[1]))) != 0) {
|
2014-08-15 07:25:30 +00:00
|
|
|
exit(rc);
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
rc = 2;
|
2016-10-30 23:23:22 +00:00
|
|
|
} else if (c == 'f' && strncmp(azArg[0], "features", n) == 0 && nArg == 1) {
|
|
|
|
meta_features(p);
|
2014-08-15 07:25:30 +00:00
|
|
|
} else if (c == 'h' && (strncmp(azArg[0], "header", n) == 0 ||
|
|
|
|
strncmp(azArg[0], "headers", n) == 0) &&
|
|
|
|
nArg > 1 && nArg < 3) {
|
2014-07-31 00:35:19 +00:00
|
|
|
p->showHeader = booleanValue(azArg[1]);
|
2014-08-15 07:25:30 +00:00
|
|
|
} else if (c == 'h' && strncmp(azArg[0], "help", n) == 0) {
|
|
|
|
fprintf(stderr, "%s", zHelp);
|
|
|
|
if (HAS_TIMER) {
|
|
|
|
fprintf(stderr, "%s", zTimerHelp);
|
|
|
|
}
|
|
|
|
} else if (c == 'm' && strncmp(azArg[0], "mode", n) == 0 && nArg == 2) {
|
2014-07-31 00:35:19 +00:00
|
|
|
int n2 = strlen30(azArg[1]);
|
2014-08-15 07:25:30 +00:00
|
|
|
if ((n2 == 4 && strncmp(azArg[1], "line", n2) == 0) ||
|
|
|
|
(n2 == 5 && strncmp(azArg[1], "lines", n2) == 0)) {
|
2014-07-31 00:35:19 +00:00
|
|
|
p->mode = MODE_Line;
|
2014-08-15 07:25:30 +00:00
|
|
|
} else if ((n2 == 6 && strncmp(azArg[1], "column", n2) == 0) ||
|
|
|
|
(n2 == 7 && strncmp(azArg[1], "columns", n2) == 0)) {
|
2014-07-31 00:35:19 +00:00
|
|
|
p->mode = MODE_Column;
|
2014-08-15 07:25:30 +00:00
|
|
|
} else if (n2 == 4 && strncmp(azArg[1], "list", n2) == 0) {
|
2014-07-31 00:35:19 +00:00
|
|
|
p->mode = MODE_List;
|
2014-09-26 03:34:26 +00:00
|
|
|
} else if (n2 == 6 && strncmp(azArg[1], "pretty", n2) == 0) {
|
|
|
|
p->mode = MODE_Pretty;
|
2014-08-15 07:25:30 +00:00
|
|
|
} else if (n2 == 3 && strncmp(azArg[1], "csv", n2) == 0) {
|
2014-07-31 00:35:19 +00:00
|
|
|
p->mode = MODE_Csv;
|
|
|
|
sqlite3_snprintf(sizeof(p->separator), p->separator, ",");
|
2014-08-15 07:25:30 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Error: mode should be one of: "
|
2015-07-26 17:34:08 +00:00
|
|
|
"column csv line list pretty\n");
|
2014-07-31 00:35:19 +00:00
|
|
|
rc = 1;
|
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
} else if (c == 'n' && strncmp(azArg[0], "nullvalue", n) == 0 && nArg == 2) {
|
|
|
|
sqlite3_snprintf(sizeof(p->nullvalue),
|
|
|
|
p->nullvalue,
|
|
|
|
"%.*s",
|
2015-08-30 05:08:01 +00:00
|
|
|
ArraySize(p->nullvalue) - 1,
|
2014-08-15 07:25:30 +00:00
|
|
|
azArg[1]);
|
|
|
|
} else if (c == 'p' && n >= 3 && strncmp(azArg[0], "print", n) == 0) {
|
2016-11-06 09:17:04 +00:00
|
|
|
int j;
|
|
|
|
for (j = 1; j < nArg; j++) {
|
|
|
|
if (j > 1) {
|
2014-08-15 07:25:30 +00:00
|
|
|
fprintf(p->out, " ");
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2016-11-06 09:17:04 +00:00
|
|
|
fprintf(p->out, "%s", azArg[j]);
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
|
|
|
fprintf(p->out, "\n");
|
2014-08-15 07:25:30 +00:00
|
|
|
} else if (c == 'q' && strncmp(azArg[0], "quit", n) == 0 && nArg == 1) {
|
2014-07-31 00:35:19 +00:00
|
|
|
rc = 2;
|
2014-08-15 07:25:30 +00:00
|
|
|
} else if (c == 's' && strncmp(azArg[0], "schema", n) == 0 && nArg < 3) {
|
2015-05-10 02:48:28 +00:00
|
|
|
meta_schema(nArg, azArg);
|
2015-03-19 03:47:35 +00:00
|
|
|
} else if (c == 's' && strncmp(azArg[0], "separator", n) == 0 && nArg == 2) {
|
2014-08-15 07:25:30 +00:00
|
|
|
sqlite3_snprintf(sizeof(p->separator),
|
|
|
|
p->separator,
|
|
|
|
"%.*s",
|
2017-10-30 05:25:49 +00:00
|
|
|
static_cast<int>(sizeof(p->separator)) - 1,
|
2014-08-15 07:25:30 +00:00
|
|
|
azArg[1]);
|
2016-10-30 23:23:22 +00:00
|
|
|
} else if (c == 's' && (strncmp(azArg[0], "show", n) == 0 ||
|
|
|
|
strncmp(azArg[0], "summary", n) == 0) &&
|
|
|
|
nArg == 1) {
|
|
|
|
meta_show(p);
|
2014-08-15 07:25:30 +00:00
|
|
|
} else if (c == 't' && n > 1 && strncmp(azArg[0], "tables", n) == 0 &&
|
|
|
|
nArg < 3) {
|
2015-05-10 02:48:28 +00:00
|
|
|
meta_tables(nArg, azArg);
|
2016-08-29 19:37:04 +00:00
|
|
|
} else if (c == 'l' && n > 1 && strncmp(azArg[0], "list", n) == 0 &&
|
|
|
|
nArg < 3) {
|
|
|
|
meta_tables(nArg, azArg);
|
2014-08-15 07:25:30 +00:00
|
|
|
} else if (c == 't' && n > 4 && strncmp(azArg[0], "timeout", n) == 0 &&
|
|
|
|
nArg == 2) {
|
2017-10-30 05:25:49 +00:00
|
|
|
sqlite3_busy_timeout(db, static_cast<int>(integerValue(azArg[1])));
|
2014-08-15 07:25:30 +00:00
|
|
|
} else if (HAS_TIMER && c == 't' && n >= 5 &&
|
|
|
|
strncmp(azArg[0], "timer", n) == 0 && nArg == 2) {
|
2014-07-31 00:35:19 +00:00
|
|
|
enableTimer = booleanValue(azArg[1]);
|
2014-08-15 07:25:30 +00:00
|
|
|
} else if (c == 'v' && strncmp(azArg[0], "version", n) == 0) {
|
2016-10-30 23:23:22 +00:00
|
|
|
meta_version(p);
|
2015-03-19 03:47:35 +00:00
|
|
|
} else if (c == 'w' && strncmp(azArg[0], "width", n) == 0 && nArg > 1) {
|
2014-07-31 00:35:19 +00:00
|
|
|
int j;
|
2014-08-15 07:25:30 +00:00
|
|
|
assert(nArg <= ArraySize(azArg));
|
|
|
|
for (j = 1; j < nArg && j < ArraySize(p->colWidth); j++) {
|
2017-10-30 05:25:49 +00:00
|
|
|
p->colWidth[j - 1] = static_cast<int>(integerValue(azArg[j]));
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Error: unknown command or invalid arguments: "
|
|
|
|
" \"%s\". Enter \".help\" for help\n",
|
|
|
|
azArg[0]);
|
2014-07-31 00:35:19 +00:00
|
|
|
rc = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Return TRUE if a semicolon occurs anywhere in the first N characters
|
|
|
|
** of string z[].
|
|
|
|
*/
|
2016-08-29 19:37:04 +00:00
|
|
|
static int line_contains_semicolon(const char* z, int N) {
|
2015-04-17 00:40:19 +00:00
|
|
|
if (z == nullptr) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-30 05:08:01 +00:00
|
|
|
for (int i = 0; i < N; i++) {
|
|
|
|
if (z[i] == ';') {
|
2014-08-15 07:25:30 +00:00
|
|
|
return 1;
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Test to see if a line consists entirely of whitespace.
|
|
|
|
*/
|
2016-08-29 19:37:04 +00:00
|
|
|
static int _all_whitespace(const char* z) {
|
2015-05-13 06:46:02 +00:00
|
|
|
if (z == nullptr) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-30 05:25:49 +00:00
|
|
|
for (; *z != 0; z++) {
|
2015-05-13 06:46:02 +00:00
|
|
|
if (IsSpace(z[0])) {
|
2014-08-15 07:25:30 +00:00
|
|
|
continue;
|
2015-05-13 06:46:02 +00:00
|
|
|
}
|
|
|
|
|
2014-08-15 07:25:30 +00:00
|
|
|
if (*z == '/' && z[1] == '*') {
|
2014-07-31 00:35:19 +00:00
|
|
|
z += 2;
|
2017-10-30 05:25:49 +00:00
|
|
|
while ((*z != 0) && (*z != '*' || z[1] != '/')) {
|
2014-08-15 07:25:30 +00:00
|
|
|
z++;
|
|
|
|
}
|
2015-05-13 06:46:02 +00:00
|
|
|
if (*z == 0) {
|
2014-08-15 07:25:30 +00:00
|
|
|
return 0;
|
2015-05-13 06:46:02 +00:00
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
z++;
|
|
|
|
continue;
|
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
if (*z == '-' && z[1] == '-') {
|
2014-07-31 00:35:19 +00:00
|
|
|
z += 2;
|
2017-10-30 05:25:49 +00:00
|
|
|
while ((*z != 0) && *z != '\n') {
|
2014-08-15 07:25:30 +00:00
|
|
|
z++;
|
|
|
|
}
|
2015-05-13 06:46:02 +00:00
|
|
|
if (*z == 0) {
|
2014-08-15 07:25:30 +00:00
|
|
|
return 1;
|
2015-05-13 06:46:02 +00:00
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Read input from *in and process it. If *in==0 then input
|
|
|
|
** is interactive - the user is typing it it. Otherwise, input
|
|
|
|
** is coming from a file or device. A prompt is issued and history
|
|
|
|
** is saved only if input is interactive. An interrupt signal will
|
|
|
|
** cause this routine to exit immediately, unless input is interactive.
|
|
|
|
**
|
|
|
|
** Return the number of errors.
|
|
|
|
*/
|
2016-08-29 19:37:04 +00:00
|
|
|
static int process_input(struct callback_data* p, FILE* in) {
|
2016-12-02 18:43:43 +00:00
|
|
|
/* A single input line */
|
|
|
|
char* zLine = nullptr;
|
|
|
|
|
|
|
|
/* Accumulated SQL text */
|
|
|
|
char* zSql = nullptr;
|
|
|
|
|
|
|
|
/* Error message returned */
|
|
|
|
char* zErrMsg = nullptr;
|
|
|
|
|
|
|
|
int nLine = 0; /* Length of current line */
|
2014-08-15 07:25:30 +00:00
|
|
|
int nSql = 0; /* Bytes of zSql[] used */
|
|
|
|
int nAlloc = 0; /* Allocated zSql[] space */
|
|
|
|
int nSqlPrior = 0; /* Bytes of zSql[] used by prior line */
|
2016-12-02 18:43:43 +00:00
|
|
|
int rc = 0; /* Error code */
|
2014-08-15 07:25:30 +00:00
|
|
|
int errCnt = 0; /* Number of errors seen */
|
|
|
|
int lineno = 0; /* Current line number */
|
|
|
|
int startline = 0; /* Line number for start of current input */
|
|
|
|
|
2017-10-30 05:25:49 +00:00
|
|
|
while (errCnt == 0 || (bail_on_error == 0) ||
|
|
|
|
(in == nullptr && stdin_is_interactive)) {
|
2014-07-31 00:35:19 +00:00
|
|
|
fflush(p->out);
|
2017-10-30 05:25:49 +00:00
|
|
|
zLine = one_input_line(in, zLine, static_cast<int>(nSql > 0));
|
2016-12-02 18:43:43 +00:00
|
|
|
if (zLine == nullptr) {
|
2014-07-31 00:35:19 +00:00
|
|
|
/* End of input */
|
2015-05-13 06:46:02 +00:00
|
|
|
if (stdin_is_interactive) {
|
2014-08-15 07:25:30 +00:00
|
|
|
printf("\n");
|
2015-05-13 06:46:02 +00:00
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-10-30 05:25:49 +00:00
|
|
|
if (seenInterrupt != 0) {
|
2016-12-02 18:43:43 +00:00
|
|
|
if (in != nullptr) {
|
2014-08-15 07:25:30 +00:00
|
|
|
break;
|
2015-05-13 06:46:02 +00:00
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
seenInterrupt = 0;
|
|
|
|
}
|
|
|
|
lineno++;
|
2017-10-30 05:25:49 +00:00
|
|
|
if (nSql == 0 && (_all_whitespace(zLine) != 0)) {
|
|
|
|
if (p->echoOn != 0) {
|
2014-08-15 07:25:30 +00:00
|
|
|
printf("%s\n", zLine);
|
2015-05-13 06:46:02 +00:00
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
continue;
|
|
|
|
}
|
2016-12-02 18:43:43 +00:00
|
|
|
if (zLine != nullptr && zLine[0] == '.' && nSql == 0) {
|
2017-10-30 05:25:49 +00:00
|
|
|
if (p->echoOn != 0) {
|
2014-08-15 07:25:30 +00:00
|
|
|
printf("%s\n", zLine);
|
2015-05-13 06:46:02 +00:00
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
rc = do_meta_command(zLine, p);
|
2014-09-21 21:29:28 +00:00
|
|
|
if (rc == 2) { /* exit requested */
|
2014-07-31 00:35:19 +00:00
|
|
|
break;
|
2017-10-30 05:25:49 +00:00
|
|
|
} else if (rc != 0) {
|
2014-07-31 00:35:19 +00:00
|
|
|
errCnt++;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
nLine = strlen30(zLine);
|
2014-08-15 07:25:30 +00:00
|
|
|
if (nSql + nLine + 2 >= nAlloc) {
|
|
|
|
nAlloc = nSql + nLine + 100;
|
2017-10-30 05:25:49 +00:00
|
|
|
auto qSql = reinterpret_cast<char*>(realloc(zSql, nAlloc));
|
2016-12-02 18:43:43 +00:00
|
|
|
if (qSql == nullptr) {
|
2014-07-31 00:35:19 +00:00
|
|
|
fprintf(stderr, "Error: out of memory\n");
|
2016-12-02 18:43:43 +00:00
|
|
|
if (zSql != nullptr) {
|
|
|
|
free(zSql);
|
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
exit(1);
|
2016-12-02 18:43:43 +00:00
|
|
|
} else {
|
|
|
|
zSql = qSql;
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
nSqlPrior = nSql;
|
2014-08-15 07:25:30 +00:00
|
|
|
if (nSql == 0) {
|
2014-07-31 00:35:19 +00:00
|
|
|
int i;
|
2017-10-30 05:25:49 +00:00
|
|
|
for (i = 0; (zLine[i] != 0) && IsSpace(zLine[i]); i++) {
|
2014-08-15 07:25:30 +00:00
|
|
|
}
|
2015-04-17 00:40:19 +00:00
|
|
|
assert(nAlloc > 0 && zSql != nullptr);
|
|
|
|
if (zSql != nullptr) {
|
|
|
|
memcpy(zSql, zLine + i, nLine + 1 - i);
|
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
startline = lineno;
|
2014-08-15 07:25:30 +00:00
|
|
|
nSql = nLine - i;
|
|
|
|
} else {
|
2014-07-31 00:35:19 +00:00
|
|
|
zSql[nSql++] = '\n';
|
2014-08-15 07:25:30 +00:00
|
|
|
memcpy(zSql + nSql, zLine, nLine + 1);
|
2014-07-31 00:35:19 +00:00
|
|
|
nSql += nLine;
|
|
|
|
}
|
2017-10-30 05:25:49 +00:00
|
|
|
if ((nSql != 0) &&
|
|
|
|
(line_contains_semicolon(&zSql[nSqlPrior], nSql - nSqlPrior) != 0) &&
|
|
|
|
(sqlite3_complete(zSql) != 0)) {
|
2014-07-31 00:35:19 +00:00
|
|
|
p->cnt = 0;
|
|
|
|
BEGIN_TIMER;
|
2015-04-27 01:54:27 +00:00
|
|
|
rc = shell_exec(zSql, shell_callback, p, &zErrMsg);
|
2014-07-31 00:35:19 +00:00
|
|
|
END_TIMER;
|
2017-10-30 05:25:49 +00:00
|
|
|
if ((rc != 0) || zErrMsg != nullptr) {
|
2016-12-02 18:43:43 +00:00
|
|
|
char zPrefix[100] = {0};
|
2017-10-30 05:25:49 +00:00
|
|
|
if (in != nullptr || !stdin_is_interactive) {
|
2016-08-29 19:37:04 +00:00
|
|
|
sqlite3_snprintf(
|
|
|
|
sizeof(zPrefix), zPrefix, "Error: near line %d:", startline);
|
2014-08-15 07:25:30 +00:00
|
|
|
} else {
|
2014-07-31 00:35:19 +00:00
|
|
|
sqlite3_snprintf(sizeof(zPrefix), zPrefix, "Error:");
|
|
|
|
}
|
2016-12-02 18:43:43 +00:00
|
|
|
if (zErrMsg != nullptr) {
|
2014-07-31 00:35:19 +00:00
|
|
|
fprintf(stderr, "%s %s\n", zPrefix, zErrMsg);
|
|
|
|
sqlite3_free(zErrMsg);
|
2016-12-02 18:43:43 +00:00
|
|
|
zErrMsg = nullptr;
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
|
|
|
errCnt++;
|
|
|
|
}
|
|
|
|
nSql = 0;
|
2017-10-30 05:25:49 +00:00
|
|
|
} else if ((nSql != 0) && (_all_whitespace(zSql) != 0)) {
|
|
|
|
if (p->echoOn != 0) {
|
2014-08-15 07:25:30 +00:00
|
|
|
printf("%s\n", zSql);
|
2015-08-30 05:08:01 +00:00
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
nSql = 0;
|
|
|
|
}
|
|
|
|
}
|
2016-12-02 18:43:43 +00:00
|
|
|
|
2017-10-30 05:25:49 +00:00
|
|
|
if (nSql != 0) {
|
|
|
|
if (_all_whitespace(zSql) == 0) {
|
2014-07-31 00:35:19 +00:00
|
|
|
fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
|
|
|
|
}
|
2016-12-02 18:43:43 +00:00
|
|
|
}
|
|
|
|
if (zSql != nullptr) {
|
2014-07-31 00:35:19 +00:00
|
|
|
free(zSql);
|
|
|
|
}
|
2016-12-02 18:43:43 +00:00
|
|
|
|
2014-07-31 00:35:19 +00:00
|
|
|
free(zLine);
|
2017-10-30 05:25:49 +00:00
|
|
|
return static_cast<int>(errCnt > 0);
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Initialize the state information in data
|
|
|
|
*/
|
2016-08-29 19:37:04 +00:00
|
|
|
static void main_init(struct callback_data* data) {
|
2015-11-01 05:20:23 +00:00
|
|
|
memset(data, 0, sizeof(struct callback_data));
|
2014-10-31 00:58:51 +00:00
|
|
|
data->prettyPrint = new struct prettyprint_data();
|
2014-09-26 03:34:26 +00:00
|
|
|
data->mode = MODE_Pretty;
|
2014-08-12 05:38:51 +00:00
|
|
|
data->showHeader = 1;
|
2015-11-01 05:20:23 +00:00
|
|
|
data->separator[0] = '|';
|
|
|
|
|
2014-07-31 00:35:19 +00:00
|
|
|
sqlite3_config(SQLITE_CONFIG_URI, 1);
|
|
|
|
sqlite3_config(SQLITE_CONFIG_LOG, shellLog, data);
|
|
|
|
|
2016-10-30 23:23:22 +00:00
|
|
|
auto term = osquery::getEnvVar("TERM");
|
|
|
|
if (term.is_initialized() &&
|
|
|
|
(*term).find("xterm-256color") != std::string::npos) {
|
|
|
|
sqlite3_snprintf(
|
|
|
|
sizeof(mainPrompt), mainPrompt, "\033[38;5;147mosquery> \033[0m");
|
|
|
|
sqlite3_snprintf(sizeof(continuePrompt),
|
|
|
|
continuePrompt,
|
|
|
|
"\033[38;5;147m ...> \033[0m");
|
|
|
|
} else {
|
|
|
|
sqlite3_snprintf(sizeof(mainPrompt), mainPrompt, "osquery> ");
|
|
|
|
sqlite3_snprintf(sizeof(continuePrompt), continuePrompt, " ...> ");
|
|
|
|
}
|
|
|
|
sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);
|
2016-08-29 19:37:04 +00:00
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2014-08-15 07:25:30 +00:00
|
|
|
namespace osquery {
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2016-11-06 09:17:48 +00:00
|
|
|
void tableCompletionFunction(char const* prefix, linenoiseCompletions* lc) {
|
2017-01-07 20:21:35 +00:00
|
|
|
auto tables = osquery::RegistryFactory::get().names("table");
|
2016-11-06 09:17:48 +00:00
|
|
|
size_t index = 0;
|
|
|
|
|
|
|
|
while (index < tables.size()) {
|
|
|
|
const std::string& table = tables.at(index);
|
|
|
|
++index;
|
|
|
|
|
|
|
|
if (boost::algorithm::starts_with(table, prefix)) {
|
|
|
|
linenoiseAddCompletion(lc, table.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int runQuery(struct callback_data* data, const char* query) {
|
2016-12-02 18:43:43 +00:00
|
|
|
char* error = nullptr;
|
2016-11-06 09:17:48 +00:00
|
|
|
int rc = shell_exec(query, shell_callback, data, &error);
|
2016-12-02 18:43:43 +00:00
|
|
|
if (error != nullptr) {
|
2016-11-06 09:17:48 +00:00
|
|
|
fprintf(stderr, "Error: %s\n", error);
|
|
|
|
rc = (rc == 0) ? 1 : rc;
|
|
|
|
} else if (rc != 0) {
|
|
|
|
fprintf(stderr, "Error: unable to process SQL \"%s\"\n", query);
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int runPack(struct callback_data* data) {
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
// Check every pack for a name matching the requested --pack flag.
|
2017-05-29 06:04:53 +00:00
|
|
|
Config::get().packs([data, &rc](std::shared_ptr<Pack>& pack) {
|
2016-11-06 09:17:48 +00:00
|
|
|
if (pack->getName() != FLAGS_pack) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto& query : pack->getSchedule()) {
|
|
|
|
rc = runQuery(data, query.second.query.c_str());
|
|
|
|
if (rc != 0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Could not execute query %s: %s\n",
|
|
|
|
query.first.c_str(),
|
|
|
|
query.second.query.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2016-08-29 19:37:04 +00:00
|
|
|
int launchIntoShell(int argc, char** argv) {
|
2017-10-30 05:25:49 +00:00
|
|
|
struct callback_data data {};
|
2015-03-19 03:47:35 +00:00
|
|
|
main_init(&data);
|
|
|
|
|
2016-03-05 04:41:06 +00:00
|
|
|
#if defined(SQLITE_ENABLE_WHERETRACE)
|
|
|
|
sqlite3WhereTrace = 0xffffffff;
|
|
|
|
#endif
|
|
|
|
|
2016-03-20 23:05:13 +00:00
|
|
|
// Move the attach function method into the osquery SQL implementation.
|
|
|
|
// This allow simple/straightforward control of concurrent DB access.
|
|
|
|
osquery::attachFunctionInternal("shellstatic", shellstaticFunc);
|
2016-09-02 22:04:03 +00:00
|
|
|
stdin_is_interactive = platformIsatty(stdin);
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2015-03-19 03:47:35 +00:00
|
|
|
// SQLite: Make sure we have a valid signal handler early
|
2014-07-31 00:35:19 +00:00
|
|
|
signal(SIGINT, interrupt_handler);
|
|
|
|
|
|
|
|
data.out = stdout;
|
|
|
|
|
2015-03-19 03:47:35 +00:00
|
|
|
// Set modes and settings from CLI flags.
|
2017-10-30 05:25:49 +00:00
|
|
|
data.showHeader = static_cast<int>(FLAGS_header);
|
2015-04-27 01:54:27 +00:00
|
|
|
if (FLAGS_list) {
|
2015-03-19 03:47:35 +00:00
|
|
|
data.mode = MODE_List;
|
|
|
|
} else if (FLAGS_line) {
|
|
|
|
data.mode = MODE_Line;
|
|
|
|
} else if (FLAGS_csv) {
|
2015-04-23 21:32:14 +00:00
|
|
|
data.mode = MODE_Csv;
|
2015-11-01 05:20:23 +00:00
|
|
|
data.separator[0] = ',';
|
2015-03-19 03:47:35 +00:00
|
|
|
} else {
|
|
|
|
data.mode = MODE_Pretty;
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
|
|
|
|
2016-08-29 19:37:04 +00:00
|
|
|
sqlite3_snprintf(
|
|
|
|
sizeof(data.separator), data.separator, "%s", FLAGS_separator.c_str());
|
|
|
|
sqlite3_snprintf(
|
|
|
|
sizeof(data.nullvalue), data.nullvalue, "%s", FLAGS_nullvalue.c_str());
|
2015-03-19 03:47:35 +00:00
|
|
|
|
|
|
|
int rc = 0;
|
2017-10-30 05:25:49 +00:00
|
|
|
if (FLAGS_L || !FLAGS_A.empty()) {
|
2015-04-27 23:40:05 +00:00
|
|
|
// Helper meta commands from shell switches.
|
|
|
|
std::string query = (FLAGS_L) ? ".tables" : ".all " + FLAGS_A;
|
2017-10-30 05:25:49 +00:00
|
|
|
auto* cmd = new char[query.size() + 1];
|
2015-04-27 23:40:05 +00:00
|
|
|
memset(cmd, 0, query.size() + 1);
|
|
|
|
std::copy(query.begin(), query.end(), cmd);
|
|
|
|
rc = do_meta_command(cmd, &data);
|
2016-09-29 16:31:56 +00:00
|
|
|
delete[] cmd;
|
2017-10-30 05:25:49 +00:00
|
|
|
} else if (!FLAGS_pack.empty()) {
|
2016-11-06 09:17:48 +00:00
|
|
|
rc = runPack(&data);
|
2015-04-27 23:40:05 +00:00
|
|
|
} else if (argc > 1 && argv[1] != nullptr) {
|
2015-03-19 03:47:35 +00:00
|
|
|
// Run a command or statement from CLI
|
2016-08-29 19:37:04 +00:00
|
|
|
char* query = argv[1];
|
2015-03-19 03:47:35 +00:00
|
|
|
if (query[0] == '.') {
|
|
|
|
rc = do_meta_command(query, &data);
|
|
|
|
rc = (rc == 2) ? 0 : rc;
|
2014-08-15 07:25:30 +00:00
|
|
|
} else {
|
2016-11-06 09:17:48 +00:00
|
|
|
rc = runQuery(&data, query);
|
2016-05-12 16:22:05 +00:00
|
|
|
if (rc != 0) {
|
2014-07-31 00:35:19 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
} else {
|
2015-03-19 03:47:35 +00:00
|
|
|
// Run commands received from standard input
|
2014-08-15 07:25:30 +00:00
|
|
|
if (stdin_is_interactive) {
|
2015-08-30 05:08:01 +00:00
|
|
|
printf("Using a ");
|
2016-10-30 23:23:22 +00:00
|
|
|
print_bold("virtual database");
|
2015-08-30 05:08:01 +00:00
|
|
|
printf(". Need help, type '.help'\n");
|
2015-03-19 03:47:35 +00:00
|
|
|
|
2016-07-25 18:58:55 +00:00
|
|
|
auto history_file =
|
|
|
|
(fs::path(osquery::osqueryHomeDirectory()) / ".history")
|
|
|
|
.make_preferred()
|
|
|
|
.string();
|
|
|
|
linenoiseHistorySetMaxLen(100);
|
|
|
|
linenoiseHistoryLoad(history_file.c_str());
|
2016-11-06 09:17:48 +00:00
|
|
|
linenoiseSetCompletionCallback(tableCompletionFunction);
|
|
|
|
|
2017-10-30 05:25:49 +00:00
|
|
|
rc = process_input(&data, nullptr);
|
2016-07-25 18:58:55 +00:00
|
|
|
|
|
|
|
linenoiseHistorySave(history_file.c_str());
|
2014-08-15 07:25:30 +00:00
|
|
|
} else {
|
2014-07-31 00:35:19 +00:00
|
|
|
rc = process_input(&data, stdin);
|
|
|
|
}
|
|
|
|
}
|
2015-03-19 03:47:35 +00:00
|
|
|
|
2017-10-30 05:25:49 +00:00
|
|
|
set_table_name(&data, nullptr);
|
2014-07-31 00:35:19 +00:00
|
|
|
sqlite3_free(data.zFreeOnClose);
|
2014-11-09 21:31:56 +00:00
|
|
|
|
|
|
|
if (data.prettyPrint != nullptr) {
|
|
|
|
delete data.prettyPrint;
|
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
return rc;
|
|
|
|
}
|
2017-10-30 05:25:49 +00:00
|
|
|
} // namespace osquery
|