Skip to content

Commit

Permalink
dont use double pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnicola committed Oct 22, 2024
1 parent 9343d96 commit 0097281
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 53 deletions.
66 changes: 34 additions & 32 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -7168,7 +7168,7 @@ nvts_feed_info_internal_from_openvasd (const gchar *scanner_uuid,
if (!connector)
return 1;

resp = openvasd_get_health_ready (&connector);
resp = openvasd_get_health_ready (connector);
if (resp->code == -1)
{
g_warning ("%s: failed to connect to %s:%d", __func__,
Expand All @@ -7184,7 +7184,7 @@ nvts_feed_info_internal_from_openvasd (const gchar *scanner_uuid,
}

openvasd_response_cleanup (resp);
openvasd_connector_free (&connector);
openvasd_connector_free (connector);
return ret;
}

Expand Down Expand Up @@ -8039,17 +8039,17 @@ stop_openvasd_task (task_t task)
current_scanner_task = task;
global_current_report = task_running_report (task);
set_task_run_status (task, TASK_STATUS_STOP_REQUESTED);
response = openvasd_stop_scan (&connector);
response = openvasd_stop_scan (connector);
if (response->code < 0)
{
ret = -1;
g_free (scan_id);
goto end_stop_openvasd;
}
response = openvasd_delete_scan (&connector);
response = openvasd_delete_scan (connector);
g_free (scan_id);
end_stop_openvasd:
openvasd_connector_free(&connector);
openvasd_connector_free (connector);
set_task_end_time_epoch (task, time (NULL));
set_task_run_status (task, TASK_STATUS_STOPPED);
if (scan_report)
Expand Down Expand Up @@ -8094,20 +8094,20 @@ prepare_openvasd_scan_for_resume (task_t task, const char *scan_id,
*error = g_strdup ("Could not connect to Openvasd Scanner");
return -1;
}
status = openvasd_parsed_scan_status (&connection);
status = openvasd_parsed_scan_status (connection);

if (status->status == OPENVASD_SCAN_STATUS_ERROR)
{
if (status->response_code == 404)
{
g_debug ("%s: Scan %s not found", __func__, scan_id);
openvasd_connector_free (&connection);
openvasd_connector_free (connection);
trim_partial_report (global_current_report);
return 1;
}
g_warning ("%s: Error getting status of scan %s: %ld",
__func__, scan_id, status->response_code);
openvasd_connector_free (&connection);
openvasd_connector_free (connection);
return -1;
}
else if (status->status == OPENVASD_SCAN_STATUS_RUNNING
Expand All @@ -8117,25 +8117,25 @@ prepare_openvasd_scan_for_resume (task_t task, const char *scan_id,
/* It would be possible to simply continue getting the results
* from the scanner, but gvmd may have crashed while receiving
* or storing the results, so some may be missing. */
response = openvasd_stop_scan (&connection);
response = openvasd_stop_scan (connection);
if (response->code != 204)
{
*error = g_strdup_printf ("Failed to stop old report: %ld",
response->code);
openvasd_connector_free (&connection);
openvasd_connector_free (connection);
openvasd_response_cleanup(response);
return -1;
}
response = openvasd_delete_scan (&connection);
response = openvasd_delete_scan (connection);
if (response->code != 204)
{
*error = g_strdup_printf ("Failed to delete old report: %ld",
response->code);
openvasd_response_cleanup(response);
openvasd_connector_free (&connection);
openvasd_connector_free (connection);
return -1;
}
openvasd_connector_free (&connection);
openvasd_connector_free (connection);
trim_partial_report (global_current_report);
return 1;
}
Expand All @@ -8144,16 +8144,16 @@ prepare_openvasd_scan_for_resume (task_t task, const char *scan_id,
/* OSP can't stop an already finished/interrupted scan,
* but it must be delete to be resumed. */
g_debug ("%s: Scan %s finished", __func__, scan_id);
response = openvasd_delete_scan (&connection);
response = openvasd_delete_scan (connection);
if (response->code != 204)
{
*error = g_strdup_printf ("Failed to delete old report: %ld",
response->code);
openvasd_response_cleanup(response);
openvasd_connector_free (&connection);
openvasd_connector_free (connection);
return -1;
}
openvasd_connector_free (&connection);
openvasd_connector_free (connection);
trim_partial_report (global_current_report);
return 1;
}
Expand All @@ -8162,23 +8162,23 @@ prepare_openvasd_scan_for_resume (task_t task, const char *scan_id,
{
g_debug ("%s: Scan %s stopped or interrupted",
__func__, scan_id);
response = openvasd_delete_scan (&connection);
response = openvasd_delete_scan (connection);
if (response->code != 204)
{
*error = g_strdup_printf ("Failed to delete old report: %ld",
response->code);
openvasd_response_cleanup(response);
openvasd_connector_free (&connection);
openvasd_connector_free (connection);
return -1;
}
openvasd_connector_free (&connection);
openvasd_connector_free (connection);
trim_partial_report (global_current_report);
return 1;
}

g_warning ("%s: Unexpected scanner status %d", __func__, status->status);
*error = g_strdup_printf ("Unexpected scanner status %d", status->status);
openvasd_connector_free (&connection);
openvasd_connector_free (connection);

return -1;
}
Expand Down Expand Up @@ -8487,7 +8487,7 @@ launch_openvasd_openvas_task (task_t task, target_t target, const char *scan_id,
scan_config =
openvasd_build_scan_config_json(openvasd_target, scanner_options, vts);

response = openvasd_start_scan (&connection, scan_config);
response = openvasd_start_scan (connection, scan_config);
openvasd_target_free(openvasd_target);
// Credentials are freed with target
g_slist_free_full (vts, (GDestroyNotify) openvasd_vt_single_free);
Expand Down Expand Up @@ -8539,7 +8539,7 @@ handle_openvasd_scan (task_t task, report_t report, const char *scan_id)
break;
}

progress = openvasd_get_scan_progress (&connector);
progress = openvasd_get_scan_progress (connector);

if (progress < 0 || progress > 100)
{
Expand All @@ -8562,14 +8562,14 @@ handle_openvasd_scan (task_t task, report_t report, const char *scan_id)
"Erroneous scan progress value", "", "",
QOD_DEFAULT, NULL, NULL);
report_add_result (report, result);
response = openvasd_delete_scan(&connector);
response = openvasd_delete_scan(connector);
rc = -1;
break;
}
else
{
/* Get the full openvasd report. */
progress = openvasd_get_scan_progress (&connector);
progress = openvasd_get_scan_progress (connector);

if (progress < 0 || progress > 100)
{
Expand Down Expand Up @@ -8606,12 +8606,12 @@ handle_openvasd_scan (task_t task, report_t report, const char *scan_id)

set_report_slave_progress (report, progress);

openvasd_parsed_results (&connector, result_start,
openvasd_parsed_results (connector, result_start,
result_end, &results);
result_start += g_slist_length (results);

gvm_sleep(1);
openvasd_scan_status = openvasd_parsed_scan_status (&connector);
openvasd_scan_status = openvasd_parsed_scan_status (connector);
start_time = openvasd_scan_status->start_time;
end_time = openvasd_scan_status->end_time;
current_status = openvasd_scan_status->status;
Expand All @@ -8620,8 +8620,10 @@ handle_openvasd_scan (task_t task, report_t report, const char *scan_id)

if (g_slist_length(results))
{
parse_openvasd_report (task, report, results,
start_time, end_time);
parse_openvasd_report (task, report, results, start_time,
end_time);
g_slist_free_full (results,
(GDestroyNotify) openvasd_result_free);
}
if (current_status == OPENVASD_SCAN_STATUS_STORED)
{
Expand All @@ -8641,7 +8643,7 @@ handle_openvasd_scan (task_t task, report_t report, const char *scan_id)
"Task interrupted unexpectedly", "", "",
QOD_DEFAULT, NULL, NULL);
report_add_result (report, result);
response = openvasd_delete_scan (&connector);
response = openvasd_delete_scan (connector);
rc = -3;
break;
}
Expand All @@ -8663,14 +8665,14 @@ handle_openvasd_scan (task_t task, report_t report, const char *scan_id)
"Scan stopped unexpectedly by the server", "", "",
QOD_DEFAULT, NULL, NULL);
report_add_result (report, result);
response = openvasd_delete_scan (&connector);
response = openvasd_delete_scan (connector);
rc = -1;
break;
}
else if (progress == 100
&& current_status == OPENVASD_SCAN_STATUS_SUCCEEDED)
{
response = openvasd_delete_scan (&connector);
response = openvasd_delete_scan (connector);
rc = response->code;
break;
}
Expand All @@ -8689,7 +8691,7 @@ handle_openvasd_scan (task_t task, report_t report, const char *scan_id)
gvm_sleep (5);
}
openvasd_response_cleanup (response);
openvasd_connector_free(&connector);
openvasd_connector_free(connector);
return rc;
}

