diff --git a/openvasd/openvasd.c b/openvasd/openvasd.c index d7d5a5e8..489293d7 100644 --- a/openvasd/openvasd.c +++ b/openvasd/openvasd.c @@ -36,14 +36,14 @@ */ struct openvasd_connector { - char *ca_cert; /**< Path to the directory holding the CA certificate. */ - char *cert; /**< Client certificate. */ - char *key; /**< Client key. */ - char *apikey; /**< API key for authentication. */ - char *server; /**< original openvasd server URL. */ - char *host; /**< server hostname. */ - char *scan_id; /**< Scan ID. */ - int port; /**< server port. */ + gchar *ca_cert; /**< Path to the directory holding the CA certificate. */ + gchar *cert; /**< Client certificate. */ + gchar *key; /**< Client key. */ + gchar *apikey; /**< API key for authentication. */ + gchar *server; /**< original openvasd server URL. */ + gchar *host; /**< server hostname. */ + gchar *scan_id; /**< Scan ID. */ + int port; /**< server port. */ }; /** @@ -51,12 +51,12 @@ struct openvasd_connector */ struct openvasd_param { - char *id; /**< Parameter id. */ - char *name; /**< Parameter name. */ - char *defval; /**< Default value. */ - char *description; /**< Description. */ - char *type; /**< Parameter type. */ - int mandatory; /**< If mandatory. */ + gchar *id; /**< Parameter id. */ + gchar *name; /**< Parameter name. */ + gchar *defval; /**< Default value. */ + gchar *description; /**< Description. */ + gchar *type; /**< Parameter type. */ + int mandatory; /**< If mandatory. */ }; /** @@ -64,9 +64,9 @@ struct openvasd_param */ struct openvasd_credential { - char *type; /**< Credential type */ - char *service; /**< Service the credential is for */ - char *port; /**< Port the credential is for */ + gchar *type; /**< Credential type */ + gchar *service; /**< Service the credential is for */ + gchar *port; /**< Port the credential is for */ GHashTable *auth_data; /**< Authentication data (username, password, etc.)*/ }; @@ -75,12 +75,12 @@ struct openvasd_credential */ struct openvasd_target { - char *scan_id; /** Scan ID */ + gchar *scan_id; /** Scan ID */ GSList *credentials; /** Credentials to use in the scan */ - char *exclude_hosts; /** String defining one or many hosts to exclude */ - char *hosts; /** String defining one or many hosts to scan */ - char *ports; /** String defining the ports to scan */ - char *finished_hosts; /** String defining hosts to exclude as finished */ + gchar *exclude_hosts; /** String defining one or many hosts to exclude */ + gchar *hosts; /** String defining one or many hosts to scan */ + gchar *ports; /** String defining the ports to scan */ + gchar *finished_hosts; /** String defining hosts to exclude as finished */ gboolean icmp; /** Alive test method icmp */ gboolean tcp_syn; /** Alive test method tcp_syn */ gboolean tcp_ack; /** Alive test method tcp_ack */ @@ -95,7 +95,7 @@ struct openvasd_target */ struct openvasd_vt_single { - char *vt_id; + gchar *vt_id; GHashTable *vt_values; }; @@ -112,7 +112,7 @@ enum openvas_request_method typedef enum openvas_request_method openvasd_req_method_t; -/** @brief Initialize a notus info struct and stores the server URL +/** @brief Initialize a openvasd info struct and stores the server URL * * @param server Original server to store and to get the info from * @@ -123,14 +123,11 @@ openvasd_connector_new (void) { openvasd_connector_t connector; connector = g_malloc0 (sizeof (struct openvasd_connector)); - if (!connector) - return NULL; - return connector; } /** @brief Build a openvasd connector - * @Description Recieve option name and value to build the openvasd connector + * Receive option name and value to build the openvasd connector * * @param[in/out] conn struct holding the openvasd connector information * @param[in] opt option to set @@ -175,7 +172,7 @@ openvasd_connector_builder (openvasd_connector_t *conn, openvasd_conn_opt_t opt, (*conn)->host = g_strdup ((char *) val); break; case OPENVASD_SCAN_ID: - (*conn)->scan_id = g_strdup ((const char *) val); + (*conn)->scan_id = g_strdup ((const gchar *) val); break; case OPENVASD_PORT: default: @@ -187,7 +184,7 @@ openvasd_connector_builder (openvasd_connector_t *conn, openvasd_conn_opt_t opt, } /** @brief Build a openvasd connector - * @Description Recieve option name and value to build the openvasd connector + * Receive option name and value to build the openvasd connector * * @param[in/out] conn struct holding the openvasd connector information * @param[in] opt option to set @@ -204,6 +201,7 @@ openvasd_connector_free (openvasd_connector_t *conn) g_free ((*conn)->ca_cert); g_free ((*conn)->cert); g_free ((*conn)->key); + g_free ((*conn)->apikey); g_free ((*conn)->server); g_free ((*conn)->host); g_free ((*conn)->scan_id); @@ -239,12 +237,6 @@ init_openvasd_stringstream (openvasd_stringstream *s) { s->len = 0; s->ptr = g_malloc0 (s->len + 1); - if (s->ptr == NULL) - { - g_warning ("%s: Error allocating memory for response", __func__); - return; - } - s->ptr[0] = '\0'; } /** @brief Reinitialize the string struct to hold the response @@ -260,7 +252,7 @@ reset_openvasd_stringstream (openvasd_stringstream *s) /** @brief Call back function to stored the response. * - * @description The function signature is the necessary to work with + * The function signature is the necessary to work with * libcurl. It stores the response in s. It reallocate memory if necessary. */ static size_t @@ -268,13 +260,8 @@ response_callback_fn (void *ptr, size_t size, size_t nmemb, void *struct_string) { openvasd_stringstream *s = struct_string; size_t new_len = s->len + size * nmemb; - char *ptr_aux = g_realloc (s->ptr, new_len + 1); + gchar *ptr_aux = g_realloc (s->ptr, new_len + 1); s->ptr = ptr_aux; - if (s->ptr == NULL) - { - g_warning ("%s: Error allocating memory for response", __func__); - return 0; // no memory left - } memcpy (s->ptr + s->len, ptr, size * nmemb); s->ptr[new_len] = '\0'; s->len = new_len; @@ -297,8 +284,8 @@ response_callback_fn (void *ptr, size_t size, size_t nmemb, void *struct_string) * @return a CURL handler, or NULL on error. */ static CURL * -handler (openvasd_connector_t *conn, openvasd_req_method_t method, char *path, - char *data, openvasd_stringstream *resp, char **err) +handler (openvasd_connector_t *conn, openvasd_req_method_t method, gchar *path, + gchar *data, openvasd_stringstream *resp, gchar **err) { CURL *curl; GString *url = NULL; @@ -334,8 +321,9 @@ handler (openvasd_connector_t *conn, openvasd_req_method_t method, char *path, // Set URL g_debug ("%s: URL: %s", __func__, url->str); - if (curl_easy_setopt (curl, CURLOPT_URL, g_strdup (url->str)) != CURLE_OK) + if (curl_easy_setopt (curl, CURLOPT_URL, url->str) != CURLE_OK) { + g_string_free (url, TRUE); g_warning ("%s: Not possible to set the URL", __func__); curl_easy_cleanup (curl); *err = g_strdup ("{\"error\": \"Not possible to set URL\"}"); @@ -408,7 +396,7 @@ handler (openvasd_connector_t *conn, openvasd_req_method_t method, char *path, { xapikey = g_string_new ("X-API-KEY: "); g_string_append (xapikey, (*conn)->apikey); - customheader = curl_slist_append (customheader, g_strdup (xapikey->str)); + customheader = curl_slist_append (customheader, xapikey->str); g_string_free (xapikey, TRUE); } @@ -460,7 +448,7 @@ handler (openvasd_connector_t *conn, openvasd_req_method_t method, char *path, * caller with openvasd_response_free() */ static openvasd_resp_t -openvasd_send_request (CURL *curl, const char *header_name, +openvasd_send_request (CURL *curl, const gchar *header_name, openvasd_resp_t response) { long http_code = RESP_CODE_ERR; @@ -470,7 +458,6 @@ openvasd_send_request (CURL *curl, const char *header_name, { g_warning ("%s: Error sending request: %d", __func__, ret); curl_easy_cleanup (curl); - curl = NULL; response->code = http_code; response->body = g_strdup ("{\"error\": \"Error sending request\"}"); return response; @@ -485,7 +472,6 @@ openvasd_send_request (CURL *curl, const char *header_name, response->header = g_strdup (hname->value); } curl_easy_cleanup (curl); - curl = NULL; response->code = http_code; return response; @@ -501,14 +487,12 @@ openvasd_send_request (CURL *curl, const char *header_name, openvasd_resp_t openvasd_get_version (openvasd_connector_t *conn) { - char *err = NULL; + gchar *err = NULL; CURL *hnd = NULL; openvasd_resp_t response = NULL; openvasd_stringstream resp; response = g_malloc0 (sizeof (struct openvasd_response)); - if (response == NULL) - return NULL; init_openvasd_stringstream (&resp); if ((hnd = handler (conn, HEAD, "/", NULL, &resp, &err)) == NULL) @@ -573,12 +557,10 @@ openvasd_get_vts_stream_init (openvasd_connector_t *conn, { GString *path; openvasd_resp_t response = NULL; - char *err = NULL; + gchar *err = NULL; CURL *hnd = NULL; CURLM *h = NULL; response = g_malloc0 (sizeof (struct openvasd_response)); - if (response == NULL) - return NULL; path = g_string_new ("/vts?information=1"); if ((hnd = handler (conn, GET, path->str, NULL, resp, &err)) == NULL) @@ -646,13 +628,11 @@ openvasd_get_vts (openvasd_connector_t *conn) { GString *path; openvasd_resp_t response = NULL; - char *err = NULL; + gchar *err = NULL; CURL *hnd = NULL; openvasd_stringstream resp; response = g_malloc0 (sizeof (struct openvasd_response)); - if (response == NULL) - return NULL; init_openvasd_stringstream (&resp); path = g_string_new ("/vts?information=1"); @@ -684,18 +664,16 @@ openvasd_get_vts (openvasd_connector_t *conn) * body. NULL on error. */ openvasd_resp_t -openvasd_start_scan (openvasd_connector_t *conn, char *data) +openvasd_start_scan (openvasd_connector_t *conn, gchar *data) { openvasd_resp_t response = NULL; cJSON *parser = NULL; GString *path; - char *err = NULL; + gchar *err = NULL; CURL *hnd = NULL; openvasd_stringstream resp; response = g_malloc0 (sizeof (struct openvasd_response)); - if (response == NULL) - return NULL; init_openvasd_stringstream (&resp); if ((hnd = handler (conn, POST, "/scans", data, &resp, &err)) == NULL) @@ -707,9 +685,7 @@ openvasd_start_scan (openvasd_connector_t *conn, char *data) } openvasd_send_request (hnd, NULL, response); - if (response != NULL && response->code != RESP_CODE_ERR) - response->body = g_strdup (resp.ptr); - else if (response == NULL || response->code == RESP_CODE_ERR) + if (response == NULL || response->code == RESP_CODE_ERR) { g_free (resp.ptr); response->code = RESP_CODE_ERR; @@ -724,7 +700,7 @@ openvasd_start_scan (openvasd_connector_t *conn, char *data) parser = cJSON_Parse (response->body); if (!parser) { - const char *error_ptr = cJSON_GetErrorPtr (); + const gchar *error_ptr = cJSON_GetErrorPtr (); if (error_ptr != NULL) { response->body = g_strdup_printf ("{\"error\": \"%s\"}", error_ptr); @@ -775,9 +751,7 @@ openvasd_start_scan (openvasd_connector_t *conn, char *data) g_string_free (path, TRUE); openvasd_send_request (hnd, NULL, response); - if (response != NULL && response->code != RESP_CODE_ERR) - response->body = g_strdup (resp.ptr); - else if (response == NULL || response->code == RESP_CODE_ERR) + if (response == NULL || response->code == RESP_CODE_ERR) { g_free (resp.ptr); response->code = RESP_CODE_ERR; @@ -798,13 +772,11 @@ openvasd_stop_scan (openvasd_connector_t *conn) { openvasd_resp_t response = NULL; GString *path; - char *err = NULL; + gchar *err = NULL; CURL *hnd = NULL; openvasd_stringstream resp; response = g_malloc0 (sizeof (struct openvasd_response)); - if (response == NULL) - return NULL; // Stop the scan path = g_string_new ("/scans"); @@ -848,13 +820,11 @@ openvasd_get_scan_results (openvasd_connector_t *conn, long first, long last) { openvasd_resp_t response = NULL; GString *path = NULL; - char *err = NULL; + gchar *err = NULL; CURL *hnd = NULL; openvasd_stringstream resp; response = g_malloc0 (sizeof (struct openvasd_response)); - if (response == NULL) - return NULL; path = g_string_new ("/scans"); if ((*conn)->scan_id != NULL && (*conn)->scan_id[0] != '\0') @@ -903,15 +873,13 @@ openvasd_get_scan_results (openvasd_connector_t *conn, long first, long last) } openvasd_result_t -openvasd_result_new (unsigned long id, char *type, char *ip_address, - char *hostname, char *oid, int port, char *protocol, - char *message, char *detail_name, char *detail_value, - char *detail_source_type, char *detail_source_name, - char *detail_source_description) +openvasd_result_new (unsigned long id, gchar *type, gchar *ip_address, + gchar *hostname, gchar *oid, int port, gchar *protocol, + gchar *message, gchar *detail_name, gchar *detail_value, + gchar *detail_source_type, gchar *detail_source_name, + gchar *detail_source_description) { openvasd_result_t result = g_malloc0 (sizeof (struct openvasd_result)); - if (!result) - return NULL; result->id = id; result->type = g_strdup (type); @@ -1011,22 +979,22 @@ openvasd_parsed_results (openvasd_connector_t *conn, unsigned long first, { cJSON *parser = NULL; cJSON *result_obj = NULL; - const char *err = NULL; + const gchar *err = NULL; openvasd_resp_t resp = NULL; openvasd_result_t result = NULL; unsigned long id = 0; - char *type = NULL; - char *ip_address = NULL; - char *hostname = NULL; - char *oid = NULL; + gchar *type = NULL; + gchar *ip_address = NULL; + gchar *hostname = NULL; + gchar *oid = NULL; int port = 0; - char *protocol = NULL; - char *message = NULL; - char *detail_name = NULL; - char *detail_value = NULL; - char *detail_source_type = NULL; - char *detail_source_name = NULL; - char *detail_source_description = NULL; + gchar *protocol = NULL; + gchar *message = NULL; + gchar *detail_name = NULL; + gchar *detail_value = NULL; + gchar *detail_source_type = NULL; + gchar *detail_source_name = NULL; + gchar *detail_source_description = NULL; int ret = -1; resp = openvasd_get_scan_results (conn, first, last); @@ -1137,13 +1105,11 @@ openvasd_get_scan_status (openvasd_connector_t *conn) { openvasd_resp_t response = NULL; GString *path = NULL; - char *err = NULL; + gchar *err = NULL; CURL *hnd = NULL; openvasd_stringstream resp; response = g_malloc0 (sizeof (struct openvasd_response)); - if (response == NULL) - return NULL; path = g_string_new ("/scans"); if ((*conn)->scan_id != NULL && (*conn)->scan_id[0] != '\0') @@ -1191,7 +1157,7 @@ openvasd_get_scan_status (openvasd_connector_t *conn) * @return 0 on success, -1 on error. */ static int -get_member_value_or_fail (cJSON *reader, const char *member) +get_member_value_or_fail (cJSON *reader, const gchar *member) { cJSON *item = NULL; if ((item = cJSON_GetObjectItem (reader, member)) == NULL @@ -1207,7 +1173,7 @@ openvasd_get_scan_progress_ext (openvasd_connector_t *conn, { cJSON *parser; cJSON *reader = NULL; - const char *err = NULL; + const gchar *err = NULL; int all = 0, excluded = 0, dead = 0, alive = 0, queued = 0, finished = 0; int running_hosts_progress_sum = 0; @@ -1295,7 +1261,7 @@ openvasd_get_scan_progress (openvasd_connector_t *conn) } static openvasd_status_t -get_status_code_from_openvas (const char *status_val) +get_status_code_from_openvas (const gchar *status_val) { openvasd_status_t status_code = OPENVASD_SCAN_STATUS_ERROR; @@ -1328,7 +1294,7 @@ openvasd_parsed_scan_status (openvasd_connector_t *conn) cJSON *parser = NULL; cJSON *status = NULL; openvasd_resp_t resp = NULL; - char *status_val = NULL; + gchar *status_val = NULL; time_t start_time = 0, end_time = 0; int progress = -1; openvasd_status_t status_code = OPENVASD_SCAN_STATUS_ERROR; @@ -1382,13 +1348,11 @@ openvasd_delete_scan (openvasd_connector_t *conn) { openvasd_resp_t response = NULL; GString *path; - char *err = NULL; + gchar *err = NULL; CURL *hnd = NULL; openvasd_stringstream resp; response = g_malloc0 (sizeof (struct openvasd_response)); - if (response == NULL) - return NULL; // Stop the scan path = g_string_new ("/scans"); @@ -1435,13 +1399,11 @@ openvasd_resp_t openvasd_get_health_alive (openvasd_connector_t *conn) { openvasd_resp_t response = NULL; - char *err = NULL; + gchar *err = NULL; CURL *hnd = NULL; openvasd_stringstream resp; response = g_malloc0 (sizeof (struct openvasd_response)); - if (response == NULL) - return NULL; init_openvasd_stringstream (&resp); if ((hnd = handler (conn, GET, "/health/alive", NULL, &resp, &err)) == NULL) @@ -1470,13 +1432,11 @@ openvasd_resp_t openvasd_get_health_ready (openvasd_connector_t *conn) { openvasd_resp_t response = NULL; - char *err = NULL; + gchar *err = NULL; CURL *hnd = NULL; openvasd_stringstream resp; response = g_malloc0 (sizeof (struct openvasd_response)); - if (response == NULL) - return NULL; init_openvasd_stringstream (&resp); if ((hnd = handler (conn, GET, "/health/ready", NULL, &resp, &err)) == NULL) @@ -1505,13 +1465,11 @@ openvasd_resp_t openvasd_get_health_started (openvasd_connector_t *conn) { openvasd_resp_t response = NULL; - char *err = NULL; + gchar *err = NULL; CURL *hnd = NULL; openvasd_stringstream resp; response = g_malloc0 (sizeof (struct openvasd_response)); - if (response == NULL) - return NULL; init_openvasd_stringstream (&resp); if ((hnd = handler (conn, GET, "/health/started", NULL, &resp, &err)) == NULL) @@ -1540,13 +1498,11 @@ openvasd_resp_t openvasd_get_scan_preferences (openvasd_connector_t *conn) { openvasd_resp_t response = NULL; - char *err = NULL; + gchar *err = NULL; CURL *hnd = NULL; openvasd_stringstream resp; response = g_malloc0 (sizeof (struct openvasd_response)); - if (response == NULL) - return NULL; init_openvasd_stringstream (&resp); if ((hnd = handler (conn, GET, "/scans/preferences", NULL, &resp, &err)) @@ -1578,8 +1534,8 @@ openvasd_get_scan_preferences (openvasd_connector_t *conn) * @return New Openvasd parameter. */ static openvasd_param_t * -openvasd_param_new (char *id, char *name, char *defval, char *description, - char *type, int mandatory) +openvasd_param_new (char *id, gchar *name, gchar *defval, gchar *description, + gchar *type, int mandatory) { openvasd_param_t *param = g_malloc0 (sizeof (openvasd_param_t)); @@ -1715,8 +1671,8 @@ openvasd_parsed_scans_preferences (openvasd_connector_t *conn, GSList **params) cJSON_ArrayForEach (param_obj, parser) { - const char *id = NULL, *name = NULL, *desc = NULL; - char *defval = NULL, *param_type = NULL; + const gchar *id = NULL, *name = NULL, *desc = NULL; + gchar *defval = NULL, *param_type = NULL; openvasd_param_t *param = NULL; int val, mandatory = 0; char buf[6]; @@ -1813,7 +1769,7 @@ static void add_credential_to_scan_json (gpointer credentials, gpointer cred_array) { GHashTableIter auth_data_iter; - char *auth_data_name, *auth_data_value; + gchar *auth_data_name, *auth_data_value; cJSON *cred_obj = NULL; openvasd_credential_t *cred = credentials; @@ -1850,7 +1806,7 @@ static void add_vts_to_scan_json (gpointer single_vt, gpointer vts_array) { GHashTableIter vt_data_iter; - char *vt_param_id, *vt_param_value; + gchar *vt_param_id, *vt_param_value; openvasd_vt_single_t *vt = single_vt; @@ -1895,7 +1851,7 @@ openvasd_build_scan_config_json (openvasd_target_t *target, cJSON *hosts_array = NULL; cJSON *exclude_hosts_array = NULL; cJSON *finished_hosts_array = NULL; - char *json_str = NULL; + gchar *json_str = NULL; /* Build the message in json format to be published. */ scan_obj = cJSON_CreateObject (); @@ -1908,7 +1864,7 @@ openvasd_build_scan_config_json (openvasd_target_t *target, // hosts hosts_array = cJSON_CreateArray (); - char **hosts_list = g_strsplit (target->hosts, ",", 0); + gchar **hosts_list = g_strsplit (target->hosts, ",", 0); for (int i = 0; hosts_list[i] != NULL; i++) { cJSON *host_item = NULL; @@ -1922,7 +1878,7 @@ openvasd_build_scan_config_json (openvasd_target_t *target, if (target->exclude_hosts && target->exclude_hosts[0] != '\0') { exclude_hosts_array = cJSON_CreateArray (); - char **exclude_hosts_list = g_strsplit (target->exclude_hosts, ",", 0); + gchar **exclude_hosts_list = g_strsplit (target->exclude_hosts, ",", 0); for (int i = 0; exclude_hosts_list[i] != NULL; i++) { cJSON *exclude_host_item = NULL; @@ -1937,7 +1893,7 @@ openvasd_build_scan_config_json (openvasd_target_t *target, if (target->finished_hosts && target->finished_hosts[0] != '\0') { finished_hosts_array = cJSON_CreateArray (); - char **finished_hosts_list = g_strsplit (target->finished_hosts, ",", 0); + gchar **finished_hosts_list = g_strsplit (target->finished_hosts, ",", 0); for (int i = 0; finished_hosts_list[i] != NULL; i++) { cJSON *finished_host_item = NULL; @@ -2022,8 +1978,8 @@ openvasd_build_scan_config_json (openvasd_target_t *target, * @return New openvasd credential. */ openvasd_credential_t * -openvasd_credential_new (const char *type, const char *service, - const char *port) +openvasd_credential_new (const gchar *type, const gchar *service, + const gchar *port) { openvasd_credential_t *new_credential; @@ -2065,7 +2021,7 @@ openvasd_credential_free (openvasd_credential_t *credential) */ void openvasd_credential_set_auth_data (openvasd_credential_t *credential, - const char *name, const char *value) + const gchar *name, const gchar *value) { if (credential == NULL || name == NULL) return; @@ -2097,9 +2053,9 @@ openvasd_credential_set_auth_data (openvasd_credential_t *credential, * @return The newly allocated openvasd_target_t. */ openvasd_target_t * -openvasd_target_new (const char *scanid, const char *hosts, const char *ports, - const char *exclude_hosts, int reverse_lookup_unify, - int reverse_lookup_only) +openvasd_target_new (const gchar *scanid, const gchar *hosts, + const gchar *ports, const gchar *exclude_hosts, + int reverse_lookup_unify, int reverse_lookup_only) { openvasd_target_t *new_target; new_target = g_malloc0 (sizeof (openvasd_target_t)); @@ -2127,7 +2083,7 @@ openvasd_target_new (const char *scanid, const char *hosts, const char *ports, */ void openvasd_target_set_finished_hosts (openvasd_target_t *target, - const char *finished_hosts) + const gchar *finished_hosts) { g_free (target->finished_hosts); target->finished_hosts = finished_hosts ? g_strdup (finished_hosts) : NULL; @@ -2205,7 +2161,7 @@ openvasd_target_add_credential (openvasd_target_t *target, * @return The newly allocated single VT. */ openvasd_vt_single_t * -openvasd_vt_single_new (const char *vt_id) +openvasd_vt_single_new (const gchar *vt_id) { openvasd_vt_single_t *new_vt_single; new_vt_single = g_malloc0 (sizeof (openvasd_vt_single_t)); @@ -2243,8 +2199,8 @@ openvasd_vt_single_free (openvasd_vt_single_t *vt_single) * @param[in] value The value of the preference. */ void -openvasd_vt_single_add_value (openvasd_vt_single_t *vt_single, const char *name, - const char *value) +openvasd_vt_single_add_value (openvasd_vt_single_t *vt_single, + const gchar *name, const gchar *value) { g_hash_table_replace (vt_single->vt_values, g_strdup (name), g_strdup (value)); diff --git a/openvasd/openvasd.h b/openvasd/openvasd.h index 395faacb..f9fc4e87 100644 --- a/openvasd/openvasd.h +++ b/openvasd/openvasd.h @@ -22,18 +22,18 @@ struct openvasd_result { unsigned long id; - char *type; - char *ip_address; - char *hostname; - char *oid; + gchar *type; + gchar *ip_address; + gchar *hostname; + gchar *oid; int port; - char *protocol; - char *message; - char *detail_name; - char *detail_value; - char *detail_source_type; - char *detail_source_name; - char *detail_source_description; + gchar *protocol; + gchar *message; + gchar *detail_name; + gchar *detail_value; + gchar *detail_source_type; + gchar *detail_source_name; + gchar *detail_source_description; }; /** @brief Openvasd Errors */ @@ -96,9 +96,9 @@ typedef enum struct openvasd_response { - long code; /**< HTTP code response. */ - char *body; /**< String containing the body response. */ - char *header; /**< A header value. */ + long code; /**< HTTP code response. */ + gchar *body; /**< String containing the body response. */ + gchar *header; /**< A header value. */ }; struct openvasd_scan_status @@ -147,7 +147,7 @@ openvasd_resp_t openvasd_get_vts (openvasd_connector_t *); openvasd_resp_t -openvasd_start_scan (openvasd_connector_t *, char *); +openvasd_start_scan (openvasd_connector_t *, gchar *); openvasd_resp_t openvasd_stop_scan (openvasd_connector_t *); @@ -159,8 +159,9 @@ openvasd_resp_t openvasd_get_scan_results (openvasd_connector_t *, long, long); openvasd_result_t -openvasd_result_new (unsigned long, char *, char *, char *, char *, int, char *, - char *, char *, char *, char *, char *, char *); +openvasd_result_new (unsigned long, gchar *, gchar *, gchar *, gchar *, int, + gchar *, gchar *, gchar *, gchar *, gchar *, gchar *, + gchar *); void openvasd_result_free (openvasd_result_t *); @@ -233,11 +234,11 @@ typedef struct openvasd_vt_single openvasd_vt_single_t; typedef struct openvasd_credential openvasd_credential_t; openvasd_target_t * -openvasd_target_new (const char *, const char *, const char *, const char *, +openvasd_target_new (const gchar *, const gchar *, const gchar *, const gchar *, int, int); void -openvasd_target_set_finished_hosts (openvasd_target_t *, const char *); +openvasd_target_set_finished_hosts (openvasd_target_t *, const gchar *); void openvasd_target_add_alive_test_methods (openvasd_target_t *, gboolean, gboolean, @@ -247,11 +248,11 @@ void openvasd_target_free (openvasd_target_t *); openvasd_credential_t * -openvasd_credential_new (const char *, const char *, const char *); +openvasd_credential_new (const gchar *, const gchar *, const gchar *); void -openvasd_credential_set_auth_data (openvasd_credential_t *, const char *, - const char *); +openvasd_credential_set_auth_data (openvasd_credential_t *, const gchar *, + const gchar *); void openvasd_credential_free (openvasd_credential_t *); @@ -259,14 +260,14 @@ void openvasd_target_add_credential (openvasd_target_t *, openvasd_credential_t *); openvasd_vt_single_t * -openvasd_vt_single_new (const char *); +openvasd_vt_single_new (const gchar *); void openvasd_vt_single_free (openvasd_vt_single_t *); void -openvasd_vt_single_add_value (openvasd_vt_single_t *, const char *, - const char *); +openvasd_vt_single_add_value (openvasd_vt_single_t *, const gchar *, + const gchar *); /* Scan config builder */ char * @@ -280,7 +281,7 @@ typedef void *openvasd_curlm_t; */ typedef struct openvasd_string { - char *ptr; + gchar *ptr; size_t len; } openvasd_stringstream; diff --git a/openvasd/vtparser.c b/openvasd/vtparser.c index c6f64ff5..ba86d2ed 100644 --- a/openvasd/vtparser.c +++ b/openvasd/vtparser.c @@ -45,7 +45,7 @@ typedef enum * @return Integer representing the category type. */ static int -get_category_from_name (const char *cat) +get_category_from_name (const gchar *cat) { if (!g_strcmp0 (cat, "init")) return ACT_INIT; @@ -132,7 +132,7 @@ add_tags_to_nvt (nvti_t *nvt, cJSON *tag_obj) nvti_set_detection (nvt, item->valuestring); // Parse severity - char *severity_vector = NULL; + gchar *severity_vector = NULL; if ((item = cJSON_GetObjectItem (tag_obj, "severity_vector")) != NULL && cJSON_IsString (item)) @@ -147,8 +147,8 @@ add_tags_to_nvt (nvti_t *nvt, cJSON *tag_obj) if (severity_vector) { - char *severity_origin = NULL, *severity_type = NULL; - char *cvss_base; + gchar *severity_origin = NULL, *severity_type = NULL; + gchar *cvss_base; time_t severity_date = 0; double cvss_base_dbl; @@ -202,7 +202,7 @@ parse_references (nvti_t *nvt, cJSON *vt_obj) cJSON *ref_item; cJSON_ArrayForEach (ref_obj, item) { - char *id, *class; + gchar *id, *class; if (!cJSON_IsObject (ref_obj)) { @@ -248,7 +248,7 @@ add_preferences_to_nvt (nvti_t *nvt, cJSON *vt_obj) cJSON_ArrayForEach (prefs_obj, item) { - char *class, *name, *default_val; + gchar *class, *name, *default_val; int id; if (!cJSON_IsObject (prefs_obj)) { @@ -310,12 +310,12 @@ openvasd_parse_vt (gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event) nvti_t *nvt = NULL; cJSON *vt_obj = NULL; cJSON *item = NULL; - char *error_message = NULL; + gchar *error_message = NULL; gvm_json_pull_parser_next (parser, event); // Handle start/end of json array - char *path = gvm_json_path_to_string (event->path); + gchar *path = gvm_json_path_to_string (event->path); if (!g_strcmp0 (path, "$") && event->type == GVM_JSON_PULL_EVENT_ARRAY_START) { gvm_json_pull_parser_next (parser, event);