diff --git a/src/gmp.c b/src/gmp.c index 0691dc0c6..9c7be2fc9 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -8508,6 +8508,7 @@ buffer_config_preference_xml (GString *buffer, iterator_t *prefs, "" "%s" "%s" + "%s" "%s" "%s", oid ? oid : "", @@ -11546,7 +11547,7 @@ handle_get_configs (gmp_parser_t *gmp_parser, GError **error) SEND_GET_START ("config"); while (1) { - int config_nvts_growing, config_families_growing, config_type; + int config_nvts_growing, config_families_growing; const char *selector, *usage_type; config_t config; @@ -11565,7 +11566,6 @@ handle_get_configs (gmp_parser_t *gmp_parser, GError **error) selector = config_iterator_nvt_selector (&configs); config = get_iterator_resource (&configs); config_nvts_growing = config_iterator_nvts_growing (&configs); - config_type = config_iterator_type (&configs); usage_type = config_iterator_usage_type (&configs); config_families_growing = config_iterator_families_growing (&configs); @@ -11578,19 +11578,17 @@ handle_get_configs (gmp_parser_t *gmp_parser, GError **error) "" "%i%i" "" - "%i" + "0" "%s" "%i", config_iterator_family_count (&configs), config_families_growing, config_iterator_nvt_count (&configs), config_nvts_growing, - config_type, usage_type, config_iterator_predefined (&configs)); - if (config_type == 0 && (get_configs_data->families - || get_configs_data->get.details)) + if (get_configs_data->families || get_configs_data->get.details) { iterator_t families; int max_nvt_count = 0, known_nvt_count = 0; @@ -11656,62 +11654,7 @@ handle_get_configs (gmp_parser_t *gmp_parser, GError **error) known_nvt_count); } - if (config_type > 0) - { - iterator_t prefs; - scanner_t scanner; - char *s_uuid, *s_name; - - assert (config); - scanner = config_iterator_scanner (&configs); - - if (config_iterator_scanner_trash (&configs)) - { - s_uuid = trash_scanner_uuid (scanner); - s_name = trash_scanner_name (scanner); - } - else - { - s_uuid = scanner_uuid (scanner); - s_name = scanner_name (scanner); - } - - SENDF_TO_CLIENT_OR_FAIL ("" - "%s" - "%d" - "", - s_uuid, s_name, - config_iterator_scanner_trash (&configs)); - - g_free (s_uuid); - g_free (s_name); - SEND_TO_CLIENT_OR_FAIL (""); - - init_config_preference_iterator (&prefs, config); - while (next (&prefs)) - { - const char *name, *value, *type, *def; - - 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 - ("" - "" - "" - "%s" - "osp_%s" - "%s" - "%s" - "", - name, type, value ?: "", def); - } - cleanup_iterator (&prefs); - SEND_TO_CLIENT_OR_FAIL (""); - } - else if (get_configs_data->preferences - || get_configs_data->get.details) + if (get_configs_data->preferences || get_configs_data->get.details) { iterator_t prefs; @@ -11758,7 +11701,7 @@ handle_get_configs (gmp_parser_t *gmp_parser, GError **error) SEND_TO_CLIENT_OR_FAIL (""); } - if (config_type == 0 && get_configs_data->get.details) + if (get_configs_data->get.details) { iterator_t selectors; @@ -17181,7 +17124,6 @@ handle_get_tasks (gmp_parser_t *gmp_parser, GError **error) "%s" "" "%s" - "%i" "%i" "%s" "" @@ -17211,7 +17153,6 @@ handle_get_tasks (gmp_parser_t *gmp_parser, GError **error) task_iterator_usage_type (&tasks), config_uuid ?: "", config_name_escaped ?: "", - config_type (task_config (index)), task_config_in_trash (index), config_available ? "" : "", task_target_uuid ?: "", diff --git a/src/gmp_configs.c b/src/gmp_configs.c index fb34e7387..d9f8b30cd 100644 --- a/src/gmp_configs.c +++ b/src/gmp_configs.c @@ -363,6 +363,7 @@ parse_config_entity (entity_t config, const char **config_id, char **name, preference_nvt_oid, import_alts, text_or_null (entity_child (preference, "default")), + NULL, 0 /* do not free strings */); } @@ -443,7 +444,6 @@ create_config_run (gmp_parser_t *gmp_parser, GError **error) all_selector, import_nvt_selectors, import_preferences, - type, usage_type_text, &new_config, &created_name)) diff --git a/src/manage_configs.c b/src/manage_configs.c index 2d4ccaf63..baf9bc53b 100644 --- a/src/manage_configs.c +++ b/src/manage_configs.c @@ -238,7 +238,6 @@ create_config_from_file (const gchar *path) all_selector, nvt_selectors, preferences, - type, usage_type, &new_config, &created_name)) diff --git a/src/manage_configs.h b/src/manage_configs.h index 2f976096c..b34aa2097 100644 --- a/src/manage_configs.h +++ b/src/manage_configs.h @@ -45,7 +45,7 @@ typedef struct int create_config (const char*, const char*, int, const char*, int, const array_t*, - const array_t*, const char*, const char*, config_t*, char**); + const array_t*, const char*, config_t*, char**); int copy_config (const char*, const char*, const char *, const char *, config_t*); @@ -59,9 +59,6 @@ find_config_with_permission (const char*, config_t*, const char *); char * config_uuid (config_t); -int -config_type (config_t); - char * config_nvt_timeout (config_t, const char *); diff --git a/src/manage_preferences.c b/src/manage_preferences.c index 8fe8f0deb..9d37831d5 100644 --- a/src/manage_preferences.c +++ b/src/manage_preferences.c @@ -43,7 +43,7 @@ gpointer preference_new (char *id, char *name, char *type, char *value, char *nvt_name, char *nvt_oid, array_t *alts, char* default_value, - int free_strings) + char *hr_name, int free_strings) { preference_t *preference; @@ -56,6 +56,7 @@ 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; diff --git a/src/manage_preferences.h b/src/manage_preferences.h index 15b412ebb..a8fb24633 100644 --- a/src/manage_preferences.h +++ b/src/manage_preferences.h @@ -39,12 +39,13 @@ 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. 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*, int); + char *, array_t *, char*, char *, int); void preference_free (preference_t *); diff --git a/src/manage_sql_configs.c b/src/manage_sql_configs.c index 140d1e022..85c44de8b 100644 --- a/src/manage_sql_configs.c +++ b/src/manage_sql_configs.c @@ -970,10 +970,6 @@ manage_set_config_families (config_t config, return 1; } - if (config_type (config) > 0) - { - return 0; - } constraining = config_families_growing (config); if (constraining + grow_families == 1) @@ -2184,11 +2180,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; + char *full_name, *id, *name, *type, *nvt_name, *default_value, *hr_name; array_t *alts; gchar *quoted_oid, *quoted_id; - full_name = name = type = nvt_name = default_value = NULL; + full_name = name = type = nvt_name = default_value = hr_name = NULL; /* Check parameters */ if (nvt_oid == NULL) @@ -2279,6 +2275,7 @@ get_nvt_preference_by_id (const char *nvt_oid, strdup (nvt_oid), alts, default_value, + hr_name, 1); return new_pref; @@ -2289,14 +2286,12 @@ get_nvt_preference_by_id (const char *nvt_oid, * * @param[in] config Config. * @param[in] preferences Preferences. - * @param[in] config_type Config type. * * @return 0 success, -1 error, -4 input error. */ static int config_insert_preferences (config_t config, - const array_t* preferences /* preference_t. */, - const char* config_type) + const array_t* preferences /* preference_t. */) { int index = 0; const preference_t *preference; @@ -2318,8 +2313,7 @@ config_insert_preferences (config_t config, /* Special Timeout preference. */ - if (preference->nvt_oid == NULL - && (config_type == NULL || strcmp (config_type, "0") == 0)) + if (preference->nvt_oid == NULL) return -4; quoted_nvt_oid = sql_quote (preference->nvt_oid); @@ -2342,8 +2336,7 @@ config_insert_preferences (config_t config, /* Presume NVT or OSP preference. */ - if (preference->nvt_oid == NULL - && (config_type == NULL || strcmp (config_type, "0") == 0)) + if (preference->nvt_oid == NULL) return -4; value = g_string_new (preference->value); @@ -2366,32 +2359,18 @@ config_insert_preferences (config_t config, ? sql_quote (preference->default_value) : NULL; - if (config_type == NULL || strcmp (config_type, "0") == 0) - { - /* NVT preference */ - /* OID:PrefID:PrefType:PrefName value */ - sql ("INSERT INTO config_preferences" - " (config, type, name, value)" - " VALUES (%llu, 'PLUGINS_PREFS', '%s:%s:%s:%s', '%s');", - config, - quoted_nvt_oid, - quoted_preference_id, - quoted_type, - quoted_preference_name, - quoted_value); - } - else - { - /* OSP preference */ - sql ("INSERT into config_preferences" - " (config, type, name, value, default_value)" - " VALUES (%llu, '%s', '%s', '%s', '%s');", - config, - quoted_type, - quoted_preference_name, - quoted_value, - quoted_default); - } + /* NVT preference */ + /* OID:PrefID:PrefType:PrefName value */ + sql ("INSERT INTO config_preferences" + " (config, type, name, value)" + " VALUES (%llu, 'PLUGINS_PREFS', '%s:%s:%s:%s', '%s');", + config, + quoted_nvt_oid, + quoted_preference_id, + quoted_type, + quoted_preference_name, + quoted_value); + g_free (quoted_nvt_oid); g_free (quoted_preference_name); g_free (quoted_type); @@ -2433,7 +2412,6 @@ config_insert_preferences (config_t config, * @param[in] all_selector Whether to use "all" selector instead of selectors. * @param[in] selectors NVT selectors. * @param[in] preferences Preferences. - * @param[in] config_type Config type. * @param[in] usage_type The usage type ("scan" or "policy") * @param[in] allow_errors Whether certain errors are allowed. * @param[in] predefined Whether config is predefined. @@ -2451,7 +2429,7 @@ create_config_internal (int check_access, const char *config_id, int all_selector, const array_t *selectors /* nvt_selector_t. */, const array_t *preferences /* preference_t. */, - const char *config_type, const char *usage_type, + const char *usage_type, int allow_errors, int predefined, config_t *config, char **name) { @@ -2492,7 +2470,7 @@ create_config_internal (int check_access, const char *config_id, candidate_name = g_strdup (proposed_name); quoted_candidate_name = sql_quote (candidate_name); - quoted_type = config_type ? sql_quote (config_type) : g_strdup ("0"); + quoted_type = g_strdup ("0"); if (usage_type && strcasecmp (usage_type, "policy") == 0) actual_usage_type = "policy"; else @@ -2550,7 +2528,7 @@ create_config_internal (int check_access, const char *config_id, *config = sql_last_insert_id (); - if (selector_uuid && (config_type == NULL || strcmp (config_type, "0") == 0)) + if (selector_uuid) { if ((ret = insert_nvt_selectors (selector_uuid, selectors, allow_errors))) { @@ -2558,12 +2536,12 @@ create_config_internal (int check_access, const char *config_id, free (selector_uuid); return ret; } + free (selector_uuid); } - free (selector_uuid); /* Insert the preferences into the config_preferences table. */ - if ((ret = config_insert_preferences (*config, preferences, config_type))) + if ((ret = config_insert_preferences (*config, preferences))) { sql_rollback (); return ret; @@ -2591,7 +2569,6 @@ create_config_internal (int check_access, const char *config_id, * @param[in] all_selector Whether to use "all" selector instead of selectors. * @param[in] selectors NVT selectors. * @param[in] preferences Preferences. - * @param[in] config_type Config type. * @param[in] usage_type The usage type ("scan" or "policy") * @param[out] config On success the config. * @param[out] name On success the name of the config. @@ -2605,12 +2582,12 @@ create_config (const char *config_id, const char *proposed_name, int make_name_unique, const char *comment, int all_selector, const array_t *selectors /* nvt_selector_t. */, const array_t *preferences /* preference_t. */, - const char *config_type, const char *usage_type, + const char *usage_type, config_t *config, char **name) { return create_config_internal (1, config_id, proposed_name, make_name_unique, comment, all_selector, selectors, preferences, - config_type, usage_type, 1, + usage_type, 1, 0, /* Predefined. */ config, name); } @@ -2628,7 +2605,6 @@ create_config (const char *config_id, const char *proposed_name, * @param[in] all_selector Whether to use "all" selector instead of selectors. * @param[in] selectors NVT selectors. * @param[in] preferences Preferences. - * @param[in] config_type Config type. * @param[in] usage_type The usage type ("scan" or "policy") * @param[out] config On success the config. * @param[out] name On success the name of the config. @@ -2643,12 +2619,12 @@ create_config_no_acl (const char *config_id, const char *proposed_name, int all_selector, const array_t *selectors /* nvt_selector_t. */, const array_t *preferences /* preference_t. */, - const char *config_type, const char *usage_type, + const char *usage_type, config_t *config, char **name) { return create_config_internal (0, config_id, proposed_name, make_name_unique, comment, all_selector, selectors, preferences, - config_type, usage_type, 0, + usage_type, 0, 1, /* Predefined. */ config, name); } @@ -2688,26 +2664,6 @@ config_uuid (config_t config) return sql_string ("SELECT uuid FROM configs WHERE id = %llu;", config); } -/** - * @brief Return the type of a config. - * - * @param[in] config Config. - * - * @return Config type, -1 if not found. - */ -int -config_type (config_t config) -{ - int type; - char *str; - str = sql_string ("SELECT type FROM configs WHERE id = %llu;", config); - if (!str) - return -1; - type = atoi (str); - g_free (str); - return type; -} - /** * @brief Return whether a config is predefined. * @@ -2768,17 +2724,16 @@ config_nvt_timeout (config_t config, const char *oid) int create_task_check_config_scanner (config_t config, scanner_t scanner) { - int ctype, stype; + int stype; assert (config); assert (scanner); - ctype = config_type (config); stype = scanner_type (scanner); - if (ctype == 0 && stype == SCANNER_TYPE_OPENVAS) + if (stype == SCANNER_TYPE_OPENVAS) return 1; - if (ctype == 0 && stype == SCANNER_TYPE_OSP_SENSOR) + if (stype == SCANNER_TYPE_OSP_SENSOR) return 1; return 0; @@ -2800,7 +2755,7 @@ modify_task_check_config_scanner (task_t task, const char *config_id, { config_t config = 0; scanner_t scanner = 0; - int ctype, stype; + int stype; if (config_id == NULL) config_id = "0"; @@ -2841,19 +2796,16 @@ modify_task_check_config_scanner (task_t task, const char *config_id, * leave the config alone. */ : (config ? 1 : 0); - ctype = config_type (config); - /* OpenVAS Scanner with OpenVAS config. */ - if ((stype == SCANNER_TYPE_OPENVAS) - && ctype == 0) + if (stype == SCANNER_TYPE_OPENVAS) return 0; /* OSP Sensor with OpenVAS config. */ - if (stype == SCANNER_TYPE_OSP_SENSOR && ctype == 0) + if (stype == SCANNER_TYPE_OSP_SENSOR) return 0; /* Default Scanner with OpenVAS Config. */ - if (scanner == 0 && ctype == 0) + if (scanner == 0) return 0; return 1; @@ -2875,7 +2827,7 @@ int copy_config (const char* name, const char* comment, const char *config_id, const char* usage_type, config_t* new_config) { - int ret, type; + int ret; char *config_selector; gchar *quoted_config_selector; config_t new, old; @@ -2904,17 +2856,6 @@ copy_config (const char* name, const char* comment, const char *config_id, " FROM config_preferences" " WHERE config = %llu;", new, old); - type = config_type (new); - if (type > 0) - { - /* Don't create nvt_selector etc,. for non-standard configs - * (eg. OSP config.) Only config preferences are copied. - */ - sql_commit (); - if (new_config) *new_config = new; - return 0; - } - sql ("UPDATE configs SET nvt_selector = make_uuid () WHERE id = %llu;", new); @@ -3683,23 +3624,16 @@ modify_config_preference (config_t config, const char* nvt, quoted_value = sql_quote ((gchar*) value); g_free (value); - if (config_type (config) > 0) - sql ("UPDATE config_preferences SET value = '%s'" - " WHERE config = %llu AND name = '%s';", - quoted_value, config, quoted_name); - else - { - /* nvt prefs are not present on first modification. */ - sql ("DELETE FROM config_preferences" - " WHERE config = %llu AND type %s AND name = '%s'", - config, - nvt ? "= 'PLUGINS_PREFS'" : "= 'SERVER_PREFS'", - quoted_name); - sql ("INSERT INTO config_preferences" - " (config, type, name, value) VALUES (%llu, %s, '%s', '%s');", - config, nvt ? "'PLUGINS_PREFS'" : "'SERVER_PREFS'", quoted_name, - quoted_value); - } + /* nvt prefs are not present on first modification. */ + sql ("DELETE FROM config_preferences" + " WHERE config = %llu AND type %s AND name = '%s'", + config, + nvt ? "= 'PLUGINS_PREFS'" : "= 'SERVER_PREFS'", + quoted_name); + sql ("INSERT INTO config_preferences" + " (config, type, name, value) VALUES (%llu, %s, '%s', '%s');", + config, nvt ? "'PLUGINS_PREFS'" : "'SERVER_PREFS'", quoted_name, + quoted_value); return 0; } @@ -4559,7 +4493,7 @@ update_config (config_t config, const gchar *type, const gchar *name, /* Replace the preferences. */ sql ("DELETE FROM config_preferences WHERE config = %llu;", config); - if (config_insert_preferences (config, preferences, type)) + if (config_insert_preferences (config, preferences)) { g_warning ("%s: Error in feed config preference", __func__); sql_rollback (); diff --git a/src/manage_sql_configs.h b/src/manage_sql_configs.h index 27236d706..9ae45816c 100644 --- a/src/manage_sql_configs.h +++ b/src/manage_sql_configs.h @@ -73,7 +73,7 @@ configs_extra_where (const char *); int create_config_no_acl (const char *, const char *, int, const char *, int, const array_t *, const array_t *, const char *, - const char *, config_t *, char **); + config_t *, char **); gboolean find_config_no_acl (const char *, config_t *);