Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove hr_name from gvmd #1691

Merged
merged 4 commits into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ include (CPack)

## Variables

set (GVMD_DATABASE_VERSION 247)
set (GVMD_DATABASE_VERSION 248)

set (GVMD_SCAP_DATABASE_VERSION 19)

Expand Down
7 changes: 2 additions & 5 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -8508,7 +8508,6 @@ buffer_config_preference_xml (GString *buffer, iterator_t *prefs,
"<preference>"
"<nvt oid=\"%s\"><name>%s</name></nvt>"
"<id>%s</id>"
"<hr_name>%s</hr_name>"
"<name>%s</name>"
"<type>%s</type>",
oid ? oid : "",
Expand Down Expand Up @@ -11691,24 +11690,22 @@ handle_get_configs (gmp_parser_t *gmp_parser, GError **error)
init_config_preference_iterator (&prefs, config);
while (next (&prefs))
{
const char *name, *hr_name, *value, *type, *def;
const char *name, *value, *type, *def;

hr_name = config_preference_iterator_hr_name (&prefs);
name = config_preference_iterator_name (&prefs);
value = config_preference_iterator_value (&prefs);
def = config_preference_iterator_default (&prefs);
type = config_preference_iterator_type (&prefs);
SENDF_TO_CLIENT_OR_FAIL
("<preference>"
"<nvt oid=\"\"><name/></nvt>"
"<hr_name>%s</hr_name>"
"<id/>"
"<name>%s</name>"
"<type>osp_%s</type>"
"<value>%s</value>"
"<default>%s</default>"
"</preference>",
hr_name, name, type, value ?: "", def);
name, type, value ?: "", def);
}
cleanup_iterator (&prefs);
SEND_TO_CLIENT_OR_FAIL ("</preferences>");
Expand Down
16 changes: 2 additions & 14 deletions src/gmp_configs.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ parse_config_entity (entity_t config, const char **config_id, char **name,
children = preferences->entities;
while ((preference = first_entity (children)))
{
entity_t pref_name, pref_nvt_name, hr_name, nvt, alt;
char *preference_hr_name, *preference_nvt_oid;
entity_t pref_name, pref_nvt_name, nvt, alt;
char *preference_nvt_oid;
array_t *import_alts;
entities_t alts;
preference_t *new_preference;
Expand All @@ -295,17 +295,6 @@ parse_config_entity (entity_t config, const char **config_id, char **name,
if (nvt)
pref_nvt_name = entity_child (nvt, "name");

hr_name = entity_child (preference, "hr_name");
if (*type == NULL || strcmp (*type, "0") == 0)
/* Classic OpenVAS config preference. */
preference_hr_name = NULL;
else if (hr_name && strlen (entity_text (hr_name)))
/* OSP config preference with hr_name given. */
preference_hr_name = entity_text (hr_name);
else
/* Old OSP config without hr_name. */
preference_hr_name = text_or_null (pref_name);

import_alts = make_array ();
alts = preference->entities;
while ((alt = first_entity (alts)))
Expand Down Expand Up @@ -374,7 +363,6 @@ parse_config_entity (entity_t config, const char **config_id, char **name,
preference_nvt_oid,
import_alts,
text_or_null (entity_child (preference, "default")),
preference_hr_name,
0 /* do not free strings */);
}

Expand Down
3 changes: 0 additions & 3 deletions src/manage_configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ config_preference_iterator_type (iterator_t *);
const char*
config_preference_iterator_default (iterator_t *);

const char*
config_preference_iterator_hr_name (iterator_t *);

int
manage_set_config (config_t, const char*, const char *, const char *);

Expand Down
36 changes: 36 additions & 0 deletions src/manage_migrators.c
Original file line number Diff line number Diff line change
Expand Up @@ -2816,6 +2816,41 @@ migrate_246_to_247 ()
return 0;
}

/**
* @brief Migrate the database from version 247 to version 248.
*
* @return 0 success, -1 error.
*/
int
migrate_247_to_248 ()
{
sql_begin_immediate ();

/* Ensure that the database is currently version 247. */

if (manage_db_version () != 247)
{
sql_rollback ();
return -1;
}

/* Update the database. */

/* OSP-scanners are no longer supported. So delete the
* the column hr_name, which was only used by OSP-scanners.
*/
sql ("ALTER TABLE config_preferences DROP COLUMN hr_name;");
sql ("ALTER TABLE config_preferences_trash DROP COLUMN hr_name;");

/* Set the database version to 248. */

set_db_version (248);

sql_commit ();

return 0;
}


#undef UPDATE_DASHBOARD_SETTINGS

Expand Down Expand Up @@ -2870,6 +2905,7 @@ static migrator_t database_migrators[] = {
{245, migrate_244_to_245},
{246, migrate_245_to_246},
{247, migrate_246_to_247},
{248, migrate_247_to_248},
/* End marker. */
{-1, NULL}};

Expand Down
6 changes: 2 additions & 4 deletions src/manage_pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2270,17 +2270,15 @@ create_tables ()
" type text,"
" name text,"
" value text,"
" default_value text,"
" hr_name text);");
" default_value text);");

