Greenbone Vulnerability Management Libraries
11.0.1
|
Go to the documentation of this file.
32 #include "../util/serverutils.h"
42 #define G_LOG_DOMAIN "lib gmp"
44 #define GMP_FMT_BOOL_ATTRIB(var, attrib) \
45 (var.attrib == 0 ? " " #attrib "=\"0\"" : " " #attrib "=\"1\"")
47 #define GMP_FMT_STRING_ATTRIB(var, attrib) \
48 (var.attrib ? " " #attrib "= \"" : ""), (var.attrib ? var.attrib : ""), \
49 (var.attrib ? "\"" : "")
102 if (strlen (status) == 0)
107 if (status[0] ==
'2')
111 ret = (int) strtol (status, NULL, 10);
163 if (strlen (status) == 0)
194 if (version && *version)
224 if (strlen (status) == 0)
229 if (status[0] ==
'2')
235 if (omp_version == NULL)
261 const char *password)
268 "<authenticate><credentials>"
269 "<username>%s</username>"
270 "<password>%s</password>"
271 "</credentials></authenticate>",
272 username ? username :
"",
273 password ? password :
"");
316 "<authenticate><credentials>"
317 "<username>%s</username>"
318 "<password>%s</password>"
319 "</credentials></authenticate>",
345 if (strlen (status) == 0)
353 entity_t timezone_entity, role_entity, severity_entity, pw_warn_entity;
364 pw_warn_entity =
entity_child (entity,
"password_warning");
403 "<username>%s</username>"
404 "<password>%s</password>"
432 if (strlen (status) == 0)
440 entity_t timezone_entity, role_entity, severity_entity;
443 if (timezone_entity && opts.
timezone)
446 if (role_entity && opts.
role)
449 if (severity_entity && opts.
severity)
454 pw_warn_entity =
entity_child (entity,
"password_warning");
487 gchar *
prefs, *start, *hosts_ordering, *scanner, *schedule, *slave;
488 GString *alerts, *observers;
494 start = g_markup_printf_escaped (
496 "<config id=\"%s\"/>"
497 "<target id=\"%s\"/>"
499 "<comment>%s</comment>"
500 "<alterable>%d</alterable>",
505 hosts_ordering = g_strdup_printf (
"<hosts_ordering>%s</hosts_ordering>",
508 hosts_ordering = NULL;
511 scanner = g_strdup_printf (
"<scanner id=\"%s\"/>", opts.
scanner_id);
516 schedule = g_strdup_printf (
"<schedule id=\"%s\"/>"
517 "<schedule_periods>%d</schedule_periods>",
523 slave = g_strdup_printf (
"<slave id=\"%s\"/>", opts.
slave_id);
529 gchar *in_assets, *checks, *hosts, *source_iface;
531 in_assets = checks = hosts = source_iface = NULL;
534 in_assets = g_markup_printf_escaped (
"<preference>"
545 hosts = g_markup_printf_escaped (
"<preference>"
556 checks = g_markup_printf_escaped (
"<preference>"
567 source_iface = g_markup_printf_escaped (
"<preference>"
578 g_strdup_printf (
"<preferences>%s%s%s%s</preferences>",
579 in_assets ? in_assets :
"", checks ? checks :
"",
580 hosts ? hosts :
"", source_iface ? source_iface :
"");
584 g_free (source_iface);
590 alerts = g_string_new (
"");
591 for (i = 0; i < opts.
alert_ids->len; i++)
593 char *alert = (
char *) g_ptr_array_index (opts.
alert_ids, i);
594 g_string_append_printf (alerts,
"<alert id=\"%s\"/>", alert);
598 alerts = g_string_new (
"");
602 observers = g_string_new (
"<observers>");
605 g_string_append (observers, opts.
observers);
614 g_string_append_printf (observers,
"<group id=\"%s\"/>", group);
617 g_string_append (observers,
"</observers>");
620 observers = g_string_new (
"");
624 session,
"%s%s%s%s%s%s%s%s</create_task>", start,
prefs ?
prefs :
"",
625 hosts_ordering ? hosts_ordering :
"", scanner ? scanner :
"",
626 schedule ? schedule :
"", slave ? slave :
"", alerts ? alerts->str :
"",
627 observers ? observers->str :
"");
630 g_free (hosts_ordering);
634 g_string_free (alerts, TRUE);
635 g_string_free (observers, TRUE);
663 const char *config,
const char *target,
const char *comment,
670 "<config id=\"%s\"/>"
671 "<target id=\"%s\"/>"
673 "<comment>%s</comment>"
675 config, target,
name, comment);
702 if (
gvm_server_sendf (session,
"<start_task task_id=\"%s\"/>", task_id) == -1)
716 *report_id = g_strdup (
entity_text (report_id_xml));
767 if (strlen (status) == 0)
779 *report_id = g_strdup (
entity_text (report_id_xml));
821 if (strlen (status) == 0)
826 if (status[0] ==
'2')
831 ret = (int) strtol (status, NULL, 10);
868 if (strlen (status) == 0)
884 if (strlen (
id) == 0)
889 *uuid = g_strdup (
id);
969 *report_id = g_strdup (
entity_text (report_id_xml));
1016 if (strlen (status) == 0)
1021 char first = status[0];
1028 *report_id = g_strdup (
entity_text (report_id_xml));
1059 "<delete_task task_id=\"%s\" ultimate=\"%d\"/>",
id,
1085 int include_rcfile,
entity_t *status)
1087 (void) include_rcfile;
1099 " details=\"%i\"/>",
1122 if ((response == NULL) || (opts.
task_id == NULL))
1160 const char *status_code;
1163 if (response == NULL)
1166 cmd = g_markup_printf_escaped (
"<get_tasks"
1192 if (status_code == NULL)
1197 if (strlen (status_code) == 0)
1202 if (status_code[0] ==
'2')
1204 ret = (int) strtol (status_code, NULL, 10);
1206 if (errno == ERANGE)
1224 const char *
name,
const void *content, gsize content_len)
1243 gchar *base64_content =
1244 g_base64_encode ((guchar *) content, content_len);
1246 g_free (base64_content);
1309 int include_rcfile,
entity_t *target)
1311 (void) include_rcfile;
1350 const char *status_code;
1352 if (response == NULL)
1361 " host_first_result=\"%i\""
1362 " host_max_results=\"%i\""
1415 if (status_code == NULL)
1420 if (strlen (status_code) == 0)
1425 if (status_code[0] ==
'2')
1427 ret = (int) strtol (status_code, NULL, 10);
1429 if (errno == ERANGE)
1451 session,
"<delete_port_list port_list_id=\"%s\" ultimate=\"%d\"/>",
id,
1505 gchar *comment, *ssh, *smb, *esxi, *snmp, *port_range, *start;
1506 gchar *exclude_hosts, *alive_tests;
1511 if (opts.
hosts == NULL)
1515 g_markup_printf_escaped (
"<create_target>"
1517 "<hosts>%s</hosts>",
1521 exclude_hosts = g_markup_printf_escaped (
"<exclude_hosts>"
1526 exclude_hosts = NULL;
1529 alive_tests = g_markup_printf_escaped (
"<alive_tests>"
1537 comment = g_markup_printf_escaped (
"<comment>"
1547 ssh = g_markup_printf_escaped (
"<ssh_lsc_credential id=\"%s\">"
1549 "</ssh_lsc_credential>",
1553 ssh = g_markup_printf_escaped (
"<ssh_lsc_credential id=\"%s\"/>",
1560 smb = g_markup_printf_escaped (
"<smb_lsc_credential id=\"%s\"/>",
1566 esxi = g_markup_printf_escaped (
"<esxi_lsc_credential id=\"%s\"/>",
1572 snmp = g_markup_printf_escaped (
"<snmp_credential id=\"%s\"/>",
1579 g_markup_printf_escaped (
"<port_range>%s</port_range>", opts.
port_range);
1585 "%s%s%s%s%s%s%s%s%s"
1586 "<reverse_lookup_only>%d</reverse_lookup_only>"
1587 "<reverse_lookup_unify>%d</reverse_lookup_unify>"
1589 start, exclude_hosts ? exclude_hosts :
"",
1590 alive_tests ? alive_tests :
"", ssh ? ssh :
"",
1591 smb ? smb :
"", esxi ? esxi :
"", snmp ? snmp :
"",
1592 port_range ? port_range :
"", comment ? comment :
"",
1595 g_free (exclude_hosts);
1596 g_free (alive_tests);
1600 g_free (port_range);
1630 "<delete_target target_id=\"%s\" ultimate=\"%d\"/>",
id,
1659 "<delete_config config_id=\"%s\" ultimate=\"%d\"/>",
id,
1685 const char *login,
const char *password,
1686 const char *comment, gchar **uuid)
1694 "<create_credential>"
1697 "<password>%s</password>"
1698 "<comment>%s</comment>"
1699 "</create_credential>",
1700 name, login, password, comment);
1703 "<create_credential>"
1706 "<password>%s</password>"
1707 "</create_credential>",
1708 name, login, password);
1714 "<create_credential>"
1717 "<comment>%s</comment>"
1718 "</create_credential>",
1719 name, login, comment);
1722 "<create_credential>"
1725 "</create_credential>",
1753 const char *login,
const char *passphrase,
1754 const char *private_key,
const char *comment,
1761 "<create_credential>"
1765 "<phrase>%s</phrase>"
1766 "<private>%s</private>"
1768 "<comment>%s</comment>"
1769 "</create_credential>",
1770 name, login, passphrase ? passphrase :
"",
1771 private_key, comment);
1774 "<create_credential>"
1778 "<phrase>%s</phrase>"
1779 "<private>%s</private>"
1781 "</create_credential>",
1782 name, login, passphrase ? passphrase :
"",
1809 gchar *comment, *pass, *start, *snmp_elems;
1814 if (opts.
login == NULL)
1818 g_markup_printf_escaped (
"<create_credential>"
1820 "<login>%s</login>",
1824 comment = g_markup_printf_escaped (
"<comment>"
1832 pass = g_markup_printf_escaped (
"<key>"
1833 "<phrase>%s</phrase>"
1834 "<private>%s</private>"
1841 pass = g_markup_printf_escaped (
"<password>"
1852 g_markup_printf_escaped (
"<community>"
1859 "<password>%s</password>"
1860 "<algorithm>%s</algorithm>"
1870 comment ? comment :
"", pass ? pass :
"",
1871 snmp_elems ? snmp_elems :
"");
1904 "<delete_credential credential_id=\"%s\""
1905 " ultimate=\"%d\"/>",
1935 "<get_system_reports name=\"%s\" brief=\"%i\"/>",
1966 request = g_string_new (
"<get_system_reports");
1983 g_string_append (request,
"/>");
1989 g_string_free (request, 1);
1992 g_string_free (request, 1);
const char * ssh_credential_id
ID of SSH credential.
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
int host_first_result
Skip over results before this result number.
const char * slave_id
ID of task schedule.
entity_t entity_child(entity_t entity, const char *name)
Get a child of an entity.
#define GMP_FMT_BOOL_ATTRIB(var, attrib)
const char * privacy_algorithm
SNMP privacy algorithm.
const char * private_key
Private key.
const char * task_id
ID of single task to get.
#define GMP_FMT_STRING_ATTRIB(var, attrib)
const char * format_id
ID of required report format.
const char * hosts
Name of target.
const char * auth_algorithm
SNMP authentication algorithm.
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.
const char * username
Password.
const char * actions
Actions argument.
int gvm_connection_sendf(gvm_connection_t *connection, const char *format,...)
Format and send a string to the server.
const char * exclude_hosts
Hosts to exclude.
int gmp_delete_config_ext(gnutls_session_t *session, const char *id, gmp_delete_opts_t opts)
Delete a config.
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_delete_task_ext(gnutls_session_t *session, const char *id, gmp_delete_opts_t opts)
Delete a task and read the manager response.
const char * target_id
ID of target.
char * entity_text(entity_t entity)
Get the text an entity.
const char * max_checks
Max checks preference.
int gmp_authenticate_info_ext(gnutls_session_t *session, gmp_authenticate_info_opts_t opts)
Authenticate with the manager.
int gmp_get_targets(gnutls_session_t *session, const char *id, int tasks, int include_rcfile, entity_t *target)
Get a target.
int gmp_resume_task_report(gnutls_session_t *session, const char *task_id, char **report_id)
Resume a task and read the manager response.
char ** severity
[out] Severity class setting.
int read_entity(gnutls_session_t *session, entity_t *entity)
Read an XML entity tree from the manager.
int gmp_check_response(gnutls_session_t *session, entity_t *entity)
Read response and convert status of response to a return value.
int gvm_server_sendf_xml(gnutls_session_t *session, const char *format,...)
Format and send an XML string to the server.
const char * snmp_credential_id
ID of SNMP credential.
gint timeout
Default timeout time for this NVT.
void free_entity(entity_t entity)
Free an entity, recursively.
int gmp_delete_target_ext(gnutls_session_t *session, const char *id, gmp_delete_opts_t opts)
Delete a target.
const char * report_id
ID of single report to get.
const char * hosts_ordering
Order for scanning target hosts.
void xml_string_append(GString *xml, const char *format,...)
Append formatted escaped XML to a string.
Struct holding options for gmp get_report command.
const char * name
Name of target.
Struct holding options for gmp get_tasks command.
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.
const char * in_assets
In assets preference.
int read_entity_c(gvm_connection_t *connection, entity_t *entity)
Read an XML entity tree from the manager.
const char * duration
Duration.
int gmp_ping(gnutls_session_t *session, int timeout)
"Ping" the manager.
Struct holding options for gmp create_task command.
int gmp_stop_task_c(gvm_connection_t *connection, const char *id)
Stop a task and read the manager response.
int timeout
Timeout for GMP response.
int reverse_lookup_only
Scanner pref reverse_lookup_only.
const char * slave_id
ID of the slave to get report from.
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.
const char * start_time
Time of first data point.
const char * name
Name of LSC credential.
Struct holding options for gmp create_lsc_credential command.
const char * passphrase
Passphrase.
const char * gmp_task_status(entity_t response)
Get the task status from a GMP GET_TASKS response.
int gmp_create_lsc_credential_ext(gnutls_session_t *session, gmp_create_lsc_credential_opts_t opts, gchar **id)
Create an LSC credential.
int timeout
Timeout for authentication.
const char * esxi_credential_id
ID of ESXi credential.
Struct holding options for various gmp delete_[...] commands.
const char * password
Username.
int gmp_create_task_ext(gnutls_session_t *session, gmp_create_task_opts_t opts, gchar **id)
Create a task.
int gmp_ping_c(gvm_connection_t *connection, int timeout, gchar **version)
"Ping" the manager.
int try_read_entity(gnutls_session_t *session, int timeout, entity_t *entity)
Try read an XML entity tree from the manager.
char ** timezone
[out] Timezone if any, else NULL.
int gmp_authenticate(gnutls_session_t *session, const char *username, const char *password)
Authenticate with the manager.
int gmp_create_target_ext(gnutls_session_t *session, gmp_create_target_opts_t opts, gchar **id)
Create a target.
const char * community
SNMP community.
int gmp_get_system_reports_ext(gnutls_session_t *session, gmp_get_system_reports_opts_t opts, entity_t *reports)
Get system reports.
int gvm_connection_sendf_xml_quiet(gvm_connection_t *connection, const char *format,...)
Format and send an XML string to the server.
const char * comment
Comment on task.
int alterable
Whether the task is alterable.
array_t * alert_ids
Array of alert IDs.
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.
Struct holding options for gmp get_system_reports command.
int gmp_authenticate_info_ext_c(gvm_connection_t *connection, gmp_authenticate_info_opts_t opts)
Authenticate with the manager.
int gmp_delete_lsc_credential_ext(gnutls_session_t *session, const char *id, gmp_delete_opts_t opts)
Delete a LSC credential.
const char * comment
Comment on LSC credential.
const char * schedule_id
ID of task schedule.
const char * max_hosts
Max hosts preference.
const char * filter
Filter argument.
int gmp_stop_task(gnutls_session_t *session, const char *id)
Stop a task and read the manager response.
array_t * observer_groups
IDs of observer groups.
const char * comment
Comment on target.
int schedule_periods
Number of periods the schedule must run for.
int host_max_results
Maximum number of results to return.
const char * name
Name of report.
int gvm_server_sendf_xml_quiet(gnutls_session_t *session, const char *format,...)
Format and send an XML string to the server.
const char * name
Name of task.
const char * observers
Comma-separated string of observer users.
int gmp_read_create_response(gnutls_session_t *session, gchar **uuid)
Read response status and resource UUID.
const char * scanner_id
ID of task scanner.
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_delete_port_list_ext(gnutls_session_t *session, const char *id, gmp_delete_opts_t opts)
Delete a port list.
const char * config_id
ID of config.
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_delete_report(gnutls_session_t *session, const char *id)
Remove a report.
Struct holding options for gmp get_tasks command.
int timeout
Timeout for GMP response.
char ** pw_warning
[out] Password warning, NULL if password is okay.
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.
const char * source_iface
Source iface preference.
const char * alive_tests
Alive tests.
const char * end_time
Time of last data point.
int reverse_lookup_unify
Scanner pref reverse_lookup_unify.
API for Greenbone Management Protocol communication.
int gvm_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
int try_read_entity_c(gvm_connection_t *connection, int timeout, entity_t *entity)
Try read an XML entity tree from the manager.
int gmp_get_system_reports(gnutls_session_t *session, const char *name, int brief, entity_t *reports)
Get system reports.
int gmp_get_tasks_ext(gnutls_session_t *session, gmp_get_tasks_opts_t opts, entity_t *response)
Get all tasks (generic version).
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_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_start_task_report_c(gvm_connection_t *connection, const char *task_id, char **report_id)
Start a task and read the manager response.
const char * port_range
Port range.
int ssh_credential_port
Port for SSH access.
Struct holding options for authentication.
GSList * prefs
Collection of NVT preferences.
const char * privacy_password
SNMP privacy password.
const char * smb_credential_id
ID of SMB credential.
Struct holding options for gmp create_target command.