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");
465 "<authenticate token=\"%d\">"
467 "<username>%s</username>"
468 "<password>%s</password>"
497 if (strlen (status) == 0)
505 entity_t timezone_entity, role_entity, token_entity;
508 if (timezone_entity && opts.
timezone)
511 if (role_entity && opts.
role)
516 pw_warn_entity =
entity_child (entity,
"password_warning");
552 gchar *prefs, *start, *scanner, *schedule, *slave;
553 GString *alerts, *observers;
559 start = g_markup_printf_escaped (
561 "<config id=\"%s\"/>"
562 "<target id=\"%s\"/>"
564 "<comment>%s</comment>"
565 "<alterable>%d</alterable>",
570 scanner = g_strdup_printf (
"<scanner id=\"%s\"/>", opts.
scanner_id);
575 schedule = g_strdup_printf (
"<schedule id=\"%s\"/>"
576 "<schedule_periods>%d</schedule_periods>",
582 slave = g_strdup_printf (
"<slave id=\"%s\"/>", opts.
slave_id);
588 gchar *in_assets, *checks, *hosts, *source_iface;
590 in_assets = checks = hosts = source_iface = NULL;
593 in_assets = g_markup_printf_escaped (
"<preference>"
604 hosts = g_markup_printf_escaped (
"<preference>"
615 checks = g_markup_printf_escaped (
"<preference>"
626 source_iface = g_markup_printf_escaped (
"<preference>"
637 g_strdup_printf (
"<preferences>%s%s%s%s</preferences>",
638 in_assets ? in_assets :
"", checks ? checks :
"",
639 hosts ? hosts :
"", source_iface ? source_iface :
"");
643 g_free (source_iface);
649 alerts = g_string_new (
"");
650 for (i = 0; i < opts.
alert_ids->len; i++)
652 char *alert = (
char *) g_ptr_array_index (opts.
alert_ids, i);
653 g_string_append_printf (alerts,
"<alert id=\"%s\"/>", alert);
657 alerts = g_string_new (
"");
661 observers = g_string_new (
"<observers>");
664 g_string_append (observers, opts.
observers);
673 g_string_append_printf (observers,
"<group id=\"%s\"/>", group);
676 g_string_append (observers,
"</observers>");
679 observers = g_string_new (
"");
683 session,
"%s%s%s%s%s%s%s</create_task>", start, prefs ? prefs :
"",
684 scanner ? scanner :
"", schedule ? schedule :
"", slave ? slave :
"",
685 alerts ? alerts->str :
"", observers ? observers->str :
"");
691 g_string_free (alerts, TRUE);
692 g_string_free (observers, TRUE);
720 const char *config,
const char *target,
const char *comment,
727 "<config id=\"%s\"/>"
728 "<target id=\"%s\"/>"
730 "<comment>%s</comment>"
732 config, target, name, comment);
759 if (
gvm_server_sendf (session,
"<start_task task_id=\"%s\"/>", task_id) == -1)
773 *report_id = g_strdup (
entity_text (report_id_xml));
824 if (strlen (status) == 0)
836 *report_id = g_strdup (
entity_text (report_id_xml));
910 if (strlen (status) == 0)
926 if (strlen (
id) == 0)
931 *uuid = g_strdup (
id);
1011 *report_id = g_strdup (
entity_text (report_id_xml));
1058 if (strlen (status) == 0)
1063 char first = status[0];
1070 *report_id = g_strdup (
entity_text (report_id_xml));
1101 "<delete_task task_id=\"%s\" ultimate=\"%d\"/>",
id,
1127 int include_rcfile,
entity_t *status)
1129 (void) include_rcfile;
1141 " details=\"%i\"/>",
1164 if ((response == NULL) || (opts.
task_id == NULL))
1202 const char *status_code;
1205 if (response == NULL)
1208 cmd = g_markup_printf_escaped (
"<get_tasks"
1234 if (status_code == NULL)
1239 if (strlen (status_code) == 0)
1244 if (status_code[0] ==
'2')
1246 ret = (int) strtol (status_code, NULL, 10);
1248 if (errno == ERANGE)
1266 const char *name,
const void *content, gsize content_len)
1285 gchar *base64_content =
1286 g_base64_encode ((guchar *) content, content_len);
1288 g_free (base64_content);
1351 int include_rcfile,
entity_t *target)
1353 (void) include_rcfile;
1392 const char *status_code;
1394 if (response == NULL)
1403 " host_first_result=\"%i\""
1404 " host_max_results=\"%i\""
1457 if (status_code == NULL)
1462 if (strlen (status_code) == 0)
1467 if (status_code[0] ==
'2')
1469 ret = (int) strtol (status_code, NULL, 10);
1471 if (errno == ERANGE)
1493 session,
"<delete_port_list port_list_id=\"%s\" ultimate=\"%d\"/>",
id,
1547 gchar *comment, *ssh, *smb, *esxi, *snmp, *port_range, *start;
1548 gchar *exclude_hosts, *alive_tests;
1553 if (opts.
hosts == NULL)
1557 g_markup_printf_escaped (
"<create_target>"
1559 "<hosts>%s</hosts>",
1563 exclude_hosts = g_markup_printf_escaped (
"<exclude_hosts>"
1568 exclude_hosts = NULL;
1571 alive_tests = g_markup_printf_escaped (
"<alive_tests>"
1579 comment = g_markup_printf_escaped (
"<comment>"
1589 ssh = g_markup_printf_escaped (
"<ssh_lsc_credential id=\"%s\">"
1591 "</ssh_lsc_credential>",
1595 ssh = g_markup_printf_escaped (
"<ssh_lsc_credential id=\"%s\"/>",
1602 smb = g_markup_printf_escaped (
"<smb_lsc_credential id=\"%s\"/>",
1608 esxi = g_markup_printf_escaped (
"<esxi_lsc_credential id=\"%s\"/>",
1614 snmp = g_markup_printf_escaped (
"<snmp_credential id=\"%s\"/>",
1621 g_markup_printf_escaped (
"<port_range>%s</port_range>", opts.
port_range);
1627 "%s%s%s%s%s%s%s%s%s"
1628 "<reverse_lookup_only>%d</reverse_lookup_only>"
1629 "<reverse_lookup_unify>%d</reverse_lookup_unify>"
1631 start, exclude_hosts ? exclude_hosts :
"",
1632 alive_tests ? alive_tests :
"", ssh ? ssh :
"",
1633 smb ? smb :
"", esxi ? esxi :
"", snmp ? snmp :
"",
1634 port_range ? port_range :
"", comment ? comment :
"",
1637 g_free (exclude_hosts);
1638 g_free (alive_tests);
1642 g_free (port_range);
1672 "<delete_target target_id=\"%s\" ultimate=\"%d\"/>",
id,
1701 "<delete_config config_id=\"%s\" ultimate=\"%d\"/>",
id,
1727 const char *login,
const char *password,
1728 const char *comment, gchar **uuid)
1736 "<create_credential>"
1739 "<password>%s</password>"
1740 "<comment>%s</comment>"
1741 "</create_credential>",
1742 name, login, password, comment);
1745 "<create_credential>"
1748 "<password>%s</password>"
1749 "</create_credential>",
1750 name, login, password);
1756 "<create_credential>"
1759 "<comment>%s</comment>"
1760 "</create_credential>",
1761 name, login, comment);
1764 "<create_credential>"
1767 "</create_credential>",
1795 const char *login,
const char *passphrase,
1796 const char *private_key,
const char *comment,
1803 "<create_credential>"
1807 "<phrase>%s</phrase>"
1808 "<private>%s</private>"
1810 "<comment>%s</comment>"
1811 "</create_credential>",
1812 name, login, passphrase ? passphrase :
"",
1813 private_key, comment);
1816 "<create_credential>"
1820 "<phrase>%s</phrase>"
1821 "<private>%s</private>"
1823 "</create_credential>",
1824 name, login, passphrase ? passphrase :
"",
1851 gchar *comment, *pass, *start, *snmp_elems;
1856 if (opts.
login == NULL)
1860 g_markup_printf_escaped (
"<create_credential>"
1862 "<login>%s</login>",
1866 comment = g_markup_printf_escaped (
"<comment>"
1874 pass = g_markup_printf_escaped (
"<key>"
1875 "<phrase>%s</phrase>"
1876 "<private>%s</private>"
1883 pass = g_markup_printf_escaped (
"<password>"
1894 g_markup_printf_escaped (
"<community>"
1901 "<password>%s</password>"
1902 "<algorithm>%s</algorithm>"
1912 comment ? comment :
"", pass ? pass :
"",
1913 snmp_elems ? snmp_elems :
"");
1946 "<delete_credential credential_id=\"%s\""
1947 " ultimate=\"%d\"/>",
1977 "<get_system_reports name=\"%s\" brief=\"%i\"/>",
2008 request = g_string_new (
"<get_system_reports");
2025 g_string_append (request,
"/>");
2031 g_string_free (request, 1);
2034 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.
Definition gmp.c:1971
int gmp_start_task_report(gnutls_session_t *session, const char *task_id, char **report_id)
Start a task and read the manager response.
Definition gmp.c:754
int gmp_ping_c(gvm_connection_t *connection, int timeout, gchar **version)
"Ping" the manager.
Definition gmp.c:249
#define GMP_FMT_BOOL_ATTRIB(var, attrib)
Definition gmp.c:30
int gmp_delete_target_ext(gnutls_session_t *session, const char *id, gmp_delete_opts_t opts)
Delete a target.
Definition gmp.c:1665
int gmp_get_tasks_ext(gnutls_session_t *session, gmp_get_tasks_opts_t opts, entity_t *response)
Get all tasks (generic version).
Definition gmp.c:1198
const char * gmp_task_status(entity_t response)
Get the task status from a GMP GET_TASKS response.
Definition gmp.c:48
int gmp_get_task_ext(gnutls_session_t *session, gmp_get_task_opts_t opts, entity_t *response)
Get a task (generic version).
Definition gmp.c:1161
int gmp_create_lsc_credential_ext(gnutls_session_t *session, gmp_create_lsc_credential_opts_t opts, gchar **id)
Create an LSC credential.
Definition gmp.c:1847
int gmp_create_target_ext(gnutls_session_t *session, gmp_create_target_opts_t opts, gchar **id)
Create a target.
Definition gmp.c:1544
int gmp_ping(gnutls_session_t *session, int timeout)
"Ping" the manager.
Definition gmp.c:190
int gmp_create_task_ext(gnutls_session_t *session, gmp_create_task_opts_t opts, gchar **id)
Create a task.
Definition gmp.c:547
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.
Definition gmp.c:1726
int gmp_delete_report(gnutls_session_t *session, const char *id)
Remove a report.
Definition gmp.c:1514
int gmp_authenticate(gnutls_session_t *session, const char *username, const char *password)
Authenticate with the manager.
Definition gmp.c:321
int gmp_stop_task_c(gvm_connection_t *connection, const char *id)
Stop a task and read the manager response.
Definition gmp.c:972
int gmp_resume_task_report(gnutls_session_t *session, const char *task_id, char **report_id)
Resume a task and read the manager response.
Definition gmp.c:991
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.
Definition gmp.c:719
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.
Definition gmp.c:1265
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.
Definition gmp.c:799
static int gmp_check_response_c(gvm_connection_t *connection)
Read response and convert status of response to a return value.
Definition gmp.c:174
int gmp_delete_task(gnutls_session_t *session, const char *id)
Delete a task and read the manager response.
Definition gmp.c:1322
int gmp_delete_port_list_ext(gnutls_session_t *session, const char *id, gmp_delete_opts_t opts)
Delete a port list.
Definition gmp.c:1486
static int check_response_c(gvm_connection_t *connection, int convert_99)
Read response and convert status of response to a return value.
Definition gmp.c:119
int gmp_authenticate_info_ext_c(gvm_connection_t *connection, gmp_authenticate_info_opts_t opts)
Authenticate with the manager.
Definition gmp.c:445
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.
Definition gmp.c:1094
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.
Definition gmp.c:1036
int gmp_delete_config_ext(gnutls_session_t *session, const char *id, gmp_delete_opts_t opts)
Delete a config.
Definition gmp.c:1694
int gmp_read_create_response(gnutls_session_t *session, gchar **uuid)
Read response status and resource UUID.
Definition gmp.c:890
int gmp_get_report_ext(gnutls_session_t *session, gmp_get_report_opts_t opts, entity_t *response)
Get a report (generic version).
Definition gmp.c:1388
int gmp_delete_lsc_credential_ext(gnutls_session_t *session, const char *id, gmp_delete_opts_t opts)
Delete a LSC credential.
Definition gmp.c:1939
int gmp_authenticate_info_ext(gnutls_session_t *session, gmp_authenticate_info_opts_t opts)
Authenticate with the manager.
Definition gmp.c:364
int gmp_start_task_ext_c(gvm_connection_t *connection, gmp_start_task_opts_t opts)
Start a task and read the manager response.
Definition gmp.c:859
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.
Definition gmp.c:1126
#define GMP_FMT_STRING_ATTRIB(var, attrib)
Definition gmp.c:33
int gmp_get_system_reports_ext(gnutls_session_t *session, gmp_get_system_reports_opts_t opts, entity_t *reports)
Get system reports.
Definition gmp.c:2002
int gmp_get_targets(gnutls_session_t *session, const char *id, int tasks, int include_rcfile, entity_t *target)
Get a target.
Definition gmp.c:1350
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.
Definition gmp.c:1794
int gmp_stop_task(gnutls_session_t *session, const char *id)
Stop a task and read the manager response.
Definition gmp.c:948
static int gmp_check_response(gnutls_session_t *session, entity_t *entity)
Read response and convert status of response to a return value.
Definition gmp.c:70
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.
Definition serverutils.c:823
int gvm_server_sendf_xml_quiet(gnutls_session_t *session, const char *format,...)
Format and send an XML string to the server.
Definition serverutils.c:938
int gvm_server_sendf_xml(gnutls_session_t *session, const char *format,...)
Format and send an XML string to the server.
Definition serverutils.c:886
int gvm_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
Definition serverutils.c:803
int gvm_connection_sendf_xml_quiet(gvm_connection_t *connection, const char *format,...)
Format and send an XML string to the server.
Definition serverutils.c:965
GnuTLS based functions for server communication - header file.
Struct holding options for authentication.
Definition gmp.h:27
const char * password
Username.
Definition gmp.h:30
int timeout
Timeout for authentication.
Definition gmp.h:28
int jwt_requested
Flag for JWT. 0 = false, 1 = true.
Definition gmp.h:34
char ** pw_warning
[out] Password warning, NULL if password is okay.
Definition gmp.h:33
char ** timezone
[out] Timezone if any, else NULL.
Definition gmp.h:32
char ** jwt
[out] JWT token value, NULL if not requested.
Definition gmp.h:35
const char * username
Password.
Definition gmp.h:29
char ** role
[out] Role.
Definition gmp.h:31
Struct holding options for gmp create_lsc_credential command.
Definition gmp.h:242
const char * privacy_password
SNMP privacy password.
Definition gmp.h:249
const char * privacy_algorithm
SNMP privacy algorithm.
Definition gmp.h:250
const char * login
Login.
Definition gmp.h:245
const char * community
SNMP community.
Definition gmp.h:244
const char * passphrase
Passphrase.
Definition gmp.h:246
const char * comment
Comment on LSC credential.
Definition gmp.h:251
const char * private_key
Private key.
Definition gmp.h:247
const char * auth_algorithm
SNMP authentication algorithm.
Definition gmp.h:248
const char * name
Name of LSC credential.
Definition gmp.h:243
Struct holding options for gmp create_target command.
Definition gmp.h:196
const char * exclude_hosts
Hosts to exclude.
Definition gmp.h:206
const char * comment
Comment on target.
Definition gmp.h:204
const char * smb_credential_id
ID of SMB credential.
Definition gmp.h:199
int reverse_lookup_only
Scanner pref reverse_lookup_only.
Definition gmp.h:209
int reverse_lookup_unify
Scanner pref reverse_lookup_unify.
Definition gmp.h:210
const char * esxi_credential_id
ID of ESXi credential.
Definition gmp.h:200
const char * snmp_credential_id
ID of SNMP credential.
Definition gmp.h:201
const char * hosts
Name of target.
Definition gmp.h:205
const char * port_range
Port range.
Definition gmp.h:202
int ssh_credential_port
Port for SSH access.
Definition gmp.h:197
const char * alive_tests
Alive tests.
Definition gmp.h:207
const char * ssh_credential_id
ID of SSH credential.
Definition gmp.h:198
const char * name
Name of target.
Definition gmp.h:203
Struct holding options for gmp create_task command.
Definition gmp.h:163
int schedule_periods
Number of periods the schedule must run for.
Definition gmp.h:175
const char * max_checks
Max checks preference.
Definition gmp.h:179
const char * slave_id
ID of task schedule.
Definition gmp.h:168
array_t * alert_ids
Array of alert IDs.
Definition gmp.h:164
const char * config_id
ID of config.
Definition gmp.h:165
const char * in_assets
In assets preference.
Definition gmp.h:177
const char * schedule_id
ID of task schedule.
Definition gmp.h:167
const char * source_iface
Source iface preference.
Definition gmp.h:180
array_t * observer_groups
IDs of observer groups.
Definition gmp.h:174
const char * observers
Comma-separated string of observer users.
Definition gmp.h:173
const char * name
Name of task.
Definition gmp.h:170
const char * target_id
ID of target.
Definition gmp.h:169
const char * scanner_id
ID of task scanner.
Definition gmp.h:166
int alterable
Whether the task is alterable.
Definition gmp.h:182
const char * max_hosts
Max hosts preference.
Definition gmp.h:178
const char * comment
Comment on task.
Definition gmp.h:171
Struct holding options for various gmp delete_[...] commands.
Definition gmp.h:265
int ultimate
Definition gmp.h:266
Struct holding options for gmp get_report command.
Definition gmp.h:48
int timeout
Timeout for GMP response.
Definition gmp.h:56
const char * format_id
ID of required report format.
Definition gmp.h:51
int host_max_results
Maximum number of results to return.
Definition gmp.h:58
const char * report_id
ID of single report to get.
Definition gmp.h:53
int host_first_result
Skip over results before this result number.
Definition gmp.h:57
Struct holding options for gmp get_system_reports command.
Definition gmp.h:223
const char * duration
Duration.
Definition gmp.h:225
const char * slave_id
ID of the slave to get report from.
Definition gmp.h:228
const char * end_time
Time of last data point.
Definition gmp.h:227
const char * name
Name of report.
Definition gmp.h:224
const char * start_time
Time of first data point.
Definition gmp.h:226
Struct holding options for gmp get_tasks command.
Definition gmp.h:145
const char * task_id
ID of single task to get.
Definition gmp.h:147
const char * actions
Actions argument.
Definition gmp.h:146
Struct holding options for gmp get_tasks command.
Definition gmp.h:126
int timeout
Timeout for GMP response.
Definition gmp.h:128
const char * filter
Filter argument.
Definition gmp.h:127
Struct holding options for gmp start_task command.
Definition gmp.h:318
const char * task_id
ID of task.
Definition gmp.h:319
Connection.
Definition serverutils.h:30
int read_entity_c(gvm_connection_t *connection, entity_t *entity)
Read an XML entity tree from the manager.
Definition xmlutils.c:1497
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition xmlutils.c:216
char * entity_text(entity_t entity)
Get the text an entity.
Definition xmlutils.c:145
int read_entity(gnutls_session_t *session, entity_t *entity)
Read an XML entity tree from the manager.
Definition xmlutils.c:1469
int try_read_entity(gnutls_session_t *session, int timeout, entity_t *entity)
Try read an XML entity tree from the manager.
Definition xmlutils.c:1436
void free_entity(entity_t entity)
Free an entity, recursively.
Definition xmlutils.c:115
entity_t entity_child(entity_t entity, const char *name)
Get a child of an entity.
Definition xmlutils.c:193
int try_read_entity_c(gvm_connection_t *connection, int timeout, entity_t *entity)
Try read an XML entity tree from the manager.
Definition xmlutils.c:1452
void xml_string_append(GString *xml, const char *format,...)
Append formatted escaped XML to a string.
Definition xmlutils.c:1849
struct entity_s * entity_t
Definition xmlutils.h:58