51 #include "../misc/openvas_server.h" 57 #define G_LOG_DOMAIN "lib omp" 59 #define OMP_FMT_BOOL_ATTRIB(var, attrib) \ 60 (var.attrib == 0 ? " " #attrib "=\"0\"" : " " #attrib "=\"1\"") 62 #define OMP_FMT_STRING_ATTRIB(var, attrib) \ 63 (var.attrib ? " " #attrib "= \"" : ""), \ 64 (var.attrib ? var.attrib : ""), \ 65 (var.attrib ? "\"" : "") 82 #define DO_CHILDREN(entity, child, temp, body) \ 85 GSList* temp = entity->entities; \ 88 entity_t child = temp->data; \ 92 temp = g_slist_next (temp); \ 99 (defmacro
do-children ((entity child) &body body)
100 "Do something for each child of an entity." 101 (let ((temp (gensym)))
102 `(
while ((,temp (entity-entities ,entity) (rest ,temp)))
175 if (strlen (status) == 0)
182 if (first ==
'2')
return 0;
235 if (strlen (status) == 0)
240 if (status[0] ==
'2')
246 if (omp_version == NULL)
272 const char* username,
273 const char* password)
282 "<authenticate><credentials>" 283 "<username>%s</username>" 284 "<password>%s</password>" 285 "</credentials></authenticate>",
286 username ? username :
"",
287 password ? password :
"");
304 if (strlen (status) == 0)
311 if (first ==
'2')
return 0;
340 "<authenticate><credentials>" 341 "<username>%s</username>" 342 "<password>%s</password>" 343 "</credentials></authenticate>",
370 if (strlen (status) == 0)
378 entity_t timezone_entity, role_entity, severity_entity, pw_warn_entity;
389 pw_warn_entity =
entity_child (entity,
"password_warning");
428 "<username>%s</username>" 429 "<password>%s</password>" 458 if (strlen (status) == 0)
466 entity_t timezone_entity, role_entity, severity_entity;
469 if (timezone_entity && opts.
timezone)
472 if (role_entity && opts.
role)
475 if (severity_entity && opts.
severity)
480 pw_warn_entity =
entity_child (entity,
"password_warning");
514 gchar *prefs, *start, *hosts_ordering, *scanner, *schedule, *slave;
515 GString *alerts, *observers;
521 start = g_markup_printf_escaped (
"<create_task>" 522 "<config id=\"%s\"/>" 523 "<target id=\"%s\"/>" 525 "<comment>%s</comment>" 526 "<alterable>%d</alterable>",
534 hosts_ordering = g_strdup_printf (
"<hosts_ordering>%s</hosts_ordering>",
537 hosts_ordering = NULL;
540 scanner = g_strdup_printf (
"<scanner id=\"%s\"/>",
546 schedule = g_strdup_printf (
"<schedule id=\"%s\"/>" 547 "<schedule_periods>%d</schedule_periods>",
554 slave = g_strdup_printf (
"<slave id=\"%s\"/>",
561 gchar *in_assets, *checks, *hosts, *source_iface;
563 in_assets = checks = hosts = source_iface = NULL;
566 in_assets = g_markup_printf_escaped (
"<preference>" 577 checks = g_markup_printf_escaped (
"<preference>" 588 hosts = g_markup_printf_escaped (
"<preference>" 599 source_iface = g_markup_printf_escaped (
"<preference>" 609 prefs = g_strdup_printf (
"<preferences>%s%s%s%s</preferences>",
610 in_assets ? in_assets :
"",
611 checks ? checks :
"",
613 source_iface ? source_iface :
"");
617 g_free (source_iface);
623 alerts = g_string_new (
"");
624 for (i = 0; i < opts.
alert_ids->len; i++)
626 char *alert = (
char*)g_ptr_array_index (opts.
alert_ids, i);
627 g_string_append_printf (alerts,
628 "<alert id=\"%s\"/>",
633 alerts = g_string_new (
"");
638 observers = g_string_new (
"<observers>");
641 g_string_append (observers, opts.
observers);
649 g_string_append_printf (observers,
650 "<group id=\"%s\"/>",
654 g_string_append (observers,
"</observers>");
657 observers = g_string_new (
"");
663 hosts_ordering ? hosts_ordering :
"",
664 scanner ? scanner :
"",
665 schedule ? schedule :
"",
667 alerts ? alerts->str :
"",
668 observers ? observers->str :
"");
671 g_free (hosts_ordering);
675 g_string_free (alerts, TRUE);
676 g_string_free (observers, TRUE);
714 "<config id=\"%s\"/>" 715 "<target id=\"%s\"/>" 717 "<comment>%s</comment>" 748 "<start_task task_id=\"%s\"/>",
766 if (strlen (status) == 0)
771 char first = status[0];
778 *report_id = g_strdup (
entity_text (report_id_xml));
810 "<start_task task_id=\"%s\"/>",
828 if (strlen (status) == 0)
840 *report_id = g_strdup (
entity_text (report_id_xml));
882 if (strlen (status) == 0)
887 if (status[0] ==
'2')
892 ret = (int) strtol (status, NULL, 10);
894 if (errno == ERANGE)
return -1;
925 if (strlen (status) == 0)
930 if (status[0] ==
'2')
935 ret = (int) strtol (status, NULL, 10);
937 if (errno == ERANGE)
return -1;
954 const char *status, *id;
970 if (strlen (status) == 0)
984 if (strlen (
id) == 0)
989 *uuid = g_strdup (
id);
1009 "<stop_task task_id=\"%s\"/>",
1029 "<stop_task task_id=\"%s\"/>",
1051 "<resume_task task_id=\"%s\"/>",
1069 if (strlen (status) == 0)
1074 char first = status[0];
1081 *report_id = g_strdup (
entity_text (report_id_xml));
1109 "<resume_task task_id=\"%s\"/>",
1127 if (strlen (status) == 0)
1132 char first = status[0];
1139 *report_id = g_strdup (
entity_text (report_id_xml));
1167 "<delete_task task_id=\"%s\" ultimate=\"%d\"/>",
1189 int include_rcfile,
entity_t* status)
1191 const char* status_code;
1194 (void) include_rcfile;
1198 "<get_tasks details=\"%i\"/>",
1208 " details=\"%i\"/>",
1223 if (status_code == NULL)
1228 if (strlen (status_code) == 0)
1233 if (status_code[0] ==
'2')
return 0;
1234 ret = (int) strtol (status_code, NULL, 10);
1236 if (errno == ERANGE)
return -1;
1255 const char *status_code;
1257 if ((response == NULL) || (opts.
task_id == NULL))
1286 if (status_code == NULL)
1291 if (strlen (status_code) == 0)
1296 if (status_code[0] ==
'2')
return 0;
1297 ret = (int) strtol (status_code, NULL, 10);
1299 if (errno == ERANGE)
return -1;
1318 const char *status_code;
1321 if (response == NULL)
1324 cmd = g_markup_printf_escaped (
"<get_tasks" 1352 if (status_code == NULL)
1357 if (strlen (status_code) == 0)
1362 if (status_code[0] ==
'2')
return 0;
1363 ret = (int) strtol (status_code, NULL, 10);
1365 if (errno == ERANGE)
return -1;
1382 const char*
name,
const void* content,
1399 gchar *base64_content = g_base64_encode ((guchar*) content,
1404 g_free (base64_content);
1414 "<file name=\"%s\" action=\"remove\" />",
1456 int include_rcfile,
entity_t* target)
1458 const char* status_code;
1461 (void) include_rcfile;
1465 "<get_targets tasks=\"%i\"/>",
1490 if (status_code == NULL)
1495 if (strlen (status_code) == 0)
1500 if (status_code[0] ==
'2')
return 0;
1501 ret = (int) strtol (status_code, NULL, 10);
1503 if (errno == ERANGE)
return -1;
1525 const char *status_code;
1527 if (response == NULL)
1534 " host_first_result=\"%i\"" 1535 " host_max_results=\"%i\"" 1592 if (status_code == NULL)
1597 if (strlen (status_code) == 0)
1602 if (status_code[0] ==
'2')
return 0;
1603 ret = (int) strtol (status_code, NULL, 10);
1605 if (errno == ERANGE)
return -1;
1624 "<delete_port_list port_list_id=\"%s\" ultimate=\"%d\"/>",
1668 gchar *comment, *ssh, *smb, *esxi, *snmp, *port_range, *start;
1669 gchar *exclude_hosts, *alive_tests;
1674 if (opts.
hosts == NULL)
1677 start = g_markup_printf_escaped (
"<create_target>" 1679 "<hosts>%s</hosts>",
1684 exclude_hosts = g_markup_printf_escaped (
"<exclude_hosts>" 1689 exclude_hosts = NULL;
1692 alive_tests = g_markup_printf_escaped (
"<alive_tests>" 1700 comment = g_markup_printf_escaped (
"<comment>" 1710 ssh = g_markup_printf_escaped (
"<ssh_lsc_credential id=\"%s\">" 1712 "</ssh_lsc_credential>",
1716 ssh = g_markup_printf_escaped (
"<ssh_lsc_credential id=\"%s\"/>",
1723 smb = g_markup_printf_escaped (
"<smb_lsc_credential id=\"%s\"/>",
1729 esxi = g_markup_printf_escaped (
"<esxi_lsc_credential id=\"%s\"/>",
1735 snmp = g_markup_printf_escaped (
"<snmp_credential id=\"%s\"/>",
1741 port_range = g_markup_printf_escaped (
"<port_range>%s</port_range>",
1748 "%s%s%s%s%s%s%s%s%s" 1749 "<reverse_lookup_only>%d</reverse_lookup_only>" 1750 "<reverse_lookup_unify>%d</reverse_lookup_unify>" 1753 exclude_hosts ? exclude_hosts :
"",
1754 alive_tests ? alive_tests :
"",
1759 port_range ? port_range :
"",
1760 comment ? comment :
"",
1764 g_free (exclude_hosts);
1765 g_free (alive_tests);
1769 g_free (port_range);
1797 "<delete_target target_id=\"%s\" ultimate=\"%d\"/>",
1820 "<delete_config config_id=\"%s\" ultimate=\"%d\"/>",
1844 const char* password,
1845 const char* comment,
1854 "<create_credential>" 1857 "<password>%s</password>" 1858 "<comment>%s</comment>" 1859 "</create_credential>",
1866 "<create_credential>" 1869 "<password>%s</password>" 1870 "</create_credential>",
1879 "<create_credential>" 1882 "<comment>%s</comment>" 1883 "</create_credential>",
1889 "<create_credential>" 1892 "</create_credential>",
1923 const char *passphrase,
1924 const char *private_key,
1925 const char *comment,
1932 "<create_credential>" 1936 "<phrase>%s</phrase>" 1937 "<private>%s</private>" 1939 "<comment>%s</comment>" 1940 "</create_credential>",
1943 passphrase ? passphrase :
"",
1948 "<create_credential>" 1952 "<phrase>%s</phrase>" 1953 "<private>%s</private>" 1955 "</create_credential>",
1958 passphrase ? passphrase :
"",
1985 gchar *comment, *pass, *start, *snmp_elems;
1990 if (opts.
login == NULL)
1993 start = g_markup_printf_escaped (
"<create_credential>" 1995 "<login>%s</login>",
2000 comment = g_markup_printf_escaped (
"<comment>" 2008 pass = g_markup_printf_escaped (
"<key>" 2009 "<phrase>%s</phrase>" 2010 "<private>%s</private>" 2017 pass = g_markup_printf_escaped (
"<password>" 2027 snmp_elems = g_markup_printf_escaped (
"<community>" 2034 "<password>%s</password>" 2035 "<algorithm>%s</algorithm>" 2047 "%s%s%s%s</create_credential>",
2049 comment ? comment :
"",
2051 snmp_elems ? snmp_elems :
"");
2082 "<delete_credential credential_id=\"%s\"" 2083 " ultimate=\"%d\"/>",
2107 const char *status_code;
2112 "<get_system_reports name=\"%s\" brief=\"%i\"/>",
2119 "<get_system_reports brief=\"%i\"/>",
2132 if (status_code == NULL)
2137 if (strlen (status_code) == 0)
2142 if (status_code[0] ==
'2')
return 0;
2143 ret = (int) strtol (status_code, NULL, 10);
2145 if (errno == ERANGE)
return -1;
2164 const char* status_code;
2168 request = g_string_new (
"<get_system_reports");
2185 g_string_append (request,
"/>");
2191 g_string_free (request, 1);
2194 g_string_free (request, 1);
2204 if (status_code == NULL)
2209 if (strlen (status_code) == 0)
2214 if (status_code[0] ==
'2')
return 0;
2215 ret = (int) strtol (status_code, NULL, 10);
2217 if (errno == ERANGE)
return -1;
int omp_delete_report(gnutls_session_t *session, const char *id)
Remove a report.
int omp_get_tasks(gnutls_session_t *session, const char *id, int details, int include_rcfile, entity_t *status)
Get the status of a task.
int omp_stop_task_c(openvas_connection_t *connection, const char *id)
Stop a task and read the manager response.
int try_read_entity_c(openvas_connection_t *connection, int timeout, entity_t *entity)
Try read an XML entity tree from the manager.
int timeout
Timeout for OMP response.
Struct holding options for omp get_report command.
int reverse_lookup_only
Scanner pref reverse_lookup_only.
int omp_authenticate_info_ext_c(openvas_connection_t *connection, omp_authenticate_info_opts_t opts)
Authenticate with the manager.
#define OMP_FMT_STRING_ATTRIB(var, attrib)
int openvas_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
const char * duration
Duration.
const char * task_id
ID of single task to get.
const char * name
Name of report.
int omp_ping_c(openvas_connection_t *connection, int timeout, gchar **version)
"Ping" the manager.
const char * target_id
ID of target.
int schedule_periods
Number of periods the schedule must run for.
int openvas_server_sendf_xml(gnutls_session_t *session, const char *format,...)
Format and send an XML string to the server.
int read_entity(gnutls_session_t *session, entity_t *entity)
Read an XML entity tree from the manager.
int omp_stop_task(gnutls_session_t *session, const char *id)
Stop a task and read the manager response.
int omp_resume_task_report(gnutls_session_t *session, const char *task_id, char **report_id)
Resume a task and read the manager response.
Struct holding options for omp get_tasks command.
const char * hosts_ordering
Order for scanning target hosts.
int omp_start_task_report_c(openvas_connection_t *connection, const char *task_id, char **report_id)
Start a task and read the manager response.
int check_response(gnutls_session_t *session)
Read response and convert status of response to a return value.
const char * community
SNMP community.
const char * comment
Comment on LSC credential.
int alterable
Whether the task is alterable.
const char * slave_id
ID of the slave to get report from.
const char * ssh_credential_id
ID of SSH credential.
char * entity_text(entity_t entity)
Get the text an entity.
Struct holding options for omp get_system_reports command.
const char * comment
Comment on task.
int omp_authenticate(gnutls_session_t *session, const char *username, const char *password)
Authenticate with the manager.
int host_first_result
Skip over results before this result number.
Struct holding options for omp get_tasks command.
const char * auth_algorithm
SNMP authentication algorithm.
array_t * alert_ids
Array of alert IDs.
void xml_string_append(GString *xml, const char *format,...)
Append formatted escaped XML to a string.
array_t * observer_groups
IDs of observer groups.
const char * passphrase
Passphrase.
const char * alive_tests
Alive tests.
int openvas_server_sendf_xml_quiet(gnutls_session_t *session, const char *format,...)
Format and send an XML string to the server.
const char * slave_id
ID of task schedule.
int omp_get_system_reports(gnutls_session_t *session, const char *name, int brief, entity_t *reports)
Get system reports.
int omp_delete_target_ext(gnutls_session_t *session, const char *id, omp_delete_opts_t opts)
Delete a target.
const char * esxi_credential_id
ID of ESXi credential.
const char * max_hosts
Max hosts preference.
const char * privacy_password
SNMP privacy password.
int omp_get_task_ext(gnutls_session_t *session, omp_get_task_opts_t opts, entity_t *response)
Get a task (generic version).
int omp_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 omp_resume_task_report_c(openvas_connection_t *connection, const char *task_id, char **report_id)
Resume a task and read the manager response.
const char * source_iface
Source iface preference.
int omp_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.
const char * hosts
Name of target.
int try_read_entity(gnutls_session_t *session, int timeout, entity_t *entity)
Try read an XML entity tree from the manager.
int omp_delete_lsc_credential_ext(gnutls_session_t *session, const char *id, omp_delete_opts_t opts)
Delete a LSC credential.
int timeout
Timeout for authentication.
Struct holding options for authentication.
int omp_start_task_report(gnutls_session_t *session, const char *task_id, char **report_id)
Start a task and read the manager response.
const char * start_time
Time of first data point.
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
int omp_get_report_ext(gnutls_session_t *session, omp_get_report_opts_t opts, entity_t *response)
Get a report (generic version).
int omp_delete_port_list_ext(gnutls_session_t *session, const char *id, omp_delete_opts_t opts)
Delete a port list.
Struct holding options for omp create_lsc_credential command.
char ** severity
[out] Severity class setting.
int omp_delete_task(gnutls_session_t *session, const char *id)
Delete a task and read the manager response.
const char * port_range
Port range.
int omp_delete_task_ext(gnutls_session_t *session, const char *id, omp_delete_opts_t opts)
Delete a task and read the manager response.
const char * end_time
Time of last data point.
const char * actions
Actions argument.
const char * exclude_hosts
Hosts to exclude.
int host_max_results
Maximum number of results to return.
int timeout
Timeout for OMP response.
const char * comment
Comment on target.
const char * username
Password.
int check_response_c(openvas_connection_t *connection)
Read response and convert status of response to a return value.
int omp_get_targets(gnutls_session_t *session, const char *id, int tasks, int include_rcfile, entity_t *target)
Get a target.
const char * password
Username.
int omp_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.
Struct holding options for omp create_task command.
int omp_authenticate_info_ext(gnutls_session_t *session, omp_authenticate_info_opts_t opts)
Authenticate with the manager.
const char * privacy_algorithm
SNMP privacy algorithm.
Struct holding options for omp create_target command.
#define OMP_FMT_BOOL_ATTRIB(var, attrib)
const char * smb_credential_id
ID of SMB credential.
const char * scanner_id
ID of task scanner.
int ssh_credential_port
Port for SSH access.
const char * in_assets
In assets preference.
int omp_get_system_reports_ext(gnutls_session_t *session, omp_get_system_reports_opts_t opts, entity_t *reports)
Get system reports.
const char * schedule_id
ID of task schedule.
const char * name
Name of target.
entity_t entity_child(entity_t entity, const char *name)
Get a child of an entity.
Struct holding options for various omp delete_[...] commands.
char ** timezone
[out] Timezone if any, else NULL.
int omp_read_create_response(gnutls_session_t *session, gchar **uuid)
Read response status and resource UUID.
int read_entity_c(openvas_connection_t *connection, entity_t *entity)
Read an XML entity tree from the manager.
char ** pw_warning
[out] Password warning, NULL if password is okay.
int omp_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 openvas_connection_sendf(openvas_connection_t *connection, const char *format,...)
Format and send a string to the server.
const char * max_checks
Max checks preference.
int omp_delete_config_ext(gnutls_session_t *session, const char *id, omp_delete_opts_t opts)
Delete a config.
void free_entity(entity_t entity)
Free an entity, recursively.
const char * filter
Filter argument.
int omp_ping(gnutls_session_t *session, int timeout)
"Ping" the manager.
const char * name
Name of LSC credential.
const char * name
Name of task.
const char * omp_task_status(entity_t response)
Get the task status from an OMP GET_TASKS response.
const char * config_id
ID of config.
int openvas_connection_sendf_xml_quiet(openvas_connection_t *connection, const char *format,...)
Format and send an XML string to the server.
int omp_create_task_ext(gnutls_session_t *session, omp_create_task_opts_t opts, gchar **id)
Create a task.
int omp_get_tasks_ext(gnutls_session_t *session, omp_get_tasks_opts_t opts, entity_t *response)
Get all tasks (generic version).
int omp_create_lsc_credential_ext(gnutls_session_t *session, omp_create_lsc_credential_opts_t opts, gchar **id)
Create an LSC credential.
int reverse_lookup_unify
Scanner pref reverse_lookup_unify.
const char * snmp_credential_id
ID of SNMP credential.
const char * report_id
ID of single report to get.
int omp_create_target_ext(gnutls_session_t *session, omp_create_target_opts_t opts, gchar **id)
Create a target.
const char * private_key
Private key.
const char * format_id
ID of required report format.
const char * observers
Comma-separated string of observer users.