Greenbone Vulnerability Manager
22.4.0~dev1
|
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... | |
int | migrate_221_to_222 () |
Migrate the database from version 221 to version 222. More... | |
int | migrate_222_to_223 () |
Migrate the database from version 222 to version 223. More... | |
int | migrate_223_to_224 () |
Migrate the database from version 223 to version 224. More... | |
int | migrate_224_to_225 () |
Migrate the database from version 224 to version 225. More... | |
int | migrate_225_to_226 () |
Migrate the database from version 225 to version 226. More... | |
int | migrate_226_to_227 () |
Migrate the database from version 226 to version 227. More... | |
static int | migrate_227_to_228_delete (const char *table) |
Delete results for migrate_227_to_228. More... | |
int | migrate_227_to_228 () |
Migrate the database from version 227 to version 228. More... | |
int | migrate_228_to_229 () |
Migrate the database from version 228 to version 229. More... | |
int | migrate_229_to_230 () |
Migrate the database from version 229 to version 230. More... | |
static void | convert_schedules_231 (gboolean trash) |
Add timezones to schedule iCalendar strings. More... | |
int | migrate_230_to_231 () |
Migrate the database from version 230 to version 231. More... | |
int | migrate_231_to_232 () |
Migrate the database from version 231 to version 232. More... | |
int | migrate_232_to_233_set_predefined (const gchar *type, const gchar *table) |
Set predefined. More... | |
int | migrate_232_to_233 () |
Migrate the database from version 232 to version 233. More... | |
int | migrate_233_to_234 () |
Migrate the database from version 233 to version 234. More... | |
int | migrate_234_to_235 () |
Migrate the database from version 234 to version 235. More... | |
int | migrate_235_to_236 () |
Migrate the database from version 235 to version 236. More... | |
int | migrate_236_to_237 () |
Migrate the database from version 236 to version 237. More... | |
int | migrate_237_to_238 () |
Migrate the database from version 237 to version 238. More... | |
int | migrate_238_to_239 () |
Migrate the database from version 238 to version 239. More... | |
int | migrate_239_to_240 () |
Migrate the database from version 239 to version 240. More... | |
int | migrate_240_to_241 () |
Migrate the database from version 240 to version 241. More... | |
int | migrate_241_to_242 () |
Migrate the database from version 241 to version 242. More... | |
int | migrate_242_to_243 () |
Migrate the database from version 242 to version 243. More... | |
int | migrate_243_to_244 () |
Migrate the database from version 243 to version 244. More... | |
int | migrate_244_to_245 () |
Migrate the database from version 244 to version 245. More... | |
int | migrate_245_to_246 () |
Migrate the database from version 245 to version 246. More... | |
int | migrate_246_to_247 () |
Migrate the database from version 246 to version 247. More... | |
int | migrate_247_to_248 () |
Migrate the database from version 247 to version 248. More... | |
int | migrate_248_to_249 () |
Migrate the database from version 248 to version 249. More... | |
int | migrate_249_to_250 () |
Migrate the database from version 249 to version 250. More... | |
gboolean | manage_migrate_needs_timezone (GSList *log_config, const db_conn_info_t *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 db_conn_info_t *database) |
Migrate database to version supported by this manager. More... | |
Variables | |
static migrator_t | database_migrators [] |
Array of database version migrators. | |
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 |
Add timezones to schedule iCalendar strings.
[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 db_conn_info_t * | 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 db_conn_info_t * | 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.
int migrate_221_to_222 | ( | ) |
Migrate the database from version 221 to version 222.
int migrate_222_to_223 | ( | ) |
Migrate the database from version 222 to version 223.
int migrate_223_to_224 | ( | ) |
Migrate the database from version 223 to version 224.
int migrate_224_to_225 | ( | ) |
Migrate the database from version 224 to version 225.
int migrate_225_to_226 | ( | ) |
Migrate the database from version 225 to version 226.
int migrate_226_to_227 | ( | ) |
Migrate the database from version 226 to version 227.
int migrate_227_to_228 | ( | ) |
Migrate the database from version 227 to version 228.
|
static |
Delete results for migrate_227_to_228.
[in] | table | Name of table. |
int migrate_228_to_229 | ( | ) |
Migrate the database from version 228 to version 229.
int migrate_229_to_230 | ( | ) |
Migrate the database from version 229 to version 230.
int migrate_230_to_231 | ( | ) |
Migrate the database from version 230 to version 231.
int migrate_231_to_232 | ( | ) |
Migrate the database from version 231 to version 232.
int migrate_232_to_233 | ( | ) |
Migrate the database from version 232 to version 233.
int migrate_232_to_233_set_predefined | ( | const gchar * | type, |
const gchar * | table | ||
) |
Set predefined.
[in] | type | Type to update. |
[in] | table | Table to update. |
int migrate_233_to_234 | ( | ) |
Migrate the database from version 233 to version 234.
int migrate_234_to_235 | ( | ) |
Migrate the database from version 234 to version 235.
int migrate_235_to_236 | ( | ) |
Migrate the database from version 235 to version 236.
int migrate_236_to_237 | ( | ) |
Migrate the database from version 236 to version 237.
int migrate_237_to_238 | ( | ) |
Migrate the database from version 237 to version 238.
int migrate_238_to_239 | ( | ) |
Migrate the database from version 238 to version 239.
int migrate_239_to_240 | ( | ) |
Migrate the database from version 239 to version 240.
int migrate_240_to_241 | ( | ) |
Migrate the database from version 240 to version 241.
int migrate_241_to_242 | ( | ) |
Migrate the database from version 241 to version 242.
int migrate_242_to_243 | ( | ) |
Migrate the database from version 242 to version 243.
int migrate_243_to_244 | ( | ) |
Migrate the database from version 243 to version 244.
int migrate_244_to_245 | ( | ) |
Migrate the database from version 244 to version 245.
int migrate_245_to_246 | ( | ) |
Migrate the database from version 245 to version 246.
int migrate_246_to_247 | ( | ) |
Migrate the database from version 246 to version 247.
int migrate_247_to_248 | ( | ) |
Migrate the database from version 247 to version 248.
int migrate_248_to_249 | ( | ) |
Migrate the database from version 248 to version 249.
int migrate_249_to_250 | ( | ) |
Migrate the database from version 249 to version 250.
|
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. |