Greenbone Vulnerability Manager
9.0.1
|
The Greenbone Vulnerability Manager DB Migrators file. More...
#include <assert.h>
#include <errno.h>
#include <glib/gstdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <time.h>
#include "manage_migrators_219_to_220_names.h"
#include "manage_sql.h"
#include "sql.h"
#include "utils.h"
#include <ctype.h>
#include <dirent.h>
#include <gvm/base/logging.h>
#include <gvm/util/fileutils.h>
#include <gvm/util/uuidutils.h>
Data Structures | |
struct | migrator_t |
A migrator. More... | |
Macros | |
#define | _XOPEN_SOURCE |
#define | G_LOG_DOMAIN "md main" |
GLib log domain. | |
#define | MIGRATE_MIN_OLD_VERSION 205 |
The oldest version for which migration is supported. | |
Functions | |
void | manage_create_result_indexes () |
Create result indexes. | |
static void | move (const gchar *table, const gchar *old, const gchar *new) |
Rename a column. More... | |
int | migrate_204_to_205 () |
Migrate the database from version 204 to version 205. More... | |
static void | replace_preference_names_205_to_206 (const char *table_name) |
Converts old NVT preferences to the new format. More... | |
int | migrate_205_to_206 () |
Migrate the database from version 205 to version 206. More... | |
int | migrate_206_to_207 () |
Migrate the database from version 206 to version 207. More... | |
int | migrate_207_to_208 () |
Migrate the database from version 207 to version 208. More... | |
int | migrate_208_to_209 () |
Migrate the database from version 208 to version 209. More... | |
int | migrate_209_to_210 () |
Migrate the database from version 209 to version 210. More... | |
int | migrate_210_to_211 () |
Migrate the database from version 210 to version 211. More... | |
int | migrate_211_to_212 () |
Migrate the database from version 211 to version 212. More... | |
resource_t | tls_certificate_get_location_213 (const char *host_ip, const char *port) |
Gets or creates a tls_certificate_location in the version 213 format. More... | |
resource_t | tls_certificate_get_origin_213 (const char *origin_type, const char *origin_id, const char *origin_data) |
Gets or creates a tls_certificate_origin in the version 213 format. More... | |
int | migrate_212_to_213 () |
Migrate the database from version 212 to version 213. More... | |
static tls_certificate_t | make_tls_certificate_214 (user_t owner, const char *certificate_b64, const char *subject_dn, const char *issuer_dn, time_t activation_time, time_t expiration_time, const char *md5_fingerprint, const char *sha256_fingerprint, const char *serial, gnutls_x509_crt_fmt_t certificate_format) |
Create a TLS certificate in the version 214 format. More... | |
static void | create_temp_tables_213_to_214 () |
Create temporary, indexed tables for TLS certificate host details. More... | |
int | migrate_213_to_214 () |
Migrate the database from version 213 to version 214. More... | |
int | migrate_214_to_215 () |
Migrate the database from version 214 to version 215. More... | |
int | migrate_215_to_216 () |
Migrate the database from version 215 to version 216. More... | |
int | migrate_216_to_217 () |
Migrate the database from version 216 to version 217. More... | |
int | migrate_217_to_218 () |
Migrate the database from version 217 to version 218. More... | |
int | migrate_218_to_219 () |
Migrate the database from version 218 to version 219. More... | |
static const gchar * | migrate_219_to_220_new_name (const char *old_name) |
Get new name of a preference. More... | |
static void | replace_preference_names_219_to_220 (const char *table_name) |
Converts old NVT preferences to the new format. More... | |
int | migrate_219_to_220 () |
Migrate the database from version 219 to version 220. More... | |
static void | convert_schedules_221 (gboolean trash) |
Convert iCalendar strings of schedules to new format for version 221. More... | |
int | migrate_220_to_221 () |
Migrate the database from version 220 to version 221. More... | |
gboolean | manage_migrate_needs_timezone (GSList *log_config, const gchar *database) |
Check whether the migration needs the real timezone. More... | |
static int | migrate_is_available (int old_version, int new_version) |
Check whether a migration is available. More... | |
int | manage_migrate (GSList *log_config, const gchar *database) |
Migrate database to version supported by this manager. More... | |
Variables | |
static migrator_t | database_migrators [] |
Array of database version migrators. More... | |
The Greenbone Vulnerability Manager DB Migrators file.
This file defines the functions used by the manager to migrate the DB to the newest version.
#define _XOPEN_SOURCE |
Every change that affects the database schema or the format of the data in the database must have a migrator so that someone using an older version of the database can update to the newer version.
Simply adding a new table to the database is, however, OK. At startup, the manager will automatically add a table if it is missing from the database.
* CMakeLists.txt (GVMD_DATABASE_VERSION): Increase to 6, for... * src/manage_sql.c (create_tables): Add new table...
Add database migration from version 5 to 6.SQL that created database version 0:
CREATE TABLE IF NOT EXISTS config_preferences (config INTEGER, type, name, value); CREATE TABLE IF NOT EXISTS configs (name UNIQUE, nvt_selector, comment, family_count INTEGER, nvt_count INTEGER, families_growing INTEGER, nvts_growing INTEGER); CREATE TABLE IF NOT EXISTS meta (name UNIQUE, value); CREATE TABLE IF NOT EXISTS nvt_selectors (name, exclude INTEGER, type INTEGER, family_or_nvt); CREATE TABLE IF NOT EXISTS nvts (oid, version, name, summary, description, copyright, cve, bid, xref, tag, sign_key_ids, category, family); CREATE TABLE IF NOT EXISTS report_hosts (report INTEGER, host, start_time, end_time, attack_state, current_port, max_port); CREATE TABLE IF NOT EXISTS report_results (report INTEGER, result INTEGER); CREATE TABLE IF NOT EXISTS reports (uuid, hidden INTEGER, task INTEGER, date INTEGER, start_time, end_time, nbefile, comment); CREATE TABLE IF NOT EXISTS results (task INTEGER, subnet, host, port, nvt, type, description); CREATE TABLE IF NOT EXISTS targets (name, hosts, comment); CREATE TABLE IF NOT EXISTS tasks (uuid, name, hidden INTEGER, time, comment, description, owner, run_status, start_time, end_time, config, target); CREATE TABLE IF NOT EXISTS users (name UNIQUE, password);
|
static |
Convert iCalendar strings of schedules to new format for version 221.
[in] | trash | Whether to convert the trash table. |
|
static |
Create temporary, indexed tables for TLS certificate host details.
This makes it quicker to access host details that are slow to get repeatedly for every TLS certificate, presumably because of the "LIKE" conditions for the name or value field.
|
static |
Create a TLS certificate in the version 214 format.
[in] | owner | Owner of the new tls_certificate. |
[in] | certificate_b64 | The Base64 encoded certificate. |
[in] | subject_dn | The subject DN of the certificate. |
[in] | issuer_dn | The issuer DN of the certificate. |
[in] | activation_time | Time before which the certificate is invalid. |
[in] | expiration_time | Time after which the certificate is expired. |
[in] | md5_fingerprint | MD5 fingerprint of the certificate. |
[in] | sha256_fingerprint | SHA-256 fingerprint of the certificate. |
[in] | serial | Serial of the certificate. |
[in] | certificate_format | Certificate format (DER or PEM). |
int manage_migrate | ( | GSList * | log_config, |
const gchar * | database | ||
) |
Migrate database to version supported by this manager.
[in] | log_config | Log configuration. |
[in] | database | Location of manage database. |
gboolean manage_migrate_needs_timezone | ( | GSList * | log_config, |
const gchar * | database | ||
) |
Check whether the migration needs the real timezone.
[in] | log_config | Log configuration. |
[in] | database | Location of manage database. |
int migrate_204_to_205 | ( | ) |
Migrate the database from version 204 to version 205.
int migrate_205_to_206 | ( | ) |
Migrate the database from version 205 to version 206.
int migrate_206_to_207 | ( | ) |
Migrate the database from version 206 to version 207.
int migrate_207_to_208 | ( | ) |
Migrate the database from version 207 to version 208.
int migrate_208_to_209 | ( | ) |
Migrate the database from version 208 to version 209.
int migrate_209_to_210 | ( | ) |
Migrate the database from version 209 to version 210.
int migrate_210_to_211 | ( | ) |
Migrate the database from version 210 to version 211.
int migrate_211_to_212 | ( | ) |
Migrate the database from version 211 to version 212.
int migrate_212_to_213 | ( | ) |
Migrate the database from version 212 to version 213.
int migrate_213_to_214 | ( | ) |
Migrate the database from version 213 to version 214.
int migrate_214_to_215 | ( | ) |
Migrate the database from version 214 to version 215.
int migrate_215_to_216 | ( | ) |
Migrate the database from version 215 to version 216.
int migrate_216_to_217 | ( | ) |
Migrate the database from version 216 to version 217.
int migrate_217_to_218 | ( | ) |
Migrate the database from version 217 to version 218.
int migrate_218_to_219 | ( | ) |
Migrate the database from version 218 to version 219.
int migrate_219_to_220 | ( | ) |
Migrate the database from version 219 to version 220.
|
static |
Get new name of a preference.
[in] | old_name | Old name of preference. |
int migrate_220_to_221 | ( | ) |
Migrate the database from version 220 to version 221.
|
static |
Check whether a migration is available.
[in] | old_version | Version to migrate from. |
[in] | new_version | Version to migrate to. |
|
static |
Rename a column.
Currently the SQL functions abort on failure. This a general problem, not just for migrators, so perhaps the SQL interface should keep track of the transaction, and rollback before aborting.
[in] | table | Table |
[in] | old | Old column. |
[in] | new | New column. |
|
static |
Converts old NVT preferences to the new format.
[in] | table_name | The name of the table to update. |
|
static |
Converts old NVT preferences to the new format.
[in] | table_name | The name of the table to update. |
resource_t tls_certificate_get_location_213 | ( | const char * | host_ip, |
const char * | port | ||
) |
Gets or creates a tls_certificate_location in the version 213 format.
If a location with matching host_ip and port exists its id is returned, otherwise a new one is created and its id is returned.
[in] | host_ip | IP address of the location |
[in] | port | Port number of the location |
resource_t tls_certificate_get_origin_213 | ( | const char * | origin_type, |
const char * | origin_id, | ||
const char * | origin_data | ||
) |
Gets or creates a tls_certificate_origin in the version 213 format.
If an origin with matching type, id and data exists its id is returned, otherwise a new one is created and its id is returned.
[in] | origin_type | Origin type, e.g. "GMP" or "Report" |
[in] | origin_id | Origin resource id, e.g. a report UUID. |
[in] | origin_data | Origin extra data, e.g. OID of generating NVT. |
|
static |
Array of database version migrators.