2014-12-18 18:50:47 +00:00
|
|
|
/*
|
2016-02-11 19:48:58 +00:00
|
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
2014-12-18 18:50:47 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
2015-02-03 05:21:36 +00:00
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
2014-12-18 18:50:47 +00:00
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
*/
|
2014-12-03 04:36:46 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2015-01-12 18:02:44 +00:00
|
|
|
#include <osquery/tables.h>
|
2014-12-03 04:36:46 +00:00
|
|
|
|
2015-11-01 09:12:48 +00:00
|
|
|
#include "osquery/core/conversions.h"
|
2015-02-03 05:21:36 +00:00
|
|
|
#include "osquery/sql/sqlite_util.h"
|
|
|
|
|
2014-12-03 04:36:46 +00:00
|
|
|
namespace osquery {
|
|
|
|
|
2014-12-03 16:29:36 +00:00
|
|
|
/**
|
|
|
|
* @brief osquery cursor object.
|
|
|
|
*
|
|
|
|
* Only used in the SQLite virtual table module methods.
|
|
|
|
*/
|
2015-01-30 18:44:25 +00:00
|
|
|
struct BaseCursor {
|
2014-12-03 04:36:46 +00:00
|
|
|
/// SQLite virtual table cursor.
|
|
|
|
sqlite3_vtab_cursor base;
|
2015-12-03 03:57:24 +00:00
|
|
|
/// Track cursors for optional planner output.
|
|
|
|
size_t id{0};
|
2015-11-20 19:03:57 +00:00
|
|
|
/// Table data generated from last access.
|
2015-08-17 23:58:54 +00:00
|
|
|
QueryData data;
|
2015-11-20 19:03:57 +00:00
|
|
|
/// Current cursor position.
|
|
|
|
size_t row{0};
|
|
|
|
/// Total number of rows.
|
|
|
|
size_t n{0};
|
2015-01-30 18:44:25 +00:00
|
|
|
};
|
|
|
|
|
2014-12-03 16:29:36 +00:00
|
|
|
/**
|
|
|
|
* @brief osquery virtual table object
|
|
|
|
*
|
|
|
|
* Only used in the SQLite virtual table module methods.
|
|
|
|
* This adds each table plugin class to the state tracking in SQLite.
|
|
|
|
*/
|
2015-01-30 18:44:25 +00:00
|
|
|
struct VirtualTable {
|
2016-02-25 01:58:58 +00:00
|
|
|
/// The SQLite-provided virtual table structure.
|
2014-12-03 04:36:46 +00:00
|
|
|
sqlite3_vtab base;
|
2016-02-25 01:58:58 +00:00
|
|
|
|
|
|
|
/// Added structure: A content structure with metadata about the table.
|
2015-11-20 19:03:57 +00:00
|
|
|
VirtualTableContent *content{nullptr};
|
2016-02-25 01:58:58 +00:00
|
|
|
|
|
|
|
/// Added structure: The thread-local DB instance associated with the query.
|
|
|
|
SQLiteDBInstance *instance{nullptr};
|
2014-12-03 04:36:46 +00:00
|
|
|
};
|
|
|
|
|
2015-02-23 05:56:52 +00:00
|
|
|
/// Attach a table plugin name to an in-memory SQLite database.
|
|
|
|
Status attachTableInternal(const std::string &name,
|
|
|
|
const std::string &statement,
|
2016-02-25 01:58:58 +00:00
|
|
|
const SQLiteDBInstanceRef &instance);
|
2015-02-03 05:21:36 +00:00
|
|
|
|
2015-02-23 05:56:52 +00:00
|
|
|
/// Detach (drop) a table.
|
|
|
|
Status detachTableInternal(const std::string &name, sqlite3 *db);
|
|
|
|
|
|
|
|
/// Attach all table plugins to an in-memory SQLite database.
|
2016-02-25 01:58:58 +00:00
|
|
|
void attachVirtualTables(const SQLiteDBInstanceRef &instance);
|
2014-12-03 04:36:46 +00:00
|
|
|
}
|