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

Always check for 'All' when deleting selectors #1342

Merged
merged 3 commits into from
Nov 3, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Correct check of get_certificate_info return [#1318](https://github.com/greenbone/gvmd/pull/1318)
- Fix GMP doc text of `active` elem for notes and overrides [#1323](https://github.com/greenbone/gvmd/pull/1323)
- Move feed object in trash checks to startup [#1325](https://github.com/greenbone/gvmd/pull/1325)
- Always check for 'All' when deleting selectors [#1342](https://github.com/greenbone/gvmd/pull/1342)
- Do not inherit settings from deleted users [#1328](https://github.com/greenbone/gvmd/pull/1328)
- Delete TLS certificate sources when deleting users [#1334](https://github.com/greenbone/gvmd/pull/1334)

Expand Down
9 changes: 5 additions & 4 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -47526,10 +47526,11 @@ manage_empty_trashcan ()
return 99;
}

sql ("DELETE FROM nvt_selectors WHERE name IN"
" (SELECT nvt_selector FROM configs_trash"
" WHERE owner = (SELECT id FROM users"
" WHERE uuid = '%s'));",
sql ("DELETE FROM nvt_selectors"
" WHERE name != '" MANAGE_NVT_SELECTOR_UUID_ALL "'"
" AND name IN (SELECT nvt_selector FROM configs_trash"
" WHERE owner = (SELECT id FROM users"
" WHERE uuid = '%s'));",
current_credentials.uuid);
sql ("DELETE FROM config_preferences_trash"
" WHERE config IN (SELECT id FROM configs_trash"
Expand Down
47 changes: 29 additions & 18 deletions src/manage_sql_configs.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,8 @@ nvt_selector_remove (const char* quoted_selector,
const char* quoted_family,
int type)
{
if (strcmp (quoted_selector, MANAGE_NVT_SELECTOR_UUID_ALL) == 0)
return;
if (type == NVT_SELECTOR_TYPE_ANY)
sql ("DELETE FROM nvt_selectors"
" WHERE name = '%s'"
Expand Down Expand Up @@ -637,6 +639,8 @@ nvt_selector_remove_selector (const char* quoted_selector,
const char* family_or_nvt,
int type)
{
if (strcmp (quoted_selector, MANAGE_NVT_SELECTOR_UUID_ALL) == 0)
return;
if (type == NVT_SELECTOR_TYPE_ANY)
sql ("DELETE FROM nvt_selectors"
" WHERE name = '%s' AND family_or_nvt = '%s');",
Expand Down Expand Up @@ -3087,8 +3091,10 @@ delete_config (const char *config_id, int ultimate)
permissions_set_orphans ("config", config, LOCATION_TRASH);
tags_remove_resource ("config", config, LOCATION_TRASH);

sql ("DELETE FROM nvt_selectors WHERE name ="
" (SELECT nvt_selector FROM configs_trash WHERE id = %llu);",
sql ("DELETE FROM nvt_selectors"
" WHERE name != '" MANAGE_NVT_SELECTOR_UUID_ALL "'"
" AND name = (SELECT nvt_selector FROM configs_trash"
" WHERE id = %llu);",
config);
sql ("DELETE FROM config_preferences_trash WHERE config = %llu;",
config);
Expand All @@ -3109,8 +3115,10 @@ delete_config (const char *config_id, int ultimate)
return 1;
}

sql ("DELETE FROM nvt_selectors WHERE name ="
" (SELECT nvt_selector FROM configs_trash WHERE id = %llu);",
sql ("DELETE FROM nvt_selectors"
" WHERE name != '" MANAGE_NVT_SELECTOR_UUID_ALL "'"
" AND name = (SELECT nvt_selector FROM configs_trash"
" WHERE id = %llu);",
config);

permissions_set_orphans ("config", config, LOCATION_TABLE);
Expand Down Expand Up @@ -4172,12 +4180,13 @@ manage_set_config_nvts (const gchar *config_id, const char* family,

/* Clear any NVT selectors for this family from the config. */

sql ("DELETE FROM nvt_selectors"
" WHERE name = '%s'"
" AND type = " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT)
" AND family = '%s';",
quoted_selector,
quoted_family);
if (strcmp (quoted_selector, MANAGE_NVT_SELECTOR_UUID_ALL))
sql ("DELETE FROM nvt_selectors"
" WHERE name = '%s'"
" AND type = " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT)
" AND family = '%s';",
quoted_selector,
quoted_family);

/* Exclude all no's. */

Expand Down Expand Up @@ -4214,12 +4223,13 @@ manage_set_config_nvts (const gchar *config_id, const char* family,

/* Clear any NVT selectors for this family from the config. */

sql ("DELETE FROM nvt_selectors"
" WHERE name = '%s'"
" AND type = " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT)
" AND family = '%s';",
quoted_selector,
quoted_family);
if (strcmp (quoted_selector, MANAGE_NVT_SELECTOR_UUID_ALL))
sql ("DELETE FROM nvt_selectors"
" WHERE name = '%s'"
" AND type = " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT)
" AND family = '%s';",
quoted_selector,
quoted_family);

/* Include all yes's. */

Expand Down Expand Up @@ -4776,8 +4786,9 @@ update_config (config_t config, const gchar *type, const gchar *name,
}

sql ("DELETE FROM nvt_selectors"
" WHERE name = (SELECT nvt_selector FROM configs"
" WHERE id = %llu);",
" WHERE name != '" MANAGE_NVT_SELECTOR_UUID_ALL "'"
" AND name = (SELECT nvt_selector FROM configs"
" WHERE id = %llu);",
config);

sql ("UPDATE configs SET nvt_selector = '%s' WHERE id = %llu;",
Expand Down