sql ("CREATE TABLE IF NOT EXISTS config_preferences_trash"
" (id SERIAL PRIMARY KEY,"
" config integer REFERENCES configs_trash (id) ON DELETE RESTRICT,"
" type text,"
" name text,"
" value text,"
" default_value text,"
" hr_name text);");
" default_value text);");

sql ("CREATE TABLE IF NOT EXISTS schedules"
" (id SERIAL PRIMARY KEY,"
Expand Down
5 changes: 1 addition & 4 deletions src/manage_preferences.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@
* @param[in] nvt_oid OID of NVT of preference.
* @param[in] alts Array of gchar's. Alternative values for type radio.
* @param[in] default_value Default value of preference.
* @param[in] hr_name Extended, more human-readable name of the preference.
* @param[in] free_strings Whether string fields are freed by preference_free.
*
* @return Newly allocated preference.
*/
gpointer
preference_new (char *id, char *name, char *type, char *value, char *nvt_name,
char *nvt_oid, array_t *alts, char* default_value,
char *hr_name, int free_strings)
int free_strings)
{
preference_t *preference;

Expand All @@ -57,7 +56,6 @@ preference_new (char *id, char *name, char *type, char *value, char *nvt_name,
preference->nvt_oid = nvt_oid;
preference->alts = alts;
preference->default_value = default_value;
preference->hr_name = hr_name;
preference->free_strings = free_strings;

return preference;
Expand Down Expand Up @@ -85,7 +83,6 @@ preference_free (preference_t *preference)
free (preference->nvt_name);
free (preference->nvt_oid);
free (preference->default_value);
free (preference->hr_name);
}

g_free (preference);
Expand Down
4 changes: 1 addition & 3 deletions src/manage_preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,12 @@ typedef struct
char *nvt_oid; ///< OID of NVT preference affects.
array_t *alts; ///< Array of gchar's. Alternate values for radio type.
char *default_value; ///< Default value of preference.
char *hr_name; ///< Extended, more human-readable name used by OSP.
int free_strings; ///< Whether string fields are freed by preference_free.
} preference_t;

gpointer
preference_new (char *, char *, char *, char *, char *,
char *, array_t *, char*,
char *, int);
char *, array_t *, char*, int);

void
preference_free (preference_t *);
Expand Down
4 changes: 2 additions & 2 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -45983,8 +45983,8 @@ manage_restore (const char *id)
config = sql_last_insert_id ();