Expand Down
26 changes: 13 additions & 13 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -43413,19 +43413,19 @@ openvasd_get_details_from_iterator (iterator_t *iterator, char **desc,

connection = openvasd_connector_new();

openvasd_connector_builder (&connection, OPENVASD_SERVER, server);
openvasd_connector_builder (&connection, OPENVASD_CA_CERT, ca_pub);
openvasd_connector_builder (&connection, OPENVASD_KEY, key_priv);
openvasd_connector_builder (&connection, OPENVASD_CERT, key_pub);
openvasd_connector_builder (&connection, OPENVASD_PORT, (void *) &port);
openvasd_connector_builder (connection, OPENVASD_SERVER, server);
openvasd_connector_builder (connection, OPENVASD_CA_CERT, ca_pub);
openvasd_connector_builder (connection, OPENVASD_KEY, key_priv);
openvasd_connector_builder (connection, OPENVASD_CERT, key_pub);
openvasd_connector_builder (connection, OPENVASD_PORT, (void *) &port);

if (!connection)
return 1;

*desc = g_strdup_printf("Openvasd Sensor on htt://%s:%d", server, port);
if (openvasd_parsed_scans_preferences (&connection, params) < 0)
if (openvasd_parsed_scans_preferences (connection, params) < 0)
return 1;
openvasd_connector_free (&connection);
openvasd_connector_free (connection);
return 0;
}

