28#define G_LOG_DOMAIN "libgvm gmp"
30#define GMP_FMT_BOOL_ATTRIB(var, attrib) \
31 (var.attrib == 0 ? " " #attrib "=\"0\"" : " " #attrib "=\"1\"")
33#define GMP_FMT_STRING_ATTRIB(var, attrib) \
34 (var.attrib ? " " #attrib "= \"" : ""), (var.attrib ? var.attrib : ""), \
35 (var.attrib ? "\"" : "")
90 if (strlen (status) == 0)
100 ret = (int) strtol (status, NULL, 10);
139 if (strlen (status) == 0)
144 if (status[0] ==
'2')
149 ret = (int) strtol (status, NULL, 10);
224 if (strlen (status) == 0)
255 if (version && *version)
285 if (strlen (status) == 0)
290 if (status[0] ==
'2')
296 if (omp_version == NULL)
322 const char *password)
329 "<authenticate><credentials>"
330 "<username>%s</username>"
331 "<password>%s</password>"
332 "</credentials></authenticate>",
333 username ? username :
"",
334 password ? password :
"");
377 "<authenticate><credentials>"
378 "<username>%s</username>"
379 "<password>%s</password>"
380 "</credentials></authenticate>",
406 if (strlen (status) == 0)
414 entity_t timezone_entity, role_entity, pw_warn_entity;
422 pw_warn_entity =
entity_child (entity,
"password_warning");
461 "<username>%s</username>"
462 "<password>%s</password>"
490 if (strlen (status) == 0)
498 entity_t timezone_entity, role_entity;
501 if (timezone_entity && opts.
timezone)
504 if (role_entity && opts.
role)
509 pw_warn_entity =
entity_child (entity,
"password_warning");
542 gchar *prefs, *start, *hosts_ordering, *scanner, *schedule, *slave;
543 GString *alerts, *observers;
549 start = g_markup_printf_escaped (
551 "<config id=\"%s\"/>"
552 "<target id=\"%s\"/>"
554 "<comment>%s</comment>"
555 "<alterable>%d</alterable>",
560 hosts_ordering = g_strdup_printf (
"<hosts_ordering>%s</hosts_ordering>",
563 hosts_ordering = NULL;
566 scanner = g_strdup_printf (
"<scanner id=\"%s\"/>", opts.
scanner_id);
571 schedule = g_strdup_printf (
"<schedule id=\"%s\"/>"
572 "<schedule_periods>%d</schedule_periods>",
578 slave = g_strdup_printf (
"<slave id=\"%s\"/>", opts.
slave_id);
584 gchar *in_assets, *checks, *hosts, *source_iface;
586 in_assets = checks = hosts = source_iface = NULL;
589 in_assets = g_markup_printf_escaped (
"<preference>"
600 hosts = g_markup_printf_escaped (
"<preference>"
611 checks = g_markup_printf_escaped (
"<preference>"
622 source_iface = g_markup_printf_escaped (
"<preference>"
633 g_strdup_printf (
"<preferences>%s%s%s%s</preferences>",
634 in_assets ? in_assets :
"", checks ? checks :
"",
635 hosts ? hosts :
"", source_iface ? source_iface :
"");
639 g_free (source_iface);
645 alerts = g_string_new (
"");
646 for (i = 0; i < opts.
alert_ids->len; i++)
648 char *alert = (
char *) g_ptr_array_index (opts.
alert_ids, i);
649 g_string_append_printf (alerts,
"<alert id=\"%s\"/>", alert);
653 alerts = g_string_new (
"");
657 observers = g_string_new (
"<observers>");
660 g_string_append (observers, opts.
observers);
669 g_string_append_printf (observers,
"<group id=\"%s\"/>", group);
672 g_string_append (observers,
"</observers>");
675 observers = g_string_new (
"");
679 session,
"%s%s%s%s%s%s%s%s</create_task>", start, prefs ? prefs :
"",
680 hosts_ordering ? hosts_ordering :
"", scanner ? scanner :
"",
681 schedule ? schedule :
"", slave ? slave :
"", alerts ? alerts->str :
"",
682 observers ? observers->str :
"");
685 g_free (hosts_ordering);
689 g_string_free (alerts, TRUE);
690 g_string_free (observers, TRUE);
718 const char *config,
const char *target,
const char *comment,
725 "<config id=\"%s\"/>"
726 "<target id=\"%s\"/>"
728 "<comment>%s</comment>"
730 config, target, name, comment);
757 if (
gvm_server_sendf (session,
"<start_task task_id=\"%s\"/>", task_id) == -1)
771 *report_id = g_strdup (
entity_text (report_id_xml));
822 if (strlen (status) == 0)
834 *report_id = g_strdup (
entity_text (report_id_xml));
908 if (strlen (status) == 0)
924 if (strlen (
id) == 0)
929 *uuid = g_strdup (
id);
1009 *report_id = g_strdup (
entity_text (report_id_xml));
1056 if (strlen (status) == 0)
1061 char first = status[0];
1068 *report_id = g_strdup (
entity_text (report_id_xml));
1099 "<delete_task task_id=\"%s\" ultimate=\"%d\"/>",
id,
1125 int include_rcfile,
entity_t *status)
1127 (void) include_rcfile;
1139 " details=\"%i\"/>",
1162 if ((response == NULL) || (opts.
task_id == NULL))
1200 const char *status_code;
1203 if (response == NULL)
1206 cmd = g_markup_printf_escaped (
"<get_tasks"
1232 if (status_code == NULL)
1237 if (strlen (status_code) == 0)
1242 if (status_code[0] ==
'2')
1244 ret = (int) strtol (status_code, NULL, 10);
1246 if (errno == ERANGE)
1264 const char *name,
const void *content, gsize content_len)
1283 gchar *base64_content =
1284 g_base64_encode ((guchar *) content, content_len);
1286 g_free (base64_content);
1349 int include_rcfile,
entity_t *target)
1351 (void) include_rcfile;
1390 const char *status_code;
1392 if (response == NULL)
1401 " host_first_result=\"%i\""
1402 " host_max_results=\"%i\""
1455 if (status_code == NULL)
1460 if (strlen (status_code) == 0)
1465 if (status_code[0] ==
'2')
1467 ret = (int) strtol (status_code, NULL, 10);
1469 if (errno == ERANGE)
1491 session,
"<delete_port_list port_list_id=\"%s\" ultimate=\"%d\"/>",
id,
1545 gchar *comment, *ssh, *smb, *esxi, *snmp, *port_range, *start;
1546 gchar *exclude_hosts, *alive_tests;
1551 if (opts.
hosts == NULL)
1555 g_markup_printf_escaped (
"<create_target>"
1557 "<hosts>%s</hosts>",
1561 exclude_hosts = g_markup_printf_escaped (
"<exclude_hosts>"
1566 exclude_hosts = NULL;
1569 alive_tests = g_markup_printf_escaped (
"<alive_tests>"
1577 comment = g_markup_printf_escaped (
"<comment>"
1587 ssh = g_markup_printf_escaped (
"<ssh_lsc_credential id=\"%s\">"
1589 "</ssh_lsc_credential>",
1593 ssh = g_markup_printf_escaped (
"<ssh_lsc_credential id=\"%s\"/>",
1600 smb = g_markup_printf_escaped (
"<smb_lsc_credential id=\"%s\"/>",
1606 esxi = g_markup_printf_escaped (
"<esxi_lsc_credential id=\"%s\"/>",
1612 snmp = g_markup_printf_escaped (
"<snmp_credential id=\"%s\"/>",
1619 g_markup_printf_escaped (
"<port_range>%s</port_range>", opts.
port_range);
1625 "%s%s%s%s%s%s%s%s%s"
1626 "<reverse_lookup_only>%d</reverse_lookup_only>"
1627 "<reverse_lookup_unify>%d</reverse_lookup_unify>"
1629 start, exclude_hosts ? exclude_hosts :
"",
1630 alive_tests ? alive_tests :
"", ssh ? ssh :
"",
1631 smb ? smb :
"", esxi ? esxi :
"", snmp ? snmp :
"",
1632 port_range ? port_range :
"", comment ? comment :
"",
1635 g_free (exclude_hosts);
1636 g_free (alive_tests);
1640 g_free (port_range);
1670 "<delete_target target_id=\"%s\" ultimate=\"%d\"/>",
id,
1699 "<delete_config config_id=\"%s\" ultimate=\"%d\"/>",
id,
1725 const char *login,
const char *password,
1726 const char *comment, gchar **uuid)
1734 "<create_credential>"
1737 "<password>%s</password>"
1738 "<comment>%s</comment>"
1739 "</create_credential>",
1740 name, login, password, comment);
1743 "<create_credential>"
1746 "<password>%s</password>"
1747 "</create_credential>",
1748 name, login, password);
1754 "<create_credential>"
1757 "<comment>%s</comment>"
1758 "</create_credential>",
1759 name, login, comment);
1762 "<create_credential>"
1765 "</create_credential>",
1793 const char *login,
const char *passphrase,
1794 const char *private_key,
const char *comment,
1801 "<create_credential>"
1805 "<phrase>%s</phrase>"
1806 "<private>%s</private>"
1808 "<comment>%s</comment>"
1809 "</create_credential>",
1810 name, login, passphrase ? passphrase :
"",
1811 private_key, comment);
1814 "<create_credential>"
1818 "<phrase>%s</phrase>"
1819 "<private>%s</private>"
1821 "</create_credential>",
1822 name, login, passphrase ? passphrase :
"",
1849 gchar *comment, *pass, *start, *snmp_elems;
1854 if (opts.
login == NULL)
1858 g_markup_printf_escaped (
"<create_credential>"
1860 "<login>%s</login>",
1864 comment = g_markup_printf_escaped (
"<comment>"
1872 pass = g_markup_printf_escaped (
"<key>"
1873 "<phrase>%s</phrase>"
1874 "<private>%s</private>"
1881 pass = g_markup_printf_escaped (
"<password>"
1892 g_markup_printf_escaped (
"<community>"
1899 "<password>%s</password>"
1900 "<algorithm>%s</algorithm>"
1910 comment ? comment :
"", pass ? pass :
"",
1911 snmp_elems ? snmp_elems :
"");
1944 "<delete_credential credential_id=\"%s\""
1945 " ultimate=\"%d\"/>",
1975 "<get_system_reports name=\"%s\" brief=\"%i\"/>",
2006 request = g_string_new (
"<get_system_reports");
2023 g_string_append (request,
"/>");
2029 g_string_free (request, 1);
2032 g_string_free (request, 1);
int gmp_get_system_reports(gnutls_session_t *session, const char *name, int brief, entity_t *reports)
Get system reports.
int gmp_start_task_report(gnutls_session_t *session, const char *task_id, char **report_id)
Start a task and read the manager response.
int gmp_ping_c(gvm_connection_t *connection, int timeout, gchar **version)
"Ping" the manager.
#define GMP_FMT_BOOL_ATTRIB(var, attrib)
int gmp_delete_target_ext(gnutls_session_t *session, const char *id, gmp_delete_opts_t opts)
Delete a target.
int gmp_get_tasks_ext(gnutls_session_t *session, gmp_get_tasks_opts_t opts, entity_t *response)
Get all tasks (generic version).
const char * gmp_task_status(entity_t response)
Get the task status from a GMP GET_TASKS response.
int gmp_get_task_ext(gnutls_session_t *session, gmp_get_task_opts_t opts, entity_t *response)
Get a task (generic version).
int gmp_create_lsc_credential_ext(gnutls_session_t *session, gmp_create_lsc_credential_opts_t opts, gchar **id)
Create an LSC credential.
int gmp_create_target_ext(gnutls_session_t *session, gmp_create_target_opts_t opts, gchar **id)
Create a target.
int gmp_ping(gnutls_session_t *session, int timeout)
"Ping" the manager.
int gmp_create_task_ext(gnutls_session_t *session, gmp_create_task_opts_t opts, gchar **id)
Create a task.
int gmp_create_lsc_credential(gnutls_session_t *session, const char *name, const char *login, const char *password, const char *comment, gchar **uuid)
Create an LSC Credential.
int gmp_delete_report(gnutls_session_t *session, const char *id)
Remove a report.
int gmp_authenticate(gnutls_session_t *session, const char *username, const char *password)
Authenticate with the manager.
int gmp_stop_task_c(gvm_connection_t *connection, const char *id)
Stop a task and read the manager response.
int gmp_resume_task_report(gnutls_session_t *session, const char *task_id, char **report_id)
Resume a task and read the manager response.
int gmp_create_task(gnutls_session_t *session, const char *name, const char *config, const char *target, const char *comment, gchar **id)
Create a task given a config and target.
int gmp_modify_task_file(gnutls_session_t *session, const char *id, const char *name, const void *content, gsize content_len)
Modify a file on a task.
int gmp_start_task_report_c(gvm_connection_t *connection, const char *task_id, char **report_id)
Start a task and read the manager response.
static int gmp_check_response_c(gvm_connection_t *connection)
Read response and convert status of response to a return value.
int gmp_delete_task(gnutls_session_t *session, const char *id)
Delete a task and read the manager response.
int gmp_delete_port_list_ext(gnutls_session_t *session, const char *id, gmp_delete_opts_t opts)
Delete a port list.
static int check_response_c(gvm_connection_t *connection, int convert_99)
Read response and convert status of response to a return value.
int gmp_authenticate_info_ext_c(gvm_connection_t *connection, gmp_authenticate_info_opts_t opts)
Authenticate with the manager.
int gmp_delete_task_ext(gnutls_session_t *session, const char *id, gmp_delete_opts_t opts)
Delete a task and read the manager response.
int gmp_resume_task_report_c(gvm_connection_t *connection, const char *task_id, char **report_id)
Resume a task and read the manager response.
int gmp_delete_config_ext(gnutls_session_t *session, const char *id, gmp_delete_opts_t opts)
Delete a config.
int gmp_read_create_response(gnutls_session_t *session, gchar **uuid)
Read response status and resource UUID.
int gmp_get_report_ext(gnutls_session_t *session, gmp_get_report_opts_t opts, entity_t *response)
Get a report (generic version).
int gmp_delete_lsc_credential_ext(gnutls_session_t *session, const char *id, gmp_delete_opts_t opts)
Delete a LSC credential.
int gmp_authenticate_info_ext(gnutls_session_t *session, gmp_authenticate_info_opts_t opts)
Authenticate with the manager.
int gmp_start_task_ext_c(gvm_connection_t *connection, gmp_start_task_opts_t opts)
Start a task and read the manager response.
int gmp_get_tasks(gnutls_session_t *session, const char *id, int details, int include_rcfile, entity_t *status)
Get the status of a task.
#define GMP_FMT_STRING_ATTRIB(var, attrib)
int gmp_get_system_reports_ext(gnutls_session_t *session, gmp_get_system_reports_opts_t opts, entity_t *reports)
Get system reports.
int gmp_get_targets(gnutls_session_t *session, const char *id, int tasks, int include_rcfile, entity_t *target)
Get a target.
int gmp_create_lsc_credential_key(gnutls_session_t *session, const char *name, const char *login, const char *passphrase, const char *private_key, const char *comment, gchar **uuid)
Create an LSC Credential with a key.
int gmp_stop_task(gnutls_session_t *session, const char *id)
Stop a task and read the manager response.
static int gmp_check_response(gnutls_session_t *session, entity_t *entity)
Read response and convert status of response to a return value.
API for Greenbone Management Protocol communication.
int gvm_connection_sendf(gvm_connection_t *connection, const char *format,...)
Format and send a string to the server.
int gvm_server_sendf_xml_quiet(gnutls_session_t *session, const char *format,...)
Format and send an XML string to the server.
int gvm_server_sendf_xml(gnutls_session_t *session, const char *format,...)
Format and send an XML string to the server.
int gvm_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
int gvm_connection_sendf_xml_quiet(gvm_connection_t *connection, const char *format,...)
Format and send an XML string to the server.
GnuTLS based functions for server communication - header file.
Struct holding options for authentication.
const char * password
Username.
int timeout
Timeout for authentication.
char ** pw_warning
[out] Password warning, NULL if password is okay.
char ** timezone
[out] Timezone if any, else NULL.
const char * username
Password.
Struct holding options for gmp create_lsc_credential command.
const char * privacy_password
SNMP privacy password.
const char * privacy_algorithm
SNMP privacy algorithm.
const char * community
SNMP community.
const char * passphrase
Passphrase.
const char * comment
Comment on LSC credential.
const char * private_key
Private key.
const char * auth_algorithm
SNMP authentication algorithm.
const char * name
Name of LSC credential.
Struct holding options for gmp create_target command.
const char * exclude_hosts
Hosts to exclude.
const char * comment
Comment on target.
const char * smb_credential_id
ID of SMB credential.
int reverse_lookup_only
Scanner pref reverse_lookup_only.
int reverse_lookup_unify
Scanner pref reverse_lookup_unify.
const char * esxi_credential_id
ID of ESXi credential.
const char * snmp_credential_id
ID of SNMP credential.
const char * hosts
Name of target.
const char * port_range
Port range.
int ssh_credential_port
Port for SSH access.
const char * alive_tests
Alive tests.
const char * ssh_credential_id
ID of SSH credential.
const char * name
Name of target.
Struct holding options for gmp create_task command.
int schedule_periods
Number of periods the schedule must run for.
const char * max_checks
Max checks preference.
const char * slave_id
ID of task schedule.
array_t * alert_ids
Array of alert IDs.
const char * config_id
ID of config.
const char * in_assets
In assets preference.
const char * schedule_id
ID of task schedule.
const char * source_iface
Source iface preference.
array_t * observer_groups
IDs of observer groups.
const char * observers
Comma-separated string of observer users.
const char * name
Name of task.
const char * target_id
ID of target.
const char * scanner_id
ID of task scanner.
int alterable
Whether the task is alterable.
const char * max_hosts
Max hosts preference.
const char * hosts_ordering
Order for scanning target hosts.
const char * comment
Comment on task.
Struct holding options for various gmp delete_[...] commands.
Struct holding options for gmp get_report command.
int timeout
Timeout for GMP response.
const char * format_id
ID of required report format.
int host_max_results
Maximum number of results to return.
const char * report_id
ID of single report to get.
int host_first_result
Skip over results before this result number.
Struct holding options for gmp get_system_reports command.
const char * duration
Duration.
const char * slave_id
ID of the slave to get report from.
const char * end_time
Time of last data point.
const char * name
Name of report.
const char * start_time
Time of first data point.
Struct holding options for gmp get_tasks command.
const char * task_id
ID of single task to get.
const char * actions
Actions argument.
Struct holding options for gmp get_tasks command.
int timeout
Timeout for GMP response.
const char * filter
Filter argument.
Struct holding options for gmp start_task command.
const char * task_id
ID of task.
int read_entity_c(gvm_connection_t *connection, entity_t *entity)
Read an XML entity tree from the manager.
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
char * entity_text(entity_t entity)
Get the text an entity.
int read_entity(gnutls_session_t *session, entity_t *entity)
Read an XML entity tree from the manager.
int try_read_entity(gnutls_session_t *session, int timeout, entity_t *entity)
Try read an XML entity tree from the manager.
void free_entity(entity_t entity)
Free an entity, recursively.
entity_t entity_child(entity_t entity, const char *name)
Get a child of an entity.
int try_read_entity_c(gvm_connection_t *connection, int timeout, entity_t *entity)
Try read an XML entity tree from the manager.
void xml_string_append(GString *xml, const char *format,...)
Append formatted escaped XML to a string.
struct entity_s * entity_t