sql ("INSERT INTO config_preferences"
" (config, type, name, value, default_value, hr_name)"
" SELECT %llu, type, name, value, default_value, hr_name"
" (config, type, name, value, default_value)"
" SELECT %llu, type, name, value, default_value"
" FROM config_preferences_trash WHERE config = %llu;",
config,
resource);
Expand Down
43 changes: 11 additions & 32 deletions src/manage_sql_configs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2184,11 +2184,11 @@ get_nvt_preference_by_id (const char *nvt_oid,
const char *value)
{
preference_t *new_pref;
char *full_name, *id, *name, *type, *nvt_name, *default_value, *hr_name;
char *full_name, *id, *name, *type, *nvt_name, *default_value;
array_t *alts;
gchar *quoted_oid, *quoted_id;

full_name = name = type = nvt_name = default_value = hr_name = NULL;
full_name = name = type = nvt_name = default_value = NULL;

/* Check parameters */
if (nvt_oid == NULL)
Expand Down Expand Up @@ -2279,7 +2279,6 @@ get_nvt_preference_by_id (const char *nvt_oid,
strdup (nvt_oid),
alts,
default_value,
hr_name,
1);

return new_pref;
Expand Down Expand Up @@ -2338,7 +2337,7 @@ config_insert_preferences (config_t config,
else if (preference->type)
{
gchar *quoted_type, *quoted_nvt_oid, *quoted_preference_name;
gchar *quoted_default, *quoted_preference_hr_name;
gchar *quoted_default;
gchar *quoted_preference_id;

/* Presume NVT or OSP preference. */
Expand All @@ -2357,10 +2356,6 @@ config_insert_preferences (config_t config,
quoted_nvt_oid = sql_quote (preference->nvt_oid ?: "");
quoted_preference_id = sql_quote (preference->id ?: "");
quoted_preference_name = sql_quote (preference->name);
quoted_preference_hr_name
= preference->hr_name
? sql_quote (preference->hr_name)
: NULL;
quoted_type
= g_str_has_prefix (preference->type, "osp_")
? sql_quote (preference->type + strlen ("osp_"))
Expand Down Expand Up @@ -2389,22 +2384,19 @@ config_insert_preferences (config_t config,
{
/* OSP preference */
sql ("INSERT into config_preferences"
" (config, type, name, value, default_value, hr_name)"
" VALUES (%llu, '%s', '%s', '%s', '%s', '%s');",
" (config, type, name, value, default_value)"
" VALUES (%llu, '%s', '%s', '%s', '%s');",
config,
quoted_type,
quoted_preference_name,
quoted_value,
quoted_default,
quoted_preference_hr_name
? quoted_preference_name : quoted_preference_hr_name);
quoted_default);
}
g_free (quoted_nvt_oid);
g_free (quoted_preference_name);
g_free (quoted_type);
g_free (quoted_value);
g_free (quoted_default);
g_free (quoted_preference_hr_name);
g_free (quoted_preference_id);
}
else
Expand Down Expand Up @@ -2907,8 +2899,8 @@ copy_config (const char* name, const char* comment, const char *config_id,
sql ("UPDATE configs SET predefined = 0 WHERE id = %llu;", new);

sql ("INSERT INTO config_preferences (config, type, name, value,"
" default_value, hr_name)"
" SELECT %llu, type, name, value, default_value, hr_name"
" default_value)"
" SELECT %llu, type, name, value, default_value"
" FROM config_preferences"
" WHERE config = %llu;", new, old);

Expand Down Expand Up @@ -3085,8 +3077,8 @@ delete_config (const char *config_id, int ultimate)
trash_config = sql_last_insert_id ();

sql ("INSERT INTO config_preferences_trash"
" (config, type, name, value, default_value, hr_name)"
" SELECT %llu, type, name, value, default_value, hr_name"
" (config, type, name, value, default_value)"
" SELECT %llu, type, name, value, default_value"
" FROM config_preferences WHERE config = %llu;",
trash_config,
config);
Expand Down Expand Up @@ -3455,7 +3447,7 @@ init_config_preference_iterator (iterator_t* iterator, config_t config)
{
gchar* sql;

sql = g_strdup_printf ("SELECT name, value, type, default_value, hr_name"
sql = g_strdup_printf ("SELECT name, value, type, default_value"
" FROM config_preferences"
" WHERE config = %llu;",
config);
Expand Down Expand Up @@ -3505,19 +3497,6 @@ DEF_ACCESS (config_preference_iterator_type, 2);
*/
DEF_ACCESS (config_preference_iterator_default, 3);

/**
* @brief Get the hr_name from a preference iterator.
*
* Note: This corresponds to the "name" in OSP and is not defined for classic
* OpenVAS config preferences.
*
* @param[in] iterator Iterator.
*
* @return The hr_name of the preference iterator, or NULL if iteration is
* complete. Freed by cleanup_iterator.
*/
DEF_ACCESS (config_preference_iterator_hr_name, 4);

/**
* @brief Initialise a config preference iterator, with defaults.
*
Expand Down
18 changes: 0 additions & 18 deletions src/schema_formats/XML/GMP.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -7564,7 +7564,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<name>preference</name>
<pattern>
<e>nvt</e>
<e>hr_name</e>
<e>name</e>
<e>id</e>
<e>type</e>
Expand All @@ -7589,11 +7588,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<pattern><t>name</t></pattern>
</ele>
</ele>
<ele>
<name>hr_name</name>
<summary>The full, more "human readable" name of the preference</summary>
<pattern><t>name</t></pattern>
</ele>
<ele>
<name>name</name>
<summary>The compact name of the preference as used by the scanner</summary>
Expand Down Expand Up @@ -13136,7 +13130,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<pattern>
<e>nvt</e>
<e>name</e>
<e>hr_name</e>
<e>id</e>
<e>type</e>
<e>value</e>
Expand Down Expand Up @@ -13165,11 +13158,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<summary>The name of the preference</summary>
<pattern>text</pattern>
</ele>
<ele>
<name>hr_name</name>
<summary>The full, more "human readable" name of the preference</summary>
<pattern>text</pattern>
</ele>
<ele>
<name>id</name>
<summary>The ID of the preference</summary>
Expand Down Expand Up @@ -14690,7 +14678,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<name>preference</name>
<pattern>
<e>nvt</e>
<e>hr_name</e>
<e>name</e>
<e>id</e>
<e>type</e>
Expand All @@ -14715,11 +14702,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<pattern><t>name</t></pattern>
</ele>
</ele>
<ele>
<name>hr_name</name>
<summary>The full, more "human readable" name of the preference</summary>
<pattern><t>name</t></pattern>
</ele>
<ele>
<name>name</name>
<summary>The name of the preference</summary>
Expand Down