Expand Down Expand Up @@ -60081,14 +60081,14 @@ openvasd_scanner_connect (scanner_t scanner, const char *scan_id)

connection = openvasd_connector_new();

openvasd_connector_builder (&connection, OPENVASD_SERVER, server);
openvasd_connector_builder (&connection, OPENVASD_CA_CERT, ca_pub);
openvasd_connector_builder (&connection, OPENVASD_KEY, key_priv);
openvasd_connector_builder (&connection, OPENVASD_CERT, key_pub);
openvasd_connector_builder (&connection, OPENVASD_PORT, (void *) &port);
openvasd_connector_builder (connection, OPENVASD_SERVER, server);
openvasd_connector_builder (connection, OPENVASD_CA_CERT, ca_pub);
openvasd_connector_builder (connection, OPENVASD_KEY, key_priv);
openvasd_connector_builder (connection, OPENVASD_CERT, key_pub);
openvasd_connector_builder (connection, OPENVASD_PORT, (void *) &port);

if (scan_id && scan_id[0] != '\0')
openvasd_connector_builder (&connection, OPENVASD_SCAN_ID, scan_id);
openvasd_connector_builder (connection, OPENVASD_SCAN_ID, scan_id);

g_free (server);
g_free (ca_pub);
Expand Down
16 changes: 8 additions & 8 deletions src/manage_sql_nvts.c
Original file line number Diff line number Diff line change
Expand Up @@ -2252,7 +2252,7 @@ static int move_buffer_data(struct FILESTREAM *filestream){
* @return 0 success, 1 VT integrity check failed, -1 error
*/
static int
update_nvts_from_json_vts (openvasd_connector_t *connector,
update_nvts_from_json_vts (openvasd_connector_t connector,
const gchar *scanner_feed_version,
int rebuild)
{
Expand Down Expand Up @@ -2831,28 +2831,28 @@ update_nvt_cache_openvasd (gchar* openvasd_uuid, gchar *db_feed_version,
return -1;
}

ret = update_nvts_from_json_vts (&connector, scanner_feed_version,
ret = update_nvts_from_json_vts (connector, scanner_feed_version,
rebuild);
if (ret)
{
openvasd_connector_free (&connector);
openvasd_connector_free (connector);
return ret;
}

/* Update scanner preferences */
// TODO: update scanner preferences

resp = openvasd_get_vts (&connector);
resp = openvasd_get_vts (connector);
if (resp->code != 200)
{
g_warning ("%s: failed to get scanner preferences", __func__);
return -1;
}
GSList *scan_prefs = NULL;

openvasd_parsed_scans_preferences (&connector, &scan_prefs);
openvasd_parsed_scans_preferences (connector, &scan_prefs);
g_debug ("There %d scan preferences", g_slist_length (scan_prefs));
openvasd_connector_free (&connector);
openvasd_connector_free (connector);

GString *prefs_sql;
GSList *point;
Expand Down Expand Up @@ -2956,7 +2956,7 @@ nvts_feed_info_internal_from_openvasd (const gchar *scanner_uuid,
if (!connector)
return 1;

resp = openvasd_get_health_ready (&connector);
resp = openvasd_get_health_ready (connector);
if (resp->code == -1)
{
g_warning ("%s: failed to connect to %s:%d", __func__,
Expand All @@ -2972,7 +2972,7 @@ nvts_feed_info_internal_from_openvasd (const gchar *scanner_uuid,
}

openvasd_response_cleanup (resp);
openvasd_connector_free (&connector);
openvasd_connector_free (connector);
return ret;
}

Expand Down

0 comments on commit 0097281

Please sign in to comment.