Skip to content

Commit

Permalink
Change: Rebuild NVTs in shadow tables
Browse files Browse the repository at this point in the history
  • Loading branch information
timopollmeier authored Apr 24, 2023
2 parents 89c15e2 + 104914b commit b927bf7
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 93 deletions.
2 changes: 1 addition & 1 deletion src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1924,7 +1924,7 @@ nvt_selector_iterator_type (iterator_t*);
/* NVT preferences. */

void
manage_nvt_preference_add (const char*, const char*);
manage_nvt_preference_add (const char*, const char*, int);

void
manage_nvt_preferences_enable ();
Expand Down
103 changes: 58 additions & 45 deletions src/manage_pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@


/* Headers */
int
int
check_db_extensions ();


Expand Down Expand Up @@ -1747,6 +1747,62 @@ create_view_vulns ()

#undef VULNS_RESULTS_WHERE

/**
* @brief Create NVT related tables.
*/
void
create_tables_nvt (const gchar *suffix)
{
sql ("CREATE TABLE IF NOT EXISTS vt_refs%s"
" (id SERIAL PRIMARY KEY,"
" vt_oid text NOT NULL,"
" type text NOT NULL,"
" ref_id text NOT NULL,"
" ref_text text);",
suffix);

sql ("CREATE TABLE IF NOT EXISTS vt_severities%s"
" (id SERIAL PRIMARY KEY,"
" vt_oid text NOT NULL,"
" type text NOT NULL,"
" origin text,"
" date integer,"
" score double precision,"
" value text);",
suffix);

sql ("CREATE TABLE IF NOT EXISTS nvt_preferences%s"
" (id SERIAL PRIMARY KEY,"
" name text UNIQUE NOT NULL,"
" value text);",
suffix);

sql ("CREATE TABLE IF NOT EXISTS nvts%s"
" (id SERIAL PRIMARY KEY,"
" uuid text UNIQUE NOT NULL,"
" oid text UNIQUE NOT NULL,"
" name text,"
" comment text,"
" summary text,"
" insight text,"
" affected text,"
" impact text,"
" cve text,"
" tag text,"
" category text,"
" family text,"
" cvss_base text,"
" creation_time integer,"
" modification_time integer,"
" solution text,"
" solution_type text,"
" solution_method text,"
" detection text,"
" qod integer,"
" qod_type text);",
suffix);
}

/**
* @brief Create all tables.
*/
Expand Down Expand Up @@ -2565,50 +2621,7 @@ create_tables ()
" name text,"
" value text);");

sql ("CREATE TABLE IF NOT EXISTS vt_refs"
" (id SERIAL PRIMARY KEY,"
" vt_oid text NOT NULL,"
" type text NOT NULL,"
" ref_id text NOT NULL,"
" ref_text text);");

sql ("CREATE TABLE IF NOT EXISTS vt_severities"
" (id SERIAL PRIMARY KEY,"
" vt_oid text NOT NULL,"
" type text NOT NULL,"
" origin text,"
" date integer,"
" score double precision,"
" value text);");

sql ("CREATE TABLE IF NOT EXISTS nvt_preferences"
" (id SERIAL PRIMARY KEY,"
" name text UNIQUE NOT NULL,"
" value text);");

sql ("CREATE TABLE IF NOT EXISTS nvts"
" (id SERIAL PRIMARY KEY,"
" uuid text UNIQUE NOT NULL,"
" oid text UNIQUE NOT NULL,"
" name text,"
" comment text,"
" summary text,"
" insight text,"
" affected text,"
" impact text,"
" cve text,"
" tag text,"
" category text,"
" family text,"
" cvss_base text,"
" creation_time integer,"
" modification_time integer,"
" solution text,"
" solution_type text,"
" solution_method text,"
" detection text,"
" qod integer,"
" qod_type text);");
create_tables_nvt ("");

sql ("CREATE TABLE IF NOT EXISTS notes"
" (id SERIAL PRIMARY KEY,"
Expand Down
22 changes: 13 additions & 9 deletions src/manage_sql_configs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1694,25 +1694,29 @@ check_config_families ()
/**
* @brief Add/replace an NVT preference.
*
* @param[in] name The name of the preference.
* @param[in] value The value of the preference.
* @param[in] name The name of the preference.
* @param[in] value The value of the preference.
* @param[in] rebuild Whether a rebuild is happening.
*/
void
manage_nvt_preference_add (const char* name, const char* value)
manage_nvt_preference_add (const char* name, const char* value, int rebuild)
{
gchar* quoted_name = sql_quote (name);
gchar* quoted_value = sql_quote (value);

if (strcmp (name, "port_range"))
{
if (sql_int ("SELECT EXISTS"
" (SELECT * FROM nvt_preferences"
" WHERE name = '%s')",
quoted_name))
sql ("DELETE FROM nvt_preferences WHERE name = '%s';", quoted_name);
if (rebuild == 0) {
if (sql_int ("SELECT EXISTS"
" (SELECT * FROM nvt_preferences"
" WHERE name = '%s')",
quoted_name))
sql ("DELETE FROM nvt_preferences WHERE name = '%s';", quoted_name);
}

sql ("INSERT into nvt_preferences (name, value)"
sql ("INSERT into nvt_preferences%s (name, value)"
" VALUES ('%s', '%s');",
rebuild ? "_rebuild" : "",
quoted_name, quoted_value);
}

Expand Down
Loading

0 comments on commit b927bf7

Please sign in to comment.