Skip to content
Open
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
63 changes: 59 additions & 4 deletions src/gsad_gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2331,9 +2331,27 @@ create_agent_group_task_gmp (gvm_connection_t *connection,
"<comment>%s</comment>"
"<alterable>%i</alterable>"
"<usage_type>scan</usage_type>"
"<preferences>"
"<preference>"
"<scanner_name>in_assets</scanner_name>"
"<value>%s</value>"
"</preference>"
"<preference>"
"<scanner_name>"
"assets_apply_overrides"
"</scanner_name>"
"<value>%s</value>"
"</preference>"
"<preference>"
"<scanner_name>assets_min_qod</scanner_name>"
"<value>%s</value>"
"</preference>"
"</preferences>"
"</create_task>",
schedule_periods, schedule_element, alert_element->str, agent_group_id,
name_escaped, comment_escaped, alterable ? strcmp (alterable, "0") : 0);
name_escaped, comment_escaped, alterable ? strcmp (alterable, "0") : 0,
strcmp (in_assets, "0") ? "yes" : "no",
strcmp (apply_overrides, "0") ? "yes" : "no", min_qod);

g_free (name_escaped);
g_free (comment_escaped);
Expand Down Expand Up @@ -3319,8 +3337,8 @@ save_agent_group_task_gmp (gvm_connection_t *connection,
gsad_command_response_data_t *response_data)
{
gchar *html = NULL, *format = NULL;
const char *comment, *name, *schedule_id, *schedule_periods;
const char *task_id, *agent_group_id;
const char *comment, *name, *schedule_id, *schedule_periods, *in_assets;
const char *min_qod, *task_id, *agent_group_id, *apply_overrides;
const char *alterable;
int ret;
params_t *alerts;
Expand All @@ -3329,10 +3347,15 @@ save_agent_group_task_gmp (gvm_connection_t *connection,

/* Read params */
alterable = params_value (params, "alterable");
apply_overrides = params_value (params, "apply_overrides");
in_assets = params_value (params, "in_assets");
comment = params_value (params, "comment");
name = params_value (params, "name");
schedule_id = params_value (params, "schedule_id");
schedule_periods = params_value (params, "schedule_periods");
min_qod = params_value (params, "min_qod");
if (!params_given (params, "min_qod") || !params_valid (params, "min_qod"))
min_qod = "";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct. In this case CHECK_VARIABLE_INVALID (min_qod, "Save Agent Group Task"); below will not work.

task_id = params_value (params, "task_id");
agent_group_id = params_value (params, "agent_group_id");

Expand All @@ -3350,6 +3373,23 @@ save_agent_group_task_gmp (gvm_connection_t *connection,
CHECK_VARIABLE_INVALID (schedule_id, "Save Agent Group Task");
CHECK_VARIABLE_INVALID (task_id, "Save Agent Group Task");
CHECK_VARIABLE_INVALID (agent_group_id, "Save Agent Group Task");
CHECK_VARIABLE_INVALID (in_assets, "Save Task");

if (!strcmp (in_assets, "1"))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love if we can use str_equal from gsad_utils here. strcmp is very confusing to read if C is not your daily business.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I don't understand the desired logic here. if in_assets is set apply_overrides and min_qod are validated? what's the connection here? I thought all three values are independent of each other.

IMHO also it is best to not add to specific business logic into gsad. Business logic belongs to gvmd. gsad should only forward things it gets from GSA with validation and cleanup as little as possible.

{
CHECK_VARIABLE_INVALID (apply_overrides, "Save Agent Group Task");
CHECK_VARIABLE_INVALID (min_qod, "Save Agent Group Task");
}
else
{
if (!params_given (params, "apply_overrides")
|| !params_valid (params, "apply_overrides"))
apply_overrides = "";

if (!params_given (params, "min_qod")
|| !params_valid (params, "min_qod"))
min_qod = "";
}

/* Build alerts list */
alert_element = g_string_new ("");
Expand Down Expand Up @@ -3384,6 +3424,20 @@ save_agent_group_task_gmp (gvm_connection_t *connection,
"<agent_group id=\"%%s\"/>"
"<schedule id=\"%%s\"/>"
"<schedule_periods>%%s</schedule_periods>"
"<preferences>"
"<preference>"
"<scanner_name>in_assets</scanner_name>"
"<value>%%s</value>"
"</preference>"
"<preference>"
"<scanner_name>assets_apply_overrides</scanner_name>"
"<value>%%s</value>"
"</preference>"
"<preference>"
"<scanner_name>assets_min_qod</scanner_name>"
"<value>%%s</value>"
"</preference>"
"</preferences>"
"%s%i%s" /* optional alterable wrapper with numeric value */
"</modify_task>",
alert_element->str, alterable ? "<alterable>" : "",
Expand All @@ -3392,7 +3446,8 @@ save_agent_group_task_gmp (gvm_connection_t *connection,
/* Send */
ret = gmpf (connection, credentials, NULL, &entity, response_data, format,
task_id, name, comment, agent_group_id, schedule_id,
schedule_periods);
schedule_periods, strcmp (in_assets, "0") ? "yes" : "no",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As i wrote strcmp is very confusing to read.

Suggested change
schedule_periods, strcmp (in_assets, "0") ? "yes" : "no",
schedule_periods, str_equal(in_assets, "1") ? "yes" : "no",

strcmp (apply_overrides, "0") ? "yes" : "no", min_qod);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
strcmp (apply_overrides, "0") ? "yes" : "no", min_qod);
str_equal (apply_overrides, "1") ? "yes" : "no", min_qod);


g_free (format);
g_string_free (alert_element, TRUE);
Expand Down
Loading