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

Change: Call GET_NVTS with close flag #141

Closed
Closed
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
75 changes: 72 additions & 3 deletions src/gsad_gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -6931,6 +6931,22 @@ save_config_gmp (gvm_connection_t *connection, credentials_t *credentials,
return ret;
}

/**
* @brief Connect to Greenbone Vulnerability Manager daemon.
*
* @param[in] credentials Username and password for authentication.
* @param[out] connection Connection to Manager on success.
*
* @return 0 success, 1 if manager closed connection, 2 if auth failed,
* 3 on timeout, 4 failed to connect, -1 on error
*/
int
manager_reconnect (credentials_t *credentials, gvm_connection_t *connection)
{
gvm_connection_close (connection); // FIX need to free content?
return manager_connect (credentials, connection, NULL);
}

/**
* @brief Get details of a family for a config, envelope the result.
*
Expand Down Expand Up @@ -6966,7 +6982,7 @@ get_config_family (gvm_connection_t *connection, credentials_t *credentials,
if (gvm_connection_sendf (
connection,
"<get_nvts"
" config_id=\"%s\" details=\"1\""
" close=\"1\" config_id=\"%s\" details=\"1\""
" family=\"%s\" timeout=\"1\" preference_count=\"1\""
" skip_cert_refs=\"1\""
" sort_field=\"%s\" sort_order=\"%s\"/>",
Expand All @@ -6985,7 +7001,7 @@ get_config_family (gvm_connection_t *connection, credentials_t *credentials,
response_data);
}

if (read_string_c (connection, &xml))
if (read_text_string_c (connection, &xml))
{
g_string_free (xml, TRUE);
cmd_response_data_set_status_code (response_data,
Expand All @@ -7000,12 +7016,65 @@ get_config_family (gvm_connection_t *connection, credentials_t *credentials,

if (edit)
{
char *res = NULL;

switch (manager_reconnect (credentials, connection))
{
case 0:
break;
case 1: /* manager closed connection */
cmd_response_data_set_status_code (response_data,
MHD_HTTP_INTERNAL_SERVER_ERROR);
res = gsad_message (credentials, "Internal error", __func__, __LINE__,
"An internal error occurred. "
"Diagnostics: Could not connect to manager daemon. "
"Manager closed the connection.",
response_data);
break;
#if 0
// FIX caller needs special check for this return
case 2: /* auth failed */
cmd_response_data_free (response_data);
return handler_send_reauthentication (con, MHD_HTTP_UNAUTHORIZED,
LOGIN_FAILED);
#endif
case 3: /* timeout */
cmd_response_data_set_status_code (response_data,
MHD_HTTP_INTERNAL_SERVER_ERROR);
res = gsad_message (credentials, "Internal error", __func__, __LINE__,
"An internal error occurred. "
"Diagnostics: Could not connect to manager daemon. "
"Connection timeout.",
response_data);
break;
case 4: /* can't connect to manager */
cmd_response_data_set_status_code (response_data,
MHD_HTTP_SERVICE_UNAVAILABLE);
res = gsad_message (credentials, "Internal error", __func__, __LINE__,
"An internal error occurred. "
"Diagnostics: Could not connect to manager daemon. "
"Could not open a connection.",
response_data);
break;
default: /* unknown error */
cmd_response_data_set_status_code (response_data,
MHD_HTTP_INTERNAL_SERVER_ERROR);
res = gsad_message (credentials, "Internal error", __func__, __LINE__,
"An internal error occurred. "
"Diagnostics: Could not connect to manager daemon. "
"Unknown error.",
response_data);
}
if (res)
return res;

/* Get the details for all NVT's in the family. */

g_string_append (xml, "<all>");

if (gvm_connection_sendf (connection,
"<get_nvts"
" close=\"1\""
" details=\"1\""
" timeout=\"1\""
" family=\"%s\""
Expand All @@ -7030,7 +7099,7 @@ get_config_family (gvm_connection_t *connection, credentials_t *credentials,
response_data);
}

if (read_string_c (connection, &xml))
if (read_text_string_c (connection, &xml))
{
g_string_free (xml, TRUE);
cmd_response_data_set_status_code (response_data,
Expand Down
Loading