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, *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 scanner = g_strdup_printf (
"<scanner id=\"%s\"/>", opts.
scanner_id);
565 schedule = g_strdup_printf (
"<schedule id=\"%s\"/>"
566 "<schedule_periods>%d</schedule_periods>",
572 slave = g_strdup_printf (
"<slave id=\"%s\"/>", opts.
slave_id);
578 gchar *in_assets, *checks, *hosts, *source_iface;
580 in_assets = checks = hosts = source_iface = NULL;
583 in_assets = g_markup_printf_escaped (
"<preference>"
594 hosts = g_markup_printf_escaped (
"<preference>"
605 checks = g_markup_printf_escaped (
"<preference>"
616 source_iface = g_markup_printf_escaped (
"<preference>"
627 g_strdup_printf (
"<preferences>%s%s%s%s</preferences>",
628 in_assets ? in_assets :
"", checks ? checks :
"",
629 hosts ? hosts :
"", source_iface ? source_iface :
"");
633 g_free (source_iface);
639 alerts = g_string_new (
"");
640 for (i = 0; i < opts.
alert_ids->len; i++)
642 char *alert = (
char *) g_ptr_array_index (opts.
alert_ids, i);
643 g_string_append_printf (alerts,
"<alert id=\"%s\"/>", alert);
647 alerts = g_string_new (
"");
651 observers = g_string_new (
"<observers>");
654 g_string_append (observers, opts.
observers);
663 g_string_append_printf (observers,
"<group id=\"%s\"/>", group);
666 g_string_append (observers,
"</observers>");
669 observers = g_string_new (
"");
673 session,
"%s%s%s%s%s%s%s</create_task>", start, prefs ? prefs :
"",
674 scanner ? scanner :
"", schedule ? schedule :
"", slave ? slave :
"",
675 alerts ? alerts->str :
"", observers ? observers->str :
"");
681 g_string_free (alerts, TRUE);
682 g_string_free (observers, TRUE);
710 const char *config,
const char *target,
const char *comment,
717 "<config id=\"%s\"/>"
718 "<target id=\"%s\"/>"
720 "<comment>%s</comment>"
722 config, target, name, comment);
749 if (
gvm_server_sendf (session,
"<start_task task_id=\"%s\"/>", task_id) == -1)
763 *report_id = g_strdup (
entity_text (report_id_xml));
814 if (strlen (status) == 0)
826 *report_id = g_strdup (
entity_text (report_id_xml));
900 if (strlen (status) == 0)
916 if (strlen (
id) == 0)
921 *uuid = g_strdup (
id);
1001 *report_id = g_strdup (
entity_text (report_id_xml));
1048 if (strlen (status) == 0)
1053 char first = status[0];
1060 *report_id = g_strdup (
entity_text (report_id_xml));
1091 "<delete_task task_id=\"%s\" ultimate=\"%d\"/>",
id,
1117 int include_rcfile,
entity_t *status)
1119 (void) include_rcfile;
1131 " details=\"%i\"/>",
1154 if ((response == NULL) || (opts.
task_id == NULL))
1192 const char *status_code;
1195 if (response == NULL)
1198 cmd = g_markup_printf_escaped (
"<get_tasks"
1224 if (status_code == NULL)
1229 if (strlen (status_code) == 0)
1234 if (status_code[0] ==
'2')
1236 ret = (int) strtol (status_code, NULL, 10);
1238 if (errno == ERANGE)
1256 const char *name,
const void *content, gsize content_len)
1275 gchar *base64_content =
1276 g_base64_encode ((guchar *) content, content_len);
1278 g_free (base64_content);
1341 int include_rcfile,
entity_t *target)
1343 (void) include_rcfile;
1382 const char *status_code;
1384 if (response == NULL)
1393 " host_first_result=\"%i\""
1394 " host_max_results=\"%i\""
1447 if (status_code == NULL)
1452 if (strlen (status_code) == 0)
1457 if (status_code[0] ==
'2')
1459 ret = (int) strtol (status_code, NULL, 10);
1461 if (errno == ERANGE)
1483 session,
"<delete_port_list port_list_id=\"%s\" ultimate=\"%d\"/>",
id,
1537 gchar *comment, *ssh, *smb, *esxi, *snmp, *port_range, *start;
1538 gchar *exclude_hosts, *alive_tests;
1543 if (opts.
hosts == NULL)
1547 g_markup_printf_escaped (
"<create_target>"
1549 "<hosts>%s</hosts>",
1553 exclude_hosts = g_markup_printf_escaped (
"<exclude_hosts>"
1558 exclude_hosts = NULL;
1561 alive_tests = g_markup_printf_escaped (
"<alive_tests>"
1569 comment = g_markup_printf_escaped (
"<comment>"
1579 ssh = g_markup_printf_escaped (
"<ssh_lsc_credential id=\"%s\">"
1581 "</ssh_lsc_credential>",
1585 ssh = g_markup_printf_escaped (
"<ssh_lsc_credential id=\"%s\"/>",
1592 smb = g_markup_printf_escaped (
"<smb_lsc_credential id=\"%s\"/>",
1598 esxi = g_markup_printf_escaped (
"<esxi_lsc_credential id=\"%s\"/>",
1604 snmp = g_markup_printf_escaped (
"<snmp_credential id=\"%s\"/>",
1611 g_markup_printf_escaped (
"<port_range>%s</port_range>", opts.
port_range);
1617 "%s%s%s%s%s%s%s%s%s"
1618 "<reverse_lookup_only>%d</reverse_lookup_only>"
1619 "<reverse_lookup_unify>%d</reverse_lookup_unify>"
1621 start, exclude_hosts ? exclude_hosts :
"",
1622 alive_tests ? alive_tests :
"", ssh ? ssh :
"",
1623 smb ? smb :
"", esxi ? esxi :
"", snmp ? snmp :
"",
1624 port_range ? port_range :
"", comment ? comment :
"",
1627 g_free (exclude_hosts);
1628 g_free (alive_tests);
1632 g_free (port_range);
1662 "<delete_target target_id=\"%s\" ultimate=\"%d\"/>",
id,
1691 "<delete_config config_id=\"%s\" ultimate=\"%d\"/>",
id,
1717 const char *login,
const char *password,
1718 const char *comment, gchar **uuid)
1726 "<create_credential>"
1729 "<password>%s</password>"
1730 "<comment>%s</comment>"
1731 "</create_credential>",
1732 name, login, password, comment);
1735 "<create_credential>"
1738 "<password>%s</password>"
1739 "</create_credential>",
1740 name, login, password);
1746 "<create_credential>"
1749 "<comment>%s</comment>"
1750 "</create_credential>",
1751 name, login, comment);
1754 "<create_credential>"
1757 "</create_credential>",
1785 const char *login,
const char *passphrase,
1786 const char *private_key,
const char *comment,
1793 "<create_credential>"
1797 "<phrase>%s</phrase>"
1798 "<private>%s</private>"
1800 "<comment>%s</comment>"
1801 "</create_credential>",
1802 name, login, passphrase ? passphrase :
"",
1803 private_key, comment);
1806 "<create_credential>"
1810 "<phrase>%s</phrase>"
1811 "<private>%s</private>"
1813 "</create_credential>",
1814 name, login, passphrase ? passphrase :
"",
1841 gchar *comment, *pass, *start, *snmp_elems;
1846 if (opts.
login == NULL)
1850 g_markup_printf_escaped (
"<create_credential>"
1852 "<login>%s</login>",
1856 comment = g_markup_printf_escaped (
"<comment>"
1864 pass = g_markup_printf_escaped (
"<key>"
1865 "<phrase>%s</phrase>"
1866 "<private>%s</private>"
1873 pass = g_markup_printf_escaped (
"<password>"
1884 g_markup_printf_escaped (
"<community>"
1891 "<password>%s</password>"
1892 "<algorithm>%s</algorithm>"
1902 comment ? comment :
"", pass ? pass :
"",
1903 snmp_elems ? snmp_elems :
"");
1936 "<delete_credential credential_id=\"%s\""
1937 " ultimate=\"%d\"/>",
1967 "<get_system_reports name=\"%s\" brief=\"%i\"/>",
1998 request = g_string_new (
"<get_system_reports");
2015 g_string_append (request,
"/>");
2021 g_string_free (request, 1);
2024 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:1961
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:744
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:1655
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:1188
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:1151
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:1837
int gmp_create_target_ext(gnutls_session_t *session, gmp_create_target_opts_t opts, gchar **id)
Create a target.
Definition gmp.c:1534
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:537
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:1716
int gmp_delete_report(gnutls_session_t *session, const char *id)
Remove a report.
Definition gmp.c:1504
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:962
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:981
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:709
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:1255
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:789
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:1312
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:1476
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:1084
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:1026
int gmp_delete_config_ext(gnutls_session_t *session, const char *id, gmp_delete_opts_t opts)
Delete a config.
Definition gmp.c:1684
int gmp_read_create_response(gnutls_session_t *session, gchar **uuid)
Read response status and resource UUID.
Definition gmp.c:880
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:1378
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:1929
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:849
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:1116
#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:1992
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:1340
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:1784
int gmp_stop_task(gnutls_session_t *session, const char *id)
Stop a task and read the manager response.
Definition gmp.c:938
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:824
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:939
int gvm_server_sendf_xml(gnutls_session_t *session, const char *format,...)
Format and send an XML string to the server.
Definition serverutils.c:887
int gvm_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
Definition serverutils.c:804
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:966
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
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
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:240
const char * privacy_password
SNMP privacy password.
Definition gmp.h:247
const char * privacy_algorithm
SNMP privacy algorithm.
Definition gmp.h:248
const char * login
Login.
Definition gmp.h:243
const char * community
SNMP community.
Definition gmp.h:242
const char * passphrase
Passphrase.
Definition gmp.h:244
const char * comment
Comment on LSC credential.
Definition gmp.h:249
const char * private_key
Private key.
Definition gmp.h:245
const char * auth_algorithm
SNMP authentication algorithm.
Definition gmp.h:246
const char * name
Name of LSC credential.
Definition gmp.h:241
Struct holding options for gmp create_target command.
Definition gmp.h:194
const char * exclude_hosts
Hosts to exclude.
Definition gmp.h:204
const char * comment
Comment on target.
Definition gmp.h:202
const char * smb_credential_id
ID of SMB credential.
Definition gmp.h:197
int reverse_lookup_only
Scanner pref reverse_lookup_only.
Definition gmp.h:207
int reverse_lookup_unify
Scanner pref reverse_lookup_unify.
Definition gmp.h:208
const char * esxi_credential_id
ID of ESXi credential.
Definition gmp.h:198
const char * snmp_credential_id
ID of SNMP credential.
Definition gmp.h:199
const char * hosts
Name of target.
Definition gmp.h:203
const char * port_range
Port range.
Definition gmp.h:200
int ssh_credential_port
Port for SSH access.
Definition gmp.h:195
const char * alive_tests
Alive tests.
Definition gmp.h:205
const char * ssh_credential_id
ID of SSH credential.
Definition gmp.h:196
const char * name
Name of target.
Definition gmp.h:201
Struct holding options for gmp create_task command.
Definition gmp.h:161
int schedule_periods
Number of periods the schedule must run for.
Definition gmp.h:173
const char * max_checks
Max checks preference.
Definition gmp.h:177
const char * slave_id
ID of task schedule.
Definition gmp.h:166
array_t * alert_ids
Array of alert IDs.
Definition gmp.h:162
const char * config_id
ID of config.
Definition gmp.h:163
const char * in_assets
In assets preference.
Definition gmp.h:175
const char * schedule_id
ID of task schedule.
Definition gmp.h:165
const char * source_iface
Source iface preference.
Definition gmp.h:178
array_t * observer_groups
IDs of observer groups.
Definition gmp.h:172
const char * observers
Comma-separated string of observer users.
Definition gmp.h:171
const char * name
Name of task.
Definition gmp.h:168
const char * target_id
ID of target.
Definition gmp.h:167
const char * scanner_id
ID of task scanner.
Definition gmp.h:164
int alterable
Whether the task is alterable.
Definition gmp.h:180
const char * max_hosts
Max hosts preference.
Definition gmp.h:176
const char * comment
Comment on task.
Definition gmp.h:169
Struct holding options for various gmp delete_[...] commands.
Definition gmp.h:263
int ultimate
Definition gmp.h:264
Struct holding options for gmp get_report command.
Definition gmp.h:46
int timeout
Timeout for GMP response.
Definition gmp.h:54
const char * format_id
ID of required report format.
Definition gmp.h:49
int host_max_results
Maximum number of results to return.
Definition gmp.h:56
const char * report_id
ID of single report to get.
Definition gmp.h:51
int host_first_result
Skip over results before this result number.
Definition gmp.h:55
Struct holding options for gmp get_system_reports command.
Definition gmp.h:221
const char * duration
Duration.
Definition gmp.h:223
const char * slave_id
ID of the slave to get report from.
Definition gmp.h:226
const char * end_time
Time of last data point.
Definition gmp.h:225
const char * name
Name of report.
Definition gmp.h:222
const char * start_time
Time of first data point.
Definition gmp.h:224
Struct holding options for gmp get_tasks command.
Definition gmp.h:143
const char * task_id
ID of single task to get.
Definition gmp.h:145
const char * actions
Actions argument.
Definition gmp.h:144
Struct holding options for gmp get_tasks command.
Definition gmp.h:124
int timeout
Timeout for GMP response.
Definition gmp.h:126
const char * filter
Filter argument.
Definition gmp.h:125
Struct holding options for gmp start_task command.
Definition gmp.h:316
const char * task_id
ID of task.
Definition gmp.h:317
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