Greenbone Security Assistant  8.0.0
gsad_gmp.c File Reference

GMP communication module of Greenbone Security Assistant daemon. More...

#include "gsad_gmp.h"
#include "gsad_base.h"
#include "gsad_credentials.h"
#include "gsad_http.h"
#include "gsad_i18n.h"
#include "gsad_params.h"
#include "gsad_session.h"
#include "gsad_settings.h"
#include "utils.h"
#include <arpa/inet.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <glib.h>
#include <gvm/base/cvss.h>
#include <gvm/gmp/gmp.h>
#include <gvm/util/fileutils.h>
#include <gvm/util/serverutils.h>
#include <gvm/util/xmlutils.h>
#include <microhttpd.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/un.h>
#include <time.h>
#include <unistd.h>
Include dependency graph for gsad_gmp.c:

Go to the source code of this file.

Data Structures

struct  find_by_value_t
 Structure to search a key by value. More...
 

Macros

#define G_LOG_DOMAIN   "gsad gmp"
 GLib log domain. More...
 
#define OPENVASMD_ADDRESS   "127.0.0.1"
 Manager (gvmd) address. More...
 
#define GSAD_MESSAGE_INVALID
 Answer for invalid input. More...
 
#define GSAD_MESSAGE_INVALID_PARAM(op)
 Answer for invalid input. More...
 
#define GSAD_STATUS_INVALID_REQUEST   MHD_HTTP_UNPROCESSABLE_ENTITY
 HTTP status code for expected failure of gmp requests e.g. if some parameter was missing or invalid. More...
 
#define RESULTS_PER_PAGE   100
 Initial filtered results per page on the report summary. More...
 
#define FILT_ID_NONE   "0"
 filt_id value to use term or built-in default filter. More...
 
#define FILT_ID_USER_SETTING   "-2"
 filt_id value to use the filter in the user setting if possible. More...
 
#define CHECK_VARIABLE_INVALID(name, op_name)
 Check if variable is NULL. More...
 
#define PARAM_OR_SETTING(value, param, setting_id, cleanup)
 Get a value from a param or fall back to a setting. More...
 
#define EVENT_TYPE_NEW_SECINFO   "New SecInfo arrived"
 
#define EVENT_TYPE_UPDATED_SECINFO   "Updated SecInfo arrived"
 
#define EVENT_TYPE_TASK_RUN_STATUS_CHANGED   "Task run status changed"
 
#define EVENT_TYPE_TICKET_RECEIVED   "Ticket received"
 
#define EVENT_TYPE_ASSIGNED_TICKET_CHANGED   "Assigned ticket changed"
 
#define EVENT_TYPE_OWNED_TICKET_CHANGED   "Owned ticket changed"
 
#define GET_TRASH_RESOURCE(capability, command, name)
 
#define CHECK_GMPF_RET
 
#define AUTH_CONF_SETTING(key, value)
 Generate AUTH_CONF_SETTING element for save_auth_gmp. More...
 

Functions

static int gmp (gvm_connection_t *connection, credentials_t *credentials, gchar **response, entity_t *entity_return, cmd_response_data_t *response_data, const char *command)
 Run a single GMP command. More...
 
static int gmpf (gvm_connection_t *connection, credentials_t *credentials, gchar **response, entity_t *entity_return, cmd_response_data_t *response_data, const char *format,...)
 Run a single formatted GMP command. More...
 
static char * edit_role (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Setup edit_role XML, envelope the result. More...
 
static char * get_alert (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get one alert, envelope the result. More...
 
static char * get_alerts (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get all alerts, envelope the result. More...
 
static char * get_agent (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get one agent, envelope the result. More...
 
static char * get_agents (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get all agents, envelope the result. More...
 
static char * get_asset (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Request an asset. More...
 
static char * get_assets (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Request assets. More...
 
static char * get_tasks (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get all tasks, envelope the result. More...
 
static char * get_trash (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Setup trash page XML, envelope the result. More...
 
static char * get_config_family (gvm_connection_t *connection, credentials_t *credentials, params_t *params, int edit, cmd_response_data_t *response_data)
 Get details of a family for a config, envelope the result. More...
 
static char * get_config (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, int edit, cmd_response_data_t *response_data)
 Get a config, envelope the result. More...
 
static char * get_configs (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get all scan configs, envelope the result. More...
 
static char * get_filter (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get one filter, envelope the result. More...
 
static char * get_filters (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get all filters, envelope the result. More...
 
static char * get_group (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get one group, envelope the result. More...
 
static char * get_groups (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get all groups, envelope the result. More...
 
static char * get_credential (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get one credential, envelope the result. More...
 
static char * get_credentials (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get one or all credentials, envelope the result. More...
 
static char * get_notes (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get all notes, envelope the result. More...
 
static char * get_note (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get a note, envelope the result. More...
 
static char * get_overrides (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get all overrides, envelope the result. More...
 
static char * get_override (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get a override, envelope the result. More...
 
static char * get_permission (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get one permission, envelope the result. More...
 
static char * get_permissions (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get all permissions, envelope the result. More...
 
static char * get_port_list (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get one port_list, envelope the result. More...
 
static char * get_port_lists (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get all Port Lists, envelope the result. More...
 
static char * get_tag (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get one tag, envelope the result. More...
 
static char * get_tags (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get all tags, envelope the result. More...
 
static char * get_target (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get one target, envelope the result. More...
 
static char * get_targets (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get all targets, envelope the result. More...
 
static char * get_report_format (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get one report format, envelope the result. More...
 
static char * get_report_formats (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get all Report Formats, envelope the result. More...
 
static char * get_reports (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get all reports, envelope the result. More...
 
static char * get_results (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get all results, envelope the result. More...
 
static char * get_role (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get one role, envelope the result. More...
 
static char * get_roles (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get all roles, envelope the result. More...
 
static char * get_scanner (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get one scanner, envelope the result. More...
 
static char * get_scanners (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get all scanners, envelope the result. More...
 
static char * get_schedule (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get one schedule, envelope the result. More...
 
static char * get_schedules (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get all schedules, envelope the result. More...
 
static char * get_user (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get one user, envelope the result. More...
 
static char * get_users (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get all users, envelope the result. More...
 
static char * get_vulns (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get multiple vulns, envelope the result. More...
 
static char * wizard (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Returns a wizard page. More...
 
static char * wizard_get (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Returns a wizard_get page. More...
 
static int gmp_success (entity_t entity)
 Check whether an GMP command failed. More...
 
static gchar * response_from_entity (gvm_connection_t *connection, credentials_t *credentials, params_t *params, entity_t entity, const char *action, cmd_response_data_t *response_data)
 Set redirect or return a basic action_result page based on entity. More...
 
static gchar * action_result (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data, const char *action, const char *message, const char *details, const char *id)
 Generate a enveloped GMP XML containing an action result. More...
 
int command_enabled (credentials_t *credentials, const gchar *name)
 Init the GSA GMP library. More...
 
void gmp_init (const gchar *manager_address_unix, const gchar *manager_address_tls, int port_manager)
 Init the GSA GMP library. More...
 
static int filter_exists (gvm_connection_t *connection, const char *filt_id)
 Check whether a filter exists. More...
 
static char * envelope_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, gchar *xml, cmd_response_data_t *response_data)
 Wrap some XML in an envelope. More...
 
static int member (params_t *params, const char *string)
 Look for a param with name equal to a given string. More...
 
int member1 (params_t *params, const char *string)
 Look for param with value 1 and name equal to given string. More...
 
static char * check_modify_config (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *next, const char *fail_next, int *success, cmd_response_data_t *response_data)
 Check a modify_config response. More...
 
void set_http_status_from_entity (entity_t entity, cmd_response_data_t *response_data)
 Set the HTTP status according to GMP response entity. More...
 
static int simple_gmpf (gvm_connection_t *connection, const gchar *message_operation, credentials_t *credentials, gchar **response, cmd_response_data_t *response_data, const char *format,...)
 Run a single GMP command, preparing a response even on error. More...
 
static int setting_get_value (gvm_connection_t *connection, const char *setting_id, gchar **value, cmd_response_data_t *response_data)
 Get a setting by UUID for the current user of an GMP connection. More...
 
gchar * message_invalid (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data, const char *message, const char *op_name)
 Check a param using the direct response method. More...
 
char * get_one (gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
 Get one resource, envelope the result. More...
 
static char * get_many (gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
 Get all of a particular type of resource, envelope the result. More...
 
char * edit_resource (gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_get_attribs, const char *extra_xml, cmd_response_data_t *response_data)
 Setup edit XML, envelope the result. More...
 
gchar * format_file_name (gchar *fname_format, credentials_t *credentials, const char *type, const char *uuid, entity_t resource_entity)
 Generates a file name for exporting. More...
 
char * export_resource (gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a resource. More...
 
static char * export_many (gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a list of resources. More...
 
char * delete_resource (gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, gboolean ultimate, cmd_response_data_t *response_data)
 Delete a resource, get all resources, envelope the result. More...
 
char * move_resource_to_trash (gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Move a resource to the trashcan. More...
 
char * delete_from_trash_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Delete a resource from the trashcan. More...
 
char * resource_action (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *type, const char *action, cmd_response_data_t *response_data)
 Perform action on resource, get next page, envelope result. More...
 
char * create_report_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Returns page to create a new container task. More...
 
char * import_report_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Import report, get all reports, envelope the result. More...
 
char * create_container_task_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Create a container task, serve next page. More...
 
char * create_task_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Create a task, get all tasks, envelope the result. More...
 
char * delete_task_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Delete a task, get all tasks, envelope the result. More...
 
char * save_task_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Save task, get next page, envelope the result. More...
 
char * save_container_task_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Save container task, get next page, envelope the result. More...
 
char * export_task_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a task. More...
 
char * export_tasks_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a list of tasks. More...
 
char * stop_task_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Stop a task, get all tasks, envelope the result. More...
 
char * resume_task_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Resume a task, get all tasks, envelope the result. More...
 
char * start_task_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Start a task, get all tasks, envelope the result. More...
 
char * move_task_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Reassign a task to a new GMP slave. More...
 
char * get_info (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Requests SecInfo. More...
 
char * get_info_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get info, envelope the result. More...
 
static void params_toggle_overrides (params_t *params, const char *overrides)
 Toggle overrides. More...
 
char * get_tasks_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get all tasks, envelope the result. More...
 
char * get_task_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get a task, envelope the result. More...
 
char * create_credential_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Create a credential, get all credentials, envelope result. More...
 
char * get_credential_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get one credential, envelope the result. More...
 
int download_credential_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, char **html, char **login, cmd_response_data_t *response_data)
 Export a Credential in a defined format. More...
 
char * export_credential_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a Credential. More...
 
char * export_credentials_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a list of Credentials. More...
 
char * get_credentials_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get one or all credentials, envelope the result. More...
 
char * delete_credential_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Delete credential, get all credentials, envelope result. More...
 
char * save_credential_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Save credential, get next page, envelope the result. More...
 
char * create_agent_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Create an agent, get all agents, envelope result. More...
 
char * delete_agent_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Delete agent, get all agents, envelope result. More...
 
int download_agent_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, char **html, char **filename, cmd_response_data_t *response_data)
 Get an agent, envelope the result. More...
 
char * save_agent_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Modify a agent, get all agents, envelope the result. More...
 
char * get_agent_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get one agent, envelope the result. More...
 
char * get_agents_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get all agents, envelope the result. More...
 
char * verify_agent_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Verify agent, get agents, envelope the result. More...
 
char * export_agent_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a agent. More...
 
char * export_agents_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a list of agents. More...
 
char * get_aggregate_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get an aggregate of resources. More...
 
static char * new_alert (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Returns page to create a new alert. More...
 
char * new_alert_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Returns page to create a new alert. More...
 
static void append_alert_event_data (GString *xml, params_t *data, const char *event)
 Send event data for an alert. More...
 
static void append_alert_condition_data (GString *xml, params_t *data, const char *condition)
 Send condition data for an alert. More...
 
static void append_alert_method_data (GString *xml, params_t *data, const char *method, params_t *report_formats)
 Send method data for an alert. More...
 
char * create_alert_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Create an alert, get all alerts, envelope the result. More...
 
char * delete_alert_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Delete an alert, get all alerts, envelope the result. More...
 
char * get_alert_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get one alert, envelope the result. More...
 
char * get_alerts_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get all alerts, envelope the result. More...
 
char * edit_alert (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Setup edit_alert XML, envelope the result. More...
 
char * edit_alert_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Setup edit_alert XML, envelope the result. More...
 
char * save_alert_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Modify an alert, get all alerts, envelope the result. More...
 
char * test_alert_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Test an alert, get all alerts envelope the result. More...
 
char * export_alert_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export an alert. More...
 
char * export_alerts_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a list of alerts. More...
 
char * create_target_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Create a target, get all targets, envelope the result. More...
 
char * clone_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Clone a resource, envelope the result. More...
 
char * delete_target_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Delete a target, get all targets, envelope the result. More...
 
char * restore_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Restore a resource, get all trash, envelope the result. More...
 
char * empty_trashcan_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Empty the trashcan, get all trash, envelope the result. More...
 
char * create_tag_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Create a tag, envelope the result. More...
 
char * delete_tag_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Delete note, get next page, envelope the result. More...
 
char * save_tag_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Modify a tag, get all tags, envelope the result. More...
 
char * export_tag_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a tag. More...
 
char * export_tags_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a list of tags. More...
 
char * get_tag_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get one tag, envelope the result. More...
 
char * get_tags_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get all tags, envelope the result. More...
 
char * toggle_tag_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Set tag enabled status. More...
 
char * get_target_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get one target, envelope the result. More...
 
char * get_targets_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get all targets, envelope the result. More...
 
char * save_target_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Modify a target, get all targets, envelope the result. More...
 
char * export_target_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a target. More...
 
char * export_targets_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a list of targets. More...
 
char * create_config_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Create config, get all configs, envelope the result. More...
 
char * import_config_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Import config, get all configs, envelope the result. More...
 
char * get_configs_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get all scan configs, envelope the result. More...
 
char * get_config_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get a config, envelope the result. More...
 
static char * edit_config (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get a config, envelope the result. More...
 
char * edit_config_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get a config, envelope the result. More...
 
char * sync_config_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Sync config, get configs, envelope the result. More...
 
static char * save_osp_prefs (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *next, const char *fail_next, int *success, cmd_response_data_t *response_data)
 Save OSP file preferences. More...
 
char * save_config_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Save details of an NVT for a config and return the next page. More...
 
char * get_config_family_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get details of a family for a config, envelope the result. More...
 
char * edit_config_family_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get details of a family for editing a config, envelope result. More...
 
char * save_config_family_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get details of an NVT for a config, envelope the result. More...
 
static char * get_config_nvt (gvm_connection_t *connection, credentials_t *credentials, params_t *params, int edit, cmd_response_data_t *response_data)
 Get details of an NVT for a config, envelope the result. More...
 
char * get_config_nvt_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get details of an NVT for a config, envelope the result. More...
 
char * edit_config_nvt_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Edit details of an NVT for a config, envelope the result. More...
 
char * save_config_nvt_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Save NVT prefs for a config, get NVT details, envelope result. More...
 
char * delete_config_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Delete config, get all configs, envelope the result. More...
 
char * export_config_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a config. More...
 
char * export_configs_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a list of scan configs. More...
 
char * export_note_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a note. More...
 
char * export_notes_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a list of notes. More...
 
char * export_override_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export an override. More...
 
char * export_overrides_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a list of overrides. More...
 
char * export_port_list_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a Port List. More...
 
char * export_port_lists_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a list of Port Lists. More...
 
char * export_preference_file_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a file preference. More...
 
char * export_report_format_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a report format. More...
 
char * export_report_formats_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a list of Report Formats. More...
 
char * delete_report_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Delete report, get task status, envelope the result. More...
 
char * get_report (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
 Get a report and return the result. More...
 
char * get_report_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get a report and envelope the result. More...
 
char * report_alert_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Run alert for a report. More...
 
char * get_reports_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get all reports, envelope the result. More...
 
char * download_ssl_cert (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get an SSL Certificate. More...
 
char * download_ca_pub (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get a Scanner's CA Certificate. More...
 
char * download_key_pub (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get a Scanner's Certificate. More...
 
char * export_result_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a result. More...
 
char * export_results_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a list of results. More...
 
char * get_results_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get all results, envelope the result. More...
 
char * get_result_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get one result, envelope the result. More...
 
char * get_notes_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get all notes, envelope the result. More...
 
char * get_note_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get a note, envelope the result. More...
 
const char * get_port_from_params (params_t *params)
 Get a port from request params. More...
 
const char * get_hosts_from_params (params_t *params)
 Get hosts from request params. More...
 
const char * get_task_id_from_params (params_t *params)
 Get task_id from request params. More...
 
const char * get_severity_from_params (params_t *params)
 Get severity from request params. More...
 
const char * get_result_id_from_params (params_t *params)
 Get result_id from request params. More...
 
char * create_note_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Create a note, get report, envelope the result. More...
 
char * delete_note_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Delete note, get next page, envelope the result. More...
 
char * save_note_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Save note, get next page, envelope the result. More...
 
char * get_overrides_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get all overrides, envelope the result. More...
 
char * get_override_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get an override, envelope the result. More...
 
char * create_override_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Create an override, get report, envelope the result. More...
 
char * delete_override_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Delete override, get next page, envelope the result. More...
 
char * save_override_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Save override, get next page, envelope the result. More...
 
char * get_scanners_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get all scanners, envelope the result. More...
 
char * get_scanner_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get one scanner, envelope the result. More...
 
char * export_scanner_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a scanner. More...
 
char * export_scanners_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a list of scanners. More...
 
char * verify_scanner_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Verify scanner, get scanners, envelope the result. More...
 
char * create_scanner_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Create a scanner, get all scanners, envelope the result. More...
 
char * delete_scanner_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Delete a scanner, get all scanners, envelope the result. More...
 
char * save_scanner_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Save scanner, get next page, envelope the result. More...
 
char * get_schedule_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get one schedule, envelope the result. More...
 
char * get_schedules_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get all schedules, envelope the result. More...
 
char * create_schedule_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Create a schedule, get all schedules, envelope the result. More...
 
char * delete_schedule_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Delete a schedule, get all schedules, envelope the result. More...
 
char * get_system_reports_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get all system reports, envelope the result. More...
 
char * get_system_report_gmp (gvm_connection_t *connection, credentials_t *credentials, const char *url, params_t *params, cmd_response_data_t *response_data)
 Return system report image. More...
 
char * get_report_format_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get one report format, envelope the result. More...
 
char * get_report_formats_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get all Report Formats, envelope the result. More...
 
char * delete_report_format_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Delete report format, get report formats, envelope the result. More...
 
char * import_report_format_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Import report format, get all report formats, envelope result. More...
 
char * save_report_format_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Save report_format, get next page, envelope the result. More...
 
char * verify_report_format_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Verify report format, get report formats, envelope the result. More...
 
char * run_wizard_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Run a wizard and envelope the result. More...
 
char * get_trash_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get all trash, envelope the result. More...
 
static int send_settings_filters (gvm_connection_t *connection, params_t *data, params_t *changed, GString *xml, int *modify_failed_flag, cmd_response_data_t *response_data)
 Send settings resource filters. More...
 
char * save_my_settings_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const gchar *accept_language, cmd_response_data_t *response_data)
 Returns page with user's settings, for editing. More...
 
char * get_group_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get one group, envelope the result. More...
 
char * get_groups_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get all groups, envelope the result. More...
 
char * delete_group_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Delete a group, get all groups, envelope the result. More...
 
char * create_group_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Create a group, get all groups, envelope the result. More...
 
char * export_group_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a group. More...
 
char * export_groups_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a list of groups. More...
 
char * save_group_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Modify a group, return the next page. More...
 
char * get_permission_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get one permission, envelope the result. More...
 
char * get_permissions_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get all permissions, envelope the result. More...
 
char * delete_permission_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Delete a permission, get all permissions, envelope the result. More...
 
char * create_permission_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Create a permission, get all permissions, envelope the result. More...
 
char * create_permissions_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Create multiple permission, get next page, envelope the result. More...
 
char * export_permission_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a permission. More...
 
char * export_permissions_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a list of permissions. More...
 
char * save_permission_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Modify a permission, get all permissions, envelope the result. More...
 
char * create_port_list_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Create a port list, get all port lists, envelope the result. More...
 
char * create_port_range_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Add a range to a port list, envelope the result. More...
 
char * get_port_list_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get one port_list, envelope the result. More...
 
char * get_port_lists_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get all port_lists, envelope the result. More...
 
char * save_port_list_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Modify a port list, get all port list, envelope the result. More...
 
char * delete_port_list_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Delete a port list, get all port lists, envelope the result. More...
 
char * delete_port_range_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Delete a port range, get the port list, envelope the result. More...
 
char * import_port_list_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Import port list, get all port_lists, envelope the result. More...
 
char * delete_role_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Delete a role, get all roles, envelope the result. More...
 
char * create_role_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Create a role, get all roles, envelope the result. More...
 
char * edit_role_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Setup edit_role XML, envelope the result. More...
 
char * get_role_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get one role, envelope the result. More...
 
char * get_roles_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get all roles, envelope the result. More...
 
char * export_role_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a role. More...
 
char * export_roles_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a list of roles. More...
 
char * save_role_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Modify a role, return the next page. More...
 
char * get_feeds_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get descriptions of the feeds connected to the manager. More...
 
static char * sync_feed (gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *sync_cmd, const char *action, const char *feed_name, cmd_response_data_t *response_data)
 Synchronize with a feed and envelope the result. More...
 
char * sync_feed_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Synchronize with an NVT feed and envelope the result. More...
 
char * sync_scap_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Synchronize with a SCAP feed and envelope the result. More...
 
char * sync_cert_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Synchronize with a CERT feed and envelope the result. More...
 
char * get_filter_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get one filter, envelope the result. More...
 
char * get_filters_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get all filters, envelope the result. More...
 
char * create_filter_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Create a filter, get all filters, envelope the result. More...
 
char * delete_filter_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Delete a filter, get all filters, envelope the result. More...
 
char * export_filter_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a filter. More...
 
char * export_filters_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a list of filters. More...
 
char * save_filter_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Modify a filter, get all filters, envelope the result. More...
 
char * export_schedule_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a schedule. More...
 
char * export_schedules_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a list of schedules. More...
 
char * save_schedule_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Save schedule, get next page, envelope the result. More...
 
char * delete_user_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Delete a user, get all users, envelope the result. More...
 
char * get_user_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get one user, envelope the result. More...
 
char * get_users_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get all users, envelope the result. More...
 
char * create_user_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Create a user, get all users, envelope the result. More...
 
char * get_vulns_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get multiple vulns, envelope the result. More...
 
char * auth_settings_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 
char * save_user_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Modify a user, get all users, envelope the result. More...
 
char * export_user_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a user. More...
 
char * export_users_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a list of users. More...
 
char * cvss_calculator (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 
char * save_auth_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Save authentication settings. More...
 
char * get_settings_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get all user defined settings. More...
 
char * save_setting_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Save user setting. More...
 
char * get_setting_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 
char * wizard_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Returns a wizard page. More...
 
char * wizard_get_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Returns a wizard_get page. More...
 
char * bulk_delete_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Delete multiple resources, get next page, envelope the result. More...
 
char * bulk_export_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export multiple resources. More...
 
char * create_host_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Create a host, serve next page. More...
 
char * get_asset_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get asset, envelope the result. More...
 
char * get_assets_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get assets, envelope the result. More...
 
char * create_asset_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Create an asset, get report, envelope the result. More...
 
char * delete_asset_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Delete an asset, go to the next page. More...
 
char * export_asset_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export an asset. More...
 
char * export_assets_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Export a list of assets. More...
 
char * save_asset_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Modify an asset, get all assets, envelope the result. More...
 
char * get_tickets_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get all tickets, envelope the result. More...
 
char * get_ticket_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get single tickets, envelope the result. More...
 
char * create_ticket_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Create a ticket. More...
 
char * save_ticket_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Modify a ticket. More...
 
char * delete_ticket_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Delete a ticket. More...
 
char * renew_session_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 
char * ping_gmp (gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
 Get assets, envelope the result. More...
 
int connect_unix (const gchar *path)
 Connect to Greenbone Vulnerability Manager daemon. More...
 
int gvm_connection_open (gvm_connection_t *connection, const gchar *address, int port)
 Connect to an address. More...
 
int authenticate_gmp (const gchar *username, const gchar *password, gchar **role, gchar **timezone, gchar **severity, gchar **capabilities, gchar **language, gchar **pw_warning)
 Check authentication credentials. More...
 
int login (http_connection_t *con, params_t *params, cmd_response_data_t *response_data, const char *client_address)
 Login and create a session. More...
 
int manager_connect (credentials_t *credentials, gvm_connection_t *connection, cmd_response_data_t *response_data)
 Connect to Greenbone Vulnerability Manager daemon. More...
 

Variables

int manager_use_tls = 0
 Whether to use TLS for Manager connections. More...
 
gchar * manager_address = NULL
 The address the manager is on. More...
 
int manager_port = 9390
 The port the manager is on. More...
 

Detailed Description

GMP communication module of Greenbone Security Assistant daemon.

This file implements an API for GMP. The functions call the Greenbone Vulnerability Manager via GMP properly.

Definition in file gsad_gmp.c.

Macro Definition Documentation

◆ AUTH_CONF_SETTING

#define AUTH_CONF_SETTING (   key,
  value 
)
Value:
"<auth_conf_setting>" \
"<key>" key "</key>" \
"<value>" value "</value>" \
"</auth_conf_setting>"

Generate AUTH_CONF_SETTING element for save_auth_gmp.

Definition at line 17657 of file gsad_gmp.c.

◆ CHECK_GMPF_RET

#define CHECK_GMPF_RET

Definition at line 14725 of file gsad_gmp.c.

◆ CHECK_VARIABLE_INVALID

#define CHECK_VARIABLE_INVALID (   name,
  op_name 
)
Value:
if (name == NULL) \
{ \
return message_invalid (connection, credentials, params, response_data, \
"Given " G_STRINGIFY (name) " was invalid", \
op_name); \
}
Structure of credential related information.
gchar * message_invalid(gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data, const char *message, const char *op_name)
Check a param using the direct response method.
Definition: gsad_gmp.c:1004

Check if variable is NULL.

Parameters
[in]nameParam name.
[in]op_nameOperation name.

Definition at line 119 of file gsad_gmp.c.

◆ EVENT_TYPE_ASSIGNED_TICKET_CHANGED

#define EVENT_TYPE_ASSIGNED_TICKET_CHANGED   "Assigned ticket changed"

Definition at line 5432 of file gsad_gmp.c.

◆ EVENT_TYPE_NEW_SECINFO

#define EVENT_TYPE_NEW_SECINFO   "New SecInfo arrived"

Definition at line 5428 of file gsad_gmp.c.

◆ EVENT_TYPE_OWNED_TICKET_CHANGED

#define EVENT_TYPE_OWNED_TICKET_CHANGED   "Owned ticket changed"

Definition at line 5433 of file gsad_gmp.c.

◆ EVENT_TYPE_TASK_RUN_STATUS_CHANGED

#define EVENT_TYPE_TASK_RUN_STATUS_CHANGED   "Task run status changed"

Definition at line 5430 of file gsad_gmp.c.

◆ EVENT_TYPE_TICKET_RECEIVED

#define EVENT_TYPE_TICKET_RECEIVED   "Ticket received"

Definition at line 5431 of file gsad_gmp.c.

◆ EVENT_TYPE_UPDATED_SECINFO

#define EVENT_TYPE_UPDATED_SECINFO   "Updated SecInfo arrived"

Definition at line 5429 of file gsad_gmp.c.

◆ FILT_ID_NONE

#define FILT_ID_NONE   "0"

filt_id value to use term or built-in default filter.

Definition at line 106 of file gsad_gmp.c.

◆ FILT_ID_USER_SETTING

#define FILT_ID_USER_SETTING   "-2"

filt_id value to use the filter in the user setting if possible.

Definition at line 111 of file gsad_gmp.c.

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "gsad gmp"

GLib log domain.

Definition at line 65 of file gsad_gmp.c.

◆ GET_TRASH_RESOURCE

#define GET_TRASH_RESOURCE (   capability,
  command,
  name 
)

Definition at line 13113 of file gsad_gmp.c.

◆ GSAD_MESSAGE_INVALID

#define GSAD_MESSAGE_INVALID
Value:
"<gsad_msg status_text=\"%s\" operation=\"%s\">" \
"At least one entered value contains invalid characters or exceeds" \
" a size limit. You may use the Back button of your browser to adjust" \
" the entered values. If in doubt, the online help of the respective " \
"section" \
" will lead you to the appropriate help page." \
"</gsad_msg>"

Answer for invalid input.

Definition at line 73 of file gsad_gmp.c.

◆ GSAD_MESSAGE_INVALID_PARAM

#define GSAD_MESSAGE_INVALID_PARAM (   op)
Value:
"<gsad_msg status_text=\"Invalid parameter\" operation=\"" op "\">" \
"At least one entered value contains invalid characters or exceeds" \
" a size limit. You may use the Back button of your browser to adjust" \
" the entered values. If in doubt, the online help of the respective " \
"section" \
" will lead you to the appropriate help page." \
"</gsad_msg>"

Answer for invalid input.

Definition at line 83 of file gsad_gmp.c.

◆ GSAD_STATUS_INVALID_REQUEST

#define GSAD_STATUS_INVALID_REQUEST   MHD_HTTP_UNPROCESSABLE_ENTITY

HTTP status code for expected failure of gmp requests e.g. if some parameter was missing or invalid.

Definition at line 96 of file gsad_gmp.c.

◆ OPENVASMD_ADDRESS

#define OPENVASMD_ADDRESS   "127.0.0.1"

Manager (gvmd) address.

Definition at line 70 of file gsad_gmp.c.

◆ PARAM_OR_SETTING

#define PARAM_OR_SETTING (   value,
  param,
  setting_id,
  cleanup 
)
Value:
if (params_valid (params, param)) \
value = g_strdup (params_value (params, param)); \
else \
{ \
char *message; \
message = setting_get_value_error (connection, credentials, setting_id, \
&value, response_data); \
if (message) \
{ \
cleanup; \
return message; \
} \
}
Structure of credential related information.
Request parameter.
Definition: gsad_params.h:38
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
int params_valid(params_t *params, const char *name)
Get whether a param is valid.
Definition: gsad_base.c:303

Get a value from a param or fall back to a setting.

Todo:
Consider doing the input sanatizing in the page handlers.

Currently the input sanatizing is done in serve_post, exec_gmp_post and exec_gmp_get in gsad.c. This means that the information about what input is suitable for a page is separate from the page handler.

Doing the input sanatizing in the page handler will probably also help in responding with more detailed messages when an input error occurs.

Todo:
Take care of XML in input.

Anything that is printed into the XML directly (usually via g_string_append_printf below) must use something like g_markup_printf_escaped or g_markup_escape_text to ensure that any XML special sequences in the string are escaped.

Todo:
Unify the style of page handlers.

There are variations in the style of the page handlers that run multiple GMP commands.

Some, like delete_credential_gmp, simply run the GMP commands inside one GMP COMMANDS.

Others, like create_target_gmp, run each command separately and wrap the responses in a unique page tag.

One handler, delete_target_gmp, runs all the commands in a single COMMANDS and also wraps the response in a unique page tag to convey the context to the enveloped XML. This is probably the way to go.

Parameters
[out]valueVariable to assign the value to.
[in]paramThe param to try get the value from first.
[in]setting_idThe UUID of the setting to try next.
[in]cleanupCode to run on failure.

Definition at line 2206 of file gsad_gmp.c.

◆ RESULTS_PER_PAGE

#define RESULTS_PER_PAGE   100

Initial filtered results per page on the report summary.

Definition at line 101 of file gsad_gmp.c.

Function Documentation

◆ action_result()

static gchar * action_result ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data,
const char *  action,
const char *  message,
const char *  details,
const char *  id 
)
static

Generate a enveloped GMP XML containing an action result.

Parameters
[in]connectionConnection to manager
[in]credentialsUsername and password for authentication.
[in]paramsHTTP request params
[out]response_dataExtra data return for the HTTP response.
[in]actionName of the action.
[in]messageStatus message.
[in]detailsStatus details (optional).
[in]idID of the handled entity (optional).
Returns
Enveloped XML object.

Definition at line 965 of file gsad_gmp.c.

969 {
970  GString *xml;
971 
972  xml = g_string_new ("");
973  xml_string_append (xml,
974  "<action_result>"
975  "<action>%s</action>"
976  "<message>%s</message>",
977  action ? action : "", message ? message : "");
978 
979  if (details)
980  xml_string_append (xml, "<details>%s</details>", details);
981 
982  if (id)
983  xml_string_append (xml, "<id>%s</id>", id);
984 
985  g_string_append (xml, "</action_result>");
986 
987  return envelope_gmp (connection, credentials, params,
988  g_string_free (xml, FALSE), response_data);
989 }
Structure of credential related information.
static char * envelope_gmp(gvm_connection_t *connection, credentials_t *credentials, params_t *params, gchar *xml, cmd_response_data_t *response_data)
Wrap some XML in an envelope.
Definition: gsad_gmp.c:443

References envelope_gmp().

Referenced by check_modify_config(), create_permissions_gmp(), message_invalid(), ping_gmp(), renew_session_gmp(), response_from_entity(), and save_config_nvt_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ append_alert_condition_data()

static void append_alert_condition_data ( GString *  xml,
params_t *  data,
const char *  condition 
)
static

Send condition data for an alert.

Parameters
[in]xmlXML.
[out]dataData.
[out]conditionCondition.

Definition at line 5472 of file gsad_gmp.c.

5474 {
5475  if (data)
5476  {
5477  params_iterator_t iter;
5478  char *name;
5479  param_t *param;
5480 
5481  params_iterator_init (&iter, data);
5482  while (params_iterator_next (&iter, &name, &param))
5483  {
5484  if (strcmp (condition, "Filter count at least") == 0)
5485  {
5486  if (strcmp (name, "at_least_count") == 0)
5487  xml_string_append (xml, "<data><name>count</name>%s</data>",
5488  param->value ? param->value : "");
5489  if (strcmp (name, "at_least_filter_id") == 0)
5490  xml_string_append (xml, "<data><name>filter_id</name>%s</data>",
5491  param->value ? param->value : "");
5492  }
5493  else if (strcmp (condition, "Filter count changed") == 0)
5494  {
5495  if (strcmp (name, "count") == 0
5496  || strcmp (name, "filter_id") == 0)
5497  xml_string_append (xml, "<data><name>%s</name>%s</data>", name,
5498  param->value ? param->value : "");
5499  else if (strcmp (name, "filter_direction") == 0)
5500  xml_string_append (xml, "<data><name>direction</name>%s</data>",
5501  param->value ? param->value : "");
5502  }
5503  else if ((strcmp (condition, "Severity at least") == 0
5504  && strcmp (name, "severity") == 0)
5505  || (strcmp (condition, "Severity changed") == 0
5506  && strcmp (name, "direction") == 0))
5507  xml_string_append (xml, "<data><name>%s</name>%s</data>", name,
5508  param->value ? param->value : "");
5509  }
5510  }
5511 }
gchar * value
Definition: gsad_params.h:40
#define params_iterator_t
Definition: gsad_params.h:94
Request parameter.
Definition: gsad_params.h:38
gboolean params_iterator_next(params_iterator_t *iterator, char **name, param_t **param)
Increment a params iterator.
Definition: gsad_base.c:394
#define params_iterator_init
Definition: gsad_params.h:96

References params_iterator_init, params_iterator_next(), params_iterator_t, and param::value.

Referenced by create_alert_gmp(), and save_alert_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ append_alert_event_data()

static void append_alert_event_data ( GString *  xml,
params_t *  data,
const char *  event 
)
static

Send event data for an alert.

Parameters
[in]xmlXML.
[out]dataData.
[out]eventEvent.
Returns
0 on success, -1 on error.

Definition at line 5444 of file gsad_gmp.c.

5445 {
5446  if (data)
5447  {
5448  params_iterator_t iter;
5449  char *name;
5450  param_t *param;
5451 
5452  params_iterator_init (&iter, data);
5453  while (params_iterator_next (&iter, &name, &param))
5455  && str_equal (name, "status"))
5456  || ((str_equal (event, EVENT_TYPE_NEW_SECINFO)
5458  && str_equal (name, "secinfo_type")))
5459  xml_string_append (xml, "<data><name>%s</name>%s</data>", name,
5460  param->value ? param->value : "");
5461  }
5462 }
gchar * value
Definition: gsad_params.h:40
#define EVENT_TYPE_UPDATED_SECINFO
Definition: gsad_gmp.c:5429
gboolean str_equal(const gchar *str1, const gchar *str2)
Check if two strings are equal.
Definition: utils.c:35
#define params_iterator_t
Definition: gsad_params.h:94
#define EVENT_TYPE_NEW_SECINFO
Definition: gsad_gmp.c:5428
Request parameter.
Definition: gsad_params.h:38
gboolean params_iterator_next(params_iterator_t *iterator, char **name, param_t **param)
Increment a params iterator.
Definition: gsad_base.c:394
#define params_iterator_init
Definition: gsad_params.h:96
#define EVENT_TYPE_TASK_RUN_STATUS_CHANGED
Definition: gsad_gmp.c:5430

References EVENT_TYPE_NEW_SECINFO, EVENT_TYPE_TASK_RUN_STATUS_CHANGED, EVENT_TYPE_UPDATED_SECINFO, params_iterator_init, params_iterator_next(), params_iterator_t, str_equal(), and param::value.

Referenced by create_alert_gmp(), and save_alert_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ append_alert_method_data()

static void append_alert_method_data ( GString *  xml,
params_t *  data,
const char *  method,
params_t *  report_formats 
)
static

Send method data for an alert.

Parameters
[in]xmlCommand XML to append to.
[in]dataAlert method data params.
[in]methodName of the Alert method.
[in]report_formatsReport formats to use if multiple are supported.

Definition at line 5522 of file gsad_gmp.c.

5524 {
5525  params_iterator_t iter;
5526  char *name;
5527  param_t *param;
5528  int notice;
5529 
5530  if (data == NULL)
5531  return;
5532 
5533  /* Add report formats for methods that support multiple */
5534  if (strcmp (method, "Alemba vFire") == 0)
5535  {
5536  g_string_append (xml, "<data><name>report_formats</name>");
5537 
5538  if (report_formats && g_hash_table_size (report_formats))
5539  {
5540  int report_formats_count = g_hash_table_size (report_formats);
5541  int index;
5542  params_iterator_init (&iter, report_formats);
5543 
5544  for (index = 1; index <= report_formats_count; index++)
5545  {
5546  gchar *index_str = g_strdup_printf ("%d", index);
5547  const char *value;
5548  value = params_value (report_formats, index_str);
5549 
5550  if (index > 1)
5551  xml_string_append (xml, ", %s", value);
5552  else
5553  xml_string_append (xml, "%s", value);
5554 
5555  g_free (index_str);
5556  }
5557  }
5558  g_string_append (xml, "</data>");
5559  }
5560 
5561  /* Add single-value method data items */
5562  params_iterator_init (&iter, data);
5563  /* Used to check email notice type before sending report formats values */
5564  notice = 1;
5565  while (params_iterator_next (&iter, &name, &param))
5566  if (strcmp (name, "notice") == 0)
5567  {
5568  notice = atoi (param->value);
5569  break;
5570  }
5571 
5572  if (strcmp (method, "Sourcefire Connector"))
5573  {
5574  params_iterator_init (&iter, data);
5575 
5576  while (params_iterator_next (&iter, &name, &param))
5577  if ((strcmp (method, "HTTP Get") == 0 && strcmp (name, "URL") == 0)
5578  || (strcmp (method, "Send") == 0
5579  && (strcmp (name, "send_host") == 0
5580  || strcmp (name, "send_port") == 0
5581  || strcmp (name, "send_report_format") == 0))
5582  || (strcmp (method, "SCP") == 0
5583  && (strcmp (name, "scp_credential") == 0
5584  || strcmp (name, "scp_host") == 0
5585  || strcmp (name, "scp_known_hosts") == 0
5586  || strcmp (name, "scp_path") == 0
5587  || strcmp (name, "scp_report_format") == 0))
5588  || (strcmp (method, "SMB") == 0
5589  && (strcmp (name, "smb_credential") == 0
5590  || strcmp (name, "smb_file_path") == 0
5591  || strcmp (name, "smb_report_format") == 0
5592  || strcmp (name, "smb_share_path") == 0))
5593  || (strcmp (method, "SNMP") == 0
5594  && (strcmp (name, "snmp_community") == 0
5595  || strcmp (name, "snmp_agent") == 0
5596  || strcmp (name, "snmp_message") == 0))
5597  || (strcmp (method, "TippingPoint SMS") == 0
5598  && (strcmp (name, "tp_sms_credential") == 0
5599  || strcmp (name, "tp_sms_hostname") == 0
5600  || strcmp (name, "tp_sms_tls_certificate") == 0
5601  || strcmp (name, "tp_sms_tls_workaround") == 0))
5602  || (strcmp (method, "verinice Connector") == 0
5603  && (strcmp (name, "verinice_server_credential") == 0
5604  || strcmp (name, "verinice_server_url") == 0
5605  || strcmp (name, "verinice_server_report_format") == 0))
5606  || (strcmp (method, "Alemba vFire") == 0
5607  && (strcmp (name, "vfire_base_url") == 0
5608  || strcmp (name, "vfire_call_description") == 0
5609  || strcmp (name, "vfire_call_impact_name") == 0
5610  || strcmp (name, "vfire_call_partition_name") == 0
5611  || strcmp (name, "vfire_call_template_name") == 0
5612  || strcmp (name, "vfire_call_type_name") == 0
5613  || strcmp (name, "vfire_call_urgency_name") == 0
5614  || strcmp (name, "vfire_client_id") == 0
5615  || strcmp (name, "vfire_credential") == 0
5616  || strcmp (name, "vfire_session_type") == 0))
5617  || (strcmp (method, "Email") == 0
5618  && (strcmp (name, "to_address") == 0
5619  || strcmp (name, "from_address") == 0
5620  || strcmp (name, "subject") == 0
5621  || strcmp (name, "notice") == 0
5622  || (strcmp (name, "notice_report_format") == 0
5623  && notice == 0)
5624  || (strcmp (name, "notice_attach_format") == 0
5625  && notice == 2)
5626  || (str_equal (name, "recipient_credential")
5627  && !str_equal (param->value, "0"))))
5628  || (strcmp (method, "Syslog") == 0
5629  && strcmp (name, "submethod") == 0)
5630  || (strcmp (method, "Start Task") == 0
5631  && strcmp (name, "start_task_task") == 0)
5632  || strcmp (name, "details_url") == 0
5633  || strcmp (name, "delta_type") == 0
5634  || strcmp (name, "delta_report_id") == 0
5635  || strcmp (name, "composer_include_notes") == 0
5636  || strcmp (name, "composer_include_overrides") == 0)
5637  xml_string_append (xml, "<data><name>%s</name>%s</data>", name,
5638  param->value ? param->value : "");
5639  else if (strcmp (method, "Email") == 0 && notice == 0
5640  && strcmp (name, "message") == 0)
5641  xml_string_append (xml, "<data><name>message</name>%s</data>",
5642  param->value ? param->value : "");
5643  else if (strcmp (method, "Email") == 0 && notice == 2
5644  && strcmp (name, "message_attach") == 0)
5645  xml_string_append (xml, "<data><name>message</name>%s</data>",
5646  param->value ? param->value : "");
5647 
5648  return;
5649  }
5650 
5651  params_iterator_init (&iter, data);
5652  while (params_iterator_next (&iter, &name, &param))
5653  if (strcmp (name, "pkcs12"))
5654  {
5655  if (strcmp (name, "defense_center_ip") == 0
5656  || strcmp (name, "defense_center_port") == 0
5657  || (strcmp (name, "pkcs12_credential") == 0
5658  && !str_equal (param->value, "0")))
5659  xml_string_append (xml, "<data><name>%s</name>%s</data>", name,
5660  param->value ? param->value : "");
5661  }
5662  else
5663  {
5664  gchar *base64;
5665 
5666  /* Special case the pkcs12 file, which is binary. */
5667 
5668  base64 =
5669  (param->value && param->value_size)
5670  ? g_base64_encode ((guchar *) param->value, param->value_size)
5671  : g_strdup ("");
5672  xml_string_append (xml, "<data><name>%s</name>%s</data>", name, base64);
5673  g_free (base64);
5674  }
5675 }
gchar * value
Definition: gsad_params.h:40
gboolean str_equal(const gchar *str1, const gchar *str2)
Check if two strings are equal.
Definition: utils.c:35
#define params_iterator_t
Definition: gsad_params.h:94
int value_size
Definition: gsad_params.h:46
Request parameter.
Definition: gsad_params.h:38
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
gboolean params_iterator_next(params_iterator_t *iterator, char **name, param_t **param)
Increment a params iterator.
Definition: gsad_base.c:394
#define params_iterator_init
Definition: gsad_params.h:96

References params_iterator_init, params_iterator_next(), params_iterator_t, params_value(), str_equal(), param::value, and param::value_size.

Referenced by create_alert_gmp(), and save_alert_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ auth_settings_gmp()

char* auth_settings_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Definition at line 17238 of file gsad_gmp.c.

17240 {
17241  GString *xml;
17242  gchar *buf;
17243  const char *name;
17244 
17245  name = params_value (params, "name");
17246 
17247  CHECK_VARIABLE_INVALID (name, "Auth settings");
17248 
17249  xml = g_string_new ("");
17250  buf = g_markup_printf_escaped ("<auth_settings name=\"%s\">", name);
17251  g_string_append (xml, buf);
17252  g_free (buf);
17253 
17254  if (command_enabled (credentials, "DESCRIBE_AUTH"))
17255  {
17256  gchar *response = NULL;
17257  entity_t entity = NULL;
17258 
17259  switch (gmp (connection, credentials, &response, &entity, response_data,
17260  "<describe_auth/>"))
17261  {
17262  case 0:
17263  case -1:
17264  break;
17265  case 1:
17266  cmd_response_data_set_status_code (response_data,
17267  MHD_HTTP_INTERNAL_SERVER_ERROR);
17268  return gsad_message (
17269  credentials, "Internal error", __FUNCTION__, __LINE__,
17270  "An internal error occurred getting the auth list. "
17271  "Diagnostics: Failure to send command to manager daemon.",
17272  response_data);
17273  case 2:
17274  cmd_response_data_set_status_code (response_data,
17275  MHD_HTTP_INTERNAL_SERVER_ERROR);
17276  return gsad_message (
17277  credentials, "Internal error", __FUNCTION__, __LINE__,
17278  "An internal error occurred getting the auth list. "
17279  "Diagnostics: Failure to receive response from manager daemon.",
17280  response_data);
17281  default:
17282  cmd_response_data_set_status_code (response_data,
17283  MHD_HTTP_INTERNAL_SERVER_ERROR);
17284  return gsad_message (
17285  credentials, "Internal error", __FUNCTION__, __LINE__,
17286  "An internal error occurred getting the auth list. "
17287  "Diagnostics: Internal Error.",
17288  response_data);
17289  }
17290 
17291  g_string_append (xml, response);
17292  free_entity (entity);
17293  g_free (response);
17294  }
17295 
17296  g_string_append (xml, "</auth_settings>");
17297 
17298  return envelope_gmp (connection, credentials, params,
17299  g_string_free (xml, FALSE), response_data);
17300 }
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
int command_enabled(credentials_t *credentials, const gchar *name)
Init the GSA GMP library.
Definition: gsad_gmp.c:352
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
static char * envelope_gmp(gvm_connection_t *connection, credentials_t *credentials, params_t *params, gchar *xml, cmd_response_data_t *response_data)
Wrap some XML in an envelope.
Definition: gsad_gmp.c:443

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), command_enabled(), envelope_gmp(), gmp(), gsad_message(), and params_value().

Here is the call graph for this function:

◆ authenticate_gmp()

int authenticate_gmp ( const gchar *  username,
const gchar *  password,
gchar **  role,
gchar **  timezone,
gchar **  severity,
gchar **  capabilities,
gchar **  language,
gchar **  pw_warning 
)

Check authentication credentials.

Parameters
[in]usernameUsername.
[in]passwordPassword.
[out]roleRole.
[out]timezoneTimezone.
[out]severitySeverity class.
[out]capabilitiesCapabilities of manager.
[out]languageUser Interface Language, or NULL.
[out]pw_warningPassword warning message, NULL if password is OK.
Returns
0 if valid, 1 failed, 2 manager down, -1 error.

Definition at line 19273 of file gsad_gmp.c.

19276 {
19277  gvm_connection_t connection;
19278  int auth;
19279  gmp_authenticate_info_opts_t auth_opts;
19280 
19281  if (gvm_connection_open (&connection, manager_address, manager_port))
19282  {
19283  g_debug ("%s failed to acquire socket!\n", __FUNCTION__);
19284  return 2;
19285  }
19286 
19287  auth_opts = gmp_authenticate_info_opts_defaults;
19288  auth_opts.username = username;
19289  auth_opts.password = password;
19290  auth_opts.role = role;
19291  auth_opts.severity = severity;
19292  auth_opts.timezone = timezone;
19293  auth_opts.pw_warning = pw_warning;
19294 
19295  auth = gmp_authenticate_info_ext_c (&connection, auth_opts);
19296  if (auth == 0)
19297  {
19298  entity_t entity;
19299  const char *status;
19300  char first;
19301  gchar *response;
19302  int ret;
19303 
19304  /* Get language setting. */
19305 
19306  ret = setting_get_value (
19307  &connection, "6765549a-934e-11e3-b358-406186ea4fc5", language, NULL);
19308 
19309  switch (ret)
19310  {
19311  case 0:
19312  break;
19313  case 1:
19314  case 2:
19315  gvm_connection_close (&connection);
19316  return 2;
19317  default:
19318  gvm_connection_close (&connection);
19319  return -1;
19320  }
19321 
19322  /* Request help. */
19323 
19324  ret = gvm_connection_sendf (&connection,
19325  "<help format=\"XML\" type=\"brief\"/>");
19326  if (ret)
19327  {
19328  gvm_connection_close (&connection);
19329  return 2;
19330  }
19331 
19332  /* Read the response. */
19333 
19334  entity = NULL;
19335  if (read_entity_and_text_c (&connection, &entity, &response))
19336  {
19337  gvm_connection_close (&connection);
19338  return 2;
19339  }
19340 
19341  /* Check the response. */
19342 
19343  status = entity_attribute (entity, "status");
19344  if (status == NULL || strlen (status) == 0)
19345  {
19346  g_free (response);
19347  free_entity (entity);
19348  return -1;
19349  }
19350  first = status[0];
19351  free_entity (entity);
19352  if (first == '2')
19353  {
19354  *capabilities = response;
19355  }
19356  else
19357  {
19358  gvm_connection_close (&connection);
19359  g_free (response);
19360  return -1;
19361  }
19362 
19363  gvm_connection_close (&connection);
19364  return 0;
19365  }
19366  else
19367  {
19368  gvm_connection_close (&connection);
19369  return 1;
19370  }
19371 }
static int setting_get_value(gvm_connection_t *connection, const char *setting_id, gchar **value, cmd_response_data_t *response_data)
Get a setting by UUID for the current user of an GMP connection.
Definition: gsad_gmp.c:888
int manager_port
The port the manager is on.
Definition: gsad_gmp.c:140
int gvm_connection_open(gvm_connection_t *connection, const gchar *address, int port)
Connect to an address.
Definition: gsad_gmp.c:19235
gchar * manager_address
The address the manager is on.
Definition: gsad_gmp.c:135

References gvm_connection_open(), manager_address, manager_port, and setting_get_value().

Referenced by login().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bulk_delete_gmp()

char* bulk_delete_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Delete multiple resources, get next page, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 18260 of file gsad_gmp.c.

18262 {
18263  const char *type;
18264  GString *commands_xml;
18265  params_t *selected_ids;
18266  params_iterator_t iter;
18267  param_t *param;
18268  gchar *param_name;
18269  gchar *html, *response;
18270  entity_t entity;
18271  gchar *extra_attribs;
18272 
18273  type = params_value (params, "resource_type");
18274  if (type == NULL)
18275  {
18276  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
18277  return gsad_message (
18278  credentials, "Internal error", __FUNCTION__, __LINE__,
18279  "An internal error occurred while deleting resources. "
18280  "The resources were not deleted. "
18281  "Diagnostics: Required parameter 'resource_type' was NULL.",
18282  response_data);
18283  }
18284 
18285  /* Extra attributes */
18286  extra_attribs = NULL;
18287 
18288  /* Inheritor of user's resource */
18289  if (strcmp (type, "user") == 0)
18290  {
18291  const char *inheritor_id;
18292  inheritor_id = params_value (params, "inheritor_id");
18293  if (inheritor_id)
18294  extra_attribs = g_strdup_printf ("inheritor_id=\"%s\"", inheritor_id);
18295  }
18296 
18297  commands_xml = g_string_new ("<commands>");
18298 
18299  selected_ids = params_values (params, "bulk_selected:");
18300  if (selected_ids)
18301  {
18302  params_iterator_init (&iter, selected_ids);
18303  while (params_iterator_next (&iter, &param_name, &param))
18304  {
18305  xml_string_append (commands_xml,
18306  "<delete_%s %s_id=\"%s\" ultimate=\"0\"", type,
18307  type, param_name);
18308  if (extra_attribs)
18309  g_string_append_printf (commands_xml, " %s/>", extra_attribs);
18310  else
18311  g_string_append (commands_xml, "/>");
18312  }
18313  }
18314 
18315  g_string_append (commands_xml, "</commands>");
18316 
18317  /* Delete the resources and get all resources. */
18318 
18319  if (gvm_connection_sendf_xml (connection, commands_xml->str) == -1)
18320  {
18321  g_string_free (commands_xml, TRUE);
18322  cmd_response_data_set_status_code (response_data,
18323  MHD_HTTP_INTERNAL_SERVER_ERROR);
18324  return gsad_message (
18325  credentials, "Internal error", __FUNCTION__, __LINE__,
18326  "An internal error occurred while deleting resources. "
18327  "The resources were not deleted. "
18328  "Diagnostics: Failure to send command to manager daemon.",
18329  response_data);
18330  }
18331  g_string_free (commands_xml, TRUE);
18332 
18333  entity = NULL;
18334  if (read_entity_and_text_c (connection, &entity, &response))
18335  {
18336  cmd_response_data_set_status_code (response_data,
18337  MHD_HTTP_INTERNAL_SERVER_ERROR);
18338  return gsad_message (
18339  credentials, "Internal error", __FUNCTION__, __LINE__,
18340  "An internal error occurred while deleting resources. "
18341  "It is unclear whether the resources have been deleted or not. "
18342  "Diagnostics: Failure to read response from manager daemon.",
18343  response_data);
18344  }
18345 
18346  /* Cleanup, and return transformed XML. */
18347  html = response_from_entity (connection, credentials, params, entity,
18348  "Bulk Delete", response_data);
18349  g_free (response);
18350  free_entity (entity);
18351 
18352  return html;
18353 }
params_t * params_values(params_t *params, const char *name)
Get values of param.
Definition: gsad_base.c:287
Structure of credential related information.
#define params_iterator_t
Definition: gsad_params.h:94
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
Request parameter.
Definition: gsad_params.h:38
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
gboolean params_iterator_next(params_iterator_t *iterator, char **name, param_t **param)
Increment a params iterator.
Definition: gsad_base.c:394
#define params_iterator_init
Definition: gsad_params.h:96
#define params_t
Definition: gsad_params.h:31
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References cmd_response_data_set_status_code(), gsad_message(), params_iterator_init, params_iterator_next(), params_iterator_t, params_t, params_value(), params_values(), and response_from_entity().

Here is the call graph for this function:

◆ bulk_export_gmp()

char* bulk_export_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export multiple resources.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 18366 of file gsad_gmp.c.

18368 {
18369  const gchar *type, *filter, *bulk_select;
18370  gchar *param_name;
18371  GString *bulk_string;
18372  params_t *selected_ids;
18373  params_iterator_t iter;
18374  param_t *param;
18375 
18376  type = params_value (params, "resource_type");
18377  filter = params_value (params, "filter");
18378  bulk_select = params_value (params, "bulk_select");
18379 
18380  CHECK_VARIABLE_INVALID (type, "Bulk Export")
18381  CHECK_VARIABLE_INVALID (bulk_select, "Bulk Export")
18382 
18383  if (bulk_select && str_equal (bulk_select, "1"))
18384  {
18385  bulk_string = g_string_new ("first=1 rows=-1 uuid=");
18386 
18387  selected_ids = params_values (params, "bulk_selected:");
18388  if (selected_ids)
18389  {
18390  params_iterator_init (&iter, selected_ids);
18391  while (params_iterator_next (&iter, &param_name, &param))
18392  {
18393  xml_string_append (bulk_string, " uuid=%s", param_name);
18394  }
18395  }
18396  }
18397  else
18398  {
18399  bulk_string = g_string_new (filter ?: "");
18400  }
18401 
18402  params_add (params, "filter", g_string_free (bulk_string, FALSE));
18403 
18404  return export_many (connection, type, credentials, params, response_data);
18405 }
params_t * params_values(params_t *params, const char *name)
Get values of param.
Definition: gsad_base.c:287
Structure of credential related information.
gboolean str_equal(const gchar *str1, const gchar *str2)
Check if two strings are equal.
Definition: utils.c:35
#define params_iterator_t
Definition: gsad_params.h:94
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
static char * export_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a list of resources.
Definition: gsad_gmp.c:1738
Request parameter.
Definition: gsad_params.h:38
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
gboolean params_iterator_next(params_iterator_t *iterator, char **name, param_t **param)
Increment a params iterator.
Definition: gsad_base.c:394
#define params_iterator_init
Definition: gsad_params.h:96
#define params_t
Definition: gsad_params.h:31
param_t * params_add(params_t *params, const char *name, const char *value)
Add a param.
Definition: gsad_base.c:318

References CHECK_VARIABLE_INVALID, export_many(), params_add(), params_iterator_init, params_iterator_next(), params_iterator_t, params_t, params_value(), params_values(), and str_equal().

Here is the call graph for this function:

◆ check_modify_config()

static char* check_modify_config ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  next,
const char *  fail_next,
int *  success,
cmd_response_data_t *  response_data 
)
static

Check a modify_config response.

Parameters
[in]connectionConnection with manager.
[in]credentialsCredentials of user issuing the action.
[in]paramsHTTP request parameters.
[in]nextNext page command on success.
[in]fail_nextNext page command on failure.
[out]successWhether the command returned a success response.
[out]response_dataExtra data return for the HTTP response.
Returns
Error message on failure, NULL on success.
Todo:
This would be much easier with real error codes.

Definition at line 570 of file gsad_gmp.c.

573 {
574  entity_t entity;
575  gchar *response;
576  const char *status_text;
577 
578  if (success)
579  *success = 0;
580 
583  /* Read the response. */
584 
585  if (read_entity_c (connection, &entity))
586  {
587  cmd_response_data_set_status_code (response_data,
588  MHD_HTTP_INTERNAL_SERVER_ERROR);
589  return gsad_message (
590  credentials, "Internal error", __FUNCTION__, __LINE__,
591  "An internal error occurred while saving a config. "
592  "It is unclear whether the entire config has been saved. "
593  "Diagnostics: Failure to read command to manager daemon.",
594  response_data);
595  }
596 
597  /* Check the response. */
598 
599  status_text = entity_attribute (entity, "status_text");
600  if (status_text == NULL)
601  {
602  free_entity (entity);
603  cmd_response_data_set_status_code (response_data,
604  MHD_HTTP_INTERNAL_SERVER_ERROR);
605  return gsad_message (
606  credentials, "Internal error", __FUNCTION__, __LINE__,
607  "An internal error occurred while saving a config. "
608  "It is unclear whether the entire config has been saved. "
609  "Diagnostics: Failure to parse status_text from response.",
610  response_data);
611  }
612 
613  if (str_equal (status_text, "Config is in use"))
614  {
615  const char *message = "The config is now in use by a task,"
616  " so only name and comment can be modified.";
617 
618  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
619  response = action_result (connection, credentials, params, response_data,
620  "Save Config", message, NULL, NULL);
621 
622  free_entity (entity);
623  return response;
624  }
625  else if (str_equal (status_text, "MODIFY_CONFIG name must be unique"))
626  {
627  const char *message = "A config with the given name exists already.";
628 
629  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
630  response = action_result (connection, credentials, params, response_data,
631  "Save Config", message, NULL, NULL);
632 
633  free_entity (entity);
634  return response;
635  }
636  else if (success && gmp_success (entity))
637  {
638  *success = 1;
639  }
640 
641  response = response_from_entity (connection, credentials, params, entity,
642  "Save Config", response_data);
643  free_entity (entity);
644 
645  return response;
646 }
static int gmp_success(entity_t entity)
Check whether an GMP command failed.
Definition: gsad_gmp.c:656
Structure of credential related information.
gboolean str_equal(const gchar *str1, const gchar *str2)
Check if two strings are equal.
Definition: utils.c:35
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
static gchar * action_result(gvm_connection_t *, credentials_t *, params_t *, cmd_response_data_t *, const char *action, const char *message, const char *details, const char *id)
Generate a enveloped GMP XML containing an action result.
Definition: gsad_gmp.c:965
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References action_result(), cmd_response_data_set_status_code(), gmp_success(), gsad_message(), response_from_entity(), and str_equal().

Referenced by save_config_family_gmp(), save_config_gmp(), save_config_nvt_gmp(), and save_osp_prefs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clone_gmp()

char* clone_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Clone a resource, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 6868 of file gsad_gmp.c.

6870 {
6871  gchar *html, *response;
6872  const char *id, *type, *alterable;
6873  entity_t entity;
6874 
6875  id = params_value (params, "id");
6876  type = params_value (params, "resource_type");
6877  alterable = params_value (params, "alterable");
6878 
6879  CHECK_VARIABLE_INVALID (id, "Clone");
6880  CHECK_VARIABLE_INVALID (type, "Clone");
6881 
6882  /* Clone the resource. */
6883 
6884  if (alterable && strcmp (alterable, "0"))
6885  {
6886  if (gvm_connection_sendf (connection,
6887  "<create_%s>"
6888  "<copy>%s</copy>"
6889  "<alterable>1</alterable>"
6890  "</create_%s>",
6891  type, id, type)
6892  == -1)
6893  {
6894  cmd_response_data_set_status_code (response_data,
6895  MHD_HTTP_INTERNAL_SERVER_ERROR);
6896  return gsad_message (
6897  credentials, "Internal error", __FUNCTION__, __LINE__,
6898  "An internal error occurred while cloning a resource. "
6899  "The resource was not cloned. "
6900  "Diagnostics: Failure to send command to manager daemon.",
6901  response_data);
6902  }
6903  }
6904  else if (gvm_connection_sendf (connection,
6905  "<create_%s>"
6906  "<copy>%s</copy>"
6907  "</create_%s>",
6908  type, id, type)
6909  == -1)
6910  {
6911  cmd_response_data_set_status_code (response_data,
6912  MHD_HTTP_INTERNAL_SERVER_ERROR);
6913  return gsad_message (
6914  credentials, "Internal error", __FUNCTION__, __LINE__,
6915  "An internal error occurred while cloning a resource. "
6916  "The resource was not cloned. "
6917  "Diagnostics: Failure to send command to manager daemon.",
6918  response_data);
6919  }
6920 
6921  entity = NULL;
6922  if (read_entity_and_text_c (connection, &entity, &response))
6923  {
6924  cmd_response_data_set_status_code (response_data,
6925  MHD_HTTP_INTERNAL_SERVER_ERROR);
6926  return gsad_message (
6927  credentials, "Internal error", __FUNCTION__, __LINE__,
6928  "An internal error occurred while cloning a resource. "
6929  "It is unclear whether the resource has been cloned or not. "
6930  "Diagnostics: Failure to read response from manager daemon.",
6931  response_data);
6932  }
6933 
6934  /* Cleanup, and return next page. */
6935  html = response_from_entity (connection, credentials, params, entity, "Clone",
6936  response_data);
6937 
6938  free_entity (entity);
6939  g_free (response);
6940 
6941  return html;
6942 }
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gsad_message(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ command_enabled()

int command_enabled ( credentials_t *  credentials,
const gchar *  name 
)

Init the GSA GMP library.

Parameters
[in]credentialsCredentials.
[in]nameCommand name.

Definition at line 352 of file gsad_gmp.c.

353 {
354  /* TODO Hack. Fails if command named in summary of another command. */
355  user_t *user =
356  credentials_get_user (credentials); // TODO pass user_t directly
357  return strstr (user_get_capabilities (user), name) ? 1 : 0;
358 }
Structure of credential related information.
const gchar * user_get_capabilities(user_t *user)
Definition: gsad_user.c:181
User information structure, for sessions.
Definition: gsad_user.c:42
user_t * credentials_get_user(credentials_t *cred)

References credentials_get_user(), and user_get_capabilities().

Referenced by auth_settings_gmp(), edit_alert(), edit_role(), get_alert(), get_alerts(), get_info(), get_system_reports_gmp(), get_user(), and get_users().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ connect_unix()

int connect_unix ( const gchar *  path)

Connect to Greenbone Vulnerability Manager daemon.

Parameters
[in]pathPath to the Manager socket.
Returns
Socket, or -1 on error.

Definition at line 19196 of file gsad_gmp.c.

19197 {
19198  struct sockaddr_un address;
19199  int sock;
19200 
19201  /* Make socket. */
19202 
19203  sock = socket (AF_UNIX, SOCK_STREAM, 0);
19204  if (sock == -1)
19205  {
19206  g_warning ("Failed to create server socket");
19207  return -1;
19208  }
19209 
19210  /* Connect to server. */
19211 
19212  address.sun_family = AF_UNIX;
19213  strncpy (address.sun_path, path, sizeof (address.sun_path) - 1);
19214  if (connect (sock, (struct sockaddr *) &address, sizeof (address)) == -1)
19215  {
19216  g_warning ("Failed to connect to server at %s: %s", path,
19217  strerror (errno));
19218  close (sock);
19219  return -1;
19220  }
19221 
19222  return sock;
19223 }

Referenced by gvm_connection_open().

Here is the caller graph for this function:

◆ create_agent_gmp()

char* create_agent_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Create an agent, get all agents, envelope result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 4436 of file gsad_gmp.c.

4438 {
4439  entity_t entity;
4440  gchar *response, *html;
4441  const char *name, *comment, *installer, *installer_filename, *installer_sig;
4442  const char *howto_install, *howto_use;
4443  int installer_size, installer_sig_size, howto_install_size, howto_use_size;
4444  int ret;
4445  gchar *name_escaped, *comment_escaped;
4446  gchar *installer_64, *installer_sig_64, *howto_install_64, *howto_use_64;
4447  gchar *command;
4448 
4449  name = params_value (params, "name");
4450  comment = params_value (params, "comment");
4451  installer = params_value (params, "installer");
4452  installer_filename = params_filename (params, "installer");
4453  installer_size = params_value_size (params, "installer");
4454  installer_sig = params_value (params, "installer_sig");
4455  installer_sig_size = params_value_size (params, "installer_sig");
4456  howto_install = params_value (params, "howto_install");
4457  howto_install_size = params_value_size (params, "howto_install");
4458  howto_use = params_value (params, "howto_use");
4459  howto_use_size = params_value_size (params, "howto_use");
4460 
4461  CHECK_VARIABLE_INVALID (name, "Create Agent");
4462  CHECK_VARIABLE_INVALID (comment, "Create Agent");
4463 
4464  /* Create the agent. */
4465 
4466  installer_64 = (installer_size > 0)
4467  ? g_base64_encode ((guchar *) installer, installer_size)
4468  : g_strdup ("");
4469 
4470  installer_sig_64 =
4471  (installer_sig_size > 0)
4472  ? g_base64_encode ((guchar *) installer_sig, installer_sig_size)
4473  : g_strdup ("");
4474 
4475  howto_install_64 =
4476  (howto_install_size > 0)
4477  ? g_base64_encode ((guchar *) howto_install, howto_install_size)
4478  : g_strdup ("");
4479 
4480  howto_use_64 = (howto_use_size > 0)
4481  ? g_base64_encode ((guchar *) howto_use, howto_use_size)
4482  : g_strdup ("");
4483 
4484  name_escaped = name ? g_markup_escape_text (name, -1) : NULL;
4485  comment_escaped = comment ? g_markup_escape_text (comment, -1) : NULL;
4486 
4487  command = g_strdup_printf ("<create_agent>"
4488  "<name>%s</name>"
4489  "%s%s%s"
4490  "<installer>"
4491  "%s"
4492  "<signature>%s</signature>"
4493  "<filename>%s</filename>"
4494  "</installer>"
4495  "<howto_install>%s</howto_install>"
4496  "<howto_use>%s</howto_use>"
4497  "</create_agent>",
4498  name_escaped, comment_escaped ? "<comment>" : "",
4499  comment_escaped ? comment_escaped : "",
4500  comment_escaped ? "</comment>" : "", installer_64,
4501  installer_sig_64,
4502  installer_filename ? installer_filename : "",
4503  howto_install_64, howto_use_64);
4504 
4505  ret =
4506  gmp (connection, credentials, &response, &entity, response_data, command);
4507  g_free (command);
4508 
4509  g_free (installer_64);
4510  g_free (howto_install_64);
4511  g_free (howto_use_64);
4512  g_free (name_escaped);
4513  g_free (comment_escaped);
4514 
4515  switch (ret)
4516  {
4517  case 0:
4518  break;
4519  case -1:
4520  /* 'gmp' set response. */
4521  return response;
4522  case 1:
4523  cmd_response_data_set_status_code (response_data,
4524  MHD_HTTP_INTERNAL_SERVER_ERROR);
4525  return gsad_message (
4526  credentials, "Internal error", __FUNCTION__, __LINE__,
4527  "An internal error occurred while creating a new agent. "
4528  "No new agent was created. "
4529  "Diagnostics: Failure to send command to manager daemon.",
4530  response_data);
4531  case 2:
4532  cmd_response_data_set_status_code (response_data,
4533  MHD_HTTP_INTERNAL_SERVER_ERROR);
4534  return gsad_message (
4535  credentials, "Internal error", __FUNCTION__, __LINE__,
4536  "An internal error occurred while creating a new agent. "
4537  "It is unclear whether the agent has been created or not. "
4538  "Diagnostics: Failure to receive response from manager daemon.",
4539  response_data);
4540  default:
4541  cmd_response_data_set_status_code (response_data,
4542  MHD_HTTP_INTERNAL_SERVER_ERROR);
4543  return gsad_message (
4544  credentials, "Internal error", __FUNCTION__, __LINE__,
4545  "An internal error occurred while creating a new agent. "
4546  "It is unclear whether the agent has been created or not. "
4547  "Diagnostics: Internal Error.",
4548  response_data);
4549  }
4550 
4551  if (entity_attribute (entity, "id"))
4552  params_add (params, "agent_id", entity_attribute (entity, "id"));
4553  html = response_from_entity (connection, credentials, params, entity,
4554  "Create Agent", response_data);
4555  free_entity (entity);
4556  g_free (response);
4557  return html;
4558 }
int params_value_size(params_t *params, const char *name)
Get the size of the value of param.
Definition: gsad_base.c:237
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
const char * params_filename(params_t *params, const char *name)
Get filename of param.
Definition: gsad_base.c:271
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
param_t * params_add(params_t *params, const char *name, const char *value)
Add a param.
Definition: gsad_base.c:318

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmp(), gsad_message(), params_add(), params_filename(), params_value(), params_value_size(), and response_from_entity().

Here is the call graph for this function:

◆ create_alert_gmp()

char* create_alert_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Create an alert, get all alerts, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 5688 of file gsad_gmp.c.

5690 {
5691  int ret;
5692  gchar *html, *response;
5693  const char *name, *comment, *active, *condition, *event, *method, *filter_id;
5694  params_t *method_data, *event_data, *condition_data, *report_formats;
5695  entity_t entity;
5696  GString *xml;
5697 
5698  name = params_value (params, "name");
5699  comment = params_value (params, "comment");
5700  active = params_value (params, "active");
5701  condition = params_value (params, "condition");
5702  event = params_value (params, "event");
5703  method = params_value (params, "method");
5704  filter_id = params_value (params, "filter_id");
5705 
5706  CHECK_VARIABLE_INVALID (name, "Create Alert");
5707  CHECK_VARIABLE_INVALID (active, "Create Alert");
5708  CHECK_VARIABLE_INVALID (comment, "Create Alert");
5709  CHECK_VARIABLE_INVALID (condition, "Create Alert");
5710  CHECK_VARIABLE_INVALID (event, "Create Alert");
5711  CHECK_VARIABLE_INVALID (method, "Create Alert");
5712  CHECK_VARIABLE_INVALID (filter_id, "Create Alert");
5713 
5714  /* Create the alert. */
5715 
5716  method_data = params_values (params, "method_data:");
5717  event_data = params_values (params, "event_data:");
5718  condition_data = params_values (params, "condition_data:");
5719  report_formats = params_values (params, "report_format_ids:");
5720 
5721  xml = g_string_new ("");
5722 
5723  if (str_equal (event, EVENT_TYPE_NEW_SECINFO) && event_data)
5724  {
5725  params_iterator_t iter;
5726  char *name;
5727  param_t *param;
5728 
5729  params_iterator_init (&iter, event_data);
5730  while (params_iterator_next (&iter, &name, &param))
5731  if (str_equal (name, "feed_event") && param->value
5732  && str_equal (param->value, "updated"))
5733  {
5735  break;
5736  }
5737  }
5738 
5739  xml_string_append (xml,
5740  "<create_alert>"
5741  "<name>%s</name>"
5742  "<filter id=\"%s\"/>"
5743  "<active>%s</active>"
5744  "<comment>%s</comment>"
5745  "<event>%s",
5746  name, filter_id, active, comment ? comment : "", event);
5747 
5748  append_alert_event_data (xml, event_data, event);
5749 
5750  xml_string_append (xml,
5751  "</event>"
5752  "<method>%s",
5753  method);
5754 
5755  append_alert_method_data (xml, method_data, method, report_formats);
5756 
5757  xml_string_append (xml,
5758  "</method>"
5759  "<condition>%s",
5760  condition);
5761 
5762  append_alert_condition_data (xml, condition_data, condition);
5763 
5764  xml_string_append (xml, "</condition>"
5765  "</create_alert>");
5766 
5767  ret =
5768  gmp (connection, credentials, &response, &entity, response_data, xml->str);
5769  g_string_free (xml, TRUE);
5770  switch (ret)
5771  {
5772  case 0:
5773  case -1:
5774  break;
5775  case 1:
5776  cmd_response_data_set_status_code (response_data,
5777  MHD_HTTP_INTERNAL_SERVER_ERROR);
5778  return gsad_message (
5779  credentials, "Internal error", __FUNCTION__, __LINE__,
5780  "An internal error occurred while creating a new alert. "
5781  "No new alert was created. "
5782  "Diagnostics: Failure to send command to manager daemon.",
5783  response_data);
5784  case 2:
5785  cmd_response_data_set_status_code (response_data,
5786  MHD_HTTP_INTERNAL_SERVER_ERROR);
5787  return gsad_message (
5788  credentials, "Internal error", __FUNCTION__, __LINE__,
5789  "An internal error occurred while creating a new alert. "
5790  "It is unclear whether the alert has been created or not. "
5791  "Diagnostics: Failure to receive response from manager daemon.",
5792  response_data);
5793  default:
5794  cmd_response_data_set_status_code (response_data,
5795  MHD_HTTP_INTERNAL_SERVER_ERROR);
5796  return gsad_message (
5797  credentials, "Internal error", __FUNCTION__, __LINE__,
5798  "An internal error occurred while creating a new alert. "
5799  "It is unclear whether the alert has been created or not. "
5800  "Diagnostics: Internal Error.",
5801  response_data);
5802  }
5803 
5804  if (entity_attribute (entity, "id"))
5805  params_add (params, "alert_id", entity_attribute (entity, "id"));
5806  html = response_from_entity (connection, credentials, params, entity,
5807  "Create Alert", response_data);
5808  free_entity (entity);
5809  g_free (response);
5810  return html;
5811 }
params_t * params_values(params_t *params, const char *name)
Get values of param.
Definition: gsad_base.c:287
gchar * value
Definition: gsad_params.h:40
#define EVENT_TYPE_UPDATED_SECINFO
Definition: gsad_gmp.c:5429
Structure of credential related information.
gboolean str_equal(const gchar *str1, const gchar *str2)
Check if two strings are equal.
Definition: utils.c:35
#define params_iterator_t
Definition: gsad_params.h:94
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
static void append_alert_condition_data(GString *xml, params_t *data, const char *condition)
Send condition data for an alert.
Definition: gsad_gmp.c:5472
#define EVENT_TYPE_NEW_SECINFO
Definition: gsad_gmp.c:5428
static void append_alert_event_data(GString *xml, params_t *data, const char *event)
Send event data for an alert.
Definition: gsad_gmp.c:5444
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
Request parameter.
Definition: gsad_params.h:38
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
gboolean params_iterator_next(params_iterator_t *iterator, char **name, param_t **param)
Increment a params iterator.
Definition: gsad_base.c:394
#define params_iterator_init
Definition: gsad_params.h:96
#define params_t
Definition: gsad_params.h:31
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
static void append_alert_method_data(GString *xml, params_t *data, const char *method, params_t *report_formats)
Send method data for an alert.
Definition: gsad_gmp.c:5522
param_t * params_add(params_t *params, const char *name, const char *value)
Add a param.
Definition: gsad_base.c:318

References append_alert_condition_data(), append_alert_event_data(), append_alert_method_data(), CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), EVENT_TYPE_NEW_SECINFO, EVENT_TYPE_UPDATED_SECINFO, gmp(), gsad_message(), params_add(), params_iterator_init, params_iterator_next(), params_iterator_t, params_t, params_value(), params_values(), response_from_entity(), str_equal(), and param::value.

Here is the call graph for this function:

◆ create_asset_gmp()

char* create_asset_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Create an asset, get report, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 18674 of file gsad_gmp.c.

18676 {
18677  char *ret;
18678  gchar *response;
18679  const char *report_id, *filter;
18680  entity_t entity;
18681 
18682  report_id = params_value (params, "report_id");
18683  filter = params_value (params, "filter");
18684 
18685  CHECK_VARIABLE_INVALID (report_id, "Create Asset");
18686  CHECK_VARIABLE_INVALID (filter, "Create Asset");
18687 
18688  response = NULL;
18689  entity = NULL;
18690  switch (gmpf (connection, credentials, &response, &entity, response_data,
18691  "<create_asset>"
18692  "<report id=\"%s\">"
18693  "<filter><term>%s</term></filter>"
18694  "</report>"
18695  "</create_asset>",
18696  report_id, filter))
18697  {
18698  case 0:
18699  case -1:
18700  break;
18701  case 1:
18702  cmd_response_data_set_status_code (response_data,
18703  MHD_HTTP_INTERNAL_SERVER_ERROR);
18704  return gsad_message (
18705  credentials, "Internal error", __FUNCTION__, __LINE__,
18706  "An internal error occurred while creating an asset. "
18707  "No new asset was created. "
18708  "Diagnostics: Failure to send command to manager daemon.",
18709  response_data);
18710  case 2:
18711  cmd_response_data_set_status_code (response_data,
18712  MHD_HTTP_INTERNAL_SERVER_ERROR);
18713  return gsad_message (
18714  credentials, "Internal error", __FUNCTION__, __LINE__,
18715  "An internal error occurred while creating an asset. "
18716  "It is unclear whether the asset has been created or not. "
18717  "Diagnostics: Failure to receive response from manager daemon.",
18718  response_data);
18719  default:
18720  cmd_response_data_set_status_code (response_data,
18721  MHD_HTTP_INTERNAL_SERVER_ERROR);
18722  return gsad_message (
18723  credentials, "Internal error", __FUNCTION__, __LINE__,
18724  "An internal error occurred while creating an asset. "
18725  "It is unclear whether the asset has been created or not. "
18726  "Diagnostics: Internal Error.",
18727  response_data);
18728  }
18729 
18730  ret = response_from_entity (connection, credentials, params, entity,
18731  "Create Asset", response_data);
18732  free_entity (entity);
18733  g_free (response);
18734  return ret;
18735 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmpf(), gsad_message(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ create_config_gmp()

char* create_config_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Create config, get all configs, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 7884 of file gsad_gmp.c.

7886 {
7887  gchar *html, *response;
7888  const char *name, *comment, *base, *scanner = NULL;
7889  entity_t entity;
7890 
7891  name = params_value (params, "name");
7892  comment = params_value (params, "comment");
7893  base = params_value (params, "base");
7894 
7895  CHECK_VARIABLE_INVALID (name, "New Config");
7896  CHECK_VARIABLE_INVALID (comment, "New Config");
7897  CHECK_VARIABLE_INVALID (base, "New Config");
7898  if (str_equal (base, "0"))
7899  {
7900  scanner = params_value (params, "scanner_id");
7901  CHECK_VARIABLE_INVALID (scanner, "New Config");
7902  }
7903 
7904  /* Create the config. */
7905  switch (gmpf (connection, credentials, &response, &entity, response_data,
7906  "<create_config>"
7907  "<name>%s</name>"
7908  "<copy>%s</copy>"
7909  "<comment>%s</comment>"
7910  "<scanner>%s</scanner>"
7911  "</create_config>",
7912  name, base, comment, scanner ?: ""))
7913  {
7914  case 0:
7915  case -1:
7916  break;
7917  case 1:
7918  cmd_response_data_set_status_code (response_data,
7919  MHD_HTTP_INTERNAL_SERVER_ERROR);
7920  return gsad_message (
7921  credentials, "Internal error", __FUNCTION__, __LINE__,
7922  "An internal error occurred while creating a new config. "
7923  "No new config was created. "
7924  "Diagnostics: Failure to send command to manager daemon.",
7925  response_data);
7926  case 2:
7927  cmd_response_data_set_status_code (response_data,
7928  MHD_HTTP_INTERNAL_SERVER_ERROR);
7929  return gsad_message (
7930  credentials, "Internal error", __FUNCTION__, __LINE__,
7931  "An internal error occurred while creating a new config. "
7932  "It is unclear whether the config has been created or not. "
7933  "Diagnostics: Failure to receive response from manager daemon.",
7934  response_data);
7935  default:
7936  cmd_response_data_set_status_code (response_data,
7937  MHD_HTTP_INTERNAL_SERVER_ERROR);
7938  return gsad_message (
7939  credentials, "Internal error", __FUNCTION__, __LINE__,
7940  "An internal error occurred while creating a new config. "
7941  "It is unclear whether the config has been created or not. "
7942  "Diagnostics: Internal Error.",
7943  response_data);
7944  }
7945 
7946  if (entity_attribute (entity, "id"))
7947  params_add (params, "config_id", entity_attribute (entity, "id"));
7948  html = response_from_entity (connection, credentials, params, entity,
7949  "Create Config", response_data);
7950 
7951  free_entity (entity);
7952  g_free (response);
7953  return html;
7954 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
gboolean str_equal(const gchar *str1, const gchar *str2)
Check if two strings are equal.
Definition: utils.c:35
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
param_t * params_add(params_t *params, const char *name, const char *value)
Add a param.
Definition: gsad_base.c:318

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmpf(), gsad_message(), params_add(), params_value(), response_from_entity(), and str_equal().

Here is the call graph for this function:

◆ create_container_task_gmp()

char* create_container_task_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Create a container task, serve next page.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 2401 of file gsad_gmp.c.

2404 {
2405  entity_t entity;
2406  int ret;
2407  gchar *command, *html, *response;
2408  const char *name, *comment;
2409 
2410  name = params_value (params, "name");
2411  comment = params_value (params, "comment");
2412  CHECK_VARIABLE_INVALID (name, "Create Container Task");
2413  CHECK_VARIABLE_INVALID (comment, "Create Container Task");
2414 
2415  command = g_markup_printf_escaped ("<create_task>"
2416  "<target id=\"0\"/>"
2417  "<name>%s</name>"
2418  "<comment>%s</comment>"
2419  "</create_task>",
2420  name, comment);
2421  ret =
2422  gmp (connection, credentials, &response, &entity, response_data, command);
2423  g_free (command);
2424 
2425  switch (ret)
2426  {
2427  case 0:
2428  break;
2429  case -1:
2430  /* 'gmp' set response. */
2431  return response;
2432  case 1:
2433  cmd_response_data_set_status_code (response_data,
2434  MHD_HTTP_INTERNAL_SERVER_ERROR);
2435  return gsad_message (
2436  credentials, "Internal error", __FUNCTION__, __LINE__,
2437  "An internal error occurred while creating a container task. "
2438  "No task was created. "
2439  "Diagnostics: Failure to send command to manager daemon.",
2440  response_data);
2441  case 2:
2442  cmd_response_data_set_status_code (response_data,
2443  MHD_HTTP_INTERNAL_SERVER_ERROR);
2444  return gsad_message (
2445  credentials, "Internal error", __FUNCTION__, __LINE__,
2446  "An internal error occurred while creating a container task. "
2447  "It is unclear whether the task has been created or not. "
2448  "Diagnostics: Failure to receive response from manager daemon.",
2449  response_data);
2450  default:
2451  cmd_response_data_set_status_code (response_data,
2452  MHD_HTTP_INTERNAL_SERVER_ERROR);
2453  return gsad_message (
2454  credentials, "Internal error", __FUNCTION__, __LINE__,
2455  "An internal error occurred while creating a container task. "
2456  "It is unclear whether the task has been created or not. "
2457  "Diagnostics: Internal Error.",
2458  response_data);
2459  }
2460 
2461  if (entity_attribute (entity, "id"))
2462  params_add (params, "task_id", entity_attribute (entity, "id"));
2463  html = response_from_entity (connection, credentials, params, entity,
2464  "Create Container Task", response_data);
2465  free_entity (entity);
2466  g_free (response);
2467  return html;
2468 }
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
param_t * params_add(params_t *params, const char *name, const char *value)
Add a param.
Definition: gsad_base.c:318

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmp(), gsad_message(), params_add(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ create_credential_gmp()

char* create_credential_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Create a credential, get all credentials, envelope result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 3585 of file gsad_gmp.c.

3587 {
3588  int ret;
3589  gchar *html, *response;
3590  const char *name, *comment, *login, *type, *password, *passphrase;
3591  const char *private_key, *public_key, *certificate, *community;
3592  const char *privacy_password, *auth_algorithm, *privacy_algorithm;
3593  const char *autogenerate, *allow_insecure;
3594  entity_t entity;
3595 
3596  name = params_value (params, "name");
3597  comment = params_value (params, "comment");
3598  login = params_value (params, "credential_login");
3599  type = params_value (params, "credential_type");
3600  password = params_value (params, "lsc_password");
3601  passphrase = params_value (params, "passphrase");
3602  private_key = params_value (params, "private_key");
3603  public_key = params_value (params, "public_key");
3604  certificate = params_value (params, "certificate");
3605  community = params_value (params, "community");
3606  privacy_password = params_value (params, "privacy_password");
3607  auth_algorithm = params_value (params, "auth_algorithm");
3608  privacy_algorithm = params_value (params, "privacy_algorithm");
3609  allow_insecure = params_value (params, "allow_insecure");
3610  autogenerate = params_value (params, "autogenerate");
3611 
3612  CHECK_VARIABLE_INVALID (name, "Create Credential");
3613  CHECK_VARIABLE_INVALID (comment, "Create Credential");
3614  CHECK_VARIABLE_INVALID (type, "Create Credential");
3615  CHECK_VARIABLE_INVALID (allow_insecure, "Create Credential");
3616  CHECK_VARIABLE_INVALID (autogenerate, "Create Credential");
3617 
3618  if (str_equal (autogenerate, "1"))
3619  {
3620  if (str_equal (type, "cc"))
3621  {
3622  // Auto-generate types without username
3623  ret =
3624  gmpf (connection, credentials, &response, &entity, response_data,
3625  "<create_credential>"
3626  "<name>%s</name>"
3627  "<comment>%s</comment>"
3628  "<type>%s</type>"
3629  "<allow_insecure>%s</allow_insecure>"
3630  "</create_credential>",
3631  name, comment ? comment : "", type, allow_insecure);
3632  }
3633  else
3634  {
3635  // Auto-generate types with username
3636  CHECK_VARIABLE_INVALID (login, "Create Credential");
3637 
3638  ret =
3639  gmpf (connection, credentials, &response, &entity, response_data,
3640  "<create_credential>"
3641  "<name>%s</name>"
3642  "<comment>%s</comment>"
3643  "<type>%s</type>"
3644  "<login>%s</login>"
3645  "<allow_insecure>%s</allow_insecure>"
3646  "</create_credential>",
3647  name, comment ? comment : "", type, login, allow_insecure);
3648  }
3649  }
3650  else
3651  {
3652  if (str_equal (type, "up"))
3653  {
3654  CHECK_VARIABLE_INVALID (login, "Create Credential");
3655  CHECK_VARIABLE_INVALID (password, "Create Credential");
3656 
3657  ret =
3658  gmpf (connection, credentials, &response, &entity, response_data,
3659  "<create_credential>"
3660  "<name>%s</name>"
3661  "<comment>%s</comment>"
3662  "<type>%s</type>"
3663  "<login>%s</login>"
3664  "<password>%s</password>"
3665  "<allow_insecure>%s</allow_insecure>"
3666  "</create_credential>",
3667  name, comment ? comment : "", type, login ? login : "",
3668  password ? password : "", allow_insecure);
3669  }
3670  else if (str_equal (type, "usk"))
3671  {
3672  CHECK_VARIABLE_INVALID (login, "Create Credential");
3673  CHECK_VARIABLE_INVALID (passphrase, "Create Credential");
3674  CHECK_VARIABLE_INVALID (private_key, "Create Credential");
3675 
3676  ret =
3677  gmpf (connection, credentials, &response, &entity, response_data,
3678  "<create_credential>"
3679  "<name>%s</name>"
3680  "<comment>%s</comment>"
3681  "<type>%s</type>"
3682  "<login>%s</login>"
3683  "<key>"
3684  "<private>%s</private>"
3685  "<phrase>%s</phrase>"
3686  "</key>"
3687  "<allow_insecure>%s</allow_insecure>"
3688  "</create_credential>",
3689  name, comment ? comment : "", type, login ? login : "",
3690  private_key ? private_key : "", passphrase ? passphrase : "",
3691  allow_insecure);
3692  }
3693  else if (str_equal (type, "cc"))
3694  {
3695  CHECK_VARIABLE_INVALID (certificate, "Create Credential");
3696  CHECK_VARIABLE_INVALID (private_key, "Create Credential");
3697 
3698  ret = gmpf (
3699  connection, credentials, &response, &entity, response_data,
3700  "<create_credential>"
3701  "<name>%s</name>"
3702  "<comment>%s</comment>"
3703  "<type>%s</type>"
3704  "<certificate>%s</certificate>"
3705  "<key>"
3706  "<private>%s</private>"
3707  "</key>"
3708  "<allow_insecure>%s</allow_insecure>"
3709  "</create_credential>",
3710  name, comment ? comment : "", type, certificate ? certificate : "",
3711  private_key ? private_key : "", allow_insecure);
3712  }
3713  else if (str_equal (type, "snmp"))
3714  {
3715  CHECK_VARIABLE_INVALID (community, "Create Credential");
3716  CHECK_VARIABLE_INVALID (login, "Create Credential");
3717  CHECK_VARIABLE_INVALID (password, "Create Credential");
3718  CHECK_VARIABLE_INVALID (privacy_password, "Create Credential");
3719  CHECK_VARIABLE_INVALID (auth_algorithm, "Create Credential");
3720  CHECK_VARIABLE_INVALID (privacy_algorithm, "Create Credential");
3721 
3722  if (privacy_password && strcmp (privacy_password, ""))
3723  ret = gmpf (
3724  connection, credentials, &response, &entity, response_data,
3725  "<create_credential>"
3726  "<name>%s</name>"
3727  "<comment>%s</comment>"
3728  "<type>%s</type>"
3729  "<community>%s</community>"
3730  "<login>%s</login>"
3731  "<password>%s</password>"
3732  "<privacy>"
3733  "<password>%s</password>"
3734  "<algorithm>%s</algorithm>"
3735  "</privacy>"
3736  "<auth_algorithm>%s</auth_algorithm>"
3737  "<allow_insecure>%s</allow_insecure>"
3738  "</create_credential>",
3739  name, comment ? comment : "", type, community ? community : "",
3740  login ? login : "", password ? password : "",
3741  privacy_password ? privacy_password : "",
3742  privacy_algorithm ? privacy_algorithm : "",
3743  auth_algorithm ? auth_algorithm : "", allow_insecure);
3744  else
3745  ret = gmpf (
3746  connection, credentials, &response, &entity, response_data,
3747  "<create_credential>"
3748  "<name>%s</name>"
3749  "<comment>%s</comment>"
3750  "<type>%s</type>"
3751  "<community>%s</community>"
3752  "<login>%s</login>"
3753  "<password>%s</password>"
3754  "<auth_algorithm>%s</auth_algorithm>"
3755  "<allow_insecure>%s</allow_insecure>"
3756  "</create_credential>",
3757  name, comment ? comment : "", type, community ? community : "",
3758  login ? login : "", password ? password : "",
3759  auth_algorithm ? auth_algorithm : "", allow_insecure);
3760  }
3761  else if (str_equal (type, "pgp"))
3762  {
3763  CHECK_VARIABLE_INVALID (public_key, "Create Credential");
3764 
3765  ret = gmpf (
3766  connection, credentials, &response, &entity, response_data,
3767  "<create_credential>"
3768  "<name>%s</name>"
3769  "<comment>%s</comment>"
3770  "<type>%s</type>"
3771  "<key>"
3772  "<public>%s</public>"
3773  "</key>"
3774  "<allow_insecure>%s</allow_insecure>"
3775  "</create_credential>",
3776  name, comment ? comment : "", type, public_key, allow_insecure);
3777  }
3778  else if (str_equal (type, "smime"))
3779  {
3780  CHECK_VARIABLE_INVALID (certificate, "Create Credential");
3781 
3782  ret = gmpf (
3783  connection, credentials, &response, &entity, response_data,
3784  "<create_credential>"
3785  "<name>%s</name>"
3786  "<comment>%s</comment>"
3787  "<type>%s</type>"
3788  "<certificate>%s</certificate>"
3789  "<allow_insecure>%s</allow_insecure>"
3790  "</create_credential>",
3791  name, comment ? comment : "", type, certificate, allow_insecure);
3792  }
3793  else if (type && (strcmp (type, "pw") == 0))
3794  {
3795  CHECK_VARIABLE_INVALID (password, "Create Credential");
3796 
3797  ret =
3798  gmpf (connection, credentials, &response, &entity, response_data,
3799  "<create_credential>"
3800  "<name>%s</name>"
3801  "<comment>%s</comment>"
3802  "<type>%s</type>"
3803  "<password>%s</password>"
3804  "<allow_insecure>%s</allow_insecure>"
3805  "</create_credential>",
3806  name, comment ? comment : "", type, password ? password : "",
3807  allow_insecure);
3808  }
3809  else
3810  {
3811  cmd_response_data_set_status_code (response_data,
3812  MHD_HTTP_INTERNAL_SERVER_ERROR);
3813  return gsad_message (
3814  credentials, "Internal error", __FUNCTION__, __LINE__,
3815  "An internal error occurred while creating a new credential. "
3816  "The credential could not be created. "
3817  "Diagnostics: Unrecognized credential type.",
3818  response_data);
3819  }
3820  }
3821 
3822  /* Create the credential. */
3823  switch (ret)
3824  {
3825  case 0:
3826  case -1:
3827  break;
3828  case 1:
3829  cmd_response_data_set_status_code (response_data,
3830  MHD_HTTP_INTERNAL_SERVER_ERROR);
3831  return gsad_message (
3832  credentials, "Internal error", __FUNCTION__, __LINE__,
3833  "An internal error occurred while creating a new credential. "
3834  "It is unclear whether the credential has been created or not. "
3835  "Diagnostics: Failure to send command to manager daemon.",
3836  response_data);
3837  case 2:
3838  cmd_response_data_set_status_code (response_data,
3839  MHD_HTTP_INTERNAL_SERVER_ERROR);
3840  return gsad_message (
3841  credentials, "Internal error", __FUNCTION__, __LINE__,
3842  "An internal error occurred while creating a new credential. "
3843  "It is unclear whether the credential has been created or not. "
3844  "Diagnostics: Failure to receive response from manager daemon.",
3845  response_data);
3846  default:
3847  cmd_response_data_set_status_code (response_data,
3848  MHD_HTTP_INTERNAL_SERVER_ERROR);
3849  return gsad_message (
3850  credentials, "Internal error", __FUNCTION__, __LINE__,
3851  "An internal error occurred while creating a new credential. "
3852  "It is unclear whether the credential has been created or not. "
3853  "Diagnostics: Internal Error.",
3854  response_data);
3855  }
3856 
3857  if (entity_attribute (entity, "id"))
3858  params_add (params, "credential_id", entity_attribute (entity, "id"));
3859  html = response_from_entity (connection, credentials, params, entity,
3860  "Create Credential", response_data);
3861  free_entity (entity);
3862  g_free (response);
3863  return html;
3864 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
gboolean str_equal(const gchar *str1, const gchar *str2)
Check if two strings are equal.
Definition: utils.c:35
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
int login(http_connection_t *con, params_t *params, cmd_response_data_t *response_data, const char *client_address)
Login and create a session.
Definition: gsad_gmp.c:19384
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
param_t * params_add(params_t *params, const char *name, const char *value)
Add a param.
Definition: gsad_base.c:318

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmpf(), gsad_message(), login(), params_add(), params_value(), response_from_entity(), and str_equal().

Here is the call graph for this function:

◆ create_filter_gmp()

char* create_filter_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Create a filter, get all filters, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 16486 of file gsad_gmp.c.

16488 {
16489  gchar *html, *response;
16490  const char *name, *comment, *term, *type;
16491  entity_t entity;
16492 
16493  name = params_value (params, "name");
16494  comment = params_value (params, "comment");
16495  term = params_value (params, "term");
16496  type = params_value (params, "optional_resource_type");
16497 
16498  CHECK_VARIABLE_INVALID (name, "Create Filter");
16499  CHECK_VARIABLE_INVALID (comment, "Create Filter");
16500  CHECK_VARIABLE_INVALID (term, "Create Filter");
16501  CHECK_VARIABLE_INVALID (type, "Create Filter");
16502 
16503  switch (gmpf (connection, credentials, &response, &entity, response_data,
16504  "<create_filter>"
16505  "<name>%s</name>"
16506  "<comment>%s</comment>"
16507  "<term>%s</term>"
16508  "<type>%s</type>"
16509  "</create_filter>",
16510  name, comment, term, type))
16511  {
16512  case 0:
16513  case -1:
16514  break;
16515  case 1:
16516  cmd_response_data_set_status_code (response_data,
16517  MHD_HTTP_INTERNAL_SERVER_ERROR);
16518  return gsad_message (
16519  credentials, "Internal error", __FUNCTION__, __LINE__,
16520  "An internal error occurred while creating a new alert. "
16521  "No new alert was created. "
16522  "Diagnostics: Failure to send command to manager daemon.",
16523  response_data);
16524  case 2:
16525  cmd_response_data_set_status_code (response_data,
16526  MHD_HTTP_INTERNAL_SERVER_ERROR);
16527  return gsad_message (
16528  credentials, "Internal error", __FUNCTION__, __LINE__,
16529  "An internal error occurred while creating a new alert. "
16530  "It is unclear whether the alert has been created or not. "
16531  "Diagnostics: Failure to receive response from manager daemon.",
16532  response_data);
16533  default:
16534  cmd_response_data_set_status_code (response_data,
16535  MHD_HTTP_INTERNAL_SERVER_ERROR);
16536  return gsad_message (
16537  credentials, "Internal error", __FUNCTION__, __LINE__,
16538  "An internal error occurred while creating a new alert. "
16539  "It is unclear whether the alert has been created or not. "
16540  "Diagnostics: Internal Error.",
16541  response_data);
16542  }
16543 
16544  if (gmp_success (entity))
16545  {
16546  const char *filter_id;
16547 
16548  filter_id = entity_attribute (entity, "id");
16549  if (filter_id && strlen (filter_id))
16550  {
16551  param_t *param;
16552  param = params_add (params, "filt_id", filter_id);
16553  param->valid = 1;
16554  param->valid_utf8 = g_utf8_validate (param->value, -1, NULL);
16555  }
16556  }
16557 
16558  if (entity_attribute (entity, "id"))
16559  params_add (params, "filter_id", entity_attribute (entity, "id"));
16560  html = response_from_entity (connection, credentials, params, entity,
16561  "Create Filter", response_data);
16562  free_entity (entity);
16563  g_free (response);
16564  return html;
16565 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
gchar * value
Definition: gsad_params.h:40
static int gmp_success(entity_t entity)
Check whether an GMP command failed.
Definition: gsad_gmp.c:656
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
int valid_utf8
Definition: gsad_params.h:45
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
Request parameter.
Definition: gsad_params.h:38
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
int valid
Definition: gsad_params.h:44
param_t * params_add(params_t *params, const char *name, const char *value)
Add a param.
Definition: gsad_base.c:318

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmp_success(), gmpf(), gsad_message(), params_add(), params_value(), response_from_entity(), param::valid, param::valid_utf8, and param::value.

Here is the call graph for this function:

◆ create_group_gmp()

char* create_group_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Create a group, get all groups, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 14153 of file gsad_gmp.c.

14155 {
14156  gchar *html, *response, *command, *specials_element;
14157  const char *name, *comment, *users, *grant_full;
14158  entity_t entity;
14159  GString *xml;
14160  int ret;
14161 
14162  name = params_value (params, "name");
14163  comment = params_value (params, "comment");
14164  grant_full = params_value (params, "grant_full");
14165  users = params_value (params, "users");
14166 
14167  CHECK_VARIABLE_INVALID (name, "Create Group");
14168  CHECK_VARIABLE_INVALID (comment, "Create Group");
14169  CHECK_VARIABLE_INVALID (users, "Create Group");
14170 
14171  /* Create the group. */
14172 
14173  xml = g_string_new ("");
14174 
14175  xml_string_append (xml,
14176  "<name>%s</name>"
14177  "<comment>%s</comment>"
14178  "<users>%s</users>",
14179  name, comment, users);
14180 
14181  if (grant_full)
14182  specials_element = g_strdup_printf ("<full/>");
14183  else
14184  specials_element = NULL;
14185 
14186  command = g_strdup_printf ("<create_group>"
14187  "%s"
14188  "<specials>"
14189  "%s"
14190  "</specials>"
14191  "</create_group>",
14192  xml->str, specials_element);
14193 
14194  g_string_free (xml, TRUE);
14195  g_free (specials_element);
14196 
14197  ret =
14198  gmp (connection, credentials, &response, &entity, response_data, command);
14199  g_free (command);
14200  switch (ret)
14201  {
14202  case 0:
14203  case -1:
14204  break;
14205  case 1:
14206  cmd_response_data_set_status_code (response_data,
14207  MHD_HTTP_INTERNAL_SERVER_ERROR);
14208  return gsad_message (
14209  credentials, "Internal error", __FUNCTION__, __LINE__,
14210  "An internal error occurred while creating a new group. "
14211  "No new group was created. "
14212  "Diagnostics: Failure to send command to manager daemon.",
14213  response_data);
14214  case 2:
14215  cmd_response_data_set_status_code (response_data,
14216  MHD_HTTP_INTERNAL_SERVER_ERROR);
14217  return gsad_message (
14218  credentials, "Internal error", __FUNCTION__, __LINE__,
14219  "An internal error occurred while creating a new group. "
14220  "It is unclear whether the group has been created or not. "
14221  "Diagnostics: Failure to receive response from manager daemon.",
14222  response_data);
14223  default:
14224  cmd_response_data_set_status_code (response_data,
14225  MHD_HTTP_INTERNAL_SERVER_ERROR);
14226  return gsad_message (
14227  credentials, "Internal error", __FUNCTION__, __LINE__,
14228  "An internal error occurred while creating a new group. "
14229  "It is unclear whether the group has been created or not. "
14230  "Diagnostics: Internal Error.",
14231  response_data);
14232  }
14233 
14234  if (entity_attribute (entity, "id"))
14235  params_add (params, "group_id", entity_attribute (entity, "id"));
14236  html = response_from_entity (connection, credentials, params, entity,
14237  "Create Group", response_data);
14238  free_entity (entity);
14239  g_free (response);
14240  return html;
14241 }
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
GPtrArray * users
User session data.
Definition: gsad_session.c:39
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
param_t * params_add(params_t *params, const char *name, const char *value)
Add a param.
Definition: gsad_base.c:318

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmp(), gsad_message(), params_add(), params_value(), response_from_entity(), and users.

Here is the call graph for this function:

◆ create_host_gmp()

char* create_host_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Create a host, serve next page.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 18420 of file gsad_gmp.c.

18422 {
18423  int ret;
18424  gchar *html, *response;
18425  const char *name, *comment;
18426  entity_t entity;
18427  GString *xml;
18428 
18429  name = params_value (params, "name");
18430  CHECK_VARIABLE_INVALID (name, "Create Host");
18431 
18432  comment = params_value (params, "comment");
18433  CHECK_VARIABLE_INVALID (comment, "Create Host");
18434 
18435  /* Create the host. */
18436 
18437  xml = g_string_new ("");
18438 
18439  xml_string_append (xml,
18440  "<create_asset>"
18441  "<asset>"
18442  "<type>host</type>"
18443  "<name>%s</name>"
18444  "<comment>%s</comment>"
18445  "</asset>"
18446  "</create_asset>",
18447  name, comment);
18448 
18449  ret =
18450  gmp (connection, credentials, &response, &entity, response_data, xml->str);
18451  g_string_free (xml, TRUE);
18452  switch (ret)
18453  {
18454  case 0:
18455  case -1:
18456  break;
18457  case 1:
18458  cmd_response_data_set_status_code (response_data,
18459  MHD_HTTP_INTERNAL_SERVER_ERROR);
18460  return gsad_message (
18461  credentials, "Internal error", __FUNCTION__, __LINE__,
18462  "An internal error occurred while creating a new host. "
18463  "No new host was created. "
18464  "Diagnostics: Failure to send command to manager daemon.",
18465  response_data);
18466  case 2:
18467  cmd_response_data_set_status_code (response_data,
18468  MHD_HTTP_INTERNAL_SERVER_ERROR);
18469  return gsad_message (
18470  credentials, "Internal error", __FUNCTION__, __LINE__,
18471  "An internal error occurred while creating a new host. "
18472  "It is unclear whether the host has been created or not. "
18473  "Diagnostics: Failure to receive response from manager daemon.",
18474  response_data);
18475  default:
18476  cmd_response_data_set_status_code (response_data,
18477  MHD_HTTP_INTERNAL_SERVER_ERROR);
18478  return gsad_message (
18479  credentials, "Internal error", __FUNCTION__, __LINE__,
18480  "An internal error occurred while creating a new host. "
18481  "It is unclear whether the host has been created or not. "
18482  "Diagnostics: Internal Error.",
18483  response_data);
18484  }
18485 
18486  if (entity_attribute (entity, "id"))
18487  params_add (params, "asset_id", entity_attribute (entity, "id"));
18488  html = response_from_entity (connection, credentials, params, entity,
18489  "Create Host", response_data);
18490  free_entity (entity);
18491  g_free (response);
18492  return html;
18493 }
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
param_t * params_add(params_t *params, const char *name, const char *value)
Add a param.
Definition: gsad_base.c:318

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmp(), gsad_message(), params_add(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ create_note_gmp()

char* create_note_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Create a note, get report, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 10971 of file gsad_gmp.c.

10973 {
10974  char *ret;
10975  gchar *response;
10976  const char *oid, *severity, *port, *hosts;
10977  const char *text, *task_id, *result_id;
10978  /* For get_report. */
10979  const char *active, *days;
10980  entity_t entity;
10981 
10982  oid = params_value (params, "oid");
10983  CHECK_VARIABLE_INVALID (oid, "Create Note");
10984 
10985  port = get_port_from_params (params);
10986  hosts = get_hosts_from_params (params);
10987  task_id = get_task_id_from_params (params);
10988  severity = get_severity_from_params (params);
10989  result_id = get_result_id_from_params (params);
10990 
10991  CHECK_VARIABLE_INVALID (severity, "Create Note");
10992  CHECK_VARIABLE_INVALID (hosts, "Create Note");
10993 
10994  active = params_value (params, "active");
10995  CHECK_VARIABLE_INVALID (active, "Create Note");
10996 
10997  text = params_value (params, "text");
10998  days = params_value (params, "days");
10999 
11000  response = NULL;
11001  entity = NULL;
11002  switch (gmpf (connection, credentials, &response, &entity, response_data,
11003  "<create_note>"
11004  "<active>%s</active>"
11005  "<nvt oid=\"%s\"/>"
11006  "<hosts>%s</hosts>"
11007  "<port>%s</port>"
11008  "<severity>%s</severity>"
11009  "<text>%s</text>"
11010  "<task id=\"%s\"/>"
11011  "<result id=\"%s\"/>"
11012  "</create_note>",
11013  strcmp (active, "1") ? active : (days ? days : "-1"), oid,
11014  hosts ? hosts : "", port ? port : "", severity ? severity : "",
11015  text ? text : "", task_id ? task_id : "",
11016  result_id ? result_id : ""))
11017  {
11018  case 0:
11019  case -1:
11020  break;
11021  case 1:
11022  cmd_response_data_set_status_code (response_data,
11023  MHD_HTTP_INTERNAL_SERVER_ERROR);
11024  return gsad_message (
11025  credentials, "Internal error", __FUNCTION__, __LINE__,
11026  "An internal error occurred while creating a new note. "
11027  "No new note was created. "
11028  "Diagnostics: Failure to send command to manager daemon.",
11029  response_data);
11030  case 2:
11031  cmd_response_data_set_status_code (response_data,
11032  MHD_HTTP_INTERNAL_SERVER_ERROR);
11033  return gsad_message (
11034  credentials, "Internal error", __FUNCTION__, __LINE__,
11035  "An internal error occurred while creating a new note. "
11036  "It is unclear whether the note has been created or not. "
11037  "Diagnostics: Failure to receive response from manager daemon.",
11038  response_data);
11039  default:
11040  cmd_response_data_set_status_code (response_data,
11041  MHD_HTTP_INTERNAL_SERVER_ERROR);
11042  return gsad_message (
11043  credentials, "Internal error", __FUNCTION__, __LINE__,
11044  "An internal error occurred while creating a new note. "
11045  "It is unclear whether the note has been created or not. "
11046  "Diagnostics: Internal Error.",
11047  response_data);
11048  }
11049 
11050  if (entity_attribute (entity, "id"))
11051  params_add (params, "note_id", entity_attribute (entity, "id"));
11052  ret = response_from_entity (connection, credentials, params, entity,
11053  "Create Note", response_data);
11054  free_entity (entity);
11055  g_free (response);
11056  return ret;
11057 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
const char * get_port_from_params(params_t *params)
Get a port from request params.
Definition: gsad_gmp.c:10842
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
const char * get_severity_from_params(params_t *params)
Get severity from request params.
Definition: gsad_gmp.c:10923
const char * get_task_id_from_params(params_t *params)
Get task_id from request params.
Definition: gsad_gmp.c:10903
const char * get_hosts_from_params(params_t *params)
Get hosts from request params.
Definition: gsad_gmp.c:10868
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
const char * get_result_id_from_params(params_t *params)
Get result_id from request params.
Definition: gsad_gmp.c:10946
param_t * params_add(params_t *params, const char *name, const char *value)
Add a param.
Definition: gsad_base.c:318

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), get_hosts_from_params(), get_port_from_params(), get_result_id_from_params(), get_severity_from_params(), get_task_id_from_params(), gmpf(), gsad_message(), params_add(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ create_override_gmp()

char* create_override_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Create an override, get report, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 11262 of file gsad_gmp.c.

11264 {
11265  char *ret;
11266  gchar *response;
11267  const char *oid, *severity, *custom_severity, *new_severity, *port, *hosts;
11268  const char *text, *task_id, *result_id;
11269  /* For get_report. */
11270  const char *active, *days;
11271  entity_t entity;
11272 
11273  oid = params_value (params, "oid");
11274  CHECK_VARIABLE_INVALID (oid, "Create Override");
11275 
11276  port = get_port_from_params (params);
11277  hosts = get_hosts_from_params (params);
11278  task_id = get_task_id_from_params (params);
11279  severity = get_severity_from_params (params);
11280  result_id = get_result_id_from_params (params);
11281 
11282  custom_severity = params_value (params, "custom_severity");
11283  CHECK_VARIABLE_INVALID (custom_severity, "Create Override");
11284 
11285  if (custom_severity != NULL && strcmp (custom_severity, "0"))
11286  {
11287  if (params_valid (params, "new_severity"))
11288  new_severity = params_value (params, "new_severity");
11289  else if (params_original_value (params, "new_severity") == NULL
11290  || strcmp (params_original_value (params, "new_severity"), ""))
11291  new_severity = NULL;
11292  else
11293  new_severity = "";
11294  CHECK_VARIABLE_INVALID (new_severity, "Create Override");
11295  }
11296  else
11297  {
11298  if (params_valid (params, "new_severity_from_list"))
11299  new_severity = params_value (params, "new_severity_from_list");
11300  else if (params_original_value (params, "new_severity_from_list") == NULL
11301  || strcmp (
11302  params_original_value (params, "new_severity_from_list"),
11303  ""))
11304  new_severity = NULL;
11305  else
11306  new_severity = "";
11307  CHECK_VARIABLE_INVALID (new_severity, "Create Override");
11308  }
11309 
11310  active = params_value (params, "active");
11311  CHECK_VARIABLE_INVALID (active, "Create Override");
11312 
11313  text = params_value (params, "text");
11314  days = params_value (params, "days");
11315 
11316  response = NULL;
11317  entity = NULL;
11318  switch (gmpf (connection, credentials, &response, &entity, response_data,
11319  "<create_override>"
11320  "<active>%s</active>"
11321  "<nvt oid=\"%s\"/>"
11322  "<hosts>%s</hosts>"
11323  "<port>%s</port>"
11324  "<severity>%s</severity>"
11325  "<new_severity>%s</new_severity>"
11326  "<text>%s</text>"
11327  "<task id=\"%s\"/>"
11328  "<result id=\"%s\"/>"
11329  "</create_override>",
11330  strcmp (active, "1") ? active : (days ? days : "-1"), oid,
11331  hosts ? hosts : "", port ? port : "", severity ? severity : "",
11332  new_severity, text ? text : "", task_id ? task_id : "",
11333  result_id ? result_id : ""))
11334  {
11335  case 0:
11336  case -1:
11337  break;
11338  case 1:
11339  cmd_response_data_set_status_code (response_data,
11340  MHD_HTTP_INTERNAL_SERVER_ERROR);
11341  return gsad_message (
11342  credentials, "Internal error", __FUNCTION__, __LINE__,
11343  "An internal error occurred while creating a new override. "
11344  "No new override was created. "
11345  "Diagnostics: Failure to send command to manager daemon.",
11346  response_data);
11347  case 2:
11348  cmd_response_data_set_status_code (response_data,
11349  MHD_HTTP_INTERNAL_SERVER_ERROR);
11350  return gsad_message (
11351  credentials, "Internal error", __FUNCTION__, __LINE__,
11352  "An internal error occurred while creating a new override. "
11353  "It is unclear whether the override has been created or not. "
11354  "Diagnostics: Failure to receive response from manager daemon.",
11355  response_data);
11356  default:
11357  cmd_response_data_set_status_code (response_data,
11358  MHD_HTTP_INTERNAL_SERVER_ERROR);
11359  return gsad_message (
11360  credentials, "Internal error", __FUNCTION__, __LINE__,
11361  "An internal error occurred while creating a new override. "
11362  "It is unclear whether the override has been created or not. "
11363  "Diagnostics: Internal Error.",
11364  response_data);
11365  }
11366 
11367  if (entity_attribute (entity, "id"))
11368  params_add (params, "override_id", entity_attribute (entity, "id"));
11369  ret = response_from_entity (connection, credentials, params, entity,
11370  "Create Override", response_data);
11371  free_entity (entity);
11372  g_free (response);
11373  return ret;
11374 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
const char * get_port_from_params(params_t *params)
Get a port from request params.
Definition: gsad_gmp.c:10842
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
const char * params_original_value(params_t *params, const char *name)
Get original value of param, before validation.
Definition: gsad_base.c:255
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
const char * get_severity_from_params(params_t *params)
Get severity from request params.
Definition: gsad_gmp.c:10923
const char * get_task_id_from_params(params_t *params)
Get task_id from request params.
Definition: gsad_gmp.c:10903
const char * get_hosts_from_params(params_t *params)
Get hosts from request params.
Definition: gsad_gmp.c:10868
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
const char * get_result_id_from_params(params_t *params)
Get result_id from request params.
Definition: gsad_gmp.c:10946
param_t * params_add(params_t *params, const char *name, const char *value)
Add a param.
Definition: gsad_base.c:318
int params_valid(params_t *params, const char *name)
Get whether a param is valid.
Definition: gsad_base.c:303

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), get_hosts_from_params(), get_port_from_params(), get_result_id_from_params(), get_severity_from_params(), get_task_id_from_params(), gmpf(), gsad_message(), params_add(), params_original_value(), params_valid(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ create_permission_gmp()

char* create_permission_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Create a permission, get all permissions, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 14466 of file gsad_gmp.c.

14468 {
14469  int ret;
14470  gchar *html, *response;
14471  const char *name, *comment, *resource_id, *resource_type;
14472  const char *subject_id, *subject_type, *subject_name;
14473  entity_t entity;
14474 
14475  gchar *subject_response;
14476  entity_t get_subject_entity = NULL;
14477  entity_t subject_entity;
14478 
14479  name = params_value (params, "permission");
14480  comment = params_value (params, "comment");
14481  resource_id = params_value (params, "id_or_empty");
14482  resource_type = params_value (params, "optional_resource_type");
14483  subject_type = params_value (params, "subject_type");
14484  subject_name = params_value (params, "subject_name");
14485 
14486  CHECK_VARIABLE_INVALID (name, "Create Permission");
14487  CHECK_VARIABLE_INVALID (comment, "Create Permission");
14488  if (params_given (params, "id_or_empty"))
14489  CHECK_VARIABLE_INVALID (resource_id, "Create Permission");
14490  CHECK_VARIABLE_INVALID (subject_type, "Create Permission");
14491  if (params_given (params, "optional_resource_type"))
14492  CHECK_VARIABLE_INVALID (resource_type, "Create Permission");
14493 
14494  if (params_given (params, "subject_name"))
14495  {
14496  CHECK_VARIABLE_INVALID (subject_name, "Create Permission");
14497  subject_id = NULL;
14498  ret = gmpf (connection, credentials, &subject_response,
14499  &get_subject_entity, response_data,
14500  "<get_%ss filter=\"rows=1 name=%s\">"
14501  "</get_%ss>",
14502  subject_type, subject_name, subject_type);
14503 
14504  switch (ret)
14505  {
14506  case 0:
14507  case -1:
14508  break;
14509  case 1:
14510  cmd_response_data_set_status_code (response_data,
14511  MHD_HTTP_INTERNAL_SERVER_ERROR);
14512  return gsad_message (credentials, "Internal error", __FUNCTION__,
14513  __LINE__,
14514  "An internal error occurred while getting"
14515  " the subject for a permission. "
14516  "The permission was not created. "
14517  "Diagnostics: Failure to send command"
14518  " to manager daemon.",
14519  response_data);
14520  case 2:
14521  cmd_response_data_set_status_code (response_data,
14522  MHD_HTTP_INTERNAL_SERVER_ERROR);
14523  return gsad_message (credentials, "Internal error", __FUNCTION__,
14524  __LINE__,
14525  "An internal error occurred while getting"
14526  " the subject for a permission. "
14527  "The permission was not created. "
14528  "Diagnostics: Failure to receive response"
14529  " from manager daemon.",
14530  response_data);
14531  default:
14532  cmd_response_data_set_status_code (response_data,
14533  MHD_HTTP_INTERNAL_SERVER_ERROR);
14534  return gsad_message (credentials, "Internal error", __FUNCTION__,
14535  __LINE__,
14536  "An internal error occurred while getting"
14537  " the subject for a permission. "
14538  "The permission was not created. "
14539  "Diagnostics: Internal Error.",
14540  response_data);
14541  }
14542 
14543  subject_entity = entity_child (get_subject_entity, subject_type);
14544 
14545  if (subject_entity)
14546  subject_id = entity_attribute (subject_entity, "id");
14547 
14548  if (subject_id == NULL)
14549  {
14550  cmd_response_data_set_status_code (response_data,
14551  MHD_HTTP_INTERNAL_SERVER_ERROR);
14552  return gsad_message (credentials, "Internal error", __FUNCTION__,
14553  __LINE__,
14554  "An internal error occurred while creating a "
14555  "permission. Could not find Subject."
14556  "The permission was not created. "
14557  "Diagnostics: Internal Error.",
14558  response_data);
14559  }
14560  }
14561  else if (strcmp (subject_type, "user") == 0)
14562  subject_id = params_value (params, "permission_user_id");
14563  else if (strcmp (subject_type, "group") == 0)
14564  subject_id = params_value (params, "permission_group_id");
14565  else if (strcmp (subject_type, "role") == 0)
14566  subject_id = params_value (params, "permission_role_id");
14567  else
14568  subject_id = NULL;
14569 
14570  CHECK_VARIABLE_INVALID (subject_id, "Create Permission");
14571 
14572  /* Create the permission(s). */
14573 
14574  if (strcmp (name, "task_proxy") == 0)
14575  {
14576  response = NULL;
14577  entity = NULL;
14578  ret = gmpf (connection, credentials, &response, &entity, response_data,
14579  "<commands>"
14580  "<create_permission>"
14581  "<name>get_tasks</name>"
14582  "<comment>%s</comment>"
14583  "<resource id=\"%s\"/>"
14584  "<subject id=\"%s\"><type>%s</type></subject>"
14585  "</create_permission>"
14586  "<create_permission>"
14587  "<name>modify_task</name>"
14588  "<comment>%s</comment>"
14589  "<resource id=\"%s\"/>"
14590  "<subject id=\"%s\"><type>%s</type></subject>"
14591  "</create_permission>"
14592  "<create_permission>"
14593  "<name>start_task</name>"
14594  "<comment>%s</comment>"
14595  "<resource id=\"%s\"/>"
14596  "<subject id=\"%s\"><type>%s</type></subject>"
14597  "</create_permission>"
14598  "<create_permission>"
14599  "<name>stop_task</name>"
14600  "<comment>%s</comment>"
14601  "<resource id=\"%s\"/>"
14602  "<subject id=\"%s\"><type>%s</type></subject>"
14603  "</create_permission>"
14604  "<create_permission>"
14605  "<name>resume_task</name>"
14606  "<comment>%s</comment>"
14607  "<resource id=\"%s\"/>"
14608  "<subject id=\"%s\"><type>%s</type></subject>"
14609  "</create_permission>"
14610  "</commands>",
14611  comment ? comment : "", resource_id ? resource_id : "",
14612  subject_id, subject_type, comment ? comment : "",
14613  resource_id ? resource_id : "", subject_id, subject_type,
14614  comment ? comment : "", resource_id ? resource_id : "",
14615  subject_id, subject_type, comment ? comment : "",
14616  resource_id ? resource_id : "", subject_id, subject_type,
14617  comment ? comment : "", resource_id ? resource_id : "",
14618  subject_id, subject_type);
14619 
14620  if (get_subject_entity)
14621  free_entity (get_subject_entity);
14622 
14623  switch (ret)
14624  {
14625  case 0:
14626  case -1:
14627  break;
14628  case 1:
14629  cmd_response_data_set_status_code (response_data,
14630  MHD_HTTP_INTERNAL_SERVER_ERROR);
14631  return gsad_message (
14632  credentials, "Internal error", __FUNCTION__, __LINE__,
14633  "An internal error occurred while creating a permission. "
14634  "The permission was not created. "
14635  "Diagnostics: Failure to send command to manager daemon.",
14636  response_data);
14637  case 2:
14638  cmd_response_data_set_status_code (response_data,
14639  MHD_HTTP_INTERNAL_SERVER_ERROR);
14640  return gsad_message (
14641  credentials, "Internal error", __FUNCTION__, __LINE__,
14642  "An internal error occurred while creating a permission. "
14643  "It is unclear whether the permission has been created or not. "
14644  "Diagnostics: Failure to receive response from manager daemon.",
14645  response_data);
14646  default:
14647  cmd_response_data_set_status_code (response_data,
14648  MHD_HTTP_INTERNAL_SERVER_ERROR);
14649  return gsad_message (
14650  credentials, "Internal error", __FUNCTION__, __LINE__,
14651  "An internal error occurred while creating a permission. "
14652  "It is unclear whether the permission has been created or not. "
14653  "Diagnostics: Internal Error.",
14654  response_data);
14655  }
14656 
14657  if (entity_attribute (entity, "id"))
14658  params_add (params, "permission_id", entity_attribute (entity, "id"));
14659  html = response_from_entity (connection, credentials, params, entity,
14660  "Create Permission", response_data);
14661  }
14662  else
14663  {
14664  response = NULL;
14665  entity = NULL;
14666  ret = gmpf (connection, credentials, &response, &entity, response_data,
14667  "<create_permission>"
14668  "<name>%s</name>"
14669  "<comment>%s</comment>"
14670  "<resource id=\"%s\">"
14671  "<type>%s</type>"
14672  "</resource>"
14673  "<subject id=\"%s\"><type>%s</type></subject>"
14674  "</create_permission>",
14675  name, comment ? comment : "", resource_id ? resource_id : "",
14676  resource_type ? resource_type : "", subject_id, subject_type);
14677 
14678  if (get_subject_entity)
14679  free_entity (get_subject_entity);
14680 
14681  switch (ret)
14682  {
14683  case 0:
14684  case -1:
14685  break;
14686  case 1:
14687  cmd_response_data_set_status_code (response_data,
14688  MHD_HTTP_INTERNAL_SERVER_ERROR);
14689  return gsad_message (
14690  credentials, "Internal error", __FUNCTION__, __LINE__,
14691  "An internal error occurred while creating a permission. "
14692  "The permission was not created. "
14693  "Diagnostics: Failure to send command to manager daemon.",
14694  response_data);
14695  case 2:
14696  cmd_response_data_set_status_code (response_data,
14697  MHD_HTTP_INTERNAL_SERVER_ERROR);
14698  return gsad_message (
14699  credentials, "Internal error", __FUNCTION__, __LINE__,
14700  "An internal error occurred while creating a permission. "
14701  "It is unclear whether the permission has been created or not. "
14702  "Diagnostics: Failure to receive response from manager daemon.",
14703  response_data);
14704  default:
14705  cmd_response_data_set_status_code (response_data,
14706  MHD_HTTP_INTERNAL_SERVER_ERROR);
14707  return gsad_message (
14708  credentials, "Internal error", __FUNCTION__, __LINE__,
14709  "An internal error occurred while creating a permission. "
14710  "It is unclear whether the permission has been created or not. "
14711  "Diagnostics: Internal Error.",
14712  response_data);
14713  }
14714 
14715  if (entity_attribute (entity, "id"))
14716  params_add (params, "permission_id", entity_attribute (entity, "id"));
14717  html = response_from_entity (connection, credentials, params, entity,
14718  "Create Permission", response_data);
14719  }
14720  free_entity (entity);
14721  g_free (response);
14722  return html;
14723 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
int params_given(params_t *params, const char *name)
Get whether a param was given at all.
Definition: gsad_base.c:189
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
param_t * params_add(params_t *params, const char *name, const char *value)
Add a param.
Definition: gsad_base.c:318

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmpf(), gsad_message(), params_add(), params_given(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ create_permissions_gmp()

char* create_permissions_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Create multiple permission, get next page, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 14785 of file gsad_gmp.c.

14788 {
14789  int ret;
14790  gchar *html, *response, *summary_response;
14791  int successes;
14792  const char *permission, *comment, *resource_id, *resource_type;
14793  const char *subject_id, *subject_type, *subject_name;
14794  const char *permission_resource_type;
14795  int include_related;
14796 
14797  entity_t entity;
14798 
14799  gchar *subject_response;
14800  entity_t get_subject_entity = NULL;
14801  entity_t subject_entity;
14802 
14803  permission = params_value (params, "permission");
14804  comment = params_value (params, "comment");
14805  resource_id = params_value (params, "resource_id");
14806  resource_type = params_value (params, "resource_type");
14807  subject_type = params_value (params, "subject_type");
14808  subject_name = params_value (params, "subject_name");
14809 
14810  CHECK_VARIABLE_INVALID (params_value (params, "include_related"),
14811  "Create Permission");
14812  CHECK_VARIABLE_INVALID (permission, "Create Permission");
14813  CHECK_VARIABLE_INVALID (comment, "Create Permission");
14814  CHECK_VARIABLE_INVALID (resource_id, "Create Permission");
14815  CHECK_VARIABLE_INVALID (subject_type, "Create Permission");
14816  CHECK_VARIABLE_INVALID (resource_type, "Create Permission");
14817 
14818  if (str_equal (resource_type, "host") || str_equal (resource_type, "os"))
14819  {
14820  permission_resource_type = "asset";
14821  }
14822  else
14823  permission_resource_type = resource_type;
14824 
14825  include_related = atoi (params_value (params, "include_related"));
14826 
14827  if (params_given (params, "subject_name"))
14828  {
14829  CHECK_VARIABLE_INVALID (subject_name, "Create Permission");
14830  subject_id = NULL;
14831  ret = gmpf (connection, credentials, &subject_response,
14832  &get_subject_entity, response_data,
14833  "<get_%ss filter=\"rows=1 name=%s\">"
14834  "</get_%ss>",
14835  subject_type, subject_name, subject_type);
14836 
14837  switch (ret)
14838  {
14839  case 0:
14840  case -1:
14841  break;
14842  case 1:
14843  cmd_response_data_set_status_code (response_data,
14844  MHD_HTTP_INTERNAL_SERVER_ERROR);
14845  return gsad_message (credentials, "Internal error", __FUNCTION__,
14846  __LINE__,
14847  "An internal error occurred while getting"
14848  " the subject for a permission. "
14849  "The permission was not created. "
14850  "Diagnostics: Failure to send command"
14851  " to manager daemon.",
14852  response_data);
14853  case 2:
14854  cmd_response_data_set_status_code (response_data,
14855  MHD_HTTP_INTERNAL_SERVER_ERROR);
14856  return gsad_message (credentials, "Internal error", __FUNCTION__,
14857  __LINE__,
14858  "An internal error occurred while getting"
14859  " the subject for a permission. "
14860  "The permission was not created. "
14861  "Diagnostics: Failure to receive response"
14862  " from manager daemon.",
14863  response_data);
14864  default:
14865  cmd_response_data_set_status_code (response_data,
14866  MHD_HTTP_INTERNAL_SERVER_ERROR);
14867  return gsad_message (credentials, "Internal error", __FUNCTION__,
14868  __LINE__,
14869  "An internal error occurred while getting"
14870  " the subject for a permission. "
14871  "The permission was not created. "
14872  "Diagnostics: Internal Error.",
14873  response_data);
14874  }
14875 
14876  subject_entity = entity_child (get_subject_entity, subject_type);
14877 
14878  if (subject_entity)
14879  subject_id = entity_attribute (subject_entity, "id");
14880 
14881  if (subject_id == NULL)
14882  {
14883  cmd_response_data_set_status_code (response_data,
14884  MHD_HTTP_INTERNAL_SERVER_ERROR);
14885  return gsad_message (credentials, "Internal error", __FUNCTION__,
14886  __LINE__,
14887  "An internal error occurred while creating a "
14888  "permission. Could not find Subject."
14889  "The permission was not created. "
14890  "Diagnostics: Internal Error.",
14891  response_data);
14892  }
14893  }
14894  else if (str_equal (subject_type, "user"))
14895  subject_id = params_value (params, "permission_user_id");
14896  else if (str_equal (subject_type, "group"))
14897  subject_id = params_value (params, "permission_group_id");
14898  else if (str_equal (subject_type, "role"))
14899  subject_id = params_value (params, "permission_role_id");
14900  else
14901  subject_id = NULL;
14902 
14903  CHECK_VARIABLE_INVALID (subject_id, "Create Permission");
14904 
14905  successes = 0;
14906 
14907  /* Create the permission(s). */
14908 
14909  // Main resource permissions
14910  if (include_related != 2)
14911  {
14912  if (strcmp (permission, "read") == 0 || strcmp (permission, "proxy") == 0)
14913  {
14914  response = NULL;
14915  entity = NULL;
14916  ret =
14917  gmpf (connection, credentials, &response, &entity, response_data,
14918  "<create_permission>"
14919  "<name>get_%ss</name>"
14920  "<comment>%s</comment>"
14921  "<resource id=\"%s\">"
14922  "</resource>"
14923  "<subject id=\"%s\"><type>%s</type></subject>"
14924  "</create_permission>",
14925  permission_resource_type, comment ? comment : "", resource_id,
14926  subject_id, subject_type);
14927 
14929  }
14930 
14931  if ((strcmp (permission, "proxy") == 0)
14932  && strcmp (permission_resource_type, "result")
14933  && strcmp (permission_resource_type, "report"))
14934  {
14935  response = NULL;
14936  entity = NULL;
14937  ret =
14938  gmpf (connection, credentials, &response, &entity, response_data,
14939  "<create_permission>"
14940  "<name>modify_%s</name>"
14941  "<comment>%s</comment>"
14942  "<resource id=\"%s\">"
14943  "</resource>"
14944  "<subject id=\"%s\"><type>%s</type></subject>"
14945  "</create_permission>",
14946  permission_resource_type, comment ? comment : "", resource_id,
14947  subject_id, subject_type);
14948 
14950 
14951  if (strcmp (permission_resource_type, "task") == 0)
14952  {
14953  response = NULL;
14954  entity = NULL;
14955  ret = gmpf (connection, credentials, &response, &entity,
14956  response_data,
14957  "<create_permission>"
14958  "<name>start_%s</name>"
14959  "<comment>%s</comment>"
14960  "<resource id=\"%s\">"
14961  "</resource>"
14962  "<subject id=\"%s\"><type>%s</type></subject>"
14963  "</create_permission>",
14964  permission_resource_type, comment ? comment : "",
14965  resource_id, subject_id, subject_type);
14966 
14968 
14969  response = NULL;
14970  entity = NULL;
14971  ret = gmpf (connection, credentials, &response, &entity,
14972  response_data,
14973  "<create_permission>"
14974  "<name>stop_%s</name>"
14975  "<comment>%s</comment>"
14976  "<resource id=\"%s\">"
14977  "</resource>"
14978  "<subject id=\"%s\"><type>%s</type></subject>"
14979  "</create_permission>",
14980  permission_resource_type, comment ? comment : "",
14981  resource_id, subject_id, subject_type);
14982 
14984 
14985  response = NULL;
14986  entity = NULL;
14987  ret = gmpf (connection, credentials, &response, &entity,
14988  response_data,
14989  "<create_permission>"
14990  "<name>resume_%s</name>"
14991  "<comment>%s</comment>"
14992  "<resource id=\"%s\">"
14993  "</resource>"
14994  "<subject id=\"%s\"><type>%s</type></subject>"
14995  "</create_permission>",
14996  permission_resource_type, comment ? comment : "",
14997  resource_id, subject_id, subject_type);
14998 
15000  }
15001 
15002  if (strcmp (permission_resource_type, "alert") == 0)
15003  {
15004  response = NULL;
15005  entity = NULL;
15006  ret = gmpf (connection, credentials, &response, &entity,
15007  response_data,
15008  "<create_permission>"
15009  "<name>test_%s</name>"
15010  "<comment>%s</comment>"
15011  "<resource id=\"%s\">"
15012  "</resource>"
15013  "<subject id=\"%s\"><type>%s</type></subject>"
15014  "</create_permission>",
15015  permission_resource_type, comment ? comment : "",
15016  resource_id, subject_id, subject_type);
15017 
15019  }
15020 
15021  if (strcmp (permission_resource_type, "agent") == 0
15022  || strcmp (permission_resource_type, "report_format") == 0
15023  || strcmp (permission_resource_type, "scanner") == 0)
15024  {
15025  response = NULL;
15026  entity = NULL;
15027  ret = gmpf (connection, credentials, &response, &entity,
15028  response_data,
15029  "<create_permission>"
15030  "<name>verify_%s</name>"
15031  "<comment>%s</comment>"
15032  "<resource id=\"%s\">"
15033  "</resource>"
15034  "<subject id=\"%s\"><type>%s</type></subject>"
15035  "</create_permission>",
15036  permission_resource_type, comment ? comment : "",
15037  resource_id, subject_id, subject_type);
15038 
15040  }
15041  }
15042  }
15043 
15044  // Related permissions
15045  if (include_related)
15046  {
15047  params_t *related;
15048  related = params_values (params, "related:");
15049  if (related)
15050  {
15051  params_iterator_t iter;
15052  char *name;
15053  param_t *param;
15054 
15055  params_iterator_init (&iter, related);
15056  while (params_iterator_next (&iter, &name, &param))
15057  {
15058  char *related_id = name;
15059  char *related_type;
15060 
15061  if (str_equal (param->value, "host")
15062  || str_equal (param->value, "os"))
15063  {
15064  related_type = "asset";
15065  }
15066  else
15067  related_type = param->value;
15068 
15069  if (strcmp (permission, "read") == 0
15070  || strcmp (permission, "proxy") == 0)
15071  {
15072  response = NULL;
15073  entity = NULL;
15074  ret = gmpf (connection, credentials, &response, &entity,
15075  response_data,
15076  "<create_permission>"
15077  "<name>get_%ss</name>"
15078  "<comment>%s</comment>"
15079  "<resource id=\"%s\">"
15080  "</resource>"
15081  "<subject id=\"%s\"><type>%s</type></subject>"
15082  "</create_permission>",
15083  related_type, comment ? comment : "", related_id,
15084  subject_id, subject_type);
15085 
15087  }
15088 
15089  if ((strcmp (permission, "proxy") == 0)
15090  && strcmp (related_type, "result")
15091  && strcmp (related_type, "report"))
15092  {
15093  response = NULL;
15094  entity = NULL;
15095  ret = gmpf (connection, credentials, &response, &entity,
15096  response_data,
15097  "<create_permission>"
15098  "<name>modify_%s</name>"
15099  "<comment>%s</comment>"
15100  "<resource id=\"%s\">"
15101  "</resource>"
15102  "<subject id=\"%s\"><type>%s</type></subject>"
15103  "</create_permission>",
15104  related_type, comment ? comment : "", related_id,
15105  subject_id, subject_type);
15106 
15108 
15109  if (strcmp (related_type, "task") == 0)
15110  {
15111  response = NULL;
15112  entity = NULL;
15113  ret = gmpf (connection, credentials, &response, &entity,
15114  response_data,
15115  "<create_permission>"
15116  "<name>start_%s</name>"
15117  "<comment>%s</comment>"
15118  "<resource id=\"%s\">"
15119  "</resource>"
15120  "<subject id=\"%s\"><type>%s</type></subject>"
15121  "</create_permission>",
15122  related_type, comment ? comment : "",
15123  related_id, subject_id, subject_type);
15124 
15126 
15127  response = NULL;
15128  entity = NULL;
15129  ret = gmpf (connection, credentials, &response, &entity,
15130  response_data,
15131  "<create_permission>"
15132  "<name>stop_%s</name>"
15133  "<comment>%s</comment>"
15134  "<resource id=\"%s\">"
15135  "</resource>"
15136  "<subject id=\"%s\"><type>%s</type></subject>"
15137  "</create_permission>",
15138  related_type, comment ? comment : "",
15139  related_id, subject_id, subject_type);
15140 
15142 
15143  response = NULL;
15144  entity = NULL;
15145  ret = gmpf (connection, credentials, &response, &entity,
15146  response_data,
15147  "<create_permission>"
15148  "<name>resume_%s</name>"
15149  "<comment>%s</comment>"
15150  "<resource id=\"%s\">"
15151  "</resource>"
15152  "<subject id=\"%s\"><type>%s</type></subject>"
15153  "</create_permission>",
15154  related_type, comment ? comment : "",
15155  related_id, subject_id, subject_type);
15156 
15158  }
15159 
15160  if (strcmp (related_type, "alert") == 0)
15161  {
15162  response = NULL;
15163  entity = NULL;
15164  ret = gmpf (connection, credentials, &response, &entity,
15165  response_data,
15166  "<create_permission>"
15167  "<name>test_%s</name>"
15168  "<comment>%s</comment>"
15169  "<resource id=\"%s\">"
15170  "</resource>"
15171  "<subject id=\"%s\"><type>%s</type></subject>"
15172  "</create_permission>",
15173  related_type, comment ? comment : "",
15174  related_id, subject_id, subject_type);
15175 
15177  }
15178 
15179  if (strcmp (related_type, "agent") == 0
15180  || strcmp (related_type, "report_format") == 0
15181  || strcmp (related_type, "scanner") == 0)
15182  {
15183  response = NULL;
15184  entity = NULL;
15185  ret = gmpf (connection, credentials, &response, &entity,
15186  response_data,
15187  "<create_permission>"
15188  "<name>verify_%s</name>"
15189  "<comment>%s</comment>"
15190  "<resource id=\"%s\">"
15191  "</resource>"
15192  "<subject id=\"%s\"><type>%s</type></subject>"
15193  "</create_permission>",
15194  related_type, comment ? comment : "",
15195  related_id, subject_id, subject_type);
15196 
15198  }
15199  }
15200  }
15201  }
15202  }
15203 
15204  if (get_subject_entity)
15205  free_entity (get_subject_entity);
15206 
15207  summary_response =
15208  g_strdup_printf ("Successfully created %i permissions", successes);
15209 
15210  html = action_result (connection, credentials, params, response_data,
15211  "Create Permissions", summary_response, NULL, NULL);
15212  return html;
15213 }
params_t * params_values(params_t *params, const char *name)
Get values of param.
Definition: gsad_base.c:287
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
gchar * value
Definition: gsad_params.h:40
Structure of credential related information.
gboolean str_equal(const gchar *str1, const gchar *str2)
Check if two strings are equal.
Definition: utils.c:35
#define params_iterator_t
Definition: gsad_params.h:94
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
int params_given(params_t *params, const char *name)
Get whether a param was given at all.
Definition: gsad_base.c:189
#define CHECK_GMPF_RET
Definition: gsad_gmp.c:14725
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
Request parameter.
Definition: gsad_params.h:38
static gchar * action_result(gvm_connection_t *, credentials_t *, params_t *, cmd_response_data_t *, const char *action, const char *message, const char *details, const char *id)
Generate a enveloped GMP XML containing an action result.
Definition: gsad_gmp.c:965
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
gboolean params_iterator_next(params_iterator_t *iterator, char **name, param_t **param)
Increment a params iterator.
Definition: gsad_base.c:394
#define params_iterator_init
Definition: gsad_params.h:96
#define params_t
Definition: gsad_params.h:31
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References action_result(), CHECK_GMPF_RET, CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmpf(), gsad_message(), params_given(), params_iterator_init, params_iterator_next(), params_iterator_t, params_t, params_value(), params_values(), str_equal(), and param::value.

Here is the call graph for this function:

◆ create_port_list_gmp()

char* create_port_list_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Create a port list, get all port lists, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 15372 of file gsad_gmp.c.

15374 {
15375  gchar *html, *response;
15376  const char *name, *comment, *port_range, *from_file;
15377  entity_t entity;
15378 
15379  name = params_value (params, "name");
15380  comment = params_value (params, "comment");
15381  port_range = params_value (params, "port_range");
15382  from_file = params_value (params, "from_file");
15383 
15384  CHECK_VARIABLE_INVALID (name, "Create Port List");
15385  CHECK_VARIABLE_INVALID (comment, "Create Port List");
15386  CHECK_VARIABLE_INVALID (port_range, "Create Port List");
15387  CHECK_VARIABLE_INVALID (from_file, "Create Port List");
15388 
15389  /* Create the port_list. */
15390 
15391  switch (gmpf (
15392  connection, credentials, &response, &entity, response_data,
15393  "<create_port_list>"
15394  "<name>%s</name>"
15395  "<port_range>%s</port_range>"
15396  "<comment>%s</comment>"
15397  "</create_port_list>",
15398  name, strcmp (from_file, "0") ? params_value (params, "file") : port_range,
15399  comment ? comment : ""))
15400  {
15401  case 0:
15402  case -1:
15403  break;
15404  case 1:
15405  cmd_response_data_set_status_code (response_data,
15406  MHD_HTTP_INTERNAL_SERVER_ERROR);
15407  return gsad_message (
15408  credentials, "Internal error", __FUNCTION__, __LINE__,
15409  "An internal error occurred while creating a new port list. "
15410  "No new port list was created. "
15411  "Diagnostics: Failure to send command to manager daemon.",
15412  response_data);
15413  case 2:
15414  cmd_response_data_set_status_code (response_data,
15415  MHD_HTTP_INTERNAL_SERVER_ERROR);
15416  return gsad_message (
15417  credentials, "Internal error", __FUNCTION__, __LINE__,
15418  "An internal error occurred while creating a new port list. "
15419  "It is unclear whether the port list has been created or not. "
15420  "Diagnostics: Failure to receive response from manager daemon.",
15421  response_data);
15422  default:
15423  cmd_response_data_set_status_code (response_data,
15424  MHD_HTTP_INTERNAL_SERVER_ERROR);
15425  return gsad_message (
15426  credentials, "Internal error", __FUNCTION__, __LINE__,
15427  "An internal error occurred while creating a new port list. "
15428  "It is unclear whether the port list has been created or not. "
15429  "Diagnostics: Internal Error.",
15430  response_data);
15431  }
15432 
15433  if (entity_attribute (entity, "id"))
15434  params_add (params, "port_list_id", entity_attribute (entity, "id"));
15435  html = response_from_entity (connection, credentials, params, entity,
15436  "Create Port List", response_data);
15437  free_entity (entity);
15438  g_free (response);
15439  return html;
15440 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
param_t * params_add(params_t *params, const char *name, const char *value)
Add a param.
Definition: gsad_base.c:318

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmpf(), gsad_message(), params_add(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ create_port_range_gmp()

char* create_port_range_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Add a range to a port list, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 15453 of file gsad_gmp.c.

15455 {
15456  int ret;
15457  gchar *html, *response;
15458  const char *port_list_id, *start, *end, *type;
15459  entity_t entity;
15460 
15461  port_list_id = params_value (params, "port_list_id");
15462  start = params_value (params, "port_range_start");
15463  end = params_value (params, "port_range_end");
15464  type = params_value (params, "port_type");
15465 
15466  CHECK_VARIABLE_INVALID (port_list_id, "Create Port Range");
15467  CHECK_VARIABLE_INVALID (start, "Create Port Range");
15468  CHECK_VARIABLE_INVALID (end, "Create Port Range");
15469  CHECK_VARIABLE_INVALID (type, "Create Port Range");
15470 
15471  /* Create the port range. */
15472 
15473  response = NULL;
15474  entity = NULL;
15475  ret = gmpf (connection, credentials, &response, &entity, response_data,
15476  "<create_port_range>"
15477  "<port_list id=\"%s\"/>"
15478  "<start>%s</start>"
15479  "<end>%s</end>"
15480  "<type>%s</type>"
15481  "</create_port_range>",
15482  port_list_id, start, end, type);
15483 
15484  switch (ret)
15485  {
15486  case 0:
15487  case -1:
15488  break;
15489  case 1:
15490  cmd_response_data_set_status_code (response_data,
15491  MHD_HTTP_INTERNAL_SERVER_ERROR);
15492  return gsad_message (
15493  credentials, "Internal error", __FUNCTION__, __LINE__,
15494  "An internal error occurred while creating a Port Range. "
15495  "The Port Range was not created. "
15496  "Diagnostics: Failure to send command to manager daemon.",
15497  response_data);
15498  case 2:
15499  cmd_response_data_set_status_code (response_data,
15500  MHD_HTTP_INTERNAL_SERVER_ERROR);
15501  return gsad_message (
15502  credentials, "Internal error", __FUNCTION__, __LINE__,
15503  "An internal error occurred while creating a Port Range. "
15504  "It is unclear whether the Port Range has been created or not. "
15505  "Diagnostics: Failure to receive response from manager daemon.",
15506  response_data);
15507  default:
15508  cmd_response_data_set_status_code (response_data,
15509  MHD_HTTP_INTERNAL_SERVER_ERROR);
15510  return gsad_message (
15511  credentials, "Internal error", __FUNCTION__, __LINE__,
15512  "An internal error occurred while creating a Port Range. "
15513  "It is unclear whether the Port Range has been created or not. "
15514  "Diagnostics: Internal Error.",
15515  response_data);
15516  }
15517 
15518  html = response_from_entity (connection, credentials, params, entity,
15519  "Create Port Range", response_data);
15520  free_entity (entity);
15521  g_free (response);
15522  return html;
15523 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmpf(), gsad_message(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ create_report_gmp()

char* create_report_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Returns page to create a new container task.

Parameters
[in]connectionConnection to manager.
[in]credentialsCredentials of user issuing the action.
[in]paramsRequest parameters.
[in]messageIf not NULL, display message.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.Create a report, get all tasks, envelope the result.
Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 2245 of file gsad_gmp.c.

2247 {
2248  entity_t entity;
2249  int ret;
2250  gchar *command, *html, *response;
2251  const char *task_id, *name, *comment, *xml_file;
2252  const char *in_assets;
2253 
2254  task_id = params_value (params, "task_id");
2255  xml_file = params_value (params, "xml_file");
2256  name = params_value (params, "name");
2257  comment = params_value (params, "comment");
2258  in_assets = params_value (params, "in_assets");
2259 
2260  if (task_id == NULL)
2261  {
2262  CHECK_VARIABLE_INVALID (name, "Create Report");
2263  CHECK_VARIABLE_INVALID (comment, "Create Report");
2264  }
2265  CHECK_VARIABLE_INVALID (xml_file, "Create Report");
2266 
2267  if (params_given (params, "in_assets"))
2268  CHECK_VARIABLE_INVALID (xml_file, "Create Report");
2269 
2270  if (strlen (xml_file) == 0)
2271  {
2272  if (task_id)
2273  return message_invalid (connection, credentials, params, response_data,
2274  "Report required", "Create Report");
2275 
2276  /* Create only the container task. */
2277 
2278  command = g_markup_printf_escaped ("<create_task>"
2279  "<target id=\"0\"/>"
2280  "<name>%s</name>"
2281  "<comment>%s</comment>"
2282  "</create_task>",
2283  name, comment);
2284  }
2285  else
2286  {
2287  gchar **xml_file_array, *xml_file_escaped;
2288 
2289  xml_file_array = g_strsplit (xml_file, "%", -1);
2290  if (xml_file_array != NULL && xml_file_array[0] != NULL)
2291  xml_file_escaped = g_strjoinv ("%%", xml_file_array);
2292  else
2293  xml_file_escaped = g_strdup (xml_file);
2294  g_strfreev (xml_file_array);
2295 
2296  if (task_id)
2297  command =
2298  g_strdup_printf ("<create_report>"
2299  "<in_assets>%s</in_assets>"
2300  "<task id=\"%s\"/>"
2301  "%s"
2302  "</create_report>",
2303  in_assets ? in_assets : "0", task_id ? task_id : "0",
2304  xml_file_escaped ? xml_file_escaped : "");
2305  else
2306  {
2307  gchar *name_escaped, *comment_escaped;
2308  name_escaped = name ? g_markup_escape_text (name, -1) : NULL;
2309  comment_escaped = comment ? g_markup_escape_text (comment, -1) : NULL;
2310  command = g_strdup_printf ("<create_report>"
2311  "<in_assets>%s</in_assets>"
2312  "<task>"
2313  "<name>%s</name>"
2314  "<comment>%s</comment>"
2315  "</task>"
2316  "%s"
2317  "</create_report>",
2318  in_assets ? in_assets : "", name_escaped,
2319  comment_escaped, xml_file_escaped);
2320  g_free (name_escaped);
2321  g_free (comment_escaped);
2322  }
2323  g_free (xml_file_escaped);
2324  }
2325 
2326  ret =
2327  gmp (connection, credentials, &response, &entity, response_data, command);
2328  g_free (command);
2329 
2330  switch (ret)
2331  {
2332  case 0:
2333  break;
2334  case -1:
2335  /* 'gmp' set response. */
2336  return response;
2337  case 1:
2338  cmd_response_data_set_status_code (response_data,
2339  MHD_HTTP_INTERNAL_SERVER_ERROR);
2340  return gsad_message (
2341  credentials, "Internal error", __FUNCTION__, __LINE__,
2342  "An internal error occurred while creating a new report. "
2343  "No new report was created. "
2344  "Diagnostics: Failure to send command to manager daemon.",
2345  response_data);
2346  case 2:
2347  cmd_response_data_set_status_code (response_data,
2348  MHD_HTTP_INTERNAL_SERVER_ERROR);
2349  return gsad_message (
2350  credentials, "Internal error", __FUNCTION__, __LINE__,
2351  "An internal error occurred while creating a new report. "
2352  "It is unclear whether the report has been created or not. "
2353  "Diagnostics: Failure to receive response from manager daemon.",
2354  response_data);
2355  default:
2356  cmd_response_data_set_status_code (response_data,
2357  MHD_HTTP_INTERNAL_SERVER_ERROR);
2358  return gsad_message (
2359  credentials, "Internal error", __FUNCTION__, __LINE__,
2360  "An internal error occurred while creating a new report. "
2361  "It is unclear whether the report has been created or not. "
2362  "Diagnostics: Internal Error.",
2363  response_data);
2364  }
2365 
2366  html = response_from_entity (connection, credentials, params, entity,
2367  "Import Report", response_data);
2368  free_entity (entity);
2369  g_free (response);
2370  return html;
2371 }
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
int params_given(params_t *params, const char *name)
Get whether a param was given at all.
Definition: gsad_base.c:189
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
gchar * message_invalid(gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data, const char *message, const char *op_name)
Check a param using the direct response method.
Definition: gsad_gmp.c:1004
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmp(), gsad_message(), message_invalid(), params_given(), params_value(), and response_from_entity().

Referenced by import_report_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_role_gmp()

char* create_role_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Create a role, get all roles, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 15817 of file gsad_gmp.c.

15819 {
15820  char *ret;
15821  gchar *response;
15822  const char *name, *comment, *users;
15823  entity_t entity;
15824 
15825  name = params_value (params, "name");
15826  comment = params_value (params, "comment");
15827  users = params_value (params, "users");
15828 
15829  CHECK_VARIABLE_INVALID (name, "Create Role");
15830  CHECK_VARIABLE_INVALID (comment, "Create Role");
15831  CHECK_VARIABLE_INVALID (users, "Create Role");
15832 
15833  response = NULL;
15834  entity = NULL;
15835  switch (gmpf (connection, credentials, &response, &entity, response_data,
15836  "<create_role>"
15837  "<name>%s</name>"
15838  "<comment>%s</comment>"
15839  "<users>%s</users>"
15840  "</create_role>",
15841  name, comment, users))
15842  {
15843  case 0:
15844  case -1:
15845  break;
15846  case 1:
15847  cmd_response_data_set_status_code (response_data,
15848  MHD_HTTP_INTERNAL_SERVER_ERROR);
15849  return gsad_message (
15850  credentials, "Internal error", __FUNCTION__, __LINE__,
15851  "An internal error occurred while creating a new role. "
15852  "No new role was created. "
15853  "Diagnostics: Failure to send command to manager daemon.",
15854  response_data);
15855  case 2:
15856  cmd_response_data_set_status_code (response_data,
15857  MHD_HTTP_INTERNAL_SERVER_ERROR);
15858  return gsad_message (
15859  credentials, "Internal error", __FUNCTION__, __LINE__,
15860  "An internal error occurred while creating a new role. "
15861  "It is unclear whether the role has been created or not. "
15862  "Diagnostics: Failure to receive response from manager daemon.",
15863  response_data);
15864  default:
15865  cmd_response_data_set_status_code (response_data,
15866  MHD_HTTP_INTERNAL_SERVER_ERROR);
15867  return gsad_message (
15868  credentials, "Internal error", __FUNCTION__, __LINE__,
15869  "An internal error occurred while creating a new role. "
15870  "It is unclear whether the role has been created or not. "
15871  "Diagnostics: Internal Error.",
15872  response_data);
15873  }
15874 
15875  if (entity_attribute (entity, "id"))
15876  params_add (params, "role_id", entity_attribute (entity, "id"));
15877  ret = response_from_entity (connection, credentials, params, entity,
15878  "Create Role", response_data);
15879  free_entity (entity);
15880  g_free (response);
15881  return ret;
15882 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
GPtrArray * users
User session data.
Definition: gsad_session.c:39
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
param_t * params_add(params_t *params, const char *name, const char *value)
Add a param.
Definition: gsad_base.c:318

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmpf(), gsad_message(), params_add(), params_value(), response_from_entity(), and users.

Here is the call graph for this function:

◆ create_scanner_gmp()

char* create_scanner_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Create a scanner, get all scanners, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 11692 of file gsad_gmp.c.

11694 {
11695  int ret;
11696  char *html;
11697  gchar *response = NULL;
11698  const char *name, *comment, *host, *port, *type, *ca_pub, *credential_id;
11699  entity_t entity = NULL;
11700 
11701  name = params_value (params, "name");
11702  comment = params_value (params, "comment");
11703  host = params_value (params, "scanner_host");
11704  port = params_value (params, "port");
11705  type = params_value (params, "scanner_type");
11706  ca_pub = params_value (params, "ca_pub");
11707  credential_id = params_value (params, "credential_id");
11708  CHECK_VARIABLE_INVALID (name, "Create Scanner");
11709  CHECK_VARIABLE_INVALID (comment, "Create Scanner");
11710  CHECK_VARIABLE_INVALID (host, "Create Scanner");
11711  CHECK_VARIABLE_INVALID (port, "Create Scanner");
11712  CHECK_VARIABLE_INVALID (type, "Create Scanner");
11713  if (params_given (params, "ca_pub"))
11714  CHECK_VARIABLE_INVALID (ca_pub, "Create Scanner");
11715  CHECK_VARIABLE_INVALID (credential_id, "Create Scanner");
11716 
11717  if (ca_pub)
11718  ret = gmpf (connection, credentials, &response, &entity, response_data,
11719  "<create_scanner>"
11720  "<name>%s</name><comment>%s</comment>"
11721  "<host>%s</host><port>%s</port><type>%s</type>"
11722  "<ca_pub>%s</ca_pub>"
11723  "<credential id=\"%s\"/>"
11724  "</create_scanner>",
11725  name, comment, host, port, type, ca_pub, credential_id);
11726  else
11727  ret = gmpf (connection, credentials, &response, &entity, response_data,
11728  "<create_scanner>"
11729  "<name>%s</name><comment>%s</comment>"
11730  "<host>%s</host><port>%s</port><type>%s</type>"
11731  "<credential id=\"%s\"/>"
11732  "</create_scanner>",
11733  name, comment, host, port, type, credential_id);
11734  switch (ret)
11735  {
11736  case 0:
11737  case -1:
11738  break;
11739  case 1:
11740  cmd_response_data_set_status_code (response_data,
11741  MHD_HTTP_INTERNAL_SERVER_ERROR);
11742  return gsad_message (
11743  credentials, "Internal error", __FUNCTION__, __LINE__,
11744  "An internal error occurred while creating a new scanner. "
11745  "No new scanner was created. "
11746  "Diagnostics: Failure to send command to manager daemon.",
11747  response_data);
11748  case 2:
11749  cmd_response_data_set_status_code (response_data,
11750  MHD_HTTP_INTERNAL_SERVER_ERROR);
11751  return gsad_message (
11752  credentials, "Internal error", __FUNCTION__, __LINE__,
11753  "An internal error occurred while creating a new scanner. "
11754  "It is unclear whether the scanner has been created or not. "
11755  "Diagnostics: Failure to receive response from manager daemon.",
11756  response_data);
11757  default:
11758  cmd_response_data_set_status_code (response_data,
11759  MHD_HTTP_INTERNAL_SERVER_ERROR);
11760  return gsad_message (
11761  credentials, "Internal error", __FUNCTION__, __LINE__,
11762  "An internal error occurred while creating a new scanner. "
11763  "It is unclear whether the scanner has been created or not. "
11764  "Diagnostics: Internal Error.",
11765  response_data);
11766  }
11767 
11768  if (entity_attribute (entity, "id"))
11769  params_add (params, "scanner_id", entity_attribute (entity, "id"));
11770  html = response_from_entity (connection, credentials, params, entity,
11771  "Create Scanner", response_data);
11772  free_entity (entity);
11773  g_free (response);
11774  return html;
11775 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
int params_given(params_t *params, const char *name)
Get whether a param was given at all.
Definition: gsad_base.c:189
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
param_t * params_add(params_t *params, const char *name, const char *value)
Add a param.
Definition: gsad_base.c:318

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmpf(), gsad_message(), params_add(), params_given(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ create_schedule_gmp()

char* create_schedule_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Create a schedule, get all schedules, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 12038 of file gsad_gmp.c.

12040 {
12041  char *ret;
12042  gchar *response;
12043  const char *name, *comment, *timezone, *icalendar;
12044  entity_t entity;
12045 
12046  name = params_value (params, "name");
12047  comment = params_value (params, "comment");
12048  timezone = params_value (params, "timezone");
12049  icalendar = params_value (params, "icalendar");
12050 
12051  CHECK_VARIABLE_INVALID (name, "Create Schedule");
12052  CHECK_VARIABLE_INVALID (comment, "Create Schedule");
12053  CHECK_VARIABLE_INVALID (timezone, "Create Schedule");
12054  CHECK_VARIABLE_INVALID (icalendar, "Create Schedule");
12055 
12056  response = NULL;
12057  entity = NULL;
12058  switch (gmpf (connection, credentials, &response, &entity, response_data,
12059  "<create_schedule>"
12060  "<name>%s</name>"
12061  "<comment>%s</comment>"
12062  "<timezone>%s</timezone>"
12063  "<icalendar>%s</icalendar>"
12064  "</create_schedule>",
12065  name, comment, timezone, icalendar))
12066  {
12067  case 0:
12068  case -1:
12069  break;
12070  case 1:
12071  cmd_response_data_set_status_code (response_data,
12072  MHD_HTTP_INTERNAL_SERVER_ERROR);
12073  return gsad_message (
12074  credentials, "Internal error", __FUNCTION__, __LINE__,
12075  "An internal error occurred while creating a new schedule. "
12076  "No new schedule was created. "
12077  "Diagnostics: Failure to send command to manager daemon.",
12078  response_data);
12079  case 2:
12080  cmd_response_data_set_status_code (response_data,
12081  MHD_HTTP_INTERNAL_SERVER_ERROR);
12082  return gsad_message (
12083  credentials, "Internal error", __FUNCTION__, __LINE__,
12084  "An internal error occurred while creating a new schedule. "
12085  "It is unclear whether the schedule has been created or not. "
12086  "Diagnostics: Failure to receive response from manager daemon.",
12087  response_data);
12088  default:
12089  cmd_response_data_set_status_code (response_data,
12090  MHD_HTTP_INTERNAL_SERVER_ERROR);
12091  return gsad_message (
12092  credentials, "Internal error", __FUNCTION__, __LINE__,
12093  "An internal error occurred while creating a new schedule. "
12094  "It is unclear whether the schedule has been created or not. "
12095  "Diagnostics: Internal Error.",
12096  response_data);
12097  }
12098 
12099  if (entity_attribute (entity, "id"))
12100  params_add (params, "schedule_id", entity_attribute (entity, "id"));
12101  ret = response_from_entity (connection, credentials, params, entity,
12102  "Create Schedule", response_data);
12103  free_entity (entity);
12104  g_free (response);
12105  return ret;
12106 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
param_t * params_add(params_t *params, const char *name, const char *value)
Add a param.
Definition: gsad_base.c:318

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmpf(), gsad_message(), params_add(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ create_tag_gmp()

char* create_tag_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Create a tag, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 7095 of file gsad_gmp.c.

7097 {
7098  char *ret;
7099  gchar *response;
7100  const char *name, *comment, *filter, *value, *resource_type, *active;
7101  params_t *resource_ids;
7102  GString *command;
7103  entity_t entity;
7104 
7105  name = params_value (params, "tag_name");
7106  comment = params_value (params, "comment");
7107  filter = params_value (params, "filter");
7108  value = params_value (params, "tag_value");
7109  resource_type = params_value (params, "resource_type");
7110  resource_ids = params_values (params, "resource_ids:");
7111  active = params_value (params, "active");
7112 
7113  CHECK_VARIABLE_INVALID (name, "Create Tags")
7114  CHECK_VARIABLE_INVALID (comment, "Create Tags")
7115  if (params_given (params, "filter"))
7116  CHECK_VARIABLE_INVALID (filter, "Create Tags")
7117  CHECK_VARIABLE_INVALID (value, "Create Tags")
7118  CHECK_VARIABLE_INVALID (resource_type, "Create Tags")
7119  CHECK_VARIABLE_INVALID (active, "Create Tags")
7120 
7121  command = g_string_new ("");
7122 
7123  xml_string_append (command,
7124  "<create_tag>"
7125  "<name>%s</name>"
7126  "<comment>%s</comment>"
7127  "<value>%s</value>"
7128  "<active>%s</active>"
7129  "<resources filter=\"%s\">"
7130  "<type>%s</type>",
7131  name, comment, value, active, filter ? filter : "",
7132  resource_type);
7133 
7134  if (resource_ids)
7135  {
7136  params_iterator_t iter;
7137  char *name;
7138  param_t *param;
7139 
7140  params_iterator_init (&iter, resource_ids);
7141  while (params_iterator_next (&iter, &name, &param))
7142  if (param->value && strcmp (param->value, "0"))
7143  g_string_append_printf (command, "<resource id=\"%s\"/>",
7144  param->value ? param->value : "");
7145  }
7146 
7147  xml_string_append (command, "</resources>"
7148  "</create_tag>");
7149 
7150  response = NULL;
7151  entity = NULL;
7152  switch (gmp (connection, credentials, &response, &entity, response_data,
7153  command->str))
7154  {
7155  case 0:
7156  case -1:
7157  break;
7158  case 1:
7159  cmd_response_data_set_status_code (response_data,
7160  MHD_HTTP_INTERNAL_SERVER_ERROR);
7161  g_string_free (command, TRUE);
7162  return gsad_message (
7163  credentials, "Internal error", __FUNCTION__, __LINE__,
7164  "An internal error occurred while creating a new tag. "
7165  "No new tag was created. "
7166  "Diagnostics: Failure to send command to manager daemon.",
7167  response_data);
7168  case 2:
7169  cmd_response_data_set_status_code (response_data,
7170  MHD_HTTP_INTERNAL_SERVER_ERROR);
7171  g_string_free (command, TRUE);
7172  return gsad_message (
7173  credentials, "Internal error", __FUNCTION__, __LINE__,
7174  "An internal error occurred while creating a new tag. "
7175  "It is unclear whether the tag has been created or not. "
7176  "Diagnostics: Failure to receive response from manager daemon.",
7177  response_data);
7178  default:
7179  cmd_response_data_set_status_code (response_data,
7180  MHD_HTTP_INTERNAL_SERVER_ERROR);
7181  g_string_free (command, TRUE);
7182  return gsad_message (
7183  credentials, "Internal error", __FUNCTION__, __LINE__,
7184  "An internal error occurred while creating a new tag. "
7185  "It is unclear whether the tag has been created or not. "
7186  "Diagnostics: Internal Error.",
7187  response_data);
7188  }
7189 
7190  g_string_free (command, TRUE);
7191  ret = response_from_entity (connection, credentials, params, entity,
7192  "Create Tag", response_data);
7193 
7194  free_entity (entity);
7195  g_free (response);
7196  return ret;
7197 }
params_t * params_values(params_t *params, const char *name)
Get values of param.
Definition: gsad_base.c:287
gchar * value
Definition: gsad_params.h:40
Structure of credential related information.
#define params_iterator_t
Definition: gsad_params.h:94
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
int params_given(params_t *params, const char *name)
Get whether a param was given at all.
Definition: gsad_base.c:189
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
Request parameter.
Definition: gsad_params.h:38
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
gboolean params_iterator_next(params_iterator_t *iterator, char **name, param_t **param)
Increment a params iterator.
Definition: gsad_base.c:394
#define params_iterator_init
Definition: gsad_params.h:96
#define params_t
Definition: gsad_params.h:31
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmp(), gsad_message(), params_given(), params_iterator_init, params_iterator_next(), params_iterator_t, params_t, params_value(), params_values(), response_from_entity(), and param::value.

Here is the call graph for this function:

◆ create_target_gmp()

char* create_target_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Create a target, get all targets, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 6668 of file gsad_gmp.c.

6670 {
6671  int ret;
6672  gchar *html, *response, *command;
6673  const char *name, *hosts, *exclude_hosts, *comment;
6674  const char *target_ssh_credential, *port, *target_smb_credential;
6675  const char *target_esxi_credential, *target_snmp_credential, *target_source;
6676  const char *target_exclude_source;
6677  const char *port_list_id, *reverse_lookup_only, *reverse_lookup_unify;
6678  const char *alive_tests, *hosts_filter, *file, *exclude_file;
6679  gchar *ssh_credentials_element, *smb_credentials_element;
6680  gchar *esxi_credentials_element, *snmp_credentials_element;
6681  gchar *asset_hosts_element;
6682  gchar *comment_element = NULL;
6683  entity_t entity;
6684  GString *xml;
6685 
6686  name = params_value (params, "name");
6687  hosts = params_value (params, "hosts");
6688  exclude_hosts = params_value (params, "exclude_hosts");
6689  reverse_lookup_only = params_value (params, "reverse_lookup_only");
6690  reverse_lookup_unify = params_value (params, "reverse_lookup_unify");
6691  target_source = params_value (params, "target_source");
6692  target_exclude_source = params_value (params, "target_exclude_source");
6693  comment = params_value (params, "comment");
6694  port_list_id = params_value (params, "port_list_id");
6695  target_ssh_credential = params_value (params, "ssh_credential_id");
6696  port = params_value (params, "port");
6697  target_smb_credential = params_value (params, "smb_credential_id");
6698  target_esxi_credential = params_value (params, "esxi_credential_id");
6699  target_snmp_credential = params_value (params, "snmp_credential_id");
6700  alive_tests = params_value (params, "alive_tests");
6701  hosts_filter = params_value (params, "hosts_filter");
6702  file = params_value (params, "file");
6703  exclude_file = params_value (params, "exclude_file");
6704 
6705  CHECK_VARIABLE_INVALID (name, "Create Target");
6706  CHECK_VARIABLE_INVALID (target_source, "Create Target")
6707  if (strcmp (target_source, "manual") == 0)
6708  CHECK_VARIABLE_INVALID (hosts, "Create Target");
6709  if (strcmp (target_source, "file") == 0)
6710  CHECK_VARIABLE_INVALID (file, "Create Target")
6711  /* require hosts_filter if target_source is "asset_hosts" */
6712  if (strcmp (target_source, "asset_hosts") == 0)
6713  CHECK_VARIABLE_INVALID (hosts_filter, "Create Target");
6714 
6715  if (params_given (params, "target_exclude_source"))
6716  {
6717  CHECK_VARIABLE_INVALID (target_exclude_source, "Create Target")
6718  if (strcmp (target_exclude_source, "manual") == 0
6719  /* In case browser doesn't send empty field. */
6720  && params_given (params, "exclude_hosts"))
6721  CHECK_VARIABLE_INVALID (exclude_hosts, "Create Target");
6722  if (strcmp (target_exclude_source, "file") == 0)
6723  CHECK_VARIABLE_INVALID (exclude_file, "Create Target");
6724  }
6725 
6726  CHECK_VARIABLE_INVALID (comment, "Create Target");
6727  CHECK_VARIABLE_INVALID (port_list_id, "Create Target");
6728  CHECK_VARIABLE_INVALID (target_ssh_credential, "Create Target");
6729  if (strcmp (target_ssh_credential, "--"))
6730  CHECK_VARIABLE_INVALID (port, "Create Target");
6731  CHECK_VARIABLE_INVALID (target_smb_credential, "Create Target");
6732  CHECK_VARIABLE_INVALID (target_esxi_credential, "Create Target");
6733  CHECK_VARIABLE_INVALID (target_snmp_credential, "Create Target");
6734  CHECK_VARIABLE_INVALID (alive_tests, "Create Target");
6735 
6736  if (comment != NULL)
6737  comment_element = g_strdup_printf ("<comment>%s</comment>", comment);
6738  else
6739  comment_element = g_strdup ("");
6740 
6741  if (strcmp (target_ssh_credential, "0") == 0)
6742  ssh_credentials_element = g_strdup ("");
6743  else
6744  ssh_credentials_element = g_strdup_printf ("<ssh_credential id=\"%s\">"
6745  "<port>%s</port>"
6746  "</ssh_credential>",
6747  target_ssh_credential, port);
6748 
6749  if (strcmp (target_smb_credential, "0") == 0)
6750  smb_credentials_element = g_strdup ("");
6751  else
6752  smb_credentials_element =
6753  g_strdup_printf ("<smb_credential id=\"%s\"/>", target_smb_credential);
6754 
6755  if (strcmp (target_esxi_credential, "0") == 0)
6756  esxi_credentials_element = g_strdup ("");
6757  else
6758  esxi_credentials_element =
6759  g_strdup_printf ("<esxi_credential id=\"%s\"/>", target_esxi_credential);
6760 
6761  if (strcmp (target_snmp_credential, "0") == 0)
6762  snmp_credentials_element = g_strdup ("");
6763  else
6764  snmp_credentials_element =
6765  g_strdup_printf ("<snmp_credential id=\"%s\"/>", target_snmp_credential);
6766 
6767  if (strcmp (target_source, "asset_hosts") == 0)
6768  asset_hosts_element = g_markup_printf_escaped ("<asset_hosts"
6769  " filter=\"%s\"/>",
6770  hosts_filter);
6771  else
6772  asset_hosts_element = g_strdup ("");
6773 
6774  /* Create the target. */
6775 
6776  xml = g_string_new ("");
6777 
6778  xml_string_append (xml,
6779  "<name>%s</name>"
6780  "<hosts>%s</hosts>"
6781  "<exclude_hosts>%s</exclude_hosts>"
6782  "<reverse_lookup_only>%s</reverse_lookup_only>"
6783  "<reverse_lookup_unify>%s</reverse_lookup_unify>"
6784  "<port_list id=\"%s\"/>"
6785  "<alive_tests>%s</alive_tests>",
6786  name, strcmp (target_source, "file") == 0 ? file : hosts,
6787  target_exclude_source
6788  ? (strcmp (target_exclude_source, "file") == 0
6789  ? exclude_file
6790  : (exclude_hosts ? exclude_hosts : ""))
6791  : "",
6792  reverse_lookup_only ? reverse_lookup_only : "0",
6793  reverse_lookup_unify ? reverse_lookup_unify : "0",
6794  port_list_id, alive_tests);
6795 
6796  command = g_strdup_printf ("<create_target>"
6797  "%s%s%s%s%s%s%s"
6798  "</create_target>",
6799  xml->str, comment_element, ssh_credentials_element,
6800  smb_credentials_element, esxi_credentials_element,
6801  snmp_credentials_element, asset_hosts_element);
6802 
6803  g_string_free (xml, TRUE);
6804  g_free (comment_element);
6805  g_free (ssh_credentials_element);
6806  g_free (smb_credentials_element);
6807  g_free (esxi_credentials_element);
6808 
6809  ret =
6810  gmp (connection, credentials, &response, &entity, response_data, command);
6811  g_free (command);
6812  switch (ret)
6813  {
6814  case 0:
6815  break;
6816  case -1:
6817  /* 'gmp' set response. */
6818  return response;
6819  case 1:
6820  cmd_response_data_set_status_code (response_data,
6821  MHD_HTTP_INTERNAL_SERVER_ERROR);
6822  return gsad_message (
6823  credentials, "Internal error", __FUNCTION__, __LINE__,
6824  "An internal error occurred while creating a new target. "
6825  "No new target was created. "
6826  "Diagnostics: Failure to send command to manager daemon.",
6827  response_data);
6828  case 2:
6829  cmd_response_data_set_status_code (response_data,
6830  MHD_HTTP_INTERNAL_SERVER_ERROR);
6831  return gsad_message (
6832  credentials, "Internal error", __FUNCTION__, __LINE__,
6833  "An internal error occurred while creating a new target. "
6834  "It is unclear whether the target has been created or not. "
6835  "Diagnostics: Failure to receive response from manager daemon.",
6836  response_data);
6837  default:
6838  cmd_response_data_set_status_code (response_data,
6839  MHD_HTTP_INTERNAL_SERVER_ERROR);
6840  return gsad_message (
6841  credentials, "Internal error", __FUNCTION__, __LINE__,
6842  "An internal error occurred while creating a new target. "
6843  "It is unclear whether the target has been created or not. "
6844  "Diagnostics: Internal Error.",
6845  response_data);
6846  }
6847 
6848  if (entity_attribute (entity, "id"))
6849  params_add (params, "target_id", entity_attribute (entity, "id"));
6850  html = response_from_entity (connection, credentials, params, entity,
6851  "Create Target", response_data);
6852  free_entity (entity);
6853  g_free (response);
6854  return html;
6855 }
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
int params_given(params_t *params, const char *name)
Get whether a param was given at all.
Definition: gsad_base.c:189
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
param_t * params_add(params_t *params, const char *name, const char *value)
Add a param.
Definition: gsad_base.c:318

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmp(), gsad_message(), params_add(), params_given(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ create_task_gmp()

char* create_task_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Create a task, get all tasks, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 2481 of file gsad_gmp.c.

2483 {
2484  entity_t entity;
2485  int ret;
2486  gchar *schedule_element, *command;
2487  gchar *response, *html;
2488  const char *name, *comment, *config_id, *target_id, *scanner_type;
2489  const char *scanner_id, *schedule_id, *schedule_periods;
2490  const char *max_checks, *max_hosts;
2491  const char *in_assets, *hosts_ordering, *alterable, *source_iface;
2492  const char *add_tag, *tag_id, *auto_delete, *auto_delete_data;
2493  const char *apply_overrides, *min_qod;
2494  gchar *name_escaped, *comment_escaped;
2495  params_t *alerts;
2496  GString *alert_element;
2497 
2498  add_tag = params_value (params, "add_tag");
2499  alterable = params_value (params, "alterable");
2500  apply_overrides = params_value (params, "apply_overrides");
2501  auto_delete = params_value (params, "auto_delete");
2502  auto_delete_data = params_value (params, "auto_delete_data");
2503  comment = params_value (params, "comment");
2504  config_id = params_value (params, "config_id");
2505  hosts_ordering = params_value (params, "hosts_ordering");
2506  in_assets = params_value (params, "in_assets");
2507  max_checks = params_value (params, "max_checks");
2508  max_hosts = params_value (params, "max_hosts");
2509  min_qod = params_value (params, "min_qod");
2510  name = params_value (params, "name");
2511  scanner_id = params_value (params, "scanner_id");
2512  scanner_type = params_value (params, "scanner_type");
2513  schedule_id = params_value (params, "schedule_id");
2514  schedule_periods = params_value (params, "schedule_periods");
2515  source_iface = params_value (params, "source_iface");
2516  tag_id = params_value (params, "tag_id");
2517  target_id = params_value (params, "target_id");
2518 
2519  CHECK_VARIABLE_INVALID (scanner_type, "Create Task");
2520  if (!strcmp (scanner_type, "1"))
2521  {
2522  hosts_ordering = "";
2523  max_checks = "";
2524  source_iface = "";
2525  max_hosts = "";
2526  }
2527  else if (!strcmp (scanner_type, "3"))
2528  {
2529  config_id = "";
2530  hosts_ordering = "";
2531  max_checks = "";
2532  source_iface = "";
2533  max_hosts = "";
2534  }
2535 
2536  CHECK_VARIABLE_INVALID (name, "Create Task");
2537  CHECK_VARIABLE_INVALID (comment, "Create Task");
2538  CHECK_VARIABLE_INVALID (config_id, "Create Task");
2539  CHECK_VARIABLE_INVALID (target_id, "Create Task");
2540  CHECK_VARIABLE_INVALID (hosts_ordering, "Create Task");
2541  CHECK_VARIABLE_INVALID (scanner_id, "Create Task");
2542  CHECK_VARIABLE_INVALID (schedule_id, "Create Task");
2543 
2544  if (str_equal (target_id, "0"))
2545  {
2546  /* Don't allow to create container task via create_task */
2547  return message_invalid (connection, credentials, params, response_data,
2548  "Given target_id was invalid", "Create Task");
2549  }
2550 
2551  if (params_given (params, "schedule_periods"))
2552  {
2553  CHECK_VARIABLE_INVALID (schedule_periods, "Create Task");
2554  }
2555  else
2556  schedule_periods = "0";
2557 
2558  CHECK_VARIABLE_INVALID (in_assets, "Create Task");
2559 
2560  if (!strcmp (in_assets, "1"))
2561  {
2562  CHECK_VARIABLE_INVALID (apply_overrides, "Create Task");
2563  CHECK_VARIABLE_INVALID (min_qod, "Create Task");
2564  }
2565  else
2566  {
2567  if (!params_given (params, "apply_overrides")
2568  || !params_valid (params, "apply_overrides"))
2569  apply_overrides = "";
2570 
2571  if (!params_given (params, "min_qod")
2572  || !params_valid (params, "min_qod"))
2573  min_qod = "";
2574  }
2575 
2576  CHECK_VARIABLE_INVALID (max_checks, "Create Task");
2577  CHECK_VARIABLE_INVALID (source_iface, "Create Task");
2578  CHECK_VARIABLE_INVALID (auto_delete, "Create Task");
2579  CHECK_VARIABLE_INVALID (auto_delete_data, "Create Task");
2580  CHECK_VARIABLE_INVALID (max_hosts, "Create Task");
2581  CHECK_VARIABLE_INVALID (alterable, "Create Task");
2582 
2583  if (add_tag && strcmp (add_tag, "1") == 0)
2584  {
2585  CHECK_VARIABLE_INVALID (tag_id, "Create Task");
2586  }
2587 
2588  if (schedule_id == NULL || strcmp (schedule_id, "0") == 0)
2589  schedule_element = g_strdup ("");
2590  else
2591  schedule_element = g_strdup_printf ("<schedule id=\"%s\"/>", schedule_id);
2592 
2593  alert_element = g_string_new ("");
2594  if (params_given (params, "alert_id_optional:"))
2595  alerts = params_values (params, "alert_id_optional:");
2596  else
2597  alerts = params_values (params, "alert_ids:");
2598 
2599  if (alerts)
2600  {
2601  params_iterator_t iter;
2602  char *name;
2603  param_t *param;
2604 
2605  params_iterator_init (&iter, alerts);
2606  while (params_iterator_next (&iter, &name, &param))
2607  if (param->value && strcmp (param->value, "0"))
2608  g_string_append_printf (alert_element, "<alert id=\"%s\"/>",
2609  param->value ? param->value : "");
2610  }
2611 
2612  name_escaped = name ? g_markup_escape_text (name, -1) : NULL;
2613  comment_escaped = comment ? g_markup_escape_text (comment, -1) : NULL;
2614 
2615  command = g_strdup_printf (
2616  "<create_task>"
2617  "<config id=\"%s\"/>"
2618  "<schedule_periods>%s</schedule_periods>"
2619  "%s%s"
2620  "<target id=\"%s\"/>"
2621  "<scanner id=\"%s\"/>"
2622  "<hosts_ordering>%s</hosts_ordering>"
2623  "<name>%s</name>"
2624  "<comment>%s</comment>"
2625  "<preferences>"
2626  "<preference>"
2627  "<scanner_name>max_checks</scanner_name>"
2628  "<value>%s</value>"
2629  "</preference>"
2630  "<preference>"
2631  "<scanner_name>max_hosts</scanner_name>"
2632  "<value>%s</value>"
2633  "</preference>"
2634  "<preference>"
2635  "<scanner_name>in_assets</scanner_name>"
2636  "<value>%s</value>"
2637  "</preference>"
2638  "<preference>"
2639  "<scanner_name>"
2640  "assets_apply_overrides"
2641  "</scanner_name>"
2642  "<value>%s</value>"
2643  "</preference>"
2644  "<preference>"
2645  "<scanner_name>assets_min_qod</scanner_name>"
2646  "<value>%s</value>"
2647  "</preference>"
2648  "<preference>"
2649  "<scanner_name>source_iface</scanner_name>"
2650  "<value>%s</value>"
2651  "</preference>"
2652  "<preference>"
2653  "<scanner_name>auto_delete</scanner_name>"
2654  "<value>%s</value>"
2655  "</preference>"
2656  "<preference>"
2657  "<scanner_name>auto_delete_data</scanner_name>"
2658  "<value>%s</value>"
2659  "</preference>"
2660  "</preferences>"
2661  "<alterable>%i</alterable>"
2662  "</create_task>",
2663  config_id, schedule_periods, schedule_element, alert_element->str,
2664  target_id, scanner_id, hosts_ordering, name_escaped, comment_escaped,
2665  max_checks, max_hosts, strcmp (in_assets, "0") ? "yes" : "no",
2666  strcmp (apply_overrides, "0") ? "yes" : "no", min_qod, source_iface,
2667  auto_delete, auto_delete_data, alterable ? strcmp (alterable, "0") : 0);
2668 
2669  g_free (name_escaped);
2670  g_free (comment_escaped);
2671 
2672  ret =
2673  gmp (connection, credentials, &response, &entity, response_data, command);
2674  g_free (command);
2675 
2676  g_free (schedule_element);
2677  g_string_free (alert_element, TRUE);
2678 
2679  switch (ret)
2680  {
2681  case 0:
2682  break;
2683  case -1:
2684  /* 'gmp' set response. */
2685  return response;
2686  case 1:
2687  cmd_response_data_set_status_code (response_data,
2688  MHD_HTTP_INTERNAL_SERVER_ERROR);
2689  return gsad_message (
2690  credentials, "Internal error", __FUNCTION__, __LINE__,
2691  "An internal error occurred while creating a new task. "
2692  "No new task was created. "
2693  "Diagnostics: Failure to send command to manager daemon.",
2694  response_data);
2695  case 2:
2696  cmd_response_data_set_status_code (response_data,
2697  MHD_HTTP_INTERNAL_SERVER_ERROR);
2698  return gsad_message (
2699  credentials, "Internal error", __FUNCTION__, __LINE__,
2700  "An internal error occurred while creating a new task. "
2701  "It is unclear whether the task has been created or not. "
2702  "Diagnostics: Failure to receive response from manager daemon.",
2703  response_data);
2704  default:
2705  cmd_response_data_set_status_code (response_data,
2706  MHD_HTTP_INTERNAL_SERVER_ERROR);
2707  return gsad_message (
2708  credentials, "Internal error", __FUNCTION__, __LINE__,
2709  "An internal error occurred while creating a new task. "
2710  "It is unclear whether the task has been created or not. "
2711  "Diagnostics: Internal Error.",
2712  response_data);
2713  }
2714 
2715  if (gmp_success (entity))
2716  {
2717  if (add_tag && strcmp (add_tag, "1") == 0)
2718  {
2719  const char *new_task_id = entity_attribute (entity, "id");
2720  gchar *tag_command, *tag_response;
2721  entity_t tag_entity;
2722 
2723  tag_command = g_markup_printf_escaped ("<modify_tag tag_id=\"%s\">"
2724  "<resources action=\"add\">"
2725  "<resource id=\"%s\"/>"
2726  "</resources>"
2727  "</modify_tag>",
2728  tag_id, new_task_id);
2729 
2730  ret = gmp (connection, credentials, &tag_response, &tag_entity,
2731  response_data, tag_command);
2732 
2733  switch (ret)
2734  {
2735  case 0:
2736  case -1:
2737  break;
2738  case 1:
2739  free_entity (entity);
2740  g_free (response);
2742  response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
2743  return gsad_message (
2744  credentials, "Internal error", __FUNCTION__, __LINE__,
2745  "An internal error occurred while creating a new tag. "
2746  "No new tag was created. "
2747  "Diagnostics: Failure to send command to manager daemon.",
2748  response_data);
2749  case 2:
2750  free_entity (entity);
2751  g_free (response);
2753  response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
2754  return gsad_message (
2755  credentials, "Internal error", __FUNCTION__, __LINE__,
2756  "An internal error occurred while creating a new tag. "
2757  "It is unclear whether the tag has been created or not. "
2758  "Diagnostics: Failure to receive response from manager daemon.",
2759  response_data);
2760  default:
2761  free_entity (entity);
2762  g_free (response);
2764  response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
2765  return gsad_message (
2766  credentials, "Internal error", __FUNCTION__, __LINE__,
2767  "An internal error occurred while creating a new task. "
2768  "It is unclear whether the tag has been created or not. "
2769  "Diagnostics: Internal Error.",
2770  response_data);
2771  }
2772 
2773  if (entity_attribute (entity, "id"))
2774  params_add (params, "task_id", entity_attribute (entity, "id"));
2775  html =
2776  response_from_entity (connection, credentials, params, tag_entity,
2777  "Create Task and Tag", response_data);
2778  free_entity (tag_entity);
2779  g_free (tag_response);
2780  }
2781  else
2782  {
2783  if (entity_attribute (entity, "id"))
2784  params_add (params, "task_id", entity_attribute (entity, "id"));
2785  html = response_from_entity (connection, credentials, params, entity,
2786  "Create Task", response_data);
2787  }
2788  }
2789  else
2790  {
2791  html = response_from_entity (connection, credentials, params, entity,
2792  "Create Task", response_data);
2793  }
2794  free_entity (entity);
2795  g_free (response);
2796  return html;
2797 }
params_t * params_values(params_t *params, const char *name)
Get values of param.
Definition: gsad_base.c:287
gchar * value
Definition: gsad_params.h:40
static int gmp_success(entity_t entity)
Check whether an GMP command failed.
Definition: gsad_gmp.c:656
Structure of credential related information.
gboolean str_equal(const gchar *str1, const gchar *str2)
Check if two strings are equal.
Definition: utils.c:35
#define params_iterator_t
Definition: gsad_params.h:94
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
int params_given(params_t *params, const char *name)
Get whether a param was given at all.
Definition: gsad_base.c:189
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
gchar * message_invalid(gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data, const char *message, const char *op_name)
Check a param using the direct response method.
Definition: gsad_gmp.c:1004
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
Request parameter.
Definition: gsad_params.h:38
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
gboolean params_iterator_next(params_iterator_t *iterator, char **name, param_t **param)
Increment a params iterator.
Definition: gsad_base.c:394
#define params_iterator_init
Definition: gsad_params.h:96
#define params_t
Definition: gsad_params.h:31
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
param_t * params_add(params_t *params, const char *name, const char *value)
Add a param.
Definition: gsad_base.c:318
int params_valid(params_t *params, const char *name)
Get whether a param is valid.
Definition: gsad_base.c:303

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmp(), gmp_success(), gsad_message(), message_invalid(), params_add(), params_given(), params_iterator_init, params_iterator_next(), params_iterator_t, params_t, params_valid(), params_value(), params_values(), response_from_entity(), str_equal(), and param::value.

Here is the call graph for this function:

◆ create_ticket_gmp()

char* create_ticket_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Create a ticket.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 18983 of file gsad_gmp.c.

18985 {
18986  gchar *response = NULL;
18987  entity_t entity = NULL;
18988  const gchar *result_id, *user_id, *note;
18989  char *ret;
18990 
18991  result_id = params_value (params, "result_id");
18992  user_id = params_value (params, "user_id");
18993  note = params_value (params, "note");
18994 
18995  CHECK_VARIABLE_INVALID (result_id, "Create Ticket");
18996  CHECK_VARIABLE_INVALID (user_id, "Create Ticket");
18997  CHECK_VARIABLE_INVALID (note, "Create Ticket")
18998 
18999  switch (gmpf (connection, credentials, &response, &entity, response_data,
19000  "<create_ticket>"
19001  "<result id=\"%s\"/>"
19002  "<assigned_to>"
19003  "<user id=\"%s\"/>"
19004  "</assigned_to>"
19005  "<open_note>%s</open_note>"
19006  "</create_ticket>",
19007  result_id, user_id, note ? note : ""))
19008  {
19009  case 0:
19010  case -1:
19011  break;
19012  case 1:
19013  cmd_response_data_set_status_code (response_data,
19014  MHD_HTTP_INTERNAL_SERVER_ERROR);
19015  return gsad_message (
19016  credentials, "Internal error", __FUNCTION__, __LINE__,
19017  "An internal error occurred while creating a ticket. "
19018  "Diagnostics: Failure to send command to manager daemon.",
19019  response_data);
19020  case 2:
19021  cmd_response_data_set_status_code (response_data,
19022  MHD_HTTP_INTERNAL_SERVER_ERROR);
19023  return gsad_message (
19024  credentials, "Internal error", __FUNCTION__, __LINE__,
19025  "An internal error occurred while creating a ticket. "
19026  "It is unclear whether the ticket has been created or not. "
19027  "Diagnostics: Failure to receive response from manager daemon.",
19028  response_data);
19029  default:
19030  cmd_response_data_set_status_code (response_data,
19031  MHD_HTTP_INTERNAL_SERVER_ERROR);
19032  return gsad_message (
19033  credentials, "Internal error", __FUNCTION__, __LINE__,
19034  "An internal error occurred while creating a ticket. "
19035  "It is unclear whether the ticket has been created or not. "
19036  "Diagnostics: Internal Error.",
19037  response_data);
19038  }
19039 
19040  ret = response_from_entity (connection, credentials, params, entity,
19041  "Create Ticket", response_data);
19042 
19043  free_entity (entity);
19044  g_free (response);
19045  return ret;
19046 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
User information structure, for sessions.
Definition: gsad_user.c:42
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmpf(), gsad_message(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ create_user_gmp()

char* create_user_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Create a user, get all users, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 17039 of file gsad_gmp.c.

17041 {
17042  const char *name, *password, *hosts, *hosts_allow, *ifaces, *ifaces_allow;
17043  const char *auth_method, *comment;
17044  int ret;
17045  params_t *groups, *roles;
17046  GString *group_elements, *role_elements, *string;
17047  gchar *buf, *response, *html;
17048  entity_t entity;
17049 
17050  name = params_value (params, "login");
17051  password = params_value (params, "password");
17052  hosts = params_value (params, "access_hosts");
17053  hosts_allow = params_value (params, "hosts_allow");
17054  ifaces = params_value (params, "access_ifaces");
17055  ifaces_allow = params_value (params, "ifaces_allow");
17056  auth_method = params_value (params, "auth_method");
17057  comment = params_value (params, "comment");
17058 
17059  CHECK_VARIABLE_INVALID (name, "Create User");
17060  CHECK_VARIABLE_INVALID (hosts, "Create User");
17061  CHECK_VARIABLE_INVALID (hosts_allow, "Create User");
17062  CHECK_VARIABLE_INVALID (ifaces, "Create User");
17063  CHECK_VARIABLE_INVALID (ifaces_allow, "Create User");
17064 
17065  if (auth_method && strcmp (auth_method, "1") == 0)
17066  {
17067  CHECK_VARIABLE_INVALID (password, "Create User");
17068  }
17069 
17070  if (params_given (params, "comment"))
17071  {
17072  CHECK_VARIABLE_INVALID (comment, "Create User");
17073  }
17074 
17075  /* Create the user. */
17076 
17077  string = g_string_new ("<create_user>");
17078  buf = g_markup_printf_escaped ("<name>%s</name>"
17079  "<password>%s</password>",
17080  name, password ? password : "");
17081 
17082  g_string_append (string, buf);
17083  g_free (buf);
17084 
17085  group_elements = g_string_new ("<groups>");
17086  if (params_given (params, "group_id_optional:"))
17087  groups = params_values (params, "group_id_optional:");
17088  else
17089  groups = params_values (params, "group_ids:");
17090 
17091  if (groups)
17092  {
17093  params_iterator_t iter;
17094  char *name;
17095  param_t *param;
17096 
17097  params_iterator_init (&iter, groups);
17098  while (params_iterator_next (&iter, &name, &param))
17099  {
17100  if (param->value && strcmp (param->value, "--"))
17101  g_string_append_printf (group_elements, "<group id=\"%s\"/>",
17102  param->value ? param->value : "");
17103  }
17104  }
17105  g_string_append (string, group_elements->str);
17106  g_string_free (group_elements, TRUE);
17107  g_string_append (string, "</groups>");
17108 
17109  role_elements = g_string_new ("");
17110  if (params_given (params, "role_id_optional:"))
17111  roles = params_values (params, "role_id_optional:");
17112  else
17113  roles = params_values (params, "role_ids:");
17114 
17115  if (roles)
17116  {
17117  params_iterator_t iter;
17118  char *name;
17119  param_t *param;
17120 
17121  params_iterator_init (&iter, roles);
17122  while (params_iterator_next (&iter, &name, &param))
17123  {
17124  if (param->value && strcmp (param->value, "--"))
17125  g_string_append_printf (role_elements, "<role id=\"%s\"/>",
17126  param->value ? param->value : "");
17127  }
17128  }
17129  g_string_append (string, role_elements->str);
17130  g_string_free (role_elements, TRUE);
17131 
17132  buf = g_markup_printf_escaped ("<hosts allow=\"%s\">%s</hosts>"
17133  "<ifaces allow=\"%s\">%s</ifaces>",
17134  hosts_allow, hosts, ifaces_allow, ifaces);
17135  g_string_append (string, buf);
17136  g_free (buf);
17137  if (auth_method && !strcmp (auth_method, "1"))
17138  g_string_append (string,
17139  "<sources><source>ldap_connect</source></sources>");
17140  else if (auth_method && !strcmp (auth_method, "2"))
17141  g_string_append (string,
17142  "<sources><source>radius_connect</source></sources>");
17143 
17144  if (comment)
17145  {
17146  xml_string_append (string, "<comment>%s</comment>", comment);
17147  }
17148 
17149  g_string_append (string, "</create_user>");
17150 
17151  buf = g_string_free (string, FALSE);
17152 
17153  response = NULL;
17154  entity = NULL;
17155  ret = gmp (connection, credentials, &response, &entity, response_data, buf);
17156  g_free (buf);
17157  switch (ret)
17158  {
17159  case 0:
17160  case -1:
17161  break;
17162  case 1:
17163  cmd_response_data_set_status_code (response_data,
17164  MHD_HTTP_INTERNAL_SERVER_ERROR);
17165  return gsad_message (
17166  credentials, "Internal error", __FUNCTION__, __LINE__,
17167  "An internal error occurred while creating a new user. "
17168  "No new user was created. "
17169  "Diagnostics: Failure to send command to manager daemon.",
17170  response_data);
17171  case 2:
17172  cmd_response_data_set_status_code (response_data,
17173  MHD_HTTP_INTERNAL_SERVER_ERROR);
17174  return gsad_message (
17175  credentials, "Internal error", __FUNCTION__, __LINE__,
17176  "An internal error occurred while creating a new user. "
17177  "It is unclear whether the user has been created or not. "
17178  "Diagnostics: Failure to receive response from manager daemon.",
17179  response_data);
17180  default:
17181  cmd_response_data_set_status_code (response_data,
17182  MHD_HTTP_INTERNAL_SERVER_ERROR);
17183  return gsad_message (
17184  credentials, "Internal error", __FUNCTION__, __LINE__,
17185  "An internal error occurred while creating a new user. "
17186  "It is unclear whether the user has been created or not. "
17187  "Diagnostics: Internal Error.",
17188  response_data);
17189  }
17190 
17191  if (entity_attribute (entity, "id"))
17192  params_add (params, "user_id", entity_attribute (entity, "id"));
17193  html = response_from_entity (connection, credentials, params, entity,
17194  "Create User", response_data);
17195  free_entity (entity);
17196  g_free (response);
17197  return html;
17198 }
params_t * params_values(params_t *params, const char *name)
Get values of param.
Definition: gsad_base.c:287
gchar * value
Definition: gsad_params.h:40
Structure of credential related information.
#define params_iterator_t
Definition: gsad_params.h:94
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
int params_given(params_t *params, const char *name)
Get whether a param was given at all.
Definition: gsad_base.c:189
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
Request parameter.
Definition: gsad_params.h:38
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
gboolean params_iterator_next(params_iterator_t *iterator, char **name, param_t **param)
Increment a params iterator.
Definition: gsad_base.c:394
#define params_iterator_init
Definition: gsad_params.h:96
#define params_t
Definition: gsad_params.h:31
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
param_t * params_add(params_t *params, const char *name, const char *value)
Add a param.
Definition: gsad_base.c:318

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmp(), gsad_message(), params_add(), params_given(), params_iterator_init, params_iterator_next(), params_iterator_t, params_t, params_value(), params_values(), response_from_entity(), and param::value.

Here is the call graph for this function:

◆ cvss_calculator()

char* cvss_calculator ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Definition at line 17574 of file gsad_gmp.c.

17576 {
17577  GString *xml;
17578  const char *cvss_av, *cvss_au, *cvss_ac, *cvss_c, *cvss_i, *cvss_a;
17579  const char *cvss_vector, *name;
17580 
17581  cvss_av = params_value (params, "cvss_av");
17582  cvss_au = params_value (params, "cvss_au");
17583  cvss_ac = params_value (params, "cvss_ac");
17584  cvss_c = params_value (params, "cvss_c");
17585  cvss_i = params_value (params, "cvss_i");
17586  cvss_a = params_value (params, "cvss_a");
17587  cvss_vector = params_value (params, "cvss_vector");
17588  name = params_value (params, "name");
17589 
17590  xml = g_string_new ("<cvss_calculator>");
17591 
17592  /* Calculate base score */
17593  if (cvss_av && cvss_au && cvss_ac && cvss_c && cvss_i && cvss_a)
17594  {
17595  char *vector =
17596  g_strdup_printf ("AV:%c/AC:%c/Au:%c/C:%c/I:%c/A:%c", *cvss_av, *cvss_ac,
17597  *cvss_au, *cvss_c, *cvss_i, *cvss_a);
17598 
17599  g_string_append_printf (xml,
17600  "<cvss_vector>%s</cvss_vector>"
17601  "<cvss_score>%.1f</cvss_score>",
17602  vector,
17603  get_cvss_score_from_base_metrics (vector));
17604 
17605  g_string_append_printf (xml,
17606  "<cvss_av>%c</cvss_av><cvss_au>%c</cvss_au>"
17607  "<cvss_ac>%c</cvss_ac><cvss_c>%c</cvss_c>"
17608  "<cvss_i>%c</cvss_i><cvss_a>%c</cvss_a>",
17609  *cvss_av, *cvss_au, *cvss_ac, *cvss_c, *cvss_i,
17610  *cvss_a);
17611 
17612  g_free (vector);
17613  }
17614  else if (cvss_vector)
17615  {
17616  double cvss_score = get_cvss_score_from_base_metrics (cvss_vector);
17617 
17618  g_string_append_printf (xml,
17619  "<cvss_vector>%s</cvss_vector>"
17620  "<cvss_score>%.1f</cvss_score>",
17621  cvss_vector, cvss_score);
17622 
17623  if (cvss_score != -1.0)
17624  {
17625  cvss_av = strstr (cvss_vector, "AV:");
17626  cvss_ac = strstr (cvss_vector, "/AC:");
17627  cvss_au = strstr (cvss_vector, "/Au:");
17628  if (cvss_au == NULL)
17629  cvss_au = strstr (cvss_vector, "/AU:");
17630  cvss_c = strstr (cvss_vector, "/C:");
17631  cvss_i = strstr (cvss_vector, "/I:");
17632  cvss_a = strstr (cvss_vector, "/A:");
17633 
17634  if (cvss_av && cvss_ac && cvss_au && cvss_c && cvss_i && cvss_a)
17635  g_string_append_printf (xml,
17636  "<cvss_av>%c</cvss_av><cvss_ac>%c</cvss_ac>"
17637  "<cvss_au>%c</cvss_au><cvss_c>%c</cvss_c>"
17638  "<cvss_i>%c</cvss_i><cvss_a>%c</cvss_a>",
17639  *(cvss_av + 3), *(cvss_ac + 4),
17640  *(cvss_au + 4), *(cvss_c + 3),
17641  *(cvss_i + 3), *(cvss_a + 3));
17642  }
17643  }
17644  else if (name && !strcmp ("vector", name))
17645  {
17646  g_string_append_printf (xml, "<cvss_score>%.1f</cvss_score>", -1.0);
17647  }
17648 
17649  g_string_append (xml, "</cvss_calculator>");
17650  return envelope_gmp (connection, credentials, params,
17651  g_string_free (xml, FALSE), response_data);
17652 }
Structure of credential related information.
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
static char * envelope_gmp(gvm_connection_t *connection, credentials_t *credentials, params_t *params, gchar *xml, cmd_response_data_t *response_data)
Wrap some XML in an envelope.
Definition: gsad_gmp.c:443

References envelope_gmp(), and params_value().

Here is the call graph for this function:

◆ delete_agent_gmp()

char* delete_agent_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Delete agent, get all agents, envelope result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 4571 of file gsad_gmp.c.

4573 {
4574  return move_resource_to_trash (connection, "agent", credentials, params,
4575  response_data);
4576 }
Structure of credential related information.
char * move_resource_to_trash(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Move a resource to the trashcan.
Definition: gsad_gmp.c:2022

References move_resource_to_trash().

Here is the call graph for this function:

◆ delete_alert_gmp()

char* delete_alert_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Delete an alert, get all alerts, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 5824 of file gsad_gmp.c.

5826 {
5827  return move_resource_to_trash (connection, "alert", credentials, params,
5828  response_data);
5829 }
Structure of credential related information.
char * move_resource_to_trash(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Move a resource to the trashcan.
Definition: gsad_gmp.c:2022

References move_resource_to_trash().

Here is the call graph for this function:

◆ delete_asset_gmp()

char* delete_asset_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Delete an asset, go to the next page.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 18748 of file gsad_gmp.c.

18750 {
18751  gchar *html, *response, *resource_id;
18752  const char *next_id;
18753  entity_t entity;
18754 
18755  if (params_value (params, "asset_id"))
18756  resource_id = g_strdup (params_value (params, "asset_id"));
18757  else if (params_value (params, "report_id"))
18758  resource_id = g_strdup (params_value (params, "report_id"));
18759  else
18760  {
18761  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
18762  return gsad_message (
18763  credentials, "Internal error", __FUNCTION__, __LINE__,
18764  "An internal error occurred while deleting an asset. "
18765  "The asset was not deleted. "
18766  "Diagnostics: Required parameter was NULL.",
18767  response_data);
18768  }
18769 
18770  /* This is a hack, needed because asset_id is the param name used for
18771  * both the asset being deleted and the asset on the next page. */
18772  next_id = params_value (params, "next_id");
18773  if (next_id && params_value (params, "asset_id"))
18774  {
18775  param_t *param;
18776  param = params_get (params, "asset_id");
18777  g_free (param->value);
18778  param->value = g_strdup (next_id);
18779  param->value_size = strlen (param->value);
18780  }
18781 
18782  /* Delete the resource and get all resources. */
18783 
18784  if (gvm_connection_sendf (
18785  connection, "<delete_asset %s_id=\"%s\"/>",
18786  params_value (params, "asset_id") ? "asset" : "report", resource_id)
18787  == -1)
18788  {
18789  g_free (resource_id);
18790  cmd_response_data_set_status_code (response_data,
18791  MHD_HTTP_INTERNAL_SERVER_ERROR);
18792  return gsad_message (
18793  credentials, "Internal error", __FUNCTION__, __LINE__,
18794  "An internal error occurred while deleting an asset. "
18795  "The asset is not deleted. "
18796  "Diagnostics: Failure to send command to manager daemon.",
18797  response_data);
18798  }
18799 
18800  g_free (resource_id);
18801 
18802  entity = NULL;
18803  if (read_entity_and_text_c (connection, &entity, &response))
18804  {
18805  cmd_response_data_set_status_code (response_data,
18806  MHD_HTTP_INTERNAL_SERVER_ERROR);
18807  return gsad_message (
18808  credentials, "Internal error", __FUNCTION__, __LINE__,
18809  "An internal error occurred while deleting an asset. "
18810  "It is unclear whether the asset has been deleted or not. "
18811  "Diagnostics: Failure to read response from manager daemon.",
18812  response_data);
18813  }
18814 
18815  /* Cleanup, and return transformed XML. */
18816 
18817  html = response_from_entity (connection, credentials, params, entity,
18818  "Delete Asset", response_data);
18819  g_free (response);
18820  free_entity (entity);
18821  return html;
18822 }
gchar * value
Definition: gsad_params.h:40
Structure of credential related information.
param_t * params_get(params_t *params, const char *name)
Get param.
Definition: gsad_base.c:173
int value_size
Definition: gsad_params.h:46
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
Request parameter.
Definition: gsad_params.h:38
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References cmd_response_data_set_status_code(), gsad_message(), params_get(), params_value(), response_from_entity(), param::value, and param::value_size.

Here is the call graph for this function:

◆ delete_config_gmp()

char* delete_config_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Delete config, get all configs, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 9360 of file gsad_gmp.c.

9362 {
9363  return move_resource_to_trash (connection, "config", credentials, params,
9364  response_data);
9365 }
Structure of credential related information.
char * move_resource_to_trash(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Move a resource to the trashcan.
Definition: gsad_gmp.c:2022

References move_resource_to_trash().

Here is the call graph for this function:

◆ delete_credential_gmp()

char* delete_credential_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Delete credential, get all credentials, envelope result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 4179 of file gsad_gmp.c.

4181 {
4182  return move_resource_to_trash (connection, "credential", credentials, params,
4183  response_data);
4184 }
Structure of credential related information.
char * move_resource_to_trash(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Move a resource to the trashcan.
Definition: gsad_gmp.c:2022

References move_resource_to_trash().

Here is the call graph for this function:

◆ delete_filter_gmp()

char* delete_filter_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Delete a filter, get all filters, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 16578 of file gsad_gmp.c.

16580 {
16581  param_t *filt_id, *id;
16582 
16583  filt_id = params_get (params, "filt_id");
16584  id = params_get (params, "filter_id");
16585  if (id && id->value && filt_id && filt_id->value
16586  && (strcmp (id->value, filt_id->value) == 0))
16587  // TODO: Add params_remove.
16588  filt_id->value = NULL;
16589 
16590  return move_resource_to_trash (connection, "filter", credentials, params,
16591  response_data);
16592 }
gchar * value
Definition: gsad_params.h:40
Structure of credential related information.
param_t * params_get(params_t *params, const char *name)
Get param.
Definition: gsad_base.c:173
Request parameter.
Definition: gsad_params.h:38
char * move_resource_to_trash(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Move a resource to the trashcan.
Definition: gsad_gmp.c:2022

References move_resource_to_trash(), params_get(), and param::value.

Here is the call graph for this function:

◆ delete_from_trash_gmp()

char* delete_from_trash_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Delete a resource from the trashcan.

Parameters
[in]connectionConnection to manager.
[in]typeType of resource.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 2042 of file gsad_gmp.c.

2044 {
2045  const gchar *resource_type;
2046 
2047  resource_type = params_value (params, "resource_type");
2048 
2049  CHECK_VARIABLE_INVALID (resource_type, "Delete from Trashcan");
2050 
2051  return delete_resource (connection, resource_type, credentials, params, TRUE,
2052  response_data);
2053 }
Structure of credential related information.
char * delete_resource(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, gboolean ultimate, cmd_response_data_t *response_data)
Delete a resource, get all resources, envelope the result.
Definition: gsad_gmp.c:1915
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205

References CHECK_VARIABLE_INVALID, delete_resource(), and params_value().

Here is the call graph for this function:

◆ delete_group_gmp()

char* delete_group_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Delete a group, get all groups, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 14135 of file gsad_gmp.c.

14137 {
14138  return move_resource_to_trash (connection, "group", credentials, params,
14139  response_data);
14140 }
Structure of credential related information.
char * move_resource_to_trash(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Move a resource to the trashcan.
Definition: gsad_gmp.c:2022

References move_resource_to_trash().

Here is the call graph for this function:

◆ delete_note_gmp()

char* delete_note_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Delete note, get next page, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 11070 of file gsad_gmp.c.

11072 {
11073  return move_resource_to_trash (connection, "note", credentials, params,
11074  response_data);
11075 }
Structure of credential related information.
char * move_resource_to_trash(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Move a resource to the trashcan.
Definition: gsad_gmp.c:2022

References move_resource_to_trash().

Here is the call graph for this function:

◆ delete_override_gmp()

char* delete_override_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Delete override, get next page, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 11387 of file gsad_gmp.c.

11389 {
11390  return move_resource_to_trash (connection, "override", credentials, params,
11391  response_data);
11392 }
Structure of credential related information.
char * move_resource_to_trash(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Move a resource to the trashcan.
Definition: gsad_gmp.c:2022

References move_resource_to_trash().

Here is the call graph for this function:

◆ delete_permission_gmp()

char* delete_permission_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Delete a permission, get all permissions, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 14448 of file gsad_gmp.c.

14450 {
14451  return move_resource_to_trash (connection, "permission", credentials, params,
14452  response_data);
14453 }
Structure of credential related information.
char * move_resource_to_trash(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Move a resource to the trashcan.
Definition: gsad_gmp.c:2022

References move_resource_to_trash().

Here is the call graph for this function:

◆ delete_port_list_gmp()

char* delete_port_list_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Delete a port list, get all port lists, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 15689 of file gsad_gmp.c.

15691 {
15692  return move_resource_to_trash (connection, "port_list", credentials, params,
15693  response_data);
15694 }
Structure of credential related information.
char * move_resource_to_trash(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Move a resource to the trashcan.
Definition: gsad_gmp.c:2022

References move_resource_to_trash().

Here is the call graph for this function:

◆ delete_port_range_gmp()

char* delete_port_range_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Delete a port range, get the port list, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 15707 of file gsad_gmp.c.

15709 {
15710  return delete_resource (connection, "port_range", credentials, params, TRUE,
15711  response_data);
15712 }
Structure of credential related information.
char * delete_resource(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, gboolean ultimate, cmd_response_data_t *response_data)
Delete a resource, get all resources, envelope the result.
Definition: gsad_gmp.c:1915

References delete_resource().

Here is the call graph for this function:

◆ delete_report_format_gmp()

char* delete_report_format_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Delete report format, get report formats, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 12566 of file gsad_gmp.c.

12569 {
12570  return move_resource_to_trash (connection, "report_format", credentials,
12571  params, response_data);
12572 }
Structure of credential related information.
char * move_resource_to_trash(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Move a resource to the trashcan.
Definition: gsad_gmp.c:2022

References move_resource_to_trash().

Here is the call graph for this function:

◆ delete_report_gmp()

char* delete_report_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Delete report, get task status, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 9661 of file gsad_gmp.c.

9663 {
9664  return delete_resource (connection, "report", credentials, params, TRUE,
9665  response_data);
9666 }
Structure of credential related information.
char * delete_resource(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, gboolean ultimate, cmd_response_data_t *response_data)
Delete a resource, get all resources, envelope the result.
Definition: gsad_gmp.c:1915

References delete_resource().

Here is the call graph for this function:

◆ delete_resource()

char* delete_resource ( gvm_connection_t *  connection,
const char *  type,
credentials_t *  credentials,
params_t *  params,
gboolean  ultimate,
cmd_response_data_t *  response_data 
)

Delete a resource, get all resources, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]typeType of resource.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]ultimate0 move to trash, 1 remove entirely.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 1915 of file gsad_gmp.c.

1918 {
1919  gchar *html, *response, *id_name, *resource_id, *extra_attribs;
1920  entity_t entity;
1921  gchar *cap_type, *prev_action;
1922 
1923  id_name = g_strdup_printf ("%s_id", type);
1924  if (params_value (params, id_name))
1925  resource_id = g_strdup (params_value (params, id_name));
1926  else
1927  {
1928  g_free (id_name);
1929  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
1930  return gsad_message (
1931  credentials, "Internal error", __FUNCTION__, __LINE__,
1932  "An internal error occurred while deleting a resource. "
1933  "The resource was not deleted. "
1934  "Diagnostics: Required parameter resource_id was NULL.",
1935  response_data);
1936  }
1937 
1938  /* This is a hack for assets, because asset_id is the param name used for
1939  * both the asset being deleted and the asset on the next page. */
1940  g_free (id_name);
1941 
1942  /* Extra attributes */
1943  extra_attribs = NULL;
1944 
1945  /* Inheritor of user's resource */
1946  if (strcmp (type, "user") == 0)
1947  {
1948  const char *inheritor_id;
1949  inheritor_id = params_value (params, "inheritor_id");
1950  if (inheritor_id)
1951  extra_attribs = g_strdup_printf ("inheritor_id=\"%s\"", inheritor_id);
1952  else if (params_given (params, "inheritor_id"))
1953  return message_invalid (connection, credentials, params, response_data,
1954  "Invalid inheritor_id", "Delete User");
1955  }
1956 
1957  /* Delete the resource and get all resources. */
1958 
1959  if (gvm_connection_sendf (
1960  connection, "<delete_%s %s_id=\"%s\" ultimate=\"%i\"%s%s/>", type, type,
1961  resource_id, !!ultimate, extra_attribs ? " " : "",
1962  extra_attribs ? extra_attribs : "")
1963  == -1)
1964  {
1965  g_free (resource_id);
1966  g_free (extra_attribs);
1967  cmd_response_data_set_status_code (response_data,
1968  MHD_HTTP_INTERNAL_SERVER_ERROR);
1969  return gsad_message (
1970  credentials, "Internal error", __FUNCTION__, __LINE__,
1971  "An internal error occurred while deleting a resource. "
1972  "The resource is not deleted. "
1973  "Diagnostics: Failure to send command to manager daemon.",
1974  response_data);
1975  }
1976 
1977  g_free (resource_id);
1978  g_free (extra_attribs);
1979 
1980  entity = NULL;
1981  if (read_entity_and_text_c (connection, &entity, &response))
1982  {
1983  cmd_response_data_set_status_code (response_data,
1984  MHD_HTTP_INTERNAL_SERVER_ERROR);
1985  return gsad_message (
1986  credentials, "Internal error", __FUNCTION__, __LINE__,
1987  "An internal error occurred while deleting a resource. "
1988  "It is unclear whether the resource has been deleted or not. "
1989  "Diagnostics: Failure to read response from manager daemon.",
1990  response_data);
1991  }
1992 
1993  if (!gmp_success (entity))
1994  set_http_status_from_entity (entity, response_data);
1995 
1996  cap_type = capitalize (type);
1997  prev_action = g_strdup_printf ("Delete %s", cap_type);
1998 
1999  html = response_from_entity (connection, credentials, params, entity,
2000  prev_action, response_data);
2001 
2002  g_free (response);
2003  free_entity (entity);
2004  g_free (cap_type);
2005  g_free (prev_action);
2006 
2007  return html;
2008 }
static int gmp_success(entity_t entity)
Check whether an GMP command failed.
Definition: gsad_gmp.c:656
Structure of credential related information.
gchar * capitalize(const char *input)
Capitalize a type or command name and replace underscores.
Definition: utils.c:48
int params_given(params_t *params, const char *name)
Get whether a param was given at all.
Definition: gsad_base.c:189
gchar * message_invalid(gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data, const char *message, const char *op_name)
Check a param using the direct response method.
Definition: gsad_gmp.c:1004
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
void set_http_status_from_entity(entity_t entity, cmd_response_data_t *response_data)
Set the HTTP status according to GMP response entity.
Definition: gsad_gmp.c:677
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References capitalize(), cmd_response_data_set_status_code(), gmp_success(), gsad_message(), message_invalid(), params_given(), params_value(), response_from_entity(), and set_http_status_from_entity().

Referenced by delete_from_trash_gmp(), delete_port_range_gmp(), delete_report_gmp(), and move_resource_to_trash().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ delete_role_gmp()

char* delete_role_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Delete a role, get all roles, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 15799 of file gsad_gmp.c.

15801 {
15802  return move_resource_to_trash (connection, "role", credentials, params,
15803  response_data);
15804 }
Structure of credential related information.
char * move_resource_to_trash(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Move a resource to the trashcan.
Definition: gsad_gmp.c:2022

References move_resource_to_trash().

Here is the call graph for this function:

◆ delete_scanner_gmp()

char* delete_scanner_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Delete a scanner, get all scanners, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 11788 of file gsad_gmp.c.

11790 {
11791  return move_resource_to_trash (connection, "scanner", credentials, params,
11792  response_data);
11793 }
Structure of credential related information.
char * move_resource_to_trash(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Move a resource to the trashcan.
Definition: gsad_gmp.c:2022

References move_resource_to_trash().

Here is the call graph for this function:

◆ delete_schedule_gmp()

char* delete_schedule_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Delete a schedule, get all schedules, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 12119 of file gsad_gmp.c.

12121 {
12122  return move_resource_to_trash (connection, "schedule", credentials, params,
12123  response_data);
12124 }
Structure of credential related information.
char * move_resource_to_trash(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Move a resource to the trashcan.
Definition: gsad_gmp.c:2022

References move_resource_to_trash().

Here is the call graph for this function:

◆ delete_tag_gmp()

char* delete_tag_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Delete note, get next page, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 7210 of file gsad_gmp.c.

7212 {
7213  return move_resource_to_trash (connection, "tag", credentials, params,
7214  response_data);
7215 }
Structure of credential related information.
char * move_resource_to_trash(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Move a resource to the trashcan.
Definition: gsad_gmp.c:2022

References move_resource_to_trash().

Here is the call graph for this function:

◆ delete_target_gmp()

char* delete_target_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Delete a target, get all targets, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 6955 of file gsad_gmp.c.

6957 {
6958  return move_resource_to_trash (connection, "target", credentials, params,
6959  response_data);
6960 }
Structure of credential related information.
char * move_resource_to_trash(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Move a resource to the trashcan.
Definition: gsad_gmp.c:2022

References move_resource_to_trash().

Here is the call graph for this function:

◆ delete_task_gmp()

char* delete_task_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Delete a task, get all tasks, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 2810 of file gsad_gmp.c.

2812 {
2813  return move_resource_to_trash (connection, "task", credentials, params,
2814  response_data);
2815 }
Structure of credential related information.
char * move_resource_to_trash(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Move a resource to the trashcan.
Definition: gsad_gmp.c:2022

References move_resource_to_trash().

Here is the call graph for this function:

◆ delete_ticket_gmp()

char* delete_ticket_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Delete a ticket.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 19142 of file gsad_gmp.c.

19144 {
19145  return move_resource_to_trash (connection, "ticket", credentials, params,
19146  response_data);
19147 }
Structure of credential related information.
char * move_resource_to_trash(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Move a resource to the trashcan.
Definition: gsad_gmp.c:2022

References move_resource_to_trash().

Here is the call graph for this function:

◆ delete_user_gmp()

char* delete_user_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Delete a user, get all users, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 16843 of file gsad_gmp.c.

16845 {
16846  return move_resource_to_trash (connection, "user", credentials, params,
16847  response_data);
16848 }
Structure of credential related information.
char * move_resource_to_trash(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Move a resource to the trashcan.
Definition: gsad_gmp.c:2022

References move_resource_to_trash().

Here is the call graph for this function:

◆ download_agent_gmp()

int download_agent_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
char **  html,
char **  filename,
cmd_response_data_t *  response_data 
)

Get an agent, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]htmlResult. Required.
[out]filenameAgent filename return. NULL to skip. Only set on success with agent_id.
[out]response_dataExtra data return for the HTTP response.
Returns
0 success, 1 failure.

Definition at line 4592 of file gsad_gmp.c.

4595 {
4596  entity_t entity;
4597  const char *agent_id, *format;
4598  gsize result_len = 0;
4599 
4600  agent_id = params_value (params, "agent_id");
4601  format = params_value (params, "agent_format");
4602 
4603  if ((agent_id == NULL) || (format == NULL))
4604  {
4605  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
4606  *html =
4607  gsad_message (credentials, "Internal error", __FUNCTION__, __LINE__,
4608  "An internal error occurred while downloading "
4609  "an agent. "
4610  "Diagnostics: Required parameter was NULL.",
4611  response_data);
4612  return 1;
4613  }
4614 
4615  /* Send the request. */
4616 
4617  if (gvm_connection_sendf (connection,
4618  "<get_agents agent_id=\"%s\" format=\"%s\"/>",
4619  agent_id, format)
4620  == -1)
4621  {
4622  cmd_response_data_set_status_code (response_data,
4623  MHD_HTTP_INTERNAL_SERVER_ERROR);
4624  *html =
4625  gsad_message (credentials, "Internal error", __FUNCTION__, __LINE__,
4626  "An internal error occurred while getting agent list. "
4627  "The current list of agents is not available. "
4628  "Diagnostics: Failure to send command to manager daemon.",
4629  response_data);
4630  return 1;
4631  }
4632 
4633  /* Read and handle the response. */
4634 
4635  if (strcmp (format, "installer") == 0 || strcmp (format, "howto_install") == 0
4636  || strcmp (format, "howto_use") == 0)
4637  {
4638  gchar *package_decoded = NULL;
4639  entity_t package_entity = NULL, agent_entity;
4640 
4641  /* A base64 encoded package. */
4642 
4643  entity = NULL;
4644  if (read_entity_c (connection, &entity))
4645  {
4646  cmd_response_data_set_status_code (response_data,
4647  MHD_HTTP_INTERNAL_SERVER_ERROR);
4648  *html = gsad_message (
4649  credentials, "Internal error", __FUNCTION__, __LINE__,
4650  "An internal error occurred while getting a agent. "
4651  "The agent is not available. "
4652  "Diagnostics: Failure to receive response from manager daemon.",
4653  response_data);
4654  return 1;
4655  }
4656 
4657  agent_entity = entity_child (entity, "agent");
4658  if (agent_entity)
4659  package_entity = entity_child (agent_entity, "package");
4660  if (package_entity != NULL)
4661  {
4662  char *package_encoded = entity_text (package_entity);
4663  if (strlen (package_encoded))
4664  {
4665  package_decoded =
4666  (gchar *) g_base64_decode (package_encoded, &result_len);
4667  if (package_decoded == NULL)
4668  {
4669  package_decoded = (gchar *) g_strdup ("");
4670  result_len = 0;
4671  }
4672  }
4673  else
4674  {
4675  package_decoded = (gchar *) g_strdup ("");
4676  result_len = 0;
4677  }
4678  *html = package_decoded;
4679  if (filename)
4680  {
4681  entity_t filename_entity;
4682  filename_entity = entity_child (package_entity, "filename");
4683  if (filename_entity)
4684  *filename = g_strdup (entity_text (filename_entity));
4685  else
4686  *filename = NULL;
4687  if (!(*filename && strlen (*filename)))
4688  {
4689  g_free (*filename);
4690  *filename = g_strdup_printf ("agent-%s-%s", agent_id, format);
4691  }
4692  }
4693  cmd_response_data_set_content_length (response_data, result_len);
4694  free_entity (entity);
4695  return 0;
4696  }
4697  else
4698  {
4699  free_entity (entity);
4700  cmd_response_data_set_status_code (response_data,
4701  MHD_HTTP_INTERNAL_SERVER_ERROR);
4702  *html = gsad_message (
4703  credentials, "Internal error", __FUNCTION__, __LINE__,
4704  "An internal error occurred while getting a agent. "
4705  "The agent could not be delivered. "
4706  "Diagnostics: Failure to receive agent from manager daemon.",
4707  response_data);
4708  return 1;
4709  }
4710  }
4711  else
4712  {
4713  /* An error. */
4714 
4715  entity = NULL;
4716  if (read_entity_c (connection, &entity))
4717  {
4718  cmd_response_data_set_status_code (response_data,
4719  MHD_HTTP_INTERNAL_SERVER_ERROR);
4720  *html = gsad_message (
4721  credentials, "Internal error", __FUNCTION__, __LINE__,
4722  "An internal error occurred while getting a agent. "
4723  "The agent could not be delivered. "
4724  "Diagnostics: Failure to receive agent from manager daemon.",
4725  response_data);
4726  return 1;
4727  }
4728 
4729  free_entity (entity);
4730  cmd_response_data_set_status_code (response_data,
4731  MHD_HTTP_INTERNAL_SERVER_ERROR);
4732  *html = gsad_message (
4733  credentials, "Internal error", __FUNCTION__, __LINE__,
4734  "An internal error occurred while getting a agent. "
4735  "The agent could not be delivered. "
4736  "Diagnostics: Failure to parse agent from manager daemon.",
4737  response_data);
4738  return 1;
4739  }
4740 }
Structure of credential related information.
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_content_length(cmd_response_data_t *data, gsize content_length)
Set response content length of cmd_response_data_t struct.
Definition: gsad_cmd.c:186
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References cmd_response_data_set_content_length(), cmd_response_data_set_status_code(), gsad_message(), and params_value().

Here is the call graph for this function:

◆ download_ca_pub()

char* download_ca_pub ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get a Scanner's CA Certificate.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
CA Certificate.

Definition at line 10605 of file gsad_gmp.c.

10607 {
10608  const char *ca_pub;
10609  char *unescaped;
10610 
10611  ca_pub = params_value (params, "ca_pub");
10612  if (ca_pub == NULL)
10613  {
10614  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
10615  return gsad_message (credentials, "Internal error", __FUNCTION__,
10616  __LINE__,
10617  "An internal error occurred."
10618  " Diagnostics: ca_pub was NULL.",
10619  response_data);
10620  }
10621  /* The Base64 comes URI escaped as it may contain special characters. */
10622  unescaped = g_uri_unescape_string (ca_pub, NULL);
10623  cmd_response_data_set_content_length (response_data, strlen (unescaped));
10624  return unescaped;
10625 }
Structure of credential related information.
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_content_length(cmd_response_data_t *data, gsize content_length)
Set response content length of cmd_response_data_t struct.
Definition: gsad_cmd.c:186
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References cmd_response_data_set_content_length(), cmd_response_data_set_status_code(), gsad_message(), and params_value().

Here is the call graph for this function:

◆ download_credential_gmp()

int download_credential_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
char **  html,
char **  login,
cmd_response_data_t *  response_data 
)

Export a Credential in a defined format.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]htmlResult. Required.
[out]loginLogin name return. NULL to skip. Only set on success with credential_id.
[out]response_dataExtra data return for the HTTP response.
Returns
0 success, 1 failure.

Definition at line 3917 of file gsad_gmp.c.

3921 {
3922  entity_t entity;
3923  const char *credential_id, *format;
3924 
3925  assert (html);
3926 
3927  /* Send the request. */
3928 
3929  credential_id = params_value (params, "credential_id");
3930  format = params_value (params, "package_format");
3931 
3932  if ((credential_id == NULL) || (format == NULL))
3933  {
3934  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
3935  *html =
3936  gsad_message (credentials, "Internal error", __FUNCTION__, __LINE__,
3937  "An internal error occurred while getting a credential. "
3938  "Diagnostics: Required parameter was NULL.",
3939  response_data);
3940  return 1;
3941  }
3942 
3943  if (gvm_connection_sendf (connection,
3944  "<get_credentials"
3945  " credential_id=\"%s\""
3946  " format=\"%s\"/>",
3947  credential_id, format)
3948  == -1)
3949  {
3950  cmd_response_data_set_status_code (response_data,
3951  MHD_HTTP_INTERNAL_SERVER_ERROR);
3952  *html =
3953  gsad_message (credentials, "Internal error", __FUNCTION__, __LINE__,
3954  "An internal error occurred while getting a credential. "
3955  "Diagnostics: Failure to send command to manager daemon.",
3956  response_data);
3957  return 1;
3958  }
3959 
3960  /* Read and handle the response. */
3961 
3962  if (strcmp (format, "rpm") == 0 || strcmp (format, "deb") == 0
3963  || strcmp (format, "exe") == 0)
3964  {
3965  gchar *package_decoded = NULL;
3966  entity_t package_entity = NULL, credential_entity;
3967 
3968  /* A base64 encoded package. */
3969 
3970  entity = NULL;
3971  if (read_entity_c (connection, &entity))
3972  {
3973  cmd_response_data_set_status_code (response_data,
3974  MHD_HTTP_INTERNAL_SERVER_ERROR);
3975  *html = gsad_message (
3976  credentials, "Internal error", __FUNCTION__, __LINE__,
3977  "An internal error occurred while getting a credential. "
3978  "The credential is not available. "
3979  "Diagnostics: Failure to receive response from manager daemon.",
3980  response_data);
3981  return 1;
3982  }
3983 
3984  credential_entity = entity_child (entity, "credential");
3985  if (credential_entity)
3986  package_entity = entity_child (credential_entity, "package");
3987  if (package_entity != NULL)
3988  {
3989  gsize len;
3990  char *package_encoded = entity_text (package_entity);
3991  if (strlen (package_encoded))
3992  {
3993  package_decoded =
3994  (gchar *) g_base64_decode (package_encoded, &len);
3995  if (package_decoded == NULL)
3996  {
3997  package_decoded = (gchar *) g_strdup ("");
3998  len = 0;
3999  }
4000  }
4001  else
4002  {
4003  package_decoded = (gchar *) g_strdup ("");
4004  len = 0;
4005  }
4006 
4007  cmd_response_data_set_content_length (response_data, len);
4008 
4009  *html = package_decoded;
4010  if (login)
4011  {
4012  entity_t login_entity;
4013  login_entity = entity_child (credential_entity, "login");
4014  if (login_entity)
4015  *login = g_strdup (entity_text (login_entity));
4016  else
4017  *login = NULL;
4018  }
4019  free_entity (entity);
4020  return 0;
4021  }
4022  else
4023  {
4024  free_entity (entity);
4025  cmd_response_data_set_status_code (response_data,
4026  MHD_HTTP_INTERNAL_SERVER_ERROR);
4027  *html = gsad_message (
4028  credentials, "Internal error", __FUNCTION__, __LINE__,
4029  "An internal error occurred while getting a credential. "
4030  "The credential could not be delivered. "
4031  "Diagnostics: Failure to receive credential from manager daemon.",
4032  response_data);
4033  return 1;
4034  }
4035  }
4036  else
4037  {
4038  entity_t credential_entity, key_entity = NULL;
4039 
4040  /* A key or certificate. */
4041 
4042  entity = NULL;
4043  if (read_entity_c (connection, &entity))
4044  {
4045  cmd_response_data_set_status_code (response_data,
4046  MHD_HTTP_INTERNAL_SERVER_ERROR);
4047  *html = gsad_message (
4048  credentials, "Internal error", __FUNCTION__, __LINE__,
4049  "An internal error occurred while getting a credential. "
4050  "The credential could not be delivered. "
4051  "Diagnostics: Failure to receive credential from manager daemon.",
4052  response_data);
4053  return 1;
4054  }
4055 
4056  credential_entity = entity_child (entity, "credential");
4057  if (credential_entity)
4058  {
4059  if (strcmp (format, "pem") == 0)
4060  key_entity = entity_child (credential_entity, "certificate");
4061  else
4062  key_entity = entity_child (credential_entity, "public_key");
4063  }
4064  if (key_entity != NULL)
4065  {
4066  *html = g_strdup (entity_text (key_entity));
4067  if (login)
4068  {
4069  entity_t login_entity = entity_child (credential_entity, "login");
4070  if (login_entity)
4071  *login = g_strdup (entity_text (login_entity));
4072  else
4073  *login = NULL;
4074  }
4075  free_entity (entity);
4076  return 0;
4077  }
4078  cmd_response_data_set_status_code (response_data,
4079  MHD_HTTP_INTERNAL_SERVER_ERROR);
4080  *html = gsad_message (
4081  credentials, "Internal error", __FUNCTION__, __LINE__,
4082  "An internal error occurred while getting a credential. "
4083  "The credential could not be delivered. "
4084  "Diagnostics: Failure to parse credential from manager daemon.",
4085  response_data);
4086  free_entity (entity);
4087  return 1;
4088  }
4089 }
Structure of credential related information.
int login(http_connection_t *con, params_t *params, cmd_response_data_t *response_data, const char *client_address)
Login and create a session.
Definition: gsad_gmp.c:19384
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_content_length(cmd_response_data_t *data, gsize content_length)
Set response content length of cmd_response_data_t struct.
Definition: gsad_cmd.c:186
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References cmd_response_data_set_content_length(), cmd_response_data_set_status_code(), gsad_message(), login(), and params_value().

Here is the call graph for this function:

◆ download_key_pub()

char* download_key_pub ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get a Scanner's Certificate.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Certificate.

Definition at line 10638 of file gsad_gmp.c.

10640 {
10641  const char *key_pub;
10642  char *unescaped;
10643 
10644  key_pub = params_value (params, "key_pub");
10645  if (key_pub == NULL)
10646  {
10647  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
10648  return gsad_message (credentials, "Internal error", __FUNCTION__,
10649  __LINE__,
10650  "An internal error occurred."
10651  " Diagnostics: key_pub was NULL.",
10652  response_data);
10653  }
10654 
10655  /* The Base64 comes URI escaped as it may contain special characters. */
10656  unescaped = g_uri_unescape_string (key_pub, NULL);
10657  cmd_response_data_set_content_length (response_data, strlen (unescaped));
10658  return unescaped;
10659 }
Structure of credential related information.
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_content_length(cmd_response_data_t *data, gsize content_length)
Set response content length of cmd_response_data_t struct.
Definition: gsad_cmd.c:186
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References cmd_response_data_set_content_length(), cmd_response_data_set_status_code(), gsad_message(), and params_value().

Here is the call graph for this function:

◆ download_ssl_cert()

char* download_ssl_cert ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get an SSL Certificate.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
SSL Certificate.

Definition at line 10564 of file gsad_gmp.c.

10566 {
10567  const char *ssl_cert;
10568  gchar *cert;
10569  char *unescaped;
10570 
10571  ssl_cert = params_value (params, "ssl_cert");
10572  if (ssl_cert == NULL)
10573  {
10574  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
10575  return gsad_message (credentials, "Internal error", __FUNCTION__,
10576  __LINE__,
10577  "An internal error occurred."
10578  " Diagnostics: ssl_cert was NULL.",
10579  response_data);
10580  }
10581  /* The Base64 comes URI escaped as it may contain special characters. */
10582  unescaped = g_uri_unescape_string (ssl_cert, NULL);
10583 
10584  cert = g_strdup_printf ("-----BEGIN CERTIFICATE-----\n"
10585  "%s\n-----END CERTIFICATE-----\n",
10586  unescaped);
10587 
10588  cmd_response_data_set_content_length (response_data, strlen (cert));
10589 
10590  g_free (unescaped);
10591  return cert;
10592 }
Structure of credential related information.
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_content_length(cmd_response_data_t *data, gsize content_length)
Set response content length of cmd_response_data_t struct.
Definition: gsad_cmd.c:186
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References cmd_response_data_set_content_length(), cmd_response_data_set_status_code(), gsad_message(), and params_value().

Here is the call graph for this function:

◆ edit_alert()

char* edit_alert ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)

Setup edit_alert XML, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 6182 of file gsad_gmp.c.

6185 {
6186  GString *xml;
6187  gchar *edit;
6188  const char *alert_id, *next, *filter;
6189 
6190  alert_id = params_value (params, "alert_id");
6191  next = params_value (params, "next");
6192  filter = params_value (params, "filter");
6193 
6194  if (alert_id == NULL)
6195  {
6196  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
6197  return gsad_message (credentials, "Internal error", __FUNCTION__,
6198  __LINE__,
6199  "An internal error occurred while editing an alert. "
6200  "The alert remains as it was. "
6201  "Diagnostics: Required parameter alert_id was NULL.",
6202  response_data);
6203  }
6204 
6205  if (next == NULL)
6206  next = "get_alerts";
6207 
6208  if (gvm_connection_sendf (connection,
6209  "<get_alerts"
6210  " alert_id=\"%s\""
6211  " details=\"1\"/>",
6212  alert_id)
6213  == -1)
6214  {
6215  cmd_response_data_set_status_code (response_data,
6216  MHD_HTTP_INTERNAL_SERVER_ERROR);
6217  return gsad_message (
6218  credentials, "Internal error", __FUNCTION__, __LINE__,
6219  "An internal error occurred while getting alert info. "
6220  "Diagnostics: Failure to send command to manager daemon.",
6221  response_data);
6222  }
6223 
6224  xml = g_string_new ("<edit_alert>");
6225 
6226  if (extra_xml)
6227  g_string_append (xml, extra_xml);
6228 
6229  edit = g_markup_printf_escaped ("<alert id=\"%s\"/>"
6230  /* Page that follows. */
6231  "<next>%s</next>"
6232  /* Passthroughs. */
6233  "<filters><term>%s</term></filters>",
6234  alert_id, next, filter);
6235  g_string_append (xml, edit);
6236  g_free (edit);
6237 
6238  if (read_string_c (connection, &xml))
6239  {
6240  g_string_free (xml, TRUE);
6241  cmd_response_data_set_status_code (response_data,
6242  MHD_HTTP_INTERNAL_SERVER_ERROR);
6243  return gsad_message (
6244  credentials, "Internal error", __FUNCTION__, __LINE__,
6245  "An internal error occurred while getting alert info. "
6246  "Diagnostics: Failure to receive response from manager daemon.",
6247  response_data);
6248  }
6249 
6250  if (command_enabled (credentials, "GET_REPORT_FORMATS"))
6251  {
6252  /* Get the report formats. */
6253 
6254  if (gvm_connection_sendf (connection, "<get_report_formats"
6255  " filter=\"rows=-1\"/>")
6256  == -1)
6257  {
6258  g_string_free (xml, TRUE);
6259  cmd_response_data_set_status_code (response_data,
6260  MHD_HTTP_INTERNAL_SERVER_ERROR);
6261  return gsad_message (
6262  credentials, "Internal error", __FUNCTION__, __LINE__,
6263  "An internal error occurred while getting report formats. "
6264  "The current list of report formats is not available. "
6265  "Diagnostics: Failure to send command to manager daemon.",
6266  response_data);
6267  }
6268 
6269  if (read_string_c (connection, &xml))
6270  {
6271  g_string_free (xml, TRUE);
6272  cmd_response_data_set_status_code (response_data,
6273  MHD_HTTP_INTERNAL_SERVER_ERROR);
6274  return gsad_message (
6275  credentials, "Internal error", __FUNCTION__, __LINE__,
6276  "An internal error occurred while getting report formats. "
6277  "The current list of report formats is not available. "
6278  "Diagnostics: Failure to receive response from manager daemon.",
6279  response_data);
6280  }
6281  }
6282 
6283  if (command_enabled (credentials, "GET_FILTERS"))
6284  {
6285  /* Get filters. */
6286 
6287  if (gvm_connection_sendf (connection, "<get_filters filter=\"rows=-1\"/>")
6288  == -1)
6289  {
6290  g_string_free (xml, TRUE);
6291  cmd_response_data_set_status_code (response_data,
6292  MHD_HTTP_INTERNAL_SERVER_ERROR);
6293  return gsad_message (
6294  credentials, "Internal error", __FUNCTION__, __LINE__,
6295  "An internal error occurred while getting the list "
6296  "of filters. "
6297  "The current list of filters is not available. "
6298  "Diagnostics: Failure to send command to manager daemon.",
6299  response_data);
6300  }
6301 
6302  if (read_string_c (connection, &xml))
6303  {
6304  g_string_free (xml, TRUE);
6305  cmd_response_data_set_status_code (response_data,
6306  MHD_HTTP_INTERNAL_SERVER_ERROR);
6307  return gsad_message (
6308  credentials, "Internal error", __FUNCTION__, __LINE__,
6309  "An internal error occurred while getting the list "
6310  "of filters. "
6311  "The current list of filters is not available. "
6312  "Diagnostics: Failure to receive response from manager daemon.",
6313  response_data);
6314  }
6315  }
6316 
6317  if (command_enabled (credentials, "GET_TASKS"))
6318  {
6319  /* Get tasks. */
6320 
6321  if (gvm_connection_sendf (connection,
6322  "<get_tasks"
6323  " schedules_only=\"1\""
6324  " filter=\"owner=any permission=start_task"
6325  " rows=-1\"/>")
6326  == -1)
6327  {
6328  g_string_free (xml, TRUE);
6329  cmd_response_data_set_status_code (response_data,
6330  MHD_HTTP_INTERNAL_SERVER_ERROR);
6331  return gsad_message (
6332  credentials, "Internal error", __FUNCTION__, __LINE__,
6333  "An internal error occurred while getting the list "
6334  "of tasks. "
6335  "The current list of tasks is not available. "
6336  "Diagnostics: Failure to send command to manager daemon.",
6337  response_data);
6338  }
6339 
6340  if (read_string_c (connection, &xml))
6341  {
6342  g_string_free (xml, TRUE);
6343  cmd_response_data_set_status_code (response_data,
6344  MHD_HTTP_INTERNAL_SERVER_ERROR);
6345  return gsad_message (
6346  credentials, "Internal error", __FUNCTION__, __LINE__,
6347  "An internal error occurred while getting the list "
6348  "of tasks. "
6349  "The current list of tasks is not available. "
6350  "Diagnostics: Failure to receive response from manager daemon.",
6351  response_data);
6352  }
6353  }
6354 
6355  /* Get Credentials. */
6356 
6357  if (command_enabled (credentials, "GET_CREDENTIALS"))
6358  {
6359  if (gvm_connection_sendf (connection, "<get_credentials"
6360  " filter=\"type=up or type=pw"
6361  " owner=any permission=any"
6362  " rows=-1\"/>")
6363  == -1)
6364  {
6365  g_string_free (xml, TRUE);
6366  cmd_response_data_set_status_code (response_data,
6367  MHD_HTTP_INTERNAL_SERVER_ERROR);
6368  return gsad_message (
6369  credentials, "Internal error", __FUNCTION__, __LINE__,
6370  "An internal error occurred while getting the list "
6371  "of credentials. "
6372  "The current list of tasks is not available. "
6373  "Diagnostics: Failure to send command to manager daemon.",
6374  response_data);
6375  }
6376 
6377  if (read_string_c (connection, &xml))
6378  {
6379  g_string_free (xml, TRUE);
6380  cmd_response_data_set_status_code (response_data,
6381  MHD_HTTP_INTERNAL_SERVER_ERROR);
6382  return gsad_message (
6383  credentials, "Internal error", __FUNCTION__, __LINE__,
6384  "An internal error occurred while getting the list "
6385  "of credentials. "
6386  "The current list of tasks is not available. "
6387  "Diagnostics: Failure to receive response from manager daemon.",
6388  response_data);
6389  }
6390  }
6391 
6392  /* Cleanup, and return transformed XML. */
6393 
6394  g_string_append (xml, "</edit_alert>");
6395  return envelope_gmp (connection, credentials, params,
6396  g_string_free (xml, FALSE), response_data);
6397 }
Structure of credential related information.
int command_enabled(credentials_t *credentials, const gchar *name)
Init the GSA GMP library.
Definition: gsad_gmp.c:352
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
static char * envelope_gmp(gvm_connection_t *connection, credentials_t *credentials, params_t *params, gchar *xml, cmd_response_data_t *response_data)
Wrap some XML in an envelope.
Definition: gsad_gmp.c:443

References cmd_response_data_set_status_code(), command_enabled(), envelope_gmp(), gsad_message(), and params_value().

Referenced by edit_alert_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ edit_alert_gmp()

char* edit_alert_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Setup edit_alert XML, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 6410 of file gsad_gmp.c.

6412 {
6413  return edit_alert (connection, credentials, params, NULL, response_data);
6414 }
Structure of credential related information.
char * edit_alert(gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
Setup edit_alert XML, envelope the result.
Definition: gsad_gmp.c:6182

References edit_alert().

Here is the call graph for this function:

◆ edit_config()

static char* edit_config ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get a config, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 8290 of file gsad_gmp.c.

8293 {
8294  return get_config (connection, credentials, params, extra_xml, 1,
8295  response_data);
8296 }
Structure of credential related information.
static char * get_config(gvm_connection_t *, credentials_t *, params_t *, const char *, int, cmd_response_data_t *)
Get a config, envelope the result.
Definition: gsad_gmp.c:8078

References get_config().

Referenced by edit_config_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ edit_config_family_gmp()

char* edit_config_family_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get details of a family for editing a config, envelope result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 8862 of file gsad_gmp.c.

8865 {
8866  return get_config_family (connection, credentials, params, 1, response_data);
8867 }
Structure of credential related information.
static char * get_config_family(gvm_connection_t *, credentials_t *, params_t *, int, cmd_response_data_t *)
Get details of a family for a config, envelope the result.
Definition: gsad_gmp.c:8712

References get_config_family().

Here is the call graph for this function:

◆ edit_config_gmp()

char* edit_config_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get a config, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 8309 of file gsad_gmp.c.

8311 {
8312  return edit_config (connection, credentials, params, NULL, response_data);
8313 }
Structure of credential related information.
static char * edit_config(gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
Get a config, envelope the result.
Definition: gsad_gmp.c:8290

References edit_config().

Here is the call graph for this function:

◆ edit_config_nvt_gmp()

char* edit_config_nvt_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Edit details of an NVT for a config, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 9125 of file gsad_gmp.c.

9127 {
9128  return get_config_nvt (connection, credentials, params, 1, response_data);
9129 }
Structure of credential related information.
static char * get_config_nvt(gvm_connection_t *connection, credentials_t *credentials, params_t *params, int edit, cmd_response_data_t *response_data)
Get details of an NVT for a config, envelope the result.
Definition: gsad_gmp.c:8968

References get_config_nvt().

Here is the call graph for this function:

◆ edit_resource()

char* edit_resource ( gvm_connection_t *  connection,
const char *  type,
credentials_t *  credentials,
params_t *  params,
const char *  extra_get_attribs,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)

Setup edit XML, envelope the result.

Parameters
[in]connectionConnection to manager
[in]typeType or resource to edit.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_get_attribsExtra attributes for the get_... command.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 1421 of file gsad_gmp.c.

1425 {
1426  GString *xml;
1427  gchar *id_name;
1428  const char *resource_id;
1429 
1430  id_name = g_strdup_printf ("%s_id", type);
1431  resource_id = params_value (params, id_name);
1432  g_free (id_name);
1433 
1434  if (resource_id == NULL)
1435  {
1436  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
1437  return gsad_message (
1438  credentials, "Internal error", __FUNCTION__, __LINE__,
1439  "An internal error occurred while editing a resource. "
1440  "The resource remains as it was. "
1441  "Diagnostics: Required ID parameter was NULL.",
1442  response_data);
1443  }
1444 
1445  if (gvm_connection_sendf (connection,
1446  "<get_%ss"
1447  " %s"
1448  " %s_id=\"%s\""
1449  " details=\"1\"/>",
1450  type, extra_get_attribs ? extra_get_attribs : "",
1451  type, resource_id)
1452  == -1)
1453  {
1454  cmd_response_data_set_status_code (response_data,
1455  MHD_HTTP_INTERNAL_SERVER_ERROR);
1456  return gsad_message (
1457  credentials, "Internal error", __FUNCTION__, __LINE__,
1458  "An internal error occurred while getting a resource. "
1459  "Diagnostics: Failure to send command to manager daemon.",
1460  response_data);
1461  }
1462 
1463  xml = g_string_new ("");
1464 
1465  g_string_append_printf (xml, "<edit_%s>", type);
1466 
1467  if (extra_xml)
1468  g_string_append (xml, extra_xml);
1469 
1470  if (read_string_c (connection, &xml))
1471  {
1472  g_string_free (xml, TRUE);
1473  cmd_response_data_set_status_code (response_data,
1474  MHD_HTTP_INTERNAL_SERVER_ERROR);
1475  return gsad_message (
1476  credentials, "Internal error", __FUNCTION__, __LINE__,
1477  "An internal error occurred while getting a resource. "
1478  "Diagnostics: Failure to receive response from manager daemon.",
1479  response_data);
1480  }
1481 
1482  /* Cleanup, and return transformed XML. */
1483 
1484  g_string_append_printf (xml, "</edit_%s>", type);
1485  return envelope_gmp (connection, credentials, params,
1486  g_string_free (xml, FALSE), response_data);
1487 }
Structure of credential related information.
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
static char * envelope_gmp(gvm_connection_t *connection, credentials_t *credentials, params_t *params, gchar *xml, cmd_response_data_t *response_data)
Wrap some XML in an envelope.
Definition: gsad_gmp.c:443

References cmd_response_data_set_status_code(), envelope_gmp(), gsad_message(), and params_value().

Referenced by edit_role().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ edit_role()

char * edit_role ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Setup edit_role XML, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 15896 of file gsad_gmp.c.

15899 {
15900  gchar *html;
15901  GString *extra;
15902 
15903  extra = g_string_new ("");
15904 
15905  if (command_enabled (credentials, "GET_PERMISSIONS"))
15906  {
15907  gchar *response;
15908  entity_t entity;
15909 
15910  response = NULL;
15911  entity = NULL;
15912  switch (
15913  gmpf (connection, credentials, &response, &entity, response_data,
15914  "<get_permissions"
15915  " filter=\"rows=-1 subject_type=role and subject_uuid=%s\"/>",
15916  params_value (params, "role_id")))
15917  {
15918  case 0:
15919  case -1:
15920  break;
15921  case 1:
15922  cmd_response_data_set_status_code (response_data,
15923  MHD_HTTP_INTERNAL_SERVER_ERROR);
15924  return gsad_message (
15925  credentials, "Internal error", __FUNCTION__, __LINE__,
15926  "An internal error occurred getting the permission list. "
15927  "Diagnostics: Failure to send command to manager daemon.",
15928  response_data);
15929  case 2:
15930  cmd_response_data_set_status_code (response_data,
15931  MHD_HTTP_INTERNAL_SERVER_ERROR);
15932  return gsad_message (
15933  credentials, "Internal error", __FUNCTION__, __LINE__,
15934  "An internal error occurred getting the permission list. "
15935  "Diagnostics: Failure to receive response from manager daemon.",
15936  response_data);
15937  default:
15938  cmd_response_data_set_status_code (response_data,
15939  MHD_HTTP_INTERNAL_SERVER_ERROR);
15940  return gsad_message (
15941  credentials, "Internal error", __FUNCTION__, __LINE__,
15942  "An internal error occurred getting the permission list. "
15943  "Diagnostics: Internal Error.",
15944  response_data);
15945  }
15946 
15947  g_string_append (extra, response);
15948 
15949  free_entity (entity);
15950  g_free (response);
15951  }
15952 
15953  if (command_enabled (credentials, "GET_GROUPS"))
15954  {
15955  gchar *response;
15956  entity_t entity;
15958 
15959  response = NULL;
15960  entity = NULL;
15961  switch (gmpf (connection, credentials, &response, &entity, response_data,
15962  "<get_groups"
15963  " filter=\"rows=-1 owner=%s\"/>",
15965  {
15966  case 0:
15967  case -1:
15968  break;
15969  case 1:
15970  cmd_response_data_set_status_code (response_data,
15971  MHD_HTTP_INTERNAL_SERVER_ERROR);
15972  return gsad_message (
15973  credentials, "Internal error", __FUNCTION__, __LINE__,
15974  "An internal error occurred getting the group list. "
15975  "Diagnostics: Failure to send command to manager daemon.",
15976  response_data);
15977  case 2:
15978  cmd_response_data_set_status_code (response_data,
15979  MHD_HTTP_INTERNAL_SERVER_ERROR);
15980  return gsad_message (
15981  credentials, "Internal error", __FUNCTION__, __LINE__,
15982  "An internal error occurred getting the group list. "
15983  "Diagnostics: Failure to receive response from manager daemon.",
15984  response_data);
15985  default:
15986  cmd_response_data_set_status_code (response_data,
15987  MHD_HTTP_INTERNAL_SERVER_ERROR);
15988  return gsad_message (
15989  credentials, "Internal error", __FUNCTION__, __LINE__,
15990  "An internal error occurred getting the group list. "
15991  "Diagnostics: Internal Error.",
15992  response_data);
15993  }
15994 
15995  g_string_append (extra, response);
15996 
15997  free_entity (entity);
15998  g_free (response);
15999  }
16000 
16001  if (extra_xml)
16002  g_string_append (extra, extra_xml);
16003  html = edit_resource (connection, "role", credentials, params, NULL,
16004  extra->str, response_data);
16005  g_string_free (extra, TRUE);
16006  return html;
16007 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
const gchar * user_get_username(user_t *user)
Definition: gsad_user.c:157
int command_enabled(credentials_t *credentials, const gchar *name)
Init the GSA GMP library.
Definition: gsad_gmp.c:352
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
User information structure, for sessions.
Definition: gsad_user.c:42
char * edit_resource(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_get_attribs, const char *extra_xml, cmd_response_data_t *response_data)
Setup edit XML, envelope the result.
Definition: gsad_gmp.c:1421
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
user_t * credentials_get_user(credentials_t *cred)

References cmd_response_data_set_status_code(), command_enabled(), credentials_get_user(), edit_resource(), gmpf(), gsad_message(), params_value(), and user_get_username().

Referenced by edit_role_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ edit_role_gmp()

char* edit_role_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Setup edit_role XML, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 16020 of file gsad_gmp.c.

16022 {
16023  return edit_role (connection, credentials, params, NULL, response_data);
16024 }
Structure of credential related information.
static char * edit_role(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Setup edit_role XML, envelope the result.
Definition: gsad_gmp.c:15896

References edit_role().

Here is the call graph for this function:

◆ empty_trashcan_gmp()

char* empty_trashcan_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Empty the trashcan, get all trash, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 7040 of file gsad_gmp.c.

7042 {
7043  GString *xml;
7044  gchar *ret;
7045  entity_t entity;
7046 
7047  xml = g_string_new ("");
7048 
7049  /* Empty the trash. */
7050 
7051  if (gvm_connection_sendf (connection, "<empty_trashcan/>") == -1)
7052  {
7053  g_string_free (xml, TRUE);
7054  cmd_response_data_set_status_code (response_data,
7055  MHD_HTTP_INTERNAL_SERVER_ERROR);
7056  return gsad_message (
7057  credentials, "Internal error", __FUNCTION__, __LINE__,
7058  "An internal error occurred while emptying the trashcan. "
7059  "Diagnostics: Failure to send command to manager daemon.",
7060  response_data);
7061  }
7062 
7063  if (read_entity_and_string_c (connection, &entity, &xml))
7064  {
7065  g_string_free (xml, TRUE);
7066  cmd_response_data_set_status_code (response_data,
7067  MHD_HTTP_INTERNAL_SERVER_ERROR);
7068  return gsad_message (
7069  credentials, "Internal error", __FUNCTION__, __LINE__,
7070  "An internal error occurred while emptying the trashcan. "
7071  "Diagnostics: Failure to read response from manager daemon.",
7072  response_data);
7073  }
7074 
7075  /* Cleanup, and return trash page. */
7076 
7077  ret = response_from_entity (connection, credentials, params, entity,
7078  "Empty Trashcan", response_data);
7079  free_entity (entity);
7080  g_string_free (xml, FALSE);
7081  return ret;
7082 }
Structure of credential related information.
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References cmd_response_data_set_status_code(), gsad_message(), and response_from_entity().

Here is the call graph for this function:

◆ envelope_gmp()

static char* envelope_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
gchar *  xml,
cmd_response_data_t *  response_data 
)
static

Wrap some XML in an envelope.

Parameters
[in]connectionConnection to manager
[in]credentialsUsername and password for authentication.
[in]paramsHTTP request params (UNUSED)
[in]xmlXML string. Freed before exit.
[out]response_dataExtra data return for the HTTP response or NULL.
Returns
Enveloped GMP XML object.

Definition at line 443 of file gsad_gmp.c.

445 {
446  time_t now;
447  gchar *res;
448  GString *string;
449  char ctime_now[200];
450  struct timeval tv;
451 
452  assert (credentials);
453 
455  const gchar *timezone = user_get_timezone (user);
456  const gchar *pw_warning = user_get_password_warning (user);
457 
458  now = time (NULL);
459  ctime_r_strip_newline (&now, ctime_now);
460 
461  string = g_string_new ("");
462 
463  gettimeofday (&tv, NULL);
464  res = g_markup_printf_escaped (
465  "<envelope>"
466  "<version>%s</version>"
467  "<vendor_version>%s</vendor_version>"
468  "<token>%s</token>"
469  "<time>%s</time>"
470  "<timezone>%s</timezone>"
471  "<login>%s</login>"
472  "<session>%ld</session>"
473  "<role>%s</role>"
474  "<severity>%s</severity>"
475  "<i18n>%s</i18n>"
476  "<guest>%d</guest>"
477  "<client_address>%s</client_address>"
478  "<backend_operation>%.2f</backend_operation>",
479  GSAD_VERSION, vendor_version_get (), user_get_token (user), ctime_now,
480  timezone ? timezone : "", user_get_username (user),
485 
486  g_string_append (string, res);
487  g_free (res);
488 
489  if (pw_warning)
490  {
491  gchar *warning_elem;
492  warning_elem = g_markup_printf_escaped ("<password_warning>"
493  "%s"
494  "</password_warning>",
495  pw_warning);
496  g_string_append (string, warning_elem);
497  g_free (warning_elem);
498  }
499 
500  g_string_append_printf (string,
501  "<capabilities>%s</capabilities>"
502  "%s"
503  "</envelope>",
504  user_get_capabilities (user), xml);
505  g_free (xml);
506 
508  return g_string_free (string, FALSE);
509 }
const gchar * user_get_severity(user_t *user)
Definition: gsad_user.c:205
Structure of credential related information.
const gchar * user_get_password_warning(user_t *user)
Definition: gsad_user.c:187
const gchar * vendor_version_get()
Get the vendor version.
const gchar * user_get_role(user_t *user)
Definition: gsad_user.c:211
const gchar * user_get_username(user_t *user)
Definition: gsad_user.c:157
const gchar * credentials_get_language(credentials_t *cred)
const gchar * user_get_token(user_t *user)
Definition: gsad_user.c:175
const time_t user_get_session_timeout(user_t *user)
Definition: gsad_user.c:229
void cmd_response_data_set_content_type(cmd_response_data_t *data, content_type_t content_type)
Set content type of cmd_response_data_t struct.
Definition: gsad_cmd.c:134
const gchar * user_get_capabilities(user_t *user)
Definition: gsad_user.c:181
double credentials_get_cmd_duration(credentials_t *cred)
const gchar * user_get_timezone(user_t *user)
Definition: gsad_user.c:193
User information structure, for sessions.
Definition: gsad_user.c:42
gboolean user_get_guest(user_t *user)
Definition: gsad_user.c:223
char * ctime_r_strip_newline(time_t *time, char *string)
Return string from ctime_r with newline replaces with terminator.
Definition: gsad_base.c:111
user_t * credentials_get_user(credentials_t *cred)
const gchar * user_get_client_address(user_t *user)
Definition: gsad_user.c:199

References cmd_response_data_set_content_type(), credentials_get_cmd_duration(), credentials_get_language(), credentials_get_user(), ctime_r_strip_newline(), GSAD_CONTENT_TYPE_APP_XML, user_get_capabilities(), user_get_client_address(), user_get_guest(), user_get_password_warning(), user_get_role(), user_get_session_timeout(), user_get_severity(), user_get_timezone(), user_get_token(), user_get_username(), and vendor_version_get().

Referenced by action_result(), auth_settings_gmp(), cvss_calculator(), edit_alert(), edit_resource(), export_preference_file_gmp(), export_resource(), get_aggregate_gmp(), get_config(), get_config_family(), get_config_nvt(), get_feeds_gmp(), get_many(), get_one(), get_report(), get_setting_gmp(), get_settings_gmp(), get_system_reports_gmp(), get_trash(), login(), new_alert(), save_my_settings_gmp(), wizard(), and wizard_get().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ export_agent_gmp()

char* export_agent_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a agent.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Agent XML on success. Enveloped XML on error.

Definition at line 4981 of file gsad_gmp.c.

4983 {
4984  return export_resource (connection, "agent", credentials, params,
4985  response_data);
4986 }
Structure of credential related information.
char * export_resource(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a resource.
Definition: gsad_gmp.c:1586

References export_resource().

Here is the call graph for this function:

◆ export_agents_gmp()

char* export_agents_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a list of agents.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Agents XML on success. Enveloped XML on error.

Definition at line 5000 of file gsad_gmp.c.

5002 {
5003  return export_many (connection, "agent", credentials, params, response_data);
5004 }
Structure of credential related information.
static char * export_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a list of resources.
Definition: gsad_gmp.c:1738

References export_many().

Here is the call graph for this function:

◆ export_alert_gmp()

char* export_alert_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export an alert.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Alert XML on success. Enveloped XML on error.

Definition at line 6632 of file gsad_gmp.c.

6634 {
6635  return export_resource (connection, "alert", credentials, params,
6636  response_data);
6637 }
Structure of credential related information.
char * export_resource(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a resource.
Definition: gsad_gmp.c:1586

References export_resource().

Here is the call graph for this function:

◆ export_alerts_gmp()

char* export_alerts_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a list of alerts.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Alerts XML on success. Enveloped XML on error.

Definition at line 6651 of file gsad_gmp.c.

6653 {
6654  return export_many (connection, "alert", credentials, params, response_data);
6655 }
Structure of credential related information.
static char * export_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a list of resources.
Definition: gsad_gmp.c:1738

References export_many().

Here is the call graph for this function:

◆ export_asset_gmp()

char* export_asset_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export an asset.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Asset XML on success. Enveloped XML on error.

Definition at line 18835 of file gsad_gmp.c.

18837 {
18838  return export_resource (connection, "asset", credentials, params,
18839  response_data);
18840 }
Structure of credential related information.
char * export_resource(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a resource.
Definition: gsad_gmp.c:1586

References export_resource().

Here is the call graph for this function:

◆ export_assets_gmp()

char* export_assets_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a list of assets.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Assets XML on success. Enveloped XML on error.

Definition at line 18854 of file gsad_gmp.c.

18856 {
18857  return export_many (connection, "asset", credentials, params, response_data);
18858 }
Structure of credential related information.
static char * export_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a list of resources.
Definition: gsad_gmp.c:1738

References export_many().

Here is the call graph for this function:

◆ export_config_gmp()

char* export_config_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a config.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Config XML on success. Enveloped XML on error.

Definition at line 9378 of file gsad_gmp.c.

9380 {
9381  return export_resource (connection, "config", credentials, params,
9382  response_data);
9383 }
Structure of credential related information.
char * export_resource(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a resource.
Definition: gsad_gmp.c:1586

References export_resource().

Here is the call graph for this function:

◆ export_configs_gmp()

char* export_configs_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a list of scan configs.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Scan configs XML on success. Enveloped XML on error.

Definition at line 9397 of file gsad_gmp.c.

9399 {
9400  return export_many (connection, "config", credentials, params, response_data);
9401 }
Structure of credential related information.
static char * export_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a list of resources.
Definition: gsad_gmp.c:1738

References export_many().

Here is the call graph for this function:

◆ export_credential_gmp()

char* export_credential_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a Credential.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Credential XML on success. Enveloped XML on error.

Definition at line 4103 of file gsad_gmp.c.

4105 {
4106  return export_resource (connection, "credential", credentials, params,
4107  response_data);
4108 }
Structure of credential related information.
char * export_resource(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a resource.
Definition: gsad_gmp.c:1586

References export_resource().

Here is the call graph for this function:

◆ export_credentials_gmp()

char* export_credentials_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a list of Credentials.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Credentials XML on success. Enveloped XML on error.

Definition at line 4122 of file gsad_gmp.c.

4125 {
4126  return export_many (connection, "credential", credentials, params,
4127  response_data);
4128 }
Structure of credential related information.
static char * export_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a list of resources.
Definition: gsad_gmp.c:1738

References export_many().

Here is the call graph for this function:

◆ export_filter_gmp()

char* export_filter_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a filter.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Filter XML on success. Enveloped XML on error.

Definition at line 16605 of file gsad_gmp.c.

16607 {
16608  return export_resource (connection, "filter", credentials, params,
16609  response_data);
16610 }
Structure of credential related information.
char * export_resource(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a resource.
Definition: gsad_gmp.c:1586

References export_resource().

Here is the call graph for this function:

◆ export_filters_gmp()

char* export_filters_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a list of filters.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Filters XML on success. Enveloped XML on error.

Definition at line 16624 of file gsad_gmp.c.

16626 {
16627  return export_many (connection, "filter", credentials, params, response_data);
16628 }
Structure of credential related information.
static char * export_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a list of resources.
Definition: gsad_gmp.c:1738

References export_many().

Here is the call graph for this function:

◆ export_group_gmp()

char* export_group_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a group.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Group XML on success. Enveloped XML on error.

Definition at line 14254 of file gsad_gmp.c.

14256 {
14257  return export_resource (connection, "group", credentials, params,
14258  response_data);
14259 }
Structure of credential related information.
char * export_resource(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a resource.
Definition: gsad_gmp.c:1586

References export_resource().

Here is the call graph for this function:

◆ export_groups_gmp()

char* export_groups_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a list of groups.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Groups XML on success. Enveloped XML on error.

Definition at line 14273 of file gsad_gmp.c.

14275 {
14276  return export_many (connection, "group", credentials, params, response_data);
14277 }
Structure of credential related information.
static char * export_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a list of resources.
Definition: gsad_gmp.c:1738

References export_many().

Here is the call graph for this function:

◆ export_many()

static char* export_many ( gvm_connection_t *  connection,
const char *  type,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)
static

Export a list of resources.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
XML on success. XML error object on error.

Definition at line 1738 of file gsad_gmp.c.

1741 {
1742  entity_t entity;
1743  char *content = NULL;
1744  const char *filter;
1745  gchar *filter_escaped;
1746  gchar *type_many;
1747  gchar *fname_format, *file_name;
1748  int ret;
1749 
1750  filter = params_value (params, "filter");
1751 
1752  filter_escaped = g_markup_escape_text (filter, -1);
1753 
1754  if (strcmp (type, "info") == 0)
1755  {
1756  if (gvm_connection_sendf (connection,
1757  "<get_info"
1758  " type=\"%s\""
1759  " export=\"1\""
1760  " details=\"1\""
1761  " filter=\"%s\"/>",
1762  params_value (params, "info_type"),
1763  filter_escaped ? filter_escaped : "")
1764  == -1)
1765  {
1766  g_free (filter_escaped);
1767  cmd_response_data_set_status_code (response_data,
1768  MHD_HTTP_INTERNAL_SERVER_ERROR);
1769  return gsad_message (
1770  credentials, "Internal error", __FUNCTION__, __LINE__,
1771  "An internal error occurred while getting a list. "
1772  "The list could not be delivered. "
1773  "Diagnostics: Failure to send command to manager daemon.",
1774  response_data);
1775  }
1776  }
1777  else if (strcmp (type, "asset") == 0)
1778  {
1779  if (gvm_connection_sendf (connection,
1780  "<get_assets"
1781  " type=\"%s\""
1782  " export=\"1\""
1783  " details=\"1\""
1784  " filter=\"%s\"/>",
1785  params_value (params, "asset_type"),
1786  filter_escaped ? filter_escaped : "")
1787  == -1)
1788  {
1789  g_free (filter_escaped);
1790  cmd_response_data_set_status_code (response_data,
1791  MHD_HTTP_INTERNAL_SERVER_ERROR);
1792  return gsad_message (
1793  credentials, "Internal error", __FUNCTION__, __LINE__,
1794  "An internal error occurred while getting a list. "
1795  "The list could not be delivered. "
1796  "Diagnostics: Failure to send command to manager daemon.",
1797  response_data);
1798  }
1799  }
1800  else
1801  {
1802  if (gvm_connection_sendf (connection,
1803  "<get_%ss"
1804  " export=\"1\""
1805  " details=\"1\""
1806  " filter=\"%s\"/>",
1807  type, filter_escaped ? filter_escaped : "")
1808  == -1)
1809  {
1810  g_free (filter_escaped);
1811  cmd_response_data_set_status_code (response_data,
1812  MHD_HTTP_INTERNAL_SERVER_ERROR);
1813  return gsad_message (
1814  credentials, "Internal error", __FUNCTION__, __LINE__,
1815  "An internal error occurred while getting a list. "
1816  "The list could not be delivered. "
1817  "Diagnostics: Failure to send command to manager daemon.",
1818  response_data);
1819  }
1820  }
1821  g_free (filter_escaped);
1822 
1823  entity = NULL;
1824  if (read_entity_and_text_c (connection, &entity, &content))
1825  {
1826  cmd_response_data_set_status_code (response_data,
1827  MHD_HTTP_INTERNAL_SERVER_ERROR);
1828  return gsad_message (
1829  credentials, "Internal error", __FUNCTION__, __LINE__,
1830  "An internal error occurred while getting a list. "
1831  "The list could not be delivered. "
1832  "Diagnostics: Failure to receive response from manager daemon.",
1833  response_data);
1834  }
1835 
1836  if (!gmp_success (entity))
1837  set_http_status_from_entity (entity, response_data);
1838 
1839  ret = setting_get_value (connection, "0872a6ed-4f85-48c5-ac3f-a5ef5e006745",
1840  &fname_format, response_data);
1841  if (ret)
1842  {
1843  g_free (content);
1844  free_entity (entity);
1845  cmd_response_data_set_status_code (response_data,
1846  MHD_HTTP_INTERNAL_SERVER_ERROR);
1847  switch (ret)
1848  {
1849  case 1:
1850  return gsad_message (
1851  credentials, "Internal error", __FUNCTION__, __LINE__,
1852  "An internal error occurred while getting a setting. "
1853  "The setting could not be delivered. "
1854  "Diagnostics: Failure to send command to manager daemon.",
1855  response_data);
1856  case 2:
1857  return gsad_message (
1858  credentials, "Internal error", __FUNCTION__, __LINE__,
1859  "An internal error occurred while getting a setting. "
1860  "The setting could not be delivered. "
1861  "Diagnostics: Failure to receive response from manager daemon.",
1862  response_data);
1863  default:
1864  return gsad_message (
1865  credentials, "Internal error", __FUNCTION__, __LINE__,
1866  "An internal error occurred while getting a setting. "
1867  "The setting could not be delivered. "
1868  "Diagnostics: Internal error.",
1869  response_data);
1870  }
1871  }
1872 
1873  if (fname_format == NULL)
1874  {
1875  g_warning ("%s : File name format setting not found.", __FUNCTION__);
1876  fname_format = "%T-%D";
1877  }
1878 
1879  if (strcmp (type, "info") == 0)
1880  type_many = g_strdup (type);
1881  else
1882  type_many = g_strdup_printf ("%ss", type);
1883 
1884  file_name =
1885  format_file_name (fname_format, credentials, type_many, "list", NULL);
1886  if (file_name == NULL)
1887  file_name = g_strdup_printf ("%s-%s", type_many, "list");
1888 
1889  g_free (type_many);
1890 
1893  response_data,
1894  g_strdup_printf ("attachment; filename=\"%s.xml\"", file_name));
1895  cmd_response_data_set_content_length (response_data, strlen (content));
1896 
1897  free_entity (entity);
1898  g_free (file_name);
1899  return content;
1900 }
static int setting_get_value(gvm_connection_t *connection, const char *setting_id, gchar **value, cmd_response_data_t *response_data)
Get a setting by UUID for the current user of an GMP connection.
Definition: gsad_gmp.c:888
static int gmp_success(entity_t entity)
Check whether an GMP command failed.
Definition: gsad_gmp.c:656
Structure of credential related information.
void cmd_response_data_set_content_disposition(cmd_response_data_t *data, gchar *content_disposition)
Set content disposition of cmd_response_data_t struct.
Definition: gsad_cmd.c:212
void cmd_response_data_set_content_type(cmd_response_data_t *data, content_type_t content_type)
Set content type of cmd_response_data_t struct.
Definition: gsad_cmd.c:134
gchar * format_file_name(gchar *fname_format, credentials_t *credentials, const char *type, const char *uuid, entity_t resource_entity)
Generates a file name for exporting.
Definition: gsad_gmp.c:1501
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
void set_http_status_from_entity(entity_t entity, cmd_response_data_t *response_data)
Set the HTTP status according to GMP response entity.
Definition: gsad_gmp.c:677
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_content_length(cmd_response_data_t *data, gsize content_length)
Set response content length of cmd_response_data_t struct.
Definition: gsad_cmd.c:186
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References cmd_response_data_set_content_disposition(), cmd_response_data_set_content_length(), cmd_response_data_set_content_type(), cmd_response_data_set_status_code(), format_file_name(), gmp_success(), GSAD_CONTENT_TYPE_APP_XML, gsad_message(), params_value(), set_http_status_from_entity(), and setting_get_value().

Referenced by bulk_export_gmp(), export_agents_gmp(), export_alerts_gmp(), export_assets_gmp(), export_configs_gmp(), export_credentials_gmp(), export_filters_gmp(), export_groups_gmp(), export_notes_gmp(), export_overrides_gmp(), export_permissions_gmp(), export_port_lists_gmp(), export_report_formats_gmp(), export_results_gmp(), export_roles_gmp(), export_scanners_gmp(), export_schedules_gmp(), export_tags_gmp(), export_targets_gmp(), export_tasks_gmp(), and export_users_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ export_note_gmp()

char* export_note_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a note.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Note XML on success. Enveloped XML on error.

Definition at line 9414 of file gsad_gmp.c.

9416 {
9417  return export_resource (connection, "note", credentials, params,
9418  response_data);
9419 }
Structure of credential related information.
char * export_resource(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a resource.
Definition: gsad_gmp.c:1586

References export_resource().

Here is the call graph for this function:

◆ export_notes_gmp()

char* export_notes_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a list of notes.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Notes XML on success. Enveloped XML on error.

Definition at line 9433 of file gsad_gmp.c.

9435 {
9436  return export_many (connection, "note", credentials, params, response_data);
9437 }
Structure of credential related information.
static char * export_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a list of resources.
Definition: gsad_gmp.c:1738

References export_many().

Here is the call graph for this function:

◆ export_override_gmp()

char* export_override_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export an override.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Override XML on success. Enveloped XML on error.

Definition at line 9450 of file gsad_gmp.c.

9452 {
9453  return export_resource (connection, "override", credentials, params,
9454  response_data);
9455 }
Structure of credential related information.
char * export_resource(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a resource.
Definition: gsad_gmp.c:1586

References export_resource().

Here is the call graph for this function:

◆ export_overrides_gmp()

char* export_overrides_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a list of overrides.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Overrides XML on success. Enveloped XML on error.

Definition at line 9469 of file gsad_gmp.c.

9471 {
9472  return export_many (connection, "override", credentials, params,
9473  response_data);
9474 }
Structure of credential related information.
static char * export_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a list of resources.
Definition: gsad_gmp.c:1738

References export_many().

Here is the call graph for this function:

◆ export_permission_gmp()

char* export_permission_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a permission.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Permission XML on success. Enveloped XML on error.

Definition at line 15228 of file gsad_gmp.c.

15230 {
15231  return export_resource (connection, "permission", credentials, params,
15232  response_data);
15233 }
Structure of credential related information.
char * export_resource(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a resource.
Definition: gsad_gmp.c:1586

References export_resource().

Here is the call graph for this function:

◆ export_permissions_gmp()

char* export_permissions_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a list of permissions.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Permissions XML on success. Enveloped XML on error.

Definition at line 15247 of file gsad_gmp.c.

15250 {
15251  return export_many (connection, "permission", credentials, params,
15252  response_data);
15253 }
Structure of credential related information.
static char * export_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a list of resources.
Definition: gsad_gmp.c:1738

References export_many().

Here is the call graph for this function:

◆ export_port_list_gmp()

char* export_port_list_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a Port List.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Port List XML on success. Enveloped XML on error.

Definition at line 9488 of file gsad_gmp.c.

9490 {
9491  return export_resource (connection, "port_list", credentials, params,
9492  response_data);
9493 }
Structure of credential related information.
char * export_resource(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a resource.
Definition: gsad_gmp.c:1586

References export_resource().

Here is the call graph for this function:

◆ export_port_lists_gmp()

char* export_port_lists_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a list of Port Lists.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Port Lists XML on success. Enveloped XML on error.

Definition at line 9507 of file gsad_gmp.c.

9509 {
9510  return export_many (connection, "port_list", credentials, params,
9511  response_data);
9512 }
Structure of credential related information.
static char * export_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a list of resources.
Definition: gsad_gmp.c:1738

References export_many().

Here is the call graph for this function:

◆ export_preference_file_gmp()

char* export_preference_file_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a file preference.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Config XML on success. Enveloped XML on error.

Definition at line 9525 of file gsad_gmp.c.

9528 {
9529  GString *xml;
9530  entity_t entity, preference_entity, value_entity;
9531  const char *config_id, *oid, *preference_name;
9532 
9533  config_id = params_value (params, "config_id");
9534  oid = params_value (params, "oid");
9535  preference_name = params_value (params, "preference_name");
9536 
9537  xml = g_string_new ("<get_preferences_response>");
9538 
9539  CHECK_VARIABLE_INVALID (config_id, "Export Preference File")
9540  CHECK_VARIABLE_INVALID (oid, "Export Preference File")
9541  CHECK_VARIABLE_INVALID (preference_name, "Export Preference File")
9542 
9543  if (gvm_connection_sendf (connection,
9544  "<get_preferences"
9545  " config_id=\"%s\""
9546  " nvt_oid=\"%s\""
9547  " preference=\"%s\"/>",
9548  config_id, oid, preference_name)
9549  == -1)
9550  {
9551  g_string_free (xml, TRUE);
9552  cmd_response_data_set_status_code (response_data,
9553  MHD_HTTP_INTERNAL_SERVER_ERROR);
9554  return gsad_message (
9555  credentials, "Internal error", __FUNCTION__, __LINE__,
9556  "An internal error occurred while getting a preference file. "
9557  "The file could not be delivered. "
9558  "Diagnostics: Failure to send command to manager daemon.",
9559  response_data);
9560  }
9561 
9562  entity = NULL;
9563  if (read_entity_c (connection, &entity))
9564  {
9565  g_string_free (xml, TRUE);
9566  cmd_response_data_set_status_code (response_data,
9567  MHD_HTTP_INTERNAL_SERVER_ERROR);
9568  return gsad_message (
9569  credentials, "Internal error", __FUNCTION__, __LINE__,
9570  "An internal error occurred while getting a preference file. "
9571  "The file could not be delivered. "
9572  "Diagnostics: Failure to receive response from manager daemon.",
9573  response_data);
9574  }
9575 
9576  preference_entity = entity_child (entity, "preference");
9577  if (preference_entity != NULL
9578  && (value_entity = entity_child (preference_entity, "value")))
9579  {
9580  char *content = strdup (entity_text (value_entity));
9581  cmd_response_data_set_content_type (response_data,
9584  response_data,
9585  g_strdup_printf ("attachment; filename=\"pref_file.bin\""));
9586  cmd_response_data_set_content_length (response_data, strlen (content));
9587  free_entity (entity);
9588  g_string_free (xml, TRUE);
9589  return content;
9590  }
9591  else
9592  {
9593  free_entity (entity);
9594  g_string_free (xml, TRUE);
9595  cmd_response_data_set_status_code (response_data,
9596  MHD_HTTP_INTERNAL_SERVER_ERROR);
9597  return gsad_message (
9598  credentials, "Internal error", __FUNCTION__, __LINE__,
9599  "An internal error occurred while getting a preference file. "
9600  "The file could not be delivered. "
9601  "Diagnostics: Failure to receive file from manager daemon.",
9602  response_data);
9603  }
9604 
9605  g_string_append (xml, "</get_preferences_response>");
9606  return envelope_gmp (connection, credentials, params,
9607  g_string_free (xml, FALSE), response_data);
9608 }
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
void cmd_response_data_set_content_disposition(cmd_response_data_t *data, gchar *content_disposition)
Set content disposition of cmd_response_data_t struct.
Definition: gsad_cmd.c:212
void cmd_response_data_set_content_type(cmd_response_data_t *data, content_type_t content_type)
Set content type of cmd_response_data_t struct.
Definition: gsad_cmd.c:134
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_content_length(cmd_response_data_t *data, gsize content_length)
Set response content length of cmd_response_data_t struct.
Definition: gsad_cmd.c:186
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
static char * envelope_gmp(gvm_connection_t *connection, credentials_t *credentials, params_t *params, gchar *xml, cmd_response_data_t *response_data)
Wrap some XML in an envelope.
Definition: gsad_gmp.c:443

References CHECK_VARIABLE_INVALID, cmd_response_data_set_content_disposition(), cmd_response_data_set_content_length(), cmd_response_data_set_content_type(), cmd_response_data_set_status_code(), envelope_gmp(), GSAD_CONTENT_TYPE_OCTET_STREAM, gsad_message(), and params_value().

Here is the call graph for this function:

◆ export_report_format_gmp()

char* export_report_format_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a report format.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Report format XML on success. Enveloped XML on error.

Definition at line 9622 of file gsad_gmp.c.

9625 {
9626  return export_resource (connection, "report_format", credentials, params,
9627  response_data);
9628 }
Structure of credential related information.
char * export_resource(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a resource.
Definition: gsad_gmp.c:1586

References export_resource().

Here is the call graph for this function:

◆ export_report_formats_gmp()

char* export_report_formats_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a list of Report Formats.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Report Formats XML on success. Enveloped XML on error.

Definition at line 9642 of file gsad_gmp.c.

9645 {
9646  return export_many (connection, "report_format", credentials, params,
9647  response_data);
9648 }
Structure of credential related information.
static char * export_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a list of resources.
Definition: gsad_gmp.c:1738

References export_many().

Here is the call graph for this function:

◆ export_resource()

char* export_resource ( gvm_connection_t *  connection,
const char *  type,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a resource.

Parameters
[in]connectionConnection to manager.
[in]typeType of resource.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Resource XML on success. XML error object on error.

Definition at line 1586 of file gsad_gmp.c.

1589 {
1590  GString *xml;
1591  entity_t entity;
1592  entity_t resource_entity;
1593  char *content = NULL;
1594  gchar *id_name;
1595  gchar *fname_format, *file_name;
1596  int ret;
1597  const char *resource_id, *subtype;
1598 
1599  xml = g_string_new ("");
1600 
1601  id_name = g_strdup_printf ("%s_id", type);
1602  resource_id = params_value (params, id_name);
1603  g_free (id_name);
1604 
1605  if (resource_id == NULL)
1606  {
1607  g_string_append (xml, GSAD_MESSAGE_INVALID_PARAM ("Export Resource"));
1608  return envelope_gmp (connection, credentials, params,
1609  g_string_free (xml, FALSE), response_data);
1610  }
1611 
1612  subtype = params_value (params, "subtype");
1613 
1614  if (gvm_connection_sendf (connection,
1615  "<get_%ss"
1616  " %s_id=\"%s\""
1617  "%s%s%s"
1618  " export=\"1\""
1619  " details=\"1\"/>",
1620  type, type, resource_id, subtype ? " type=\"" : "",
1621  subtype ? subtype : "", subtype ? "\"" : "")
1622  == -1)
1623  {
1624  g_string_free (xml, TRUE);
1625  cmd_response_data_set_status_code (response_data,
1626  MHD_HTTP_INTERNAL_SERVER_ERROR);
1627  return gsad_message (
1628  credentials, "Internal error", __FUNCTION__, __LINE__,
1629  "An internal error occurred while getting a resource. "
1630  "The resource could not be delivered. "
1631  "Diagnostics: Failure to send command to manager daemon.",
1632  response_data);
1633  }
1634 
1635  entity = NULL;
1636  if (read_entity_and_text_c (connection, &entity, &content))
1637  {
1638  g_string_free (xml, TRUE);
1639  cmd_response_data_set_status_code (response_data,
1640  MHD_HTTP_INTERNAL_SERVER_ERROR);
1641  return gsad_message (
1642  credentials, "Internal error", __FUNCTION__, __LINE__,
1643  "An internal error occurred while getting a resource. "
1644  "The resource could not be delivered. "
1645  "Diagnostics: Failure to receive response from manager daemon.",
1646  response_data);
1647  }
1648 
1649  if (!gmp_success (entity))
1650  set_http_status_from_entity (entity, response_data);
1651 
1652  resource_entity = entity_child (entity, type);
1653 
1654  if (resource_entity == NULL)
1655  {
1656  g_free (content);
1657  free_entity (entity);
1658  g_string_free (xml, TRUE);
1659  cmd_response_data_set_status_code (response_data,
1660  MHD_HTTP_INTERNAL_SERVER_ERROR);
1661  return gsad_message (
1662  credentials, "Internal error", __FUNCTION__, __LINE__,
1663  "An internal error occurred while getting a resource. "
1664  "The resource could not be delivered. "
1665  "Diagnostics: Failure to receive resource from manager daemon.",
1666  response_data);
1667  }
1668 
1669  ret = setting_get_value (connection, "a6ac88c5-729c-41ba-ac0a-deea4a3441f2",
1670  &fname_format, response_data);
1671  if (ret)
1672  {
1673  g_free (content);
1674  free_entity (entity);
1675  g_string_free (xml, TRUE);
1676  cmd_response_data_set_status_code (response_data,
1677  MHD_HTTP_INTERNAL_SERVER_ERROR);
1678  switch (ret)
1679  {
1680  case 1:
1681  return gsad_message (
1682  credentials, "Internal error", __FUNCTION__, __LINE__,
1683  "An internal error occurred while getting a setting. "
1684  "The setting could not be delivered. "
1685  "Diagnostics: Failure to send command to manager daemon.",
1686  response_data);
1687  case 2:
1688  return gsad_message (
1689  credentials, "Internal error", __FUNCTION__, __LINE__,
1690  "An internal error occurred while getting a setting. "
1691  "The setting could not be delivered. "
1692  "Diagnostics: Failure to receive response from manager daemon.",
1693  response_data);
1694  default:
1695  return gsad_message (
1696  credentials, "Internal error", __FUNCTION__, __LINE__,
1697  "An internal error occurred while getting a setting. "
1698  "The setting could not be delivered. "
1699  "Diagnostics: Internal error.",
1700  response_data);
1701  }
1702  }
1703 
1704  if (fname_format == NULL)
1705  {
1706  g_warning ("%s : File name format setting not found.", __FUNCTION__);
1707  fname_format = "%T-%U";
1708  }
1709 
1710  file_name = format_file_name (fname_format, credentials, type, resource_id,
1711  resource_entity);
1712  if (file_name == NULL)
1713  file_name = g_strdup_printf ("%s-%s", type, resource_id);
1714 
1717  response_data,
1718  g_strdup_printf ("attachment; filename=\"%s.xml\"", file_name));
1719  cmd_response_data_set_content_length (response_data, strlen (content));
1720 
1721  free_entity (entity);
1722  g_free (file_name);
1723  g_string_free (xml, TRUE);
1724  return content;
1725 }
static int setting_get_value(gvm_connection_t *connection, const char *setting_id, gchar **value, cmd_response_data_t *response_data)
Get a setting by UUID for the current user of an GMP connection.
Definition: gsad_gmp.c:888
static int gmp_success(entity_t entity)
Check whether an GMP command failed.
Definition: gsad_gmp.c:656
Structure of credential related information.
#define GSAD_MESSAGE_INVALID_PARAM(op)
Answer for invalid input.
Definition: gsad_gmp.c:83
void cmd_response_data_set_content_disposition(cmd_response_data_t *data, gchar *content_disposition)
Set content disposition of cmd_response_data_t struct.
Definition: gsad_cmd.c:212
void cmd_response_data_set_content_type(cmd_response_data_t *data, content_type_t content_type)
Set content type of cmd_response_data_t struct.
Definition: gsad_cmd.c:134
gchar * format_file_name(gchar *fname_format, credentials_t *credentials, const char *type, const char *uuid, entity_t resource_entity)
Generates a file name for exporting.
Definition: gsad_gmp.c:1501
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
void set_http_status_from_entity(entity_t entity, cmd_response_data_t *response_data)
Set the HTTP status according to GMP response entity.
Definition: gsad_gmp.c:677
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_content_length(cmd_response_data_t *data, gsize content_length)
Set response content length of cmd_response_data_t struct.
Definition: gsad_cmd.c:186
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
static char * envelope_gmp(gvm_connection_t *connection, credentials_t *credentials, params_t *params, gchar *xml, cmd_response_data_t *response_data)
Wrap some XML in an envelope.
Definition: gsad_gmp.c:443

References cmd_response_data_set_content_disposition(), cmd_response_data_set_content_length(), cmd_response_data_set_content_type(), cmd_response_data_set_status_code(), envelope_gmp(), format_file_name(), gmp_success(), GSAD_CONTENT_TYPE_APP_XML, gsad_message(), GSAD_MESSAGE_INVALID_PARAM, params_value(), set_http_status_from_entity(), and setting_get_value().

Referenced by export_agent_gmp(), export_alert_gmp(), export_asset_gmp(), export_config_gmp(), export_credential_gmp(), export_filter_gmp(), export_group_gmp(), export_note_gmp(), export_override_gmp(), export_permission_gmp(), export_port_list_gmp(), export_report_format_gmp(), export_result_gmp(), export_role_gmp(), export_scanner_gmp(), export_schedule_gmp(), export_tag_gmp(), export_target_gmp(), export_task_gmp(), and export_user_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ export_result_gmp()

char* export_result_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Result XML on success. Enveloped XML on error.

Definition at line 10673 of file gsad_gmp.c.

10675 {
10676  return export_resource (connection, "result", credentials, params,
10677  response_data);
10678 }
Structure of credential related information.
char * export_resource(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a resource.
Definition: gsad_gmp.c:1586

References export_resource().

Here is the call graph for this function:

◆ export_results_gmp()

char* export_results_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a list of results.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Results XML on success. Enveloped XML on error.

Definition at line 10692 of file gsad_gmp.c.

10694 {
10695  return export_many (connection, "result", credentials, params, response_data);
10696 }
Structure of credential related information.
static char * export_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a list of resources.
Definition: gsad_gmp.c:1738

References export_many().

Here is the call graph for this function:

◆ export_role_gmp()

char* export_role_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a role.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Role XML on success. Enveloped XML on error.

Definition at line 16111 of file gsad_gmp.c.

16113 {
16114  return export_resource (connection, "role", credentials, params,
16115  response_data);
16116 }
Structure of credential related information.
char * export_resource(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a resource.
Definition: gsad_gmp.c:1586

References export_resource().

Here is the call graph for this function:

◆ export_roles_gmp()

char* export_roles_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a list of roles.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Roles XML on success. Enveloped XML on error.

Definition at line 16130 of file gsad_gmp.c.

16132 {
16133  return export_many (connection, "role", credentials, params, response_data);
16134 }
Structure of credential related information.
static char * export_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a list of resources.
Definition: gsad_gmp.c:1738

References export_many().

Here is the call graph for this function:

◆ export_scanner_gmp()

char* export_scanner_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a scanner.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Scanner XML on success. Enveloped XML on error.

Definition at line 11590 of file gsad_gmp.c.

11592 {
11593  return export_resource (connection, "scanner", credentials, params,
11594  response_data);
11595 }
Structure of credential related information.
char * export_resource(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a resource.
Definition: gsad_gmp.c:1586

References export_resource().

Here is the call graph for this function:

◆ export_scanners_gmp()

char* export_scanners_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a list of scanners.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Scanners XML on success. Enveloped XML on error.

Definition at line 11608 of file gsad_gmp.c.

11610 {
11611  return export_many (connection, "scanner", credentials, params,
11612  response_data);
11613 }
Structure of credential related information.
static char * export_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a list of resources.
Definition: gsad_gmp.c:1738

References export_many().

Here is the call graph for this function:

◆ export_schedule_gmp()

char* export_schedule_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a schedule.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Schedule XML on success. Enveloped XML on error.

Definition at line 16723 of file gsad_gmp.c.

16725 {
16726  return export_resource (connection, "schedule", credentials, params,
16727  response_data);
16728 }
Structure of credential related information.
char * export_resource(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a resource.
Definition: gsad_gmp.c:1586

References export_resource().

Here is the call graph for this function:

◆ export_schedules_gmp()

char* export_schedules_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a list of schedules.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Schedules XML on success. Enveloped XML on error.

Definition at line 16741 of file gsad_gmp.c.

16743 {
16744  return export_many (connection, "schedule", credentials, params,
16745  response_data);
16746 }
Structure of credential related information.
static char * export_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a list of resources.
Definition: gsad_gmp.c:1738

References export_many().

Here is the call graph for this function:

◆ export_tag_gmp()

char* export_tag_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a tag.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Target XML on success. Enveloped XML on error.

Definition at line 7356 of file gsad_gmp.c.

7358 {
7359  return export_resource (connection, "tag", credentials, params,
7360  response_data);
7361 }
Structure of credential related information.
char * export_resource(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a resource.
Definition: gsad_gmp.c:1586

References export_resource().

Here is the call graph for this function:

◆ export_tags_gmp()

char* export_tags_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a list of tags.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Targets XML on success. Enveloped XML on error.

Definition at line 7375 of file gsad_gmp.c.

7377 {
7378  return export_many (connection, "tag", credentials, params, response_data);
7379 }
Structure of credential related information.
static char * export_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a list of resources.
Definition: gsad_gmp.c:1738

References export_many().

Here is the call graph for this function:

◆ export_target_gmp()

char* export_target_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a target.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Target XML on success. Enveloped XML on error.

Definition at line 7848 of file gsad_gmp.c.

7850 {
7851  return export_resource (connection, "target", credentials, params,
7852  response_data);
7853 }
Structure of credential related information.
char * export_resource(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a resource.
Definition: gsad_gmp.c:1586

References export_resource().

Here is the call graph for this function:

◆ export_targets_gmp()

char* export_targets_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a list of targets.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Targets XML on success. Enveloped XML on error.

Definition at line 7867 of file gsad_gmp.c.

7869 {
7870  return export_many (connection, "target", credentials, params, response_data);
7871 }
Structure of credential related information.
static char * export_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a list of resources.
Definition: gsad_gmp.c:1738

References export_many().

Here is the call graph for this function:

◆ export_task_gmp()

char* export_task_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a task.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Note XML on success. Enveloped XML on error.

Definition at line 3160 of file gsad_gmp.c.

3162 {
3163  return export_resource (connection, "task", credentials, params,
3164  response_data);
3165 }
Structure of credential related information.
char * export_resource(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a resource.
Definition: gsad_gmp.c:1586

References export_resource().

Here is the call graph for this function:

◆ export_tasks_gmp()

char* export_tasks_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a list of tasks.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Tasks XML on success. Enveloped XML on error.

Definition at line 3179 of file gsad_gmp.c.

3181 {
3182  return export_many (connection, "task", credentials, params, response_data);
3183 }
Structure of credential related information.
static char * export_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a list of resources.
Definition: gsad_gmp.c:1738

References export_many().

Here is the call graph for this function:

◆ export_user_gmp()

char* export_user_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a user.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Note XML on success. Enveloped XML on error.

Definition at line 17548 of file gsad_gmp.c.

17550 {
17551  return export_resource (connection, "user", credentials, params,
17552  response_data);
17553 }
Structure of credential related information.
char * export_resource(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a resource.
Definition: gsad_gmp.c:1586

References export_resource().

Here is the call graph for this function:

◆ export_users_gmp()

char* export_users_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Export a list of users.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Users XML on success. Enveloped XML on error.

Definition at line 17567 of file gsad_gmp.c.

17569 {
17570  return export_many (connection, "user", credentials, params, response_data);
17571 }
Structure of credential related information.
static char * export_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Export a list of resources.
Definition: gsad_gmp.c:1738

References export_many().

Here is the call graph for this function:

◆ filter_exists()

static int filter_exists ( gvm_connection_t *  connection,
const char *  filt_id 
)
static

Check whether a filter exists.

Parameters
[in]connectionConnection to manager.
[in]entityResponse entity.
Returns
1 success, 0 fail, -1 error, -2 could not send command to server, -3 could not read entity from server.

Definition at line 408 of file gsad_gmp.c.

409 {
410  entity_t entity;
411 
412  if (filt_id == NULL || str_equal (filt_id, FILT_ID_NONE)
413  || str_equal (filt_id, FILT_ID_USER_SETTING))
414  return 1;
415 
416  /* check if filter still exists */
417  if (gvm_connection_sendf (connection, "<get_filters filter_id='%s'/>",
418  filt_id))
419  {
420  return -2;
421  }
422 
423  if (read_entity_c (connection, &entity))
424  {
425  return -3;
426  }
427 
428  return gmp_success (entity);
429 }
static int gmp_success(entity_t entity)
Check whether an GMP command failed.
Definition: gsad_gmp.c:656
gboolean str_equal(const gchar *str1, const gchar *str2)
Check if two strings are equal.
Definition: utils.c:35
#define FILT_ID_NONE
filt_id value to use term or built-in default filter.
Definition: gsad_gmp.c:106
#define FILT_ID_USER_SETTING
filt_id value to use the filter in the user setting if possible.
Definition: gsad_gmp.c:111

References FILT_ID_NONE, FILT_ID_USER_SETTING, gmp_success(), and str_equal().

Referenced by get_many().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ format_file_name()

gchar* format_file_name ( gchar *  fname_format,
credentials_t *  credentials,
const char *  type,
const char *  uuid,
entity_t  resource_entity 
)

Generates a file name for exporting.

Parameters
[in]fname_formatFormat string.
[in]credentialsCurrent credentials.
[in]typeType of resource.
[in]uuidUUID of resource.
[in]resource_entityResource entity to extract extra data from.
Returns
The file name.

Definition at line 1501 of file gsad_gmp.c.

1503 {
1504  gchar *creation_time, *modification_time, *name, *format_name;
1505  gchar *ret;
1506 
1507  if (resource_entity)
1508  {
1509  entity_t creation_time_entity, modification_time_entity;
1510  entity_t task_entity, format_entity, format_name_entity, name_entity;
1511 
1512  creation_time_entity = entity_child (resource_entity, "creation_time");
1513 
1514  if (creation_time_entity)
1515  creation_time = entity_text (creation_time_entity);
1516  else
1517  creation_time = NULL;
1518 
1519  modification_time_entity =
1520  entity_child (resource_entity, "modification_time");
1521 
1522  if (modification_time_entity)
1523  modification_time = entity_text (modification_time_entity);
1524  else
1525  modification_time = NULL;
1526 
1527  if (strcasecmp (type, "report") == 0)
1528  {
1529  task_entity = entity_child (resource_entity, "task");
1530  if (task_entity)
1531  name_entity = entity_child (task_entity, "name");
1532  else
1533  name_entity = NULL;
1534 
1535  format_entity = entity_child (resource_entity, "report_format");
1536  if (format_entity)
1537  {
1538  format_name_entity = entity_child (format_entity, "name");
1539  }
1540  else
1541  format_name_entity = NULL;
1542 
1543  if (format_name_entity && strlen (entity_text (format_name_entity)))
1544  format_name = entity_text (format_name_entity);
1545  else
1546  format_name = NULL;
1547  }
1548  else
1549  {
1550  name_entity = entity_child (resource_entity, "name");
1551  format_name = NULL;
1552  }
1553 
1554  if (name_entity)
1555  name = entity_text (name_entity);
1556  else
1557  name = NULL;
1558  }
1559  else
1560  {
1561  creation_time = NULL;
1562  modification_time = NULL;
1563  name = NULL;
1564  format_name = NULL;
1565  }
1566 
1568  ret =
1569  gvm_export_file_name (fname_format, user_get_username (user), type, uuid,
1570  creation_time, modification_time, name, format_name);
1571  return ret;
1572 }
Structure of credential related information.
const gchar * user_get_username(user_t *user)
Definition: gsad_user.c:157
User information structure, for sessions.
Definition: gsad_user.c:42
user_t * credentials_get_user(credentials_t *cred)

References credentials_get_user(), and user_get_username().

Referenced by export_many(), export_resource(), and get_report().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_agent()

char * get_agent ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get one agent, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 4833 of file gsad_gmp.c.

4836 {
4837  return get_one (connection, "agent", credentials, params, extra_xml, NULL,
4838  response_data);
4839 }
Structure of credential related information.
char * get_one(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get one resource, envelope the result.
Definition: gsad_gmp.c:1060

References get_one().

Referenced by get_agent_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_agent_gmp()

char* get_agent_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get one agent, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 4852 of file gsad_gmp.c.

4854 {
4855  return get_agent (connection, credentials, params, NULL, response_data);
4856 }
Structure of credential related information.
static char * get_agent(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get one agent, envelope the result.
Definition: gsad_gmp.c:4833

References get_agent().

Here is the call graph for this function:

◆ get_agents()

char * get_agents ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get all agents, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 4870 of file gsad_gmp.c.

4873 {
4874  return get_many (connection, "agent", credentials, params, extra_xml, NULL,
4875  response_data);
4876 }
Structure of credential related information.
static char * get_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get all of a particular type of resource, envelope the result.
Definition: gsad_gmp.c:1152

References get_many().

Referenced by get_agents_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_agents_gmp()

char* get_agents_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get all agents, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 4889 of file gsad_gmp.c.

4891 {
4892  return get_agents (connection, credentials, params, NULL, response_data);
4893 }
Structure of credential related information.
static char * get_agents(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get all agents, envelope the result.
Definition: gsad_gmp.c:4870

References get_agents().

Here is the call graph for this function:

◆ get_aggregate_gmp()

char* get_aggregate_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get an aggregate of resources.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
The aggregate.

Definition at line 5017 of file gsad_gmp.c.

5019 {
5020  params_t *data_columns, *text_columns;
5021  params_t *sort_fields, *sort_stats, *sort_orders;
5022  params_iterator_t data_columns_iterator, text_columns_iterator;
5023  params_iterator_t sort_fields_iterator, sort_stats_iterator;
5024  params_iterator_t sort_orders_iterator;
5025  char *param_name;
5026  param_t *param;
5027 
5028  const char *data_column, *group_column, *subgroup_column, *type;
5029  const char *filter, *filt_id;
5030  const char *first_group, *max_groups;
5031  const char *mode;
5032  gchar *filter_escaped, *command_escaped, *response;
5033  entity_t entity;
5034  GString *xml, *command;
5035  int ret;
5036 
5037  data_columns = params_values (params, "data_columns:");
5038  data_column = params_value (params, "data_column");
5039  text_columns = params_values (params, "text_columns:");
5040  group_column = params_value (params, "group_column");
5041  subgroup_column = params_value (params, "subgroup_column");
5042  type = params_value (params, "aggregate_type");
5043  filter = params_value (params, "filter");
5044  filt_id = params_value (params, "filt_id");
5045  sort_fields = params_values (params, "sort_fields:");
5046  sort_stats = params_values (params, "sort_stats:");
5047  sort_orders = params_values (params, "sort_orders:");
5048  first_group = params_value (params, "first_group");
5049  max_groups = params_value (params, "max_groups");
5050  mode = params_value (params, "aggregate_mode");
5051  if (filter && strcmp (filter, ""))
5052  filter_escaped = g_markup_escape_text (filter, -1);
5053  else
5054  {
5055  if (filt_id == NULL || strcmp (filt_id, "") == 0
5056  || strcmp (filt_id, "0") == 0)
5057  filter_escaped = g_strdup ("rows=-2");
5058  else
5059  filter_escaped = NULL;
5060  }
5061 
5062  xml = g_string_new ("<get_aggregate>");
5063 
5064  command = g_string_new ("<get_aggregates");
5065  g_string_append_printf (command, " type=\"%s\"", type);
5066  if (data_column)
5067  g_string_append_printf (command, " data_column=\"%s\"", data_column);
5068  if (group_column)
5069  g_string_append_printf (command, " group_column=\"%s\"", group_column);
5070  if (subgroup_column)
5071  g_string_append_printf (command, " subgroup_column=\"%s\"",
5072  subgroup_column);
5073  if (filter_escaped && strcmp (filter_escaped, ""))
5074  g_string_append_printf (command, " filter=\"%s\"", filter_escaped);
5075  if (filt_id && strcmp (filt_id, ""))
5076  g_string_append_printf (command, " filt_id=\"%s\"", filt_id);
5077  if (first_group && strcmp (first_group, ""))
5078  g_string_append_printf (command, " first_group=\"%s\"", first_group);
5079  if (max_groups && strcmp (max_groups, ""))
5080  g_string_append_printf (command, " max_groups=\"%s\"", max_groups);
5081  if (mode && strcmp (mode, ""))
5082  g_string_append_printf (command, " mode=\"%s\"", mode);
5083  g_string_append (command, ">");
5084 
5085  if (sort_fields && sort_stats && sort_orders)
5086  {
5087  param_t *field_param, *stat_param, *order_param;
5088  gchar *field_i, *stat_i, *order_i;
5089 
5090  params_iterator_init (&sort_fields_iterator, sort_fields);
5091  params_iterator_init (&sort_stats_iterator, sort_stats);
5092  params_iterator_init (&sort_orders_iterator, sort_orders);
5093 
5094  while (
5095  params_iterator_next (&sort_fields_iterator, &field_i, &field_param)
5096  && params_iterator_next (&sort_stats_iterator, &stat_i, &stat_param)
5097  && params_iterator_next (&sort_orders_iterator, &order_i, &order_param))
5098  {
5099  if (field_param->valid && stat_param->valid && order_param->valid)
5100  {
5101  xml_string_append (command,
5102  "<sort field=\"%s\""
5103  " stat=\"%s\""
5104  " order=\"%s\"/>",
5105  field_param->value ? field_param->value : "",
5106  stat_param->value ? stat_param->value : "",
5107  order_param->value ? order_param->value : "");
5108  }
5109  }
5110  }
5111 
5112  if (data_columns)
5113  {
5114  params_iterator_init (&data_columns_iterator, data_columns);
5115  while (params_iterator_next (&data_columns_iterator, &param_name, &param))
5116  {
5117  if (param->valid)
5118  {
5119  xml_string_append (command, "<data_column>%s</data_column>",
5120  param->value);
5121  }
5122  }
5123  }
5124 
5125  if (text_columns)
5126  {
5127  params_iterator_init (&text_columns_iterator, text_columns);
5128  while (params_iterator_next (&text_columns_iterator, &param_name, &param))
5129  {
5130  if (param->valid)
5131  {
5132  xml_string_append (command, "<text_column>%s</text_column>",
5133  param->value);
5134  }
5135  }
5136  }
5137 
5138  g_string_append (command, "</get_aggregates>");
5139 
5140  g_free (filter_escaped);
5141 
5142  command_escaped = g_markup_escape_text (command->str, -1);
5143  g_string_append (xml, command_escaped);
5144  g_free (command_escaped);
5145 
5146  response = NULL;
5147  ret = gmp (connection, credentials, &response, &entity, response_data,
5148  command->str);
5149  g_string_free (command, TRUE);
5150 
5151  if (ret)
5152  {
5153  free_entity (entity);
5154  g_string_free (xml, TRUE);
5155  }
5156 
5157  switch (ret)
5158  {
5159  case 0:
5160  break;
5161  case 1:
5162  cmd_response_data_set_status_code (response_data,
5163  MHD_HTTP_INTERNAL_SERVER_ERROR);
5164  return gsad_message (
5165  credentials, "Internal error", __FUNCTION__, __LINE__,
5166  "An internal error occurred while getting aggregates. "
5167  "Diagnostics: Failure to send command to manager daemon.",
5168  response_data);
5169  case 2:
5170  cmd_response_data_set_status_code (response_data,
5171  MHD_HTTP_INTERNAL_SERVER_ERROR);
5172  return gsad_message (
5173  credentials, "Internal error", __FUNCTION__, __LINE__,
5174  "An internal error occurred while getting aggregates. "
5175  "Diagnostics: Failure to receive response from manager daemon.",
5176  response_data);
5177  default:
5178  cmd_response_data_set_status_code (response_data,
5179  MHD_HTTP_INTERNAL_SERVER_ERROR);
5180  return gsad_message (
5181  credentials, "Internal error", __FUNCTION__, __LINE__,
5182  "An internal error occurred while getting aggregates. "
5183  "Diagnostics: Internal Error.",
5184  response_data);
5185  }
5186 
5187  if (gmp_success (entity) == 0)
5188  set_http_status_from_entity (entity, response_data);
5189  g_string_append (xml, response);
5190 
5191  g_string_append (xml, "</get_aggregate>");
5192 
5193  free_entity (entity);
5194  g_free (response);
5195  return envelope_gmp (connection, credentials, params,
5196  g_string_free (xml, FALSE), response_data);
5197 }
params_t * params_values(params_t *params, const char *name)
Get values of param.
Definition: gsad_base.c:287
gchar * value
Definition: gsad_params.h:40
static int gmp_success(entity_t entity)
Check whether an GMP command failed.
Definition: gsad_gmp.c:656
Structure of credential related information.
#define params_iterator_t
Definition: gsad_params.h:94
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
Request parameter.
Definition: gsad_params.h:38
void set_http_status_from_entity(entity_t entity, cmd_response_data_t *response_data)
Set the HTTP status according to GMP response entity.
Definition: gsad_gmp.c:677
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
gboolean params_iterator_next(params_iterator_t *iterator, char **name, param_t **param)
Increment a params iterator.
Definition: gsad_base.c:394
#define params_iterator_init
Definition: gsad_params.h:96
#define params_t
Definition: gsad_params.h:31
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
int valid
Definition: gsad_params.h:44
static char * envelope_gmp(gvm_connection_t *connection, credentials_t *credentials, params_t *params, gchar *xml, cmd_response_data_t *response_data)
Wrap some XML in an envelope.
Definition: gsad_gmp.c:443

References cmd_response_data_set_status_code(), envelope_gmp(), gmp(), gmp_success(), gsad_message(), params_iterator_init, params_iterator_next(), params_iterator_t, params_t, params_value(), params_values(), set_http_status_from_entity(), param::valid, and param::value.

Here is the call graph for this function:

◆ get_alert()

char * get_alert ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get one alert, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 5843 of file gsad_gmp.c.

5846 {
5847  gchar *html;
5848  GString *extra;
5849 
5850  extra = g_string_new ("");
5851  if (extra_xml)
5852  g_string_append (extra, extra_xml);
5853  if (command_enabled (credentials, "GET_REPORT_FORMATS"))
5854  {
5855  gchar *response;
5856  entity_t entity;
5857 
5858  response = NULL;
5859  entity = NULL;
5860  switch (gmp (connection, credentials, &response, &entity, response_data,
5861  "<get_report_formats"
5862  " filter=\"rows=-1\"/>"))
5863  {
5864  case 0:
5865  case -1:
5866  break;
5867  case 1:
5868  cmd_response_data_set_status_code (response_data,
5869  MHD_HTTP_INTERNAL_SERVER_ERROR);
5870  return gsad_message (
5871  credentials, "Internal error", __FUNCTION__, __LINE__,
5872  "An internal error occurred while getting Report "
5873  "Formats for the alert. "
5874  "Diagnostics: Failure to send command to manager daemon.",
5875  response_data);
5876  case 2:
5877  cmd_response_data_set_status_code (response_data,
5878  MHD_HTTP_INTERNAL_SERVER_ERROR);
5879  return gsad_message (
5880  credentials, "Internal error", __FUNCTION__, __LINE__,
5881  "An internal error occurred while getting Report "
5882  "Formats for the alert. "
5883  "Diagnostics: Failure to receive response from manager daemon.",
5884  response_data);
5885  default:
5886  cmd_response_data_set_status_code (response_data,
5887  MHD_HTTP_INTERNAL_SERVER_ERROR);
5888  return gsad_message (
5889  credentials, "Internal error", __FUNCTION__, __LINE__,
5890  "An internal error occurred while getting Report "
5891  "Formats for the alert. "
5892  "It is unclear whether the task has been saved or not. "
5893  "Diagnostics: Internal Error.",
5894  response_data);
5895  }
5896 
5897  g_string_append (extra, response);
5898 
5899  free_entity (entity);
5900  g_free (response);
5901  }
5902 
5903  if (command_enabled (credentials, "GET_TASKS"))
5904  {
5905  gchar *response;
5906  entity_t entity;
5907 
5908  response = NULL;
5909  entity = NULL;
5910  switch (gmp (connection, credentials, &response, &entity, response_data,
5911  "<get_tasks"
5912  " schedules_only=\"1\""
5913  " filter=\"owner=any permission=start_task rows=-1\"/>"))
5914  {
5915  case 0:
5916  case -1:
5917  break;
5918  case 1:
5919  cmd_response_data_set_status_code (response_data,
5920  MHD_HTTP_INTERNAL_SERVER_ERROR);
5921  return gsad_message (
5922  credentials, "Internal error", __FUNCTION__, __LINE__,
5923  "An internal error occurred while getting Tasks "
5924  "for the alert. "
5925  "Diagnostics: Failure to send command to manager daemon.",
5926  response_data);
5927  case 2:
5928  cmd_response_data_set_status_code (response_data,
5929  MHD_HTTP_INTERNAL_SERVER_ERROR);
5930  return gsad_message (
5931  credentials, "Internal error", __FUNCTION__, __LINE__,
5932  "An internal error occurred while getting Tasks "
5933  "for the alert. "
5934  "Diagnostics: Failure to receive response from manager daemon.",
5935  response_data);
5936  default:
5937  cmd_response_data_set_status_code (response_data,
5938  MHD_HTTP_INTERNAL_SERVER_ERROR);
5939  return gsad_message (credentials, "Internal error", __FUNCTION__,
5940  __LINE__,
5941  "An internal error occurred while getting Tasks "
5942  "for the alert. "
5943  "Diagnostics: Internal Error.",
5944  response_data);
5945  }
5946 
5947  g_string_append (extra, response);
5948 
5949  free_entity (entity);
5950  g_free (response);
5951  }
5952 
5953  if (command_enabled (credentials, "GET_FILTERS"))
5954  {
5955  gchar *response;
5956  entity_t entity;
5957 
5958  /* Get result filters for condition link. */
5959 
5960  response = NULL;
5961  entity = NULL;
5962  switch (gmp (connection, credentials, &response, &entity, response_data,
5963  "<get_filters"
5964  " filter=\"type=result rows=-1\"/>"))
5965  {
5966  case 0:
5967  case -1:
5968  break;
5969  case 1:
5970  cmd_response_data_set_status_code (response_data,
5971  MHD_HTTP_INTERNAL_SERVER_ERROR);
5972  return gsad_message (
5973  credentials, "Internal error", __FUNCTION__, __LINE__,
5974  "An internal error occurred while getting filters "
5975  "for the alert. "
5976  "Diagnostics: Failure to send command to manager daemon.",
5977  response_data);
5978  case 2:
5979  cmd_response_data_set_status_code (response_data,
5980  MHD_HTTP_INTERNAL_SERVER_ERROR);
5981  return gsad_message (
5982  credentials, "Internal error", __FUNCTION__, __LINE__,
5983  "An internal error occurred while getting filters "
5984  "for the alert. "
5985  "Diagnostics: Failure to receive response from manager daemon.",
5986  response_data);
5987  default:
5988  cmd_response_data_set_status_code (response_data,
5989  MHD_HTTP_INTERNAL_SERVER_ERROR);
5990  return gsad_message (
5991  credentials, "Internal error", __FUNCTION__, __LINE__,
5992  "An internal error occurred while getting filters "
5993  "for the alert. "
5994  "Diagnostics: Internal Error.",
5995  response_data);
5996  }
5997 
5998  g_string_append (extra, response);
5999 
6000  free_entity (entity);
6001  g_free (response);
6002  }
6003 
6004  html = get_one (connection, "alert", credentials, params, extra->str,
6005  "tasks=\"1\"", response_data);
6006  g_string_free (extra, TRUE);
6007  return html;
6008 }
Structure of credential related information.
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
int command_enabled(credentials_t *credentials, const gchar *name)
Init the GSA GMP library.
Definition: gsad_gmp.c:352
char * get_one(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get one resource, envelope the result.
Definition: gsad_gmp.c:1060
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References cmd_response_data_set_status_code(), command_enabled(), get_one(), gmp(), and gsad_message().

Referenced by get_alert_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_alert_gmp()

char* get_alert_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get one alert, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 6021 of file gsad_gmp.c.

6023 {
6024  return get_alert (connection, credentials, params, NULL, response_data);
6025 }
Structure of credential related information.
static char * get_alert(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get one alert, envelope the result.
Definition: gsad_gmp.c:5843

References get_alert().

Here is the call graph for this function:

◆ get_alerts()

char * get_alerts ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get all alerts, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 6039 of file gsad_gmp.c.

6042 {
6043  gchar *html;
6044  GString *extra;
6045 
6046  extra = g_string_new ("");
6047  if (command_enabled (credentials, "GET_TASKS"))
6048  {
6049  gchar *response;
6050  entity_t entity;
6051 
6052  response = NULL;
6053  entity = NULL;
6054  switch (gmp (connection, credentials, &response, &entity, response_data,
6055  "<get_tasks"
6056  " schedules_only=\"1\""
6057  " filter=\"owner=any permission=start_task rows=-1\"/>"))
6058  {
6059  case 0:
6060  case -1:
6061  break;
6062  case 1:
6063  cmd_response_data_set_status_code (response_data,
6064  MHD_HTTP_INTERNAL_SERVER_ERROR);
6065  return gsad_message (
6066  credentials, "Internal error", __FUNCTION__, __LINE__,
6067  "An internal error occurred getting the tasks. "
6068  "Diagnostics: Failure to send command to manager daemon.",
6069  response_data);
6070  case 2:
6071  cmd_response_data_set_status_code (response_data,
6072  MHD_HTTP_INTERNAL_SERVER_ERROR);
6073  return gsad_message (
6074  credentials, "Internal error", __FUNCTION__, __LINE__,
6075  "An internal error occurred getting the tasks. "
6076  "Diagnostics: Failure to receive response from manager daemon.",
6077  response_data);
6078  default:
6079  cmd_response_data_set_status_code (response_data,
6080  MHD_HTTP_INTERNAL_SERVER_ERROR);
6081  return gsad_message (
6082  credentials, "Internal error", __FUNCTION__, __LINE__,
6083  "An internal error occurred getting the reports. "
6084  "Diagnostics: Internal Error.",
6085  response_data);
6086  }
6087 
6088  g_string_append (extra, response);
6089 
6090  free_entity (entity);
6091  g_free (response);
6092  }
6093 
6094  if (command_enabled (credentials, "GET_FILTERS"))
6095  {
6096  gchar *response;
6097  entity_t entity;
6098 
6099  /* Get result filters for condition link. */
6100 
6101  response = NULL;
6102  entity = NULL;
6103  switch (gmp (connection, credentials, &response, &entity, response_data,
6104  "<get_filters"
6105  " filter=\"type=result rows=-1\"/>"))
6106  {
6107  case 0:
6108  case -1:
6109  break;
6110  case 1:
6111  cmd_response_data_set_status_code (response_data,
6112  MHD_HTTP_INTERNAL_SERVER_ERROR);
6113  return gsad_message (
6114  credentials, "Internal error", __FUNCTION__, __LINE__,
6115  "An internal error occurred while getting filters "
6116  "for the alerts. "
6117  "Diagnostics: Failure to send command to manager daemon.",
6118  response_data);
6119  case 2:
6120  cmd_response_data_set_status_code (response_data,
6121  MHD_HTTP_INTERNAL_SERVER_ERROR);
6122  return gsad_message (
6123  credentials, "Internal error", __FUNCTION__, __LINE__,
6124  "An internal error occurred while getting filters "
6125  "for the alerts. "
6126  "Diagnostics: Failure to receive response from manager daemon.",
6127  response_data);
6128  default:
6129  cmd_response_data_set_status_code (response_data,
6130  MHD_HTTP_INTERNAL_SERVER_ERROR);
6131  return gsad_message (
6132  credentials, "Internal error", __FUNCTION__, __LINE__,
6133  "An internal error occurred while getting filters "
6134  "for the alerts. "
6135  "Diagnostics: Internal Error.",
6136  response_data);
6137  }
6138 
6139  g_string_append (extra, response);
6140 
6141  free_entity (entity);
6142  g_free (response);
6143  }
6144 
6145  if (extra_xml)
6146  g_string_append (extra, extra_xml);
6147  html = get_many (connection, "alert", credentials, params, extra->str, NULL,
6148  response_data);
6149  g_string_free (extra, TRUE);
6150  return html;
6151 }
Structure of credential related information.
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
int command_enabled(credentials_t *credentials, const gchar *name)
Init the GSA GMP library.
Definition: gsad_gmp.c:352
static char * get_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get all of a particular type of resource, envelope the result.
Definition: gsad_gmp.c:1152
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References cmd_response_data_set_status_code(), command_enabled(), get_many(), gmp(), and gsad_message().

Referenced by get_alerts_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_alerts_gmp()

char* get_alerts_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get all alerts, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 6164 of file gsad_gmp.c.

6166 {
6167  return get_alerts (connection, credentials, params, NULL, response_data);
6168 }
Structure of credential related information.
static char * get_alerts(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get all alerts, envelope the result.
Definition: gsad_gmp.c:6039

References get_alerts().

Here is the call graph for this function:

◆ get_asset()

char * get_asset ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Request an asset.

Parameters
[in]connectionConnection to manager.
[in]credentialsCredentials for the manager connection.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
XML enveloped asset response or error message.

Definition at line 18507 of file gsad_gmp.c.

18510 {
18511  char *ret;
18512  GString *extra_attribs, *extra_response;
18513  const char *asset_type;
18514 
18515  asset_type = params_value (params, "asset_type");
18516  if (asset_type == NULL)
18517  {
18518  param_t *param;
18519  param = params_add (params, "asset_type", "host");
18520  param->valid = 1;
18521  param->valid_utf8 = g_utf8_validate (param->value, -1, NULL);
18522  asset_type = params_value (params, "asset_type");
18523  }
18524 
18525  if (strcmp (asset_type, "host") && strcmp (asset_type, "os"))
18526  {
18527  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
18528  return gsad_message (credentials, "Internal error", __FUNCTION__,
18529  __LINE__,
18530  "An internal error occurred while getting an asset. "
18531  "Diagnostics: Invalid asset_type parameter value",
18532  response_data);
18533  }
18534 
18535  if (params_value (params, "asset_name") && params_value (params, "asset_id"))
18536  {
18537  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
18538  return gsad_message (credentials, "Internal error", __FUNCTION__,
18539  __LINE__,
18540  "An internal error occurred while getting an asset. "
18541  "Diagnostics: Both ID and Name set.",
18542  response_data);
18543  }
18544 
18545  extra_response = g_string_new (extra_xml ? extra_xml : "");
18546 
18547  extra_attribs = g_string_new ("");
18548  g_string_append_printf (extra_attribs, "type=\"%s\"",
18549  params_value (params, "asset_type"));
18550  if (params_value (params, "asset_name"))
18551  g_string_append_printf (extra_attribs, " name=\"%s\"",
18552  params_value (params, "asset_name"));
18553  else if (params_value (params, "asset_id"))
18554  g_string_append_printf (extra_attribs, " asset_id=\"%s\"",
18555  params_value (params, "asset_id"));
18556  if (params_value (params, "details"))
18557  g_string_append_printf (extra_attribs, " details=\"%s\"",
18558  params_value (params, "details"));
18559 
18560  ret = get_one (connection, "asset", credentials, params, extra_response->str,
18561  extra_attribs->str, response_data);
18562 
18563  g_string_free (extra_response, TRUE);
18564  g_string_free (extra_attribs, TRUE);
18565 
18566  return ret;
18567 }
gchar * value
Definition: gsad_params.h:40
Structure of credential related information.
int valid_utf8
Definition: gsad_params.h:45
char * get_one(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get one resource, envelope the result.
Definition: gsad_gmp.c:1060
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
Request parameter.
Definition: gsad_params.h:38
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
int valid
Definition: gsad_params.h:44
param_t * params_add(params_t *params, const char *name, const char *value)
Add a param.
Definition: gsad_base.c:318

References cmd_response_data_set_status_code(), get_one(), gsad_message(), params_add(), params_value(), param::valid, param::valid_utf8, and param::value.

Referenced by get_asset_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_asset_gmp()

char* get_asset_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get asset, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 18580 of file gsad_gmp.c.

18582 {
18583  return get_asset (connection, credentials, params, NULL, response_data);
18584 }
Structure of credential related information.
static char * get_asset(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Request an asset.
Definition: gsad_gmp.c:18507

References get_asset().

Here is the call graph for this function:

◆ get_assets()

char * get_assets ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Request assets.

Parameters
[in]connectionConnection to manager.
[in]credentialsCredentials for the manager connection.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
XML enveloped assets response or error message.

Definition at line 18598 of file gsad_gmp.c.

18601 {
18602  char *ret;
18603  GString *extra_attribs, *extra_response;
18604  const char *asset_type;
18605 
18606  asset_type = params_value (params, "asset_type");
18607  if (asset_type == NULL)
18608  {
18609  param_t *param;
18610  param = params_add (params, "asset_type", "host");
18611  param->valid = 1;
18612  param->valid_utf8 = g_utf8_validate (param->value, -1, NULL);
18613  asset_type = params_value (params, "asset_type");
18614  }
18615 
18616  if (strcmp (asset_type, "host") && strcmp (asset_type, "os"))
18617  {
18618  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
18619  return gsad_message (credentials, "Internal error", __FUNCTION__,
18620  __LINE__,
18621  "An internal error occurred while getting Assets. "
18622  "Diagnostics: Invalid asset_type parameter value",
18623  response_data);
18624  }
18625 
18626  extra_response = g_string_new (extra_xml ? extra_xml : "");
18627 
18628  extra_attribs = g_string_new ("");
18629  g_string_append_printf (extra_attribs, "type=\"%s\" ignore_pagination=\"%s\"",
18630  params_value (params, "asset_type"),
18631  params_value (params, "ignore_pagination")
18632  ? params_value (params, "ignore_pagination")
18633  : "0");
18634  if (params_value (params, "details"))
18635  g_string_append_printf (extra_attribs, " details=\"%s\"",
18636  params_value (params, "details"));
18637  ret = get_many (connection, "asset", credentials, params, extra_response->str,
18638  extra_attribs->str, response_data);
18639 
18640  g_string_free (extra_response, TRUE);
18641  g_string_free (extra_attribs, TRUE);
18642 
18643  return ret;
18644 }
gchar * value
Definition: gsad_params.h:40
Structure of credential related information.
int valid_utf8
Definition: gsad_params.h:45
static char * get_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get all of a particular type of resource, envelope the result.
Definition: gsad_gmp.c:1152
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
Request parameter.
Definition: gsad_params.h:38
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
int valid
Definition: gsad_params.h:44
param_t * params_add(params_t *params, const char *name, const char *value)
Add a param.
Definition: gsad_base.c:318

References cmd_response_data_set_status_code(), get_many(), gsad_message(), params_add(), params_value(), param::valid, param::valid_utf8, and param::value.

Referenced by get_assets_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_assets_gmp()

char* get_assets_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get assets, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 18657 of file gsad_gmp.c.

18659 {
18660  return get_assets (connection, credentials, params, NULL, response_data);
18661 }
static char * get_assets(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Request assets.
Definition: gsad_gmp.c:18598
Structure of credential related information.

References get_assets().

Here is the call graph for this function:

◆ get_config()

static char * get_config ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
int  edit,
cmd_response_data_t *  response_data 
)
static

Get a config, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[in]edit0 for config view page, else config edit page.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 8078 of file gsad_gmp.c.

8081 {
8082  GString *xml;
8083  const char *config_id;
8084 
8085  config_id = params_value (params, "config_id");
8086 
8087  if (config_id == NULL)
8088  return get_configs (connection, credentials, params, extra_xml,
8089  response_data);
8090 
8091  xml = g_string_new ("<get_config_response>");
8092  if (edit)
8093  g_string_append (xml, "<edit/>");
8094 
8095  if (extra_xml)
8096  g_string_append (xml, extra_xml);
8097  /* Get the config families. */
8098 
8099  if (gvm_connection_sendf (connection,
8100  "<get_configs"
8101  " config_id=\"%s\""
8102  " families=\"1\""
8103  " tasks=\"1\""
8104  " preferences=\"1\"/>",
8105  config_id)
8106  == -1)
8107  {
8108  g_string_free (xml, TRUE);
8109  cmd_response_data_set_status_code (response_data,
8110  MHD_HTTP_INTERNAL_SERVER_ERROR);
8111  return gsad_message (
8112  credentials, "Internal error", __FUNCTION__, __LINE__,
8113  "An internal error occurred while getting the config. "
8114  "The config is not available. "
8115  "Diagnostics: Failure to send command to manager daemon.",
8116  response_data);
8117  }
8118 
8119  if (read_string_c (connection, &xml))
8120  {
8121  g_string_free (xml, TRUE);
8122  cmd_response_data_set_status_code (response_data,
8123  MHD_HTTP_INTERNAL_SERVER_ERROR);
8124  return gsad_message (
8125  credentials, "Internal error", __FUNCTION__, __LINE__,
8126  "An internal error occurred while getting the config. "
8127  "The config is not available. "
8128  "Diagnostics: Failure to receive response from manager daemon.",
8129  response_data);
8130  }
8131 
8132  /* Get all the families. */
8133 
8134  if (gvm_connection_sendf (connection, "<get_nvt_families/>") == -1)
8135  {
8136  g_string_free (xml, TRUE);
8137  cmd_response_data_set_status_code (response_data,
8138  MHD_HTTP_INTERNAL_SERVER_ERROR);
8139  return gsad_message (
8140  credentials, "Internal error", __FUNCTION__, __LINE__,
8141  "An internal error occurred while getting the config. "
8142  "The config is not available. "
8143  "Diagnostics: Failure to send command to manager daemon.",
8144  response_data);
8145  }
8146 
8147  if (read_string_c (connection, &xml))
8148  {
8149  g_string_free (xml, TRUE);
8150  cmd_response_data_set_status_code (response_data,
8151  MHD_HTTP_INTERNAL_SERVER_ERROR);
8152  return gsad_message (
8153  credentials, "Internal error", __FUNCTION__, __LINE__,
8154  "An internal error occurred while getting the config. "
8155  "The config is not available. "
8156  "Diagnostics: Failure to receive response from manager daemon.",
8157  response_data);
8158  }
8159 
8160  if (edit)
8161  {
8162  /* Get OSP scanners */
8163  if (gvm_connection_sendf (connection, "<get_scanners filter=\"type=1\"/>")
8164  == -1)
8165  {
8166  g_string_free (xml, TRUE);
8167  cmd_response_data_set_status_code (response_data,
8168  MHD_HTTP_INTERNAL_SERVER_ERROR);
8169  return gsad_message (
8170  credentials, "Internal error", __FUNCTION__, __LINE__,
8171  "An internal error occurred while getting the config. "
8172  "The config is not available. "
8173  "Diagnostics: Failure to send command to manager daemon.",
8174  response_data);
8175  }
8176 
8177  if (read_string_c (connection, &xml))
8178  {
8179  g_string_free (xml, TRUE);
8180  cmd_response_data_set_status_code (response_data,
8181  MHD_HTTP_INTERNAL_SERVER_ERROR);
8182  return gsad_message (
8183  credentials, "Internal error", __FUNCTION__, __LINE__,
8184  "An internal error occurred while getting the config. "
8185  "The config is not available. "
8186  "Diagnostics: Failure to receive response from manager daemon.",
8187  response_data);
8188  }
8189  }
8190 
8191  /* Get Credentials */
8192  if (gvm_connection_sendf (connection, "<get_credentials/>") == -1)
8193  {
8194  g_string_free (xml, TRUE);
8195  cmd_response_data_set_status_code (response_data,
8196  MHD_HTTP_INTERNAL_SERVER_ERROR);
8197  return gsad_message (
8198  credentials, "Internal error", __FUNCTION__, __LINE__,
8199  "An internal error occurred while getting the config. "
8200  "The config is not available. "
8201  "Diagnostics: Failure to send command to manager daemon.",
8202  response_data);
8203  }
8204  if (read_string_c (connection, &xml))
8205  {
8206  g_string_free (xml, TRUE);
8207  cmd_response_data_set_status_code (response_data,
8208  MHD_HTTP_INTERNAL_SERVER_ERROR);
8209  return gsad_message (
8210  credentials, "Internal error", __FUNCTION__, __LINE__,
8211  "An internal error occurred while getting the config. "
8212  "The config is not available. "
8213  "Diagnostics: Failure to receive response from manager daemon.",
8214  response_data);
8215  }
8216 
8217  /* Get the permissions */
8218 
8219  g_string_append (xml, "<permissions>");
8220 
8221  if (gvm_connection_sendf (connection,
8222  "<get_permissions"
8223  " filter=\"name:^.*(config)s?$"
8224  " and resource_uuid=%s"
8225  " first=1 rows=-1\"/>",
8226  config_id)
8227  == -1)
8228  {
8229  g_string_free (xml, TRUE);
8230  cmd_response_data_set_status_code (response_data,
8231  MHD_HTTP_INTERNAL_SERVER_ERROR);
8232  return gsad_message (
8233  credentials, "Internal error", __FUNCTION__, __LINE__,
8234  "An internal error occurred while getting permissions list. "
8235  "The current list of resources is not available. "
8236  "Diagnostics: Failure to send command to manager daemon.",
8237  response_data);
8238  }
8239 
8240  if (read_string_c (connection, &xml))
8241  {
8242  g_string_free (xml, TRUE);
8243  cmd_response_data_set_status_code (response_data,
8244  MHD_HTTP_INTERNAL_SERVER_ERROR);
8245  return gsad_message (
8246  credentials, "Internal error", __FUNCTION__, __LINE__,
8247  "An internal error occurred while getting permissions list. "
8248  "The current list of resources is not available. "
8249  "Diagnostics: Failure to receive response from manager daemon.",
8250  response_data);
8251  }
8252 
8253  g_string_append (xml, "</permissions>");
8254 
8255  /* Cleanup, and return transformed XML. */
8256 
8257  g_string_append (xml, "</get_config_response>");
8258  return envelope_gmp (connection, credentials, params,
8259  g_string_free (xml, FALSE), response_data);
8260 }
Structure of credential related information.
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
static char * get_configs(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get all scan configs, envelope the result.
Definition: gsad_gmp.c:8040
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
static char * envelope_gmp(gvm_connection_t *connection, credentials_t *credentials, params_t *params, gchar *xml, cmd_response_data_t *response_data)
Wrap some XML in an envelope.
Definition: gsad_gmp.c:443

References cmd_response_data_set_status_code(), envelope_gmp(), get_configs(), gsad_message(), and params_value().

Referenced by edit_config(), and get_config_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_config_family()

static char * get_config_family ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
int  edit,
cmd_response_data_t *  response_data 
)
static

Get details of a family for a config, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]edit0 for config view page, else config edit page.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 8712 of file gsad_gmp.c.

8715 {
8716  GString *xml;
8717  const char *config_id, *name, *family, *sort_field, *sort_order;
8718 
8719  config_id = params_value (params, "config_id");
8720  name = params_value (params, "name");
8721  family = params_value (params, "family");
8722 
8723  if ((config_id == NULL) || (name == NULL) || (family == NULL))
8724  {
8725  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
8726  return gsad_message (
8727  credentials, "Internal error", __FUNCTION__, __LINE__,
8728  "An internal error occurred while getting config family. "
8729  "Diagnostics: Required parameter was NULL.",
8730  response_data);
8731  }
8732 
8733  xml = g_string_new ("<get_config_family_response>");
8734  if (edit)
8735  g_string_append (xml, "<edit/>");
8736  /* @todo Would it be better include this in the get_nvts response? */
8737  g_string_append_printf (xml,
8738  "<config id=\"%s\">"
8739  "<name>%s</name><family>%s</family>"
8740  "</config>",
8741  config_id, name, family);
8742 
8743  /* Get the details for all NVT's in the config in the family. */
8744 
8745  sort_field = params_value (params, "sort_field");
8746  sort_order = params_value (params, "sort_order");
8747 
8748  if (gvm_connection_sendf (
8749  connection,
8750  "<get_nvts"
8751  " config_id=\"%s\" details=\"1\""
8752  " family=\"%s\" timeout=\"1\" preference_count=\"1\""
8753  " sort_field=\"%s\" sort_order=\"%s\"/>",
8754  config_id, family, sort_field ? sort_field : "nvts.name",
8755  sort_order ? sort_order : "ascending")
8756  == -1)
8757  {
8758  g_string_free (xml, TRUE);
8759  cmd_response_data_set_status_code (response_data,
8760  MHD_HTTP_INTERNAL_SERVER_ERROR);
8761  return gsad_message (
8762  credentials, "Internal error", __FUNCTION__, __LINE__,
8763  "An internal error occurred while getting list of configs. "
8764  "The current list of configs is not available. "
8765  "Diagnostics: Failure to send command to manager daemon.",
8766  response_data);
8767  }
8768 
8769  if (read_string_c (connection, &xml))
8770  {
8771  g_string_free (xml, TRUE);
8772  cmd_response_data_set_status_code (response_data,
8773  MHD_HTTP_INTERNAL_SERVER_ERROR);
8774  return gsad_message (
8775  credentials, "Internal error", __FUNCTION__, __LINE__,
8776  "An internal error occurred while getting list of configs. "
8777  "The current list of configs is not available. "
8778  "Diagnostics: Failure to receive response from manager daemon.",
8779  response_data);
8780  }
8781 
8782  if (edit)
8783  {
8784  /* Get the details for all NVT's in the family. */
8785 
8786  g_string_append (xml, "<all>");
8787 
8788  if (gvm_connection_sendf (connection,
8789  "<get_nvts"
8790  " details=\"1\""
8791  " timeout=\"1\""
8792  " family=\"%s\""
8793  " preferences_config_id=\"%s\""
8794  " preference_count=\"1\""
8795  " sort_field=\"%s\""
8796  " sort_order=\"%s\"/>",
8797  family, config_id,
8798  sort_field ? sort_field : "nvts.name",
8799  sort_order ? sort_order : "ascending")
8800  == -1)
8801  {
8802  g_string_free (xml, TRUE);
8803  cmd_response_data_set_status_code (response_data,
8804  MHD_HTTP_INTERNAL_SERVER_ERROR);
8805  return gsad_message (
8806  credentials, "Internal error", __FUNCTION__, __LINE__,
8807  "An internal error occurred while getting list of configs. "
8808  "The current list of configs is not available. "
8809  "Diagnostics: Failure to send command to manager daemon.",
8810  response_data);
8811  }
8812 
8813  if (read_string_c (connection, &xml))
8814  {
8815  g_string_free (xml, TRUE);
8816  cmd_response_data_set_status_code (response_data,
8817  MHD_HTTP_INTERNAL_SERVER_ERROR);
8818  return gsad_message (
8819  credentials, "Internal error", __FUNCTION__, __LINE__,
8820  "An internal error occurred while getting list of configs. "
8821  "The current list of configs is not available. "
8822  "Diagnostics: Failure to receive response from manager daemon.",
8823  response_data);
8824  }
8825 
8826  g_string_append (xml, "</all>");
8827  }
8828 
8829  g_string_append (xml, "</get_config_family_response>");
8830  return envelope_gmp (connection, credentials, params,
8831  g_string_free (xml, FALSE), response_data);
8832 }
Structure of credential related information.
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
static char * envelope_gmp(gvm_connection_t *connection, credentials_t *credentials, params_t *params, gchar *xml, cmd_response_data_t *response_data)
Wrap some XML in an envelope.
Definition: gsad_gmp.c:443

References cmd_response_data_set_status_code(), envelope_gmp(), gsad_message(), and params_value().

Referenced by edit_config_family_gmp(), and get_config_family_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_config_family_gmp()

char* get_config_family_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get details of a family for a config, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 8845 of file gsad_gmp.c.

8847 {
8848  return get_config_family (connection, credentials, params, 0, response_data);
8849 }
Structure of credential related information.
static char * get_config_family(gvm_connection_t *, credentials_t *, params_t *, int, cmd_response_data_t *)
Get details of a family for a config, envelope the result.
Definition: gsad_gmp.c:8712

References get_config_family().

Here is the call graph for this function:

◆ get_config_gmp()

char* get_config_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get a config, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 8273 of file gsad_gmp.c.

8275 {
8276  return get_config (connection, credentials, params, NULL, 0, response_data);
8277 }
Structure of credential related information.
static char * get_config(gvm_connection_t *, credentials_t *, params_t *, const char *, int, cmd_response_data_t *)
Get a config, envelope the result.
Definition: gsad_gmp.c:8078

References get_config().

Here is the call graph for this function:

◆ get_config_nvt()

static char* get_config_nvt ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
int  edit,
cmd_response_data_t *  response_data 
)
static

Get details of an NVT for a config, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]edit0 for config view page, else config edit page.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 8968 of file gsad_gmp.c.

8970 {
8971  GString *xml;
8972  const char *config_id, *name, *family, *sort_field, *sort_order, *nvt;
8973 
8974  config_id = params_value (params, "config_id");
8975  name = params_value (params, "name");
8976  family = params_value (params, "family");
8977  nvt = params_value (params, "oid");
8978 
8979  CHECK_VARIABLE_INVALID (name, "Get Config")
8980  CHECK_VARIABLE_INVALID (config_id, "Get Config")
8981 
8982  xml = g_string_new ("<get_config_nvt_response>");
8983  if (edit)
8984  g_string_append (xml, "<edit/>");
8985  /* @todo Would it be better include this in the get_nvts response? */
8986  g_string_append_printf (xml,
8987  "<config id=\"%s\">"
8988  "<name>%s</name><family>%s</family>"
8989  "</config>",
8990  config_id, name, family ? family : "");
8991 
8992  sort_field = params_value (params, "sort_field");
8993  sort_order = params_value (params, "sort_order");
8994 
8995  if (gvm_connection_sendf (connection,
8996  "<get_nvts"
8997  " config_id=\"%s\" nvt_oid=\"%s\""
8998  " details=\"1\" preferences=\"1\""
8999  " sort_field=\"%s\" sort_order=\"%s\"/>",
9000  config_id, nvt,
9001  sort_field ? sort_field : "nvts.name",
9002  sort_order ? sort_order : "ascending")
9003  == -1)
9004  {
9005  g_string_free (xml, TRUE);
9006  cmd_response_data_set_status_code (response_data,
9007  MHD_HTTP_INTERNAL_SERVER_ERROR);
9008  return gsad_message (
9009  credentials, "Internal error", __FUNCTION__, __LINE__,
9010  "An internal error occurred while getting list of configs. "
9011  "The current list of configs is not available. "
9012  "Diagnostics: Failure to send command to manager daemon.",
9013  response_data);
9014  }
9015 
9016  if (read_string_c (connection, &xml))
9017  {
9018  g_string_free (xml, TRUE);
9019  cmd_response_data_set_status_code (response_data,
9020  MHD_HTTP_INTERNAL_SERVER_ERROR);
9021  return gsad_message (
9022  credentials, "Internal error", __FUNCTION__, __LINE__,
9023  "An internal error occurred while getting list of configs. "
9024  "The current list of configs is not available. "
9025  "Diagnostics: Failure to receive response from manager daemon.",
9026  response_data);
9027  }
9028 
9029  g_string_append (xml, "</get_config_nvt_response>");
9030 
9031  if (gvm_connection_sendf (connection,
9032  "<get_notes"
9033  " nvt_oid=\"%s\""
9034  " sort_field=\"notes.text\"/>",
9035  nvt)
9036  == -1)
9037  {
9038  g_string_free (xml, TRUE);
9039  cmd_response_data_set_status_code (response_data,
9040  MHD_HTTP_INTERNAL_SERVER_ERROR);
9041  return gsad_message (
9042  credentials, "Internal error", __FUNCTION__, __LINE__,
9043  "An internal error occurred while getting list of notes. "
9044  "The current list of notes is not available. "
9045  "Diagnostics: Failure to send command to manager daemon.",
9046  response_data);
9047  }
9048 
9049  if (read_string_c (connection, &xml))
9050  {
9051  g_string_free (xml, TRUE);
9052  cmd_response_data_set_status_code (response_data,
9053  MHD_HTTP_INTERNAL_SERVER_ERROR);
9054  return gsad_message (
9055  credentials, "Internal error", __FUNCTION__, __LINE__,
9056  "An internal error occurred while getting list of notes. "
9057  "The current list of notes is not available. "
9058  "Diagnostics: Failure to receive response from manager daemon.",
9059  response_data);
9060  }
9061 
9062  if (gvm_connection_sendf (connection,
9063  "<get_overrides"
9064  " nvt_oid=\"%s\""
9065  " sort_field=\"overrides.text\"/>",
9066  nvt)
9067  == -1)
9068  {
9069  g_string_free (xml, TRUE);
9070  cmd_response_data_set_status_code (response_data,
9071  MHD_HTTP_INTERNAL_SERVER_ERROR);
9072  return gsad_message (
9073  credentials, "Internal error", __FUNCTION__, __LINE__,
9074  "An internal error occurred while getting list of overrides. "
9075  "The current list of overrides is not available. "
9076  "Diagnostics: Failure to send command to manager daemon.",
9077  response_data);
9078  }
9079 
9080  if (read_string_c (connection, &xml))
9081  {
9082  g_string_free (xml, TRUE);
9083  cmd_response_data_set_status_code (response_data,
9084  MHD_HTTP_INTERNAL_SERVER_ERROR);
9085  return gsad_message (
9086  credentials, "Internal error", __FUNCTION__, __LINE__,
9087  "An internal error occurred while getting list of overrides. "
9088  "The current list of overrides is not available. "
9089  "Diagnostics: Failure to receive response from manager daemon.",
9090  response_data);
9091  }
9092 
9093  return envelope_gmp (connection, credentials, params,
9094  g_string_free (xml, FALSE), response_data);
9095 }
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
static char * envelope_gmp(gvm_connection_t *connection, credentials_t *credentials, params_t *params, gchar *xml, cmd_response_data_t *response_data)
Wrap some XML in an envelope.
Definition: gsad_gmp.c:443

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), envelope_gmp(), gsad_message(), and params_value().

Referenced by edit_config_nvt_gmp(), and get_config_nvt_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_config_nvt_gmp()

char* get_config_nvt_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get details of an NVT for a config, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 9108 of file gsad_gmp.c.

9110 {
9111  return get_config_nvt (connection, credentials, params, 0, response_data);
9112 }
Structure of credential related information.
static char * get_config_nvt(gvm_connection_t *connection, credentials_t *credentials, params_t *params, int edit, cmd_response_data_t *response_data)
Get details of an NVT for a config, envelope the result.
Definition: gsad_gmp.c:8968

References get_config_nvt().

Here is the call graph for this function:

◆ get_configs()

static char * get_configs ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get all scan configs, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 8040 of file gsad_gmp.c.

8043 {
8044  return get_many (connection, "config", credentials, params, extra_xml, NULL,
8045  response_data);
8046 }
Structure of credential related information.
static char * get_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get all of a particular type of resource, envelope the result.
Definition: gsad_gmp.c:1152

References get_many().

Referenced by get_config(), get_configs_gmp(), and sync_config_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_configs_gmp()

char* get_configs_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get all scan configs, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 8059 of file gsad_gmp.c.

8061 {
8062  return get_configs (connection, credentials, params, NULL, response_data);
8063 }
Structure of credential related information.
static char * get_configs(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get all scan configs, envelope the result.
Definition: gsad_gmp.c:8040

References get_configs().

Here is the call graph for this function:

◆ get_credential()

static char * get_credential ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get one credential, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]commandsExtra commands to run before the others.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 3878 of file gsad_gmp.c.

3881 {
3882  return get_one (connection, "credential", credentials, params, extra_xml,
3883  "targets=\"1\" scanners=\"1\"", response_data);
3884 }
Structure of credential related information.
char * get_one(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get one resource, envelope the result.
Definition: gsad_gmp.c:1060

References get_one().

Referenced by get_credential_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_credential_gmp()

char* get_credential_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get one credential, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 3897 of file gsad_gmp.c.

3899 {
3900  return get_credential (connection, credentials, params, NULL, response_data);
3901 }
Structure of credential related information.
static char * get_credential(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get one credential, envelope the result.
Definition: gsad_gmp.c:3878

References get_credential().

Here is the call graph for this function:

◆ get_credentials()

static char * get_credentials ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get one or all credentials, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]commandsExtra commands to run before the others when credential_id is NULL.
[out]response_dataExtra data return for the HTTP response.
Returns
0 success, 1 failure.

Definition at line 4143 of file gsad_gmp.c.

4146 {
4147  return get_many (connection, "credential", credentials, params, extra_xml,
4148  NULL, response_data);
4149 }
Structure of credential related information.
static char * get_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get all of a particular type of resource, envelope the result.
Definition: gsad_gmp.c:1152

References get_many().

Referenced by get_credentials_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_credentials_gmp()

char* get_credentials_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get one or all credentials, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
0 success, 1 failure.

Definition at line 4162 of file gsad_gmp.c.

4164 {
4165  return get_credentials (connection, credentials, params, NULL, response_data);
4166 }
Structure of credential related information.
static char * get_credentials(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get one or all credentials, envelope the result.
Definition: gsad_gmp.c:4143

References get_credentials().

Here is the call graph for this function:

◆ get_feeds_gmp()

char* get_feeds_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get descriptions of the feeds connected to the manager.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 16231 of file gsad_gmp.c.

16233 {
16234  entity_t entity;
16235  char *text = NULL;
16236  gchar *response;
16237  time_t now;
16238  struct tm *tm;
16239  gchar current_timestamp[30];
16240 
16241  if (gvm_connection_sendf (connection, "<get_feeds/>") == -1)
16242  {
16243  cmd_response_data_set_status_code (response_data,
16244  MHD_HTTP_INTERNAL_SERVER_ERROR);
16245  return gsad_message (
16246  credentials, "Internal error", __FUNCTION__, __LINE__,
16247  "An internal error occurred while getting the feed list. "
16248  "The current list of feeds is not available. "
16249  "Diagnostics: Failure to send command to manager daemon.",
16250  response_data);
16251  }
16252 
16253  if (read_entity_and_text_c (connection, &entity, &text))
16254  {
16255  cmd_response_data_set_status_code (response_data,
16256  MHD_HTTP_INTERNAL_SERVER_ERROR);
16257  return gsad_message (
16258  credentials, "Internal error", __FUNCTION__, __LINE__,
16259  "An internal error occurred while getting the feed. "
16260  "The current list of feeds is not available. "
16261  "Diagnostics: Failure to receive response from manager daemon.",
16262  response_data);
16263  }
16264 
16265  time (&now);
16266  tm = gmtime (&now);
16267  if (tm == NULL
16268  || (strftime (current_timestamp, 29, "%Y-%m-%dT%H:%M:%S", tm) == 0))
16269  {
16270  current_timestamp[0] = '\0';
16271  }
16272 
16273  response = g_strdup_printf ("<get_feeds>"
16274  "%s"
16275  "<current_time_utc>%s</current_time_utc>"
16276  "</get_feeds>",
16277  text, current_timestamp);
16278 
16279  g_free (text);
16280 
16281  return envelope_gmp (connection, credentials, params, response,
16282  response_data);
16283 }
Structure of credential related information.
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
static char * envelope_gmp(gvm_connection_t *connection, credentials_t *credentials, params_t *params, gchar *xml, cmd_response_data_t *response_data)
Wrap some XML in an envelope.
Definition: gsad_gmp.c:443

References cmd_response_data_set_status_code(), envelope_gmp(), and gsad_message().

Here is the call graph for this function:

◆ get_filter()

char * get_filter ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get one filter, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 16413 of file gsad_gmp.c.

16416 {
16417  return get_one (connection, "filter", credentials, params, extra_xml,
16418  "alerts=\"1\"", response_data);
16419 }
Structure of credential related information.
char * get_one(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get one resource, envelope the result.
Definition: gsad_gmp.c:1060

References get_one().

Referenced by get_filter_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_filter_gmp()

char* get_filter_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get one filter, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 16432 of file gsad_gmp.c.

16434 {
16435  return get_filter (connection, credentials, params, NULL, response_data);
16436 }
Structure of credential related information.
static char * get_filter(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get one filter, envelope the result.
Definition: gsad_gmp.c:16413

References get_filter().

Here is the call graph for this function:

◆ get_filters()

char * get_filters ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get all filters, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 16450 of file gsad_gmp.c.

16453 {
16454  return get_many (connection, "filter", credentials, params, extra_xml, NULL,
16455  response_data);
16456 }
Structure of credential related information.
static char * get_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get all of a particular type of resource, envelope the result.
Definition: gsad_gmp.c:1152

References get_many().

Referenced by get_filters_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_filters_gmp()

char* get_filters_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get all filters, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 16469 of file gsad_gmp.c.

16471 {
16472  return get_filters (connection, credentials, params, NULL, response_data);
16473 }
Structure of credential related information.
static char * get_filters(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get all filters, envelope the result.
Definition: gsad_gmp.c:16450

References get_filters().

Here is the call graph for this function:

◆ get_group()

static char * get_group ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get one group, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 14062 of file gsad_gmp.c.

14065 {
14066  return get_one (connection, "group", credentials, params, extra_xml, NULL,
14067  response_data);
14068 }
Structure of credential related information.
char * get_one(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get one resource, envelope the result.
Definition: gsad_gmp.c:1060

References get_one().

Referenced by get_group_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_group_gmp()

char* get_group_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get one group, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 14081 of file gsad_gmp.c.

14083 {
14084  return get_group (connection, credentials, params, NULL, response_data);
14085 }
Structure of credential related information.
static char * get_group(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get one group, envelope the result.
Definition: gsad_gmp.c:14062

References get_group().

Here is the call graph for this function:

◆ get_groups()

static char * get_groups ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get all groups, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 14099 of file gsad_gmp.c.

14102 {
14103  return get_many (connection, "group", credentials, params, extra_xml, NULL,
14104  response_data);
14105 }
Structure of credential related information.
static char * get_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get all of a particular type of resource, envelope the result.
Definition: gsad_gmp.c:1152

References get_many().

Referenced by get_groups_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_groups_gmp()

char* get_groups_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get all groups, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 14118 of file gsad_gmp.c.

14120 {
14121  return get_groups (connection, credentials, params, NULL, response_data);
14122 }
Structure of credential related information.
static char * get_groups(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get all groups, envelope the result.
Definition: gsad_gmp.c:14099

References get_groups().

Here is the call graph for this function:

◆ get_hosts_from_params()

const char* get_hosts_from_params ( params_t *  params)

Get hosts from request params.

Parameters
[in]paramsRequest parameters.
Returns
The hosts

Definition at line 10868 of file gsad_gmp.c.

10869 {
10870  const char *hosts;
10871 
10872  if (params_valid (params, "hosts"))
10873  {
10874  hosts = params_value (params, "hosts");
10875  if (strcmp (hosts, "--") == 0)
10876  {
10877  if (params_valid (params, "hosts_manual"))
10878  hosts = params_value (params, "hosts_manual");
10879  else if (params_given (params, "hosts_manual")
10880  && strcmp (params_original_value (params, "hosts_manual"),
10881  ""))
10882  hosts = NULL;
10883  else
10884  hosts = "";
10885  }
10886  }
10887  else if (strcmp (params_original_value (params, "hosts"), ""))
10888  hosts = NULL;
10889  else
10890  hosts = "";
10891 
10892  return hosts;
10893 }
int params_given(params_t *params, const char *name)
Get whether a param was given at all.
Definition: gsad_base.c:189
const char * params_original_value(params_t *params, const char *name)
Get original value of param, before validation.
Definition: gsad_base.c:255
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
int params_valid(params_t *params, const char *name)
Get whether a param is valid.
Definition: gsad_base.c:303

References params_given(), params_original_value(), params_valid(), and params_value().

Referenced by create_note_gmp(), create_override_gmp(), save_note_gmp(), and save_override_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_info()

char* get_info ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)

Requests SecInfo.

Parameters
[in]connectionConnection to manager.
[in]credentialsCredentials for the manager connection.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
XML enveloped SecInfo response or error message.

Definition at line 3325 of file gsad_gmp.c.

3328 {
3329  char *ret;
3330  GString *extra_attribs, *extra_response;
3331  const char *info_type;
3332 
3333  info_type = params_value (params, "info_type");
3334  if (info_type == NULL)
3335  {
3336  param_t *param;
3337  param = params_add (params, "info_type", "nvt");
3338  param->valid = 1;
3339  param->valid_utf8 = g_utf8_validate (param->value, -1, NULL);
3340  info_type = params_value (params, "info_type");
3341  }
3342 
3343  if (strcmp (info_type, "nvt") && strcmp (info_type, "cve")
3344  && strcmp (info_type, "cpe") && strcmp (info_type, "ovaldef")
3345  && strcmp (info_type, "cert_bund_adv")
3346  && strcmp (info_type, "dfn_cert_adv") && strcmp (info_type, "allinfo")
3347  && strcmp (info_type, "NVT") && strcmp (info_type, "CVE")
3348  && strcmp (info_type, "CPE") && strcmp (info_type, "OVALDEF")
3349  && strcmp (info_type, "CERT_BUND_ADV")
3350  && strcmp (info_type, "DFN_CERT_ADV") && strcmp (info_type, "ALLINFO"))
3351  {
3352  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
3353  return gsad_message (credentials, "Internal error", __FUNCTION__,
3354  __LINE__,
3355  "An internal error occurred while getting SecInfo. "
3356  "Diagnostics: Invalid info_type parameter value",
3357  response_data);
3358  }
3359 
3360  if (params_value (params, "info_name") && params_value (params, "info_id"))
3361  {
3362  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
3363  return gsad_message (credentials, "Internal error", __FUNCTION__,
3364  __LINE__,
3365  "An internal error occurred while getting SecInfo. "
3366  "Diagnostics: Both ID and Name set.",
3367  response_data);
3368  }
3369  extra_response = g_string_new (extra_xml ? extra_xml : "");
3370 
3371  if (command_enabled (credentials, "GET_NOTES")
3372  && (strcasecmp (info_type, "NVT") == 0)
3373  && params_value (params, "info_id"))
3374  {
3375  gchar *response;
3376 
3377  if (simple_gmpf (connection, "getting SecInfo", credentials, &response,
3378  response_data,
3379  "<get_notes"
3380  " nvt_oid=\"%s\""
3381  " sort_field=\"notes.text\"/>",
3382  params_value (params, "info_id")))
3383  {
3384  g_string_free (extra_response, TRUE);
3385  return response;
3386  }
3387 
3388  g_string_append (extra_response, response);
3389  }
3390 
3391  if (command_enabled (credentials, "GET_OVERRIDES")
3392  && (strcasecmp (info_type, "NVT") == 0)
3393  && params_value (params, "info_id"))
3394  {
3395  gchar *response;
3396 
3397  if (simple_gmpf (connection, "getting SecInfo", credentials, &response,
3398  response_data,
3399  "<get_overrides"
3400  " nvt_oid=\"%s\""
3401  " sort_field=\"overrides.text\"/>",
3402  params_value (params, "info_id")))
3403  {
3404  g_string_free (extra_response, TRUE);
3405  return response;
3406  }
3407 
3408  g_string_append (extra_response, response);
3409  }
3410 
3411  extra_attribs = g_string_new ("");
3412  g_string_append_printf (extra_attribs, "type=\"%s\"",
3413  params_value (params, "info_type"));
3414  if (params_value (params, "info_name"))
3415  g_string_append_printf (extra_attribs, " name=\"%s\"",
3416  params_value (params, "info_name"));
3417  else if (params_value (params, "info_id"))
3418  g_string_append_printf (extra_attribs, " info_id=\"%s\"",
3419  params_value (params, "info_id"));
3420  if (params_value (params, "details"))
3421  g_string_append_printf (extra_attribs, " details=\"%s\"",
3422  params_value (params, "details"));
3423  ret = get_many (connection, "info", credentials, params, extra_response->str,
3424  extra_attribs->str, response_data);
3425 
3426  g_string_free (extra_response, TRUE);
3427  g_string_free (extra_attribs, TRUE);
3428 
3429  return ret;
3430 }
gchar * value
Definition: gsad_params.h:40
Structure of credential related information.
static int simple_gmpf(gvm_connection_t *connection, const gchar *message_operation, credentials_t *credentials, gchar **response, cmd_response_data_t *response_data, const char *format,...)
Run a single GMP command, preparing a response even on error.
Definition: gsad_gmp.c:749
int valid_utf8
Definition: gsad_params.h:45
int command_enabled(credentials_t *credentials, const gchar *name)
Init the GSA GMP library.
Definition: gsad_gmp.c:352
static char * get_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get all of a particular type of resource, envelope the result.
Definition: gsad_gmp.c:1152
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
Request parameter.
Definition: gsad_params.h:38
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
int valid
Definition: gsad_params.h:44
param_t * params_add(params_t *params, const char *name, const char *value)
Add a param.
Definition: gsad_base.c:318

References cmd_response_data_set_status_code(), command_enabled(), get_many(), gsad_message(), params_add(), params_value(), simple_gmpf(), param::valid, param::valid_utf8, and param::value.

Referenced by get_info_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_info_gmp()

char* get_info_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get info, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 3443 of file gsad_gmp.c.

3445 {
3446  return get_info (connection, credentials, params, NULL, response_data);
3447 }
Structure of credential related information.
char * get_info(gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
Requests SecInfo.
Definition: gsad_gmp.c:3325

References get_info().

Here is the call graph for this function:

◆ get_many()

static char* get_many ( gvm_connection_t *  connection,
const char *  type,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
const char *  extra_attribs,
cmd_response_data_t *  response_data 
)
static

Get all of a particular type of resource, envelope the result.

Parameters
[in]connectionConnection to manager
[in]typeResource type.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[in]extra_attribsExtra attributes for GMP GET command.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 1152 of file gsad_gmp.c.

1155 {
1156  GString *xml;
1157  GString *type_many; /* The plural form of type */
1158  gchar *request, *built_filter;
1159  const char *build_filter, *filt_id, *filter, *filter_extra;
1160  const char *first, *max, *sort_field, *sort_order, *owner, *permission;
1161  const char *replace_task_id;
1162  const char *overrides, *autofp, *autofp_value, *min_qod;
1163  const char *level_high, *level_medium, *level_low, *level_log;
1164  const char *level_false_positive;
1165  const char *details;
1166 
1167  build_filter = params_value (params, "build_filter");
1168  filt_id = params_value (params, "filt_id");
1169  filter = params_value (params, "filter");
1170  filter_extra = params_value (params, "filter_extra");
1171  first = params_value (params, "first");
1172  max = params_value (params, "max");
1173  replace_task_id = params_value (params, "replace_task_id");
1174  sort_field = params_value (params, "sort_field");
1175  sort_order = params_value (params, "sort_order");
1176  owner = params_value (params, "owner");
1177  permission = params_value (params, "permission");
1178  overrides = params_value (params, "overrides");
1179  autofp = params_value (params, "autofp");
1180  autofp_value = params_value (params, "autofp_value");
1181  min_qod = params_value (params, "min_qod");
1182  level_high = params_value (params, "level_high");
1183  level_medium = params_value (params, "level_medium");
1184  level_low = params_value (params, "level_low");
1185  level_log = params_value (params, "level_log");
1186  level_false_positive = params_value (params, "level_false_positive");
1187  details = params_value (params, "details");
1188 
1189  if (details == NULL || strcmp (details, "") == 0)
1190  details = "0";
1191 
1192  /* check if filter still exists */
1193  switch (filter_exists (connection, filt_id))
1194  {
1195  case 1:
1196  break;
1197  case 0:
1198  g_debug ("%s filter doesn't exist anymore %s!\n", __FUNCTION__, filt_id);
1199  filt_id = NULL;
1200  break;
1201  case -1:
1202  g_debug ("%s filter response didn't contain a status!\n", __FUNCTION__);
1203  filt_id = NULL;
1204  break;
1205  case -2:
1206  g_debug ("%s could not send filter request!\n", __FUNCTION__);
1207  filt_id = NULL;
1208  break;
1209  case -3:
1210  g_debug ("%s could not read entity from filter response!\n",
1211  __FUNCTION__);
1212  filt_id = NULL;
1213  break;
1214  default:
1215  filt_id = NULL;
1216  }
1217 
1218  xml = g_string_new ("");
1219  type_many = g_string_new (type);
1220 
1221  /* Workaround the fact that info is a non countable noun */
1222  if (strcmp (type, "info") != 0)
1223  g_string_append (type_many, "s");
1224 
1225  g_string_append_printf (xml, "<get_%s>", type_many->str);
1226 
1227  if (extra_xml)
1228  g_string_append (xml, extra_xml);
1229 
1230  built_filter = NULL;
1231  if (filt_id == NULL || str_equal (filt_id, "") || str_equal (filt_id, "--"))
1232  {
1233  if ((build_filter && str_equal (build_filter, "1"))
1234  || ((filter == NULL || str_equal (filter, ""))
1235  && (filter_extra == NULL || str_equal (filter_extra, ""))))
1236  {
1237  if (build_filter && (strcmp (build_filter, "1") == 0))
1238  {
1239  gchar *task;
1240  const char *search_phrase, *task_id;
1241 
1242  if (str_equal (type, "report") || str_equal (type, "task"))
1243  {
1244  task =
1245  g_strdup_printf ("apply_overrides=%i min_qod=%s ",
1246  overrides && !str_equal (overrides, "0"),
1247  min_qod ? min_qod : "");
1248  }
1249  else if (strcmp (type, "result") == 0)
1250  {
1251  gchar *levels = g_strdup_printf (
1252  "%s%s%s%s%s", level_high ? "h" : "",
1253  level_medium ? "m" : "", level_low ? "l" : "",
1254  level_log ? "g" : "", level_false_positive ? "f" : "");
1255  task = g_strdup_printf (
1256  "apply_overrides=%i min_qod=%s"
1257  " autofp=%s levels=%s ",
1258  (overrides && !str_equal (overrides, "0")),
1259  min_qod ? min_qod : "",
1260  (autofp && autofp_value) ? autofp_value : "0", levels);
1261  g_free (levels);
1262  }
1263  else
1264  task = NULL;
1265 
1266  search_phrase = params_value (params, "search_phrase");
1267  task_id = params_value (params, "task_id");
1268  built_filter = g_strdup_printf (
1269  "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
1270  task ? task : "", task_id ? "task_id=" : "",
1271  task_id ? task_id : "", task_id ? " " : "",
1272  first ? "first=" : "", first ? first : "", first ? " " : "",
1273  max ? "rows=" : "", max ? max : "", max ? " " : "",
1274  sort_field ? ((sort_order && strcmp (sort_order, "ascending"))
1275  ? "sort-reverse="
1276  : "sort=")
1277  : "",
1278  sort_field ? sort_field : "", sort_field ? " " : "",
1279  permission ? "permission=" : "", permission ? permission : "",
1280  permission ? " " : "", owner ? "owner=" : "",
1281  owner ? owner : "", owner ? " " : "",
1282  (filter && search_phrase) ? " " : "", filter ? filter : "",
1283  search_phrase ? " " : "", search_phrase ? search_phrase : "");
1284  filt_id = FILT_ID_USER_SETTING;
1285  g_free (task);
1286  }
1287  else if (strcmp (type, "info") == 0
1288  && params_value (params, "info_type"))
1289  {
1290  if (str_equal (params_value (params, "info_type"), "cve"))
1291  filter = "sort-reverse=published rows=-2";
1292  else if (str_equal (params_value (params, "info_type"), "cpe"))
1293  filter = "sort-reverse=modified rows=-2";
1294  else
1295  filter = "sort-reverse=created rows=-2";
1296  }
1297  else if (str_equal (type, "user"))
1298  filter = "sort=roles rows=-2";
1299  else if (str_equal (type, "report"))
1300  {
1301  const char *task_id;
1302  task_id = params_value (params, "task_id");
1303  if (task_id)
1304  built_filter = g_strdup_printf ("task_id=%s apply_overrides=1"
1305  " rows=-2 sort-reverse=date",
1306  task_id);
1307  else
1308  filter = "apply_overrides=1 rows=-2 sort-reverse=date";
1309  }
1310  else if (str_equal (type, "result"))
1311  {
1312  built_filter = g_strdup_printf (
1313  "apply_overrides=%d autofp=%s rows=-2"
1314  " sort-reverse=created",
1315  (overrides == NULL || str_equal (overrides, "1")),
1316  (autofp && str_equal (autofp, "1")) ? autofp_value : "0");
1317  }
1318  else if (str_equal (type, "note") || str_equal (type, "override"))
1319  {
1320  filter = "rows=-2 sort=nvt";
1321  }
1322  else if (!str_equal (type, "task"))
1323  filter = "rows=-2";
1324  else
1325  filter = "apply_overrides=1 rows=-2";
1326  if (filt_id && !str_equal (filt_id, ""))
1327  /* Request to use "filter" instead. */
1328  filt_id = FILT_ID_NONE;
1329  else
1330  filt_id = FILT_ID_USER_SETTING;
1331  }
1332  else if (str_equal (filter, "sort=nvt")
1333  && (str_equal (type, "note") || str_equal (type, "override")))
1334  filt_id = FILT_ID_USER_SETTING;
1335  else if (str_equal (filter, "apply_overrides=1")
1336  && str_equal (type, "task"))
1337  filt_id = FILT_ID_USER_SETTING;
1338  }
1339  else if (replace_task_id)
1340  {
1341  const char *task_id;
1342  task_id = params_value (params, "task_id");
1343  if (task_id)
1344  built_filter =
1345  g_strdup_printf ("task_id=%s %s", task_id, filter ? filter : "");
1346  }
1347 
1348  /* Get the list. */
1349 
1350  request = g_markup_printf_escaped (
1351  " %sfilt_id=\"%s\""
1352  " %sfilter=\"%s%s%s%s\""
1353  " filter_replace=\"%s\""
1354  " first=\"%s\""
1355  " max=\"%s\""
1356  " sort_field=\"%s\""
1357  " sort_order=\"%s\"",
1358  strcmp (type, "report") ? "" : "report_", filt_id ? filt_id : "0",
1359  strcmp (type, "report") ? "" : "report_",
1360  built_filter ? built_filter : (filter ? filter : ""),
1361  filter_extra ? " " : "", filter_extra ? filter_extra : "",
1362  filter_extra ? " " : "", replace_task_id ? "task_id" : "",
1363  first ? first : "1", max ? max : "-2", sort_field ? sort_field : "name",
1364  sort_order ? sort_order : "ascending");
1365 
1366  g_free (built_filter);
1367  if (gvm_connection_sendf (connection, "<get_%s details=\"%s\" %s %s/>",
1368  type_many->str,
1369  strcmp (type, "report") ? details : "0", request,
1370  extra_attribs ? extra_attribs : "")
1371  == -1)
1372  {
1373  g_free (request);
1374  g_string_free (xml, TRUE);
1375  g_string_free (type_many, TRUE);
1376  cmd_response_data_set_status_code (response_data,
1377  MHD_HTTP_INTERNAL_SERVER_ERROR);
1378  return gsad_message (
1379  credentials, "Internal error", __FUNCTION__, __LINE__,
1380  "An internal error occurred while getting a resource list. "
1381  "The current list of resources is not available. "
1382  "Diagnostics: Failure to send command to manager daemon.",
1383  response_data);
1384  }
1385  g_free (request);
1386  if (read_string_c (connection, &xml))
1387  {
1388  g_string_free (xml, TRUE);
1389  g_string_free (type_many, TRUE);
1390  cmd_response_data_set_status_code (response_data,
1391  MHD_HTTP_INTERNAL_SERVER_ERROR);
1392  return gsad_message (
1393  credentials, "Internal error", __FUNCTION__, __LINE__,
1394  "An internal error occurred while getting resources list. "
1395  "The current list of resources is not available. "
1396  "Diagnostics: Failure to receive response from manager daemon.",
1397  response_data);
1398  }
1399 
1400  /* Cleanup, and return transformed XML. */
1401  g_string_append_printf (xml, "</get_%s>", type_many->str);
1402  g_string_free (type_many, TRUE);
1403  return envelope_gmp (connection, credentials, params,
1404  g_string_free (xml, FALSE), response_data);
1405 }
Structure of credential related information.
gboolean str_equal(const gchar *str1, const gchar *str2)
Check if two strings are equal.
Definition: utils.c:35
static int filter_exists(gvm_connection_t *connection, const char *filt_id)
Check whether a filter exists.
Definition: gsad_gmp.c:408
#define FILT_ID_NONE
filt_id value to use term or built-in default filter.
Definition: gsad_gmp.c:106
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
#define FILT_ID_USER_SETTING
filt_id value to use the filter in the user setting if possible.
Definition: gsad_gmp.c:111
static char * envelope_gmp(gvm_connection_t *connection, credentials_t *credentials, params_t *params, gchar *xml, cmd_response_data_t *response_data)
Wrap some XML in an envelope.
Definition: gsad_gmp.c:443

References cmd_response_data_set_status_code(), envelope_gmp(), FILT_ID_NONE, FILT_ID_USER_SETTING, filter_exists(), gsad_message(), params_value(), and str_equal().

Referenced by get_agents(), get_alerts(), get_assets(), get_configs(), get_credentials(), get_filters(), get_groups(), get_info(), get_notes(), get_overrides(), get_permissions(), get_port_lists(), get_report_formats(), get_reports(), get_results(), get_roles(), get_scanners(), get_schedules(), get_tags(), get_targets(), get_tasks(), get_tickets_gmp(), get_users(), and get_vulns().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_note()

static char * get_note ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get a note, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 10809 of file gsad_gmp.c.

10812 {
10813  return get_one (connection, "note", credentials, params, extra_xml,
10814  "result=\"1\"", response_data);
10815 }
Structure of credential related information.
char * get_one(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get one resource, envelope the result.
Definition: gsad_gmp.c:1060

References get_one().

Referenced by get_note_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_note_gmp()

char* get_note_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get a note, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 10828 of file gsad_gmp.c.

10830 {
10831  return get_note (connection, credentials, params, NULL, response_data);
10832 }
Structure of credential related information.
static char * get_note(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get a note, envelope the result.
Definition: gsad_gmp.c:10809

References get_note().

Here is the call graph for this function:

◆ get_notes()

static char * get_notes ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get all notes, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 10772 of file gsad_gmp.c.

10775 {
10776  return get_many (connection, "note", credentials, params, extra_xml, NULL,
10777  response_data);
10778 }
Structure of credential related information.
static char * get_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get all of a particular type of resource, envelope the result.
Definition: gsad_gmp.c:1152

References get_many().

Referenced by get_notes_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_notes_gmp()

char* get_notes_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get all notes, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 10791 of file gsad_gmp.c.

10793 {
10794  return get_notes (connection, credentials, params, NULL, response_data);
10795 }
Structure of credential related information.
static char * get_notes(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get all notes, envelope the result.
Definition: gsad_gmp.c:10772

References get_notes().

Here is the call graph for this function:

◆ get_one()

char* get_one ( gvm_connection_t *  connection,
const char *  type,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
const char *  extra_attribs,
cmd_response_data_t *  response_data 
)

Get one resource, envelope the result.

Parameters
[in]connectionConnection to manager
[in]typeType of resource.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[in]extra_attribsExtra attributes for GMP GET command.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 1060 of file gsad_gmp.c.

1063 {
1064  GString *xml;
1065  gchar *id_name;
1066  const char *id;
1067  entity_t entity;
1068 
1069  id_name = g_strdup_printf ("%s_id", type);
1070  id = params_value (params, id_name);
1071  g_free (id_name);
1072 
1073  CHECK_VARIABLE_INVALID (id, "Get")
1074 
1075  xml = g_string_new ("");
1076  g_string_append_printf (xml, "<get_%s>", type);
1077 
1078  if (extra_xml)
1079  g_string_append (xml, extra_xml);
1080 
1081  /* Get the resource. */
1082 
1083  if (gvm_connection_sendf (connection,
1084  "<get_%ss"
1085  " %s_id=\"%s\""
1086  " details=\"1\""
1087  " %s/>",
1088  type, type, id, extra_attribs ? extra_attribs : "")
1089  == -1)
1090  {
1091  g_string_free (xml, TRUE);
1092  cmd_response_data_set_status_code (response_data,
1093  MHD_HTTP_INTERNAL_SERVER_ERROR);
1094  return gsad_message (
1095  credentials, "Internal error", __FUNCTION__, __LINE__,
1096  "An internal error occurred while getting resources list. "
1097  "The current list of resources is not available. "
1098  "Diagnostics: Failure to send command to manager daemon.",
1099  response_data);
1100  }
1101 
1102  if (read_entity_and_string_c (connection, &entity, &xml))
1103  {
1104  g_string_free (xml, TRUE);
1105  cmd_response_data_set_status_code (response_data,
1106  MHD_HTTP_INTERNAL_SERVER_ERROR);
1107  return gsad_message (
1108  credentials, "Internal error", __FUNCTION__, __LINE__,
1109  "An internal error occurred while getting resources list. "
1110  "The current list of resources is not available. "
1111  "Diagnostics: Failure to receive response from manager daemon.",
1112  response_data);
1113  }
1114 
1115  if (gmp_success (entity) != 1)
1116  {
1117  gchar *message;
1118 
1119  set_http_status_from_entity (entity, response_data);
1120 
1121  message =
1122  gsad_message (credentials, "Error", __FUNCTION__, __LINE__,
1123  entity_attribute (entity, "status_text"), response_data);
1124 
1125  g_string_free (xml, TRUE);
1126  free_entity (entity);
1127  return message;
1128  }
1129 
1130  /* Cleanup, and return transformed XML. */
1131  free_entity (entity);
1132 
1133  g_string_append_printf (xml, "</get_%s>", type);
1134  return envelope_gmp (connection, credentials, params,
1135  g_string_free (xml, FALSE), response_data);
1136 }
static int gmp_success(entity_t entity)
Check whether an GMP command failed.
Definition: gsad_gmp.c:656
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
void set_http_status_from_entity(entity_t entity, cmd_response_data_t *response_data)
Set the HTTP status according to GMP response entity.
Definition: gsad_gmp.c:677
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
static char * envelope_gmp(gvm_connection_t *connection, credentials_t *credentials, params_t *params, gchar *xml, cmd_response_data_t *response_data)
Wrap some XML in an envelope.
Definition: gsad_gmp.c:443

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), envelope_gmp(), gmp_success(), gsad_message(), params_value(), and set_http_status_from_entity().

Referenced by get_agent(), get_alert(), get_asset(), get_credential(), get_filter(), get_group(), get_note(), get_override(), get_permission(), get_port_list(), get_report_format(), get_result_gmp(), get_role(), get_scanner(), get_schedule(), get_tag(), get_target(), get_task_gmp(), get_ticket_gmp(), and get_user().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_override()

static char * get_override ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get a override, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 11226 of file gsad_gmp.c.

11229 {
11230  return get_one (connection, "override", credentials, params, extra_xml,
11231  "result=\"1\"", response_data);
11232 }
Structure of credential related information.
char * get_one(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get one resource, envelope the result.
Definition: gsad_gmp.c:1060

References get_one().

Referenced by get_override_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_override_gmp()

char* get_override_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get an override, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 11245 of file gsad_gmp.c.

11247 {
11248  return get_override (connection, credentials, params, NULL, response_data);
11249 }
Structure of credential related information.
static char * get_override(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get a override, envelope the result.
Definition: gsad_gmp.c:11226

References get_override().

Here is the call graph for this function:

◆ get_overrides()

static char * get_overrides ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get all overrides, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 11189 of file gsad_gmp.c.

11192 {
11193  return get_many (connection, "override", credentials, params, extra_xml, NULL,
11194  response_data);
11195 }
Structure of credential related information.
static char * get_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get all of a particular type of resource, envelope the result.
Definition: gsad_gmp.c:1152

References get_many().

Referenced by get_overrides_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_overrides_gmp()

char* get_overrides_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get all overrides, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 11208 of file gsad_gmp.c.

11210 {
11211  return get_overrides (connection, credentials, params, NULL, response_data);
11212 }
static char * get_overrides(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get all overrides, envelope the result.
Definition: gsad_gmp.c:11189
Structure of credential related information.

References get_overrides().

Here is the call graph for this function:

◆ get_permission()

char * get_permission ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get one permission, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 14375 of file gsad_gmp.c.

14378 {
14379  return get_one (connection, "permission", credentials, params, extra_xml,
14380  "alerts=\"1\"", response_data);
14381 }
Structure of credential related information.
char * get_one(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get one resource, envelope the result.
Definition: gsad_gmp.c:1060

References get_one().

Referenced by get_permission_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_permission_gmp()

char* get_permission_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get one permission, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 14394 of file gsad_gmp.c.

14396 {
14397  return get_permission (connection, credentials, params, NULL, response_data);
14398 }
Structure of credential related information.
static char * get_permission(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get one permission, envelope the result.
Definition: gsad_gmp.c:14375

References get_permission().

Here is the call graph for this function:

◆ get_permissions()

static char * get_permissions ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get all permissions, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 14412 of file gsad_gmp.c.

14415 {
14416  return get_many (connection, "permission", credentials, params, extra_xml,
14417  NULL, response_data);
14418 }
Structure of credential related information.
static char * get_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get all of a particular type of resource, envelope the result.
Definition: gsad_gmp.c:1152

References get_many().

Referenced by get_permissions_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_permissions_gmp()

char* get_permissions_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get all permissions, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 14431 of file gsad_gmp.c.

14433 {
14434  return get_permissions (connection, credentials, params, NULL, response_data);
14435 }
Structure of credential related information.
static char * get_permissions(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get all permissions, envelope the result.
Definition: gsad_gmp.c:14412

References get_permissions().

Here is the call graph for this function:

◆ get_port_from_params()

const char* get_port_from_params ( params_t *  params)

Get a port from request params.

Parameters
[in]paramsRequest parameters.
Returns
The port

Definition at line 10842 of file gsad_gmp.c.

10843 {
10844  const char *port;
10845 
10846  port = params_value (params, "port");
10847 
10848  if (port == NULL)
10849  return "";
10850 
10851  if (strcmp (port, "--") == 0)
10852  port = params_value (params, "port_manual");
10853 
10854  if (port == NULL)
10855  port = "";
10856 
10857  return port;
10858 }
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205

References params_value().

Referenced by create_note_gmp(), create_override_gmp(), save_note_gmp(), and save_override_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_port_list()

static char * get_port_list ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get one port_list, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]commandsExtra commands to run before the others.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 15537 of file gsad_gmp.c.

15540 {
15541  return get_one (connection, "port_list", credentials, params, extra_xml,
15542  "targets=\"1\" details=\"1\"", response_data);
15543 }
Structure of credential related information.
char * get_one(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get one resource, envelope the result.
Definition: gsad_gmp.c:1060

References get_one().

Referenced by get_port_list_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_port_list_gmp()

char* get_port_list_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get one port_list, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 15556 of file gsad_gmp.c.

15558 {
15559  return get_port_list (connection, credentials, params, NULL, response_data);
15560 }
Structure of credential related information.
static char * get_port_list(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get one port_list, envelope the result.
Definition: gsad_gmp.c:15537

References get_port_list().

Here is the call graph for this function:

◆ get_port_lists()

static char * get_port_lists ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get all Port Lists, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 15574 of file gsad_gmp.c.

15577 {
15578  return get_many (connection, "port_list", credentials, params, extra_xml,
15579  NULL, response_data);
15580 }
Structure of credential related information.
static char * get_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get all of a particular type of resource, envelope the result.
Definition: gsad_gmp.c:1152

References get_many().

Referenced by get_port_lists_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_port_lists_gmp()

char* get_port_lists_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get all port_lists, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 15593 of file gsad_gmp.c.

15595 {
15596  return get_port_lists (connection, credentials, params, NULL, response_data);
15597 }
Structure of credential related information.
static char * get_port_lists(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get all Port Lists, envelope the result.
Definition: gsad_gmp.c:15574

References get_port_lists().

Here is the call graph for this function:

◆ get_report()

char* get_report ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)

Get a report and return the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]commandsExtra commands to run before the others.
[in]extra_xmlExtra XML to insert inside page element.
[out]errorSet to 1 if error, else 0.
[out]response_dataExtra data return for the HTTP response.
Returns
Report.

Definition at line 9682 of file gsad_gmp.c.

9685 {
9686  GString *xml;
9687  entity_t entity;
9688  entity_t report_entity;
9689  unsigned int first, max;
9690  GString *levels, *delta_states;
9691  const char *search_phrase, *min_qod, *zone;
9692  const char *autofp, *autofp_value, *notes, *overrides, *result_hosts_only;
9693  const char *apply_overrides;
9694  const char *report_id, *sort_field, *sort_order, *result_id, *delta_report_id;
9695  const char *format_id, *first_result, *max_results, *host, *pos;
9696  const char *filt_id, *filter, *apply_filter, *report_section;
9697  const char *build_filter, *filter_extra;
9698  int ret;
9699  int ignore_filter, ignore_pagination;
9700  gchar *built_filter;
9701  gchar *fname_format;
9702  const gchar *extension, *requested_content_type;
9703 
9704  build_filter = params_value (params, "build_filter");
9705 
9706  if (params_given (params, "apply_filter")
9707  && params_valid (params, "apply_filter"))
9708  apply_filter = params_value (params, "apply_filter");
9709  else
9710  apply_filter = "no_pagination";
9711 
9712  if (params_given (params, "report_section")
9713  && params_valid (params, "report_section"))
9714  report_section = params_value (params, "report_section");
9715  else
9716  report_section = "";
9717 
9718  ignore_filter =
9719  (strcmp (apply_filter, "full") && strcmp (apply_filter, "no_pagination")
9720  && strcmp (report_section, "") && strcmp (report_section, "results")
9721  && strcmp (report_section, "summary"));
9722 
9723  if (params_given (params, "ignore_pagination"))
9724  {
9725  const char *ignore_pagination_str =
9726  params_value (params, "ignore_pagination");
9727  ignore_pagination =
9728  (ignore_pagination_str && strcmp (ignore_pagination_str, "")
9729  && strcmp (ignore_pagination_str, "0"));
9730  }
9731  else
9732  {
9733  ignore_pagination =
9734  (strcmp (apply_filter, "full") && strcmp (report_section, "")
9735  && strcmp (report_section, "results")
9736  && strcmp (report_section, "summary"));
9737  }
9738 
9739  search_phrase = params_value (params, "search_phrase");
9740  if (search_phrase == NULL)
9741  params_given (params, "search_phrase") || (search_phrase = "");
9742 
9743  zone = params_value (params, "timezone");
9744  if (zone == NULL)
9745  params_given (params, "zone") || (zone = "");
9746 
9747  min_qod = params_value (params, "min_qod");
9748 
9749  host = params_value (params, "host");
9750  pos = params_value (params, "pos");
9751 
9752  autofp = params_value (params, "autofp");
9753  if (autofp == NULL)
9754  params_given (params, "autofp") || (autofp = "0");
9755 
9756  autofp_value = params_value (params, "autofp_value");
9757  if (autofp_value == NULL)
9758  params_given (params, "autofp_value") || (autofp_value = "1");
9759 
9760  notes = params_value (params, "notes");
9761  if (notes == NULL)
9762  {
9763  if (params_given (params, "max_results"))
9764  /* Use the max_results param to determine if the request is from
9765  * the Result Filtering form, because the notes param is only sent
9766  * when the checkbox is ticked. */
9767  notes = "0";
9768  else
9769  params_given (params, "notes") || (notes = "1");
9770  }
9771 
9772  overrides = params_value (params, "overrides");
9773  if (overrides == NULL)
9774  {
9775  if (params_given (params, "max_results"))
9776  /* Use the max_results param to check for filtering form as above */
9777  overrides = "0";
9778  else
9779  params_given (params, "overrides") || (overrides = "1");
9780  }
9781 
9782  apply_overrides = params_value (params, "apply_overrides");
9783  if (apply_overrides == NULL)
9784  {
9785  if (params_given (params, "max_results"))
9786  /* Use the max_results param to check for filtering form as above */
9787  apply_overrides = "0";
9788  else
9789  params_given (params, "apply_overrides") || (apply_overrides = "1");
9790  }
9791 
9792  result_hosts_only = params_value (params, "result_hosts_only");
9793  if (result_hosts_only == NULL)
9794  {
9795  if (params_given (params, "max_results"))
9796  /* Use the max_results params to determine if the request is from
9797  * the Result Filtering form, because the result_hosts_only param is
9798  * only sent when the checkbox is ticked. */
9799  result_hosts_only = "0";
9800  else
9801  params_given (params, "result_hosts_only") || (result_hosts_only = "1");
9802  }
9803 
9804  if (autofp == NULL || strlen (autofp) == 0)
9805  autofp = "0";
9806 
9807  if (autofp_value == NULL || strlen (autofp_value) == 0)
9808  autofp_value = "1";
9809 
9810  if (strcmp (autofp, "2") == 0)
9811  autofp_value = "2";
9812 
9813  if (notes == NULL || strlen (notes) == 0)
9814  notes = "1";
9815 
9816  if (overrides == NULL || strlen (overrides) == 0)
9817  overrides = "1";
9818 
9819  if (result_hosts_only == NULL || strlen (result_hosts_only) == 0)
9820  result_hosts_only = "1";
9821 
9822  /* Get the report. */
9823 
9824  if (params_value (params, "delta_states"))
9825  delta_states = g_string_new (params_value (params, "delta_states"));
9826  else
9827  {
9828  delta_states = g_string_new ("");
9829  if (params_value (params, "delta_state_changed")
9830  && atoi (params_value (params, "delta_state_changed")))
9831  g_string_append (delta_states, "c");
9832  if (params_value (params, "delta_state_gone")
9833  && atoi (params_value (params, "delta_state_gone")))
9834  g_string_append (delta_states, "g");
9835  if (params_value (params, "delta_state_new")
9836  && atoi (params_value (params, "delta_state_new")))
9837  g_string_append (delta_states, "n");
9838  if (params_value (params, "delta_state_same")
9839  && atoi (params_value (params, "delta_state_same")))
9840  g_string_append (delta_states, "s");
9841  }
9842 
9843  if (strlen (delta_states->str) == 0)
9844  g_string_append (delta_states, "gn");
9845 
9846  if (params_value (params, "levels"))
9847  levels = g_string_new (params_value (params, "levels"));
9848  else
9849  {
9850  levels = g_string_new ("");
9851  if (params_value (params, "level_high")
9852  && atoi (params_value (params, "level_high")))
9853  g_string_append (levels, "h");
9854  if (params_value (params, "level_medium")
9855  && atoi (params_value (params, "level_medium")))
9856  g_string_append (levels, "m");
9857  if (params_value (params, "level_low")
9858  && atoi (params_value (params, "level_low")))
9859  g_string_append (levels, "l");
9860  if (params_value (params, "level_log")
9861  && atoi (params_value (params, "level_log")))
9862  g_string_append (levels, "g");
9863  if (params_value (params, "level_false_positive")
9864  && atoi (params_value (params, "level_false_positive")))
9865  g_string_append (levels, "f");
9866  }
9867 
9868  if (strlen (levels->str) == 0)
9869  g_string_append (levels, "hml");
9870 
9871  sort_field = params_value (params, "sort_field");
9872  sort_order = params_value (params, "sort_order");
9873  report_id = params_value (params, "report_id");
9874 
9875  CHECK_VARIABLE_INVALID (report_id, "Get Report");
9876 
9877  result_id = params_value (params, "result_id");
9878  delta_report_id = params_value (params, "delta_report_id");
9879  format_id = params_value (params, "report_format_id");
9880 
9881  first_result = params_value (params, "first_result");
9882  if (first_result == NULL || sscanf (first_result, "%u", &first) != 1)
9883  first_result = "1";
9884 
9885  max_results = params_value (params, "max_results");
9886  if (max_results == NULL || sscanf (max_results, "%u", &max) != 1)
9887  max_results = G_STRINGIFY (RESULTS_PER_PAGE);
9888 
9889  if (gvm_connection_sendf (
9890  connection,
9891  "<get_reports"
9892  " result_tags=\"0\""
9893  " details=\"%i\""
9894  "%s%s%s",
9895  delta_report_id || strcmp (report_section, "summary"),
9896  host ? " host=\"" : "", host ? host : "", host ? "\"" : "")
9897  == -1)
9898  {
9899  g_string_free (delta_states, TRUE);
9900  g_string_free (levels, TRUE);
9901  cmd_response_data_set_status_code (response_data,
9902  MHD_HTTP_INTERNAL_SERVER_ERROR);
9903  return gsad_message (
9904  credentials, "Internal error", __FUNCTION__, __LINE__,
9905  "An internal error occurred while getting a report. "
9906  "The report could not be delivered. "
9907  "Diagnostics: Failure to send command to manager daemon.",
9908  response_data);
9909  }
9910 
9911  filt_id = params_value (params, "filt_id");
9912  filter = params_value (params, "filter");
9913  filter_extra = params_value (params, "filter_extra");
9914 
9915  if (filter == NULL)
9916  filter = "";
9917 
9918  if ((build_filter && (strcmp (build_filter, "1") == 0))
9919  || ((filter == NULL || strcmp (filter, "") == 0)
9920  && (filter_extra == NULL || strcmp (filter_extra, "") == 0)))
9921  {
9922  GString *filter_buffer;
9923  filter_buffer = g_string_new ("");
9924 
9925  g_string_append_printf (
9926  filter_buffer,
9927  "autofp=%s"
9928  " apply_overrides=%i"
9929  " notes=%i"
9930  " overrides=%i"
9931  " result_hosts_only=%i"
9932  " first=%s"
9933  " rows=%s"
9934  " sort%s=%s"
9935  " levels=%s",
9936  strcmp (autofp, "0") ? autofp_value : "0",
9937  apply_overrides ? (strcmp (apply_overrides, "0") ? 1 : 0) : 1,
9938  strcmp (notes, "0") ? 1 : 0, strcmp (overrides, "0") ? 1 : 0,
9939  strcmp (result_hosts_only, "0") ? 1 : 0, first_result, max_results,
9940  sort_order ? strcmp (sort_order, "ascending") ? "-reverse" : ""
9941  : ((sort_field == NULL || strcmp (sort_field, "type") == 0
9942  || strcmp (sort_field, "severity") == 0)
9943  ? "-reverse"
9944  : ""),
9945  sort_field ? sort_field : "severity", levels->str);
9946 
9947  if (search_phrase && strcmp (search_phrase, ""))
9948  {
9949  gchar *search_phrase_escaped;
9950  search_phrase_escaped = g_markup_escape_text (search_phrase, -1);
9951  g_string_append_printf (filter_buffer, " \"%s\"",
9952  search_phrase_escaped);
9953  g_free (search_phrase_escaped);
9954  }
9955 
9956  if (delta_states->str && strcmp (delta_states->str, "") && delta_report_id
9957  && strcmp (delta_report_id, ""))
9958  g_string_append_printf (filter_buffer, " delta_states=%s",
9959  delta_states->str);
9960 
9961  if (min_qod && strcmp (min_qod, ""))
9962  g_string_append_printf (filter_buffer, " min_qod=%s", min_qod);
9963 
9964  if (zone && strcmp (zone, ""))
9965  g_string_append_printf (filter_buffer, " timezone=%s", zone);
9966 
9967  if (filter && strcmp (filter, ""))
9968  g_string_append_printf (filter_buffer, " %s", filter);
9969 
9970  built_filter = g_string_free (filter_buffer, FALSE);
9971  }
9972  else if (filter || filter_extra)
9973  built_filter = g_strdup_printf ("%s%s%s", filter ? filter : "",
9974  filter && filter_extra ? " " : "",
9975  filter_extra ? filter_extra : "");
9976  else
9977  built_filter = NULL;
9978 
9979  /* Don't apply default filter when applying result filter checkboxes/textboxes
9980  */
9981  if (sort_field == NULL && sort_order == NULL)
9982  if ((filt_id == NULL || strcmp (filt_id, "") == 0)
9983  && (filter == NULL || strcmp (filter, "") == 0))
9984  filt_id = FILT_ID_USER_SETTING;
9985 
9986  if (ignore_filter)
9987  ret = gvm_connection_sendf_xml (connection,
9988  " filt_id=\"0\""
9989  " filter=\"first=1 rows=-1"
9990  " result_hosts_only=0 apply_overrides=1"
9991  " notes=1 overrides=1"
9992  " sort-reverse=severity\""
9993  " report_id=\"%s\""
9994  " delta_report_id=\"%s\""
9995  " format_id=\"%s\"/>",
9996  report_id,
9997  delta_report_id ? delta_report_id : "0",
9998  format_id ? format_id : "");
9999  else
10000  ret = gvm_connection_sendf_xml (
10001  connection,
10002  " ignore_pagination=\"%d\""
10003  " filt_id=\"%s\""
10004  " filter=\"%s\""
10005  " pos=\"%s\""
10006  " notes_details=\"1\""
10007  " overrides_details=\"1\""
10008  " report_id=\"%s\""
10009  " delta_report_id=\"%s\""
10010  " format_id=\"%s\"/>",
10011  ignore_pagination, filt_id ? filt_id : "0",
10012  built_filter ? built_filter : "", pos ? pos : "1", report_id,
10013  delta_report_id ? delta_report_id : "0", format_id ? format_id : "",
10014  first_result, max_results, sort_field ? sort_field : "severity",
10015  sort_order ? sort_order
10016  : ((sort_field == NULL || strcmp (sort_field, "type") == 0
10017  || strcmp (sort_field, "severity") == 0)
10018  ? "descending"
10019  : "ascending"),
10020  levels->str, delta_states->str, search_phrase, min_qod, zone);
10021  if (ret == -1)
10022  {
10023  g_string_free (delta_states, TRUE);
10024  g_string_free (levels, TRUE);
10025  cmd_response_data_set_status_code (response_data,
10026  MHD_HTTP_INTERNAL_SERVER_ERROR);
10027  return gsad_message (
10028  credentials, "Internal error", __FUNCTION__, __LINE__,
10029  "An internal error occurred while getting a report. "
10030  "The report could not be delivered. "
10031  "Diagnostics: Failure to send command to manager daemon.",
10032  response_data);
10033  }
10034 
10035  g_string_free (delta_states, TRUE);
10036 
10037  if (format_id)
10038  {
10039  g_string_free (levels, TRUE);
10040  if ((strcmp (format_id, "a994b278-1f62-11e1-96ac-406186ea4fc5") == 0)
10041  || strcmp (format_id, "5057e5cc-b825-11e4-9d0e-28d24461215b") == 0)
10042  {
10043  /* Manager sends XML report as plain XML. */
10044 
10045  if (read_entity_c (connection, &entity))
10046  {
10048  response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
10049  return gsad_message (
10050  credentials, "Internal error", __FUNCTION__, __LINE__,
10051  "An internal error occurred while getting a report. "
10052  "The report could not be delivered. "
10053  "Diagnostics: Failure to receive response from manager daemon.",
10054  response_data);
10055  }
10056  entity_t report = entity_child (entity, "report");
10057  if (report == NULL)
10058  {
10059  free_entity (entity);
10061  response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
10062  return gsad_message (
10063  credentials, "Internal error", __FUNCTION__, __LINE__,
10064  "An internal error occurred while getting a report. "
10065  "The report could not be delivered. "
10066  "Diagnostics: Response from manager daemon did not contain a "
10067  "report.",
10068  response_data);
10069  }
10070  extension = entity_attribute (report, "extension");
10071  requested_content_type = entity_attribute (report, "content_type");
10072  if (extension && requested_content_type)
10073  {
10074  gchar *file_name;
10075  ret = setting_get_value (connection,
10076  "e1a2ae0b-736e-4484-b029-330c9e15b900",
10077  &fname_format, response_data);
10078  if (ret)
10079  {
10080  switch (ret)
10081  {
10082  case 1:
10084  response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
10085  return gsad_message (
10086  credentials, "Internal error", __FUNCTION__, __LINE__,
10087  "An internal error occurred while getting a setting. "
10088  "The setting could not be delivered. "
10089  "Diagnostics: Failure to send command to manager "
10090  "daemon.",
10091  response_data);
10092  case 2:
10094  response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
10095  return gsad_message (
10096  credentials, "Internal error", __FUNCTION__, __LINE__,
10097  "An internal error occurred while getting a setting. "
10098  "The setting could not be delivered. "
10099  "Diagnostics: Failure to receive response from manager "
10100  "daemon.",
10101  response_data);
10102  default:
10104  response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
10105  return gsad_message (
10106  credentials, "Internal error", __FUNCTION__, __LINE__,
10107  "An internal error occurred while getting a setting. "
10108  "The setting could not be delivered. "
10109  "Diagnostics: Internal error.",
10110  response_data);
10111  }
10112  }
10113 
10114  if (fname_format == NULL)
10115  {
10116  g_warning ("%s : File name format setting not found.",
10117  __FUNCTION__);
10118  fname_format = "%T-%U";
10119  }
10120 
10121  file_name = format_file_name (fname_format, credentials, "report",
10122  report_id, report);
10123  if (file_name == NULL)
10124  file_name = g_strdup_printf ("%s-%s", "report", report_id);
10125 
10127  response_data, g_strdup (requested_content_type));
10129  response_data,
10130  g_strdup_printf ("attachment; filename=\"%s.%s\"", file_name,
10131  extension));
10132 
10133  g_free (file_name);
10134  }
10135  xml = g_string_new ("");
10136  print_entity_to_string (report, xml);
10137  free_entity (entity);
10138  return g_string_free (xml, FALSE);
10139  }
10140  else
10141  {
10142  /* "nbe", "pdf", "dvi", "html", "html-pdf"... */
10143 
10144  entity = NULL;
10145  if (read_entity_c (connection, &entity))
10146  {
10148  response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
10149  return gsad_message (
10150  credentials, "Internal error", __FUNCTION__, __LINE__,
10151  "An internal error occurred while getting a report. "
10152  "The report could not be delivered. "
10153  "Diagnostics: Failure to receive response from manager daemon.",
10154  response_data);
10155  }
10156 
10157  report_entity = entity_child (entity, "report");
10158  if (report_entity != NULL)
10159  {
10160  char *report_encoded;
10161  gsize report_len;
10162  gchar *report_decoded;
10163  extension = entity_attribute (report_entity, "extension");
10164  requested_content_type =
10165  entity_attribute (report_entity, "content_type");
10166  report_encoded = entity_text (report_entity);
10167  report_decoded =
10168  (gchar *) g_base64_decode (report_encoded, &report_len);
10169  /* g_base64_decode can return NULL (Glib 2.12.4-2), at least
10170  * when *report_len is zero. */
10171  if (report_decoded == NULL)
10172  {
10173  report_decoded = g_strdup ("");
10174  report_len = 0;
10175  }
10176  if (extension && requested_content_type)
10177  {
10178  gchar *file_name;
10179  const char *id;
10180  if (report_id)
10181  id = report_id;
10182  else
10183  id = "ERROR";
10184 
10185  ret = setting_get_value (
10186  connection, "e1a2ae0b-736e-4484-b029-330c9e15b900",
10187  &fname_format, response_data);
10188  if (ret)
10189  {
10190  switch (ret)
10191  {
10192  case 1:
10194  response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
10195  return gsad_message (
10196  credentials, "Internal error", __FUNCTION__,
10197  __LINE__,
10198  "An internal error occurred while getting a "
10199  "setting. "
10200  "The setting could not be delivered. "
10201  "Diagnostics: Failure to send command to manager "
10202  "daemon.",
10203  response_data);
10204  case 2:
10206  response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
10207  return gsad_message (
10208  credentials, "Internal error", __FUNCTION__,
10209  __LINE__,
10210  "An internal error occurred while getting a "
10211  "setting. "
10212  "The setting could not be delivered. "
10213  "Diagnostics: Failure to receive response from "
10214  "manager daemon.",
10215  response_data);
10216  default:
10218  response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
10219  return gsad_message (
10220  credentials, "Internal error", __FUNCTION__,
10221  __LINE__,
10222  "An internal error occurred while getting a "
10223  "setting. "
10224  "The setting could not be delivered. "
10225  "Diagnostics: Internal error.",
10226  response_data);
10227  }
10228  }
10229 
10230  if (fname_format == NULL)
10231  {
10232  g_warning ("%s : File name format setting not found.",
10233  __FUNCTION__);
10234  fname_format = "%T-%U";
10235  }
10236 
10237  file_name = format_file_name (fname_format, credentials,
10238  "report", id, report_entity);
10239  if (file_name == NULL)
10240  file_name = g_strdup_printf ("%s-%s", "report", id);
10241 
10243  response_data, g_strdup (requested_content_type));
10245  response_data,
10246  g_strdup_printf ("attachment; filename=\"%s.%s\"",
10247  file_name, extension));
10248 
10249  g_free (file_name);
10250  }
10251 
10252  free_entity (entity);
10253 
10254  cmd_response_data_set_content_length (response_data, report_len);
10255  return report_decoded;
10256  }
10257  else
10258  {
10259  free_entity (entity);
10261  response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
10262  return gsad_message (
10263  credentials, "Internal error", __FUNCTION__, __LINE__,
10264  "An internal error occurred while getting a report. "
10265  "The report could not be delivered. "
10266  "Diagnostics: Failure to receive report from manager daemon.",
10267  response_data);
10268  }
10269  }
10270  }
10271  else
10272  {
10273  /* Format is NULL, send enveloped XML. */
10274 
10275  if (delta_report_id && result_id && strcmp (result_id, "0"))
10276  xml = g_string_new ("<get_delta_result>");
10277  else if (host)
10278  {
10279  xml = g_string_new ("<get_asset>");
10280  xml_string_append (xml,
10281  "<search_phrase>%s</search_phrase>"
10282  "<levels>%s</levels>"
10283  "<hosts start=\"%s\" max=\"%s\"/>",
10284  search_phrase, levels->str, first_result,
10285  max_results);
10286  }
10287  else
10288  xml = g_string_new ("<get_report>");
10289 
10290  if (extra_xml)
10291  g_string_append (xml, extra_xml);
10292 
10293  g_string_free (levels, TRUE);
10294 
10295  if (delta_report_id)
10296  g_string_append_printf (xml,
10297  "<delta>%s</delta>"
10298  "<result id=\"%s\"/>",
10299  delta_report_id, result_id ? result_id : "0");
10300 
10301  entity = NULL;
10302  if (read_entity_and_string_c (connection, &entity, &xml))
10303  {
10304  cmd_response_data_set_status_code (response_data,
10305  MHD_HTTP_INTERNAL_SERVER_ERROR);
10306  return gsad_message (
10307  credentials, "Internal error", __FUNCTION__, __LINE__,
10308  "An internal error occurred while getting a report. "
10309  "The report could not be delivered. "
10310  "Diagnostics: Failure to receive response from manager daemon.",
10311  response_data);
10312  }
10313 
10314  if (gmp_success (entity) != 1)
10315  {
10316  gchar *message;
10317 
10318  set_http_status_from_entity (entity, response_data);
10319 
10320  message =
10321  gsad_message (credentials, "Error", __FUNCTION__, __LINE__,
10322  entity_attribute (entity, "status_text"), response_data);
10323 
10324  g_string_free (xml, TRUE);
10325  free_entity (entity);
10326  return message;
10327  }
10328 
10329  if ((filt_id == NULL) && (params_value (params, "filter") == NULL))
10330  {
10331  entity_t term;
10332 
10333  /* Add the filter from the report as a param, because it's easier to
10334  * get from the envelope for things like the New Note icon. */
10335 
10336  term = entity_child (entity, "report");
10337  if (term && ((term = entity_child (term, "report")))
10338  && ((term = entity_child (term, "filters")))
10339  && ((term = entity_child (term, "term"))))
10340  {
10341  param_t *param;
10342  param = params_add (params, "filter", entity_text (term));
10343  param->valid = 1;
10344  param->valid_utf8 = g_utf8_validate (param->value, -1, NULL);
10345  }
10346  }
10347 
10348  report_entity = entity_child (entity, "report");
10349  if (report_entity)
10350  report_entity = entity_child (report_entity, "report");
10351  if (report_entity)
10352  {
10353  const char *id;
10354  entity_t task_entity, name;
10355 
10356  id = NULL;
10357  task_entity = entity_child (report_entity, "task");
10358  if (task_entity)
10359  {
10360  id = entity_attribute (task_entity, "id");
10361  name = entity_child (task_entity, "name");
10362  }
10363  else
10364  name = NULL;
10365 
10366  if (delta_report_id && result_id && id && name)
10367  g_string_append_printf (xml,
10368  "<task id=\"%s\"><name>%s</name></task>",
10369  id, entity_text (name));
10370 
10371  free_entity (entity);
10372  }
10373 
10374  if (delta_report_id && result_id && strcmp (result_id, "0"))
10375  {
10376  g_string_append (xml, "</get_delta_result>");
10377  return g_string_free (xml, FALSE);
10378  }
10379 
10380  g_string_append (xml, "</get_report>");
10381  return envelope_gmp (connection, credentials, params,
10382  g_string_free (xml, FALSE), response_data);
10383  }
10384 }
static int setting_get_value(gvm_connection_t *connection, const char *setting_id, gchar **value, cmd_response_data_t *response_data)
Get a setting by UUID for the current user of an GMP connection.
Definition: gsad_gmp.c:888
gchar * value
Definition: gsad_params.h:40
static int gmp_success(entity_t entity)
Check whether an GMP command failed.
Definition: gsad_gmp.c:656
Structure of credential related information.
void cmd_response_data_set_content_type_string(cmd_response_data_t *data, gchar *content_type_string)
Set a content type as string.
Definition: gsad_cmd.c:241
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
int params_given(params_t *params, const char *name)
Get whether a param was given at all.
Definition: gsad_base.c:189
int valid_utf8
Definition: gsad_params.h:45
void cmd_response_data_set_content_disposition(cmd_response_data_t *data, gchar *content_disposition)
Set content disposition of cmd_response_data_t struct.
Definition: gsad_cmd.c:212
gchar * format_file_name(gchar *fname_format, credentials_t *credentials, const char *type, const char *uuid, entity_t resource_entity)
Generates a file name for exporting.
Definition: gsad_gmp.c:1501
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
Request parameter.
Definition: gsad_params.h:38
void set_http_status_from_entity(entity_t entity, cmd_response_data_t *response_data)
Set the HTTP status according to GMP response entity.
Definition: gsad_gmp.c:677
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
#define RESULTS_PER_PAGE
Initial filtered results per page on the report summary.
Definition: gsad_gmp.c:101
void cmd_response_data_set_content_length(cmd_response_data_t *data, gsize content_length)
Set response content length of cmd_response_data_t struct.
Definition: gsad_cmd.c:186
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
int valid
Definition: gsad_params.h:44
param_t * params_add(params_t *params, const char *name, const char *value)
Add a param.
Definition: gsad_base.c:318
#define FILT_ID_USER_SETTING
filt_id value to use the filter in the user setting if possible.
Definition: gsad_gmp.c:111
int params_valid(params_t *params, const char *name)
Get whether a param is valid.
Definition: gsad_base.c:303
static char * envelope_gmp(gvm_connection_t *connection, credentials_t *credentials, params_t *params, gchar *xml, cmd_response_data_t *response_data)
Wrap some XML in an envelope.
Definition: gsad_gmp.c:443

References CHECK_VARIABLE_INVALID, cmd_response_data_set_content_disposition(), cmd_response_data_set_content_length(), cmd_response_data_set_content_type_string(), cmd_response_data_set_status_code(), envelope_gmp(), FILT_ID_USER_SETTING, format_file_name(), gmp_success(), gsad_message(), params_add(), params_given(), params_valid(), params_value(), RESULTS_PER_PAGE, set_http_status_from_entity(), setting_get_value(), param::valid, param::valid_utf8, and param::value.

Referenced by get_report_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_report_format()

static char * get_report_format ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get one report format, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 12490 of file gsad_gmp.c.

12493 {
12494  return get_one (connection, "report_format", credentials, params, extra_xml,
12495  "alerts =\"1\" params=\"1\"", response_data);
12496 }
Structure of credential related information.
char * get_one(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get one resource, envelope the result.
Definition: gsad_gmp.c:1060

References get_one().

Referenced by get_report_format_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_report_format_gmp()

char* get_report_format_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get one report format, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 12509 of file gsad_gmp.c.

12511 {
12512  return get_report_format (connection, credentials, params, NULL,
12513  response_data);
12514 }
Structure of credential related information.
static char * get_report_format(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get one report format, envelope the result.
Definition: gsad_gmp.c:12490

References get_report_format().

Here is the call graph for this function:

◆ get_report_formats()

static char * get_report_formats ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get all Report Formats, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 12528 of file gsad_gmp.c.

12531 {
12532  return get_many (connection, "report_format", credentials, params, extra_xml,
12533  NULL, response_data);
12534 }
Structure of credential related information.
static char * get_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get all of a particular type of resource, envelope the result.
Definition: gsad_gmp.c:1152

References get_many().

Referenced by get_report_formats_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_report_formats_gmp()

char* get_report_formats_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get all Report Formats, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 12547 of file gsad_gmp.c.

12550 {
12551  return get_report_formats (connection, credentials, params, NULL,
12552  response_data);
12553 }
Structure of credential related information.
static char * get_report_formats(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get all Report Formats, envelope the result.
Definition: gsad_gmp.c:12528

References get_report_formats().

Here is the call graph for this function:

◆ get_report_gmp()

char* get_report_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get a report and envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Report.

Definition at line 10397 of file gsad_gmp.c.

10399 {
10400  return get_report (connection, credentials, params, NULL, response_data);
10401 }
Structure of credential related information.
char * get_report(gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
Get a report and return the result.
Definition: gsad_gmp.c:9682

References get_report().

Here is the call graph for this function:

◆ get_reports()

static char * get_reports ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get all reports, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 10521 of file gsad_gmp.c.

10524 {
10525  const char *overrides;
10526 
10527  overrides = params_value (params, "overrides");
10528  if (overrides)
10529  /* User toggled overrides. Set the overrides value in the filter. */
10530  params_toggle_overrides (params, overrides);
10531 
10532  return get_many (connection, "report", credentials, params, extra_xml, NULL,
10533  response_data);
10534 }
Structure of credential related information.
static char * get_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get all of a particular type of resource, envelope the result.
Definition: gsad_gmp.c:1152
static void params_toggle_overrides(params_t *params, const char *overrides)
Toggle overrides.
Definition: gsad_gmp.c:3456
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205

References get_many(), params_toggle_overrides(), and params_value().

Referenced by get_reports_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_reports_gmp()

char* get_reports_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get all reports, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 10547 of file gsad_gmp.c.

10549 {
10550  return get_reports (connection, credentials, params, NULL, response_data);
10551 }
Structure of credential related information.
static char * get_reports(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get all reports, envelope the result.
Definition: gsad_gmp.c:10521

References get_reports().

Here is the call graph for this function:

◆ get_result_gmp()

char* get_result_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get one result, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 10753 of file gsad_gmp.c.

10755 {
10756  return get_one (connection, "result", credentials, params, NULL, NULL,
10757  response_data);
10758 }
Structure of credential related information.
char * get_one(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get one resource, envelope the result.
Definition: gsad_gmp.c:1060

References get_one().

Here is the call graph for this function:

◆ get_result_id_from_params()

const char* get_result_id_from_params ( params_t *  params)

Get result_id from request params.

Parameters
[in]paramsRequest parameters.
Returns
The result_id

Definition at line 10946 of file gsad_gmp.c.

10947 {
10948  const char *result_id;
10949 
10950  result_id = params_value (params, "result_id");
10951 
10952  if (result_id && (strcmp (result_id, "0") == 0))
10953  {
10954  result_id = params_value (params, "result_uuid");
10955  }
10956 
10957  return result_id;
10958 }
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205

References params_value().

Referenced by create_note_gmp(), create_override_gmp(), save_note_gmp(), and save_override_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_results()

char * get_results ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get all results, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 10710 of file gsad_gmp.c.

10713 {
10714  const char *overrides;
10715  overrides = params_value (params, "overrides");
10716 
10717  if (overrides)
10718  /* User toggled overrides. Set the overrides value in the filter. */
10719  params_toggle_overrides (params, overrides);
10720 
10721  return get_many (connection, "result", credentials, params, extra_xml, NULL,
10722  response_data);
10723 }
Structure of credential related information.
static char * get_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get all of a particular type of resource, envelope the result.
Definition: gsad_gmp.c:1152
static void params_toggle_overrides(params_t *params, const char *overrides)
Toggle overrides.
Definition: gsad_gmp.c:3456
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205

References get_many(), params_toggle_overrides(), and params_value().

Referenced by get_results_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_results_gmp()

char* get_results_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get all results, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 10736 of file gsad_gmp.c.

10738 {
10739  return get_results (connection, credentials, params, NULL, response_data);
10740 }
static char * get_results(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get all results, envelope the result.
Definition: gsad_gmp.c:10710
Structure of credential related information.

References get_results().

Here is the call graph for this function:

◆ get_role()

static char * get_role ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get one role, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 16038 of file gsad_gmp.c.

16041 {
16042  return get_one (connection, "role", credentials, params, extra_xml, NULL,
16043  response_data);
16044 }
Structure of credential related information.
char * get_one(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get one resource, envelope the result.
Definition: gsad_gmp.c:1060

References get_one().

Referenced by get_role_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_role_gmp()

char* get_role_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get one role, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 16057 of file gsad_gmp.c.

16059 {
16060  return get_role (connection, credentials, params, NULL, response_data);
16061 }
Structure of credential related information.
static char * get_role(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get one role, envelope the result.
Definition: gsad_gmp.c:16038

References get_role().

Here is the call graph for this function:

◆ get_roles()

static char * get_roles ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get all roles, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 16075 of file gsad_gmp.c.

16078 {
16079  return get_many (connection, "role", credentials, params, extra_xml, NULL,
16080  response_data);
16081 }
Structure of credential related information.
static char * get_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get all of a particular type of resource, envelope the result.
Definition: gsad_gmp.c:1152

References get_many().

Referenced by get_roles_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_roles_gmp()

char* get_roles_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get all roles, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 16094 of file gsad_gmp.c.

16096 {
16097  return get_roles (connection, credentials, params, NULL, response_data);
16098 }
Structure of credential related information.
static char * get_roles(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get all roles, envelope the result.
Definition: gsad_gmp.c:16075

References get_roles().

Here is the call graph for this function:

◆ get_scanner()

static char * get_scanner ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get one scanner, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 11554 of file gsad_gmp.c.

11557 {
11558  return get_one (connection, "scanner", credentials, params, extra_xml, NULL,
11559  response_data);
11560 }
Structure of credential related information.
char * get_one(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get one resource, envelope the result.
Definition: gsad_gmp.c:1060

References get_one().

Referenced by get_scanner_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_scanner_gmp()

char* get_scanner_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get one scanner, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 11573 of file gsad_gmp.c.

11575 {
11576  return get_scanner (connection, credentials, params, NULL, response_data);
11577 }
Structure of credential related information.
static char * get_scanner(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get one scanner, envelope the result.
Definition: gsad_gmp.c:11554

References get_scanner().

Here is the call graph for this function:

◆ get_scanners()

static char * get_scanners ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get all scanners, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 11517 of file gsad_gmp.c.

11520 {
11521  return get_many (connection, "scanner", credentials, params, extra_xml, NULL,
11522  response_data);
11523 }
Structure of credential related information.
static char * get_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get all of a particular type of resource, envelope the result.
Definition: gsad_gmp.c:1152

References get_many().

Referenced by get_scanners_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_scanners_gmp()

char* get_scanners_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get all scanners, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 11536 of file gsad_gmp.c.

11538 {
11539  return get_scanners (connection, credentials, params, NULL, response_data);
11540 }
Structure of credential related information.
static char * get_scanners(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get all scanners, envelope the result.
Definition: gsad_gmp.c:11517

References get_scanners().

Here is the call graph for this function:

◆ get_schedule()

static char * get_schedule ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get one schedule, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 11965 of file gsad_gmp.c.

11968 {
11969  return get_one (connection, "schedule", credentials, params, extra_xml,
11970  "tasks=\"1\"", response_data);
11971 }
Structure of credential related information.
char * get_one(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get one resource, envelope the result.
Definition: gsad_gmp.c:1060

References get_one().

Referenced by get_schedule_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_schedule_gmp()

char* get_schedule_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get one schedule, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 11984 of file gsad_gmp.c.

11986 {
11987  return get_schedule (connection, credentials, params, NULL, response_data);
11988 }
Structure of credential related information.
static char * get_schedule(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get one schedule, envelope the result.
Definition: gsad_gmp.c:11965

References get_schedule().

Here is the call graph for this function:

◆ get_schedules()

static char * get_schedules ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get all schedules, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 12002 of file gsad_gmp.c.

12005 {
12006  return get_many (connection, "schedule", credentials, params, extra_xml, NULL,
12007  response_data);
12008 }
Structure of credential related information.
static char * get_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get all of a particular type of resource, envelope the result.
Definition: gsad_gmp.c:1152

References get_many().

Referenced by get_schedules_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_schedules_gmp()

char* get_schedules_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get all schedules, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 12021 of file gsad_gmp.c.

12023 {
12024  return get_schedules (connection, credentials, params, NULL, response_data);
12025 }
Structure of credential related information.
static char * get_schedules(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get all schedules, envelope the result.
Definition: gsad_gmp.c:12002

References get_schedules().

Here is the call graph for this function:

◆ get_setting_gmp()

char* get_setting_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Definition at line 17959 of file gsad_gmp.c.

17961 {
17962  const gchar *setting_id = params_value (params, "setting_id");
17963  CHECK_VARIABLE_INVALID (setting_id, "Get Setting");
17964  GString *xml = g_string_new ("<get_settings>");
17965 
17966  if (gvm_connection_sendf_xml (connection,
17967  "<get_settings"
17968  " setting_id=\"%s\"/>",
17969  setting_id))
17970  {
17971  g_string_free (xml, TRUE);
17972  cmd_response_data_set_status_code (response_data,
17973  MHD_HTTP_INTERNAL_SERVER_ERROR);
17974  return gsad_message (credentials, "Internal error", __FUNCTION__,
17975  __LINE__,
17976  "An internal error occurred while getting the "
17977  "dashboard settings"
17978  "Diagnostics: Failure to send command to manager "
17979  "daemon.",
17980  response_data);
17981  }
17982 
17983  if (read_string_c (connection, &xml))
17984  {
17985  g_string_free (xml, TRUE);
17986  cmd_response_data_set_status_code (response_data,
17987  MHD_HTTP_INTERNAL_SERVER_ERROR);
17988  return gsad_message (credentials, "Internal error", __FUNCTION__,
17989  __LINE__,
17990  "An internal error occurred while getting the "
17991  "dashboard settings"
17992  "Diagnostics: Failure to receive response from "
17993  "manager daemon.",
17994  response_data);
17995  }
17996 
17997  g_string_append (xml, "</get_settings>");
17998  return envelope_gmp (connection, credentials, params,
17999  g_string_free (xml, FALSE), response_data);
18000 }
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
static char * envelope_gmp(gvm_connection_t *connection, credentials_t *credentials, params_t *params, gchar *xml, cmd_response_data_t *response_data)
Wrap some XML in an envelope.
Definition: gsad_gmp.c:443

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), envelope_gmp(), gsad_message(), and params_value().

Here is the call graph for this function:

◆ get_settings_gmp()

char* get_settings_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get all user defined settings.

Parameters
[in]connectionConnection to manager.
[in]credentialsCredentials of user issuing the action.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 17799 of file gsad_gmp.c.

17801 {
17802  GString *xml;
17803  gchar *command;
17804  const gchar *filter;
17805 
17806  xml = g_string_new ("<get_settings>");
17807 
17808  /* Get the settings. */
17809 
17810  filter = params_value (params, "filter");
17811  if (filter)
17812  {
17813  command = g_markup_printf_escaped ("<get_settings"
17814  " filter=\"%s\""
17815  " sort_field=\"name\""
17816  " sort_order=\"ascending\"/>",
17817  filter);
17818  }
17819  else
17820  {
17821  command = g_strdup ("<get_settings"
17822  " sort_field=\"name\""
17823  " sort_order=\"ascending\"/>");
17824  }
17825 
17826  if (gvm_connection_sendf (connection, command))
17827  {
17828  g_free (command);
17829 
17830  g_string_free (xml, TRUE);
17831  cmd_response_data_set_status_code (response_data,
17832  MHD_HTTP_INTERNAL_SERVER_ERROR);
17833  return gsad_message (
17834  credentials, "Internal error", __FUNCTION__, __LINE__,
17835  "An internal error occurred while getting the settings. "
17836  "The current list of settings is not available. "
17837  "Diagnostics: Failure to send command to manager daemon.",
17838  response_data);
17839  }
17840 
17841  if (read_string_c (connection, &xml))
17842  {
17843  g_free (command);
17844  g_string_free (xml, TRUE);
17845  cmd_response_data_set_status_code (response_data,
17846  MHD_HTTP_INTERNAL_SERVER_ERROR);
17847  return gsad_message (
17848  credentials, "Internal error", __FUNCTION__, __LINE__,
17849  "An internal error occurred while getting the settings. "
17850  "The current list of settings is not available. "
17851  "Diagnostics: Failure to receive response from manager daemon.",
17852  response_data);
17853  }
17854 
17855  g_free (command);
17856  g_string_append (xml, "</get_settings>");
17857  return envelope_gmp (connection, credentials, params,
17858  g_string_free (xml, FALSE), response_data);
17859 }
Structure of credential related information.
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
static char * envelope_gmp(gvm_connection_t *connection, credentials_t *credentials, params_t *params, gchar *xml, cmd_response_data_t *response_data)
Wrap some XML in an envelope.
Definition: gsad_gmp.c:443

References cmd_response_data_set_status_code(), envelope_gmp(), gsad_message(), and params_value().

Here is the call graph for this function:

◆ get_severity_from_params()

const char* get_severity_from_params ( params_t *  params)

Get severity from request params.

Parameters
[in]paramsRequest parameters.
Returns
The severity

Definition at line 10923 of file gsad_gmp.c.

10924 {
10925  const char *severity;
10926 
10927  if (params_valid (params, "severity"))
10928  severity = params_value (params, "severity");
10929  else if (params_given (params, "severity")
10930  && strcmp (params_original_value (params, "severity"), ""))
10931  severity = NULL;
10932  else
10933  severity = "";
10934 
10935  return severity;
10936 }
int params_given(params_t *params, const char *name)
Get whether a param was given at all.
Definition: gsad_base.c:189
const char * params_original_value(params_t *params, const char *name)
Get original value of param, before validation.
Definition: gsad_base.c:255
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
int params_valid(params_t *params, const char *name)
Get whether a param is valid.
Definition: gsad_base.c:303

References params_given(), params_original_value(), params_valid(), and params_value().

Referenced by create_note_gmp(), create_override_gmp(), save_note_gmp(), and save_override_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_system_report_gmp()

char* get_system_report_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
const char *  url,
params_t *  params,
cmd_response_data_t *  response_data 
)

Return system report image.

Parameters
[in]connectionConnection to manager.
[in]credentialsCredentials of user issuing the action.
[in]urlURL of report image.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Image, or NULL.

Definition at line 12328 of file gsad_gmp.c.

12331 {
12332  entity_t entity;
12333  entity_t report_entity;
12334  char name[501];
12335  gchar *gmp_command;
12336  time_t now;
12337  struct tm *now_broken;
12338  const char *slave_id, *duration;
12339  const char *start_year, *start_month, *start_day, *start_hour, *start_minute;
12340  const char *end_year, *end_month, *end_day, *end_hour, *end_minute;
12341  struct tm start_time, end_time;
12342  gchar *start_time_str, *end_time_str;
12343 
12344  if (url == NULL)
12345  return NULL;
12346 
12347  /* fan/report.png */
12348  if (sscanf (url, "%500[^ /]./report.png", name) == 1)
12349  {
12350  slave_id = params_value (params, "slave_id");
12351 
12352  duration = params_value (params, "duration");
12353 
12354  if (duration && strcmp (duration, ""))
12355  {
12356  gmp_command =
12357  g_markup_printf_escaped ("<get_system_reports"
12358  " name=\"%s\""
12359  " duration=\"%s\""
12360  " slave_id=\"%s\"/>",
12361  name, duration, slave_id ? slave_id : "0");
12362  }
12363  else
12364  {
12365  now = time (NULL);
12366  now_broken = localtime (&now);
12367 
12368  start_year = params_value (params, "start_year");
12369  start_month = params_value (params, "start_month");
12370  start_day = params_value (params, "start_day");
12371  start_hour = params_value (params, "start_hour");
12372  start_minute = params_value (params, "start_minute");
12373 
12374  end_year = params_value (params, "end_year");
12375  end_month = params_value (params, "end_month");
12376  end_day = params_value (params, "end_day");
12377  end_hour = params_value (params, "end_hour");
12378  end_minute = params_value (params, "end_minute");
12379 
12380  start_time.tm_year =
12381  start_year ? atoi (start_year) - 1900 : now_broken->tm_year;
12382  start_time.tm_mon =
12383  start_month ? atoi (start_month) - 1 : now_broken->tm_mon;
12384  start_time.tm_mday =
12385  start_day ? atoi (start_day) : now_broken->tm_mday;
12386  start_time.tm_hour =
12387  start_hour ? atoi (start_hour) : now_broken->tm_hour;
12388  start_time.tm_min =
12389  start_minute ? atoi (start_minute) : now_broken->tm_min;
12390  start_time.tm_zone = now_broken->tm_zone;
12391 
12392  end_time.tm_year =
12393  end_year ? atoi (end_year) - 1900 : now_broken->tm_year;
12394  end_time.tm_mon =
12395  end_month ? atoi (end_month) - 1 : now_broken->tm_mon;
12396  end_time.tm_mday = end_day ? atoi (end_day) : now_broken->tm_mday;
12397  end_time.tm_hour = end_hour ? atoi (end_hour) : now_broken->tm_hour;
12398  end_time.tm_min = end_minute ? atoi (end_minute) : now_broken->tm_min;
12399  end_time.tm_zone = now_broken->tm_zone;
12400 
12401  start_time_str = g_strdup_printf (
12402  "%04d-%02d-%02dT%02d:%02d:00", start_time.tm_year + 1900,
12403  start_time.tm_mon + 1, start_time.tm_mday, start_time.tm_hour,
12404  start_time.tm_min);
12405 
12406  end_time_str = g_strdup_printf ("%04d-%02d-%02dT%02d:%02d:00",
12407  end_time.tm_year + 1900,
12408  end_time.tm_mon + 1, end_time.tm_mday,
12409  end_time.tm_hour, end_time.tm_min);
12410 
12411  gmp_command = g_markup_printf_escaped (
12412  "<get_system_reports"
12413  " name=\"%s\""
12414  " start_time=\"%s\""
12415  " end_time=\"%s\""
12416  " slave_id=\"%s\"/>",
12417  name, start_time_str, end_time_str, slave_id ? slave_id : "0");
12418  g_free (start_time_str);
12419  g_free (end_time_str);
12420  }
12421 
12422  if (gvm_connection_sendf (connection, "%s", gmp_command) == -1)
12423  {
12424  g_free (gmp_command);
12425  return NULL;
12426  }
12427  g_free (gmp_command);
12428 
12429  entity = NULL;
12430  if (read_entity_c (connection, &entity))
12431  {
12432  return NULL;
12433  }
12434 
12435  report_entity = entity_child (entity, "system_report");
12436  if (report_entity == NULL)
12437  {
12438  free_entity (entity);
12439  return NULL;
12440  }
12441 
12442  report_entity = entity_child (report_entity, "report");
12443  if (report_entity == NULL)
12444  {
12445  free_entity (entity);
12446  return NULL;
12447  }
12448  else
12449  {
12450  char *content_64 = entity_text (report_entity);
12451  char *content = NULL;
12452  gsize content_length = 0;
12453 
12454  if (content_64 && strlen (content_64))
12455  {
12456  content = (char *) g_base64_decode (content_64, &content_length);
12457 
12458 #if 1
12459  cmd_response_data_set_content_type (response_data,
12461  //*content_disposition = g_strdup_printf ("attachment;
12462  // filename=\"xxx.png\"");
12463 #else
12464  g_free (content);
12465  content = g_strdup ("helo");
12466 #endif
12467  }
12468 
12469  cmd_response_data_set_content_length (response_data, content_length);
12470  free_entity (entity);
12471  return content;
12472  }
12473  }
12474 
12475  return NULL;
12476 }
void cmd_response_data_set_content_type(cmd_response_data_t *data, content_type_t content_type)
Set content type of cmd_response_data_t struct.
Definition: gsad_cmd.c:134
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_content_length(cmd_response_data_t *data, gsize content_length)
Set response content length of cmd_response_data_t struct.
Definition: gsad_cmd.c:186

References cmd_response_data_set_content_length(), cmd_response_data_set_content_type(), GSAD_CONTENT_TYPE_IMAGE_PNG, and params_value().

Referenced by handle_system_report().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_system_reports_gmp()

char* get_system_reports_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get all system reports, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 12137 of file gsad_gmp.c.

12140 {
12141  GString *xml;
12142  time_t now, duration, duration_start;
12143  struct tm start_time, end_time;
12144 
12145  const char *slave_id, *given_duration, *range_type;
12146  const char *start_year, *start_month, *start_day, *start_hour, *start_minute;
12147  const char *end_year, *end_month, *end_day, *end_hour, *end_minute;
12148 
12149  slave_id = params_value (params, "slave_id");
12150 
12151  now = time (NULL);
12152 
12153  given_duration = params_value (params, "duration");
12154  range_type = params_value (params, "range_type");
12155  if (!range_type)
12156  range_type = "duration";
12157 
12158  duration = given_duration ? atoi (given_duration) : 86400;
12159  duration_start = now - duration;
12160 
12161  xml = g_string_new ("<get_system_reports>");
12162 
12163  g_string_append_printf (xml, "<slave id=\"%s\"/>", slave_id ? slave_id : "0");
12164 
12165  if (strcmp (range_type, "duration") == 0)
12166  {
12167  struct tm *time_broken;
12168  time_broken = localtime (&now);
12169  end_time.tm_year = time_broken->tm_year;
12170  end_time.tm_mon = time_broken->tm_mon;
12171  end_time.tm_mday = time_broken->tm_mday;
12172  end_time.tm_hour = time_broken->tm_hour;
12173  end_time.tm_min = time_broken->tm_min;
12174 
12175  time_broken = localtime (&duration_start);
12176  start_time.tm_year = time_broken->tm_year;
12177  start_time.tm_mon = time_broken->tm_mon;
12178  start_time.tm_mday = time_broken->tm_mday;
12179  start_time.tm_hour = time_broken->tm_hour;
12180  start_time.tm_min = time_broken->tm_min;
12181 
12182  g_string_append_printf (xml, "<duration>%ld</duration>", duration);
12183  }
12184  else
12185  {
12186  struct tm *time_broken;
12187  time_broken = localtime (&now);
12188 
12189  start_year = params_value (params, "start_year");
12190  start_month = params_value (params, "start_month");
12191  start_day = params_value (params, "start_day");
12192  start_hour = params_value (params, "start_hour");
12193  start_minute = params_value (params, "start_minute");
12194 
12195  end_year = params_value (params, "end_year");
12196  end_month = params_value (params, "end_month");
12197  end_day = params_value (params, "end_day");
12198  end_hour = params_value (params, "end_hour");
12199  end_minute = params_value (params, "end_minute");
12200 
12201  start_time.tm_year =
12202  start_year ? atoi (start_year) - 1900 : time_broken->tm_year;
12203  start_time.tm_mon =
12204  start_month ? atoi (start_month) - 1 : time_broken->tm_mon;
12205  start_time.tm_mday = start_day ? atoi (start_day) : time_broken->tm_mday;
12206  start_time.tm_hour =
12207  start_hour ? atoi (start_hour) : time_broken->tm_hour;
12208  start_time.tm_min =
12209  start_minute ? atoi (start_minute) : time_broken->tm_min;
12210 
12211  end_time.tm_year =
12212  end_year ? atoi (end_year) - 1900 : time_broken->tm_year;
12213  end_time.tm_mon = end_month ? atoi (end_month) - 1 : time_broken->tm_mon;
12214  end_time.tm_mday = end_day ? atoi (end_day) : time_broken->tm_mday;
12215  end_time.tm_hour = end_hour ? atoi (end_hour) : time_broken->tm_hour;
12216  end_time.tm_min = end_minute ? atoi (end_minute) : time_broken->tm_min;
12217  }
12218 
12219  g_string_append_printf (xml,
12220  "<start_time>"
12221  "<minute>%i</minute>"
12222  "<hour>%i</hour>"
12223  "<day_of_month>%i</day_of_month>"
12224  "<month>%i</month>"
12225  "<year>%i</year>"
12226  "</start_time>",
12227  start_time.tm_min, start_time.tm_hour,
12228  start_time.tm_mday, start_time.tm_mon + 1,
12229  start_time.tm_year + 1900);
12230 
12231  g_string_append_printf (xml,
12232  "<end_time>"
12233  "<minute>%i</minute>"
12234  "<hour>%i</hour>"
12235  "<day_of_month>%i</day_of_month>"
12236  "<month>%i</month>"
12237  "<year>%i</year>"
12238  "</end_time>"
12239  "<range_type>%s</range_type>",
12240  end_time.tm_min, end_time.tm_hour, end_time.tm_mday,
12241  end_time.tm_mon + 1, end_time.tm_year + 1900,
12242  range_type);
12243 
12244  /* Get the system reports. */
12245 
12246  if (gvm_connection_sendf (connection,
12247  "<get_system_reports brief=\"1\" slave_id=\"%s\"/>",
12248  slave_id ? slave_id : "0")
12249  == -1)
12250  {
12251  g_string_free (xml, TRUE);
12252  cmd_response_data_set_status_code (response_data,
12253  MHD_HTTP_INTERNAL_SERVER_ERROR);
12254  return gsad_message (
12255  credentials, "Internal error", __FUNCTION__, __LINE__,
12256  "An internal error occurred while getting the system reports. "
12257  "The current list of system reports is not available. "
12258  "Diagnostics: Failure to send command to manager daemon.",
12259  response_data);
12260  }
12261 
12262  if (read_string_c (connection, &xml))
12263  {
12264  g_string_free (xml, TRUE);
12265  cmd_response_data_set_status_code (response_data,
12266  MHD_HTTP_INTERNAL_SERVER_ERROR);
12267  return gsad_message (
12268  credentials, "Internal error", __FUNCTION__, __LINE__,
12269  "An internal error occurred while getting the system reports. "
12270  "The current list of system reports is not available. "
12271  "Diagnostics: Failure to receive response from manager daemon.",
12272  response_data);
12273  }
12274 
12275  if (command_enabled (credentials, "GET_SCANNERS"))
12276  {
12277  /* Get the GMP scanners. */
12278 
12279  if (gvm_connection_sendf (connection,
12280  "<get_scanners"
12281  " filter=\"sort=name rows=-1 type=4\"/>")
12282  == -1)
12283  {
12284  g_string_free (xml, TRUE);
12285  cmd_response_data_set_status_code (response_data,
12286  MHD_HTTP_INTERNAL_SERVER_ERROR);
12287  return gsad_message (
12288  credentials, "Internal error", __FUNCTION__, __LINE__,
12289  "An internal error occurred while getting the system reports. "
12290  "The current list of system reports is not available. "
12291  "Diagnostics: Failure to send command to manager daemon.",
12292  response_data);
12293  }
12294 
12295  if (read_string_c (connection, &xml))
12296  {
12297  g_string_free (xml, TRUE);
12298  cmd_response_data_set_status_code (response_data,
12299  MHD_HTTP_INTERNAL_SERVER_ERROR);
12300  return gsad_message (
12301  credentials, "Internal error", __FUNCTION__, __LINE__,
12302  "An internal error occurred while getting the system reports. "
12303  "The current list of system reports is not available. "
12304  "Diagnostics: Failure to receive response from manager daemon.",
12305  response_data);
12306  }
12307  }
12308 
12309  /* Cleanup, and return transformed XML. */
12310 
12311  g_string_append (xml, "</get_system_reports>");
12312  return envelope_gmp (connection, credentials, params,
12313  g_string_free (xml, FALSE), response_data);
12314 }
Structure of credential related information.
int command_enabled(credentials_t *credentials, const gchar *name)
Init the GSA GMP library.
Definition: gsad_gmp.c:352
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
static char * envelope_gmp(gvm_connection_t *connection, credentials_t *credentials, params_t *params, gchar *xml, cmd_response_data_t *response_data)
Wrap some XML in an envelope.
Definition: gsad_gmp.c:443

References cmd_response_data_set_status_code(), command_enabled(), envelope_gmp(), gsad_message(), and params_value().

Here is the call graph for this function:

◆ get_tag()

static char * get_tag ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get one tag, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 7393 of file gsad_gmp.c.

7396 {
7397  return get_one (connection, "tag", credentials, params, extra_xml, NULL,
7398  response_data);
7399 }
Structure of credential related information.
char * get_one(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get one resource, envelope the result.
Definition: gsad_gmp.c:1060

References get_one().

Referenced by get_tag_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_tag_gmp()

char* get_tag_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get one tag, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 7412 of file gsad_gmp.c.

7414 {
7415  return get_tag (connection, credentials, params, NULL, response_data);
7416 }
Structure of credential related information.
static char * get_tag(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get one tag, envelope the result.
Definition: gsad_gmp.c:7393

References get_tag().

Here is the call graph for this function:

◆ get_tags()

static char * get_tags ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get all tags, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 7430 of file gsad_gmp.c.

7433 {
7434  return get_many (connection, "tag", credentials, params, extra_xml, NULL,
7435  response_data);
7436 }
Structure of credential related information.
static char * get_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get all of a particular type of resource, envelope the result.
Definition: gsad_gmp.c:1152

References get_many().

Referenced by get_tags_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_tags_gmp()

char* get_tags_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get all tags, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 7449 of file gsad_gmp.c.

7451 {
7452  return get_tags (connection, credentials, params, NULL, response_data);
7453 }
Structure of credential related information.
static char * get_tags(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get all tags, envelope the result.
Definition: gsad_gmp.c:7430

References get_tags().

Here is the call graph for this function:

◆ get_target()

static char * get_target ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get one target, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 7535 of file gsad_gmp.c.

7538 {
7539  return get_one (connection, "target", credentials, params, extra_xml,
7540  "tasks=\"1\"", response_data);
7541 }
Structure of credential related information.
char * get_one(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get one resource, envelope the result.
Definition: gsad_gmp.c:1060

References get_one().

Referenced by get_target_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_target_gmp()

char* get_target_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get one target, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 7554 of file gsad_gmp.c.

7556 {
7557  return get_target (connection, credentials, params, NULL, response_data);
7558 }
Structure of credential related information.
static char * get_target(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get one target, envelope the result.
Definition: gsad_gmp.c:7535

References get_target().

Here is the call graph for this function:

◆ get_targets()

static char * get_targets ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get all targets, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 7572 of file gsad_gmp.c.

7575 {
7576  return get_many (connection, "target", credentials, params, extra_xml, NULL,
7577  response_data);
7578 }
Structure of credential related information.
static char * get_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get all of a particular type of resource, envelope the result.
Definition: gsad_gmp.c:1152

References get_many().

Referenced by get_targets_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_targets_gmp()

char* get_targets_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get all targets, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 7591 of file gsad_gmp.c.

7593 {
7594  return get_targets (connection, credentials, params, NULL, response_data);
7595 }
Structure of credential related information.
static char * get_targets(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get all targets, envelope the result.
Definition: gsad_gmp.c:7572

References get_targets().

Here is the call graph for this function:

◆ get_task_gmp()

char* get_task_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get a task, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 3567 of file gsad_gmp.c.

3569 {
3570  return get_one (connection, "task", credentials, params, NULL, NULL,
3571  response_data);
3572 }
Structure of credential related information.
char * get_one(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get one resource, envelope the result.
Definition: gsad_gmp.c:1060

References get_one().

Here is the call graph for this function:

◆ get_task_id_from_params()

const char* get_task_id_from_params ( params_t *  params)

Get task_id from request params.

Parameters
[in]paramsRequest parameters.
Returns
The task_id

Definition at line 10903 of file gsad_gmp.c.

10904 {
10905  const char *task_id;
10906 
10907  task_id = params_value (params, "task_id");
10908 
10909  if (task_id && (strcmp (task_id, "0") == 0))
10910  task_id = params_value (params, "task_uuid");
10911 
10912  return task_id;
10913 }
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205

References params_value().

Referenced by create_note_gmp(), create_override_gmp(), save_note_gmp(), and save_override_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_tasks()

static char * get_tasks ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get all tasks, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 3510 of file gsad_gmp.c.

3513 {
3514  const char *overrides, *schedules_only, *ignore_pagination;
3515  gchar *extra_attribs, *ret;
3516 
3517  overrides = params_value (params, "overrides");
3518  schedules_only = params_value (params, "schedules_only");
3519  ignore_pagination = params_value (params, "ignore_pagination");
3520 
3521  if (overrides)
3522  /* User toggled overrides. Set the overrides value in the filter. */
3523  params_toggle_overrides (params, overrides);
3524 
3525  extra_attribs = g_strdup_printf (
3526  "%s%s%s"
3527  "%s%s%s",
3528  schedules_only ? "schedules_only=\"" : "",
3529  schedules_only ? schedules_only : "", schedules_only ? "\" " : "",
3530  ignore_pagination ? "ignore_pagination=\"" : "",
3531  ignore_pagination ? ignore_pagination : "", ignore_pagination ? "\" " : "");
3532 
3533  ret = get_many (connection, "task", credentials, params, extra_xml,
3534  extra_attribs, response_data);
3535  g_free (extra_attribs);
3536  return ret;
3537 }
Structure of credential related information.
static char * get_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get all of a particular type of resource, envelope the result.
Definition: gsad_gmp.c:1152
static void params_toggle_overrides(params_t *params, const char *overrides)
Toggle overrides.
Definition: gsad_gmp.c:3456
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205

References get_many(), params_toggle_overrides(), and params_value().

Referenced by get_tasks_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_tasks_gmp()

char* get_tasks_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get all tasks, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 3550 of file gsad_gmp.c.

3552 {
3553  return get_tasks (connection, credentials, params, NULL, response_data);
3554 }
Structure of credential related information.
static char * get_tasks(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get all tasks, envelope the result.
Definition: gsad_gmp.c:3510

References get_tasks().

Here is the call graph for this function:

◆ get_ticket_gmp()

char* get_ticket_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get single tickets, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 18965 of file gsad_gmp.c.

18967 {
18968  return get_one (connection, "ticket", credentials, params, NULL, NULL,
18969  response_data);
18970 }
Structure of credential related information.
char * get_one(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get one resource, envelope the result.
Definition: gsad_gmp.c:1060

References get_one().

Here is the call graph for this function:

◆ get_tickets_gmp()

char* get_tickets_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get all tickets, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 18947 of file gsad_gmp.c.

18949 {
18950  return get_many (connection, "ticket", credentials, params, NULL, NULL,
18951  response_data);
18952 }
Structure of credential related information.
static char * get_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get all of a particular type of resource, envelope the result.
Definition: gsad_gmp.c:1152

References get_many().

Here is the call graph for this function:

◆ get_trash()

char * get_trash ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Setup trash page XML, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 13159 of file gsad_gmp.c.

13162 {
13163  GString *xml;
13164 
13165  xml = g_string_new ("<get_trash>");
13166 
13167  if (extra_xml)
13168  g_string_append (xml, extra_xml);
13169 
13170  GET_TRASH_RESOURCE ("GET_AGENTS", "get_agents", "agents");
13171 
13172  GET_TRASH_RESOURCE ("GET_CONFIGS", "get_configs", "configs");
13173 
13174  GET_TRASH_RESOURCE ("GET_CREDENTIALS", "get_credentials", "credentials");
13175 
13176  GET_TRASH_RESOURCE ("GET_ALERTS", "get_alerts", "alerts");
13177 
13178  GET_TRASH_RESOURCE ("GET_GROUPS", "get_groups", "groups");
13179 
13180  GET_TRASH_RESOURCE ("GET_FILTERS", "get_filters", "filters");
13181 
13182  GET_TRASH_RESOURCE ("GET_NOTES", "get_notes", "notes");
13183 
13184  GET_TRASH_RESOURCE ("GET_OVERRIDES", "get_overrides", "overrides");
13185 
13186  GET_TRASH_RESOURCE ("GET_PERMISSIONS", "get_permissions", "permissions");
13187 
13188  GET_TRASH_RESOURCE ("GET_PORT_LISTS", "get_port_lists", "port lists");
13189 
13190  GET_TRASH_RESOURCE ("GET_REPORT_FORMATS", "get_report_formats",
13191  "report formats");
13192 
13193  GET_TRASH_RESOURCE ("GET_ROLES", "get_roles", "roles");
13194 
13195  GET_TRASH_RESOURCE ("GET_SCANNERS", "get_scanners", "scanners");
13196 
13197  GET_TRASH_RESOURCE ("GET_SCHEDULES", "get_schedules", "schedules");
13198 
13199  GET_TRASH_RESOURCE ("GET_TAGS", "get_tags", "tags");
13200 
13201  GET_TRASH_RESOURCE ("GET_TARGETS", "get_targets", "targets");
13202 
13203  GET_TRASH_RESOURCE ("GET_TASKS", "get_tasks", "tasks");
13204 
13205  GET_TRASH_RESOURCE ("GET_TICKETS", "get_tickets", "tickets");
13206 
13207  /* Cleanup, and return transformed XML. */
13208 
13209  g_string_append (xml, "</get_trash>");
13210  return envelope_gmp (connection, credentials, params,
13211  g_string_free (xml, FALSE), response_data);
13212 }
#define GET_TRASH_RESOURCE(capability, command, name)
Definition: gsad_gmp.c:13113
Structure of credential related information.
static char * envelope_gmp(gvm_connection_t *connection, credentials_t *credentials, params_t *params, gchar *xml, cmd_response_data_t *response_data)
Wrap some XML in an envelope.
Definition: gsad_gmp.c:443

References envelope_gmp(), and GET_TRASH_RESOURCE.

Referenced by get_trash_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_trash_gmp()

char* get_trash_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get all trash, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 13226 of file gsad_gmp.c.

13228 {
13229  return get_trash (connection, credentials, params, NULL, response_data);
13230 }
Structure of credential related information.
static char * get_trash(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Setup trash page XML, envelope the result.
Definition: gsad_gmp.c:13159

References get_trash().

Here is the call graph for this function:

◆ get_user()

char * get_user ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get one user, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 16862 of file gsad_gmp.c.

16865 {
16866  gchar *html;
16867  GString *extra;
16868 
16869  extra = g_string_new ("");
16870  if (extra_xml)
16871  g_string_append (extra, extra_xml);
16872  if (command_enabled (credentials, "DESCRIBE_AUTH"))
16873  {
16874  gchar *response;
16875  entity_t entity;
16876 
16877  response = NULL;
16878  entity = NULL;
16879  switch (gmp (connection, credentials, &response, &entity, response_data,
16880  "<describe_auth/>"))
16881  {
16882  case 0:
16883  case -1:
16884  break;
16885  case 1:
16886  cmd_response_data_set_status_code (response_data,
16887  MHD_HTTP_INTERNAL_SERVER_ERROR);
16888  return gsad_message (
16889  credentials, "Internal error", __FUNCTION__, __LINE__,
16890  "An internal error occurred getting the auth list. "
16891  "Diagnostics: Failure to send command to manager daemon.",
16892  response_data);
16893  case 2:
16894  cmd_response_data_set_status_code (response_data,
16895  MHD_HTTP_INTERNAL_SERVER_ERROR);
16896  return gsad_message (
16897  credentials, "Internal error", __FUNCTION__, __LINE__,
16898  "An internal error occurred getting the auth list. "
16899  "Diagnostics: Failure to receive response from manager daemon.",
16900  response_data);
16901  default:
16902  cmd_response_data_set_status_code (response_data,
16903  MHD_HTTP_INTERNAL_SERVER_ERROR);
16904  return gsad_message (
16905  credentials, "Internal error", __FUNCTION__, __LINE__,
16906  "An internal error occurred getting the auth list. "
16907  "Diagnostics: Internal Error.",
16908  response_data);
16909  }
16910 
16911  g_string_append (extra, response);
16912 
16913  free_entity (entity);
16914  g_free (response);
16915  }
16916  html = get_one (connection, "user", credentials, params, extra->str, NULL,
16917  response_data);
16918  g_string_free (extra, TRUE);
16919  return html;
16920 }
Structure of credential related information.
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
int command_enabled(credentials_t *credentials, const gchar *name)
Init the GSA GMP library.
Definition: gsad_gmp.c:352
char * get_one(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get one resource, envelope the result.
Definition: gsad_gmp.c:1060
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References cmd_response_data_set_status_code(), command_enabled(), get_one(), gmp(), and gsad_message().

Referenced by get_user_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_user_gmp()

char* get_user_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get one user, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 16933 of file gsad_gmp.c.

16935 {
16936  return get_user (connection, credentials, params, NULL, response_data);
16937 }
Structure of credential related information.
static char * get_user(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get one user, envelope the result.
Definition: gsad_gmp.c:16862

References get_user().

Here is the call graph for this function:

◆ get_users()

static char * get_users ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get all users, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 16951 of file gsad_gmp.c.

16954 {
16955  gchar *html;
16956  GString *extra;
16957 
16958  extra = g_string_new ("");
16959  if (command_enabled (credentials, "DESCRIBE_AUTH"))
16960  {
16961  gchar *response;
16962  entity_t entity;
16963 
16964  response = NULL;
16965  entity = NULL;
16966  switch (gmp (connection, credentials, &response, &entity, response_data,
16967  "<describe_auth/>"))
16968  {
16969  case 0:
16970  case -1:
16971  break;
16972  case 1:
16973  cmd_response_data_set_status_code (response_data,
16974  MHD_HTTP_INTERNAL_SERVER_ERROR);
16975  return gsad_message (
16976  credentials, "Internal error", __FUNCTION__, __LINE__,
16977  "An internal error occurred getting the auth list. "
16978  "Diagnostics: Failure to send command to manager daemon.",
16979  response_data);
16980  case 2:
16981  cmd_response_data_set_status_code (response_data,
16982  MHD_HTTP_INTERNAL_SERVER_ERROR);
16983  return gsad_message (
16984  credentials, "Internal error", __FUNCTION__, __LINE__,
16985  "An internal error occurred getting the auth list. "
16986  "Diagnostics: Failure to receive response from manager daemon.",
16987  response_data);
16988  default:
16989  cmd_response_data_set_status_code (response_data,
16990  MHD_HTTP_INTERNAL_SERVER_ERROR);
16991  return gsad_message (
16992  credentials, "Internal error", __FUNCTION__, __LINE__,
16993  "An internal error occurred getting the auth list. "
16994  "Diagnostics: Internal Error.",
16995  response_data);
16996  }
16997 
16998  g_string_append (extra, response);
16999 
17000  free_entity (entity);
17001  g_free (response);
17002  }
17003  if (extra_xml)
17004  g_string_append (extra, extra_xml);
17005  html = get_many (connection, "user", credentials, params, extra->str, NULL,
17006  response_data);
17007  g_string_free (extra, TRUE);
17008  return html;
17009 }
Structure of credential related information.
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
int command_enabled(credentials_t *credentials, const gchar *name)
Init the GSA GMP library.
Definition: gsad_gmp.c:352
static char * get_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get all of a particular type of resource, envelope the result.
Definition: gsad_gmp.c:1152
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References cmd_response_data_set_status_code(), command_enabled(), get_many(), gmp(), and gsad_message().

Referenced by get_users_gmp(), and save_auth_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_users_gmp()

char* get_users_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get all users, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 17022 of file gsad_gmp.c.

17024 {
17025  return get_users (connection, credentials, params, NULL, response_data);
17026 }
static char * get_users(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get all users, envelope the result.
Definition: gsad_gmp.c:16951
Structure of credential related information.

References get_users().

Here is the call graph for this function:

◆ get_vulns()

static char * get_vulns ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Get multiple vulns, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 17229 of file gsad_gmp.c.

17232 {
17233  return get_many (connection, "vuln", credentials, params, extra_xml, NULL,
17234  response_data);
17235 }
Structure of credential related information.
static char * get_many(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, const char *extra_xml, const char *extra_attribs, cmd_response_data_t *response_data)
Get all of a particular type of resource, envelope the result.
Definition: gsad_gmp.c:1152

References get_many().

Referenced by get_vulns_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_vulns_gmp()

char* get_vulns_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get multiple vulns, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 17211 of file gsad_gmp.c.

17213 {
17214  return get_vulns (connection, credentials, params, NULL, response_data);
17215 }
Structure of credential related information.
static char * get_vulns(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get multiple vulns, envelope the result.
Definition: gsad_gmp.c:17229

References get_vulns().

Here is the call graph for this function:

◆ gmp()

static int gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
gchar **  response,
entity_t *  entity_return,
cmd_response_data_t *  response_data,
const char *  command 
)
static

Run a single GMP command.

Parameters
[in]connectionConnection to manager
[in]credentialsUsername and password for authentication.
[out]responseResponse.
[out]entity_returnResponse entity.
[out]response_dataExtra data return for the HTTP response.
[in]commandCommand.
Returns
0 success, -1 failed to connect (response set), 1 send error, 2 read error.

Definition at line 706 of file gsad_gmp.c.

709 {
710  int ret;
711  entity_t entity;
712 
713  if (entity_return)
714  *entity_return = NULL;
715 
716  ret = gvm_connection_sendf (connection, "%s", command);
717  if (ret == -1)
718  {
719  return 1;
720  }
721 
722  entity = NULL;
723  if (read_entity_and_text_c (connection, &entity, response))
724  {
725  return 2;
726  }
727  if (entity_return)
728  *entity_return = entity;
729  else
730  free_entity (entity);
731  return 0;
732 }

Referenced by auth_settings_gmp(), create_agent_gmp(), create_alert_gmp(), create_container_task_gmp(), create_group_gmp(), create_host_gmp(), create_report_gmp(), create_tag_gmp(), create_target_gmp(), create_task_gmp(), create_user_gmp(), get_aggregate_gmp(), get_alert(), get_alerts(), get_user(), get_users(), gmpf(), import_config_gmp(), import_port_list_gmp(), import_report_format_gmp(), move_task_gmp(), new_alert(), run_wizard_gmp(), save_alert_gmp(), save_credential_gmp(), save_setting_gmp(), save_tag_gmp(), save_target_gmp(), save_user_gmp(), simple_gmpf(), and wizard_get().

Here is the caller graph for this function:

◆ gmp_init()

void gmp_init ( const gchar *  manager_address_unix,
const gchar *  manager_address_tls,
int  port_manager 
)

Init the GSA GMP library.

Parameters
[in]manager_address_unixManager address when using UNIX socket.
[in]manager_address_tlsManager address when using TLS-TCP.
[in]port_managerManager port.

Definition at line 368 of file gsad_gmp.c.

370 {
371  if (manager_address_unix)
372  {
373  manager_address = g_strdup (manager_address_unix);
374  manager_use_tls = 0;
375  }
376  else if (manager_address_tls)
377  {
378  manager_address = g_strdup (manager_address_tls);
379  manager_use_tls = 1;
380  }
381  else
382  {
383  manager_address = g_build_filename (GVM_RUN_DIR, "gvmd.sock", NULL);
384  manager_use_tls = 0;
385  }
386  manager_port = port_manager;
387 }
int manager_port
The port the manager is on.
Definition: gsad_gmp.c:140
gchar * manager_address
The address the manager is on.
Definition: gsad_gmp.c:135
int manager_use_tls
Whether to use TLS for Manager connections.
Definition: gsad_gmp.c:130

References manager_address, manager_port, and manager_use_tls.

◆ gmp_success()

static int gmp_success ( entity_t  entity)
static

Check whether an GMP command failed.

Parameters
[in]entityResponse entity.
Returns
1 success, 0 fail, -1 error.

Definition at line 656 of file gsad_gmp.c.

657 {
658  const char *status;
659 
660  if (entity == NULL)
661  return 0;
662 
663  status = entity_attribute (entity, "status");
664  if ((status == NULL) || (strlen (status) == 0))
665  return -1;
666 
667  return status[0] == '2';
668 }

Referenced by check_modify_config(), create_filter_gmp(), create_task_gmp(), delete_resource(), export_many(), export_resource(), filter_exists(), get_aggregate_gmp(), get_one(), get_report(), resource_action(), response_from_entity(), save_my_settings_gmp(), save_user_gmp(), send_settings_filters(), and simple_gmpf().

Here is the caller graph for this function:

◆ gmpf()

static int gmpf ( gvm_connection_t *  connection,
credentials_t *  credentials,
gchar **  response,
entity_t *  entity_return,
cmd_response_data_t *  response_data,
const char *  format,
  ... 
)
static

Run a single formatted GMP command.

Parameters
[in]connectionConnection to manager
[in]credentialsUsername and password for authentication.
[out]responseResponse.
[out]entity_returnResponse entity.
[out]response_dataExtra data return for the HTTP response.
[in]formatCommand.
[in]...Arguments for format string.
Returns
0 success, -1 failed to connect (response set), 1 send error, 2 read error.

Definition at line 859 of file gsad_gmp.c.

862 {
863  int ret;
864  gchar *command;
865  va_list args;
866 
867  va_start (args, format);
868  command = g_markup_vprintf_escaped (format, args);
869  va_end (args);
870 
871  ret = gmp (connection, credentials, response, entity_return, response_data,
872  command);
873  g_free (command);
874  return ret;
875 }
Structure of credential related information.
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706

References gmp().

Referenced by create_asset_gmp(), create_config_gmp(), create_credential_gmp(), create_filter_gmp(), create_note_gmp(), create_override_gmp(), create_permission_gmp(), create_permissions_gmp(), create_port_list_gmp(), create_port_range_gmp(), create_role_gmp(), create_scanner_gmp(), create_schedule_gmp(), create_ticket_gmp(), edit_role(), resource_action(), save_agent_gmp(), save_asset_gmp(), save_auth_gmp(), save_container_task_gmp(), save_group_gmp(), save_note_gmp(), save_override_gmp(), save_permission_gmp(), save_port_list_gmp(), save_report_format_gmp(), save_role_gmp(), save_scanner_gmp(), save_schedule_gmp(), save_task_gmp(), save_ticket_gmp(), verify_agent_gmp(), verify_report_format_gmp(), and verify_scanner_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gvm_connection_open()

int gvm_connection_open ( gvm_connection_t *  connection,
const gchar *  address,
int  port 
)

Connect to an address.

Parameters
[out]connectionConnection.
[out]addressAddress.
[out]portPort.
Returns
0 success, -1 failed to connect.

Definition at line 19235 of file gsad_gmp.c.

19237 {
19238  if (address == NULL)
19239  return -1;
19240 
19241  connection->tls = manager_use_tls;
19242 
19243  if (manager_use_tls)
19244  {
19245  connection->socket =
19246  gvm_server_open (&connection->session, address, port);
19247  connection->credentials = NULL;
19248  }
19249  else
19250  connection->socket = connect_unix (address);
19251 
19252  if (connection->socket == -1)
19253  return -1;
19254 
19255  return 0;
19256 }
int connect_unix(const gchar *path)
Connect to Greenbone Vulnerability Manager daemon.
Definition: gsad_gmp.c:19196
int manager_use_tls
Whether to use TLS for Manager connections.
Definition: gsad_gmp.c:130

References connect_unix(), and manager_use_tls.

Referenced by authenticate_gmp(), and manager_connect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ import_config_gmp()

char* import_config_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Import config, get all configs, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 7967 of file gsad_gmp.c.

7969 {
7970  gchar *command, *html, *response;
7971  entity_t entity;
7972  int ret;
7973 
7974  /* Create the config. */
7975 
7976  response = NULL;
7977  entity = NULL;
7978  command = g_strdup_printf ("<create_config>"
7979  "%s"
7980  "</create_config>",
7981  params_value (params, "xml_file"));
7982  ret =
7983  gmp (connection, credentials, &response, &entity, response_data, command);
7984  g_free (command);
7985  switch (ret)
7986  {
7987  case 0:
7988  case -1:
7989  break;
7990  case 1:
7991  cmd_response_data_set_status_code (response_data,
7992  MHD_HTTP_INTERNAL_SERVER_ERROR);
7993  return gsad_message (
7994  credentials, "Internal error", __FUNCTION__, __LINE__,
7995  "An internal error occurred while importing a config. "
7996  "The schedule remains the same. "
7997  "Diagnostics: Failure to send command to manager daemon.",
7998  response_data);
7999  case 2:
8000  cmd_response_data_set_status_code (response_data,
8001  MHD_HTTP_INTERNAL_SERVER_ERROR);
8002  return gsad_message (
8003  credentials, "Internal error", __FUNCTION__, __LINE__,
8004  "An internal error occurred while importing a config. "
8005  "It is unclear whether the schedule has been saved or not. "
8006  "Diagnostics: Failure to receive response from manager daemon.",
8007  response_data);
8008  default:
8009  cmd_response_data_set_status_code (response_data,
8010  MHD_HTTP_INTERNAL_SERVER_ERROR);
8011  return gsad_message (
8012  credentials, "Internal error", __FUNCTION__, __LINE__,
8013  "An internal error occurred while importing a config. "
8014  "It is unclear whether the schedule has been saved or not. "
8015  "Diagnostics: Internal Error.",
8016  response_data);
8017  }
8018 
8019  /* Cleanup, and return transformed XML. */
8020 
8021  html = response_from_entity (connection, credentials, params, entity,
8022  "Import Config", response_data);
8023  free_entity (entity);
8024  g_free (response);
8025  return html;
8026 }
Structure of credential related information.
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References cmd_response_data_set_status_code(), gmp(), gsad_message(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ import_port_list_gmp()

char* import_port_list_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Import port list, get all port_lists, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 15725 of file gsad_gmp.c.

15727 {
15728  gchar *command, *html, *response;
15729  entity_t entity;
15730  int ret;
15731 
15732  /* Create the port list. */
15733 
15734  response = NULL;
15735  entity = NULL;
15736  command = g_strdup_printf ("<create_port_list>"
15737  "%s"
15738  "</create_port_list>",
15739  params_value (params, "xml_file"));
15740  ret =
15741  gmp (connection, credentials, &response, &entity, response_data, command);
15742  g_free (command);
15743  switch (ret)
15744  {
15745  case 0:
15746  case -1:
15747  break;
15748  case 1:
15749  cmd_response_data_set_status_code (response_data,
15750  MHD_HTTP_INTERNAL_SERVER_ERROR);
15751  return gsad_message (
15752  credentials, "Internal error", __FUNCTION__, __LINE__,
15753  "An internal error occurred while importing a port_list. "
15754  "The schedule remains the same. "
15755  "Diagnostics: Failure to send command to manager daemon.",
15756  response_data);
15757  case 2:
15758  cmd_response_data_set_status_code (response_data,
15759  MHD_HTTP_INTERNAL_SERVER_ERROR);
15760  return gsad_message (
15761  credentials, "Internal error", __FUNCTION__, __LINE__,
15762  "An internal error occurred while importing a port_list. "
15763  "It is unclear whether the schedule has been saved or not. "
15764  "Diagnostics: Failure to receive response from manager daemon.",
15765  response_data);
15766  default:
15767  cmd_response_data_set_status_code (response_data,
15768  MHD_HTTP_INTERNAL_SERVER_ERROR);
15769  return gsad_message (
15770  credentials, "Internal error", __FUNCTION__, __LINE__,
15771  "An internal error occurred while importing a port_list. "
15772  "It is unclear whether the schedule has been saved or not. "
15773  "Diagnostics: Internal Error.",
15774  response_data);
15775  }
15776 
15777  /* Cleanup, and return transformed XML. */
15778 
15779  html = response_from_entity (connection, credentials, params, entity,
15780  "Import Port List", response_data);
15781  free_entity (entity);
15782  g_free (response);
15783  return html;
15784 }
Structure of credential related information.
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References cmd_response_data_set_status_code(), gmp(), gsad_message(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ import_report_format_gmp()

char* import_report_format_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Import report format, get all report formats, envelope result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 12585 of file gsad_gmp.c.

12588 {
12589  gchar *command, *html, *response;
12590  entity_t entity;
12591  int ret;
12592 
12593  /* Create the report format. */
12594 
12595  response = NULL;
12596  entity = NULL;
12597  command = g_strdup_printf ("<create_report_format>"
12598  "%s"
12599  "</create_report_format>",
12600  params_value (params, "xml_file"));
12601  ret =
12602  gmp (connection, credentials, &response, &entity, response_data, command);
12603  g_free (command);
12604  switch (ret)
12605  {
12606  case 0:
12607  case -1:
12608  break;
12609  case 1:
12610  cmd_response_data_set_status_code (response_data,
12611  MHD_HTTP_INTERNAL_SERVER_ERROR);
12612  return gsad_message (
12613  credentials, "Internal error", __FUNCTION__, __LINE__,
12614  "An internal error occurred while importing a report format. "
12615  "The schedule remains the same. "
12616  "Diagnostics: Failure to send command to manager daemon.",
12617  response_data);
12618  case 2:
12619  cmd_response_data_set_status_code (response_data,
12620  MHD_HTTP_INTERNAL_SERVER_ERROR);
12621  return gsad_message (
12622  credentials, "Internal error", __FUNCTION__, __LINE__,
12623  "An internal error occurred while importing a report format. "
12624  "It is unclear whether the schedule has been saved or not. "
12625  "Diagnostics: Failure to receive response from manager daemon.",
12626  response_data);
12627  default:
12628  cmd_response_data_set_status_code (response_data,
12629  MHD_HTTP_INTERNAL_SERVER_ERROR);
12630  return gsad_message (
12631  credentials, "Internal error", __FUNCTION__, __LINE__,
12632  "An internal error occurred while importing a report format. "
12633  "It is unclear whether the schedule has been saved or not. "
12634  "Diagnostics: Internal Error.",
12635  response_data);
12636  }
12637 
12638  /* Cleanup, and return transformed XML. */
12639 
12640  if (entity_attribute (entity, "id"))
12641  params_add (params, "report_format_id", entity_attribute (entity, "id"));
12642  html = response_from_entity (connection, credentials, params, entity,
12643  "Create Report Format", response_data);
12644 
12645  free_entity (entity);
12646  g_free (response);
12647  return html;
12648 }
Structure of credential related information.
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
param_t * params_add(params_t *params, const char *name, const char *value)
Add a param.
Definition: gsad_base.c:318

References cmd_response_data_set_status_code(), gmp(), gsad_message(), params_add(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ import_report_gmp()

char* import_report_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Import report, get all reports, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 2384 of file gsad_gmp.c.

2386 {
2387  return create_report_gmp (connection, credentials, params, response_data);
2388 }
Structure of credential related information.
char * create_report_gmp(gvm_connection_t *connection, credentials_t *credentials, params_t *params, cmd_response_data_t *response_data)
Returns page to create a new container task.
Definition: gsad_gmp.c:2245

References create_report_gmp().

Here is the call graph for this function:

◆ login()

int login ( http_connection_t *  con,
params_t *  params,
cmd_response_data_t *  response_data,
const char *  client_address 
)

Login and create a session.

Parameters
[in]conHTTP Connection
[in]paramsRequest parameters
[out]response_dataExtra data return for the HTTP response
[in]client_addressClient address
Returns
MHD_YES on success. MHD_NO on errors.

Definition at line 19384 of file gsad_gmp.c.

19386 {
19387  int ret;
19388  authentication_reason_t auth_reason;
19390  gchar *timezone;
19391  gchar *role;
19392  gchar *capabilities;
19393  gchar *severity;
19394  gchar *language;
19395  gchar *pw_warning;
19396 
19397  const char *password = params_value (params, "password");
19398  const char *login = params_value (params, "login");
19399 
19400  if ((password == NULL)
19401  && (params_original_value (params, "password") == NULL))
19402  password = "";
19403 
19404  if (login && password)
19405  {
19406  ret = authenticate_gmp (login, password, &role, &timezone, &severity,
19407  &capabilities, &language, &pw_warning);
19408  if (ret)
19409  {
19410  int status;
19411  if (ret == -1)
19412  status = MHD_HTTP_INTERNAL_SERVER_ERROR;
19413  if (ret == 2)
19414  status = MHD_HTTP_SERVICE_UNAVAILABLE;
19415  else
19416  status = MHD_HTTP_UNAUTHORIZED;
19417 
19418  auth_reason = ret == 2 ? GMP_SERVICE_DOWN
19419  : (ret == -1 ? LOGIN_ERROR : LOGIN_FAILED);
19420 
19421  g_warning ("Authentication failure for '%s' from %s", login ?: "",
19422  client_address);
19423  return handler_send_reauthentication (con, status, auth_reason);
19424  }
19425  else
19426  {
19427  user_t *user;
19428  user = user_add (login, password, timezone, severity, role,
19429  capabilities, language, pw_warning, client_address);
19430 
19431  g_message ("Authentication success for '%s' from %s", login ?: "",
19432  client_address);
19433 
19434  credentials = credentials_new (user, language);
19435 
19436  gchar *data =
19437  envelope_gmp (NULL, credentials, params, NULL, response_data);
19438 
19439  ret = handler_create_response (con, data, response_data,
19440  user_get_cookie (user));
19441 
19442  user_free (user);
19443 
19445 
19446  g_free (timezone);
19447  g_free (severity);
19448  g_free (capabilities);
19449  g_free (language);
19450  g_free (role);
19451  g_free (pw_warning);
19452 
19453  return ret;
19454  }
19455  }
19456  else
19457  {
19458  g_warning ("Authentication failure for '%s' from %s", login ?: "",
19459  client_address);
19460  return handler_send_reauthentication (con, MHD_HTTP_UNAUTHORIZED,
19461  LOGIN_FAILED);
19462  }
19463 }
int handler_send_reauthentication(http_connection_t *connection, int http_status_code, authentication_reason_t reason)
Allow for reauthentication of a user.
Definition: gsad_http.c:459
Structure of credential related information.
user_t * user_add(const gchar *username, const gchar *password, const gchar *timezone, const gchar *severity, const gchar *role, const gchar *capabilities, const gchar *language, const gchar *pw_warning, const char *address)
Add a user.
Definition: gsad_user.c:359
int authenticate_gmp(const gchar *username, const gchar *password, gchar **role, gchar **timezone, gchar **severity, gchar **capabilities, gchar **language, gchar **pw_warning)
Check authentication credentials.
Definition: gsad_gmp.c:19273
void user_free(user_t *user)
Definition: gsad_user.c:102
int login(http_connection_t *con, params_t *params, cmd_response_data_t *response_data, const char *client_address)
Login and create a session.
Definition: gsad_gmp.c:19384
const char * params_original_value(params_t *params, const char *name)
Get original value of param, before validation.
Definition: gsad_base.c:255
enum authentication_reason authentication_reason_t
Definition: gsad_http.h:171
credentials_t * credentials_new(user_t *user, const gchar *language)
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
int handler_create_response(http_connection_t *connection, gchar *data, cmd_response_data_t *response_data, const gchar *sid)
Create and send a response.
Definition: gsad_http.c:368
User information structure, for sessions.
Definition: gsad_user.c:42
void credentials_free(credentials_t *creds)
const gchar * user_get_cookie(user_t *user)
Definition: gsad_user.c:169
static char * envelope_gmp(gvm_connection_t *connection, credentials_t *credentials, params_t *params, gchar *xml, cmd_response_data_t *response_data)
Wrap some XML in an envelope.
Definition: gsad_gmp.c:443

References authenticate_gmp(), credentials_free(), credentials_new(), envelope_gmp(), GMP_SERVICE_DOWN, handler_create_response(), handler_send_reauthentication(), login(), LOGIN_ERROR, LOGIN_FAILED, params_original_value(), params_value(), user_add(), user_free(), and user_get_cookie().

Referenced by create_credential_gmp(), download_credential_gmp(), login(), save_credential_gmp(), and save_user_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ manager_connect()

int manager_connect ( credentials_t *  credentials,
gvm_connection_t *  connection,
cmd_response_data_t *  response_data 
)

Connect to Greenbone Vulnerability Manager daemon.

Parameters
[in]credentialsUsername and password for authentication.
[out]connectionConnection to Manager on success.
[out]response_dataExtra data return for the HTTP response.
Returns
0 success, -1 failed to connect, -2 authentication failed.

Definition at line 19475 of file gsad_gmp.c.

19477 {
19478  gmp_authenticate_info_opts_t auth_opts;
19479 
19481  {
19482  cmd_response_data_set_status_code (response_data,
19483  MHD_HTTP_SERVICE_UNAVAILABLE);
19484  return -1;
19485  }
19486 
19488  auth_opts = gmp_authenticate_info_opts_defaults;
19489  auth_opts.username = user_get_username (user);
19490  auth_opts.password = user_get_password (user);
19491  if (gmp_authenticate_info_ext_c (connection, auth_opts))
19492  {
19493  g_debug ("authenticate failed!\n");
19494  gvm_connection_close (connection);
19495  return -2;
19496  }
19497 
19498 #ifdef DEBUG
19499  /* Enable this if you need the CGI to sleep after launch. This can be useful
19500  * if you need to attach to manager process the CGI is talking to for
19501  * debugging purposes.
19502  *
19503  * An easier method is to run gsad under gdb and set a breakpoint here.
19504  */
19505  g_debug ("Sleeping!");
19506  sleep (10);
19507 #endif
19508  return 0;
19509 }
int manager_port
The port the manager is on.
Definition: gsad_gmp.c:140
Structure of credential related information.
const gchar * user_get_username(user_t *user)
Definition: gsad_user.c:157
const gchar * user_get_password(user_t *user)
Definition: gsad_user.c:217
int gvm_connection_open(gvm_connection_t *connection, const gchar *address, int port)
Connect to an address.
Definition: gsad_gmp.c:19235
User information structure, for sessions.
Definition: gsad_user.c:42
gchar * manager_address
The address the manager is on.
Definition: gsad_gmp.c:135
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
user_t * credentials_get_user(credentials_t *cred)

References cmd_response_data_set_status_code(), credentials_get_user(), gvm_connection_open(), manager_address, manager_port, user_get_password(), and user_get_username().

Referenced by handle_system_report().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ member()

static int member ( params_t *  params,
const char *  string 
)
static

Look for a param with name equal to a given string.

Parameters
[in]paramsParams.
[in]stringString.
Returns
1 if param with name
  • string exists in
  • params, else 0.

Definition at line 520 of file gsad_gmp.c.

521 {
522  params_iterator_t iter;
523  param_t *param;
524  char *name;
525 
526  params_iterator_init (&iter, params);
527  while (params_iterator_next (&iter, &name, &param))
528  if (strcmp (name, string) == 0)
529  return 1;
530  return 0;
531 }
#define params_iterator_t
Definition: gsad_params.h:94
Request parameter.
Definition: gsad_params.h:38
gboolean params_iterator_next(params_iterator_t *iterator, char **name, param_t **param)
Increment a params iterator.
Definition: gsad_base.c:394
#define params_iterator_init
Definition: gsad_params.h:96

References params_iterator_init, params_iterator_next(), and params_iterator_t.

Referenced by save_config_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ member1()

int member1 ( params_t *  params,
const char *  string 
)

Look for param with value 1 and name equal to given string.

Parameters
[in]paramsParams.
[in]stringString.
Returns
1 if param with name
  • string exists in
  • params, else 0.

Definition at line 542 of file gsad_gmp.c.

543 {
544  params_iterator_t iter;
545  param_t *param;
546  char *name;
547 
548  params_iterator_init (&iter, params);
549  while (params_iterator_next (&iter, &name, &param))
550  if (param->value_size && param->value[0] == '1'
551  && strcmp (name, string) == 0)
552  return 1;
553  return 0;
554 }
gchar * value
Definition: gsad_params.h:40
#define params_iterator_t
Definition: gsad_params.h:94
int value_size
Definition: gsad_params.h:46
Request parameter.
Definition: gsad_params.h:38
gboolean params_iterator_next(params_iterator_t *iterator, char **name, param_t **param)
Increment a params iterator.
Definition: gsad_base.c:394
#define params_iterator_init
Definition: gsad_params.h:96

References params_iterator_init, params_iterator_next(), params_iterator_t, param::value, and param::value_size.

Referenced by save_config_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ message_invalid()

gchar* message_invalid ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data,
const char *  message,
const char *  op_name 
)

Check a param using the direct response method.

Parameters
[in]connectionConnection to manager
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]response_dataResponse data.
[in]messageMessage.
[in]op_nameOperation name.
Returns
Enveloped XML object.

Definition at line 1004 of file gsad_gmp.c.

1007 {
1008  gchar *ret = action_result (connection, credentials, params, response_data,
1009  op_name, message, NULL, NULL);
1010 
1011  cmd_response_data_set_status_code (response_data,
1013 
1014  return ret;
1015 }
Structure of credential related information.
static gchar * action_result(gvm_connection_t *, credentials_t *, params_t *, cmd_response_data_t *, const char *action, const char *message, const char *details, const char *id)
Generate a enveloped GMP XML containing an action result.
Definition: gsad_gmp.c:965
#define GSAD_STATUS_INVALID_REQUEST
HTTP status code for expected failure of gmp requests e.g. if some parameter was missing or invalid.
Definition: gsad_gmp.c:96
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References action_result(), cmd_response_data_set_status_code(), and GSAD_STATUS_INVALID_REQUEST.

Referenced by create_report_gmp(), create_task_gmp(), and delete_resource().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ move_resource_to_trash()

char* move_resource_to_trash ( gvm_connection_t *  connection,
const char *  type,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Move a resource to the trashcan.

Parameters
[in]connectionConnection to manager.
[in]typeType of resource.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 2022 of file gsad_gmp.c.

2025 {
2026  return delete_resource (connection, type, credentials, params, FALSE,
2027  response_data);
2028 }
Structure of credential related information.
char * delete_resource(gvm_connection_t *connection, const char *type, credentials_t *credentials, params_t *params, gboolean ultimate, cmd_response_data_t *response_data)
Delete a resource, get all resources, envelope the result.
Definition: gsad_gmp.c:1915

References delete_resource().

Referenced by delete_agent_gmp(), delete_alert_gmp(), delete_config_gmp(), delete_credential_gmp(), delete_filter_gmp(), delete_group_gmp(), delete_note_gmp(), delete_override_gmp(), delete_permission_gmp(), delete_port_list_gmp(), delete_report_format_gmp(), delete_role_gmp(), delete_scanner_gmp(), delete_schedule_gmp(), delete_tag_gmp(), delete_target_gmp(), delete_task_gmp(), delete_ticket_gmp(), and delete_user_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ move_task_gmp()

char* move_task_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Reassign a task to a new GMP slave.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 3250 of file gsad_gmp.c.

3252 {
3253  gchar *command, *response, *html;
3254  const char *task_id, *slave_id;
3255  int ret;
3256  entity_t entity;
3257 
3258  slave_id = params_value (params, "slave_id");
3259  task_id = params_value (params, "task_id");
3260 
3261  command = g_strdup_printf ("<move_task task_id=\"%s\" slave_id=\"%s\"/>",
3262  task_id ? task_id : "", slave_id ? slave_id : "");
3263 
3264  response = NULL;
3265  entity = NULL;
3266  ret =
3267  gmp (connection, credentials, &response, &entity, response_data, command);
3268  g_free (command);
3269  switch (ret)
3270  {
3271  case 0:
3272  break;
3273  case -1:
3274  /* 'gmp' set response. */
3275  return response;
3276  case 1:
3277  cmd_response_data_set_status_code (response_data,
3278  MHD_HTTP_INTERNAL_SERVER_ERROR);
3279  return gsad_message (
3280  credentials, "Internal error", __FUNCTION__, __LINE__,
3281  "An internal error occurred while moving a task. "
3282  "The task was not moved. "
3283  "Diagnostics: Failure to send command to manager daemon.",
3284  response_data);
3285  case 2:
3286  cmd_response_data_set_status_code (response_data,
3287  MHD_HTTP_INTERNAL_SERVER_ERROR);
3288  return gsad_message (
3289  credentials, "Internal error", __FUNCTION__, __LINE__,
3290  "An internal error occurred while moving a task. "
3291  "It is unclear whether the task has been moved or not. "
3292  "Diagnostics: Failure to receive response from manager daemon.",
3293  response_data);
3294  default:
3295  cmd_response_data_set_status_code (response_data,
3296  MHD_HTTP_INTERNAL_SERVER_ERROR);
3297  return gsad_message (
3298  credentials, "Internal error", __FUNCTION__, __LINE__,
3299  "An internal error occurred while moving a task. "
3300  "It is unclear whether the task has been moved or not. "
3301  "Diagnostics: Internal Error.",
3302  response_data);
3303  }
3304 
3305  html = response_from_entity (connection, credentials, params, entity,
3306  "Move Task", response_data);
3307 
3308  free_entity (entity);
3309  g_free (response);
3310  return html;
3311 }
Structure of credential related information.
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References cmd_response_data_set_status_code(), gmp(), gsad_message(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ new_alert()

static char* new_alert ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Returns page to create a new alert.

Parameters
[in]connectionConnection to manager.
[in]credentialsCredentials of user issuing the action.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 5211 of file gsad_gmp.c.

5214 {
5215  GString *xml;
5216  int ret;
5217  entity_t entity;
5218  gchar *response;
5219 
5220  xml = g_string_new ("<new_alert>");
5221  if (extra_xml)
5222  g_string_append (xml, extra_xml);
5223 
5224  /* Get Report Formats. */
5225 
5226  response = NULL;
5227  entity = NULL;
5228  ret = gmp (connection, credentials, &response, &entity, response_data,
5229  "<get_report_formats filter=\"rows=-1\"/>");
5230  switch (ret)
5231  {
5232  case 0:
5233  case -1:
5234  break;
5235  case 1:
5236  cmd_response_data_set_status_code (response_data,
5237  MHD_HTTP_INTERNAL_SERVER_ERROR);
5238  return gsad_message (
5239  credentials, "Internal error", __FUNCTION__, __LINE__,
5240  "An internal error occurred while getting Report "
5241  "Formats for new alert. "
5242  "Diagnostics: Failure to send command to manager daemon.",
5243  response_data);
5244  case 2:
5245  cmd_response_data_set_status_code (response_data,
5246  MHD_HTTP_INTERNAL_SERVER_ERROR);
5247  return gsad_message (
5248  credentials, "Internal error", __FUNCTION__, __LINE__,
5249  "An internal error occurred while getting Report "
5250  "Formats for new alert. "
5251  "Diagnostics: Failure to receive response from manager daemon.",
5252  response_data);
5253  default:
5254  cmd_response_data_set_status_code (response_data,
5255  MHD_HTTP_INTERNAL_SERVER_ERROR);
5256  return gsad_message (credentials, "Internal error", __FUNCTION__,
5257  __LINE__,
5258  "An internal error occurred while getting Report "
5259  "Formats for new alert. It is unclear whether"
5260  " the alert has been saved or not. "
5261  "Diagnostics: Internal Error.",
5262  response_data);
5263  }
5264  g_string_append (xml, response);
5265  g_free (response);
5266  free_entity (entity);
5267 
5268  /* Get Report Filters. */
5269 
5270  ret = gmp (connection, credentials, &response, &entity, response_data,
5271  "<get_filters filter=\"rows=-1\"/>");
5272 
5273  switch (ret)
5274  {
5275  case 0:
5276  case -1:
5277  break;
5278  case 1:
5279  cmd_response_data_set_status_code (response_data,
5280  MHD_HTTP_INTERNAL_SERVER_ERROR);
5281  return gsad_message (
5282  credentials, "Internal error", __FUNCTION__, __LINE__,
5283  "An internal error occurred while getting Report "
5284  "Filters for new alert. "
5285  "The task was not saved. "
5286  "Diagnostics: Failure to send command to manager daemon.",
5287  response_data);
5288  case 2:
5289  cmd_response_data_set_status_code (response_data,
5290  MHD_HTTP_INTERNAL_SERVER_ERROR);
5291  return gsad_message (
5292  credentials, "Internal error", __FUNCTION__, __LINE__,
5293  "An internal error occurred while getting Report "
5294  "Filters for new alert. "
5295  "Diagnostics: Failure to receive response from manager daemon.",
5296  response_data);
5297  default:
5298  cmd_response_data_set_status_code (response_data,
5299  MHD_HTTP_INTERNAL_SERVER_ERROR);
5300  return gsad_message (credentials, "Internal error", __FUNCTION__,
5301  __LINE__,
5302  "An internal error occurred while getting Report "
5303  "Filters for new alert. "
5304  "Diagnostics: Internal Error.",
5305  response_data);
5306  }
5307  g_string_append (xml, response);
5308  g_free (response);
5309  free_entity (entity);
5310 
5311  /* Get Tasks. */
5312 
5313  ret = gmp (connection, credentials, &response, &entity, response_data,
5314  "<get_tasks"
5315  " schedules_only=\"1\""
5316  " filter=\"owner=any permission=start_task rows=-1\"/>");
5317 
5318  switch (ret)
5319  {
5320  case 0:
5321  case -1:
5322  break;
5323  case 1:
5324  cmd_response_data_set_status_code (response_data,
5325  MHD_HTTP_INTERNAL_SERVER_ERROR);
5326  return gsad_message (
5327  credentials, "Internal error", __FUNCTION__, __LINE__,
5328  "An internal error occurred while getting Tasks"
5329  " for new alert. "
5330  "The task was not saved. "
5331  "Diagnostics: Failure to send command to manager daemon.",
5332  response_data);
5333  case 2:
5334  cmd_response_data_set_status_code (response_data,
5335  MHD_HTTP_INTERNAL_SERVER_ERROR);
5336  return gsad_message (
5337  credentials, "Internal error", __FUNCTION__, __LINE__,
5338  "An internal error occurred while getting Tasks"
5339  " for new alert. "
5340  "Diagnostics: Failure to receive response from manager daemon.",
5341  response_data);
5342  default:
5343  cmd_response_data_set_status_code (response_data,
5344  MHD_HTTP_INTERNAL_SERVER_ERROR);
5345  return gsad_message (credentials, "Internal error", __FUNCTION__,
5346  __LINE__,
5347  "An internal error occurred while getting Tasks"
5348  " for new alert. "
5349  "Diagnostics: Internal Error.",
5350  response_data);
5351  }
5352  g_string_append (xml, response);
5353  g_free (response);
5354  free_entity (entity);
5355 
5356  /* Get Credentials. */
5357 
5358  ret = gmp (connection, credentials, &response, &entity, response_data,
5359  "<get_credentials"
5360  " filter=\"type=up or type=pw"
5361  " owner=any permission=any rows=-1\"/>");
5362 
5363  switch (ret)
5364  {
5365  case 0:
5366  case -1:
5367  break;
5368  case 1:
5369  cmd_response_data_set_status_code (response_data,
5370  MHD_HTTP_INTERNAL_SERVER_ERROR);
5371  return gsad_message (
5372  credentials, "Internal error", __FUNCTION__, __LINE__,
5373  "An internal error occurred while getting"
5374  " Credentials for new alert. "
5375  "The task was not saved. "
5376  "Diagnostics: Failure to send command to manager daemon.",
5377  response_data);
5378  case 2:
5379  cmd_response_data_set_status_code (response_data,
5380  MHD_HTTP_INTERNAL_SERVER_ERROR);
5381  return gsad_message (
5382  credentials, "Internal error", __FUNCTION__, __LINE__,
5383  "An internal error occurred while getting"
5384  " Credentials for new alert. "
5385  "Diagnostics: Failure to receive response from manager daemon.",
5386  response_data);
5387  default:
5388  cmd_response_data_set_status_code (response_data,
5389  MHD_HTTP_INTERNAL_SERVER_ERROR);
5390  return gsad_message (credentials, "Internal error", __FUNCTION__,
5391  __LINE__,
5392  "An internal error occurred while getting"
5393  " Credentials for new alert. "
5394  "Diagnostics: Internal Error.",
5395  response_data);
5396  }
5397 
5398  g_string_append (xml, response);
5399  g_free (response);
5400  free_entity (entity);
5401 
5402  g_string_append (xml, "</new_alert>");
5403  return envelope_gmp (connection, credentials, params,
5404  g_string_free (xml, FALSE), response_data);
5405 }
Structure of credential related information.
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
static char * envelope_gmp(gvm_connection_t *connection, credentials_t *credentials, params_t *params, gchar *xml, cmd_response_data_t *response_data)
Wrap some XML in an envelope.
Definition: gsad_gmp.c:443

References cmd_response_data_set_status_code(), envelope_gmp(), gmp(), and gsad_message().

Referenced by new_alert_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ new_alert_gmp()

char* new_alert_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Returns page to create a new alert.

Parameters
[in]connectionConnection to manager.
[in]credentialsCredentials of user issuing the action.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 5418 of file gsad_gmp.c.

5420 {
5421  return new_alert (connection, credentials, params, NULL, response_data);
5422 }
Structure of credential related information.
static char * new_alert(gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *extra_xml, cmd_response_data_t *response_data)
Returns page to create a new alert.
Definition: gsad_gmp.c:5211

References new_alert().

Here is the call graph for this function:

◆ params_toggle_overrides()

static void params_toggle_overrides ( params_t *  params,
const char *  overrides 
)
static

Toggle overrides.

Parameters
[in]paramsRequest parameters.
[in]overridesNew overrides value.

Definition at line 3456 of file gsad_gmp.c.

3457 {
3458  param_t *filt_id, *build_filter;
3459  const char *new_filt_id;
3460 
3461  build_filter = params_get (params, "build_filter");
3462 
3463  if (build_filter)
3464  new_filt_id = "";
3465  else
3466  new_filt_id = "0";
3467 
3468  filt_id = params_get (params, "filt_id");
3469  if (filt_id)
3470  {
3471  filt_id->value = g_strdup (new_filt_id);
3472  filt_id->value_size = strlen (filt_id->value);
3473  filt_id->valid = 1;
3474  filt_id->valid_utf8 = 1;
3475  }
3476  else
3477  params_add (params, "filt_id", new_filt_id);
3478 
3479  if (build_filter == NULL)
3480  {
3481  param_t *filter;
3482  filter = params_get (params, "filter");
3483  if (filter && filter->value)
3484  {
3485  gchar *old;
3486  old = filter->value;
3487  filter->value =
3488  g_strdup_printf ("apply_overrides=%s %s", overrides, old);
3489  g_free (old);
3490  }
3491  else if (strcmp (overrides, "0"))
3492  params_add (params, "filter", "apply_overrides=1 rows=-2");
3493  else
3494  params_add (params, "filter", "apply_overrides=0 rows=-2");
3495  }
3496 }
gchar * value
Definition: gsad_params.h:40
param_t * params_get(params_t *params, const char *name)
Get param.
Definition: gsad_base.c:173
int valid_utf8
Definition: gsad_params.h:45
int value_size
Definition: gsad_params.h:46
Request parameter.
Definition: gsad_params.h:38
int valid
Definition: gsad_params.h:44
param_t * params_add(params_t *params, const char *name, const char *value)
Add a param.
Definition: gsad_base.c:318

References params_add(), params_get(), param::valid, param::valid_utf8, param::value, and param::value_size.

Referenced by get_reports(), get_results(), and get_tasks().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ping_gmp()

char* ping_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get assets, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 19179 of file gsad_gmp.c.

19181 {
19182  return action_result (connection, credentials, params, response_data, "ping",
19183  "pong", NULL, NULL);
19184 }
Structure of credential related information.
static gchar * action_result(gvm_connection_t *, credentials_t *, params_t *, cmd_response_data_t *, const char *action, const char *message, const char *details, const char *id)
Generate a enveloped GMP XML containing an action result.
Definition: gsad_gmp.c:965

References action_result().

Here is the call graph for this function:

◆ renew_session_gmp()

char* renew_session_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Definition at line 19150 of file gsad_gmp.c.

19152 {
19153  gchar *html;
19154  gchar *message;
19156 
19159 
19160  message = g_strdup_printf ("%ld", user_get_session_timeout (user));
19161 
19162  html = action_result (connection, credentials, params, response_data,
19163  "renew_session", message, NULL, NULL);
19164  g_free (message);
19165  return html;
19166 }
void user_renew_session(user_t *user)
Definition: gsad_user.c:60
Structure of credential related information.
const gchar * user_get_token(user_t *user)
Definition: gsad_user.c:175
const time_t user_get_session_timeout(user_t *user)
Definition: gsad_user.c:229
void session_add_user(const gchar *id, user_t *user)
Add user to the session "database".
Definition: gsad_session.c:147
static gchar * action_result(gvm_connection_t *, credentials_t *, params_t *, cmd_response_data_t *, const char *action, const char *message, const char *details, const char *id)
Generate a enveloped GMP XML containing an action result.
Definition: gsad_gmp.c:965
User information structure, for sessions.
Definition: gsad_user.c:42
user_t * credentials_get_user(credentials_t *cred)

References action_result(), credentials_get_user(), session_add_user(), user_get_session_timeout(), user_get_token(), and user_renew_session().

Here is the call graph for this function:

◆ report_alert_gmp()

char* report_alert_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Run alert for a report.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 10414 of file gsad_gmp.c.

10416 {
10417  entity_t entity;
10418  const char *alert_id, *report_id;
10419  const char *status, *filter;
10420  gchar *response, *html;
10421  int ret;
10422 
10423  alert_id = params_value (params, "alert_id");
10424  report_id = params_value (params, "report_id");
10425 
10426  if ((alert_id == NULL) || (report_id == NULL))
10427  {
10428  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
10429  return gsad_message (credentials, "Bad Request", __FUNCTION__, __LINE__,
10430  "Missing parameter alert_id or report_id. "
10431  "Diagnostics: Required parameter was NULL.",
10432  response_data);
10433  }
10434 
10435  filter = params_value (params, "filter");
10436 
10437  if (filter == NULL && !params_given (params, "filter"))
10438  filter = "first=1 rows=-1"
10439  " result_hosts_only=0"
10440  " apply_overrides=1"
10441  " notes=1 overrides=1"
10442  " sort-reverse=severity";
10443 
10444  ret = gvm_connection_sendf_xml (connection,
10445  "<get_reports"
10446  " report_id=\"%s\""
10447  " ignore_pagination=\"1\""
10448  " filter=\"%s\""
10449  " alert_id=\"%s\"/>",
10450  report_id, filter ? filter : "", alert_id);
10451  if (ret == -1)
10452  {
10453  cmd_response_data_set_status_code (response_data,
10454  MHD_HTTP_INTERNAL_SERVER_ERROR);
10455  return gsad_message (
10456  credentials, "Internal error", __FUNCTION__, __LINE__,
10457  "An internal error occurred while getting a report. "
10458  "The report could not be delivered. "
10459  "Diagnostics: Failure to send command to manager daemon.",
10460  response_data);
10461  }
10462 
10463  if (read_entity_and_text_c (connection, &entity, &response))
10464  {
10465  cmd_response_data_set_status_code (response_data,
10466  MHD_HTTP_INTERNAL_SERVER_ERROR);
10467  return gsad_message (credentials, "Internal error", __FUNCTION__,
10468  __LINE__,
10469  "An internal error occurred while getting a report. "
10470  "The report could not be delivered. "
10471  "Diagnostics: Failure to receive response from "
10472  "manager daemon.",
10473  response_data);
10474  }
10475 
10476  status = entity_attribute (entity, "status");
10477  if ((status == NULL) || (strlen (status) == 0))
10478  {
10479  free_entity (entity);
10480  g_free (response);
10481  cmd_response_data_set_status_code (response_data,
10482  MHD_HTTP_INTERNAL_SERVER_ERROR);
10483  return gsad_message (
10484  credentials, "Internal error", __FUNCTION__, __LINE__,
10485  "An internal error occurred while getting a report. "
10486  "The report could not be delivered. "
10487  "Diagnostics: Failure to parse response from manager daemon.",
10488  response_data);
10489  }
10490  if (strcmp (status, "200"))
10491  {
10492  free_entity (entity);
10493  g_free (response);
10494  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
10495  return gsad_message (credentials, "Failed", __FUNCTION__, __LINE__,
10496  "Running the report alert failed."
10497  "The report could not be delivered.",
10498  response_data);
10499  }
10500 
10501  html = response_from_entity (connection, credentials, params, entity,
10502  "Report Alert", response_data);
10503 
10504  free_entity (entity);
10505  g_free (response);
10506  return html;
10507 }
Structure of credential related information.
int params_given(params_t *params, const char *name)
Get whether a param was given at all.
Definition: gsad_base.c:189
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References cmd_response_data_set_status_code(), gsad_message(), params_given(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ resource_action()

char* resource_action ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  type,
const char *  action,
cmd_response_data_t *  response_data 
)

Perform action on resource, get next page, envelope result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]typeType of resource.
[in]actionAction to perform.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 2068 of file gsad_gmp.c.

2071 {
2072  gchar *html, *response, *param_name;
2073  const char *resource_id;
2074  gchar *cap_action, *cap_type, *get_cmd, *prev_action;
2075 
2076  int ret;
2077  entity_t entity;
2078 
2079  assert (type);
2080 
2081  param_name = g_strdup_printf ("%s_id", type);
2082  resource_id = params_value (params, param_name);
2083 
2084  if (resource_id == NULL)
2085  {
2086  gchar *message;
2087  message = g_strdup_printf (
2088  "An internal error occurred while performing an action. "
2089  "The resource remains the same. "
2090  "Diagnostics: Required parameter %s was NULL.",
2091  param_name);
2092  g_free (param_name);
2093  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
2094  html = gsad_message (credentials, "Internal error", __FUNCTION__,
2095  __LINE__, message, response_data);
2096  g_free (message);
2097  return html;
2098  }
2099  g_free (param_name);
2100 
2101  response = NULL;
2102  entity = NULL;
2103  ret = gmpf (connection, credentials, &response, &entity, response_data,
2104  "<%s_%s %s_id=\"%s\"/>", action, type, type, resource_id);
2105  switch (ret)
2106  {
2107  case 0:
2108  case -1:
2109  break;
2110  case 1:
2111  cmd_response_data_set_status_code (response_data,
2112  MHD_HTTP_INTERNAL_SERVER_ERROR);
2113  return gsad_message (
2114  credentials, "Internal error", __FUNCTION__, __LINE__,
2115  "An internal error occurred while performing an action. "
2116  "The resource remains the same. "
2117  "Diagnostics: Failure to send command to manager daemon.",
2118  response_data);
2119  case 2:
2120  cmd_response_data_set_status_code (response_data,
2121  MHD_HTTP_INTERNAL_SERVER_ERROR);
2122  return gsad_message (
2123  credentials, "Internal error", __FUNCTION__, __LINE__,
2124  "An internal error occurred while performing an action. "
2125  "It is unclear whether the resource has been affected. "
2126  "Diagnostics: Failure to receive response from manager daemon.",
2127  response_data);
2128  default:
2129  cmd_response_data_set_status_code (response_data,
2130  MHD_HTTP_INTERNAL_SERVER_ERROR);
2131  return gsad_message (
2132  credentials, "Internal error", __FUNCTION__, __LINE__,
2133  "An internal error occurred while performing an action. "
2134  "It is unclear whether the resource has been affected. "
2135  "Diagnostics: Internal Error.",
2136  response_data);
2137  }
2138 
2139  if (!gmp_success (entity))
2140  set_http_status_from_entity (entity, response_data);
2141 
2142  cap_action = capitalize (action);
2143  cap_type = capitalize (type);
2144  get_cmd = g_strdup_printf ("get_%ss", type);
2145  prev_action = g_strdup_printf ("%s %s", cap_action, cap_type);
2146  html = response_from_entity (connection, credentials, params, entity,
2147  prev_action, response_data);
2148 
2149  g_free (response);
2150  free_entity (entity);
2151  g_free (cap_action);
2152  g_free (cap_type);
2153  g_free (get_cmd);
2154  g_free (prev_action);
2155 
2156  return html;
2157 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
static int gmp_success(entity_t entity)
Check whether an GMP command failed.
Definition: gsad_gmp.c:656
Structure of credential related information.
gchar * capitalize(const char *input)
Capitalize a type or command name and replace underscores.
Definition: utils.c:48
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
void set_http_status_from_entity(entity_t entity, cmd_response_data_t *response_data)
Set the HTTP status according to GMP response entity.
Definition: gsad_gmp.c:677
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References capitalize(), cmd_response_data_set_status_code(), gmp_success(), gmpf(), gsad_message(), params_value(), response_from_entity(), and set_http_status_from_entity().

Referenced by resume_task_gmp(), start_task_gmp(), and stop_task_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ response_from_entity()

static gchar * response_from_entity ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
entity_t  entity,
const char *  action,
cmd_response_data_t *  response_data 
)
static

Set redirect or return a basic action_result page based on entity.

Parameters
[in]connectionConnection to manager

Definition at line 1023 of file gsad_gmp.c.

1026 {
1027  gchar *res;
1028  entity_t status_details_entity;
1029  int success;
1030  success = gmp_success (entity);
1031 
1032  if (!success)
1033  {
1034  set_http_status_from_entity (entity, response_data);
1035  }
1036 
1037  status_details_entity = entity_child (entity, "status_details");
1038 
1039  res = action_result (connection, credentials, params, response_data, action,
1040  entity_attribute (entity, "status_text"),
1041  entity_text (status_details_entity),
1042  entity_attribute (entity, "id"));
1043  return res;
1044 }
static int gmp_success(entity_t entity)
Check whether an GMP command failed.
Definition: gsad_gmp.c:656
Structure of credential related information.
void set_http_status_from_entity(entity_t entity, cmd_response_data_t *response_data)
Set the HTTP status according to GMP response entity.
Definition: gsad_gmp.c:677
static gchar * action_result(gvm_connection_t *, credentials_t *, params_t *, cmd_response_data_t *, const char *action, const char *message, const char *details, const char *id)
Generate a enveloped GMP XML containing an action result.
Definition: gsad_gmp.c:965

References action_result(), gmp_success(), and set_http_status_from_entity().

Referenced by bulk_delete_gmp(), check_modify_config(), clone_gmp(), create_agent_gmp(), create_alert_gmp(), create_asset_gmp(), create_config_gmp(), create_container_task_gmp(), create_credential_gmp(), create_filter_gmp(), create_group_gmp(), create_host_gmp(), create_note_gmp(), create_override_gmp(), create_permission_gmp(), create_port_list_gmp(), create_port_range_gmp(), create_report_gmp(), create_role_gmp(), create_scanner_gmp(), create_schedule_gmp(), create_tag_gmp(), create_target_gmp(), create_task_gmp(), create_ticket_gmp(), create_user_gmp(), delete_asset_gmp(), delete_resource(), empty_trashcan_gmp(), import_config_gmp(), import_port_list_gmp(), import_report_format_gmp(), move_task_gmp(), report_alert_gmp(), resource_action(), restore_gmp(), run_wizard_gmp(), save_agent_gmp(), save_alert_gmp(), save_asset_gmp(), save_auth_gmp(), save_container_task_gmp(), save_credential_gmp(), save_filter_gmp(), save_group_gmp(), save_note_gmp(), save_override_gmp(), save_permission_gmp(), save_port_list_gmp(), save_report_format_gmp(), save_role_gmp(), save_scanner_gmp(), save_schedule_gmp(), save_setting_gmp(), save_tag_gmp(), save_target_gmp(), save_task_gmp(), save_ticket_gmp(), save_user_gmp(), sync_feed(), test_alert_gmp(), toggle_tag_gmp(), verify_agent_gmp(), verify_report_format_gmp(), and verify_scanner_gmp().

Here is the call graph for this function:

◆ restore_gmp()

char* restore_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Restore a resource, get all trash, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 6974 of file gsad_gmp.c.

6976 {
6977  GString *xml;
6978  gchar *ret;
6979  entity_t entity;
6980  const char *target_id;
6981 
6982  target_id = params_value (params, "target_id");
6983 
6984  CHECK_VARIABLE_INVALID (target_id, "Restore")
6985 
6986  xml = g_string_new ("");
6987 
6988  /* Restore the resource. */
6989 
6990  if (gvm_connection_sendf (connection,
6991  "<restore"
6992  " id=\"%s\"/>",
6993  target_id)
6994  == -1)
6995  {
6996  g_string_free (xml, TRUE);
6997  cmd_response_data_set_status_code (response_data,
6998  MHD_HTTP_INTERNAL_SERVER_ERROR);
6999  return gsad_message (
7000  credentials, "Internal error", __FUNCTION__, __LINE__,
7001  "An internal error occurred while restoring a resource. "
7002  "The resource was not deleted. "
7003  "Diagnostics: Failure to send command to manager daemon.",
7004  response_data);
7005  }
7006 
7007  if (read_entity_and_string_c (connection, &entity, &xml))
7008  {
7009  g_string_free (xml, TRUE);
7010  cmd_response_data_set_status_code (response_data,
7011  MHD_HTTP_INTERNAL_SERVER_ERROR);
7012  return gsad_message (
7013  credentials, "Internal error", __FUNCTION__, __LINE__,
7014  "An internal error occurred while restoring a resource. "
7015  "It is unclear whether the resource has been restored or not. "
7016  "Diagnostics: Failure to read response from manager daemon.",
7017  response_data);
7018  }
7019 
7020  /* Cleanup, and return trash page. */
7021 
7022  ret = response_from_entity (connection, credentials, params, entity,
7023  "Restore", response_data);
7024  free_entity (entity);
7025  g_string_free (xml, FALSE);
7026  return ret;
7027 }
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gsad_message(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ resume_task_gmp()

char* resume_task_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Resume a task, get all tasks, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 3214 of file gsad_gmp.c.

3216 {
3217  return resource_action (connection, credentials, params, "task", "resume",
3218  response_data);
3219 }
Structure of credential related information.
char * resource_action(gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *type, const char *action, cmd_response_data_t *response_data)
Perform action on resource, get next page, envelope result.
Definition: gsad_gmp.c:2068

References resource_action().

Here is the call graph for this function:

◆ run_wizard_gmp()

char* run_wizard_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Run a wizard and envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 13019 of file gsad_gmp.c.

13021 {
13022  const char *name;
13023  int ret;
13024  GString *run;
13025  param_t *param;
13026  gchar *param_name, *html, *response;
13027  params_iterator_t iter;
13028  params_t *wizard_params;
13029  entity_t entity;
13030 
13031  /* The naming is a bit subtle here, because the HTTP request
13032  * parameters are called "param"s and so are the GMP wizard
13033  * parameters. */
13034 
13035  name = params_value (params, "name");
13036  if (name == NULL)
13037  {
13038  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
13039  return gsad_message (
13040  credentials, "Internal error", __FUNCTION__, __LINE__,
13041  "An internal error occurred while trying to start a wizard. "
13042  "Diagnostics: Required parameter 'name' was NULL.",
13043  response_data);
13044  }
13045  run = g_string_new ("<run_wizard>");
13046 
13047  g_string_append_printf (run,
13048  "<name>%s</name>"
13049  "<params>",
13050  name);
13051 
13052  wizard_params = params_values (params, "event_data:");
13053  if (wizard_params)
13054  {
13055  params_iterator_init (&iter, wizard_params);
13056  while (params_iterator_next (&iter, &param_name, &param))
13057  xml_string_append (run,
13058  "<param>"
13059  "<name>%s</name>"
13060  "<value>%s</value>"
13061  "</param>",
13062  param_name, param->value);
13063  }
13064 
13065  g_string_append (run, "</params></run_wizard>");
13066 
13067  response = NULL;
13068  entity = NULL;
13069  ret =
13070  gmp (connection, credentials, &response, &entity, response_data, run->str);
13071  g_string_free (run, TRUE);
13072  switch (ret)
13073  {
13074  case 0:
13075  case -1:
13076  break;
13077  case 1:
13078  cmd_response_data_set_status_code (response_data,
13079  MHD_HTTP_INTERNAL_SERVER_ERROR);
13080  return gsad_message (
13081  credentials, "Internal error", __FUNCTION__, __LINE__,
13082  "An internal error occurred while running a wizard. "
13083  "The wizard did not start. "
13084  "Diagnostics: Failure to send command to manager daemon.",
13085  response_data);
13086  case 2:
13087  cmd_response_data_set_status_code (response_data,
13088  MHD_HTTP_INTERNAL_SERVER_ERROR);
13089  return gsad_message (
13090  credentials, "Internal error", __FUNCTION__, __LINE__,
13091  "An internal error occurred while running a wizard. "
13092  "It is unclear whether the wizard started or not. "
13093  "Diagnostics: Failure to receive response from manager daemon.",
13094  response_data);
13095  default:
13096  cmd_response_data_set_status_code (response_data,
13097  MHD_HTTP_INTERNAL_SERVER_ERROR);
13098  return gsad_message (credentials, "Internal error", __FUNCTION__,
13099  __LINE__,
13100  "An internal error occurred while running a wizard. "
13101  "It is unclear whether the wizard started or not. "
13102  "Diagnostics: Internal Error.",
13103  response_data);
13104  }
13105 
13106  html = response_from_entity (connection, credentials, params, entity,
13107  "Run Wizard", response_data);
13108  free_entity (entity);
13109  g_free (response);
13110  return html;
13111 }
params_t * params_values(params_t *params, const char *name)
Get values of param.
Definition: gsad_base.c:287
gchar * value
Definition: gsad_params.h:40
Structure of credential related information.
#define params_iterator_t
Definition: gsad_params.h:94
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
Request parameter.
Definition: gsad_params.h:38
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
gboolean params_iterator_next(params_iterator_t *iterator, char **name, param_t **param)
Increment a params iterator.
Definition: gsad_base.c:394
#define params_iterator_init
Definition: gsad_params.h:96
#define params_t
Definition: gsad_params.h:31
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References cmd_response_data_set_status_code(), gmp(), gsad_message(), params_iterator_init, params_iterator_next(), params_iterator_t, params_t, params_value(), params_values(), response_from_entity(), and param::value.

Here is the call graph for this function:

◆ save_agent_gmp()

char* save_agent_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Modify a agent, get all agents, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 4753 of file gsad_gmp.c.

4755 {
4756  int ret;
4757  gchar *html, *response;
4758  const char *agent_id, *name, *comment;
4759  entity_t entity;
4760 
4761  agent_id = params_value (params, "agent_id");
4762  name = params_value (params, "name");
4763  comment = params_value (params, "comment");
4764 
4765  CHECK_VARIABLE_INVALID (agent_id, "Save Agent");
4766  CHECK_VARIABLE_INVALID (name, "Save Agent");
4767  CHECK_VARIABLE_INVALID (comment, "Save Agent");
4768 
4769  /* Modify the agent. */
4770 
4771  response = NULL;
4772  entity = NULL;
4773  ret = gmpf (connection, credentials, &response, &entity, response_data,
4774  "<modify_agent agent_id=\"%s\">"
4775  "<name>%s</name>"
4776  "<comment>%s</comment>"
4777  "</modify_agent>",
4778  agent_id, name, comment);
4779 
4780  switch (ret)
4781  {
4782  case 0:
4783  case -1:
4784  break;
4785  case 1:
4786  cmd_response_data_set_status_code (response_data,
4787  MHD_HTTP_INTERNAL_SERVER_ERROR);
4788  return gsad_message (
4789  credentials, "Internal error", __FUNCTION__, __LINE__,
4790  "An internal error occurred while saving a agent. "
4791  "The agent was not saved. "
4792  "Diagnostics: Failure to send command to manager daemon.",
4793  response_data);
4794  case 2:
4795  cmd_response_data_set_status_code (response_data,
4796  MHD_HTTP_INTERNAL_SERVER_ERROR);
4797  return gsad_message (
4798  credentials, "Internal error", __FUNCTION__, __LINE__,
4799  "An internal error occurred while saving a agent. "
4800  "It is unclear whether the agent has been saved or not. "
4801  "Diagnostics: Failure to receive response from manager daemon.",
4802  response_data);
4803  default:
4804  cmd_response_data_set_status_code (response_data,
4805  MHD_HTTP_INTERNAL_SERVER_ERROR);
4806  return gsad_message (
4807  credentials, "Internal error", __FUNCTION__, __LINE__,
4808  "An internal error occurred while saving a agent. "
4809  "It is unclear whether the agent has been saved or not. "
4810  "Diagnostics: Internal Error.",
4811  response_data);
4812  }
4813 
4814  html = response_from_entity (connection, credentials, params, entity,
4815  "Save Agent", response_data);
4816  free_entity (entity);
4817  g_free (response);
4818  return html;
4819 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmpf(), gsad_message(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ save_alert_gmp()

char* save_alert_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Modify an alert, get all alerts, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 6427 of file gsad_gmp.c.

6429 {
6430  GString *xml;
6431  int ret;
6432  gchar *html, *response;
6433  const char *name, *comment, *alert_id;
6434  const char *event, *condition, *method;
6435  const char *filter_id, *active;
6436  params_t *event_data, *condition_data, *method_data, *report_formats;
6437  entity_t entity;
6438 
6439  name = params_value (params, "name");
6440  comment = params_value (params, "comment");
6441  condition = params_value (params, "condition");
6442  event = params_value (params, "event");
6443  method = params_value (params, "method");
6444  alert_id = params_value (params, "alert_id");
6445  filter_id = params_value (params, "filter_id");
6446  active = params_value (params, "active");
6447 
6448  CHECK_VARIABLE_INVALID (name, "Save Alert");
6449  CHECK_VARIABLE_INVALID (comment, "Save Alert");
6450  CHECK_VARIABLE_INVALID (alert_id, "Save Alert");
6451  CHECK_VARIABLE_INVALID (condition, "Save Alert");
6452  CHECK_VARIABLE_INVALID (event, "Save Alert");
6453  CHECK_VARIABLE_INVALID (method, "Save Alert");
6454  CHECK_VARIABLE_INVALID (filter_id, "Save Alert");
6455  CHECK_VARIABLE_INVALID (active, "Save Alert");
6456 
6457  xml = g_string_new ("");
6458 
6459  /* Modify the alert. */
6460 
6461  event_data = params_values (params, "event_data:");
6462  condition_data = params_values (params, "condition_data:");
6463  method_data = params_values (params, "method_data:");
6464  report_formats = params_values (params, "report_format_ids:");
6465 
6466  if (str_equal (event, EVENT_TYPE_NEW_SECINFO) && event_data)
6467  {
6468  params_iterator_t iter;
6469  char *name;
6470  param_t *param;
6471 
6472  params_iterator_init (&iter, event_data);
6473  while (params_iterator_next (&iter, &name, &param))
6474  if (str_equal (name, "feed_event") && param->value
6475  && str_equal (param->value, "updated"))
6476  {
6478  break;
6479  }
6480  }
6481 
6482  xml_string_append (xml,
6483  "<modify_alert alert_id=\"%s\">"
6484  "<name>%s</name>"
6485  "<filter id=\"%s\"/>"
6486  "<active>%s</active>"
6487  "<comment>%s</comment>"
6488  "<event>%s",
6489  alert_id, name, filter_id, active, comment ? comment : "",
6490  event);
6491 
6492  append_alert_event_data (xml, event_data, event);
6493 
6494  xml_string_append (xml,
6495  "</event>"
6496  "<method>%s",
6497  method);
6498 
6499  append_alert_method_data (xml, method_data, method, report_formats);
6500 
6501  xml_string_append (xml,
6502  "</method>"
6503  "<condition>%s",
6504  condition);
6505 
6506  append_alert_condition_data (xml, condition_data, condition);
6507 
6508  xml_string_append (xml, "</condition>"
6509  "</modify_alert>");
6510 
6511  ret =
6512  gmp (connection, credentials, &response, &entity, response_data, xml->str);
6513  g_string_free (xml, TRUE);
6514  switch (ret)
6515  {
6516  case 0:
6517  case -1:
6518  break;
6519  case 1:
6520  cmd_response_data_set_status_code (response_data,
6521  MHD_HTTP_INTERNAL_SERVER_ERROR);
6522  return gsad_message (
6523  credentials, "Internal error", __FUNCTION__, __LINE__,
6524  "An internal error occurred while saving a new alert. "
6525  "No new alert was created. "
6526  "Diagnostics: Failure to send command to manager daemon.",
6527  response_data);
6528  case 2:
6529  cmd_response_data_set_status_code (response_data,
6530  MHD_HTTP_INTERNAL_SERVER_ERROR);
6531  return gsad_message (
6532  credentials, "Internal error", __FUNCTION__, __LINE__,
6533  "An internal error occurred while saving a new alert. "
6534  "It is unclear whether the alert has been created or not. "
6535  "Diagnostics: Failure to receive response from manager daemon.",
6536  response_data);
6537  default:
6538  cmd_response_data_set_status_code (response_data,
6539  MHD_HTTP_INTERNAL_SERVER_ERROR);
6540  return gsad_message (
6541  credentials, "Internal error", __FUNCTION__, __LINE__,
6542  "An internal error occurred while saving a new alert. "
6543  "It is unclear whether the alert has been created or not. "
6544  "Diagnostics: Internal Error.",
6545  response_data);
6546  }
6547 
6548  html = response_from_entity (connection, credentials, params, entity,
6549  "Save Alert", response_data);
6550  free_entity (entity);
6551  g_free (response);
6552  return html;
6553 }
params_t * params_values(params_t *params, const char *name)
Get values of param.
Definition: gsad_base.c:287
gchar * value
Definition: gsad_params.h:40
#define EVENT_TYPE_UPDATED_SECINFO
Definition: gsad_gmp.c:5429
Structure of credential related information.
gboolean str_equal(const gchar *str1, const gchar *str2)
Check if two strings are equal.
Definition: utils.c:35
#define params_iterator_t
Definition: gsad_params.h:94
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
static void append_alert_condition_data(GString *xml, params_t *data, const char *condition)
Send condition data for an alert.
Definition: gsad_gmp.c:5472
#define EVENT_TYPE_NEW_SECINFO
Definition: gsad_gmp.c:5428
static void append_alert_event_data(GString *xml, params_t *data, const char *event)
Send event data for an alert.
Definition: gsad_gmp.c:5444
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
Request parameter.
Definition: gsad_params.h:38
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
gboolean params_iterator_next(params_iterator_t *iterator, char **name, param_t **param)
Increment a params iterator.
Definition: gsad_base.c:394
#define params_iterator_init
Definition: gsad_params.h:96
#define params_t
Definition: gsad_params.h:31
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
static void append_alert_method_data(GString *xml, params_t *data, const char *method, params_t *report_formats)
Send method data for an alert.
Definition: gsad_gmp.c:5522

References append_alert_condition_data(), append_alert_event_data(), append_alert_method_data(), CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), EVENT_TYPE_NEW_SECINFO, EVENT_TYPE_UPDATED_SECINFO, gmp(), gsad_message(), params_iterator_init, params_iterator_next(), params_iterator_t, params_t, params_value(), params_values(), response_from_entity(), str_equal(), and param::value.

Here is the call graph for this function:

◆ save_asset_gmp()

char* save_asset_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Modify an asset, get all assets, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 18871 of file gsad_gmp.c.

18873 {
18874  int ret;
18875  gchar *html, *response;
18876  const char *asset_id, *comment;
18877  entity_t entity;
18878 
18879  asset_id = params_value (params, "asset_id");
18880  comment = params_value (params, "comment");
18881 
18882  CHECK_VARIABLE_INVALID (asset_id, "Save Asset");
18883  CHECK_VARIABLE_INVALID (comment, "Save Asset");
18884 
18885  /* Modify the asset. */
18886 
18887  response = NULL;
18888  entity = NULL;
18889  ret = gmpf (connection, credentials, &response, &entity, response_data,
18890  "<modify_asset asset_id=\"%s\">"
18891  "<comment>%s</comment>"
18892  "</modify_asset>",
18893  asset_id, comment);
18894 
18895  switch (ret)
18896  {
18897  case 0:
18898  case -1:
18899  break;
18900  case 1:
18901  cmd_response_data_set_status_code (response_data,
18902  MHD_HTTP_INTERNAL_SERVER_ERROR);
18903  return gsad_message (
18904  credentials, "Internal error", __FUNCTION__, __LINE__,
18905  "An internal error occurred while saving an asset. "
18906  "The asset was not saved. "
18907  "Diagnostics: Failure to send command to manager daemon.",
18908  response_data);
18909  case 2:
18910  cmd_response_data_set_status_code (response_data,
18911  MHD_HTTP_INTERNAL_SERVER_ERROR);
18912  return gsad_message (
18913  credentials, "Internal error", __FUNCTION__, __LINE__,
18914  "An internal error occurred while saving an asset. "
18915  "It is unclear whether the asset has been saved or not. "
18916  "Diagnostics: Failure to receive response from manager daemon.",
18917  response_data);
18918  default:
18919  cmd_response_data_set_status_code (response_data,
18920  MHD_HTTP_INTERNAL_SERVER_ERROR);
18921  return gsad_message (
18922  credentials, "Internal error", __FUNCTION__, __LINE__,
18923  "An internal error occurred while saving an asset. "
18924  "It is unclear whether the asset has been saved or not. "
18925  "Diagnostics: Internal Error.",
18926  response_data);
18927  }
18928 
18929  html = response_from_entity (connection, credentials, params, entity,
18930  "Save Asset", response_data);
18931  free_entity (entity);
18932  g_free (response);
18933  return html;
18934 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmpf(), gsad_message(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ save_auth_gmp()

char* save_auth_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Save authentication settings.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
XML enveloped list of users and configuration.
Warning
authdn shall contain a single s, handle with care.
authdn shall contain a single s, handle with care.
authdn shall contain a single s, handle with care.

Definition at line 17674 of file gsad_gmp.c.

17676 {
17677  int ret;
17678  entity_t entity = NULL;
17679  char *html, *response = NULL, *truefalse;
17680  const char *method;
17681 
17682  if (params_value (params, "enable")
17683  && (strcmp (params_value (params, "enable"), "1") == 0))
17684  truefalse = "true";
17685  else
17686  truefalse = "false";
17687 
17688  method = params_value (params, "group");
17689  CHECK_VARIABLE_INVALID (method, "Save Authentication");
17690  if (!strcmp (method, "method:ldap_connect"))
17691  {
17692  const char *ldaphost, *authdn, *certificate;
17693  ldaphost = params_value (params, "ldaphost");
17694  authdn = params_value (params, "authdn");
17695  certificate = params_value (params, "certificate");
17696 
17697  CHECK_VARIABLE_INVALID (ldaphost, "Save Authentication");
17698  CHECK_VARIABLE_INVALID (authdn, "Save Authentication");
17699  if (params_given (params, "certificate") && strcmp (certificate, ""))
17700  {
17701  CHECK_VARIABLE_INVALID (certificate, "Save Authentication");
17703  ret =
17704  gmpf (connection, credentials, &response, &entity, response_data,
17705  "<modify_auth>"
17706  "<group name=\"%s\">" AUTH_CONF_SETTING ("enable", "%s")
17707  AUTH_CONF_SETTING ("ldaphost", "%s")
17708  AUTH_CONF_SETTING ("authdn", "%s")
17709  AUTH_CONF_SETTING ("cacert", "%s") "</group>"
17710  "</modify_auth>",
17711  method, truefalse, ldaphost, authdn, certificate);
17712  }
17713  else
17715  ret = gmpf (connection, credentials, &response, &entity, response_data,
17716  "<modify_auth>"
17717  "<group name=\"%s\">" AUTH_CONF_SETTING ("enable", "%s")
17718  AUTH_CONF_SETTING ("ldaphost", "%s")
17719  AUTH_CONF_SETTING ("authdn", "%s") "</group>"
17720  "</modify_auth>",
17721  method, truefalse, ldaphost, authdn);
17722  }
17723  else if (!strcmp (method, "method:radius_connect"))
17724  {
17725  const char *radiushost, *radiuskey;
17726  radiushost = params_value (params, "radiushost");
17727  radiuskey = params_value (params, "radiuskey");
17728 
17729  CHECK_VARIABLE_INVALID (radiushost, "Save Authentication");
17730  CHECK_VARIABLE_INVALID (radiuskey, "Save Authentication");
17732  ret = gmpf (connection, credentials, &response, &entity, response_data,
17733  "<modify_auth>"
17734  "<group name=\"%s\">" AUTH_CONF_SETTING ("enable", "%s")
17735  AUTH_CONF_SETTING ("radiushost", "%s")
17736  AUTH_CONF_SETTING ("radiuskey", "%s") "</group>"
17737  "</modify_auth>",
17738  method, truefalse, radiushost, radiuskey);
17739  }
17740  else
17741  return get_users (
17742  connection, credentials, params,
17743  GSAD_MESSAGE_INVALID_PARAM ("Save Authentication Configuration"),
17744  response_data);
17745 
17746  switch (ret)
17747  {
17748  case 0:
17749  case -1:
17750  break;
17751  case 1:
17752  cmd_response_data_set_status_code (response_data,
17753  MHD_HTTP_INTERNAL_SERVER_ERROR);
17754  return gsad_message (
17755  credentials, "Internal error", __FUNCTION__, __LINE__,
17756  "An internal error occurred while saving the auth settings. "
17757  "The settings were not saved. "
17758  "Diagnostics: Failure to send command to manager daemon.",
17759  response_data);
17760  case 2:
17761  cmd_response_data_set_status_code (response_data,
17762  MHD_HTTP_INTERNAL_SERVER_ERROR);
17763  return gsad_message (
17764  credentials, "Internal error", __FUNCTION__, __LINE__,
17765  "An internal error occurred while saving the auth settings. "
17766  "It is unclear whether the settings have been saved or not. "
17767  "Diagnostics: Failure to receive response from manager daemon.",
17768  response_data);
17769  default:
17770  cmd_response_data_set_status_code (response_data,
17771  MHD_HTTP_INTERNAL_SERVER_ERROR);
17772  return gsad_message (
17773  credentials, "Internal error", __FUNCTION__, __LINE__,
17774  "An internal error occurred while saving the auth settings. "
17775  "It is unclear whether the settings have been saved or not. "
17776  "Diagnostics: Internal Error.",
17777  response_data);
17778  }
17779 
17780  html =
17781  response_from_entity (connection, credentials, params, entity,
17782  "Save Authentication Configuration", response_data);
17783  free_entity (entity);
17784  g_free (response);
17785  return html;
17786 }
static char * get_users(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get all users, envelope the result.
Definition: gsad_gmp.c:16951
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
#define AUTH_CONF_SETTING(key, value)
Generate AUTH_CONF_SETTING element for save_auth_gmp.
Definition: gsad_gmp.c:17657
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
int params_given(params_t *params, const char *name)
Get whether a param was given at all.
Definition: gsad_base.c:189
#define GSAD_MESSAGE_INVALID_PARAM(op)
Answer for invalid input.
Definition: gsad_gmp.c:83
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References AUTH_CONF_SETTING, CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), get_users(), gmpf(), gsad_message(), GSAD_MESSAGE_INVALID_PARAM, params_given(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ save_config_family_gmp()

char* save_config_family_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Get details of an NVT for a config, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 8880 of file gsad_gmp.c.

8883 {
8884  char *ret;
8885  const char *config_id, *family;
8886  params_t *nvts;
8887 
8888  config_id = params_value (params, "config_id");
8889  family = params_value (params, "family");
8890 
8891  CHECK_VARIABLE_INVALID (config_id, "Save Config Family")
8892  CHECK_VARIABLE_INVALID (family, "Save Config Family")
8893 
8894  /* Set the NVT selection. */
8895 
8896  if (gvm_connection_sendf (connection,
8897  "<modify_config config_id=\"%s\">"
8898  "<nvt_selection>"
8899  "<family>%s</family>",
8900  config_id, family)
8901  == -1)
8902  {
8903  cmd_response_data_set_status_code (response_data,
8904  MHD_HTTP_INTERNAL_SERVER_ERROR);
8905  return gsad_message (
8906  credentials, "Internal error", __FUNCTION__, __LINE__,
8907  "An internal error occurred while saving a config. "
8908  "It is unclear whether the entire config has been saved. "
8909  "Diagnostics: Failure to send command to manager daemon.",
8910  response_data);
8911  }
8912 
8913  nvts = params_values (params, "nvt:");
8914  if (nvts)
8915  {
8916  params_iterator_t iter;
8917  char *name;
8918  param_t *param;
8919 
8920  params_iterator_init (&iter, nvts);
8921  while (params_iterator_next (&iter, &name, &param))
8922  if (gvm_connection_sendf (connection, "<nvt oid=\"%s\"/>", name) == -1)
8923  {
8924  cmd_response_data_set_status_code (response_data,
8925  MHD_HTTP_INTERNAL_SERVER_ERROR);
8926  return gsad_message (
8927  credentials, "Internal error", __FUNCTION__, __LINE__,
8928  "An internal error occurred while saving a config. "
8929  "It is unclear whether the entire config has been saved. "
8930  "Diagnostics: Failure to send command to manager daemon.",
8931  response_data);
8932  }
8933  }
8934 
8935  if (gvm_connection_sendf (connection, "</nvt_selection>"
8936  "</modify_config>")
8937  == -1)
8938  {
8939  cmd_response_data_set_status_code (response_data,
8940  MHD_HTTP_INTERNAL_SERVER_ERROR);
8941  return gsad_message (
8942  credentials, "Internal error", __FUNCTION__, __LINE__,
8943  "An internal error occurred while saving a config. "
8944  "It is unclear whether the entire config has been saved. "
8945  "Diagnostics: Failure to send command to manager daemon.",
8946  response_data);
8947  }
8948 
8949  ret =
8950  check_modify_config (connection, credentials, params, "get_config_family",
8951  "edit_config_family", NULL, response_data);
8952 
8953  return ret;
8954 }
params_t * params_values(params_t *params, const char *name)
Get values of param.
Definition: gsad_base.c:287
Structure of credential related information.
#define params_iterator_t
Definition: gsad_params.h:94
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
static char * check_modify_config(gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *next, const char *fail_next, int *success, cmd_response_data_t *response_data)
Check a modify_config response.
Definition: gsad_gmp.c:570
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
Request parameter.
Definition: gsad_params.h:38
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
gboolean params_iterator_next(params_iterator_t *iterator, char **name, param_t **param)
Increment a params iterator.
Definition: gsad_base.c:394
#define params_iterator_init
Definition: gsad_params.h:96
#define params_t
Definition: gsad_params.h:31
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References check_modify_config(), CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gsad_message(), params_iterator_init, params_iterator_next(), params_iterator_t, params_t, params_value(), and params_values().

Here is the call graph for this function:

◆ save_config_gmp()

char* save_config_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Save details of an NVT for a config and return the next page.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Following page.

Definition at line 8453 of file gsad_gmp.c.

8455 {
8456  int gmp_ret;
8457  char *ret, *osp_ret;
8458  params_t *preferences, *selects, *trends;
8459  const char *config_id, *name, *comment, *scanner_id;
8460  int success;
8461 
8462  config_id = params_value (params, "config_id");
8463  name = params_value (params, "name");
8464  comment = params_value (params, "comment");
8465  scanner_id = params_value (params, "scanner_id");
8466 
8467  CHECK_VARIABLE_INVALID (config_id, "Save Config");
8468  CHECK_VARIABLE_INVALID (name, "Save Config");
8469  CHECK_VARIABLE_INVALID (comment, "Save Config");
8470 
8471  /* Save name and comment. */
8472 
8473  if (scanner_id)
8474  gmp_ret = gvm_connection_sendf_xml (connection,
8475  "<modify_config config_id=\"%s\">"
8476  "<name>%s</name>"
8477  "<comment>%s</comment>"
8478  "<scanner>%s</scanner>"
8479  "</modify_config>",
8480  params_value (params, "config_id"),
8481  name, comment, scanner_id);
8482  else
8483  gmp_ret = gvm_connection_sendf_xml (connection,
8484  "<modify_config config_id=\"%s\">"
8485  "<name>%s</name>"
8486  "<comment>%s</comment>"
8487  "</modify_config>",
8488  params_value (params, "config_id"),
8489  name, comment);
8490 
8491  if (gmp_ret == -1)
8492  {
8493  cmd_response_data_set_status_code (response_data,
8494  MHD_HTTP_INTERNAL_SERVER_ERROR);
8495  return gsad_message (
8496  credentials, "Internal error", __FUNCTION__, __LINE__,
8497  "An internal error occurred while saving a config. "
8498  "It is unclear whether the entire config has been saved. "
8499  "Diagnostics: Failure to send command to manager daemon.",
8500  response_data);
8501  }
8502 
8503  ret = check_modify_config (connection, credentials, params, "get_config",
8504  "edit_config", &success, response_data);
8505  if (success == 0)
8506  {
8507  return ret;
8508  }
8509 
8510  /* Save preferences. */
8511 
8512  preferences = params_values (params, "preference:");
8513  if (preferences)
8514  {
8515  params_iterator_t iter;
8516  char *param_name;
8517  param_t *param;
8518 
8519  params_iterator_init (&iter, preferences);
8520  while (params_iterator_next (&iter, &param_name, &param))
8521  {
8522  gchar *value;
8523 
8524  value = param->value_size ? g_base64_encode ((guchar *) param->value,
8525  param->value_size)
8526  : g_strdup ("");
8527 
8528  if (gvm_connection_sendf (connection,
8529  "<modify_config config_id=\"%s\">"
8530  "<preference>"
8531  "<name>%s</name>"
8532  "<value>%s</value>"
8533  "</preference>"
8534  "</modify_config>",
8535  params_value (params, "config_id"),
8536  param_name, value)
8537  == -1)
8538  {
8539  g_free (value);
8541  response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
8542  return gsad_message (
8543  credentials, "Internal error", __FUNCTION__, __LINE__,
8544  "An internal error occurred while saving a config. "
8545  "It is unclear whether the entire config has been saved. "
8546  "Diagnostics: Failure to send command to manager daemon.",
8547  response_data);
8548  }
8549  g_free (value);
8550  g_free (ret);
8551 
8552  ret =
8553  check_modify_config (connection, credentials, params, "get_config",
8554  "edit_config", &success, response_data);
8555  if (success == 0)
8556  {
8557  return ret;
8558  }
8559  }
8560  }
8561 
8562  /* OSP config file preference. */
8563  osp_ret = save_osp_prefs (connection, credentials, params, "get_config",
8564  "edit_config", &success, response_data);
8565  if (osp_ret)
8566  {
8567  g_free (ret);
8568  ret = osp_ret;
8569  }
8570 
8571  if (success == 0)
8572  {
8573  if (osp_ret == NULL)
8574  {
8575  cmd_response_data_set_status_code (response_data,
8576  MHD_HTTP_INTERNAL_SERVER_ERROR);
8577  return gsad_message (
8578  credentials, "Internal error", __FUNCTION__, __LINE__,
8579  "An internal error occurred while saving a config. "
8580  "It is unclear whether the entire config has been saved. "
8581  "Diagnostics: save_osp_prefs returned NULL unexpectedly.",
8582  response_data);
8583  }
8584  return ret;
8585  }
8586 
8587  /* Update the config. */
8588 
8589  trends = params_values (params, "trend:");
8590  selects = params_values (params, "select:");
8591 
8592  if (trends || selects || params_value (params, "trend"))
8593  {
8594  if (gvm_connection_sendf (
8595  connection,
8596  "<modify_config config_id=\"%s\">"
8597  "<family_selection>"
8598  "<growing>%i</growing>",
8599  params_value (params, "config_id"),
8600  trends && params_value (params, "trend")
8601  && strcmp (params_value (params, "trend"), "0"))
8602  == -1)
8603  {
8604  cmd_response_data_set_status_code (response_data,
8605  MHD_HTTP_INTERNAL_SERVER_ERROR);
8606  return gsad_message (
8607  credentials, "Internal error", __FUNCTION__, __LINE__,
8608  "An internal error occurred while saving a config. "
8609  "It is unclear whether the entire config has been saved. "
8610  "Diagnostics: Failure to send command to manager daemon.",
8611  response_data);
8612  }
8613 
8614  if (selects)
8615  {
8616  gchar *family;
8617  params_iterator_t iter;
8618  param_t *param;
8619 
8620  params_iterator_init (&iter, selects);
8621  while (params_iterator_next (&iter, &family, &param))
8622  if (gvm_connection_sendf (connection,
8623  "<family>"
8624  "<name>%s</name>"
8625  "<all>1</all>"
8626  "<growing>%i</growing>"
8627  "</family>",
8628  family,
8629  trends && member1 (trends, family))
8630  == -1)
8631  {
8633  response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
8634  return gsad_message (
8635  credentials, "Internal error", __FUNCTION__, __LINE__,
8636  "An internal error occurred while saving a config. "
8637  "It is unclear whether the entire config has been saved. "
8638  "Diagnostics: Failure to send command to manager daemon.",
8639  response_data);
8640  }
8641  }
8642 
8643  if (trends)
8644  {
8645  gchar *family;
8646  params_iterator_t iter;
8647  param_t *param;
8648 
8649  params_iterator_init (&iter, trends);
8650  while (params_iterator_next (&iter, &family, &param))
8651  {
8652  if (param->value_size == 0)
8653  continue;
8654  if (param->value[0] == '0')
8655  continue;
8656  if (selects && member (selects, family))
8657  continue;
8658  if (gvm_connection_sendf (connection,
8659  "<family>"
8660  "<name>%s</name>"
8661  "<all>0</all>"
8662  "<growing>1</growing>"
8663  "</family>",
8664  family)
8665  == -1)
8666  {
8668  response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
8669  return gsad_message (
8670  credentials, "Internal error", __FUNCTION__, __LINE__,
8671  "An internal error occurred while saving a config. "
8672  "It is unclear whether the entire config has been saved. "
8673  "Diagnostics: Failure to send command to manager daemon.",
8674  response_data);
8675  }
8676  }
8677  }
8678 
8679  if (gvm_connection_sendf (connection, "</family_selection>"
8680  "</modify_config>")
8681  == -1)
8682  {
8683  cmd_response_data_set_status_code (response_data,
8684  MHD_HTTP_INTERNAL_SERVER_ERROR);
8685  return gsad_message (
8686  credentials, "Internal error", __FUNCTION__, __LINE__,
8687  "An internal error occurred while saving a config. "
8688  "It is unclear whether the entire config has been saved. "
8689  "Diagnostics: Failure to send command to manager daemon.",
8690  response_data);
8691  }
8692 
8693  g_free (ret);
8694  ret = check_modify_config (connection, credentials, params, "get_config",
8695  "edit_config", NULL, response_data);
8696  }
8697  return ret;
8698 }
params_t * params_values(params_t *params, const char *name)
Get values of param.
Definition: gsad_base.c:287
gchar * value
Definition: gsad_params.h:40
Structure of credential related information.
#define params_iterator_t
Definition: gsad_params.h:94
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
static char * check_modify_config(gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *next, const char *fail_next, int *success, cmd_response_data_t *response_data)
Check a modify_config response.
Definition: gsad_gmp.c:570
static char * save_osp_prefs(gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *next, const char *fail_next, int *success, cmd_response_data_t *response_data)
Save OSP file preferences.
Definition: gsad_gmp.c:8386
int value_size
Definition: gsad_params.h:46
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
Request parameter.
Definition: gsad_params.h:38
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
gboolean params_iterator_next(params_iterator_t *iterator, char **name, param_t **param)
Increment a params iterator.
Definition: gsad_base.c:394
#define params_iterator_init
Definition: gsad_params.h:96
static int member(params_t *params, const char *string)
Look for a param with name equal to a given string.
Definition: gsad_gmp.c:520
#define params_t
Definition: gsad_params.h:31
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
int member1(params_t *params, const char *string)
Look for param with value 1 and name equal to given string.
Definition: gsad_gmp.c:542

References check_modify_config(), CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gsad_message(), member(), member1(), params_iterator_init, params_iterator_next(), params_iterator_t, params_t, params_value(), params_values(), save_osp_prefs(), param::value, and param::value_size.

Here is the call graph for this function:

◆ save_config_nvt_gmp()

char* save_config_nvt_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Save NVT prefs for a config, get NVT details, envelope result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 9142 of file gsad_gmp.c.

9144 {
9145  params_t *preferences;
9146  const char *config_id;
9147  int success;
9148  char *modify_config_ret;
9149 
9150  modify_config_ret = NULL;
9151  config_id = params_value (params, "config_id");
9152 
9153  preferences = params_values (params, "preference:");
9154  if (preferences)
9155  {
9156  param_t *preference;
9157  gchar *preference_name;
9158  params_iterator_t iter;
9159 
9160  /* Save preferences. */
9161 
9162  params_iterator_init (&iter, preferences);
9163  while (params_iterator_next (&iter, &preference_name, &preference))
9164  {
9165  int type_start, type_end, count, ret, is_timeout = 0;
9166  gchar *value;
9167 
9168  g_free (modify_config_ret);
9169  modify_config_ret = NULL;
9170 
9171  /* Passwords and files have checkboxes to control whether they
9172  * must be reset. This works around the need for the Manager to
9173  * send the actual password or show the actual file. */
9174 
9175  /* LDAPsearch[entry]:Timeout value */
9176  count = sscanf (preference_name, "%*[^[][%n%*[^]]%n]:", &type_start,
9177  &type_end);
9178  if (count == 0 && type_start > 0 && type_end > 0)
9179  {
9180  if (strncmp (preference_name + type_start, "password",
9181  type_end - type_start)
9182  == 0)
9183  {
9184  int found = 0;
9185  params_t *passwords;
9186 
9187  passwords = params_values (params, "password:");
9188  if (passwords)
9189  {
9190  param_t *password;
9191  gchar *password_name;
9192  params_iterator_t password_params;
9193 
9194  params_iterator_init (&password_params, passwords);
9195  while (params_iterator_next (&password_params,
9196  &password_name, &password))
9197  if (strcmp (password_name, preference_name) == 0)
9198  {
9199  found = 1;
9200  break;
9201  }
9202  }
9203  if (found == 0)
9204  /* Skip modifying the password preference. */
9205  continue;
9206  }
9207  else if (strncmp (preference_name + type_start, "file",
9208  type_end - type_start)
9209  == 0)
9210  {
9211  int found = 0;
9212  params_t *files;
9213 
9214  files = params_values (params, "file:");
9215  if (files)
9216  {
9217  param_t *file;
9218  gchar *file_name;
9219  params_iterator_t file_params;
9220 
9221  params_iterator_init (&file_params, files);
9222  while (
9223  params_iterator_next (&file_params, &file_name, &file))
9224  if (strcmp (file_name, preference_name) == 0)
9225  {
9226  found = 1;
9227  break;
9228  }
9229  }
9230  if (found == 0)
9231  /* Skip modifying the file preference. */
9232  continue;
9233  }
9234  else if (strncmp (preference_name + type_start, "scanner",
9235  type_end - type_start)
9236  == 0)
9237  {
9238  /* Presume it's the timeout. */
9239  is_timeout = 1;
9240  }
9241  }
9242 
9243  value = preference->value_size
9244  ? g_base64_encode ((guchar *) preference->value,
9245  preference->value_size)
9246  : g_strdup ("");
9247 
9248  if (is_timeout)
9249  {
9250  const char *timeout;
9251  gchar *preference_name_escaped;
9252 
9253  timeout = params_value (params, "timeout");
9254 
9255  if (timeout == NULL)
9256  {
9257  g_free (value);
9258  cmd_response_data_set_status_code (response_data,
9259  MHD_HTTP_BAD_REQUEST);
9260  return gsad_message (
9261  credentials, "Internal error", __FUNCTION__, __LINE__,
9262  "An internal error occurred while saving a config. "
9263  "It is unclear whether the entire config has been saved. "
9264  "Diagnostics: Required parameter was NULL.",
9265  response_data);
9266  }
9267 
9268  preference_name_escaped =
9269  g_markup_escape_text (preference_name, -1);
9270 
9271  if (strcmp (timeout, "0") == 0)
9272  /* Leave out the value to clear the preference. */
9273  ret = gvm_connection_sendf (connection,
9274  "<modify_config"
9275  " config_id=\"%s\">"
9276  "<preference>"
9277  "<name>%s</name>"
9278  "</preference>"
9279  "</modify_config>",
9280  config_id, preference_name_escaped);
9281  else
9282  ret = gvm_connection_sendf (connection,
9283  "<modify_config"
9284  " config_id=\"%s\">"
9285  "<preference>"
9286  "<name>%s</name>"
9287  "<value>%s</value>"
9288  "</preference>"
9289  "</modify_config>",
9290  config_id, preference_name_escaped,
9291  value);
9292 
9293  g_free (preference_name_escaped);
9294  }
9295  else
9296  {
9297  gchar *preference_name_escaped;
9298  preference_name_escaped =
9299  g_markup_escape_text (preference_name, -1);
9300  ret =
9301  gvm_connection_sendf (connection,
9302  "<modify_config"
9303  " config_id=\"%s\">"
9304  "<preference>"
9305  "<nvt oid=\"%s\"/>"
9306  "<name>%s</name>"
9307  "<value>%s</value>"
9308  "</preference>"
9309  "</modify_config>",
9310  config_id, params_value (params, "oid"),
9311  preference_name_escaped, value);
9312  g_free (preference_name_escaped);
9313  }
9314 
9315  if (ret == -1)
9316  {
9317  g_free (value);
9319  response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
9320  return gsad_message (
9321  credentials, "Internal error", __FUNCTION__, __LINE__,
9322  "An internal error occurred while saving a config. "
9323  "It is unclear whether the entire config has been saved. "
9324  "Diagnostics: Failure to send command to manager daemon.",
9325  response_data);
9326  }
9327  g_free (value);
9328 
9329  modify_config_ret = check_modify_config (
9330  connection, credentials, params, "get_config_nvt",
9331  "edit_config_nvt", &success, response_data);
9332  if (success == 0)
9333  {
9334  return modify_config_ret;
9335  }
9336  }
9337  }
9338 
9339  /* Create a generic success message in case modify_config_ret is NULL,
9340  * which could happen if the last preference is a password and skipped.
9341  * This assumes that messages are returned earlier in case of errors. */
9342  modify_config_ret = action_result (
9343  connection, credentials, params, response_data, "Modify Config",
9344  "All NVT preferences modified successfully", NULL, NULL);
9345 
9346  return modify_config_ret;
9347 }
params_t * params_values(params_t *params, const char *name)
Get values of param.
Definition: gsad_base.c:287
gchar * value
Definition: gsad_params.h:40
Structure of credential related information.
#define params_iterator_t
Definition: gsad_params.h:94
static char * check_modify_config(gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *next, const char *fail_next, int *success, cmd_response_data_t *response_data)
Check a modify_config response.
Definition: gsad_gmp.c:570
int value_size
Definition: gsad_params.h:46
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
Request parameter.
Definition: gsad_params.h:38
static gchar * action_result(gvm_connection_t *, credentials_t *, params_t *, cmd_response_data_t *, const char *action, const char *message, const char *details, const char *id)
Generate a enveloped GMP XML containing an action result.
Definition: gsad_gmp.c:965
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
gboolean params_iterator_next(params_iterator_t *iterator, char **name, param_t **param)
Increment a params iterator.
Definition: gsad_base.c:394
#define params_iterator_init
Definition: gsad_params.h:96
#define params_t
Definition: gsad_params.h:31
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References action_result(), check_modify_config(), cmd_response_data_set_status_code(), gsad_message(), params_iterator_init, params_iterator_next(), params_iterator_t, params_t, params_value(), params_values(), param::value, and param::value_size.

Here is the call graph for this function:

◆ save_container_task_gmp()

char* save_container_task_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Save container task, get next page, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 3059 of file gsad_gmp.c.

3062 {
3063  gchar *format, *response, *html;
3064  const char *comment, *name, *task_id;
3065  const char *in_assets, *auto_delete, *auto_delete_data;
3066  int ret;
3067  entity_t entity;
3068 
3069  comment = params_value (params, "comment");
3070  in_assets = params_value (params, "in_assets");
3071  name = params_value (params, "name");
3072  task_id = params_value (params, "task_id");
3073  auto_delete = params_value (params, "auto_delete");
3074  auto_delete_data = params_value (params, "auto_delete_data");
3075  CHECK_VARIABLE_INVALID (name, "Save Task")
3076  CHECK_VARIABLE_INVALID (comment, "Save Task")
3077  CHECK_VARIABLE_INVALID (task_id, "Save Task")
3078  CHECK_VARIABLE_INVALID (in_assets, "Save Task")
3079  CHECK_VARIABLE_INVALID (auto_delete, "Save Task");
3080  CHECK_VARIABLE_INVALID (auto_delete_data, "Save Task");
3081 
3082  format = g_strdup_printf ("<modify_task task_id=\"%%s\">"
3083  "<name>%%s</name>"
3084  "<comment>%%s</comment>"
3085  "<preferences>"
3086  "<preference>"
3087  "<scanner_name>in_assets</scanner_name>"
3088  "<value>%%s</value>"
3089  "</preference>"
3090  "<preference>"
3091  "<scanner_name>auto_delete</scanner_name>"
3092  "<value>%%s</value>"
3093  "</preference>"
3094  "<preference>"
3095  "<scanner_name>auto_delete_data</scanner_name>"
3096  "<value>%%s</value>"
3097  "</preference>"
3098  "</preferences>"
3099  "</modify_task>");
3100 
3101  response = NULL;
3102  entity = NULL;
3103  ret =
3104  gmpf (connection, credentials, &response, &entity, response_data, format,
3105  task_id, name, comment, strcmp (in_assets, "0") ? "yes" : "no",
3106  auto_delete, auto_delete_data);
3107  g_free (format);
3108  switch (ret)
3109  {
3110  case 0:
3111  case -1:
3112  break;
3113  case 1:
3114  cmd_response_data_set_status_code (response_data,
3115  MHD_HTTP_INTERNAL_SERVER_ERROR);
3116  return gsad_message (
3117  credentials, "Internal error", __FUNCTION__, __LINE__,
3118  "An internal error occurred while saving a task. "
3119  "No new task was created. "
3120  "Diagnostics: Failure to send command to manager daemon.",
3121  response_data);
3122  case 2:
3123  cmd_response_data_set_status_code (response_data,
3124  MHD_HTTP_INTERNAL_SERVER_ERROR);
3125  return gsad_message (
3126  credentials, "Internal error", __FUNCTION__, __LINE__,
3127  "An internal error occurred while saving a task. "
3128  "It is unclear whether the task has been created or not. "
3129  "Diagnostics: Failure to receive response from manager daemon.",
3130  response_data);
3131  default:
3132  cmd_response_data_set_status_code (response_data,
3133  MHD_HTTP_INTERNAL_SERVER_ERROR);
3134  return gsad_message (
3135  credentials, "Internal error", __FUNCTION__, __LINE__,
3136  "An internal error occurred while saving a task. "
3137  "It is unclear whether the task has been created or not. "
3138  "Diagnostics: Internal Error.",
3139  response_data);
3140  }
3141 
3142  html = response_from_entity (connection, credentials, params, entity,
3143  "Save Container Task", response_data);
3144  free_entity (entity);
3145  g_free (response);
3146  return html;
3147 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmpf(), gsad_message(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ save_credential_gmp()

char* save_credential_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Save credential, get next page, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 4197 of file gsad_gmp.c.

4199 {
4200  int ret, change_password, change_ssh_passphrase;
4201  int change_community, change_privacy_password;
4202  gchar *html, *response;
4203  const char *credential_id, *public_key;
4204  const char *name, *comment, *login, *password, *passphrase, *type;
4205  const char *private_key, *certificate, *community, *privacy_password;
4206  const char *auth_algorithm, *privacy_algorithm, *allow_insecure;
4207  GString *command;
4208  entity_t entity;
4209 
4210  credential_id = params_value (params, "credential_id");
4211  type = params_value (params, "credential_type");
4212  name = params_value (params, "name");
4213  comment = params_value (params, "comment");
4214  login = params_value (params, "credential_login");
4215  password = params_value (params, "password");
4216  passphrase = params_value (params, "passphrase");
4217  private_key = params_value (params, "private_key");
4218  certificate = params_value (params, "certificate");
4219  community = params_value (params, "community");
4220  privacy_password = params_value (params, "privacy_password");
4221  auth_algorithm = params_value (params, "auth_algorithm");
4222  privacy_algorithm = params_value (params, "privacy_algorithm");
4223  allow_insecure = params_value (params, "allow_insecure");
4224  public_key = params_value (params, "public_key");
4225 
4226  CHECK_VARIABLE_INVALID (credential_id, "Save Credential");
4227  CHECK_VARIABLE_INVALID (name, "Save Credential");
4228  CHECK_VARIABLE_INVALID (comment, "Save Credential");
4229  CHECK_VARIABLE_INVALID (allow_insecure, "Save Credential");
4230  CHECK_VARIABLE_INVALID (type, "Save Credential");
4231 
4232  if (str_equal (type, "cc"))
4233  {
4234  if (params_given (params, "certificate"))
4235  CHECK_VARIABLE_INVALID (certificate, "Save Credential");
4236 
4237  if (params_given (params, "private_key"))
4238  CHECK_VARIABLE_INVALID (private_key, "Save Credential");
4239 
4240  if (params_given (params, "change_passphrase"))
4241  CHECK_VARIABLE_INVALID (passphrase, "Save Credential");
4242  }
4243  else if (str_equal (type, "snmp"))
4244  {
4245  if (params_given (params, "auth_algorithm"))
4246  CHECK_VARIABLE_INVALID (auth_algorithm, "Save Credential");
4247 
4248  if (params_given (params, "privacy_algorithm"))
4249  CHECK_VARIABLE_INVALID (privacy_algorithm, "Save Credential");
4250 
4251  if (params_given (params, "change_privacy_password"))
4252  CHECK_VARIABLE_INVALID (privacy_password, "Save Credential");
4253 
4254  if (params_given (params, "change_community"))
4255  CHECK_VARIABLE_INVALID (community, "Save Credential");
4256  }
4257  else if (str_equal (type, "up") | str_equal (type, "pw"))
4258  {
4259  if (params_given (params, "change_password"))
4260  CHECK_VARIABLE_INVALID (password, "Save Credential");
4261  }
4262  else if (str_equal (type, "smime"))
4263  {
4264  if (params_given (params, "certificate"))
4265  CHECK_VARIABLE_INVALID (certificate, "Save Credential");
4266  }
4267  else if (str_equal (type, "smime"))
4268  {
4269  if (params_given (params, "public_key"))
4270  CHECK_VARIABLE_INVALID (public_key, "Save Credential");
4271  }
4272 
4273  if (params_given (params, "login"))
4274  CHECK_VARIABLE_INVALID (login, "Save Credential");
4275 
4276  change_password = params_value_bool (params, "change_password");
4277 
4278  /* Prepare command */
4279  command = g_string_new ("");
4280 
4281  xml_string_append (command,
4282  "<modify_credential credential_id=\"%s\">"
4283  "<name>%s</name>"
4284  "<comment>%s</comment>"
4285  "<allow_insecure>%s</allow_insecure>",
4286  credential_id, name, comment, allow_insecure);
4287 
4288  if (str_equal (type, "snmp"))
4289  {
4290  change_community = params_value_bool (params, "change_community");
4291  change_privacy_password =
4292  params_value_bool (params, "change_privacy_password");
4293 
4294  if (auth_algorithm)
4295  xml_string_append (command, "<auth_algorithm>%s</auth_algorithm>",
4296  auth_algorithm);
4297 
4298  if (change_community)
4299  xml_string_append (command, "<community>%s</community>", community);
4300 
4301  if (privacy_algorithm || change_privacy_password)
4302  {
4303  xml_string_append (command, "<privacy>");
4304  if (privacy_algorithm)
4305  {
4306  xml_string_append (command, "<algorithm>%s</algorithm>",
4307  privacy_algorithm);
4308  }
4309  if (change_privacy_password && privacy_password)
4310  {
4311  xml_string_append (command, "<password>%s</password>",
4312  privacy_password);
4313  }
4314 
4315  xml_string_append (command, "</privacy>");
4316  }
4317  }
4318  else if (str_equal (type, "cc"))
4319  {
4320  if ((certificate && strcmp (certificate, "")))
4321  {
4322  xml_string_append (command, "<certificate>%s</certificate>",
4323  certificate);
4324  }
4325 
4326  if ((private_key && strcmp (private_key, "")))
4327  {
4328  xml_string_append (command, "<key>");
4329  xml_string_append (command, "<private>%s</private>", private_key);
4330  xml_string_append (command, "</key>");
4331  }
4332  }
4333  else if (str_equal (type, "usk"))
4334  {
4335  change_ssh_passphrase = params_value_bool (params, "change_passphrase");
4336 
4337  if ((private_key && strcmp (private_key, "")) || change_ssh_passphrase)
4338  {
4339  xml_string_append (command, "<key>");
4340  if (change_ssh_passphrase)
4341  xml_string_append (command, "<phrase>%s</phrase>", passphrase);
4342  if (private_key)
4343  xml_string_append (command, "<private>%s</private>", private_key);
4344  xml_string_append (command, "</key>");
4345  }
4346  }
4347  else if (str_equal (type, "up") | str_equal (type, "pw"))
4348  {
4349  if (change_password)
4350  xml_string_append (command, "<password>%s</password>", password);
4351  }
4352  else if (str_equal (type, "smime"))
4353  {
4354  if ((certificate && strcmp (certificate, "")))
4355  {
4356  xml_string_append (command, "<certificate>%s</certificate>",
4357  certificate);
4358  }
4359  }
4360  else if (str_equal (type, "pgp"))
4361  {
4362  if ((public_key && strcmp (public_key, "")))
4363  {
4364  xml_string_append (command, "<key>");
4365  xml_string_append (command, "<public>%s</public>", public_key);
4366  xml_string_append (command, "</key>");
4367  }
4368  }
4369 
4370  if (login && strcmp (login, ""))
4371  xml_string_append (command, "<login>%s</login>", login);
4372 
4373  xml_string_append (command, "</modify_credential>");
4374 
4375  /* Modify the credential. */
4376  response = NULL;
4377  entity = NULL;
4378  ret = gmp (connection, credentials, &response, &entity, response_data,
4379  command->str);
4380  g_string_free (command, TRUE);
4381 
4382  switch (ret)
4383  {
4384  case 0:
4385  break;
4386  case -1:
4387  /* 'gmp' set response. */
4388  return response;
4389  case 1:
4390  cmd_response_data_set_status_code (response_data,
4391  MHD_HTTP_INTERNAL_SERVER_ERROR);
4392  return gsad_message (
4393  credentials, "Internal error", __FUNCTION__, __LINE__,
4394  "An internal error occurred while saving a Credential. "
4395  "The Credential was not saved. "
4396  "Diagnostics: Failure to send command to manager daemon.",
4397  response_data);
4398  case 2:
4399  cmd_response_data_set_status_code (response_data,
4400  MHD_HTTP_INTERNAL_SERVER_ERROR);
4401  return gsad_message (
4402  credentials, "Internal error", __FUNCTION__, __LINE__,
4403  "An internal error occurred while saving a Credential. "
4404  "It is unclear whether the Credential has been saved or not. "
4405  "Diagnostics: Failure to receive response from manager daemon.",
4406  response_data);
4407  default:
4408  cmd_response_data_set_status_code (response_data,
4409  MHD_HTTP_INTERNAL_SERVER_ERROR);
4410  return gsad_message (
4411  credentials, "Internal error", __FUNCTION__, __LINE__,
4412  "An internal error occurred while saving a Credential. "
4413  "It is unclear whether the Credential has been saved or not. "
4414  "Diagnostics: Internal Error.",
4415  response_data);
4416  }
4417 
4418  html = response_from_entity (connection, credentials, params, entity,
4419  "Save Credential", response_data);
4420  free_entity (entity);
4421  g_free (response);
4422  return html;
4423 }
Structure of credential related information.
gboolean str_equal(const gchar *str1, const gchar *str2)
Check if two strings are equal.
Definition: utils.c:35
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
int params_given(params_t *params, const char *name)
Get whether a param was given at all.
Definition: gsad_base.c:189
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
int login(http_connection_t *con, params_t *params, cmd_response_data_t *response_data, const char *client_address)
Login and create a session.
Definition: gsad_gmp.c:19384
gboolean params_value_bool(params_t *params, const char *name)
Get boolean value of param.
Definition: gsad_base.c:221
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmp(), gsad_message(), login(), params_given(), params_value(), params_value_bool(), response_from_entity(), and str_equal().

Here is the call graph for this function:

◆ save_filter_gmp()

char* save_filter_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Modify a filter, get all filters, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 16641 of file gsad_gmp.c.

16643 {
16644  entity_t entity;
16645  gchar *html, *response;
16646  const char *filter_id, *name, *comment, *term, *type;
16647 
16648  filter_id = params_value (params, "filter_id");
16649  name = params_value (params, "name");
16650  comment = params_value (params, "comment");
16651  term = params_value (params, "term");
16652  type = params_value (params, "optional_resource_type");
16653 
16654  CHECK_VARIABLE_INVALID (filter_id, "Save Filter");
16655  CHECK_VARIABLE_INVALID (name, "Save Filter");
16656  CHECK_VARIABLE_INVALID (comment, "Save Filter");
16657  CHECK_VARIABLE_INVALID (term, "Save Filter");
16658  CHECK_VARIABLE_INVALID (type, "Save Filter");
16659 
16660  {
16661  int ret;
16662 
16663  /* Modify the filter. */
16664 
16665  ret = gvm_connection_sendf_xml (connection,
16666  "<modify_filter filter_id=\"%s\">"
16667  "<name>%s</name>"
16668  "<comment>%s</comment>"
16669  "<term>%s</term>"
16670  "<type>%s</type>"
16671  "</modify_filter>",
16672  filter_id, name, comment, term, type);
16673 
16674  if (ret == -1)
16675  {
16676  cmd_response_data_set_status_code (response_data,
16677  MHD_HTTP_INTERNAL_SERVER_ERROR);
16678  return gsad_message (
16679  credentials, "Internal error", __FUNCTION__, __LINE__,
16680  "An internal error occurred while modifying a filter. "
16681  "The filter was not modified. "
16682  "Diagnostics: Failure to send command to manager daemon.",
16683  response_data);
16684  }
16685 
16686  entity = NULL;
16687  if (read_entity_and_text_c (connection, &entity, &response))
16688  {
16689  cmd_response_data_set_status_code (response_data,
16690  MHD_HTTP_INTERNAL_SERVER_ERROR);
16691  return gsad_message (
16692  credentials, "Internal error", __FUNCTION__, __LINE__,
16693  "An internal error occurred while modifying a filter. "
16694  "It is unclear whether the filter has been modified or not. "
16695  "Diagnostics: Failure to receive response from manager daemon.",
16696  response_data);
16697  }
16698  }
16699 
16700  /* Pass response to handler of following page. */
16701 
16702  html = response_from_entity (connection, credentials, params, entity,
16703  "Save Filter", response_data);
16704 
16705  free_entity (entity);
16706  g_free (response);
16707  return html;
16708 }
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gsad_message(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ save_group_gmp()

char* save_group_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Modify a group, return the next page.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 14290 of file gsad_gmp.c.

14292 {
14293  int ret;
14294  gchar *html, *response;
14295  const char *group_id, *name, *comment, *users;
14296  entity_t entity;
14297 
14298  group_id = params_value (params, "group_id");
14299  name = params_value (params, "name");
14300  comment = params_value (params, "comment");
14301  users = params_value (params, "users");
14302 
14303  CHECK_VARIABLE_INVALID (group_id, "Save Group");
14304  CHECK_VARIABLE_INVALID (name, "Save Group");
14305  CHECK_VARIABLE_INVALID (comment, "Save Group");
14306  CHECK_VARIABLE_INVALID (users, "Save Group");
14307 
14308  /* Modify the Group. */
14309 
14310  response = NULL;
14311  entity = NULL;
14312  ret = gmpf (connection, credentials, &response, &entity, response_data,
14313  "<modify_group group_id=\"%s\">"
14314  "<name>%s</name>"
14315  "<comment>%s</comment>"
14316  "<users>%s</users>"
14317  "</modify_group>",
14318  group_id, name, comment, users);
14319 
14320  switch (ret)
14321  {
14322  case 0:
14323  case -1:
14324  break;
14325  case 1:
14326  cmd_response_data_set_status_code (response_data,
14327  MHD_HTTP_INTERNAL_SERVER_ERROR);
14328  return gsad_message (
14329  credentials, "Internal error", __FUNCTION__, __LINE__,
14330  "An internal error occurred while saving a group. "
14331  "The group was not saved. "
14332  "Diagnostics: Failure to send command to manager daemon.",
14333  response_data);
14334  case 2:
14335  cmd_response_data_set_status_code (response_data,
14336  MHD_HTTP_INTERNAL_SERVER_ERROR);
14337  return gsad_message (
14338  credentials, "Internal error", __FUNCTION__, __LINE__,
14339  "An internal error occurred while saving a group. "
14340  "It is unclear whether the group has been saved or not. "
14341  "Diagnostics: Failure to receive response from manager daemon.",
14342  response_data);
14343  default:
14344  cmd_response_data_set_status_code (response_data,
14345  MHD_HTTP_INTERNAL_SERVER_ERROR);
14346  return gsad_message (
14347  credentials, "Internal error", __FUNCTION__, __LINE__,
14348  "An internal error occurred while saving a group. "
14349  "It is unclear whether the group has been saved or not. "
14350  "Diagnostics: Internal Error.",
14351  response_data);
14352  }
14353 
14354  html = response_from_entity (connection, credentials, params, entity,
14355  "Save Group", response_data);
14356  free_entity (entity);
14357  g_free (response);
14358  return html;
14359 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
GPtrArray * users
User session data.
Definition: gsad_session.c:39
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmpf(), gsad_message(), params_value(), response_from_entity(), and users.

Here is the call graph for this function:

◆ save_my_settings_gmp()

char* save_my_settings_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const gchar *  accept_language,
cmd_response_data_t *  response_data 
)

Returns page with user's settings, for editing.

Parameters
[in]connectionConnection to manager.
[in]credentialsCredentials of user issuing the action.
[in]paramsRequest parameters.
[in]accept_languageAccept-Language, from browser.
[out]timezoneTimezone. Caller must free.
[out]passwordPassword. Caller must free.
[out]severitySeverity. Caller must free.
[out]languageLanguage. Caller must free.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 13317 of file gsad_gmp.c.

13320 {
13321  const char *lang, *text, *old_passwd, *passwd, *max;
13322  const char *details_fname, *list_fname, *report_fname;
13323  gchar *lang_64, *text_64, *max_64, *fname_64;
13324  GString *xml;
13325  entity_t entity;
13326  params_t *changed, *defaults, *filters;
13327  int modify_failed = 0;
13328  const char *changed_value;
13329  gboolean user_changed = 0;
13330 
13332 
13333  changed = params_values (params, "settings_changed:");
13334 
13335  text = params_value (params, "text");
13336  old_passwd = params_value (params, "old_password");
13337  passwd = params_value (params, "password");
13338  max = params_value (params, "max");
13339  lang = params_value (params, "lang");
13340  details_fname = params_value (params, "details_fname");
13341  list_fname = params_value (params, "list_fname");
13342  report_fname = params_value (params, "report_fname");
13343 
13344  CHECK_VARIABLE_INVALID (text, "Save Settings")
13345  CHECK_VARIABLE_INVALID (text, "Save Settings")
13346  CHECK_VARIABLE_INVALID (old_passwd, "Save Settings")
13347  CHECK_VARIABLE_INVALID (max, "Save Settings")
13348  CHECK_VARIABLE_INVALID (lang, "Save Settings")
13349  CHECK_VARIABLE_INVALID (details_fname, "Save Settings")
13350  CHECK_VARIABLE_INVALID (list_fname, "Save Settings")
13351  CHECK_VARIABLE_INVALID (report_fname, "Save Settings")
13352 
13353  xml = g_string_new ("");
13354 
13355  changed_value = params_value (changed, "password");
13356  if ((strlen (passwd) || strlen (old_passwd))
13357  && (changed_value == NULL
13358  || (strcmp (changed_value, "") && strcmp (changed_value, "0"))))
13359  {
13360  gchar *passwd_64;
13361  gmp_authenticate_info_opts_t auth_opts;
13362 
13363  /* Send Password setting */
13364 
13365  auth_opts = gmp_authenticate_info_opts_defaults;
13366  auth_opts.username = user_get_username (user);
13367  auth_opts.password = old_passwd;
13368  switch (gmp_authenticate_info_ext_c (connection, auth_opts))
13369  {
13370  case 0:
13371  break;
13372  case 1:
13373  cmd_response_data_set_status_code (response_data,
13374  MHD_HTTP_INTERNAL_SERVER_ERROR);
13375  return gsad_message (
13376  credentials, "Internal error", __FUNCTION__, __LINE__,
13377  "An internal error occurred while saving settings. "
13378  "The settings remains the same. "
13379  "Diagnostics: Manager closed connection during authenticate.",
13380  response_data);
13381  case 2:
13382  cmd_response_data_set_status_code (response_data,
13383  MHD_HTTP_INTERNAL_SERVER_ERROR);
13384  return gsad_message (
13385  credentials, "Invalid Password", __FUNCTION__, __LINE__,
13386  "You tried to change your password, but the old"
13387  " password was not provided or was incorrect. "
13388  " Please enter the correct old password or remove"
13389  " old and new passwords to apply any other changes"
13390  " of your settings.",
13391  response_data);
13392  default:
13393  cmd_response_data_set_status_code (response_data,
13394  MHD_HTTP_INTERNAL_SERVER_ERROR);
13395  return gsad_message (
13396  credentials, "Internal error", __FUNCTION__, __LINE__,
13397  "An internal error occurred while saving settings. "
13398  "The settings remains the same. "
13399  "Diagnostics: Internal Error.",
13400  response_data);
13401  }
13402 
13403  passwd_64 = g_base64_encode ((guchar *) passwd, strlen (passwd));
13404 
13405  if (gvm_connection_sendf (connection,
13406  "<modify_setting>"
13407  "<name>Password</name>"
13408  "<value>%s</value>"
13409  "</modify_setting>",
13410  passwd_64 ? passwd_64 : "")
13411  == -1)
13412  {
13413  g_free (passwd_64);
13414  cmd_response_data_set_status_code (response_data,
13415  MHD_HTTP_INTERNAL_SERVER_ERROR);
13416  return gsad_message (
13417  credentials, "Internal error", __FUNCTION__, __LINE__,
13418  "An internal error occurred while saving settings. "
13419  "It is unclear whether all the settings were saved. "
13420  "Diagnostics: Failure to send command to manager daemon.",
13421  response_data);
13422  }
13423  g_free (passwd_64);
13424 
13425  entity = NULL;
13426  xml_string_append (xml, "<save_setting name=\"Password\">");
13427  if (read_entity_and_string_c (connection, &entity, &xml))
13428  {
13429  g_string_free (xml, TRUE);
13430  cmd_response_data_set_status_code (response_data,
13431  MHD_HTTP_INTERNAL_SERVER_ERROR);
13432  return gsad_message (
13433  credentials, "Internal error", __FUNCTION__, __LINE__,
13434  "An internal error occurred while saving settings. "
13435  "Diagnostics: Failure to receive response from manager daemon.",
13436  response_data);
13437  }
13438  xml_string_append (xml, "</save_setting>");
13439 
13440  if (gmp_success (entity) == 1)
13441  {
13442  user_set_password (user, passwd);
13444  user_changed = 1;
13445  }
13446  else
13447  {
13448  set_http_status_from_entity (entity, response_data);
13449  modify_failed = 1;
13450  }
13451  }
13452 
13453  /* Send Timezone */
13454  changed_value = params_value (changed, "timezone");
13455  if (changed_value == NULL
13456  || (strcmp (changed_value, "") && strcmp (changed_value, "0")))
13457  {
13458  text_64 = g_base64_encode ((guchar *) text, strlen (text));
13459 
13460  if (gvm_connection_sendf (connection,
13461  "<modify_setting>"
13462  "<name>Timezone</name>"
13463  "<value>%s</value>"
13464  "</modify_setting>",
13465  text_64 ? text_64 : "")
13466  == -1)
13467  {
13468  g_free (text_64);
13469  cmd_response_data_set_status_code (response_data,
13470  MHD_HTTP_INTERNAL_SERVER_ERROR);
13471  return gsad_message (
13472  credentials, "Internal error", __FUNCTION__, __LINE__,
13473  "An internal error occurred while saving settings. "
13474  "It is unclear whether all the settings were saved. "
13475  "Diagnostics: Failure to send command to manager daemon.",
13476  response_data);
13477  }
13478  g_free (text_64);
13479 
13480  entity = NULL;
13481  xml_string_append (xml, "<save_setting name=\"Timezone\">");
13482  if (read_entity_and_string_c (connection, &entity, &xml))
13483  {
13484  g_string_free (xml, TRUE);
13485  cmd_response_data_set_status_code (response_data,
13486  MHD_HTTP_INTERNAL_SERVER_ERROR);
13487  return gsad_message (
13488  credentials, "Internal error", __FUNCTION__, __LINE__,
13489  "An internal error occurred while saving settings. "
13490  "Diagnostics: Failure to receive response from manager daemon.",
13491  response_data);
13492  }
13493  xml_string_append (xml, "</save_setting>");
13494 
13495  if (gmp_success (entity) == 1)
13496  {
13497  const gchar *timezone = strlen (text) ? text : "UTC";
13498 
13499  user_set_timezone (user, timezone);
13500  user_changed = 1;
13501 
13502  /* Set the timezone, so that the ENVELOPE/TIME
13503  * uses the right timezone. */
13504 
13505  if (setenv ("TZ", timezone, 1) == -1)
13506  {
13507  g_critical ("%s: failed to set TZ\n", __FUNCTION__);
13508  exit (EXIT_FAILURE);
13509  }
13510  tzset ();
13511  }
13512  else
13513  {
13514  set_http_status_from_entity (entity, response_data);
13515  modify_failed = 1;
13516  }
13517  }
13518 
13519  /* Send Rows Per Page */
13520  changed_value = params_value (changed, "max");
13521  if (changed_value == NULL
13522  || (strcmp (changed_value, "") && strcmp (changed_value, "0")))
13523  {
13524  max_64 = g_base64_encode ((guchar *) max, strlen (max));
13525 
13526  if (gvm_connection_sendf (connection,
13527  "<modify_setting"
13528  " setting_id"
13529  "=\"5f5a8712-8017-11e1-8556-406186ea4fc5\">"
13530  "<value>%s</value>"
13531  "</modify_setting>",
13532  max_64 ? max_64 : "")
13533  == -1)
13534  {
13535  g_free (max_64);
13536  cmd_response_data_set_status_code (response_data,
13537  MHD_HTTP_INTERNAL_SERVER_ERROR);
13538  return gsad_message (
13539  credentials, "Internal error", __FUNCTION__, __LINE__,
13540  "An internal error occurred while saving settings. "
13541  "It is unclear whether all the settings were saved. "
13542  "Diagnostics: Failure to send command to manager daemon.",
13543  response_data);
13544  }
13545  g_free (max_64);
13546 
13547  entity = NULL;
13548  xml_string_append (xml, "<save_setting id=\"%s\">",
13549  "5f5a8712-8017-11e1-8556-406186ea4fc5");
13550  if (read_entity_and_string_c (connection, &entity, &xml))
13551  {
13552  g_string_free (xml, TRUE);
13553  cmd_response_data_set_status_code (response_data,
13554  MHD_HTTP_INTERNAL_SERVER_ERROR);
13555  return gsad_message (
13556  credentials, "Internal error", __FUNCTION__, __LINE__,
13557  "An internal error occurred while saving settings. "
13558  "It is unclear whether all the settings were saved. "
13559  "Diagnostics: Failure to receive response from manager daemon.",
13560  response_data);
13561  }
13562  xml_string_append (xml, "</save_setting>");
13563  if (gmp_success (entity) != 1)
13564  {
13565  set_http_status_from_entity (entity, response_data);
13566  modify_failed = 1;
13567  }
13568  }
13569 
13570  /* Send resource details export file name format. */
13571  changed_value = params_value (changed, "details_fname");
13572  if (changed_value == NULL
13573  || (strcmp (changed_value, "") && strcmp (changed_value, "0")))
13574  {
13575  fname_64 =
13576  g_base64_encode ((guchar *) details_fname, strlen (details_fname));
13577 
13578  if (gvm_connection_sendf (connection,
13579  "<modify_setting"
13580  " setting_id"
13581  "=\"a6ac88c5-729c-41ba-ac0a-deea4a3441f2\">"
13582  "<value>%s</value>"
13583  "</modify_setting>",
13584  fname_64 ? fname_64 : "")
13585  == -1)
13586  {
13587  g_free (fname_64);
13588  cmd_response_data_set_status_code (response_data,
13589  MHD_HTTP_INTERNAL_SERVER_ERROR);
13590  return gsad_message (
13591  credentials, "Internal error", __FUNCTION__, __LINE__,
13592  "An internal error occurred while saving settings. "
13593  "It is unclear whether all the settings were saved. "
13594  "Diagnostics: Failure to send command to manager daemon.",
13595  response_data);
13596  }
13597  g_free (fname_64);
13598 
13599  entity = NULL;
13600  xml_string_append (xml, "<save_setting id=\"%s\">",
13601  "a6ac88c5-729c-41ba-ac0a-deea4a3441f2");
13602  if (read_entity_and_string_c (connection, &entity, &xml))
13603  {
13604  g_string_free (xml, TRUE);
13605  cmd_response_data_set_status_code (response_data,
13606  MHD_HTTP_INTERNAL_SERVER_ERROR);
13607  return gsad_message (
13608  credentials, "Internal error", __FUNCTION__, __LINE__,
13609  "An internal error occurred while saving settings. "
13610  "It is unclear whether all the settings were saved. "
13611  "Diagnostics: Failure to receive response from manager daemon.",
13612  response_data);
13613  }
13614  xml_string_append (xml, "</save_setting>");
13615  if (gmp_success (entity) != 1)
13616  {
13617  set_http_status_from_entity (entity, response_data);
13618  modify_failed = 1;
13619  }
13620  }
13621 
13622  /* Send resource list export file name format. */
13623  changed_value = params_value (changed, "list_fname");
13624  if (changed_value == NULL
13625  || (strcmp (changed_value, "") && strcmp (changed_value, "0")))
13626  {
13627  fname_64 = g_base64_encode ((guchar *) list_fname, strlen (list_fname));
13628 
13629  if (gvm_connection_sendf (connection,
13630  "<modify_setting"
13631  " setting_id"
13632  "=\"0872a6ed-4f85-48c5-ac3f-a5ef5e006745\">"
13633  "<value>%s</value>"
13634  "</modify_setting>",
13635  fname_64 ? fname_64 : "")
13636  == -1)
13637  {
13638  g_free (fname_64);
13639  cmd_response_data_set_status_code (response_data,
13640  MHD_HTTP_INTERNAL_SERVER_ERROR);
13641  return gsad_message (
13642  credentials, "Internal error", __FUNCTION__, __LINE__,
13643  "An internal error occurred while saving settings. "
13644  "It is unclear whether all the settings were saved. "
13645  "Diagnostics: Failure to send command to manager daemon.",
13646  response_data);
13647  }
13648  g_free (fname_64);
13649 
13650  entity = NULL;
13651  xml_string_append (xml, "<save_setting id=\"%s\">",
13652  "a6ac88c5-729c-41ba-ac0a-deea4a3441f2");
13653  if (read_entity_and_string_c (connection, &entity, &xml))
13654  {
13655  g_string_free (xml, TRUE);
13656  cmd_response_data_set_status_code (response_data,
13657  MHD_HTTP_INTERNAL_SERVER_ERROR);
13658  return gsad_message (
13659  credentials, "Internal error", __FUNCTION__, __LINE__,
13660  "An internal error occurred while saving settings. "
13661  "It is unclear whether all the settings were saved. "
13662  "Diagnostics: Failure to receive response from manager daemon.",
13663  response_data);
13664  }
13665  xml_string_append (xml, "</save_setting>");
13666  if (gmp_success (entity) != 1)
13667  {
13668  set_http_status_from_entity (entity, response_data);
13669  modify_failed = 1;
13670  }
13671  }
13672 
13673  /* Send report export file name format. */
13674  changed_value = params_value (changed, "report_fname");
13675  if (changed_value == NULL
13676  || (strcmp (changed_value, "") && strcmp (changed_value, "0")))
13677  {
13678  fname_64 =
13679  g_base64_encode ((guchar *) report_fname, strlen (report_fname));
13680 
13681  if (gvm_connection_sendf (connection,
13682  "<modify_setting"
13683  " setting_id"
13684  "=\"e1a2ae0b-736e-4484-b029-330c9e15b900\">"
13685  "<value>%s</value>"
13686  "</modify_setting>",
13687  fname_64 ? fname_64 : "")
13688  == -1)
13689  {
13690  g_free (fname_64);
13691  cmd_response_data_set_status_code (response_data,
13692  MHD_HTTP_INTERNAL_SERVER_ERROR);
13693  return gsad_message (
13694  credentials, "Internal error", __FUNCTION__, __LINE__,
13695  "An internal error occurred while saving settings. "
13696  "It is unclear whether all the settings were saved. "
13697  "Diagnostics: Failure to send command to manager daemon.",
13698  response_data);
13699  }
13700  g_free (fname_64);
13701 
13702  entity = NULL;
13703  xml_string_append (xml, "<save_setting id=\"%s\">",
13704  "e1a2ae0b-736e-4484-b029-330c9e15b900");
13705  if (read_entity_and_string_c (connection, &entity, &xml))
13706  {
13707  g_string_free (xml, TRUE);
13708  cmd_response_data_set_status_code (response_data,
13709  MHD_HTTP_INTERNAL_SERVER_ERROR);
13710  return gsad_message (
13711  credentials, "Internal error", __FUNCTION__, __LINE__,
13712  "An internal error occurred while saving settings. "
13713  "It is unclear whether all the settings were saved. "
13714  "Diagnostics: Failure to receive response from manager daemon.",
13715  response_data);
13716  }
13717  xml_string_append (xml, "</save_setting>");
13718  if (gmp_success (entity) != 1)
13719  {
13720  set_http_status_from_entity (entity, response_data);
13721  modify_failed = 1;
13722  }
13723  }
13724 
13725  /* Send User Interface Language. */
13726  changed_value = params_value (changed, "lang");
13727  if (changed_value == NULL
13728  || (strcmp (changed_value, "") && strcmp (changed_value, "0")))
13729  {
13730  lang_64 = g_base64_encode ((guchar *) lang, strlen (lang));
13731 
13732  if (gvm_connection_sendf (connection,
13733  "<modify_setting"
13734  " setting_id"
13735  "=\"6765549a-934e-11e3-b358-406186ea4fc5\">"
13736  "<value>%s</value>"
13737  "</modify_setting>",
13738  lang_64 ? lang_64 : "")
13739  == -1)
13740  {
13741  g_free (lang_64);
13742  cmd_response_data_set_status_code (response_data,
13743  MHD_HTTP_INTERNAL_SERVER_ERROR);
13744  return gsad_message (
13745  credentials, "Internal error", __FUNCTION__, __LINE__,
13746  "An internal error occurred while saving settings. "
13747  "It is unclear whether all the settings were saved. "
13748  "Diagnostics: Failure to send command to manager daemon.",
13749  response_data);
13750  }
13751  g_free (lang_64);
13752 
13753  entity = NULL;
13754  xml_string_append (xml, "<save_setting id=\"%s\">",
13755  "6765549a-934e-11e3-b358-406186ea4fc5");
13756  if (read_entity_and_string_c (connection, &entity, &xml))
13757  {
13758  g_string_free (xml, TRUE);
13759  cmd_response_data_set_status_code (response_data,
13760  MHD_HTTP_INTERNAL_SERVER_ERROR);
13761  return gsad_message (
13762  credentials, "Internal error", __FUNCTION__, __LINE__,
13763  "An internal error occurred while saving settings. "
13764  "It is unclear whether all the settings were saved. "
13765  "Diagnostics: Failure to receive response from manager daemon.",
13766  response_data);
13767  }
13768  xml_string_append (xml, "</save_setting>");
13769  if (gmp_success (entity) == 1)
13770  {
13771  user_set_language (user, lang);
13772  user_changed = 1;
13773  }
13774  else
13775  {
13776  set_http_status_from_entity (entity, response_data);
13777  modify_failed = 1;
13778  }
13779  }
13780 
13781  /* Send default resources */
13782 
13783  defaults = params_values (params, "settings_default:");
13784  if (send_settings_filters (connection, defaults, changed, xml, &modify_failed,
13785  response_data))
13786  {
13787  cmd_response_data_set_status_code (response_data,
13788  MHD_HTTP_INTERNAL_SERVER_ERROR);
13789  return gsad_message (
13790  credentials, "Internal error", __FUNCTION__, __LINE__,
13791  "An internal error occurred while saving settings. "
13792  "It is unclear whether all the settings were saved. "
13793  "Diagnostics: Failure to send command to manager daemon.",
13794  response_data);
13795  }
13796 
13797  /* Send resources filters */
13798 
13799  filters = params_values (params, "settings_filter:");
13800  if (send_settings_filters (connection, filters, changed, xml, &modify_failed,
13801  response_data))
13802  {
13803  cmd_response_data_set_status_code (response_data,
13804  MHD_HTTP_INTERNAL_SERVER_ERROR);
13805  return gsad_message (
13806  credentials, "Internal error", __FUNCTION__, __LINE__,
13807  "An internal error occurred while saving settings. "
13808  "It is unclear whether all the settings were saved. "
13809  "Diagnostics: Failure to send command to manager daemon.",
13810  response_data);
13811  }
13812 
13813  /* Send Severity Class. */
13814 
13815  changed_value = params_value (changed, "severity_class");
13816  if (changed_value == NULL
13817  || (strcmp (changed_value, "") && strcmp (changed_value, "0")))
13818  {
13819  text = params_value (params, "severity_class");
13820  text_64 = (text ? g_base64_encode ((guchar *) text, strlen (text))
13821  : g_strdup (""));
13822 
13823  if (gvm_connection_sendf (connection,
13824  "<modify_setting"
13825  " setting_id"
13826  "=\"f16bb236-a32d-4cd5-a880-e0fcf2599f59\">"
13827  "<value>%s</value>"
13828  "</modify_setting>",
13829  text_64 ? text_64 : "")
13830  == -1)
13831  {
13832  g_free (text_64);
13833  cmd_response_data_set_status_code (response_data,
13834  MHD_HTTP_INTERNAL_SERVER_ERROR);
13835  return gsad_message (
13836  credentials, "Internal error", __FUNCTION__, __LINE__,
13837  "An internal error occurred while saving settings. "
13838  "It is unclear whether all the settings were saved. "
13839  "Diagnostics: Failure to send command to manager daemon.",
13840  response_data);
13841  }
13842  g_free (text_64);
13843 
13844  entity = NULL;
13845  xml_string_append (xml, "<save_setting id=\"%s\">",
13846  "f16bb236-a32d-4cd5-a880-e0fcf2599f59");
13847  if (read_entity_and_string_c (connection, &entity, &xml))
13848  {
13849  g_string_free (xml, TRUE);
13850  cmd_response_data_set_status_code (response_data,
13851  MHD_HTTP_INTERNAL_SERVER_ERROR);
13852  return gsad_message (
13853  credentials, "Internal error", __FUNCTION__, __LINE__,
13854  "An internal error occurred while saving settings. "
13855  "It is unclear whether all the settings were saved. "
13856  "Diagnostics: Failure to receive response from manager daemon.",
13857  response_data);
13858  }
13859  xml_string_append (xml, "</save_setting>");
13860 
13861  if (gmp_success (entity) == 1)
13862  {
13863  if ((text != NULL) && (strlen (text) > 0))
13864  {
13865  user_set_severity (user, text);
13866  user_changed = 1;
13867  }
13868  }
13869  else
13870  {
13871  set_http_status_from_entity (entity, response_data);
13872  modify_failed = 1;
13873  }
13874  }
13875 
13876  /* Send Dynamic Severity setting. */
13877 
13878  changed_value = params_value (changed, "dynamic_severity");
13879  if (changed_value == NULL
13880  || (strcmp (changed_value, "") && strcmp (changed_value, "0")))
13881  {
13882  text = params_value (params, "dynamic_severity");
13883  text_64 = (text ? g_base64_encode ((guchar *) text, strlen (text))
13884  : g_strdup (""));
13885 
13886  if (gvm_connection_sendf (connection,
13887  "<modify_setting"
13888  " setting_id"
13889  "=\"77ec2444-e7f2-4a80-a59b-f4237782d93f\">"
13890  "<value>%s</value>"
13891  "</modify_setting>",
13892  text_64 ? text_64 : "")
13893  == -1)
13894  {
13895  g_free (text_64);
13896  cmd_response_data_set_status_code (response_data,
13897  MHD_HTTP_INTERNAL_SERVER_ERROR);
13898  return gsad_message (
13899  credentials, "Internal error", __FUNCTION__, __LINE__,
13900  "An internal error occurred while saving settings. "
13901  "It is unclear whether all the settings were saved. "
13902  "Diagnostics: Failure to send command to manager daemon.",
13903  response_data);
13904  }
13905  g_free (text_64);
13906 
13907  entity = NULL;
13908  xml_string_append (xml, "<save_setting id=\"%s\">",
13909  "77ec2444-e7f2-4a80-a59b-f4237782d93f");
13910  if (read_entity_and_string_c (connection, &entity, &xml))
13911  {
13912  g_string_free (xml, TRUE);
13913  cmd_response_data_set_status_code (response_data,
13914  MHD_HTTP_INTERNAL_SERVER_ERROR);
13915  return gsad_message (
13916  credentials, "Internal error", __FUNCTION__, __LINE__,
13917  "An internal error occurred while saving settings. "
13918  "It is unclear whether all the settings were saved. "
13919  "Diagnostics: Failure to receive response from manager daemon.",
13920  response_data);
13921  }
13922  xml_string_append (xml, "</save_setting>");
13923  if (gmp_success (entity) != 1)
13924  {
13925  set_http_status_from_entity (entity, response_data);
13926  modify_failed = 1;
13927  }
13928  }
13929 
13930  /* Send Default Severity setting. */
13931  changed_value = params_value (changed, "default_severity");
13932  if (changed_value == NULL
13933  || (strcmp (changed_value, "") && strcmp (changed_value, "0")))
13934  {
13935  text = params_value (params, "default_severity");
13936  text_64 = (text ? g_base64_encode ((guchar *) text, strlen (text))
13937  : g_strdup (""));
13938 
13939  if (gvm_connection_sendf (connection,
13940  "<modify_setting"
13941  " setting_id"
13942  "=\"7eda49c5-096c-4bef-b1ab-d080d87300df\">"
13943  "<value>%s</value>"
13944  "</modify_setting>",
13945  text_64 ? text_64 : "")
13946  == -1)
13947  {
13948  g_free (text_64);
13949  cmd_response_data_set_status_code (response_data,
13950  MHD_HTTP_INTERNAL_SERVER_ERROR);
13951  return gsad_message (
13952  credentials, "Internal error", __FUNCTION__, __LINE__,
13953  "An internal error occurred while saving settings. "
13954  "It is unclear whether all the settings were saved. "
13955  "Diagnostics: Failure to send command to manager daemon.",
13956  response_data);
13957  }
13958  g_free (text_64);
13959 
13960  entity = NULL;
13961  xml_string_append (xml, "<save_setting id=\"%s\">",
13962  "7eda49c5-096c-4bef-b1ab-d080d87300df");
13963  if (read_entity_and_string_c (connection, &entity, &xml))
13964  {
13965  g_string_free (xml, TRUE);
13966  cmd_response_data_set_status_code (response_data,
13967  MHD_HTTP_INTERNAL_SERVER_ERROR);
13968  return gsad_message (
13969  credentials, "Internal error", __FUNCTION__, __LINE__,
13970  "An internal error occurred while saving settings. "
13971  "It is unclear whether all the settings were saved. "
13972  "Diagnostics: Failure to receive response from manager daemon.",
13973  response_data);
13974  }
13975  xml_string_append (xml, "</save_setting>");
13976  if (gmp_success (entity) != 1)
13977  {
13978  set_http_status_from_entity (entity, response_data);
13979  modify_failed = 1;
13980  }
13981  }
13982 
13983  /* Send Auto Cache Rebuild setting. */
13984 
13985  changed_value = params_value (changed, "auto_cache_rebuild");
13986  if (changed_value == NULL
13987  || (strcmp (changed_value, "") && strcmp (changed_value, "0")))
13988  {
13989  text = params_value (params, "auto_cache_rebuild");
13990  text_64 = (text ? g_base64_encode ((guchar *) text, strlen (text))
13991  : g_strdup (""));
13992 
13993  if (gvm_connection_sendf (connection,
13994  "<modify_setting"
13995  " setting_id"
13996  "=\"a09285b0-2d47-49b6-a4ef-946ee71f1d5c\">"
13997  "<value>%s</value>"
13998  "</modify_setting>",
13999  text_64 ? text_64 : "")
14000  == -1)
14001  {
14002  g_free (text_64);
14003  gvm_connection_close (connection);
14004  cmd_response_data_set_status_code (response_data,
14005  MHD_HTTP_INTERNAL_SERVER_ERROR);
14006  return gsad_message (
14007  credentials, "Internal error", __FUNCTION__, __LINE__,
14008  "An internal error occurred while saving settings. "
14009  "It is unclear whether all the settings were saved. "
14010  "Diagnostics: Failure to send command to manager daemon.",
14011  response_data);
14012  }
14013  g_free (text_64);
14014 
14015  entity = NULL;
14016  xml_string_append (xml, "<save_setting id=\"%s\">",
14017  "a09285b0-2d47-49b6-a4ef-946ee71f1d5c");
14018  if (read_entity_and_string_c (connection, &entity, &xml))
14019  {
14020  g_string_free (xml, TRUE);
14021  gvm_connection_close (connection);
14022  cmd_response_data_set_status_code (response_data,
14023  MHD_HTTP_INTERNAL_SERVER_ERROR);
14024  return gsad_message (
14025  credentials, "Internal error", __FUNCTION__, __LINE__,
14026  "An internal error occurred while saving settings. "
14027  "It is unclear whether all the settings were saved. "
14028  "Diagnostics: Failure to receive response from manager daemon.",
14029  response_data);
14030  }
14031  xml_string_append (xml, "</save_setting>");
14032  if (gmp_success (entity) != 1)
14033  {
14034  set_http_status_from_entity (entity, response_data);
14035  modify_failed = 1;
14036  }
14037  }
14038 
14039  if (user_changed)
14040  {
14042  }
14043 
14044  return envelope_gmp (connection, credentials, params,
14045  g_string_free (xml, FALSE), response_data);
14046 }
params_t * params_values(params_t *params, const char *name)
Get values of param.
Definition: gsad_base.c:287
static int gmp_success(entity_t entity)
Check whether an GMP command failed.
Definition: gsad_gmp.c:656
static int send_settings_filters(gvm_connection_t *connection, params_t *data, params_t *changed, GString *xml, int *modify_failed_flag, cmd_response_data_t *response_data)
Send settings resource filters.
Definition: gsad_gmp.c:13244
Structure of credential related information.
void user_set_severity(user_t *user, const gchar *severity)
Set severity class of user.
Definition: gsad_user.c:274
void user_set_password(user_t *user, const gchar *password)
Set password of user.
Definition: gsad_user.c:257
void user_set_language(user_t *user, const gchar *language)
Set language of user.
Definition: gsad_user.c:289
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
const gchar * user_get_username(user_t *user)
Definition: gsad_user.c:157
const gchar * user_get_token(user_t *user)
Definition: gsad_user.c:175
void session_add_user(const gchar *id, user_t *user)
Add user to the session "database".
Definition: gsad_session.c:147
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
void set_http_status_from_entity(entity_t entity, cmd_response_data_t *response_data)
Set the HTTP status according to GMP response entity.
Definition: gsad_gmp.c:677
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void user_set_timezone(user_t *user, const gchar *timezone)
Set timezone of user.
Definition: gsad_user.c:242
void session_remove_other_sessions(const gchar *id, user_t *user)
Removes all session of the user, except the one with the passed id.
Definition: gsad_session.c:181
User information structure, for sessions.
Definition: gsad_user.c:42
#define params_t
Definition: gsad_params.h:31
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
user_t * credentials_get_user(credentials_t *cred)
static char * envelope_gmp(gvm_connection_t *connection, credentials_t *credentials, params_t *params, gchar *xml, cmd_response_data_t *response_data)
Wrap some XML in an envelope.
Definition: gsad_gmp.c:443

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), credentials_get_user(), envelope_gmp(), gmp_success(), gsad_message(), params_t, params_value(), params_values(), send_settings_filters(), session_add_user(), session_remove_other_sessions(), set_http_status_from_entity(), user_get_token(), user_get_username(), user_set_language(), user_set_password(), user_set_severity(), and user_set_timezone().

Here is the call graph for this function:

◆ save_note_gmp()

char* save_note_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Save note, get next page, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 11088 of file gsad_gmp.c.

11090 {
11091  gchar *response;
11092  entity_t entity;
11093  const char *note_id, *text, *hosts, *port, *severity, *task_id;
11094  const char *result_id, *active, *days, *oid;
11095  char *ret;
11096 
11097  note_id = params_value (params, "note_id");
11098 
11099  oid = params_value (params, "oid");
11100 
11101  text = params_value (params, "text");
11102  if (text == NULL)
11103  params_given (params, "text") || (text = "");
11104 
11105  port = get_port_from_params (params);
11106  hosts = get_hosts_from_params (params);
11107  task_id = get_task_id_from_params (params);
11108  severity = get_severity_from_params (params);
11109  result_id = get_result_id_from_params (params);
11110 
11111  active = params_value (params, "active");
11112  days = params_value (params, "days");
11113 
11114  CHECK_VARIABLE_INVALID (oid, "Save Note");
11115  CHECK_VARIABLE_INVALID (active, "Save Note");
11116  CHECK_VARIABLE_INVALID (note_id, "Save Note");
11117  CHECK_VARIABLE_INVALID (days, "Save Note");
11118 
11119  response = NULL;
11120  entity = NULL;
11121  switch (gmpf (connection, credentials, &response, &entity, response_data,
11122  "<modify_note note_id=\"%s\">"
11123  "<active>%s</active>"
11124  "<hosts>%s</hosts>"
11125  "<port>%s</port>"
11126  "<severity>%s</severity>"
11127  "<text>%s</text>"
11128  "<task id=\"%s\"/>"
11129  "<result id=\"%s\"/>"
11130  "<nvt oid=\"%s\"/>"
11131  "</modify_note>",
11132  note_id, strcmp (active, "1") ? active : (days ? days : "-1"),
11133  hosts ? hosts : "", port ? port : "", severity ? severity : "",
11134  text ? text : "", task_id ? task_id : "",
11135  result_id ? result_id : "", oid))
11136  {
11137  case 0:
11138  case -1:
11139  break;
11140  case 1:
11141  cmd_response_data_set_status_code (response_data,
11142  MHD_HTTP_INTERNAL_SERVER_ERROR);
11143  return gsad_message (
11144  credentials, "Internal error", __FUNCTION__, __LINE__,
11145  "An internal error occurred while saving a note. "
11146  "The note remains the same. "
11147  "Diagnostics: Failure to send command to manager daemon.",
11148  response_data);
11149  case 2:
11150  cmd_response_data_set_status_code (response_data,
11151  MHD_HTTP_INTERNAL_SERVER_ERROR);
11152  return gsad_message (
11153  credentials, "Internal error", __FUNCTION__, __LINE__,
11154  "An internal error occurred while saving a note. "
11155  "It is unclear whether the note has been saved or not. "
11156  "Diagnostics: Failure to receive response from manager daemon.",
11157  response_data);
11158  default:
11159  cmd_response_data_set_status_code (response_data,
11160  MHD_HTTP_INTERNAL_SERVER_ERROR);
11161  return gsad_message (
11162  credentials, "Internal error", __FUNCTION__, __LINE__,
11163  "An internal error occurred while saving a note. "
11164  "It is unclear whether the note has been saved or not. "
11165  "Diagnostics: Internal Error.",
11166  response_data);
11167  }
11168 
11169  ret = response_from_entity (connection, credentials, params, entity,
11170  "Save Note", response_data);
11171 
11172  free_entity (entity);
11173  g_free (response);
11174  return ret;
11175 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
const char * get_port_from_params(params_t *params)
Get a port from request params.
Definition: gsad_gmp.c:10842
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
int params_given(params_t *params, const char *name)
Get whether a param was given at all.
Definition: gsad_base.c:189
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
const char * get_severity_from_params(params_t *params)
Get severity from request params.
Definition: gsad_gmp.c:10923
const char * get_task_id_from_params(params_t *params)
Get task_id from request params.
Definition: gsad_gmp.c:10903
const char * get_hosts_from_params(params_t *params)
Get hosts from request params.
Definition: gsad_gmp.c:10868
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
const char * get_result_id_from_params(params_t *params)
Get result_id from request params.
Definition: gsad_gmp.c:10946

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), get_hosts_from_params(), get_port_from_params(), get_result_id_from_params(), get_severity_from_params(), get_task_id_from_params(), gmpf(), gsad_message(), params_given(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ save_osp_prefs()

static char* save_osp_prefs ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  next,
const char *  fail_next,
int *  success,
cmd_response_data_t *  response_data 
)
static

Save OSP file preferences.

Parameters
[in]connectionConnection.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[in]nextThe next command on success.
[in]fail_nextThe next command on failure.
[out]successWhether the last command was successful.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 8386 of file gsad_gmp.c.

8389 {
8390  GHashTableIter iter;
8391  gpointer param_name, val;
8392  char *ret;
8393  const char *config_id;
8394 
8395  config_id = params_value (params, "config_id");
8396  g_hash_table_iter_init (&iter, params);
8397  ret = NULL;
8398  while (g_hash_table_iter_next (&iter, &param_name, &val))
8399  {
8400  gchar *value;
8401  param_t *param = val;
8402 
8403  g_free (ret);
8404  ret = NULL;
8405 
8406  if (!g_str_has_prefix (param_name, "osp_pref_"))
8407  continue;
8408  value = param->value_size
8409  ? g_base64_encode ((guchar *) param->value, param->value_size)
8410  : g_strdup ("");
8411 
8412  /* Send the name without the osp_pref_ prefix. */
8413  param_name = ((char *) param_name) + 9;
8414  if (gvm_connection_sendf (connection,
8415  "<modify_config config_id=\"%s\">"
8416  "<preference><name>%s</name>"
8417  "<value>%s</value></preference>"
8418  "</modify_config>",
8419  config_id, (char *) param_name, value)
8420  == -1)
8421  {
8422  g_free (value);
8423  cmd_response_data_set_status_code (response_data,
8424  MHD_HTTP_INTERNAL_SERVER_ERROR);
8425  return gsad_message (
8426  credentials, "Internal error", __FUNCTION__, __LINE__,
8427  "An internal error occurred while saving a config. It is"
8428  " unclear whether the entire config has been saved. "
8429  "Diagnostics: Failure to send command to manager daemon.",
8430  response_data);
8431  }
8432  g_free (value);
8433 
8434  ret = check_modify_config (connection, credentials, params, next,
8435  fail_next, success, response_data);
8436  if (*success == 0)
8437  return ret;
8438  }
8439  return ret;
8440 }
gchar * value
Definition: gsad_params.h:40
Structure of credential related information.
static char * check_modify_config(gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *next, const char *fail_next, int *success, cmd_response_data_t *response_data)
Check a modify_config response.
Definition: gsad_gmp.c:570
int value_size
Definition: gsad_params.h:46
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
Request parameter.
Definition: gsad_params.h:38
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References check_modify_config(), cmd_response_data_set_status_code(), gsad_message(), params_value(), param::value, and param::value_size.

Referenced by save_config_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_override_gmp()

char* save_override_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Save override, get next page, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 11405 of file gsad_gmp.c.

11407 {
11408  gchar *response;
11409  entity_t entity;
11410  const char *override_id, *text, *hosts, *port;
11411  const char *severity, *custom_severity, *new_severity;
11412  const char *task_id, *result_id, *active, *days, *oid;
11413  char *ret;
11414 
11415  override_id = params_value (params, "override_id");
11416 
11417  port = get_port_from_params (params);
11418  hosts = get_hosts_from_params (params);
11419  task_id = get_task_id_from_params (params);
11420  severity = get_severity_from_params (params);
11421  result_id = get_result_id_from_params (params);
11422 
11423  text = params_value (params, "text");
11424  if (text == NULL)
11425  params_given (params, "text") || (text = "");
11426 
11427  custom_severity = params_value (params, "custom_severity");
11428  if (custom_severity && strcmp (custom_severity, "0") != 0)
11429  new_severity = params_value (params, "new_severity");
11430  else
11431  new_severity = params_value (params, "new_severity_from_list");
11432 
11433  active = params_value (params, "active");
11434  days = params_value (params, "days");
11435  oid = params_value (params, "oid");
11436 
11437  CHECK_VARIABLE_INVALID (active, "Save Override");
11438  CHECK_VARIABLE_INVALID (override_id, "Save Override");
11439  CHECK_VARIABLE_INVALID (new_severity, "Save Override");
11440  CHECK_VARIABLE_INVALID (days, "Save Override");
11441  CHECK_VARIABLE_INVALID (oid, "Save Override");
11442 
11443  response = NULL;
11444  entity = NULL;
11445  switch (gmpf (connection, credentials, &response, &entity, response_data,
11446  "<modify_override override_id=\"%s\">"
11447  "<active>%s</active>"
11448  "<nvt oid=\"%s\"/>"
11449  "<hosts>%s</hosts>"
11450  "<port>%s</port>"
11451  "<severity>%s</severity>"
11452  "<new_severity>%s</new_severity>"
11453  "<text>%s</text>"
11454  "<task id=\"%s\"/>"
11455  "<result id=\"%s\"/>"
11456  "</modify_override>",
11457  override_id,
11458  strcmp (active, "1") ? active : (days ? days : "-1"), oid,
11459  hosts ? hosts : "", port ? port : "", severity ? severity : "",
11460  new_severity, text ? text : "", task_id ? task_id : "",
11461  result_id ? result_id : ""))
11462  {
11463  case 0:
11464  case -1:
11465  break;
11466  case 1:
11467  cmd_response_data_set_status_code (response_data,
11468  MHD_HTTP_INTERNAL_SERVER_ERROR);
11469  return gsad_message (
11470  credentials, "Internal error", __FUNCTION__, __LINE__,
11471  "An internal error occurred while saving a override. "
11472  "The override remains the same. "
11473  "Diagnostics: Failure to send command to manager daemon.",
11474  response_data);
11475  case 2:
11476  cmd_response_data_set_status_code (response_data,
11477  MHD_HTTP_INTERNAL_SERVER_ERROR);
11478  return gsad_message (
11479  credentials, "Internal error", __FUNCTION__, __LINE__,
11480  "An internal error occurred while saving a override. "
11481  "It is unclear whether the override has been saved or not. "
11482  "Diagnostics: Failure to receive response from manager daemon.",
11483  response_data);
11484  default:
11485  cmd_response_data_set_status_code (response_data,
11486  MHD_HTTP_INTERNAL_SERVER_ERROR);
11487  return gsad_message (
11488  credentials, "Internal error", __FUNCTION__, __LINE__,
11489  "An internal error occurred while saving a override. "
11490  "It is unclear whether the override has been saved or not. "
11491  "Diagnostics: Internal Error.",
11492  response_data);
11493  }
11494 
11495  ret = response_from_entity (connection, credentials, params, entity,
11496  "Save Override", response_data);
11497 
11498  free_entity (entity);
11499  g_free (response);
11500  return ret;
11501 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
const char * get_port_from_params(params_t *params)
Get a port from request params.
Definition: gsad_gmp.c:10842
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
int params_given(params_t *params, const char *name)
Get whether a param was given at all.
Definition: gsad_base.c:189
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
const char * get_severity_from_params(params_t *params)
Get severity from request params.
Definition: gsad_gmp.c:10923
const char * get_task_id_from_params(params_t *params)
Get task_id from request params.
Definition: gsad_gmp.c:10903
const char * get_hosts_from_params(params_t *params)
Get hosts from request params.
Definition: gsad_gmp.c:10868
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
const char * get_result_id_from_params(params_t *params)
Get result_id from request params.
Definition: gsad_gmp.c:10946

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), get_hosts_from_params(), get_port_from_params(), get_result_id_from_params(), get_severity_from_params(), get_task_id_from_params(), gmpf(), gsad_message(), params_given(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ save_permission_gmp()

char* save_permission_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Modify a permission, get all permissions, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 15266 of file gsad_gmp.c.

15268 {
15269  gchar *html, *response;
15270  const char *permission_id, *name, *comment, *resource_id, *resource_type;
15271  const char *subject_id, *subject_type;
15272  entity_t entity;
15273  int ret;
15274 
15275  permission_id = params_value (params, "permission_id");
15276  name = params_value (params, "permission");
15277  comment = params_value (params, "comment");
15278  subject_type = params_value (params, "subject_type");
15279  resource_id = params_value (params, "id_or_empty");
15280  resource_type = params_value (params, "optional_resource_type");
15281 
15282  CHECK_VARIABLE_INVALID (permission_id, "Save Permission");
15283  CHECK_VARIABLE_INVALID (name, "Save Permission");
15284  CHECK_VARIABLE_INVALID (comment, "Save Permission");
15285  CHECK_VARIABLE_INVALID (resource_id, "Save Permission");
15286  CHECK_VARIABLE_INVALID (subject_type, "Save Permission");
15287  if (params_given (params, "optional_resource_type"))
15288  CHECK_VARIABLE_INVALID (resource_type, "Save Permission");
15289 
15290  if (strcmp (subject_type, "user") == 0)
15291  subject_id = params_value (params, "user_id");
15292  else if (strcmp (subject_type, "group") == 0)
15293  subject_id = params_value (params, "group_id");
15294  else if (strcmp (subject_type, "role") == 0)
15295  subject_id = params_value (params, "role_id");
15296  else
15297  subject_id = NULL;
15298  CHECK_VARIABLE_INVALID (subject_id, "Save Permission");
15299 
15300  /* Modify the permission. */
15301 
15302  response = NULL;
15303  entity = NULL;
15304  ret = gmpf (connection, credentials, &response, &entity, response_data,
15305  "<modify_permission permission_id=\"%s\">"
15306  "<name>%s</name>"
15307  "<comment>%s</comment>"
15308  "<subject id=\"%s\">"
15309  "<type>%s</type>"
15310  "</subject>"
15311  "<resource id=\"%s\">"
15312  "<type>%s</type>"
15313  "</resource>"
15314  "</modify_permission>",
15315  permission_id, name, comment, subject_id, subject_type,
15316  (resource_id && strlen (resource_id)) ? resource_id : "0",
15317  resource_type ? resource_type : "");
15318  switch (ret)
15319  {
15320  case 0:
15321  case -1:
15322  break;
15323  case 1:
15324  cmd_response_data_set_status_code (response_data,
15325  MHD_HTTP_INTERNAL_SERVER_ERROR);
15326  return gsad_message (
15327  credentials, "Internal error", __FUNCTION__, __LINE__,
15328  "An internal error occurred while modifying a permission. "
15329  "The permission was not modified. "
15330  "Diagnostics: Failure to send command to manager daemon.",
15331  response_data);
15332  case 2:
15333  cmd_response_data_set_status_code (response_data,
15334  MHD_HTTP_INTERNAL_SERVER_ERROR);
15335  return gsad_message (
15336  credentials, "Internal error", __FUNCTION__, __LINE__,
15337  "An internal error occurred while modifying a permission. "
15338  "It is unclear whether the permission has been modified or not. "
15339  "Diagnostics: Failure to receive response from manager daemon.",
15340  response_data);
15341  default:
15342  cmd_response_data_set_status_code (response_data,
15343  MHD_HTTP_INTERNAL_SERVER_ERROR);
15344  return gsad_message (
15345  credentials, "Internal error", __FUNCTION__, __LINE__,
15346  "An internal error occurred while modifying a permission. "
15347  "It is unclear whether the permission has been modified or not. "
15348  "Diagnostics: Internal Error.",
15349  response_data);
15350  }
15351 
15352  html = response_from_entity (connection, credentials, params, entity,
15353  "Save Permission", response_data);
15354  free_entity (entity);
15355  g_free (response);
15356  return html;
15357 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
int params_given(params_t *params, const char *name)
Get whether a param was given at all.
Definition: gsad_base.c:189
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmpf(), gsad_message(), params_given(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ save_port_list_gmp()

char* save_port_list_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Modify a port list, get all port list, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 15610 of file gsad_gmp.c.

15612 {
15613  int ret;
15614  gchar *html, *response;
15615  const char *port_list_id, *name, *comment;
15616  entity_t entity;
15617 
15618  port_list_id = params_value (params, "port_list_id");
15619  name = params_value (params, "name");
15620  comment = params_value (params, "comment");
15621 
15622  CHECK_VARIABLE_INVALID (port_list_id, "Save Port List");
15623  CHECK_VARIABLE_INVALID (name, "Save Port List");
15624  CHECK_VARIABLE_INVALID (comment, "Save Port List");
15625 
15626  /* Modify the Port List. */
15627 
15628  response = NULL;
15629  entity = NULL;
15630  ret = gmpf (connection, credentials, &response, &entity, response_data,
15631  "<modify_port_list port_list_id=\"%s\">"
15632  "<name>%s</name>"
15633  "<comment>%s</comment>"
15634  "</modify_port_list>",
15635  port_list_id, name, comment);
15636 
15637  switch (ret)
15638  {
15639  case 0:
15640  case -1:
15641  break;
15642  case 1:
15643  cmd_response_data_set_status_code (response_data,
15644  MHD_HTTP_INTERNAL_SERVER_ERROR);
15645  return gsad_message (
15646  credentials, "Internal error", __FUNCTION__, __LINE__,
15647  "An internal error occurred while saving a Port List. "
15648  "The Port List was not saved. "
15649  "Diagnostics: Failure to send command to manager daemon.",
15650  response_data);
15651  case 2:
15652  cmd_response_data_set_status_code (response_data,
15653  MHD_HTTP_INTERNAL_SERVER_ERROR);
15654  return gsad_message (
15655  credentials, "Internal error", __FUNCTION__, __LINE__,
15656  "An internal error occurred while saving a Port List. "
15657  "It is unclear whether the Port List has been saved or not. "
15658  "Diagnostics: Failure to receive response from manager daemon.",
15659  response_data);
15660  default:
15661  cmd_response_data_set_status_code (response_data,
15662  MHD_HTTP_INTERNAL_SERVER_ERROR);
15663  return gsad_message (
15664  credentials, "Internal error", __FUNCTION__, __LINE__,
15665  "An internal error occurred while saving a Port List. "
15666  "It is unclear whether the Port List has been saved or not. "
15667  "Diagnostics: Internal Error.",
15668  response_data);
15669  }
15670 
15671  html = response_from_entity (connection, credentials, params, entity,
15672  "Save Port List", response_data);
15673  free_entity (entity);
15674  g_free (response);
15675  return html;
15676 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmpf(), gsad_message(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ save_report_format_gmp()

char* save_report_format_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Save report_format, get next page, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 12661 of file gsad_gmp.c.

12664 {
12665  int ret;
12666  gchar *html, *response;
12667  params_t *preferences, *id_list_params, *include_id_lists;
12668  const char *report_format_id, *name, *summary, *enable;
12669  entity_t entity;
12670 
12671  report_format_id = params_value (params, "report_format_id");
12672  name = params_value (params, "name");
12673  summary = params_value (params, "summary");
12674  enable = params_value (params, "enable");
12675 
12676  CHECK_VARIABLE_INVALID (report_format_id, "Save Report Format");
12677  CHECK_VARIABLE_INVALID (name, "Save Report Format");
12678  CHECK_VARIABLE_INVALID (summary, "Save Report Format");
12679  CHECK_VARIABLE_INVALID (enable, "Save Report Format");
12680 
12681  id_list_params = params_values (params, "id_list:");
12682  include_id_lists = params_values (params, "include_id_list:");
12683  if (include_id_lists)
12684  {
12685  GHashTable *id_lists;
12686  param_t *param;
12687  gchar *param_name, *pref_name, *value, *old_values, *new_values;
12688  params_iterator_t iter;
12689  GHashTableIter hash_table_iter;
12690 
12691  id_lists =
12692  g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
12693 
12694  params_iterator_init (&iter, include_id_lists);
12695  while (params_iterator_next (&iter, &param_name, &param))
12696  {
12697  if (param->value == NULL)
12698  continue;
12699 
12700  g_hash_table_insert (id_lists, g_strdup (param_name), g_strdup (""));
12701  }
12702 
12703  params_iterator_init (&iter, id_list_params);
12704  while (params_iterator_next (&iter, &param_name, &param))
12705  {
12706  if (param->value == NULL)
12707  continue;
12708 
12709  gchar *colon_pos = strchr (param->value, ':');
12710 
12711  pref_name = g_strndup (param->value, colon_pos - param->value);
12712  value = g_strdup (colon_pos + 1);
12713 
12714  old_values = g_hash_table_lookup (id_lists, pref_name);
12715 
12716  if (old_values && strcmp (old_values, ""))
12717  {
12718  new_values = g_strdup_printf ("%s,%s", old_values, value);
12719  g_hash_table_insert (id_lists, pref_name, new_values);
12720  g_free (value);
12721  }
12722  else if (old_values)
12723  {
12724  g_hash_table_insert (id_lists, pref_name, value);
12725  }
12726  }
12727 
12728  g_hash_table_iter_init (&hash_table_iter, id_lists);
12729  while (g_hash_table_iter_next (&hash_table_iter, (void **) &pref_name,
12730  (void **) &value))
12731  {
12732  gchar *value_64;
12733 
12734  value_64 = strlen (value)
12735  ? g_base64_encode ((guchar *) value, strlen (value))
12736  : g_strdup ("");
12737 
12738  response = NULL;
12739  entity = NULL;
12740  ret =
12741  gmpf (connection, credentials, &response, &entity, response_data,
12742  "<modify_report_format"
12743  " report_format_id=\"%s\">"
12744  "<param>"
12745  "<name>%s</name>"
12746  "<value>%s</value>"
12747  "</param>"
12748  "</modify_report_format>",
12749  report_format_id, pref_name, value_64);
12750  g_free (value_64);
12751  switch (ret)
12752  {
12753  case 0:
12754  break;
12755  case 1:
12757  response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
12758  return gsad_message (
12759  credentials, "Internal error", __FUNCTION__, __LINE__,
12760  "An internal error occurred while saving a Report Format. "
12761  "The Report Format was not saved. "
12762  "Diagnostics: Failure to send command to manager daemon.",
12763  response_data);
12764  case 2:
12766  response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
12767  return gsad_message (
12768  credentials, "Internal error", __FUNCTION__, __LINE__,
12769  "An internal error occurred while saving a Report Format. "
12770  "It is unclear whether the Report Format has been saved or "
12771  "not. "
12772  "Diagnostics: Failure to receive response from manager daemon.",
12773  response_data);
12774  case -1:
12775  default:
12777  response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
12778  return gsad_message (
12779  credentials, "Internal error", __FUNCTION__, __LINE__,
12780  "An internal error occurred while saving a Report Format. "
12781  "It is unclear whether the Report Format has been saved or "
12782  "not. "
12783  "Diagnostics: Internal Error.",
12784  response_data);
12785  }
12786 
12787  /* TODO Check if succeeded. response_from_entity_if_failed? */
12788  }
12789  }
12790 
12791  /* Modify the Report Format. */
12792 
12793  preferences = params_values (params, "preference:");
12794  if (preferences)
12795  {
12796  param_t *param;
12797  gchar *param_name;
12798  params_iterator_t iter;
12799 
12800  /* The naming is a bit subtle here, because the HTTP request
12801  * parameters are called "param"s and so are the GMP report format
12802  * parameters. */
12803 
12804  params_iterator_init (&iter, preferences);
12805  while (params_iterator_next (&iter, &param_name, &param))
12806  {
12807  int type_start, type_end, count;
12808  /* LDAPsearch[entry]:Timeout value */
12809  count =
12810  sscanf (param_name, "%*[^[][%n%*[^]]%n]:", &type_start, &type_end);
12811  if (count == 0 && type_start > 0 && type_end > 0)
12812  {
12813  gchar *value;
12814 
12815  value =
12816  param->value_size
12817  ? g_base64_encode ((guchar *) param->value, param->value_size)
12818  : g_strdup ("");
12819 
12820  response = NULL;
12821  entity = NULL;
12822  ret = gmpf (connection, credentials, &response, &entity,
12823  response_data,
12824  "<modify_report_format"
12825  " report_format_id=\"%s\">"
12826  "<param>"
12827  "<name>%s</name>"
12828  "<value>%s</value>"
12829  "</param>"
12830  "</modify_report_format>",
12831  report_format_id, param_name + type_end + 2, value);
12832  g_free (value);
12833  switch (ret)
12834  {
12835  case 0:
12836  break;
12837  case 1:
12839  response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
12840  return gsad_message (
12841  credentials, "Internal error", __FUNCTION__, __LINE__,
12842  "An internal error occurred while saving a Report Format. "
12843  "The Report Format was not saved. "
12844  "Diagnostics: Failure to send command to manager daemon.",
12845  response_data);
12846  case 2:
12848  response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
12849  return gsad_message (
12850  credentials, "Internal error", __FUNCTION__, __LINE__,
12851  "An internal error occurred while saving a Report Format. "
12852  "It is unclear whether the Report Format has been saved or "
12853  "not. "
12854  "Diagnostics: Failure to receive response from manager "
12855  "daemon.",
12856  response_data);
12857  case -1:
12858  default:
12860  response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
12861  return gsad_message (
12862  credentials, "Internal error", __FUNCTION__, __LINE__,
12863  "An internal error occurred while saving a Report Format. "
12864  "It is unclear whether the Report Format has been saved or "
12865  "not. "
12866  "Diagnostics: Internal Error.",
12867  response_data);
12868  }
12869 
12870  /* TODO Check if succeeded. response_from_entity_if_failed? */
12871  }
12872  }
12873  }
12874 
12875  response = NULL;
12876  entity = NULL;
12877  ret = gmpf (connection, credentials, &response, &entity, response_data,
12878  "<modify_report_format"
12879  " report_format_id=\"%s\">"
12880  "<name>%s</name>"
12881  "<summary>%s</summary>"
12882  "<active>%s</active>"
12883  "</modify_report_format>",
12884  report_format_id, name, summary, enable);
12885 
12886  switch (ret)
12887  {
12888  case 0:
12889  break;
12890  case -1:
12891  return response;
12892  case 1:
12893  cmd_response_data_set_status_code (response_data,
12894  MHD_HTTP_INTERNAL_SERVER_ERROR);
12895  return gsad_message (
12896  credentials, "Internal error", __FUNCTION__, __LINE__,
12897  "An internal error occurred while saving a Report Format. "
12898  "The Report Format was not saved. "
12899  "Diagnostics: Failure to send command to manager daemon.",
12900  response_data);
12901  case 2:
12902  cmd_response_data_set_status_code (response_data,
12903  MHD_HTTP_INTERNAL_SERVER_ERROR);
12904  return gsad_message (
12905  credentials, "Internal error", __FUNCTION__, __LINE__,
12906  "An internal error occurred while saving a Report Format. "
12907  "It is unclear whether the Report Format has been saved or not. "
12908  "Diagnostics: Failure to receive response from manager daemon.",
12909  response_data);
12910  default:
12911  cmd_response_data_set_status_code (response_data,
12912  MHD_HTTP_INTERNAL_SERVER_ERROR);
12913  return gsad_message (
12914  credentials, "Internal error", __FUNCTION__, __LINE__,
12915  "An internal error occurred while saving a Report Format. "
12916  "It is unclear whether the Report Format has been saved or not. "
12917  "Diagnostics: Internal Error.",
12918  response_data);
12919  }
12920 
12921  html = response_from_entity (connection, credentials, params, entity,
12922  "Save Report Format", response_data);
12923  free_entity (entity);
12924  g_free (response);
12925  return html;
12926 }
params_t * params_values(params_t *params, const char *name)
Get values of param.
Definition: gsad_base.c:287
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
gchar * value
Definition: gsad_params.h:40
Structure of credential related information.
#define params_iterator_t
Definition: gsad_params.h:94
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
int value_size
Definition: gsad_params.h:46
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
Request parameter.
Definition: gsad_params.h:38
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
gboolean params_iterator_next(params_iterator_t *iterator, char **name, param_t **param)
Increment a params iterator.
Definition: gsad_base.c:394
#define params_iterator_init
Definition: gsad_params.h:96
#define params_t
Definition: gsad_params.h:31
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmpf(), gsad_message(), params_iterator_init, params_iterator_next(), params_iterator_t, params_t, params_value(), params_values(), response_from_entity(), param::value, and param::value_size.

Here is the call graph for this function:

◆ save_role_gmp()

char* save_role_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Modify a role, return the next page.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 16147 of file gsad_gmp.c.

16149 {
16150  int ret;
16151  gchar *html, *response;
16152  const char *role_id, *name, *comment, *users;
16153  entity_t entity;
16154 
16155  role_id = params_value (params, "role_id");
16156  name = params_value (params, "name");
16157  comment = params_value (params, "comment");
16158  users = params_value (params, "users");
16159 
16160  CHECK_VARIABLE_INVALID (role_id, "Save Role");
16161  CHECK_VARIABLE_INVALID (name, "Save Role");
16162  CHECK_VARIABLE_INVALID (comment, "Save Role");
16163  CHECK_VARIABLE_INVALID (users, "Save Role");
16164 
16165  /* Modify the Role. */
16166 
16167  response = NULL;
16168  entity = NULL;
16169  ret = gmpf (connection, credentials, &response, &entity, response_data,
16170  "<modify_role role_id=\"%s\">"
16171  "<name>%s</name>"
16172  "<comment>%s</comment>"
16173  "<users>%s</users>"
16174  "</modify_role>",
16175  role_id, name, comment, users);
16176 
16177  switch (ret)
16178  {
16179  case 0:
16180  case -1:
16181  break;
16182  case 1:
16183  cmd_response_data_set_status_code (response_data,
16184  MHD_HTTP_INTERNAL_SERVER_ERROR);
16185  return gsad_message (
16186  credentials, "Internal error", __FUNCTION__, __LINE__,
16187  "An internal error occurred while saving a role. "
16188  "The role was not saved. "
16189  "Diagnostics: Failure to send command to manager daemon.",
16190  response_data);
16191  case 2:
16192  cmd_response_data_set_status_code (response_data,
16193  MHD_HTTP_INTERNAL_SERVER_ERROR);
16194  return gsad_message (
16195  credentials, "Internal error", __FUNCTION__, __LINE__,
16196  "An internal error occurred while saving a role. "
16197  "It is unclear whether the role has been saved or not. "
16198  "Diagnostics: Failure to receive response from manager daemon.",
16199  response_data);
16200  default:
16201  cmd_response_data_set_status_code (response_data,
16202  MHD_HTTP_INTERNAL_SERVER_ERROR);
16203  return gsad_message (
16204  credentials, "Internal error", __FUNCTION__, __LINE__,
16205  "An internal error occurred while saving a role. "
16206  "It is unclear whether the role has been saved or not. "
16207  "Diagnostics: Internal Error.",
16208  response_data);
16209  }
16210 
16211  html = response_from_entity (connection, credentials, params, entity,
16212  "Save Role", response_data);
16213  free_entity (entity);
16214  g_free (response);
16215  return html;
16216 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
GPtrArray * users
User session data.
Definition: gsad_session.c:39
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmpf(), gsad_message(), params_value(), response_from_entity(), and users.

Here is the call graph for this function:

◆ save_scanner_gmp()

char* save_scanner_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Save scanner, get next page, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 11806 of file gsad_gmp.c.

11808 {
11809  gchar *response = NULL;
11810  entity_t entity = NULL;
11811  const char *scanner_id, *name, *comment, *port, *host, *type, *ca_pub;
11812  const char *credential_id, *which_cert;
11813  char *html;
11814  int ret, is_unix_socket, in_use;
11815 
11816  scanner_id = params_value (params, "scanner_id");
11817  name = params_value (params, "name");
11818  comment = params_value (params, "comment");
11819  host = params_value (params, "scanner_host");
11820  is_unix_socket = (host && *host == '/') ? 1 : 0;
11821  port = params_value (params, "port");
11822  type = params_value (params, "scanner_type");
11823  which_cert = params_value (params, "which_cert");
11824  ca_pub = params_value (params, "ca_pub");
11825  credential_id = params_value (params, "credential_id");
11826  CHECK_VARIABLE_INVALID (scanner_id, "Edit Scanner");
11827  CHECK_VARIABLE_INVALID (name, "Edit Scanner");
11828  if (params_given (params, "scanner_host") == 0)
11829  in_use = 1;
11830  else
11831  {
11832  in_use = 0;
11833  CHECK_VARIABLE_INVALID (host, "Edit Scanner");
11834  CHECK_VARIABLE_INVALID (port, "Edit Scanner");
11835  CHECK_VARIABLE_INVALID (type, "Edit Scanner");
11836  }
11837  if (is_unix_socket == 0)
11838  {
11839  CHECK_VARIABLE_INVALID (ca_pub, "Edit Scanner");
11840  CHECK_VARIABLE_INVALID (credential_id, "Edit Scanner");
11841  CHECK_VARIABLE_INVALID (which_cert, "Edit Scanner");
11842  }
11843 
11844  if (is_unix_socket)
11845  {
11846  ret = gmpf (connection, credentials, &response, &entity, response_data,
11847  "<modify_scanner scanner_id=\"%s\">"
11848  "<name>%s</name>"
11849  "<comment>%s</comment>"
11850  "</modify_scanner>",
11851  scanner_id, name, comment ?: "");
11852  }
11853  else if (strcmp (which_cert, "new") == 0
11854  || strcmp (which_cert, "default") == 0)
11855  {
11856  if (ca_pub == NULL)
11857  ca_pub = "";
11858  if (in_use)
11859  ret =
11860  gmpf (connection, credentials, &response, &entity, response_data,
11861  "<modify_scanner scanner_id=\"%s\">"
11862  "<name>%s</name>"
11863  "<comment>%s</comment>"
11864  "<ca_pub>%s</ca_pub>"
11865  "<credential id=\"%s\"/>"
11866  "</modify_scanner>",
11867  scanner_id, name, comment ?: "",
11868  strcmp (which_cert, "new") == 0 ? ca_pub : "", credential_id);
11869  else
11870  ret =
11871  gmpf (connection, credentials, &response, &entity, response_data,
11872  "<modify_scanner scanner_id=\"%s\">"
11873  "<name>%s</name>"
11874  "<comment>%s</comment>"
11875  "<host>%s</host>"
11876  "<port>%s</port>"
11877  "<type>%s</type>"
11878  "<ca_pub>%s</ca_pub>"
11879  "<credential id=\"%s\"/>"
11880  "</modify_scanner>",
11881  scanner_id, name, comment ?: "", host, port, type,
11882  strcmp (which_cert, "new") == 0 ? ca_pub : "", credential_id);
11883  }
11884  else
11885  {
11886  /* Using existing CA cert. */
11887  if (in_use)
11888  ret = gmpf (connection, credentials, &response, &entity, response_data,
11889  "<modify_scanner scanner_id=\"%s\">"
11890  "<name>%s</name>"
11891  "<comment>%s</comment>"
11892  "<credential id=\"%s\"/>"
11893  "</modify_scanner>",
11894  scanner_id, name, comment ?: "", credential_id);
11895  else
11896  ret = gmpf (connection, credentials, &response, &entity, response_data,
11897  "<modify_scanner scanner_id=\"%s\">"
11898  "<name>%s</name>"
11899  "<comment>%s</comment>"
11900  "<host>%s</host>"
11901  "<port>%s</port>"
11902  "<type>%s</type>"
11903  "<credential id=\"%s\"/>"
11904  "</modify_scanner>",
11905  scanner_id, name, comment ?: "", host, port, type,
11906  credential_id);
11907  }
11908 
11909  switch (ret)
11910  {
11911  case 0:
11912  case -1:
11913  break;
11914  case 1:
11915  cmd_response_data_set_status_code (response_data,
11916  MHD_HTTP_INTERNAL_SERVER_ERROR);
11917  return gsad_message (
11918  credentials, "Internal error", __FUNCTION__, __LINE__,
11919  "An internal error occurred while saving a scanner. "
11920  "The scanner remains the same. "
11921  "Diagnostics: Failure to send command to manager daemon.",
11922  response_data);
11923  case 2:
11924  cmd_response_data_set_status_code (response_data,
11925  MHD_HTTP_INTERNAL_SERVER_ERROR);
11926  return gsad_message (
11927  credentials, "Internal error", __FUNCTION__, __LINE__,
11928  "An internal error occurred while saving a scanner. "
11929  "It is unclear whether the scanner has been saved or not. "
11930  "Diagnostics: Failure to receive response from manager daemon.",
11931  response_data);
11932  default:
11933  cmd_response_data_set_status_code (response_data,
11934  MHD_HTTP_INTERNAL_SERVER_ERROR);
11935  return gsad_message (
11936  credentials, "Internal error", __FUNCTION__, __LINE__,
11937  "An internal error occurred while saving a scanner. "
11938  "It is unclear whether the scanner has been saved or not. "
11939  "Diagnostics: Internal Error.",
11940  response_data);
11941  }
11942 
11943  html = response_from_entity (connection, credentials, params, entity,
11944  "Save Scanner", response_data);
11945 
11946  free_entity (entity);
11947  g_free (response);
11948  return html;
11949 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
int params_given(params_t *params, const char *name)
Get whether a param was given at all.
Definition: gsad_base.c:189
gboolean is_unix_socket()
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmpf(), gsad_message(), is_unix_socket(), params_given(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ save_schedule_gmp()

char* save_schedule_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Save schedule, get next page, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 16759 of file gsad_gmp.c.

16761 {
16762  gchar *response;
16763  entity_t entity;
16764  const char *schedule_id, *name, *comment, *timezone, *icalendar;
16765  char *ret;
16766 
16767  schedule_id = params_value (params, "schedule_id");
16768  name = params_value (params, "name");
16769  comment = params_value (params, "comment");
16770  icalendar = params_value (params, "icalendar");
16771  timezone = params_value (params, "timezone");
16772 
16773  CHECK_VARIABLE_INVALID (schedule_id, "Save Schedule");
16774  CHECK_VARIABLE_INVALID (name, "Save Schedule");
16775  CHECK_VARIABLE_INVALID (comment, "Save Schedule");
16776  CHECK_VARIABLE_INVALID (icalendar, "Save Schedule");
16777  CHECK_VARIABLE_INVALID (timezone, "Save Schedule");
16778 
16779  response = NULL;
16780  entity = NULL;
16781  switch (gmpf (connection, credentials, &response, &entity, response_data,
16782  "<modify_schedule schedule_id=\"%s\">"
16783  "<name>%s</name>"
16784  "<comment>%s</comment>"
16785  "<timezone>%s</timezone>"
16786  "<icalendar>%s</icalendar>"
16787  "</modify_schedule>",
16788  schedule_id, name ? name : "", comment ? comment : "", timezone,
16789  icalendar))
16790  {
16791  case 0:
16792  case -1:
16793  break;
16794  case 1:
16795  cmd_response_data_set_status_code (response_data,
16796  MHD_HTTP_INTERNAL_SERVER_ERROR);
16797  return gsad_message (
16798  credentials, "Internal error", __FUNCTION__, __LINE__,
16799  "An internal error occurred while saving a schedule. "
16800  "The schedule remains the same. "
16801  "Diagnostics: Failure to send command to manager daemon.",
16802  response_data);
16803  case 2:
16804  cmd_response_data_set_status_code (response_data,
16805  MHD_HTTP_INTERNAL_SERVER_ERROR);
16806  return gsad_message (
16807  credentials, "Internal error", __FUNCTION__, __LINE__,
16808  "An internal error occurred while saving a schedule. "
16809  "It is unclear whether the schedule has been saved or not. "
16810  "Diagnostics: Failure to receive response from manager daemon.",
16811  response_data);
16812  default:
16813  cmd_response_data_set_status_code (response_data,
16814  MHD_HTTP_INTERNAL_SERVER_ERROR);
16815  return gsad_message (
16816  credentials, "Internal error", __FUNCTION__, __LINE__,
16817  "An internal error occurred while saving a schedule. "
16818  "It is unclear whether the schedule has been saved or not. "
16819  "Diagnostics: Internal Error.",
16820  response_data);
16821  }
16822 
16823  ret = response_from_entity (connection, credentials, params, entity,
16824  "Save Schedule", response_data);
16825  free_entity (entity);
16826  g_free (response);
16827  return ret;
16828 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmpf(), gsad_message(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ save_setting_gmp()

char* save_setting_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Save user setting.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
An action response.

Definition at line 17872 of file gsad_gmp.c.

17874 {
17875  const gchar *setting_id = params_value (params, "setting_id");
17876  const gchar *setting_value = params_value (params, "setting_value");
17877  const gchar *setting_name = NULL;
17878 
17879  CHECK_VARIABLE_INVALID (setting_id, "Save Setting");
17880  CHECK_VARIABLE_INVALID (setting_value, "Save Setting");
17881 
17882  if (params_given (params, "setting_name"))
17883  {
17884  setting_name = params_value (params, "setting_name");
17885  CHECK_VARIABLE_INVALID (setting_name, "Save Settings")
17886  }
17887 
17888  gchar *value_64 =
17889  g_base64_encode ((guchar *) setting_value, strlen (setting_value));
17890  gchar *html;
17891  gchar *response = NULL;
17892  entity_t entity = NULL;
17893  int ret;
17894  GString *xml = g_string_new ("");
17895 
17896  xml_string_append (xml,
17897  "<modify_setting setting_id=\"%s\">"
17898  "<value>%s</value>",
17899  setting_id, value_64);
17900 
17901  if (setting_name)
17902  {
17903  xml_string_append (xml, "<name>%s</name>", setting_name);
17904  }
17905 
17906  xml_string_append (xml, "</modify_setting>");
17907 
17909 
17910  ret =
17911  gmp (connection, credentials, &response, &entity, response_data, xml->str);
17912 
17913  g_free (value_64);
17914  g_string_free (xml, TRUE);
17915 
17916  switch (ret)
17917  {
17918  case 0:
17919  case -1:
17920  break;
17921  case 1:
17922  cmd_response_data_set_status_code (response_data,
17923  MHD_HTTP_INTERNAL_SERVER_ERROR);
17924  return gsad_message (
17925  credentials, "Internal error", __FUNCTION__, __LINE__,
17926  "An internal error occurred while saving settings. "
17927  "It is unclear whether all the settings were saved. "
17928  "Diagnostics: Failure to send command to manager daemon.",
17929  response_data);
17930  case 2:
17931 
17932  cmd_response_data_set_status_code (response_data,
17933  MHD_HTTP_INTERNAL_SERVER_ERROR);
17934  return gsad_message (
17935  credentials, "Internal error", __FUNCTION__, __LINE__,
17936  "An internal error occurred while saving settings. "
17937  "It is unclear whether all the settings were saved. "
17938  "Diagnostics: Failure to receive response from manager daemon.",
17939  response_data);
17940  default:
17941 
17942  cmd_response_data_set_status_code (response_data,
17943  MHD_HTTP_INTERNAL_SERVER_ERROR);
17944  return gsad_message (credentials, "Internal error", __FUNCTION__,
17945  __LINE__,
17946  "An internal error occurred while saving settings. "
17947  "It is unclear whether all the settings were saved. "
17948  "Diagnostics: Internal Error.",
17949  response_data);
17950  }
17951  html = response_from_entity (connection, credentials, params, entity,
17952  "Save Setting", response_data);
17953  free_entity (entity);
17954  g_free (response);
17955  return html;
17956 }
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
int params_given(params_t *params, const char *name)
Get whether a param was given at all.
Definition: gsad_base.c:189
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
void cmd_response_data_set_content_type(cmd_response_data_t *data, content_type_t content_type)
Set content type of cmd_response_data_t struct.
Definition: gsad_cmd.c:134
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_content_type(), cmd_response_data_set_status_code(), gmp(), GSAD_CONTENT_TYPE_APP_XML, gsad_message(), params_given(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ save_tag_gmp()

char* save_tag_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Modify a tag, get all tags, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 7228 of file gsad_gmp.c.

7230 {
7231  gchar *response;
7232  const char *name, *comment, *filter, *value, *resource_type, *active;
7233  const char *resources_action;
7234  params_t *resource_ids;
7235  const char *tag_id;
7236  GString *command;
7237  entity_t entity;
7238  char *ret;
7239 
7240  tag_id = params_value (params, "tag_id");
7241  name = params_value (params, "tag_name");
7242  comment = params_value (params, "comment");
7243  filter = params_value (params, "filter");
7244  value = params_value (params, "tag_value");
7245  resource_type = params_value (params, "resource_type");
7246  resource_ids = params_values (params, "resource_ids:");
7247  resources_action = params_value (params, "resources_action");
7248  active = params_value (params, "active");
7249 
7250  CHECK_VARIABLE_INVALID (tag_id, "Save Tag")
7251  CHECK_VARIABLE_INVALID (name, "Save Tag")
7252  CHECK_VARIABLE_INVALID (comment, "Save Tag")
7253  if (params_given (params, "filter"))
7254  CHECK_VARIABLE_INVALID (filter, "Save Tag")
7255  CHECK_VARIABLE_INVALID (value, "Save Tag")
7256  if (params_given (params, "resources_action"))
7257  CHECK_VARIABLE_INVALID (resources_action, "Save Tag")
7258  CHECK_VARIABLE_INVALID (resource_type, "Save Tag")
7259  CHECK_VARIABLE_INVALID (active, "Save Tag")
7260 
7261  command = g_string_new ("");
7262 
7263  xml_string_append (command,
7264  "<modify_tag tag_id=\"%s\">"
7265  "<name>%s</name>"
7266  "<comment>%s</comment>"
7267  "<value>%s</value>"
7268  "<active>%s</active>"
7269  "<resources action=\"%s\" filter=\"%s\">"
7270  "<type>%s</type>",
7271  tag_id, name, comment, value, active,
7272  resources_action ? resources_action : "",
7273  filter ? filter : "", resource_type);
7274 
7275  if (resource_ids)
7276  {
7277  params_iterator_t iter;
7278  char *name;
7279  param_t *param;
7280 
7281  params_iterator_init (&iter, resource_ids);
7282  while (params_iterator_next (&iter, &name, &param))
7283  if (param->value && strcmp (param->value, "0"))
7284  g_string_append_printf (command, "<resource id=\"%s\"/>",
7285  param->value ? param->value : "");
7286  }
7287 
7288  xml_string_append (command, "</resources>"
7289  "</modify_tag>");
7290 
7291  response = NULL;
7292  entity = NULL;
7293  switch (gmp (connection, credentials, &response, &entity, response_data,
7294  command->str))
7295  {
7296  case 0:
7297  case -1:
7298  break;
7299  case 1:
7300  cmd_response_data_set_status_code (response_data,
7301  MHD_HTTP_INTERNAL_SERVER_ERROR);
7302  g_string_free (command, TRUE);
7303  return gsad_message (credentials, "Internal error", __FUNCTION__,
7304  __LINE__,
7305  "An internal error occurred while saving a tag. "
7306  "The tag remains the same. "
7307  "Diagnostics: Failure to send command to "
7308  "manager daemon.",
7309  response_data);
7310  case 2:
7311  cmd_response_data_set_status_code (response_data,
7312  MHD_HTTP_INTERNAL_SERVER_ERROR);
7313  g_string_free (command, TRUE);
7314  return gsad_message (credentials, "Internal error", __FUNCTION__,
7315  __LINE__,
7316  "An internal error occurred while saving a tag. "
7317  "It is unclear whether the tag has been saved "
7318  "or not. "
7319  "Diagnostics: Failure to receive response from "
7320  "manager daemon.",
7321  response_data);
7322  default:
7323  cmd_response_data_set_status_code (response_data,
7324  MHD_HTTP_INTERNAL_SERVER_ERROR);
7325  g_string_free (command, TRUE);
7326  return gsad_message (credentials, "Internal error", __FUNCTION__,
7327  __LINE__,
7328  "An internal error occurred while saving a tag. "
7329  "It is unclear whether the tag has been saved "
7330  "or not. "
7331  "Diagnostics: Internal Error.",
7332  response_data);
7333  }
7334 
7335  g_string_free (command, TRUE);
7336  ret = response_from_entity (connection, credentials, params, entity,
7337  "Save Tag", response_data);
7338 
7339  free_entity (entity);
7340  g_free (response);
7341  return ret;
7342 }
params_t * params_values(params_t *params, const char *name)
Get values of param.
Definition: gsad_base.c:287
gchar * value
Definition: gsad_params.h:40
Structure of credential related information.
#define params_iterator_t
Definition: gsad_params.h:94
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
int params_given(params_t *params, const char *name)
Get whether a param was given at all.
Definition: gsad_base.c:189
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
Request parameter.
Definition: gsad_params.h:38
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
gboolean params_iterator_next(params_iterator_t *iterator, char **name, param_t **param)
Increment a params iterator.
Definition: gsad_base.c:394
#define params_iterator_init
Definition: gsad_params.h:96
#define params_t
Definition: gsad_params.h:31
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmp(), gsad_message(), params_given(), params_iterator_init, params_iterator_next(), params_iterator_t, params_t, params_value(), params_values(), response_from_entity(), and param::value.

Here is the call graph for this function:

◆ save_target_gmp()

char* save_target_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Modify a target, get all targets, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 7608 of file gsad_gmp.c.

7610 {
7611  gchar *html, *response;
7612  const char *name, *hosts, *exclude_hosts, *comment;
7613  const char *target_ssh_credential, *port, *target_smb_credential;
7614  const char *target_esxi_credential, *target_snmp_credential;
7615  const char *target_source, *target_exclude_source;
7616  const char *target_id, *port_list_id, *reverse_lookup_only;
7617  const char *reverse_lookup_unify, *alive_tests, *in_use;
7618  GString *command;
7619 
7620  alive_tests = params_value (params, "alive_tests");
7621  name = params_value (params, "name");
7622  comment = params_value (params, "comment");
7623  in_use = params_value (params, "in_use");
7624  target_id = params_value (params, "target_id");
7625 
7626  CHECK_VARIABLE_INVALID (name, "Save Target");
7627  CHECK_VARIABLE_INVALID (target_id, "Save Target");
7628  CHECK_VARIABLE_INVALID (comment, "Save Target");
7629  CHECK_VARIABLE_INVALID (alive_tests, "Save Target");
7630  CHECK_VARIABLE_INVALID (in_use, "Save Target");
7631 
7632  if (str_equal (in_use, "1"))
7633  {
7634  entity_t entity;
7635  int ret;
7636 
7637  /* Target is in use. Modify fewer fields. */
7638 
7639  command = g_string_new ("");
7640  xml_string_append (command,
7641  "<modify_target target_id=\"%s\">"
7642  "<name>%s</name>"
7643  "<comment>%s</comment>"
7644  "<alive_tests>%s</alive_tests>"
7645  "</modify_target>",
7646  target_id, name ? name : "", comment ? comment : "",
7647  alive_tests);
7648 
7649  response = NULL;
7650  entity = NULL;
7651  ret = gmp (connection, credentials, &response, &entity, response_data,
7652  command->str);
7653  g_string_free (command, TRUE);
7654  switch (ret)
7655  {
7656  case 0:
7657  case -1:
7658  break;
7659  case 1:
7660  cmd_response_data_set_status_code (response_data,
7661  MHD_HTTP_INTERNAL_SERVER_ERROR);
7662  return gsad_message (
7663  credentials, "Internal error", __FUNCTION__, __LINE__,
7664  "An internal error occurred while saving a target. "
7665  "The target remains the same. "
7666  "Diagnostics: Failure to send command to manager daemon.",
7667  response_data);
7668  case 2:
7669  cmd_response_data_set_status_code (response_data,
7670  MHD_HTTP_INTERNAL_SERVER_ERROR);
7671  return gsad_message (
7672  credentials, "Internal error", __FUNCTION__, __LINE__,
7673  "An internal error occurred while saving a target. "
7674  "It is unclear whether the target has been saved or not. "
7675  "Diagnostics: Failure to receive response from manager daemon.",
7676  response_data);
7677  default:
7678  cmd_response_data_set_status_code (response_data,
7679  MHD_HTTP_INTERNAL_SERVER_ERROR);
7680  return gsad_message (
7681  credentials, "Internal error", __FUNCTION__, __LINE__,
7682  "An internal error occurred while saving a target. "
7683  "It is unclear whether the target has been saved or not. "
7684  "Diagnostics: Internal Error.",
7685  response_data);
7686  }
7687 
7688  html = response_from_entity (connection, credentials, params, entity,
7689  "Save Target", response_data);
7690 
7691  free_entity (entity);
7692  g_free (response);
7693  return html;
7694  }
7695 
7696  hosts = params_value (params, "hosts");
7697  exclude_hosts = params_value (params, "exclude_hosts");
7698  reverse_lookup_only = params_value (params, "reverse_lookup_only");
7699  reverse_lookup_unify = params_value (params, "reverse_lookup_unify");
7700  target_source = params_value (params, "target_source");
7701  target_exclude_source = params_value (params, "target_exclude_source");
7702  port_list_id = params_value (params, "port_list_id");
7703  target_ssh_credential = params_value (params, "ssh_credential_id");
7704  port = params_value (params, "port");
7705  target_smb_credential = params_value (params, "smb_credential_id");
7706  target_esxi_credential = params_value (params, "esxi_credential_id");
7707  target_snmp_credential = params_value (params, "snmp_credential_id");
7708 
7709  CHECK_VARIABLE_INVALID (target_source, "Save Target");
7710  CHECK_VARIABLE_INVALID (target_exclude_source, "Save Target");
7711  CHECK_VARIABLE_INVALID (port_list_id, "Save Target");
7712  CHECK_VARIABLE_INVALID (target_ssh_credential, "Save Target");
7713  CHECK_VARIABLE_INVALID (target_smb_credential, "Save Target");
7714  CHECK_VARIABLE_INVALID (target_esxi_credential, "Save Target");
7715  CHECK_VARIABLE_INVALID (target_snmp_credential, "Save Target");
7716 
7717  if (strcmp (target_ssh_credential, "--")
7718  && strcmp (target_ssh_credential, "0"))
7719  CHECK_VARIABLE_INVALID (port, "Save Target");
7720 
7721  if (str_equal (target_source, "manual"))
7722  {
7723  CHECK_VARIABLE_INVALID (hosts, "Save Target")
7724  }
7725 
7726  {
7727  int ret;
7728  gchar *ssh_credentials_element, *smb_credentials_element;
7729  gchar *esxi_credentials_element, *snmp_credentials_element;
7730  gchar *comment_element;
7731  entity_t entity;
7732 
7733  if (comment)
7734  comment_element = g_strdup_printf ("<comment>%s</comment>", comment);
7735  else
7736  comment_element = g_strdup ("");
7737 
7738  if (str_equal (target_ssh_credential, "--"))
7739  ssh_credentials_element = g_strdup ("");
7740  else
7741  ssh_credentials_element = g_strdup_printf ("<ssh_credential id=\"%s\">"
7742  "<port>%s</port>"
7743  "</ssh_credential>",
7744  target_ssh_credential, port);
7745 
7746  if (str_equal (target_smb_credential, "--"))
7747  smb_credentials_element = g_strdup ("");
7748  else
7749  smb_credentials_element =
7750  g_strdup_printf ("<smb_credential id=\"%s\"/>", target_smb_credential);
7751 
7752  if (str_equal (target_esxi_credential, "--"))
7753  esxi_credentials_element = g_strdup ("");
7754  else
7755  esxi_credentials_element = g_strdup_printf (
7756  "<esxi_credential id=\"%s\"/>", target_esxi_credential);
7757 
7758  if (str_equal (target_snmp_credential, "--"))
7759  snmp_credentials_element = g_strdup ("");
7760  else
7761  snmp_credentials_element = g_strdup_printf (
7762  "<snmp_credential id=\"%s\"/>", target_snmp_credential);
7763 
7764  command = g_string_new ("");
7765  xml_string_append (
7766  command,
7767  "<modify_target target_id=\"%s\">"
7768  "<name>%s</name>"
7769  "<hosts>%s</hosts>"
7770  "<exclude_hosts>%s</exclude_hosts>"
7771  "<reverse_lookup_only>%s</reverse_lookup_only>"
7772  "<reverse_lookup_unify>%s</reverse_lookup_unify>"
7773  "<port_list id=\"%s\"/>"
7774  "<alive_tests>%s</alive_tests>",
7775  target_id, name,
7776  str_equal (target_source, "file") ? params_value (params, "file") : hosts,
7777  str_equal (target_exclude_source, "file")
7778  ? params_value (params, "exclude_file")
7779  : exclude_hosts,
7780  reverse_lookup_only ? reverse_lookup_only : "0",
7781  reverse_lookup_unify ? reverse_lookup_unify : "0", port_list_id,
7782  alive_tests);
7783 
7784  g_string_append_printf (command,
7785  "%s%s%s%s%s"
7786  "</modify_target>",
7787  comment_element, ssh_credentials_element,
7788  smb_credentials_element, esxi_credentials_element,
7789  snmp_credentials_element);
7790 
7791  g_free (comment_element);
7792  g_free (ssh_credentials_element);
7793  g_free (smb_credentials_element);
7794  g_free (esxi_credentials_element);
7795  g_free (snmp_credentials_element);
7796 
7797  /* Modify the target. */
7798 
7799  ret = gvm_connection_sendf (connection, "%s", command->str);
7800  g_string_free (command, TRUE);
7801 
7802  if (ret == -1)
7803  {
7804  cmd_response_data_set_status_code (response_data,
7805  MHD_HTTP_INTERNAL_SERVER_ERROR);
7806  return gsad_message (
7807  credentials, "Internal error", __FUNCTION__, __LINE__,
7808  "An internal error occurred while modifying target. "
7809  "No target was modified. "
7810  "Diagnostics: Failure to send command to manager daemon.",
7811  response_data);
7812  }
7813 
7814  entity = NULL;
7815  if (read_entity_and_text_c (connection, &entity, &response))
7816  {
7817  cmd_response_data_set_status_code (response_data,
7818  MHD_HTTP_INTERNAL_SERVER_ERROR);
7819  return gsad_message (
7820  credentials, "Internal error", __FUNCTION__, __LINE__,
7821  "An internal error occurred while modifying a target. "
7822  "It is unclear whether the target has been modified or not. "
7823  "Diagnostics: Failure to receive response from manager daemon.",
7824  response_data);
7825  }
7826 
7827  html = response_from_entity (connection, credentials, params, entity,
7828  "Save Target", response_data);
7829  }
7830 
7831  /* Pass response to handler of following page. */
7832 
7833  return html;
7834 }
Structure of credential related information.
gboolean str_equal(const gchar *str1, const gchar *str2)
Check if two strings are equal.
Definition: utils.c:35
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmp(), gsad_message(), params_value(), response_from_entity(), and str_equal().

Here is the call graph for this function:

◆ save_task_gmp()

char* save_task_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Save task, get next page, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 2828 of file gsad_gmp.c.

2830 {
2831  gchar *html, *response, *format;
2832  const char *comment, *name, *schedule_id, *in_assets;
2833  const char *scanner_id, *task_id, *max_checks, *max_hosts;
2834  const char *config_id, *target_id, *hosts_ordering, *alterable, *source_iface;
2835  const char *scanner_type, *schedule_periods, *auto_delete, *auto_delete_data;
2836  const char *apply_overrides, *min_qod;
2837  int ret;
2838  params_t *alerts;
2839  GString *alert_element;
2840  entity_t entity;
2841 
2842  alterable = params_value (params, "alterable");
2843  apply_overrides = params_value (params, "apply_overrides");
2844  auto_delete = params_value (params, "auto_delete");
2845  auto_delete_data = params_value (params, "auto_delete_data");
2846  comment = params_value (params, "comment");
2847  config_id = params_value (params, "config_id");
2848  hosts_ordering = params_value (params, "hosts_ordering");
2849  in_assets = params_value (params, "in_assets");
2850  max_checks = params_value (params, "max_checks");
2851  max_hosts = params_value (params, "max_hosts");
2852  min_qod = params_value (params, "min_qod");
2853  name = params_value (params, "name");
2854  scanner_id = params_value (params, "scanner_id");
2855  scanner_type = params_value (params, "scanner_type");
2856  schedule_id = params_value (params, "schedule_id");
2857  schedule_periods = params_value (params, "schedule_periods");
2858  source_iface = params_value (params, "source_iface");
2859  target_id = params_value (params, "target_id");
2860  task_id = params_value (params, "task_id");
2861 
2862  if (scanner_type != NULL)
2863  {
2864  CHECK_VARIABLE_INVALID (scanner_type, "Save Task");
2865  if (!strcmp (scanner_type, "1"))
2866  {
2867  hosts_ordering = "";
2868  max_checks = "";
2869  source_iface = "";
2870  max_hosts = "";
2871  }
2872  else if (!strcmp (scanner_type, "3"))
2873  {
2874  config_id = "0";
2875  hosts_ordering = "";
2876  max_checks = "";
2877  source_iface = "";
2878  max_hosts = "";
2879  }
2880  }
2881 
2882  CHECK_VARIABLE_INVALID (name, "Save Task");
2883  CHECK_VARIABLE_INVALID (comment, "Save Task");
2884  CHECK_VARIABLE_INVALID (target_id, "Save Task");
2885  CHECK_VARIABLE_INVALID (hosts_ordering, "Save Task");
2886  CHECK_VARIABLE_INVALID (config_id, "Save Task");
2887  CHECK_VARIABLE_INVALID (schedule_id, "Save Task");
2888  if (params_given (params, "schedule_periods"))
2889  {
2890  CHECK_VARIABLE_INVALID (schedule_periods, "Save Task");
2891  }
2892  else
2893  schedule_periods = "0";
2894  CHECK_VARIABLE_INVALID (scanner_id, "Save Task");
2895  CHECK_VARIABLE_INVALID (task_id, "Save Task");
2896  CHECK_VARIABLE_INVALID (max_checks, "Save Task");
2897  CHECK_VARIABLE_INVALID (source_iface, "Save Task");
2898  CHECK_VARIABLE_INVALID (auto_delete, "Save Task");
2899  CHECK_VARIABLE_INVALID (auto_delete_data, "Save Task");
2900  CHECK_VARIABLE_INVALID (max_hosts, "Save Task");
2901  CHECK_VARIABLE_INVALID (in_assets, "Save Task");
2902 
2903  if (!strcmp (in_assets, "1"))
2904  {
2905  CHECK_VARIABLE_INVALID (apply_overrides, "Save Task");
2906  CHECK_VARIABLE_INVALID (min_qod, "Save Task");
2907  }
2908  else
2909  {
2910  if (!params_given (params, "apply_overrides")
2911  || !params_valid (params, "apply_overrides"))
2912  apply_overrides = "";
2913 
2914  if (!params_given (params, "min_qod")
2915  || !params_valid (params, "min_qod"))
2916  min_qod = "";
2917  }
2918 
2919  alert_element = g_string_new ("");
2920  if (params_given (params, "alert_id_optional:"))
2921  alerts = params_values (params, "alert_id_optional:");
2922  else
2923  alerts = params_values (params, "alert_ids:");
2924 
2925  if (alerts)
2926  {
2927  params_iterator_t iter;
2928  char *name;
2929  param_t *param;
2930 
2931  params_iterator_init (&iter, alerts);
2932  while (params_iterator_next (&iter, &name, &param))
2933  {
2934  if (param->value && strcmp (param->value, "0"))
2935  g_string_append_printf (alert_element, "<alert id=\"%s\"/>",
2936  param->value ? param->value : "");
2937  }
2938  }
2939 
2940  // Remove Alerts from Task if none are given.
2941  if (strcmp (alert_element->str, "") == 0)
2942  g_string_append_printf (alert_element, "<alert id=\"0\"/>");
2943 
2944  format = g_strdup_printf (
2945  "<modify_task task_id=\"%%s\">"
2946  "<name>%%s</name>"
2947  "<comment>%%s</comment>"
2948  "<hosts_ordering>%s</hosts_ordering>"
2949  "%s"
2950  "<target id=\"%%s\"/>"
2951  "<config id=\"%%s\"/>"
2952  "<schedule id=\"%%s\"/>"
2953  "<schedule_periods>%%s</schedule_periods>"
2954  "<scanner id=\"%%s\"/>"
2955  "<preferences>"
2956  "<preference>"
2957  "<scanner_name>max_checks</scanner_name>"
2958  "<value>%%s</value>"
2959  "</preference>"
2960  "<preference>"
2961  "<scanner_name>max_hosts</scanner_name>"
2962  "<value>%%s</value>"
2963  "</preference>"
2964  "<preference>"
2965  "<scanner_name>in_assets</scanner_name>"
2966  "<value>%%s</value>"
2967  "</preference>"
2968  "<preference>"
2969  "<scanner_name>assets_apply_overrides</scanner_name>"
2970  "<value>%%s</value>"
2971  "</preference>"
2972  "<preference>"
2973  "<scanner_name>assets_min_qod</scanner_name>"
2974  "<value>%%s</value>"
2975  "</preference>"
2976  "<preference>"
2977  "<scanner_name>source_iface</scanner_name>"
2978  "<value>%%s</value>"
2979  "</preference>"
2980  "<preference>"
2981  "<scanner_name>auto_delete</scanner_name>"
2982  "<value>%%s</value>"
2983  "</preference>"
2984  "<preference>"
2985  "<scanner_name>auto_delete_data</scanner_name>"
2986  "<value>%%s</value>"
2987  "</preference>"
2988  "</preferences>"
2989  "%s%i%s"
2990  "</modify_task>",
2991  hosts_ordering, alert_element->str, alterable ? "<alterable>" : "",
2992  alterable ? strcmp (alterable, "0") : 0, alterable ? "</alterable>" : "");
2993  response = NULL;
2994  entity = NULL;
2995  ret = gmpf (connection, credentials, &response, &entity, response_data,
2996  format, task_id, name, comment, target_id, config_id, schedule_id,
2997  schedule_periods, scanner_id, max_checks, max_hosts,
2998  strcmp (in_assets, "0") ? "yes" : "no",
2999  strcmp (apply_overrides, "0") ? "yes" : "no", min_qod,
3000  source_iface, auto_delete, auto_delete_data);
3001  g_free (format);
3002 
3003  g_string_free (alert_element, TRUE);
3004 
3005  switch (ret)
3006  {
3007  case 0:
3008  case -1:
3009  break;
3010  case 1:
3011  cmd_response_data_set_status_code (response_data,
3012  MHD_HTTP_INTERNAL_SERVER_ERROR);
3013  return gsad_message (
3014  credentials, "Internal error", __FUNCTION__, __LINE__,
3015  "An internal error occurred while saving a task. "
3016  "The task was not saved. "
3017  "Diagnostics: Failure to send command to manager daemon.",
3018  response_data);
3019  case 2:
3020  cmd_response_data_set_status_code (response_data,
3021  MHD_HTTP_INTERNAL_SERVER_ERROR);
3022  return gsad_message (
3023  credentials, "Internal error", __FUNCTION__, __LINE__,
3024  "An internal error occurred while saving a task. "
3025  "It is unclear whether the task has been saved or not. "
3026  "Diagnostics: Failure to receive response from manager daemon.",
3027  response_data);
3028  default:
3029  cmd_response_data_set_status_code (response_data,
3030  MHD_HTTP_INTERNAL_SERVER_ERROR);
3031  return gsad_message (
3032  credentials, "Internal error", __FUNCTION__, __LINE__,
3033  "An internal error occurred while saving a task. "
3034  "It is unclear whether the task has been saved or not. "
3035  "Diagnostics: Internal Error.",
3036  response_data);
3037  }
3038 
3039  html = response_from_entity (connection, credentials, params, entity,
3040  "Save Task", response_data);
3041  free_entity (entity);
3042  g_free (response);
3043  return html;
3044 }
params_t * params_values(params_t *params, const char *name)
Get values of param.
Definition: gsad_base.c:287
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
gchar * value
Definition: gsad_params.h:40
Structure of credential related information.
#define params_iterator_t
Definition: gsad_params.h:94
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
int params_given(params_t *params, const char *name)
Get whether a param was given at all.
Definition: gsad_base.c:189
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
Request parameter.
Definition: gsad_params.h:38
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
gboolean params_iterator_next(params_iterator_t *iterator, char **name, param_t **param)
Increment a params iterator.
Definition: gsad_base.c:394
#define params_iterator_init
Definition: gsad_params.h:96
#define params_t
Definition: gsad_params.h:31
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
int params_valid(params_t *params, const char *name)
Get whether a param is valid.
Definition: gsad_base.c:303

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmpf(), gsad_message(), params_given(), params_iterator_init, params_iterator_next(), params_iterator_t, params_t, params_valid(), params_value(), params_values(), response_from_entity(), and param::value.

Here is the call graph for this function:

◆ save_ticket_gmp()

char* save_ticket_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Modify a ticket.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 19059 of file gsad_gmp.c.

19061 {
19062  gchar *response = NULL;
19063  entity_t entity = NULL;
19064  const gchar *ticket_id, *status, *open_note, *fixed_note, *closed_note;
19065  const gchar *user_id;
19066  gchar *ret;
19067 
19068  ticket_id = params_value (params, "ticket_id");
19069  status = params_value (params, "ticket_status");
19070  open_note = params_value (params, "open_note");
19071  fixed_note = params_value (params, "fixed_note");
19072  closed_note = params_value (params, "closed_note");
19073  user_id = params_value (params, "user_id");
19074 
19075  CHECK_VARIABLE_INVALID (ticket_id, "Save Ticket");
19076  CHECK_VARIABLE_INVALID (status, "Save Ticket");
19077  CHECK_VARIABLE_INVALID (user_id, "Save Ticket");
19078  CHECK_VARIABLE_INVALID (open_note, "Save Ticket");
19079  CHECK_VARIABLE_INVALID (fixed_note, "Save Ticket");
19080  CHECK_VARIABLE_INVALID (closed_note, "Save Ticket");
19081 
19082  switch (gmpf (connection, credentials, &response, &entity, response_data,
19083  "<modify_ticket ticket_id=\"%s\">"
19084  "<assigned_to><user id=\"%s\"/></assigned_to>"
19085  "<status>%s</status>"
19086  "<open_note>%s</open_note>"
19087  "<fixed_note>%s</fixed_note>"
19088  "<closed_note>%s</closed_note>"
19089  "</modify_ticket>",
19090  ticket_id, user_id, status, open_note, fixed_note, closed_note))
19091  {
19092  case 0:
19093  case -1:
19094  break;
19095  case 1:
19096  cmd_response_data_set_status_code (response_data,
19097  MHD_HTTP_INTERNAL_SERVER_ERROR);
19098  return gsad_message (
19099  credentials, "Internal error", __FUNCTION__, __LINE__,
19100  "An internal error occurred while saving a ticket. "
19101  "Diagnostics: Failure to send command to manager daemon.",
19102  response_data);
19103  case 2:
19104  cmd_response_data_set_status_code (response_data,
19105  MHD_HTTP_INTERNAL_SERVER_ERROR);
19106  return gsad_message (
19107  credentials, "Internal error", __FUNCTION__, __LINE__,
19108  "An internal error occurred while saving a ticket. "
19109  "It is unclear whether the ticket has been saved or not. "
19110  "Diagnostics: Failure to receive response from manager daemon.",
19111  response_data);
19112  default:
19113  cmd_response_data_set_status_code (response_data,
19114  MHD_HTTP_INTERNAL_SERVER_ERROR);
19115  return gsad_message (
19116  credentials, "Internal error", __FUNCTION__, __LINE__,
19117  "An internal error occurred while saving a ticket. "
19118  "It is unclear whether the ticket has been saved or not. "
19119  "Diagnostics: Internal Error.",
19120  response_data);
19121  }
19122 
19123  ret = response_from_entity (connection, credentials, params, entity,
19124  "Save Ticket", response_data);
19125 
19126  free_entity (entity);
19127  g_free (response);
19128  return ret;
19129 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmpf(), gsad_message(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ save_user_gmp()

char* save_user_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Modify a user, get all users, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 17313 of file gsad_gmp.c.

17315 {
17316  int ret;
17317  gchar *html, *response, *buf;
17318  const char *user_id, *login, *old_login, *modify_password, *password;
17319  const char *hosts, *hosts_allow, *ifaces, *ifaces_allow, *comment;
17320  entity_t entity;
17321  GString *command, *group_elements, *role_elements;
17322  params_t *groups, *roles;
17323 
17324  /* List of hosts user has/lacks access rights. */
17325  hosts = params_value (params, "access_hosts");
17326  /* Whether hosts grants ("1") or forbids ("0") access. "2" for all
17327  * access. */
17328  hosts_allow = params_value (params, "hosts_allow");
17329  ifaces = params_value (params, "access_ifaces");
17330  ifaces_allow = params_value (params, "ifaces_allow");
17331  login = params_value (params, "login");
17332  old_login = params_value (params, "old_login");
17333  modify_password = params_value (params, "modify_password");
17334  password = params_value (params, "password");
17335  user_id = params_value (params, "user_id");
17336  comment = params_value (params, "comment");
17337 
17338  CHECK_VARIABLE_INVALID (user_id, "Save User");
17339  CHECK_VARIABLE_INVALID (modify_password, "Save User");
17340  CHECK_VARIABLE_INVALID (hosts, "Save User");
17341  CHECK_VARIABLE_INVALID (hosts_allow, "Save User");
17342  CHECK_VARIABLE_INVALID (ifaces, "Save User");
17343  CHECK_VARIABLE_INVALID (ifaces_allow, "Save User");
17344  CHECK_VARIABLE_INVALID (login, "Save User");
17345  CHECK_VARIABLE_INVALID (old_login, "Save User");
17346 
17347  if (modify_password && str_equal (modify_password, "1"))
17348  {
17349  // require password if modify_password is 1 (== set new password)
17350  CHECK_VARIABLE_INVALID (password, "Save User");
17351  }
17352 
17353  if (params_given (params, "comment"))
17354  {
17355  CHECK_VARIABLE_INVALID (comment, "Save User");
17356  }
17357 
17358  /* Modify the user. */
17359 
17360  command = g_string_new ("");
17361  buf = g_markup_printf_escaped ("<modify_user user_id=\"%s\">"
17362  "<password modify=\"%s\">"
17363  "%s</password>",
17364  user_id, modify_password,
17365  password ? password : "");
17366  g_string_append (command, buf);
17367  g_free (buf);
17368 
17369  if (login)
17370  {
17371  buf = g_markup_printf_escaped ("<new_name>%s</new_name>", login);
17372  g_string_append (command, buf);
17373  g_free (buf);
17374  }
17375 
17376  buf = g_markup_printf_escaped ("<hosts allow=\"%s\">%s</hosts>"
17377  "<ifaces allow=\"%s\">%s</ifaces>",
17378  hosts_allow, hosts, ifaces_allow, ifaces);
17379  g_string_append (command, buf);
17380  g_free (buf);
17381 
17382  if (modify_password && !strcmp (modify_password, "2"))
17383  g_string_append (command,
17384  "<sources><source>ldap_connect</source></sources>");
17385  else if (modify_password && !strcmp (modify_password, "3"))
17386  g_string_append (command,
17387  "<sources><source>radius_connect</source></sources>");
17388  else
17389  g_string_append (command, "<sources><source>file</source></sources>");
17390 
17391  group_elements = g_string_new ("<groups>");
17392  if (params_given (params, "group_id_optional:"))
17393  groups = params_values (params, "group_id_optional:");
17394  else
17395  groups = params_values (params, "group_ids:");
17396 
17397  if (groups)
17398  {
17399  params_iterator_t iter;
17400  char *name;
17401  param_t *param;
17402 
17403  params_iterator_init (&iter, groups);
17404  while (params_iterator_next (&iter, &name, &param))
17405  {
17406  if (param->value && strcmp (param->value, "--"))
17407  g_string_append_printf (group_elements, "<group id=\"%s\"/>",
17408  param->value ? param->value : "");
17409  }
17410  }
17411  g_string_append (command, group_elements->str);
17412  g_string_free (group_elements, TRUE);
17413  g_string_append (command, "</groups>");
17414 
17415  role_elements = g_string_new ("");
17416  if (params_given (params, "role_id_optional:"))
17417  roles = params_values (params, "role_id_optional:");
17418  else
17419  roles = params_values (params, "role_ids:");
17420 
17421  if (roles)
17422  {
17423  params_iterator_t iter;
17424  char *name;
17425  param_t *param;
17426 
17427  params_iterator_init (&iter, roles);
17428  while (params_iterator_next (&iter, &name, &param))
17429  {
17430  if (param->value && strcmp (param->value, "--"))
17431  g_string_append_printf (role_elements, "<role id=\"%s\"/>",
17432  param->value ? param->value : "");
17433  }
17434  }
17435  else
17436  g_string_append_printf (role_elements, "<role id=\"0\"/>");
17437 
17438  g_string_append (command, role_elements->str);
17439  g_string_free (role_elements, TRUE);
17440 
17441  if (comment)
17442  {
17443  xml_string_append (command, "<comment>%s</comment>", comment);
17444  }
17445 
17446  g_string_append (command, "</modify_user>");
17447 
17448  response = NULL;
17449  entity = NULL;
17450  ret = gmp (connection, credentials, &response, &entity, response_data,
17451  command->str);
17452  g_string_free (command, TRUE);
17453 
17454  user_t *current_user = credentials_get_user (credentials);
17455 
17456  switch (ret)
17457  {
17458  case 0:
17459  if (gmp_success (entity) == 1)
17460  {
17461  user_t *user = session_get_user_by_username (old_login);
17462 
17463  if (user
17464  && (!str_equal (modify_password, "0")
17465  || !str_equal (old_login, login)))
17466  {
17467  /* logout all other user sessions if new password was set,
17468  authentication type has changed or username has changed */
17470  user);
17471  }
17472 
17473  if (str_equal (old_login, user_get_username (current_user)))
17474  {
17475  /* update username of current user */
17476  user_set_username (current_user, login);
17477 
17478  if (str_equal (modify_password, "1"))
17479  {
17480  /* update password of current user */
17481  user_set_password (current_user, password);
17482  }
17483  }
17484  }
17485  break;
17486  case -1:
17487  break;
17488  case 1:
17489  cmd_response_data_set_status_code (response_data,
17490  MHD_HTTP_INTERNAL_SERVER_ERROR);
17491  return gsad_message (
17492  credentials, "Internal error", __FUNCTION__, __LINE__,
17493  "An internal error occurred while saving a user. "
17494  "The user was not saved. "
17495  "Diagnostics: Failure to send command to manager daemon.",
17496  response_data);
17497  case 2:
17498  cmd_response_data_set_status_code (response_data,
17499  MHD_HTTP_INTERNAL_SERVER_ERROR);
17500  return gsad_message (
17501  credentials, "Internal error", __FUNCTION__, __LINE__,
17502  "An internal error occurred while saving a user. "
17503  "It is unclear whether the user has been saved or not. "
17504  "Diagnostics: Failure to receive response from manager daemon.",
17505  response_data);
17506  default:
17507  cmd_response_data_set_status_code (response_data,
17508  MHD_HTTP_INTERNAL_SERVER_ERROR);
17509  return gsad_message (
17510  credentials, "Internal error", __FUNCTION__, __LINE__,
17511  "An internal error occurred while saving a user. "
17512  "It is unclear whether the user has been saved or not. "
17513  "Diagnostics: Internal Error.",
17514  response_data);
17515  }
17516 
17517  if (gmp_success (entity)
17518  && (str_equal (modify_password, "2") || !str_equal (modify_password, "3"))
17519  && str_equal (old_login, user_get_username (current_user)))
17520  {
17521  free_entity (entity);
17522  g_free (response);
17523 
17524  cmd_response_data_set_status_code (response_data, MHD_HTTP_UNAUTHORIZED);
17525  return gsad_message (
17526  credentials, "Authentication Required", __FUNCTION__, __LINE__,
17527  "Authentication method changed. Please login with ", response_data);
17528  }
17529  else
17530  html = response_from_entity (connection, credentials, params, entity,
17531  "Save User", response_data);
17532  free_entity (entity);
17533  g_free (response);
17534  return html;
17535 }
params_t * params_values(params_t *params, const char *name)
Get values of param.
Definition: gsad_base.c:287
gchar * value
Definition: gsad_params.h:40
static int gmp_success(entity_t entity)
Check whether an GMP command failed.
Definition: gsad_gmp.c:656
Structure of credential related information.
gboolean str_equal(const gchar *str1, const gchar *str2)
Check if two strings are equal.
Definition: utils.c:35
void user_set_password(user_t *user, const gchar *password)
Set password of user.
Definition: gsad_user.c:257
#define params_iterator_t
Definition: gsad_params.h:94
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
int params_given(params_t *params, const char *name)
Get whether a param was given at all.
Definition: gsad_base.c:189
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
void user_set_username(user_t *user, const gchar *username)
Set username of user.
Definition: gsad_user.c:311
user_t * session_get_user_by_username(const gchar *username)
Definition: gsad_session.c:116
int login(http_connection_t *con, params_t *params, cmd_response_data_t *response_data, const char *client_address)
Login and create a session.
Definition: gsad_gmp.c:19384
const gchar * user_get_username(user_t *user)
Definition: gsad_user.c:157
const gchar * user_get_token(user_t *user)
Definition: gsad_user.c:175
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
Request parameter.
Definition: gsad_params.h:38
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
gboolean params_iterator_next(params_iterator_t *iterator, char **name, param_t **param)
Increment a params iterator.
Definition: gsad_base.c:394
void session_remove_other_sessions(const gchar *id, user_t *user)
Removes all session of the user, except the one with the passed id.
Definition: gsad_session.c:181
User information structure, for sessions.
Definition: gsad_user.c:42
#define params_iterator_init
Definition: gsad_params.h:96
#define params_t
Definition: gsad_params.h:31
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
user_t * credentials_get_user(credentials_t *cred)

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), credentials_get_user(), gmp(), gmp_success(), gsad_message(), login(), params_given(), params_iterator_init, params_iterator_next(), params_iterator_t, params_t, params_value(), params_values(), response_from_entity(), session_get_user_by_username(), session_remove_other_sessions(), str_equal(), user_get_token(), user_get_username(), user_set_password(), user_set_username(), and param::value.

Here is the call graph for this function:

◆ send_settings_filters()

static int send_settings_filters ( gvm_connection_t *  connection,
params_t *  data,
params_t *  changed,
GString *  xml,
int *  modify_failed_flag,
cmd_response_data_t *  response_data 
)
static

Send settings resource filters.

Parameters
[in]connectionConnection to Manager.
[in]dataData.
[in]changedParams indicating which settings changed.
[out]xmlGString to write responses to.
[out]modify_failed_flagPointer to an int to set to 1 on failure to modify one of the settings.
Returns
0 on success, -1 on error.

Definition at line 13244 of file gsad_gmp.c.

13247 {
13248  if (data)
13249  {
13250  params_iterator_t iter;
13251  char *uuid;
13252  param_t *param;
13253  entity_t entity;
13254 
13255  params_iterator_init (&iter, data);
13256  while (params_iterator_next (&iter, &uuid, &param))
13257  {
13258  const char *changed_value = params_value (changed, uuid);
13259  if (changed_value == NULL
13260  || (strcmp (changed_value, "") && strcmp (changed_value, "0")))
13261  {
13262  gchar *base64;
13263  if (param->value)
13264  base64 = g_base64_encode ((guchar *) param->value,
13265  strlen (param->value));
13266  else
13267  base64 = g_strdup ("");
13268  if (gvm_connection_sendf_xml (connection,
13269  "<modify_setting setting_id=\"%s\">"
13270  "<value>%s</value>"
13271  "</modify_setting>",
13272  uuid, base64))
13273  {
13274  g_free (base64);
13275  return -1;
13276  }
13277 
13278  g_free (base64);
13279 
13280  entity = NULL;
13281  xml_string_append (xml, "<save_setting id=\"%s\">", uuid);
13282  if (read_entity_and_string_c (connection, &entity, &xml))
13283  {
13284  free_entity (entity);
13285  return -1;
13286  }
13287  xml_string_append (xml, "</save_setting>");
13288  if (!gmp_success (entity))
13289  {
13290  set_http_status_from_entity (entity, response_data);
13291  if (modify_failed_flag)
13292  *modify_failed_flag = 1;
13293  }
13294  free_entity (entity);
13295  }
13296  }
13297  }
13298  return 0;
13299 }
gchar * value
Definition: gsad_params.h:40
static int gmp_success(entity_t entity)
Check whether an GMP command failed.
Definition: gsad_gmp.c:656
#define params_iterator_t
Definition: gsad_params.h:94
Request parameter.
Definition: gsad_params.h:38
void set_http_status_from_entity(entity_t entity, cmd_response_data_t *response_data)
Set the HTTP status according to GMP response entity.
Definition: gsad_gmp.c:677
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
gboolean params_iterator_next(params_iterator_t *iterator, char **name, param_t **param)
Increment a params iterator.
Definition: gsad_base.c:394
#define params_iterator_init
Definition: gsad_params.h:96

References gmp_success(), params_iterator_init, params_iterator_next(), params_iterator_t, params_value(), set_http_status_from_entity(), and param::value.

Referenced by save_my_settings_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_http_status_from_entity()

void set_http_status_from_entity ( entity_t  entity,
cmd_response_data_t *  response_data 
)

Set the HTTP status according to GMP response entity.

Parameters
[in]entityThe GMP response entity.
[in]response_dataResponse data.

Definition at line 677 of file gsad_gmp.c.

679 {
680  if (entity == NULL)
681  cmd_response_data_set_status_code (response_data,
682  MHD_HTTP_INTERNAL_SERVER_ERROR);
683  else if (str_equal (entity_attribute (entity, "status_text"),
684  "Permission denied"))
685  cmd_response_data_set_status_code (response_data, MHD_HTTP_FORBIDDEN);
686  else if (str_equal (entity_attribute (entity, "status"), "404"))
687  cmd_response_data_set_status_code (response_data, MHD_HTTP_NOT_FOUND);
688  else
689  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
690 }
gboolean str_equal(const gchar *str1, const gchar *str2)
Check if two strings are equal.
Definition: utils.c:35
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References cmd_response_data_set_status_code(), and str_equal().

Referenced by delete_resource(), export_many(), export_resource(), get_aggregate_gmp(), get_one(), get_report(), resource_action(), response_from_entity(), save_my_settings_gmp(), send_settings_filters(), setting_get_value(), and simple_gmpf().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setting_get_value()

static int setting_get_value ( gvm_connection_t *  connection,
const char *  setting_id,
gchar **  value,
cmd_response_data_t *  response_data 
)
static

Get a setting by UUID for the current user of an GMP connection.

Parameters
[in]connectionConnection.
[in]setting_idUUID of the setting to get.
[out]valueValue of the setting.
[out]response_dataExtra data return for the HTTP response.
Returns
-1 internal error, 0 success, 1 send error, 2 read error.

Definition at line 888 of file gsad_gmp.c.

890 {
891  int ret;
892  entity_t entity;
893  const char *status;
894  gchar *response;
895 
896  *value = NULL;
897 
898  ret = gvm_connection_sendf (connection, "<get_settings setting_id=\"%s\"/>",
899  setting_id);
900  if (ret)
901  return 1;
902 
903  entity = NULL;
904  if (read_entity_and_text_c (connection, &entity, &response))
905  return 2;
906 
907  status = entity_attribute (entity, "status");
908  if (status == NULL || strlen (status) == 0)
909  {
910  g_free (response);
911  free_entity (entity);
912  return -1;
913  }
914 
915  if (status[0] == '2')
916  {
917  entity_t setting;
918  setting = entity_child (entity, "setting");
919  if (setting == NULL)
920  {
921  free_entity (entity);
922  g_free (response);
923  return 0;
924  }
925  setting = entity_child (setting, "value");
926  if (setting == NULL)
927  {
928  free_entity (entity);
929  g_free (response);
930  return -1;
931  }
932  *value = g_strdup (entity_text (setting));
933  g_free (response);
934  free_entity (entity);
935  }
936  else
937  {
938  if (response_data)
939  set_http_status_from_entity (entity, response_data);
940  free_entity (entity);
941  g_free (response);
942  return -1;
943  }
944 
945  return 0;
946 }
void set_http_status_from_entity(entity_t entity, cmd_response_data_t *response_data)
Set the HTTP status according to GMP response entity.
Definition: gsad_gmp.c:677

References set_http_status_from_entity().

Referenced by authenticate_gmp(), export_many(), export_resource(), and get_report().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ simple_gmpf()

static int simple_gmpf ( gvm_connection_t *  connection,
const gchar *  message_operation,
credentials_t *  credentials,
gchar **  response,
cmd_response_data_t *  response_data,
const char *  format,
  ... 
)
static

Run a single GMP command, preparing a response even on error.

Parameters
[in]connectionConnection to manager
[out]message_operationOperation for error message
[in]credentialsUsername and password for authentication.
[out]responseResponse.
[out]response_dataExtra data return for the HTTP response.
[in]formatCommand.
[in]...Arguments for format string.
Returns
0 success, -1 internal error, 1 send error, 2 read error, 3 command failed, 4 connect error.

Definition at line 749 of file gsad_gmp.c.

752 {
753  int ret;
754  gchar *command;
755  va_list args;
756  entity_t entity;
757 
758  va_start (args, format);
759  command = g_markup_vprintf_escaped (format, args);
760  va_end (args);
761 
762  ret =
763  gmp (connection, credentials, response, &entity, response_data, command);
764  g_free (command);
765  switch (ret)
766  {
767  case 0:
768  break;
769  case -1:
770  /* 'gmp' set response. */
771  return 4;
772  case 1:
773  if (response_data)
774  cmd_response_data_set_status_code (response_data,
775  MHD_HTTP_INTERNAL_SERVER_ERROR);
776  if (response)
777  {
778  gchar *message;
779  message = g_strdup_printf (
780  "An internal error occurred while %s. "
781  " The operation was not started."
782  " Diagnostics: Failure to send command to manager"
783  " daemon.",
784  message_operation ? message_operation : "performing an operation");
785  *response = gsad_message (credentials, "Internal error", __FUNCTION__,
786  __LINE__, message, response_data);
787  g_free (message);
788  }
789  return 1;
790  case 2:
791  if (response_data)
792  cmd_response_data_set_status_code (response_data,
793  MHD_HTTP_INTERNAL_SERVER_ERROR);
794  if (response)
795  {
796  gchar *message;
797  message = g_strdup_printf (
798  "An internal error occurred while %s."
799  " It is unclear whether the operation succeeded."
800  " Diagnostics: Failure to receive response from manager"
801  " daemon.",
802  message_operation ? message_operation : "performing an operation");
803  *response = gsad_message (credentials, "Internal error", __FUNCTION__,
804  __LINE__, message, response_data);
805  g_free (message);
806  }
807  return 2;
808  default:
809  if (response_data)
810  cmd_response_data_set_status_code (response_data,
811  MHD_HTTP_INTERNAL_SERVER_ERROR);
812  if (response)
813  {
814  gchar *message;
815  message = g_strdup_printf (
816  "An internal error occurred while %s."
817  " It is unclear whether the operation succeeded."
818  " Diagnostics: Internal Error.",
819  message_operation ? message_operation : "performing an operation");
820  *response = gsad_message (credentials, "Internal error", __FUNCTION__,
821  __LINE__, message, response_data);
822  g_free (message);
823  }
824  return -1;
825  }
826 
827  switch (gmp_success (entity))
828  {
829  case 0:
830  set_http_status_from_entity (entity, response_data);
831  ret = 3;
832  break;
833  case 1:
834  ret = 0;
835  break;
836  default:
837  ret = -1;
838  break;
839  }
840  free_entity (entity);
841  return ret;
842 }
static int gmp_success(entity_t entity)
Check whether an GMP command failed.
Definition: gsad_gmp.c:656
Structure of credential related information.
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
void set_http_status_from_entity(entity_t entity, cmd_response_data_t *response_data)
Set the HTTP status according to GMP response entity.
Definition: gsad_gmp.c:677
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References cmd_response_data_set_status_code(), gmp(), gmp_success(), gsad_message(), and set_http_status_from_entity().

Referenced by get_info().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_task_gmp()

char* start_task_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Start a task, get all tasks, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 3232 of file gsad_gmp.c.

3234 {
3235  return resource_action (connection, credentials, params, "task", "start",
3236  response_data);
3237 }
Structure of credential related information.
char * resource_action(gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *type, const char *action, cmd_response_data_t *response_data)
Perform action on resource, get next page, envelope result.
Definition: gsad_gmp.c:2068

References resource_action().

Here is the call graph for this function:

◆ stop_task_gmp()

char* stop_task_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Stop a task, get all tasks, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 3196 of file gsad_gmp.c.

3198 {
3199  return resource_action (connection, credentials, params, "task", "stop",
3200  response_data);
3201 }
Structure of credential related information.
char * resource_action(gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *type, const char *action, cmd_response_data_t *response_data)
Perform action on resource, get next page, envelope result.
Definition: gsad_gmp.c:2068

References resource_action().

Here is the call graph for this function:

◆ sync_cert_gmp()

char* sync_cert_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Synchronize with a CERT feed and envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 16392 of file gsad_gmp.c.

16394 {
16395  return sync_feed (connection, credentials, params, "sync_cert",
16396  "Synchronize CERT Feed", "the CERT feed", response_data);
16397 }
Structure of credential related information.
static char * sync_feed(gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *sync_cmd, const char *action, const char *feed_name, cmd_response_data_t *response_data)
Synchronize with a feed and envelope the result.
Definition: gsad_gmp.c:16299

References sync_feed().

Here is the call graph for this function:

◆ sync_config_gmp()

char* sync_config_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Sync config, get configs, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 8326 of file gsad_gmp.c.

8328 {
8329  GString *xml;
8330  const char *config_id;
8331  char *ret;
8332 
8333  config_id = params_value (params, "config_id");
8334  CHECK_VARIABLE_INVALID (config_id, "Synchronize Config");
8335 
8336  if (gvm_connection_sendf (connection, "<sync_config config_id=\"%s\"/>",
8337  config_id)
8338  == -1)
8339  {
8340  cmd_response_data_set_status_code (response_data,
8341  MHD_HTTP_INTERNAL_SERVER_ERROR);
8342  return gsad_message (
8343  credentials, "Internal error", __FUNCTION__, __LINE__,
8344  "An internal error occurred while synchronizing a config. "
8345  "The config is not synchronized. "
8346  "Diagnostics: Failure to send command to manager daemon.",
8347  response_data);
8348  }
8349 
8350  xml = g_string_new ("");
8351 
8352  if (read_string_c (connection, &xml))
8353  {
8354  g_string_free (xml, TRUE);
8355  cmd_response_data_set_status_code (response_data,
8356  MHD_HTTP_INTERNAL_SERVER_ERROR);
8357  return gsad_message (
8358  credentials, "Internal error", __FUNCTION__, __LINE__,
8359  "An internal error occurred while synchronizing a config. "
8360  "It is unclear whether the config has been synchronized or not. "
8361  "Diagnostics: Failure to receive response from manager daemon.",
8362  response_data);
8363  }
8364 
8365  // TODO return action result
8366  ret = get_configs (connection, credentials, params, xml->str, response_data);
8367 
8368  g_string_free (xml, TRUE);
8369  return ret;
8370 }
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
static char * get_configs(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Get all scan configs, envelope the result.
Definition: gsad_gmp.c:8040
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), get_configs(), gsad_message(), and params_value().

Here is the call graph for this function:

◆ sync_feed()

static char* sync_feed ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  sync_cmd,
const char *  action,
const char *  feed_name,
cmd_response_data_t *  response_data 
)
static

Synchronize with a feed and envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication
[in]paramsRequest parameters.
[in]sync_cmdName of the GMP command used to sync the feed.
[in]actionAction shown in gsad status messages.
[in]feed_nameName of the feed shown in error messages.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 16299 of file gsad_gmp.c.

16302 {
16303  entity_t entity;
16304  char *text = NULL;
16305  gchar *html, *msg;
16306 
16307  if (gvm_connection_sendf (connection, "<%s/>", sync_cmd) == -1)
16308  {
16309  cmd_response_data_set_status_code (response_data,
16310  MHD_HTTP_INTERNAL_SERVER_ERROR);
16311 
16312  msg = g_strdup_printf (
16313  "An internal error occurred while synchronizing with %s. "
16314  "Feed synchronization is currently not available. "
16315  "Diagnostics: Failure to send command to manager daemon.",
16316  feed_name);
16317  html = gsad_message (credentials, "Internal error", __FUNCTION__,
16318  __LINE__, msg, response_data);
16319  g_free (msg);
16320  return html;
16321  }
16322 
16323  if (read_entity_and_text_c (connection, &entity, &text))
16324  {
16325  cmd_response_data_set_status_code (response_data,
16326  MHD_HTTP_INTERNAL_SERVER_ERROR);
16327 
16328  msg = g_strdup_printf (
16329  "An internal error occurred while synchronizing with %s. "
16330  "Feed synchronization is currently not available. "
16331  "Diagnostics: Failure to receive response from manager daemon.",
16332  feed_name);
16333  html = gsad_message (credentials, "Internal error", __FUNCTION__,
16334  __LINE__, msg, response_data);
16335  g_free (msg);
16336  return html;
16337  }
16338 
16339  html = response_from_entity (connection, credentials, params, entity, action,
16340  response_data);
16341 
16342  return html;
16343 }
Structure of credential related information.
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References cmd_response_data_set_status_code(), gsad_message(), and response_from_entity().

Referenced by sync_cert_gmp(), sync_feed_gmp(), and sync_scap_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sync_feed_gmp()

char* sync_feed_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Synchronize with an NVT feed and envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 16356 of file gsad_gmp.c.

16358 {
16359  return sync_feed (connection, credentials, params, "sync_feed",
16360  "Synchronize Feed", "the NVT feed", response_data);
16361 }
Structure of credential related information.
static char * sync_feed(gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *sync_cmd, const char *action, const char *feed_name, cmd_response_data_t *response_data)
Synchronize with a feed and envelope the result.
Definition: gsad_gmp.c:16299

References sync_feed().

Here is the call graph for this function:

◆ sync_scap_gmp()

char* sync_scap_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Synchronize with a SCAP feed and envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 16374 of file gsad_gmp.c.

16376 {
16377  return sync_feed (connection, credentials, params, "sync_scap",
16378  "Synchronize Feed", "the SCAP feed", response_data);
16379 }
Structure of credential related information.
static char * sync_feed(gvm_connection_t *connection, credentials_t *credentials, params_t *params, const char *sync_cmd, const char *action, const char *feed_name, cmd_response_data_t *response_data)
Synchronize with a feed and envelope the result.
Definition: gsad_gmp.c:16299

References sync_feed().

Here is the call graph for this function:

◆ test_alert_gmp()

char* test_alert_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Test an alert, get all alerts envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 6566 of file gsad_gmp.c.

6568 {
6569  gchar *html, *response;
6570  const char *alert_id;
6571  entity_t entity;
6572 
6573  alert_id = params_value (params, "alert_id");
6574 
6575  if (alert_id == NULL)
6576  {
6577  cmd_response_data_set_status_code (response_data,
6579  return gsad_message (credentials, "Invalid request", __FUNCTION__,
6580  __LINE__,
6581  "Missing parameter alert_id."
6582  "Diagnostics: Required parameter was NULL.",
6583  response_data);
6584  }
6585 
6586  /* Test the alert. */
6587 
6588  if (gvm_connection_sendf (connection, "<test_alert alert_id=\"%s\"/>",
6589  alert_id)
6590  == -1)
6591  {
6592  cmd_response_data_set_status_code (response_data,
6593  MHD_HTTP_INTERNAL_SERVER_ERROR);
6594  return gsad_message (
6595  credentials, "Internal error", __FUNCTION__, __LINE__,
6596  "An internal error occurred while testing an alert. "
6597  "Diagnostics: Failure to send command to manager daemon.",
6598  response_data);
6599  }
6600 
6601  entity = NULL;
6602  if (read_entity_and_text_c (connection, &entity, &response))
6603  {
6604  cmd_response_data_set_status_code (response_data,
6605  MHD_HTTP_INTERNAL_SERVER_ERROR);
6606  return gsad_message (
6607  credentials, "Internal error", __FUNCTION__, __LINE__,
6608  "An internal error occurred while testing an alert. "
6609  "Diagnostics: Failure to receive response from manager daemon.",
6610  response_data);
6611  }
6612 
6613  html = response_from_entity (connection, credentials, params, entity,
6614  "Test Alert", response_data);
6615 
6616  free_entity (entity);
6617  g_free (response);
6618  return html;
6619 }
Structure of credential related information.
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
#define GSAD_STATUS_INVALID_REQUEST
HTTP status code for expected failure of gmp requests e.g. if some parameter was missing or invalid.
Definition: gsad_gmp.c:96
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References cmd_response_data_set_status_code(), gsad_message(), GSAD_STATUS_INVALID_REQUEST, params_value(), and response_from_entity().

Here is the call graph for this function:

◆ toggle_tag_gmp()

char* toggle_tag_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Set tag enabled status.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 7466 of file gsad_gmp.c.

7468 {
7469  gchar *html, *response;
7470  const char *tag_id, *enable;
7471  entity_t entity;
7472 
7473  tag_id = params_value (params, "tag_id");
7474  enable = params_value (params, "enable");
7475 
7476  CHECK_VARIABLE_INVALID (tag_id, "Toggle Tag")
7477  CHECK_VARIABLE_INVALID (enable, "Toggle Tag")
7478 
7479  /* Delete the resource and get all resources. */
7480 
7481  if (gvm_connection_sendf (connection,
7482  "<modify_tag tag_id=\"%s\">"
7483  "<active>%s</active>"
7484  "</modify_tag>",
7485  tag_id, enable)
7486  == -1)
7487  {
7488  cmd_response_data_set_status_code (response_data,
7489  MHD_HTTP_INTERNAL_SERVER_ERROR);
7490  return gsad_message (credentials, "Internal error", __FUNCTION__,
7491  __LINE__,
7492  "An internal error occurred while modifying a tag. "
7493  "The tag is not modified. "
7494  "Diagnostics: Failure to send command to"
7495  " manager daemon.",
7496  response_data);
7497  }
7498 
7499  entity = NULL;
7500  if (read_entity_and_text_c (connection, &entity, &response))
7501  {
7502  cmd_response_data_set_status_code (response_data,
7503  MHD_HTTP_INTERNAL_SERVER_ERROR);
7504  return gsad_message (credentials, "Internal error", __FUNCTION__,
7505  __LINE__,
7506  "An internal error occurred while modifying a tag. "
7507  "It is unclear whether the tag has been modified"
7508  " or not. "
7509  "Diagnostics: Failure to read response from"
7510  " manager daemon.",
7511  response_data);
7512  }
7513 
7514  html = response_from_entity (connection, credentials, params, entity,
7515  "Toggle Tag", response_data);
7516 
7517  free_entity (entity);
7518  g_free (response);
7519 
7520  return html;
7521 }
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gsad_message(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ verify_agent_gmp()

char* verify_agent_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Verify agent, get agents, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 4906 of file gsad_gmp.c.

4908 {
4909  gchar *html, *response;
4910  const char *agent_id;
4911  int ret;
4912  entity_t entity;
4913 
4914  agent_id = params_value (params, "agent_id");
4915  if (agent_id == NULL)
4916  {
4917  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
4918  return gsad_message (
4919  credentials, "Internal error", __FUNCTION__, __LINE__,
4920  "An internal error occurred while verifying an agent. "
4921  "Diagnostics: Required parameter was NULL.",
4922  response_data);
4923  }
4924  response = NULL;
4925  entity = NULL;
4926  ret = gmpf (connection, credentials, &response, &entity, response_data,
4927  "<verify_agent agent_id=\"%s\" />", agent_id);
4928 
4929  switch (ret)
4930  {
4931  case 0:
4932  case -1:
4933  break;
4934  case 1:
4935  cmd_response_data_set_status_code (response_data,
4936  MHD_HTTP_INTERNAL_SERVER_ERROR);
4937  return gsad_message (
4938  credentials, "Internal error", __FUNCTION__, __LINE__,
4939  "An internal error occurred while verifying a agent. "
4940  "The agent was not verified. "
4941  "Diagnostics: Failure to send command to manager daemon.",
4942  response_data);
4943  case 2:
4944  cmd_response_data_set_status_code (response_data,
4945  MHD_HTTP_INTERNAL_SERVER_ERROR);
4946  return gsad_message (
4947  credentials, "Internal error", __FUNCTION__, __LINE__,
4948  "An internal error occurred while verifying a agent. "
4949  "It is unclear whether the agent was verified or not. "
4950  "Diagnostics: Failure to send command to manager daemon.",
4951  response_data);
4952  default:
4953  cmd_response_data_set_status_code (response_data,
4954  MHD_HTTP_INTERNAL_SERVER_ERROR);
4955  return gsad_message (
4956  credentials, "Internal error", __FUNCTION__, __LINE__,
4957  "An internal error occurred while verifying a agent. "
4958  "It is unclear whether the agent was verified or not. "
4959  "Diagnostics: Failure to send command to manager daemon.",
4960  response_data);
4961  }
4962 
4963  html = response_from_entity (connection, credentials, params, entity,
4964  "Verify Agent", response_data);
4965  free_entity (entity);
4966  g_free (response);
4967  return html;
4968 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References cmd_response_data_set_status_code(), gmpf(), gsad_message(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ verify_report_format_gmp()

char* verify_report_format_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Verify report format, get report formats, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 12939 of file gsad_gmp.c.

12942 {
12943  int ret;
12944  gchar *html, *response;
12945  const char *report_format_id;
12946  entity_t entity;
12947 
12948  report_format_id = params_value (params, "report_format_id");
12949  if (report_format_id == NULL)
12950  {
12951  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
12952  return gsad_message (
12953  credentials, "Internal error", __FUNCTION__, __LINE__,
12954  "An internal error occurred while verifying a report format. "
12955  "Diagnostics: Required parameter was NULL.",
12956  response_data);
12957  }
12958 
12959  /* Verify the report format. */
12960 
12961  response = NULL;
12962  entity = NULL;
12963  ret =
12964  gmpf (connection, credentials, &response, &entity, response_data,
12965  "<verify_report_format report_format_id=\"%s\"/>", report_format_id);
12966 
12967  switch (ret)
12968  {
12969  case 0:
12970  case -1:
12971  break;
12972  case 1:
12973  cmd_response_data_set_status_code (response_data,
12974  MHD_HTTP_INTERNAL_SERVER_ERROR);
12975  return gsad_message (
12976  credentials, "Internal error", __FUNCTION__, __LINE__,
12977  "An internal error occurred while verifying a report format. "
12978  "The report format was not verified. "
12979  "Diagnostics: Failure to send command to manager daemon.",
12980  response_data);
12981  case 2:
12982  cmd_response_data_set_status_code (response_data,
12983  MHD_HTTP_INTERNAL_SERVER_ERROR);
12984  return gsad_message (
12985  credentials, "Internal error", __FUNCTION__, __LINE__,
12986  "An internal error occurred while verifying a report format. "
12987  "It is unclear whether the report format was verified or not. "
12988  "Diagnostics: Failure to send command to manager daemon.",
12989  response_data);
12990  default:
12991  cmd_response_data_set_status_code (response_data,
12992  MHD_HTTP_INTERNAL_SERVER_ERROR);
12993  return gsad_message (
12994  credentials, "Internal error", __FUNCTION__, __LINE__,
12995  "An internal error occurred while verifying a report format. "
12996  "It is unclear whether the report format was verified or not. "
12997  "Diagnostics: Failure to send command to manager daemon.",
12998  response_data);
12999  }
13000 
13001  html = response_from_entity (connection, credentials, params, entity,
13002  "Verify Report Format", response_data);
13003  free_entity (entity);
13004  g_free (response);
13005  return html;
13006 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References cmd_response_data_set_status_code(), gmpf(), gsad_message(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ verify_scanner_gmp()

char* verify_scanner_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Verify scanner, get scanners, envelope the result.

Parameters
[in]connectionConnection to manager.
[in]credentialsUsername and password for authentication.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 11626 of file gsad_gmp.c.

11628 {
11629  gchar *html, *response;
11630  const char *scanner_id;
11631  int ret;
11632  entity_t entity;
11633 
11634  scanner_id = params_value (params, "scanner_id");
11635  CHECK_VARIABLE_INVALID (scanner_id, "Verify Scanner");
11636 
11637  ret = gmpf (connection, credentials, &response, &entity, response_data,
11638  "<verify_scanner scanner_id=\"%s\"/>", scanner_id);
11639 
11640  switch (ret)
11641  {
11642  case 0:
11643  case -1:
11644  break;
11645  case 1:
11646  cmd_response_data_set_status_code (response_data,
11647  MHD_HTTP_INTERNAL_SERVER_ERROR);
11648  return gsad_message (
11649  credentials, "Internal error", __FUNCTION__, __LINE__,
11650  "An internal error occurred while verifying a scanner. "
11651  "The scanner was not verified. "
11652  "Diagnostics: Failure to send command to manager daemon.",
11653  response_data);
11654  case 2:
11655  cmd_response_data_set_status_code (response_data,
11656  MHD_HTTP_INTERNAL_SERVER_ERROR);
11657  return gsad_message (
11658  credentials, "Internal error", __FUNCTION__, __LINE__,
11659  "An internal error occurred while verifying a scanner. "
11660  "It is unclear whether the scanner was verified or not. "
11661  "Diagnostics: Failure to send command to manager daemon.",
11662  response_data);
11663  default:
11664  cmd_response_data_set_status_code (response_data,
11665  MHD_HTTP_INTERNAL_SERVER_ERROR);
11666  return gsad_message (
11667  credentials, "Internal error", __FUNCTION__, __LINE__,
11668  "An internal error occurred while verifying a scanner. "
11669  "It is unclear whether the scanner was verified or not. "
11670  "Diagnostics: Failure to send command to manager daemon.",
11671  response_data);
11672  }
11673 
11674  html = response_from_entity (connection, credentials, params, entity,
11675  "Verify Scanner", response_data);
11676  free_entity (entity);
11677  g_free (response);
11678  return html;
11679 }
static int gmpf(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *,...)
Run a single formatted GMP command.
Definition: gsad_gmp.c:859
Structure of credential related information.
#define CHECK_VARIABLE_INVALID(name, op_name)
Check if variable is NULL.
Definition: gsad_gmp.c:119
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
static gchar * response_from_entity(gvm_connection_t *, credentials_t *, params_t *, entity_t, const char *, cmd_response_data_t *)
Set redirect or return a basic action_result page based on entity.
Definition: gsad_gmp.c:1023
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160

References CHECK_VARIABLE_INVALID, cmd_response_data_set_status_code(), gmpf(), gsad_message(), params_value(), and response_from_entity().

Here is the call graph for this function:

◆ wizard()

char * wizard ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Returns a wizard page.

Parameters
[in]connectionConnection to manager.
[in]credentialsCredentials of user issuing the action.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 18016 of file gsad_gmp.c.

18019 {
18020  GString *xml;
18021  const char *name = params_value (params, "name");
18022 
18023  if (name == NULL)
18024  {
18025  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
18026  return gsad_message (
18027  credentials, "Internal error", __FUNCTION__, __LINE__,
18028  "An internal error occurred while getting the wizard. "
18029  "Given name was invalid",
18030  response_data);
18031  }
18032 
18033  xml = g_string_new ("");
18034  g_string_append_printf (xml, "<wizard>%s<%s/>", extra_xml ? extra_xml : "",
18035  name);
18036 
18037  /* Try to run init mode of the wizard */
18038  if (gvm_connection_sendf_xml (connection,
18039  "<run_wizard read_only=\"1\">"
18040  "<name>%s</name>"
18041  "<mode>init</mode>"
18042  "</run_wizard>",
18043  name)
18044  == -1)
18045  {
18046  g_string_free (xml, TRUE);
18047  cmd_response_data_set_status_code (response_data,
18048  MHD_HTTP_INTERNAL_SERVER_ERROR);
18049  return gsad_message (
18050  credentials, "Internal error", __FUNCTION__, __LINE__,
18051  "An internal error occurred while getting the wizard. "
18052  "Diagnostics: Failure to send command to manager daemon.",
18053  response_data);
18054  }
18055 
18056  if (read_string_c (connection, &xml))
18057  {
18058  g_string_free (xml, TRUE);
18059  cmd_response_data_set_status_code (response_data,
18060  MHD_HTTP_INTERNAL_SERVER_ERROR);
18061  return gsad_message (credentials, "Internal error", __FUNCTION__,
18062  __LINE__,
18063  "An internal error occurred while getting the"
18064  " wizard."
18065  "Diagnostics: Failure to receive response from"
18066  " manager daemon.",
18067  response_data);
18068  }
18069 
18070  /* Get the setting. */
18071 
18072  if (gvm_connection_sendf_xml (
18073  connection, "<get_settings"
18074  " setting_id=\"20f3034c-e709-11e1-87e7-406186ea4fc5\"/>")
18075  == -1)
18076  {
18077  g_string_free (xml, TRUE);
18078  cmd_response_data_set_status_code (response_data,
18079  MHD_HTTP_INTERNAL_SERVER_ERROR);
18080  return gsad_message (
18081  credentials, "Internal error", __FUNCTION__, __LINE__,
18082  "An internal error occurred while getting the wizard. "
18083  "Diagnostics: Failure to send command to manager daemon.",
18084  response_data);
18085  }
18086 
18087  if (read_string_c (connection, &xml))
18088  {
18089  g_string_free (xml, TRUE);
18090  cmd_response_data_set_status_code (response_data,
18091  MHD_HTTP_INTERNAL_SERVER_ERROR);
18092  return gsad_message (
18093  credentials, "Internal error", __FUNCTION__, __LINE__,
18094  "An internal error occurred while the wizard. "
18095  "Diagnostics: Failure to receive response from manager daemon.",
18096  response_data);
18097  }
18098 
18099  /* Cleanup, and return transformed XML. */
18100 
18101  g_string_append_printf (xml, "</wizard>");
18102  return envelope_gmp (connection, credentials, params,
18103  g_string_free (xml, FALSE), response_data);
18104 }
Structure of credential related information.
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
static char * envelope_gmp(gvm_connection_t *connection, credentials_t *credentials, params_t *params, gchar *xml, cmd_response_data_t *response_data)
Wrap some XML in an envelope.
Definition: gsad_gmp.c:443

References cmd_response_data_set_status_code(), envelope_gmp(), gsad_message(), and params_value().

Referenced by wizard_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wizard_get()

char * wizard_get ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
const char *  extra_xml,
cmd_response_data_t *  response_data 
)
static

Returns a wizard_get page.

Parameters
[in]connectionConnection to manager.
[in]credentialsCredentials of user issuing the action.
[in]paramsRequest parameters.
[in]extra_xmlExtra XML to insert inside page element.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 18135 of file gsad_gmp.c.

18138 {
18139  const char *name;
18140  int ret;
18141  GString *run;
18142  param_t *param;
18143  gchar *param_name, *response;
18144  params_iterator_t iter;
18145  params_t *wizard_params;
18146  entity_t entity;
18147  gchar *wizard_xml;
18148 
18149  /* The naming is a bit subtle here, because the HTTP request
18150  * parameters are called "param"s and so are the GMP wizard
18151  * parameters. */
18152 
18153  name = params_value (params, "get_name");
18154  if (name == NULL)
18155  {
18156  cmd_response_data_set_status_code (response_data, MHD_HTTP_BAD_REQUEST);
18157  return gsad_message (
18158  credentials, "Internal error", __FUNCTION__, __LINE__,
18159  "An internal error occurred while trying to start a wizard. "
18160  "Diagnostics: Required parameter 'get_name' was NULL.",
18161  response_data);
18162  }
18163 
18164  run = g_string_new ("<run_wizard read_only=\"1\">");
18165 
18166  g_string_append_printf (run,
18167  "<name>%s</name>"
18168  "<params>",
18169  name);
18170 
18171  wizard_params = params_values (params, "event_data:");
18172  if (wizard_params)
18173  {
18174  params_iterator_init (&iter, wizard_params);
18175  while (params_iterator_next (&iter, &param_name, &param))
18176  xml_string_append (run,
18177  "<param>"
18178  "<name>%s</name>"
18179  "<value>%s</value>"
18180  "</param>",
18181  param_name, param->value);
18182  }
18183 
18184  g_string_append (run, "</params></run_wizard>");
18185 
18186  response = NULL;
18187  entity = NULL;
18188  ret =
18189  gmp (connection, credentials, &response, &entity, response_data, run->str);
18190  g_string_free (run, TRUE);
18191  switch (ret)
18192  {
18193  case 0:
18194  case -1:
18195  break;
18196  case 1:
18197  cmd_response_data_set_status_code (response_data,
18198  MHD_HTTP_INTERNAL_SERVER_ERROR);
18199  return gsad_message (
18200  credentials, "Internal error", __FUNCTION__, __LINE__,
18201  "An internal error occurred while running a wizard. "
18202  "The wizard did not start. "
18203  "Diagnostics: Failure to send command to manager daemon.",
18204  response_data);
18205  case 2:
18206  cmd_response_data_set_status_code (response_data,
18207  MHD_HTTP_INTERNAL_SERVER_ERROR);
18208  return gsad_message (
18209  credentials, "Internal error", __FUNCTION__, __LINE__,
18210  "An internal error occurred while running a wizard. "
18211  "It is unclear whether the wizard started or not. "
18212  "Diagnostics: Failure to receive response from manager daemon.",
18213  response_data);
18214  default:
18215  cmd_response_data_set_status_code (response_data,
18216  MHD_HTTP_INTERNAL_SERVER_ERROR);
18217  return gsad_message (credentials, "Internal error", __FUNCTION__,
18218  __LINE__,
18219  "An internal error occurred while running a wizard. "
18220  "It is unclear whether the wizard started or not. "
18221  "Diagnostics: Internal Error.",
18222  response_data);
18223  }
18224 
18225  wizard_xml = g_strdup_printf ("<wizard><%s/>%s%s</wizard>", name,
18226  extra_xml ? extra_xml : "", response);
18227 
18228  return envelope_gmp (connection, credentials, params, wizard_xml,
18229  response_data);
18230 }
params_t * params_values(params_t *params, const char *name)
Get values of param.
Definition: gsad_base.c:287
gchar * value
Definition: gsad_params.h:40
Structure of credential related information.
#define params_iterator_t
Definition: gsad_params.h:94
static int gmp(gvm_connection_t *, credentials_t *, gchar **, entity_t *, cmd_response_data_t *, const char *)
Run a single GMP command.
Definition: gsad_gmp.c:706
char * gsad_message(credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data)
Handles fatal errors.
Definition: gsad_http.c:978
Request parameter.
Definition: gsad_params.h:38
const char * params_value(params_t *params, const char *name)
Get value of param.
Definition: gsad_base.c:205
gboolean params_iterator_next(params_iterator_t *iterator, char **name, param_t **param)
Increment a params iterator.
Definition: gsad_base.c:394
#define params_iterator_init
Definition: gsad_params.h:96
#define params_t
Definition: gsad_params.h:31
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
static char * envelope_gmp(gvm_connection_t *connection, credentials_t *credentials, params_t *params, gchar *xml, cmd_response_data_t *response_data)
Wrap some XML in an envelope.
Definition: gsad_gmp.c:443

References cmd_response_data_set_status_code(), envelope_gmp(), gmp(), gsad_message(), params_iterator_init, params_iterator_next(), params_iterator_t, params_t, params_value(), params_values(), and param::value.

Referenced by wizard_get_gmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wizard_get_gmp()

char* wizard_get_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Returns a wizard_get page.

Parameters
[in]connectionConnection to manager.
[in]credentialsCredentials of user issuing the action.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 18243 of file gsad_gmp.c.

18245 {
18246  return wizard_get (connection, credentials, params, NULL, response_data);
18247 }
static char * wizard_get(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Returns a wizard_get page.
Definition: gsad_gmp.c:18135
Structure of credential related information.

References wizard_get().

Here is the call graph for this function:

◆ wizard_gmp()

char* wizard_gmp ( gvm_connection_t *  connection,
credentials_t *  credentials,
params_t *  params,
cmd_response_data_t *  response_data 
)

Returns a wizard page.

Parameters
[in]connectionConnection to manager.
[in]credentialsCredentials of user issuing the action.
[in]paramsRequest parameters.
[out]response_dataExtra data return for the HTTP response.
Returns
Enveloped XML object.

Definition at line 18117 of file gsad_gmp.c.

18119 {
18120  return wizard (connection, credentials, params, NULL, response_data);
18121 }
Structure of credential related information.
static char * wizard(gvm_connection_t *, credentials_t *, params_t *, const char *, cmd_response_data_t *)
Returns a wizard page.
Definition: gsad_gmp.c:18016

References wizard().

Here is the call graph for this function:

Variable Documentation

◆ manager_address

gchar* manager_address = NULL

The address the manager is on.

Definition at line 135 of file gsad_gmp.c.

Referenced by authenticate_gmp(), gmp_init(), and manager_connect().

◆ manager_port

int manager_port = 9390

The port the manager is on.

Definition at line 140 of file gsad_gmp.c.

Referenced by authenticate_gmp(), gmp_init(), and manager_connect().

◆ manager_use_tls

int manager_use_tls = 0

Whether to use TLS for Manager connections.

Definition at line 130 of file gsad_gmp.c.

Referenced by gmp_init(), and gvm_connection_open().