OpenVAS Libraries  9.0.3
omp.c File Reference

OMP client interface. More...

#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include "omp.h"
#include "xml.h"
#include "../misc/openvas_server.h"
Include dependency graph for omp.c:

Go to the source code of this file.

Macros

#define G_LOG_DOMAIN   "lib omp"
 GLib log domain. More...
 
#define OMP_FMT_BOOL_ATTRIB(var, attrib)   (var.attrib == 0 ? " " #attrib "=\"0\"" : " " #attrib "=\"1\"")
 
#define OMP_FMT_STRING_ATTRIB(var, attrib)
 
#define DO_CHILDREN(entity, child, temp, body)
 Do something for each child of an entity. More...
 

Functions

const char * omp_task_status (entity_t response)
 Get the task status from an OMP GET_TASKS response. More...
 
int omp_ping (gnutls_session_t *session, int timeout)
 "Ping" the manager. More...
 
int omp_ping_c (openvas_connection_t *connection, int timeout, gchar **version)
 "Ping" the manager. More...
 
int omp_authenticate (gnutls_session_t *session, const char *username, const char *password)
 Authenticate with the manager. More...
 
int omp_authenticate_info_ext (gnutls_session_t *session, omp_authenticate_info_opts_t opts)
 Authenticate with the manager. More...
 
int omp_authenticate_info_ext_c (openvas_connection_t *connection, omp_authenticate_info_opts_t opts)
 Authenticate with the manager. More...
 
int omp_create_task_ext (gnutls_session_t *session, omp_create_task_opts_t opts, gchar **id)
 Create a task. More...
 
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. More...
 
int omp_start_task_report (gnutls_session_t *session, const char *task_id, char **report_id)
 Start a task and read the manager response. More...
 
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. More...
 
int check_response (gnutls_session_t *session)
 Read response and convert status of response to a return value. More...
 
int check_response_c (openvas_connection_t *connection)
 Read response and convert status of response to a return value. More...
 
int omp_read_create_response (gnutls_session_t *session, gchar **uuid)
 Read response status and resource UUID. More...
 
int omp_stop_task (gnutls_session_t *session, const char *id)
 Stop a task and read the manager response. More...
 
int omp_stop_task_c (openvas_connection_t *connection, const char *id)
 Stop a task and read the manager response. More...
 
int omp_resume_task_report (gnutls_session_t *session, const char *task_id, char **report_id)
 Resume a task and read the manager response. More...
 
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. More...
 
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. More...
 
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. More...
 
int omp_get_task_ext (gnutls_session_t *session, omp_get_task_opts_t opts, entity_t *response)
 Get a task (generic version). More...
 
int omp_get_tasks_ext (gnutls_session_t *session, omp_get_tasks_opts_t opts, entity_t *response)
 Get all tasks (generic version). More...
 
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. More...
 
int omp_delete_task (gnutls_session_t *session, const char *id)
 Delete a task and read the manager response. More...
 
int omp_get_targets (gnutls_session_t *session, const char *id, int tasks, int include_rcfile, entity_t *target)
 Get a target. More...
 
int omp_get_report_ext (gnutls_session_t *session, omp_get_report_opts_t opts, entity_t *response)
 Get a report (generic version). More...
 
int omp_delete_port_list_ext (gnutls_session_t *session, const char *id, omp_delete_opts_t opts)
 Delete a port list. More...
 
int omp_delete_report (gnutls_session_t *session, const char *id)
 Remove a report. More...
 
int omp_create_target_ext (gnutls_session_t *session, omp_create_target_opts_t opts, gchar **id)
 Create a target. More...
 
int omp_delete_target_ext (gnutls_session_t *session, const char *id, omp_delete_opts_t opts)
 Delete a target. More...
 
int omp_delete_config_ext (gnutls_session_t *session, const char *id, omp_delete_opts_t opts)
 Delete a config. More...
 
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. More...
 
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. More...
 
int omp_create_lsc_credential_ext (gnutls_session_t *session, omp_create_lsc_credential_opts_t opts, gchar **id)
 Create an LSC credential. More...
 
int omp_delete_lsc_credential_ext (gnutls_session_t *session, const char *id, omp_delete_opts_t opts)
 Delete a LSC credential. More...
 
int omp_get_system_reports (gnutls_session_t *session, const char *name, int brief, entity_t *reports)
 Get system reports. More...
 
int omp_get_system_reports_ext (gnutls_session_t *session, omp_get_system_reports_opts_t opts, entity_t *reports)
 Get system reports. More...
 

Detailed Description

OMP client interface.

Todo:
Name functions consistently (perhaps omp_*).

This provides higher level, OMP-aware, facilities for working with with the OpenVAS manager.

There are examples of using this interface in the openvas-manager tests.

Definition in file omp.c.

Macro Definition Documentation

◆ DO_CHILDREN

#define DO_CHILDREN (   entity,
  child,
  temp,
  body 
)
Value:
do \
{ \
GSList* temp = entity->entities; \
while (temp) \
{ \
entity_t child = temp->data; \
{ \
body; \
} \
temp = g_slist_next (temp); \
} \
} \
while (0)

Do something for each child of an entity.

Todo:
Use next_entities and first_entity instead of this.

Calling "break" during body exits the loop.

Parameters
[in]entityThe entity.
[in]childName to use for child variable.
[in]tempName to use for internal variable.
[in]bodyThe code to run for each child.

Definition at line 82 of file omp.c.

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "lib omp"

GLib log domain.

Definition at line 57 of file omp.c.

◆ OMP_FMT_BOOL_ATTRIB

#define OMP_FMT_BOOL_ATTRIB (   var,
  attrib 
)    (var.attrib == 0 ? " " #attrib "=\"0\"" : " " #attrib "=\"1\"")

Definition at line 59 of file omp.c.

Referenced by omp_get_report_ext(), omp_get_task_ext(), and omp_get_tasks_ext().

◆ OMP_FMT_STRING_ATTRIB

#define OMP_FMT_STRING_ATTRIB (   var,
  attrib 
)
Value:
(var.attrib ? " " #attrib "= \"" : ""), \
(var.attrib ? var.attrib : ""), \
(var.attrib ? "\"" : "")

Definition at line 62 of file omp.c.

Referenced by omp_get_report_ext().

Function Documentation

◆ check_response()

int check_response ( gnutls_session_t *  session)

Read response and convert status of response to a return value.

Todo:
Use this in the other functions.
Parameters
[in]sessionPointer to GNUTLS session.
Returns
0 on success, -1 or OMP response code on error.

Definition at line 863 of file omp.c.

References entity_attribute(), free_entity(), and read_entity().

Referenced by omp_delete_config_ext(), omp_delete_lsc_credential_ext(), omp_delete_port_list_ext(), omp_delete_report(), omp_delete_target_ext(), omp_delete_task(), omp_delete_task_ext(), omp_modify_task_file(), and omp_stop_task().

864 {
865  int ret;
866  const char* status;
867  entity_t entity;
868 
869  /* Read the response. */
870 
871  entity = NULL;
872  if (read_entity (session, &entity)) return -1;
873 
874  /* Check the response. */
875 
876  status = entity_attribute (entity, "status");
877  if (status == NULL)
878  {
879  free_entity (entity);
880  return -1;
881  }
882  if (strlen (status) == 0)
883  {
884  free_entity (entity);
885  return -1;
886  }
887  if (status[0] == '2')
888  {
889  free_entity (entity);
890  return 0;
891  }
892  ret = (int) strtol (status, NULL, 10);
893  free_entity (entity);
894  if (errno == ERANGE) return -1;
895  return ret;
896 }
int read_entity(gnutls_session_t *session, entity_t *entity)
Read an XML entity tree from the manager.
Definition: xml.c:1004
XML element.
Definition: xml.h:48
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xml.c:241
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xml.c:148
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_response_c()

int check_response_c ( openvas_connection_t connection)

Read response and convert status of response to a return value.

Parameters
[in]sessionPointer to GNUTLS session.
Returns
0 on success, -1 or OMP response code on error.

Definition at line 906 of file omp.c.

References entity_attribute(), free_entity(), and read_entity_c().

Referenced by omp_stop_task_c().

907 {
908  int ret;
909  const char* status;
910  entity_t entity;
911 
912  /* Read the response. */
913 
914  entity = NULL;
915  if (read_entity_c (connection, &entity)) return -1;
916 
917  /* Check the response. */
918 
919  status = entity_attribute (entity, "status");
920  if (status == NULL)
921  {
922  free_entity (entity);
923  return -1;
924  }
925  if (strlen (status) == 0)
926  {
927  free_entity (entity);
928  return -1;
929  }
930  if (status[0] == '2')
931  {
932  free_entity (entity);
933  return 0;
934  }
935  ret = (int) strtol (status, NULL, 10);
936  free_entity (entity);
937  if (errno == ERANGE) return -1;
938  return ret;
939 }
XML element.
Definition: xml.h:48
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xml.c:241
int read_entity_c(openvas_connection_t *connection, entity_t *entity)
Read an XML entity tree from the manager.
Definition: xml.c:1018
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xml.c:148
Here is the call graph for this function:
Here is the caller graph for this function:

◆ omp_authenticate()

int omp_authenticate ( gnutls_session_t *  session,
const char *  username,
const char *  password 
)

Authenticate with the manager.

Parameters
[in]sessionPointer to GNUTLS session.
[in]usernameUsername.
[in]passwordPassword.
Returns
0 on success, 1 if manager closed connection, 2 if auth failed, -1 on error.

Definition at line 271 of file omp.c.

References entity_attribute(), free_entity(), openvas_server_sendf_xml_quiet(), and read_entity().

274 {
275  entity_t entity;
276  const char* status;
277  char first;
278  int ret;
279 
280  /* Send the auth request. */
281  ret = openvas_server_sendf_xml_quiet (session,
282  "<authenticate><credentials>"
283  "<username>%s</username>"
284  "<password>%s</password>"
285  "</credentials></authenticate>",
286  username ? username : "",
287  password ? password : "");
288  if (ret)
289  return ret;
290 
291  /* Read the response. */
292 
293  entity = NULL;
294  if (read_entity (session, &entity)) return -1;
295 
296  /* Check the response. */
297 
298  status = entity_attribute (entity, "status");
299  if (status == NULL)
300  {
301  free_entity (entity);
302  return -1;
303  }
304  if (strlen (status) == 0)
305  {
306  free_entity (entity);
307  return -1;
308  }
309  first = status[0];
310  free_entity (entity);
311  if (first == '2') return 0;
312  return 2;
313 }
int read_entity(gnutls_session_t *session, entity_t *entity)
Read an XML entity tree from the manager.
Definition: xml.c:1004
XML element.
Definition: xml.h:48
int openvas_server_sendf_xml_quiet(gnutls_session_t *session, const char *format,...)
Format and send an XML string to the server.
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xml.c:241
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xml.c:148
Here is the call graph for this function:

◆ omp_authenticate_info_ext()

int omp_authenticate_info_ext ( gnutls_session_t *  session,
omp_authenticate_info_opts_t  opts 
)

Authenticate with the manager.

Parameters
[in]sessionPointer to GNUTLS session.
[in]optsStruct containing the options to apply.
[out]optsAdditional account information if authentication was successful.
Returns
0 on success, 1 if manager closed connection, 2 if auth failed, 3 on timeout, -1 on error.

Definition at line 327 of file omp.c.

References entity_attribute(), entity_child(), entity_text(), free_entity(), openvas_server_sendf_xml_quiet(), omp_authenticate_info_opts_t::password, omp_authenticate_info_opts_t::pw_warning, omp_authenticate_info_opts_t::role, omp_authenticate_info_opts_t::severity, omp_authenticate_info_opts_t::timeout, omp_authenticate_info_opts_t::timezone, try_read_entity(), and omp_authenticate_info_opts_t::username.

329 {
330  entity_t entity;
331  const char* status;
332  char first;
333  int ret;
334 
335  *(opts.timezone) = NULL;
336 
337  /* Send the auth request. */
338 
339  ret = openvas_server_sendf_xml_quiet (session,
340  "<authenticate><credentials>"
341  "<username>%s</username>"
342  "<password>%s</password>"
343  "</credentials></authenticate>",
344  opts.username,
345  opts.password);
346  if (ret)
347  return ret;
348 
349  /* Read the response. */
350 
351  entity = NULL;
352  switch (try_read_entity (session, opts.timeout, &entity))
353  {
354  case 0:
355  break;
356  case -4:
357  return 3;
358  default:
359  return -1;
360  }
361 
362  /* Check the response. */
363 
364  status = entity_attribute (entity, "status");
365  if (status == NULL)
366  {
367  free_entity (entity);
368  return -1;
369  }
370  if (strlen (status) == 0)
371  {
372  free_entity (entity);
373  return -1;
374  }
375  first = status[0];
376  if (first == '2')
377  {
378  entity_t timezone_entity, role_entity, severity_entity, pw_warn_entity;
379  /* Get the extra info. */
380  timezone_entity = entity_child (entity, "timezone");
381  if (timezone_entity)
382  *opts.timezone = g_strdup (entity_text (timezone_entity));
383  role_entity = entity_child (entity, "role");
384  if (role_entity)
385  *opts.role = g_strdup (entity_text (role_entity));
386  severity_entity = entity_child (entity, "severity");
387  if (severity_entity)
388  *opts.severity = g_strdup (entity_text (severity_entity));
389  pw_warn_entity = entity_child (entity, "password_warning");
390  if (pw_warn_entity)
391  *(opts.pw_warning) = g_strdup (entity_text (pw_warn_entity));
392  else
393  *(opts.pw_warning) = NULL;
394 
395  free_entity (entity);
396  return 0;
397  }
398  free_entity (entity);
399  return 2;
400 }
char * entity_text(entity_t entity)
Get the text an entity.
Definition: xml.c:178
XML element.
Definition: xml.h:48
int openvas_server_sendf_xml_quiet(gnutls_session_t *session, const char *format,...)
Format and send an XML string to the server.
int try_read_entity(gnutls_session_t *session, int timeout, entity_t *entity)
Try read an XML entity tree from the manager.
Definition: xml.c:973
int timeout
Timeout for authentication.
Definition: omp.h:45
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xml.c:241
char ** severity
[out] Severity class setting.
Definition: omp.h:49
const char * username
Password.
Definition: omp.h:46
const char * password
Username.
Definition: omp.h:47
entity_t entity_child(entity_t entity, const char *name)
Get a child of an entity.
Definition: xml.c:220
char ** timezone
[out] Timezone if any, else NULL.
Definition: omp.h:50
char ** pw_warning
[out] Password warning, NULL if password is okay.
Definition: omp.h:51
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xml.c:148
char ** role
[out] Role.
Definition: omp.h:48
Here is the call graph for this function:

◆ omp_authenticate_info_ext_c()

int omp_authenticate_info_ext_c ( openvas_connection_t connection,
omp_authenticate_info_opts_t  opts 
)

Authenticate with the manager.

Parameters
[in]connectionConnection
[in]optsStruct containing the options to apply.
Returns
0 on success, 1 if manager closed connection, 2 if auth failed, 3 on timeout, -1 on error.

Definition at line 412 of file omp.c.

References entity_attribute(), entity_child(), entity_text(), free_entity(), openvas_connection_sendf_xml_quiet(), omp_authenticate_info_opts_t::password, omp_authenticate_info_opts_t::pw_warning, omp_authenticate_info_opts_t::role, omp_authenticate_info_opts_t::severity, omp_authenticate_info_opts_t::timeout, omp_authenticate_info_opts_t::timezone, try_read_entity_c(), and omp_authenticate_info_opts_t::username.

414 {
415  entity_t entity;
416  const char* status;
417  char first;
418  int ret;
419 
420  if (opts.timezone)
421  *(opts.timezone) = NULL;
422 
423  /* Send the auth request. */
424 
425  ret = openvas_connection_sendf_xml_quiet (connection,
426  "<authenticate>"
427  "<credentials>"
428  "<username>%s</username>"
429  "<password>%s</password>"
430  "</credentials>"
431  "</authenticate>",
432  opts.username,
433  opts.password);
434  if (ret)
435  return ret;
436 
437  /* Read the response. */
438 
439  entity = NULL;
440  switch (try_read_entity_c (connection, opts.timeout, &entity))
441  {
442  case 0:
443  break;
444  case -4:
445  return 3;
446  default:
447  return -1;
448  }
449 
450  /* Check the response. */
451 
452  status = entity_attribute (entity, "status");
453  if (status == NULL)
454  {
455  free_entity (entity);
456  return -1;
457  }
458  if (strlen (status) == 0)
459  {
460  free_entity (entity);
461  return -1;
462  }
463  first = status[0];
464  if (first == '2')
465  {
466  entity_t timezone_entity, role_entity, severity_entity;
467  /* Get the extra info. */
468  timezone_entity = entity_child (entity, "timezone");
469  if (timezone_entity && opts.timezone)
470  *opts.timezone = g_strdup (entity_text (timezone_entity));
471  role_entity = entity_child (entity, "role");
472  if (role_entity && opts.role)
473  *opts.role = g_strdup (entity_text (role_entity));
474  severity_entity = entity_child (entity, "severity");
475  if (severity_entity && opts.severity)
476  *opts.severity = g_strdup (entity_text (severity_entity));
477  if (opts.pw_warning)
478  {
479  entity_t pw_warn_entity;
480  pw_warn_entity = entity_child (entity, "password_warning");
481  if (pw_warn_entity)
482  *(opts.pw_warning) = g_strdup (entity_text (pw_warn_entity));
483  else
484  *(opts.pw_warning) = NULL;
485  }
486 
487  free_entity (entity);
488  return 0;
489  }
490  free_entity (entity);
491  return 2;
492 }
int try_read_entity_c(openvas_connection_t *connection, int timeout, entity_t *entity)
Try read an XML entity tree from the manager.
Definition: xml.c:989
char * entity_text(entity_t entity)
Get the text an entity.
Definition: xml.c:178
XML element.
Definition: xml.h:48
int timeout
Timeout for authentication.
Definition: omp.h:45
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xml.c:241
char ** severity
[out] Severity class setting.
Definition: omp.h:49
const char * username
Password.
Definition: omp.h:46
const char * password
Username.
Definition: omp.h:47
entity_t entity_child(entity_t entity, const char *name)
Get a child of an entity.
Definition: xml.c:220
char ** timezone
[out] Timezone if any, else NULL.
Definition: omp.h:50
char ** pw_warning
[out] Password warning, NULL if password is okay.
Definition: omp.h:51
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xml.c:148
char ** role
[out] Role.
Definition: omp.h:48
int openvas_connection_sendf_xml_quiet(openvas_connection_t *connection, const char *format,...)
Format and send an XML string to the server.
Here is the call graph for this function:

◆ omp_create_lsc_credential()

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.

Parameters
[in]sessionPointer to GNUTLS session.
[in]nameName of LSC Credential.
[in]loginLogin associated with name.
[in]passwordPassword, or NULL for autogenerated credentials.
[in]commentLSC Credential comment.
[out]uuidEither NULL or address for UUID of created credential.
Returns
0 on success, -1 or OMP response code on error.

Definition at line 1841 of file omp.c.

References name, omp_read_create_response(), openvas_server_sendf_xml(), and openvas_server_sendf_xml_quiet().

1847 {
1848  int ret;
1849 
1850  if (password)
1851  {
1852  if (comment)
1853  ret = openvas_server_sendf_xml_quiet (session,
1854  "<create_credential>"
1855  "<name>%s</name>"
1856  "<login>%s</login>"
1857  "<password>%s</password>"
1858  "<comment>%s</comment>"
1859  "</create_credential>",
1860  name,
1861  login,
1862  password,
1863  comment);
1864  else
1865  ret = openvas_server_sendf_xml_quiet (session,
1866  "<create_credential>"
1867  "<name>%s</name>"
1868  "<login>%s</login>"
1869  "<password>%s</password>"
1870  "</create_credential>",
1871  name,
1872  login,
1873  password);
1874  }
1875  else
1876  {
1877  if (comment)
1878  ret = openvas_server_sendf_xml (session,
1879  "<create_credential>"
1880  "<name>%s</name>"
1881  "<login>%s</login>"
1882  "<comment>%s</comment>"
1883  "</create_credential>",
1884  name,
1885  login,
1886  comment);
1887  else
1888  ret = openvas_server_sendf_xml (session,
1889  "<create_credential>"
1890  "<name>%s</name>"
1891  "<login>%s</login>"
1892  "</create_credential>",
1893  name,
1894  login);
1895  }
1896  if (ret)
1897  return -1;
1898 
1899  ret = omp_read_create_response (session, uuid);
1900  if (ret == 201)
1901  return 0;
1902  return ret;
1903 }
int openvas_server_sendf_xml(gnutls_session_t *session, const char *format,...)
Format and send an XML string to the server.
int openvas_server_sendf_xml_quiet(gnutls_session_t *session, const char *format,...)
Format and send an XML string to the server.
const char * name
Definition: nasl_init.c:524
int omp_read_create_response(gnutls_session_t *session, gchar **uuid)
Read response status and resource UUID.
Definition: omp.c:951
Here is the call graph for this function:

◆ omp_create_lsc_credential_ext()

int omp_create_lsc_credential_ext ( gnutls_session_t *  session,
omp_create_lsc_credential_opts_t  opts,
gchar **  id 
)

Create an LSC credential.

Parameters
[in]sessionPointer to GNUTLS session.
[in]optsStruct containing the options to apply.
[out]idPointer for newly allocated ID of new LSC credential, or NULL. Only set on successful return.
Returns
0 on success, -1 or OMP response code on error.

Definition at line 1981 of file omp.c.

References omp_create_lsc_credential_opts_t::auth_algorithm, omp_create_lsc_credential_opts_t::comment, omp_create_lsc_credential_opts_t::community, omp_create_lsc_credential_opts_t::login, omp_create_lsc_credential_opts_t::name, omp_read_create_response(), openvas_server_sendf(), omp_create_lsc_credential_opts_t::passphrase, omp_create_lsc_credential_opts_t::privacy_algorithm, omp_create_lsc_credential_opts_t::privacy_password, and omp_create_lsc_credential_opts_t::private_key.

1984 {
1985  gchar *comment, *pass, *start, *snmp_elems;
1986  int ret;
1987 
1988  /* Create the OMP request. */
1989 
1990  if (opts.login == NULL)
1991  return -1;
1992 
1993  start = g_markup_printf_escaped ("<create_credential>"
1994  "<name>%s</name>"
1995  "<login>%s</login>",
1996  opts.name ? opts.name : "unnamed",
1997  opts.login);
1998 
1999  if (opts.comment)
2000  comment = g_markup_printf_escaped ("<comment>"
2001  "%s"
2002  "</comment>",
2003  opts.comment);
2004  else
2005  comment = NULL;
2006 
2007  if (opts.private_key)
2008  pass = g_markup_printf_escaped ("<key>"
2009  "<phrase>%s</phrase>"
2010  "<private>%s</private>"
2011  "</key>",
2012  opts.passphrase ? opts.passphrase : "",
2013  opts.private_key);
2014  else
2015  {
2016  if (opts.passphrase)
2017  pass = g_markup_printf_escaped ("<password>"
2018  "%s"
2019  "</password>",
2020  opts.passphrase);
2021  else
2022  pass = NULL;
2023  }
2024 
2025  if (opts.community && opts.auth_algorithm && opts.privacy_password
2026  && opts.privacy_algorithm)
2027  snmp_elems = g_markup_printf_escaped ("<community>"
2028  "%s"
2029  "</community>"
2030  "<auth_algorithm>"
2031  "%s"
2032  "</auth_algorithm>"
2033  "<privacy>"
2034  "<password>%s</password>"
2035  "<algorithm>%s</algorithm>"
2036  "</privacy>",
2037  opts.community,
2038  opts.auth_algorithm,
2039  opts.privacy_password,
2040  opts.privacy_algorithm);
2041  else
2042  snmp_elems = NULL;
2043 
2044  /* Send the request. */
2045 
2046  ret = openvas_server_sendf (session,
2047  "%s%s%s%s</create_credential>",
2048  start,
2049  comment ? comment : "",
2050  pass ? pass : "",
2051  snmp_elems ? snmp_elems : "");
2052 
2053  g_free (start);
2054  g_free (comment);
2055  g_free (pass);
2056  if (ret)
2057  return -1;
2058 
2059  /* Read the response. */
2060 
2061  ret = omp_read_create_response (session, id);
2062  if (ret == 201)
2063  return 0;
2064  return ret;
2065 }
const char * login
Login.
Definition: omp.h:235
int openvas_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
const char * community
SNMP community.
Definition: omp.h:234
const char * comment
Comment on LSC credential.
Definition: omp.h:241
const char * auth_algorithm
SNMP authentication algorithm.
Definition: omp.h:238
const char * passphrase
Passphrase.
Definition: omp.h:236
const char * privacy_password
SNMP privacy password.
Definition: omp.h:239
const char * privacy_algorithm
SNMP privacy algorithm.
Definition: omp.h:240
int omp_read_create_response(gnutls_session_t *session, gchar **uuid)
Read response status and resource UUID.
Definition: omp.c:951
const char * name
Name of LSC credential.
Definition: omp.h:233
const char * private_key
Private key.
Definition: omp.h:237
Here is the call graph for this function:

◆ omp_create_lsc_credential_key()

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.

Parameters
[in]sessionPointer to GNUTLS session.
[in]nameName of LSC Credential.
[in]loginLogin associated with name.
[in]passphrasePassphrase for private key.
[in]private_keyPrivate key.
[in]commentLSC Credential comment.
[out]uuidEither NULL or address for UUID of created credential.
Returns
0 on success, -1 or OMP response code on error.

Definition at line 1920 of file omp.c.

References name, omp_read_create_response(), and openvas_server_sendf_xml().

1927 {
1928  int ret;
1929 
1930  if (comment)
1931  ret = openvas_server_sendf_xml (session,
1932  "<create_credential>"
1933  "<name>%s</name>"
1934  "<login>%s</login>"
1935  "<key>"
1936  "<phrase>%s</phrase>"
1937  "<private>%s</private>"
1938  "</key>"
1939  "<comment>%s</comment>"
1940  "</create_credential>",
1941  name,
1942  login,
1943  passphrase ? passphrase : "",
1944  private_key,
1945  comment);
1946  else
1947  ret = openvas_server_sendf_xml (session,
1948  "<create_credential>"
1949  "<name>%s</name>"
1950  "<login>%s</login>"
1951  "<key>"
1952  "<phrase>%s</phrase>"
1953  "<private>%s</private>"
1954  "</key>"
1955  "</create_credential>",
1956  name,
1957  login,
1958  passphrase ? passphrase : "",
1959  private_key);
1960 
1961  if (ret)
1962  return -1;
1963 
1964  ret = omp_read_create_response (session, uuid);
1965  if (ret == 201)
1966  return 0;
1967  return ret;
1968 }
int openvas_server_sendf_xml(gnutls_session_t *session, const char *format,...)
Format and send an XML string to the server.
const char * name
Definition: nasl_init.c:524
int omp_read_create_response(gnutls_session_t *session, gchar **uuid)
Read response status and resource UUID.
Definition: omp.c:951
Here is the call graph for this function:

◆ omp_create_target_ext()

int omp_create_target_ext ( gnutls_session_t *  session,
omp_create_target_opts_t  opts,
gchar **  id 
)

Create a target.

FIXME: Using the according opts it should be possible to generate any type of create_target request defined by the spec.

Parameters
[in]sessionPointer to GNUTLS session.
[in]optsStruct containing the options to apply.
[out]idPointer for newly allocated ID of new target, or NULL. Only set on successful return.
Returns
0 on success (OMP 201), -2 on connection error, OMP response code on OMP error, -1 other error.

Definition at line 1664 of file omp.c.

References omp_create_target_opts_t::alive_tests, omp_create_target_opts_t::comment, omp_create_target_opts_t::esxi_credential_id, omp_create_target_opts_t::exclude_hosts, omp_create_target_opts_t::hosts, omp_create_target_opts_t::name, omp_read_create_response(), openvas_server_sendf(), omp_create_target_opts_t::port_range, omp_create_target_opts_t::reverse_lookup_only, omp_create_target_opts_t::reverse_lookup_unify, omp_create_target_opts_t::smb_credential_id, omp_create_target_opts_t::snmp_credential_id, omp_create_target_opts_t::ssh_credential_id, and omp_create_target_opts_t::ssh_credential_port.

1667 {
1668  gchar *comment, *ssh, *smb, *esxi, *snmp, *port_range, *start;
1669  gchar *exclude_hosts, *alive_tests;
1670  int ret;
1671 
1672  /* Create the OMP request. */
1673 
1674  if (opts.hosts == NULL)
1675  return -1;
1676 
1677  start = g_markup_printf_escaped ("<create_target>"
1678  "<name>%s</name>"
1679  "<hosts>%s</hosts>",
1680  opts.name ? opts.name : "unnamed",
1681  opts.hosts);
1682 
1683  if (opts.exclude_hosts)
1684  exclude_hosts = g_markup_printf_escaped ("<exclude_hosts>"
1685  "%s"
1686  "</exclude_hosts>",
1687  opts.exclude_hosts);
1688  else
1689  exclude_hosts = NULL;
1690 
1691  if (opts.alive_tests)
1692  alive_tests = g_markup_printf_escaped ("<alive_tests>"
1693  "%s"
1694  "</alive_tests>",
1695  opts.alive_tests);
1696  else
1697  alive_tests = NULL;
1698 
1699  if (opts.comment)
1700  comment = g_markup_printf_escaped ("<comment>"
1701  "%s"
1702  "</comment>",
1703  opts.comment);
1704  else
1705  comment = NULL;
1706 
1707  if (opts.ssh_credential_id)
1708  {
1709  if (opts.ssh_credential_port)
1710  ssh = g_markup_printf_escaped ("<ssh_lsc_credential id=\"%s\">"
1711  "<port>%i</port>"
1712  "</ssh_lsc_credential>",
1713  opts.ssh_credential_id,
1714  opts.ssh_credential_port);
1715  else
1716  ssh = g_markup_printf_escaped ("<ssh_lsc_credential id=\"%s\"/>",
1717  opts.ssh_credential_id);
1718  }
1719  else
1720  ssh = NULL;
1721 
1722  if (opts.smb_credential_id)
1723  smb = g_markup_printf_escaped ("<smb_lsc_credential id=\"%s\"/>",
1724  opts.smb_credential_id);
1725  else
1726  smb = NULL;
1727 
1728  if (opts.esxi_credential_id)
1729  esxi = g_markup_printf_escaped ("<esxi_lsc_credential id=\"%s\"/>",
1730  opts.esxi_credential_id);
1731  else
1732  esxi = NULL;
1733 
1734  if (opts.snmp_credential_id)
1735  snmp = g_markup_printf_escaped ("<snmp_credential id=\"%s\"/>",
1736  opts.snmp_credential_id);
1737  else
1738  snmp = NULL;
1739 
1740  if (opts.port_range)
1741  port_range = g_markup_printf_escaped ("<port_range>%s</port_range>",
1742  opts.port_range);
1743  else
1744  port_range = NULL;
1745 
1746  /* Send the request. */
1747  ret = openvas_server_sendf (session,
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>"
1751  "</create_target>",
1752  start,
1753  exclude_hosts ? exclude_hosts : "",
1754  alive_tests ? alive_tests : "",
1755  ssh ? ssh : "",
1756  smb ? smb : "",
1757  esxi ? esxi : "",
1758  snmp ? snmp : "",
1759  port_range ? port_range : "",
1760  comment ? comment : "",
1761  opts.reverse_lookup_only,
1762  opts.reverse_lookup_unify);
1763  g_free (start);
1764  g_free (exclude_hosts);
1765  g_free (alive_tests);
1766  g_free (ssh);
1767  g_free (smb);
1768  g_free (esxi);
1769  g_free (port_range);
1770  g_free (comment);
1771  if (ret)
1772  return -2;
1773 
1774  /* Read the response. */
1775 
1776  ret = omp_read_create_response (session, id);
1777  if (ret == 201)
1778  return 0;
1779  return ret;
1780 }
int reverse_lookup_only
Scanner pref reverse_lookup_only.
Definition: omp.h:199
int openvas_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
const char * ssh_credential_id
ID of SSH credential.
Definition: omp.h:188
const char * alive_tests
Alive tests.
Definition: omp.h:197
const char * esxi_credential_id
ID of ESXi credential.
Definition: omp.h:190
const char * hosts
Name of target.
Definition: omp.h:195
const char * port_range
Port range.
Definition: omp.h:192
const char * exclude_hosts
Hosts to exclude.
Definition: omp.h:196
const char * comment
Comment on target.
Definition: omp.h:194
const char * smb_credential_id
ID of SMB credential.
Definition: omp.h:189
int ssh_credential_port
Port for SSH access.
Definition: omp.h:187
const char * name
Name of target.
Definition: omp.h:193
int omp_read_create_response(gnutls_session_t *session, gchar **uuid)
Read response status and resource UUID.
Definition: omp.c:951
int reverse_lookup_unify
Scanner pref reverse_lookup_unify.
Definition: omp.h:200
const char * snmp_credential_id
ID of SNMP credential.
Definition: omp.h:191
Here is the call graph for this function:

◆ omp_create_task()

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.

Parameters
[in]sessionPointer to GNUTLS session.
[in]nameTask name.
[in]configTask config name.
[in]targetTask target name.
[in]commentTask comment.
[out]idPointer for newly allocated ID of new task. Only set on successful return.
Returns
0 on success, -1 or OMP response code on error.

Definition at line 703 of file omp.c.

References name, omp_read_create_response(), and openvas_server_sendf_xml().

709 {
710  int ret;
711 
712  ret = openvas_server_sendf_xml (session,
713  "<create_task>"
714  "<config id=\"%s\"/>"
715  "<target id=\"%s\"/>"
716  "<name>%s</name>"
717  "<comment>%s</comment>"
718  "</create_task>",
719  config,
720  target,
721  name,
722  comment);
723  if (ret)
724  return -1;
725 
726  /* Read the response. */
727 
728  ret = omp_read_create_response (session, id);
729  if (ret == 201)
730  return 0;
731  return ret;
732 }
int openvas_server_sendf_xml(gnutls_session_t *session, const char *format,...)
Format and send an XML string to the server.
const char * name
Definition: nasl_init.c:524
int omp_read_create_response(gnutls_session_t *session, gchar **uuid)
Read response status and resource UUID.
Definition: omp.c:951
Here is the call graph for this function:

◆ omp_create_task_ext()

int omp_create_task_ext ( gnutls_session_t *  session,
omp_create_task_opts_t  opts,
gchar **  id 
)

Create a task.

FIXME: Using the according opts it should be possible to generate any type of create_task request defined by the spec.

Parameters
[in]sessionPointer to GNUTLS session.
[in]optsStruct containing the options to apply.
[out]idPointer for newly allocated ID of new task, or NULL. Only set on successful return.
Returns
0 on success, -1 or OMP response code on error.

Definition at line 508 of file omp.c.

References omp_create_task_opts_t::alert_ids, omp_create_task_opts_t::alterable, omp_create_task_opts_t::comment, omp_create_task_opts_t::config_id, omp_create_task_opts_t::hosts_ordering, omp_create_task_opts_t::in_assets, omp_create_task_opts_t::max_checks, omp_create_task_opts_t::max_hosts, omp_create_task_opts_t::name, omp_create_task_opts_t::observer_groups, omp_create_task_opts_t::observers, omp_read_create_response(), openvas_server_sendf(), omp_create_task_opts_t::scanner_id, omp_create_task_opts_t::schedule_id, omp_create_task_opts_t::schedule_periods, omp_create_task_opts_t::slave_id, omp_create_task_opts_t::source_iface, and omp_create_task_opts_t::target_id.

511 {
512  /* Create the OMP request. */
513 
514  gchar *prefs, *start, *hosts_ordering, *scanner, *schedule, *slave;
515  GString *alerts, *observers;
516  int ret;
517  if ((opts.config_id == NULL) || (opts.target_id == NULL))
518  return -1;
519 
520  prefs = NULL;
521  start = g_markup_printf_escaped ("<create_task>"
522  "<config id=\"%s\"/>"
523  "<target id=\"%s\"/>"
524  "<name>%s</name>"
525  "<comment>%s</comment>"
526  "<alterable>%d</alterable>",
527  opts.config_id,
528  opts.target_id,
529  opts.name ? opts.name : "unnamed",
530  opts.comment ? opts.comment : "",
531  opts.alterable ? 1 : 0);
532 
533  if (opts.hosts_ordering)
534  hosts_ordering = g_strdup_printf ("<hosts_ordering>%s</hosts_ordering>",
535  opts.hosts_ordering);
536  else
537  hosts_ordering = NULL;
538 
539  if (opts.scanner_id)
540  scanner = g_strdup_printf ("<scanner id=\"%s\"/>",
541  opts.scanner_id);
542  else
543  scanner = NULL;
544 
545  if (opts.schedule_id)
546  schedule = g_strdup_printf ("<schedule id=\"%s\"/>"
547  "<schedule_periods>%d</schedule_periods>",
548  opts.schedule_id,
549  opts.schedule_periods);
550  else
551  schedule = NULL;
552 
553  if (opts.slave_id)
554  slave = g_strdup_printf ("<slave id=\"%s\"/>",
555  opts.slave_id);
556  else
557  slave = NULL;
558 
559  if (opts.max_checks || opts.max_hosts || opts.in_assets || opts.source_iface)
560  {
561  gchar *in_assets, *checks, *hosts, *source_iface;
562 
563  in_assets = checks = hosts = source_iface = NULL;
564 
565  if (opts.in_assets)
566  in_assets = g_markup_printf_escaped ("<preference>"
567  "<scanner_name>"
568  "in_assets"
569  "</scanner_name>"
570  "<value>"
571  "%s"
572  "</value>"
573  "</preference>",
574  opts.in_assets);
575 
576  if (opts.max_checks)
577  checks = g_markup_printf_escaped ("<preference>"
578  "<scanner_name>"
579  "max_hosts"
580  "</scanner_name>"
581  "<value>"
582  "%s"
583  "</value>"
584  "</preference>",
585  opts.max_hosts);
586 
587  if (opts.max_checks)
588  hosts = g_markup_printf_escaped ("<preference>"
589  "<scanner_name>"
590  "max_checks"
591  "</scanner_name>"
592  "<value>"
593  "%s"
594  "</value>"
595  "</preference>",
596  opts.max_checks);
597 
598  if (opts.source_iface)
599  source_iface = g_markup_printf_escaped ("<preference>"
600  "<scanner_name>"
601  "source_iface"
602  "</scanner_name>"
603  "<value>"
604  "%s"
605  "</value>"
606  "</preference>",
607  opts.source_iface);
608 
609  prefs = g_strdup_printf ("<preferences>%s%s%s%s</preferences>",
610  in_assets ? in_assets : "",
611  checks ? checks : "",
612  hosts ? hosts : "",
613  source_iface ? source_iface : "");
614  g_free (in_assets);
615  g_free (checks);
616  g_free (hosts);
617  g_free (source_iface);
618  }
619 
620  if (opts.alert_ids)
621  {
622  unsigned int i;
623  alerts = g_string_new ("");
624  for (i = 0; i < opts.alert_ids->len; i++)
625  {
626  char *alert = (char*)g_ptr_array_index (opts.alert_ids, i);
627  g_string_append_printf (alerts,
628  "<alert id=\"%s\"/>",
629  alert);
630  }
631  }
632  else
633  alerts = g_string_new ("");
634 
635 
636  if (opts.observers || opts.observer_groups)
637  {
638  observers = g_string_new ("<observers>");
639 
640  if (opts.observers)
641  g_string_append (observers, opts.observers);
642 
643  if (opts.observer_groups)
644  {
645  unsigned int i;
646  for (i = 0; i < opts.observer_groups->len; i++)
647  {
648  char *group = (char*) g_ptr_array_index (opts.observer_groups, i);
649  g_string_append_printf (observers,
650  "<group id=\"%s\"/>",
651  group);
652  }
653  }
654  g_string_append (observers, "</observers>");
655  }
656  else
657  observers = g_string_new ("");
658 
659  /* Send the request. */
660  ret = openvas_server_sendf (session, "%s%s%s%s%s%s%s%s</create_task>",
661  start,
662  prefs ? prefs : "",
663  hosts_ordering ? hosts_ordering : "",
664  scanner ? scanner : "",
665  schedule ? schedule : "",
666  slave ? slave : "",
667  alerts ? alerts->str : "",
668  observers ? observers->str : "");
669  g_free (start);
670  g_free (prefs);
671  g_free (hosts_ordering);
672  g_free (scanner);
673  g_free (schedule);
674  g_free (slave);
675  g_string_free (alerts, TRUE);
676  g_string_free (observers, TRUE);
677 
678  if (ret)
679  return -1;
680 
681  /* Read the response. */
682 
683  ret = omp_read_create_response (session, id);
684  if (ret == 201)
685  return 0;
686  return ret;
687 }
int openvas_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
const char * target_id
ID of target.
Definition: omp.h:157
int schedule_periods
Number of periods the schedule must run for.
Definition: omp.h:163
const char * hosts_ordering
Order for scanning target hosts.
Definition: omp.h:160
int alterable
Whether the task is alterable.
Definition: omp.h:170
const char * comment
Comment on task.
Definition: omp.h:159
array_t * alert_ids
Array of alert IDs.
Definition: omp.h:152
array_t * observer_groups
IDs of observer groups.
Definition: omp.h:162
const char * slave_id
ID of task schedule.
Definition: omp.h:156
const char * max_hosts
Max hosts preference.
Definition: omp.h:166
const char * source_iface
Source iface preference.
Definition: omp.h:168
const char * scanner_id
ID of task scanner.
Definition: omp.h:154
const char * in_assets
In assets preference.
Definition: omp.h:165
const char * schedule_id
ID of task schedule.
Definition: omp.h:155
int omp_read_create_response(gnutls_session_t *session, gchar **uuid)
Read response status and resource UUID.
Definition: omp.c:951
const char * max_checks
Max checks preference.
Definition: omp.h:167
const char * name
Name of task.
Definition: omp.h:158
const char * config_id
ID of config.
Definition: omp.h:153
const char * observers
Comma-separated string of observer users.
Definition: omp.h:161
Here is the call graph for this function:

◆ omp_delete_config_ext()

int omp_delete_config_ext ( gnutls_session_t *  session,
const char *  id,
omp_delete_opts_t  opts 
)

Delete a config.

Parameters
[in]sessionPointer to GNUTLS session.
[in]idUUID of config.
[in]optsStruct containing the options to apply.
Returns
0 on success, -1 or OMP response code on error.

Definition at line 1815 of file omp.c.

References check_response(), openvas_server_sendf(), and omp_delete_opts_t::ultimate.

1818 {
1819  if (openvas_server_sendf (session,
1820  "<delete_config config_id=\"%s\" ultimate=\"%d\"/>",
1821  id, opts.ultimate)
1822  == -1)
1823  return -1;
1824 
1825  return check_response (session);
1826 }
int ultimate
Definition: omp.h:255
int openvas_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
int check_response(gnutls_session_t *session)
Read response and convert status of response to a return value.
Definition: omp.c:863
Here is the call graph for this function:

◆ omp_delete_lsc_credential_ext()

int omp_delete_lsc_credential_ext ( gnutls_session_t *  session,
const char *  id,
omp_delete_opts_t  opts 
)

Delete a LSC credential.

Parameters
[in]sessionPointer to GNUTLS session.
[in]idUUID of LSC credential.
[in]optsStruct containing the options to apply.
Returns
0 on success, -1 or OMP response code on error.

Definition at line 2077 of file omp.c.

References check_response(), openvas_server_sendf(), and omp_delete_opts_t::ultimate.

2080 {
2081  if (openvas_server_sendf (session,
2082  "<delete_credential credential_id=\"%s\""
2083  " ultimate=\"%d\"/>",
2084  id, opts.ultimate)
2085  == -1)
2086  return -1;
2087 
2088  return check_response (session);
2089 }
int ultimate
Definition: omp.h:255
int openvas_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
int check_response(gnutls_session_t *session)
Read response and convert status of response to a return value.
Definition: omp.c:863
Here is the call graph for this function:

◆ omp_delete_port_list_ext()

int omp_delete_port_list_ext ( gnutls_session_t *  session,
const char *  id,
omp_delete_opts_t  opts 
)

Delete a port list.

Parameters
[in]sessionPointer to GNUTLS session.
[in]idUUID of port list.
[in]optsStruct containing the options to apply.
Returns
0 on success, -1 or OMP response code on error.

Definition at line 1619 of file omp.c.

References check_response(), openvas_server_sendf(), and omp_delete_opts_t::ultimate.

1622 {
1623  if (openvas_server_sendf (session,
1624  "<delete_port_list port_list_id=\"%s\" ultimate=\"%d\"/>",
1625  id, opts.ultimate)
1626  == -1)
1627  return -1;
1628 
1629  return check_response (session);
1630 }
int ultimate
Definition: omp.h:255
int openvas_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
int check_response(gnutls_session_t *session)
Read response and convert status of response to a return value.
Definition: omp.c:863
Here is the call graph for this function:

◆ omp_delete_report()

int omp_delete_report ( gnutls_session_t *  session,
const char *  id 
)

Remove a report.

Parameters
[in]sessionPointer to GNUTLS session.
[in]idID of report.
Returns
0 on success, OMP response code on failure, -1 on error.

Definition at line 1641 of file omp.c.

References check_response(), and openvas_server_sendf().

1642 {
1643  if (openvas_server_sendf (session, "<delete_report report_id=\"%s\"/>", id))
1644  return -1;
1645 
1646  return check_response (session);
1647 }
int openvas_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
int check_response(gnutls_session_t *session)
Read response and convert status of response to a return value.
Definition: omp.c:863
Here is the call graph for this function:

◆ omp_delete_target_ext()

int omp_delete_target_ext ( gnutls_session_t *  session,
const char *  id,
omp_delete_opts_t  opts 
)

Delete a target.

Parameters
[in]sessionPointer to GNUTLS session.
[in]idUUID of target.
[in]optsStruct containing the options to apply.
Returns
0 on success, -1 or OMP response code on error.

Definition at line 1792 of file omp.c.

References check_response(), openvas_server_sendf(), and omp_delete_opts_t::ultimate.

1795 {
1796  if (openvas_server_sendf (session,
1797  "<delete_target target_id=\"%s\" ultimate=\"%d\"/>",
1798  id, opts.ultimate)
1799  == -1)
1800  return -1;
1801 
1802  return check_response (session);
1803 }
int ultimate
Definition: omp.h:255
int openvas_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
int check_response(gnutls_session_t *session)
Read response and convert status of response to a return value.
Definition: omp.c:863
Here is the call graph for this function:

◆ omp_delete_task()

int omp_delete_task ( gnutls_session_t *  session,
const char *  id 
)

Delete a task and read the manager response.

Parameters
[in]sessionPointer to GNUTLS session.
[in]idID of task.
Returns
0 on success, OMP response code on failure, -1 on error.

Definition at line 1434 of file omp.c.

References check_response(), and openvas_server_sendf().

1435 {
1436  if (openvas_server_sendf (session, "<delete_task task_id=\"%s\"/>", id) == -1)
1437  return -1;
1438 
1439  return check_response (session);
1440 }
int openvas_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
int check_response(gnutls_session_t *session)
Read response and convert status of response to a return value.
Definition: omp.c:863
Here is the call graph for this function:

◆ omp_delete_task_ext()

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.

Parameters
[in]sessionPointer to GNUTLS session.
[in]idID of task.
[in]optsStruct containing the options to apply.
Returns
0 on success, OMP response code on failure, -1 on error.

Definition at line 1163 of file omp.c.

References check_response(), openvas_server_sendf(), and omp_delete_opts_t::ultimate.

1165 {
1166  if (openvas_server_sendf (session,
1167  "<delete_task task_id=\"%s\" ultimate=\"%d\"/>",
1168  id, opts.ultimate)
1169  == -1)
1170  return -1;
1171 
1172  return check_response (session);
1173 }
int ultimate
Definition: omp.h:255
int openvas_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
int check_response(gnutls_session_t *session)
Read response and convert status of response to a return value.
Definition: omp.c:863
Here is the call graph for this function:

◆ omp_get_report_ext()

int omp_get_report_ext ( gnutls_session_t *  session,
omp_get_report_opts_t  opts,
entity_t response 
)

Get a report (generic version).

FIXME: Using the according opts it should be possible to generate any type of get_reports request defined by the spec.

Parameters
[in]sessionPointer to GNUTLS session.
[in]optsStruct containing the options to apply.
[out]responseReport. On success contains GET_REPORT response.
Returns
0 on success, 2 on timeout, -1 or OMP response code on error.

Definition at line 1520 of file omp.c.

References entity_attribute(), omp_get_report_opts_t::format_id, free_entity(), omp_get_report_opts_t::host_first_result, omp_get_report_opts_t::host_max_results, OMP_FMT_BOOL_ATTRIB, OMP_FMT_STRING_ATTRIB, openvas_server_sendf(), omp_get_report_opts_t::report_id, omp_get_report_opts_t::timeout, and try_read_entity().

1523 {
1524  int ret;
1525  const char *status_code;
1526 
1527  if (response == NULL)
1528  return -1;
1529 
1530  if (openvas_server_sendf (session,
1531  "<get_reports"
1532  " report_id=\"%s\""
1533  " format_id=\"%s\""
1534  " host_first_result=\"%i\""
1535  " host_max_results=\"%i\""
1536  "%s%s%s"
1537  "%s%s%s"
1538  "%s%s%s"
1539  "%s%s%s"
1540  "%s%s%s"
1541  "%s%s%s"
1542  "%s%s%s"
1543  "%s%s%s"
1544  "%s%s%s"
1545  "%s%s%s"
1546  "%s%s%s"
1547  "%s%s%s"
1548  "%s%s%s"
1549  "%s%s%s"
1550  "%s%s%s%s%s%s%s/>",
1551  opts.report_id,
1552  opts.format_id,
1553  opts.host_first_result,
1554  opts.host_max_results,
1555  OMP_FMT_STRING_ATTRIB (opts, type),
1556  OMP_FMT_STRING_ATTRIB (opts, filter),
1557  OMP_FMT_STRING_ATTRIB (opts, filt_id),
1558  OMP_FMT_STRING_ATTRIB (opts, host),
1559  OMP_FMT_STRING_ATTRIB (opts, pos),
1560  OMP_FMT_STRING_ATTRIB (opts, timezone),
1561  OMP_FMT_STRING_ATTRIB (opts, alert_id),
1562  OMP_FMT_STRING_ATTRIB (opts, delta_report_id),
1563  OMP_FMT_STRING_ATTRIB (opts, delta_states),
1564  OMP_FMT_STRING_ATTRIB (opts, host_levels),
1565  OMP_FMT_STRING_ATTRIB (opts, search_phrase),
1566  OMP_FMT_STRING_ATTRIB (opts, host_search_phrase),
1567  OMP_FMT_STRING_ATTRIB (opts, min_cvss_base),
1568  OMP_FMT_STRING_ATTRIB (opts, min_qod),
1569  OMP_FMT_BOOL_ATTRIB (opts, notes),
1570  OMP_FMT_BOOL_ATTRIB (opts, notes_details),
1571  OMP_FMT_BOOL_ATTRIB (opts, overrides),
1572  OMP_FMT_BOOL_ATTRIB (opts, override_details),
1573  OMP_FMT_BOOL_ATTRIB (opts, apply_overrides),
1574  OMP_FMT_BOOL_ATTRIB (opts, result_hosts_only),
1575  OMP_FMT_BOOL_ATTRIB (opts, ignore_pagination)))
1576  return -1;
1577 
1578  *response = NULL;
1579  switch (try_read_entity (session, opts.timeout, response))
1580  {
1581  case 0:
1582  break;
1583  case -4:
1584  return 2;
1585  default:
1586  return -1;
1587  }
1588 
1589  /* Check the response. */
1590 
1591  status_code = entity_attribute (*response, "status");
1592  if (status_code == NULL)
1593  {
1594  free_entity (*response);
1595  return -1;
1596  }
1597  if (strlen (status_code) == 0)
1598  {
1599  free_entity (*response);
1600  return -1;
1601  }
1602  if (status_code[0] == '2') return 0;
1603  ret = (int) strtol (status_code, NULL, 10);
1604  free_entity (*response);
1605  if (errno == ERANGE) return -1;
1606  return ret;
1607 }
int timeout
Timeout for OMP response.
Definition: omp.h:72
#define OMP_FMT_STRING_ATTRIB(var, attrib)
Definition: omp.c:62
int openvas_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
int host_first_result
Skip over results before this result number.
Definition: omp.h:73
int try_read_entity(gnutls_session_t *session, int timeout, entity_t *entity)
Try read an XML entity tree from the manager.
Definition: xml.c:973
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xml.c:241
int host_max_results
Maximum number of results to return.
Definition: omp.h:74
#define OMP_FMT_BOOL_ATTRIB(var, attrib)
Definition: omp.c:59
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xml.c:148
const char * report_id
ID of single report to get.
Definition: omp.h:69
const char * format_id
ID of required report format.
Definition: omp.h:67
Here is the call graph for this function:

◆ omp_get_system_reports()

int omp_get_system_reports ( gnutls_session_t *  session,
const char *  name,
int  brief,
entity_t reports 
)

Get system reports.

Parameters
[in]sessionPointer to GNUTLS session.
[in]nameName of system report. NULL for all.
[in]briefWhether to request brief response.
[out]reportsReports return. On success contains GET_SYSTEM_REPORTS response.
Returns
0 on success, -1 or OMP response code on error.

Definition at line 2103 of file omp.c.

References entity_attribute(), free_entity(), name, openvas_server_sendf(), and read_entity().

2105 {
2106  int ret;
2107  const char *status_code;
2108 
2109  if (name)
2110  {
2111  if (openvas_server_sendf (session,
2112  "<get_system_reports name=\"%s\" brief=\"%i\"/>",
2113  name,
2114  brief)
2115  == -1)
2116  return -1;
2117  }
2118  else if (openvas_server_sendf (session,
2119  "<get_system_reports brief=\"%i\"/>",
2120  brief)
2121  == -1)
2122  return -1;
2123 
2124  /* Read the response. */
2125 
2126  *reports = NULL;
2127  if (read_entity (session, reports)) return -1;
2128 
2129  /* Check the response. */
2130 
2131  status_code = entity_attribute (*reports, "status");
2132  if (status_code == NULL)
2133  {
2134  free_entity (*reports);
2135  return -1;
2136  }
2137  if (strlen (status_code) == 0)
2138  {
2139  free_entity (*reports);
2140  return -1;
2141  }
2142  if (status_code[0] == '2') return 0;
2143  ret = (int) strtol (status_code, NULL, 10);
2144  free_entity (*reports);
2145  if (errno == ERANGE) return -1;
2146  return ret;
2147 }
int openvas_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
int read_entity(gnutls_session_t *session, entity_t *entity)
Read an XML entity tree from the manager.
Definition: xml.c:1004
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xml.c:241
const char * name
Definition: nasl_init.c:524
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xml.c:148
Here is the call graph for this function:

◆ omp_get_system_reports_ext()

int omp_get_system_reports_ext ( gnutls_session_t *  session,
omp_get_system_reports_opts_t  opts,
entity_t reports 
)

Get system reports.

Parameters
[in]sessionPointer to GNUTLS session.
[in]optsStruct containing the options to apply.
[out]reportsReports return. On success contains GET_SYSTEM_REPORTS response.
Returns
0 on success, -1 or OMP response code on error.

Definition at line 2160 of file omp.c.

References omp_get_system_reports_opts_t::duration, omp_get_system_reports_opts_t::end_time, entity_attribute(), free_entity(), omp_get_system_reports_opts_t::name, openvas_server_sendf(), read_entity(), omp_get_system_reports_opts_t::slave_id, omp_get_system_reports_opts_t::start_time, and xml_string_append().

2163 {
2164  const char* status_code;
2165  GString *request;
2166  int ret;
2167 
2168  request = g_string_new ("<get_system_reports");
2169 
2170  if (opts.slave_id)
2171  xml_string_append (request, " slave_id=\"%s\"", opts.slave_id);
2172 
2173  if (opts.name)
2174  xml_string_append (request, " name=\"%s\"", opts.name);
2175 
2176  if (opts.duration)
2177  xml_string_append (request, " duration=\"%s\"", opts.duration);
2178 
2179  if (opts.start_time)
2180  xml_string_append (request, " start_time=\"%s\"", opts.start_time);
2181 
2182  if (opts.end_time)
2183  xml_string_append (request, " end_time=\"%s\"", opts.end_time);
2184 
2185  g_string_append (request, "/>");
2186 
2187  /* Create the OMP request. */
2188 
2189  if (openvas_server_sendf (session, "%s", request->str) == -1)
2190  {
2191  g_string_free (request, 1);
2192  return -1;
2193  }
2194  g_string_free (request, 1);
2195 
2196  /* Read the response. */
2197 
2198  *reports = NULL;
2199  if (read_entity (session, reports)) return -1;
2200 
2201  /* Check the response. */
2202 
2203  status_code = entity_attribute (*reports, "status");
2204  if (status_code == NULL)
2205  {
2206  free_entity (*reports);
2207  return -1;
2208  }
2209  if (strlen (status_code) == 0)
2210  {
2211  free_entity (*reports);
2212  return -1;
2213  }
2214  if (status_code[0] == '2') return 0;
2215  ret = (int) strtol (status_code, NULL, 10);
2216  free_entity (*reports);
2217  if (errno == ERANGE) return -1;
2218  return ret;
2219 }
int openvas_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
const char * duration
Duration.
Definition: omp.h:215
const char * name
Name of report.
Definition: omp.h:214
int read_entity(gnutls_session_t *session, entity_t *entity)
Read an XML entity tree from the manager.
Definition: xml.c:1004
const char * slave_id
ID of the slave to get report from.
Definition: omp.h:218
void xml_string_append(GString *xml, const char *format,...)
Append formatted escaped XML to a string.
Definition: xml.c:1366
const char * start_time
Time of first data point.
Definition: omp.h:216
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xml.c:241
const char * end_time
Time of last data point.
Definition: omp.h:217
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xml.c:148
Here is the call graph for this function:

◆ omp_get_targets()

int omp_get_targets ( gnutls_session_t *  session,
const char *  id,
int  tasks,
int  include_rcfile,
entity_t target 
)

Get a target.

Parameters
[in]sessionPointer to GNUTLS session.
[in]idID of target or NULL for all targets.
[in]tasksWhether to include tasks that use the target.
[in]include_rcfileNot used.
[out]targetTarget return. On success contains GET_TARGETS response.
Returns
0 on success, -1 or OMP response code on error.

Definition at line 1455 of file omp.c.

References entity_attribute(), free_entity(), openvas_server_sendf(), and read_entity().

1457 {
1458  const char* status_code;
1459  int ret;
1460 
1461  (void) include_rcfile;
1462  if (id == NULL)
1463  {
1464  if (openvas_server_sendf (session,
1465  "<get_targets tasks=\"%i\"/>",
1466  tasks)
1467  == -1)
1468  return -1;
1469  }
1470  else
1471  {
1472  if (openvas_server_sendf (session,
1473  "<get_targets"
1474  " target_id=\"%s\""
1475  " tasks=\"%i\"/>",
1476  id,
1477  tasks)
1478  == -1)
1479  return -1;
1480  }
1481 
1482  /* Read the response. */
1483 
1484  *target = NULL;
1485  if (read_entity (session, target)) return -1;
1486 
1487  /* Check the response. */
1488 
1489  status_code = entity_attribute (*target, "status");
1490  if (status_code == NULL)
1491  {
1492  free_entity (*target);
1493  return -1;
1494  }
1495  if (strlen (status_code) == 0)
1496  {
1497  free_entity (*target);
1498  return -1;
1499  }
1500  if (status_code[0] == '2') return 0;
1501  ret = (int) strtol (status_code, NULL, 10);
1502  free_entity (*target);
1503  if (errno == ERANGE) return -1;
1504  return ret;
1505 }
int openvas_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
int read_entity(gnutls_session_t *session, entity_t *entity)
Read an XML entity tree from the manager.
Definition: xml.c:1004
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xml.c:241
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xml.c:148
Here is the call graph for this function:

◆ omp_get_task_ext()

int omp_get_task_ext ( gnutls_session_t *  session,
omp_get_task_opts_t  opts,
entity_t response 
)

Get a task (generic version).

Parameters
[in]sessionPointer to GNUTLS session.
[in]optsStruct containing the options to apply.
[out]responseTask. On success contains GET_TASKS response.
Returns
0 on success, -1 or OMP response code on error.

Definition at line 1250 of file omp.c.

References omp_get_task_opts_t::actions, entity_attribute(), free_entity(), OMP_FMT_BOOL_ATTRIB, openvas_server_sendf(), read_entity(), and omp_get_task_opts_t::task_id.

1253 {
1254  int ret;
1255  const char *status_code;
1256 
1257  if ((response == NULL) || (opts.task_id == NULL))
1258  return -1;
1259 
1260  if (opts.actions)
1261  {
1262  if (openvas_server_sendf (session,
1263  "<get_tasks"
1264  " task_id=\"%s\""
1265  " actions=\"%s\""
1266  "%s/>",
1267  opts.task_id,
1268  opts.actions,
1269  OMP_FMT_BOOL_ATTRIB (opts, details)))
1270  return -1;
1271  }
1272  else if (openvas_server_sendf (session,
1273  "<get_tasks"
1274  " task_id=\"%s\""
1275  "%s/>",
1276  opts.task_id,
1277  OMP_FMT_BOOL_ATTRIB (opts, details)))
1278  return -1;
1279 
1280  *response = NULL;
1281  if (read_entity (session, response)) return -1;
1282 
1283  /* Check the response. */
1284 
1285  status_code = entity_attribute (*response, "status");
1286  if (status_code == NULL)
1287  {
1288  free_entity (*response);
1289  return -1;
1290  }
1291  if (strlen (status_code) == 0)
1292  {
1293  free_entity (*response);
1294  return -1;
1295  }
1296  if (status_code[0] == '2') return 0;
1297  ret = (int) strtol (status_code, NULL, 10);
1298  free_entity (*response);
1299  if (errno == ERANGE) return -1;
1300  return ret;
1301 }
int openvas_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
const char * task_id
ID of single task to get.
Definition: omp.h:135
int read_entity(gnutls_session_t *session, entity_t *entity)
Read an XML entity tree from the manager.
Definition: xml.c:1004
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xml.c:241
const char * actions
Actions argument.
Definition: omp.h:134
#define OMP_FMT_BOOL_ATTRIB(var, attrib)
Definition: omp.c:59
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xml.c:148
Here is the call graph for this function:

◆ omp_get_tasks()

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.

Parameters
[in]sessionPointer to GNUTLS session.
[in]idID of task or NULL for all tasks.
[in]detailsWhether to request task details.
[in]include_rcfileIgnored. Removed since OMP 6.0.
[out]statusStatus return. On success contains GET_TASKS response.
Returns
0 on success, -1 or OMP response code on error.

Definition at line 1188 of file omp.c.

References entity_attribute(), free_entity(), openvas_server_sendf(), and read_entity().

1190 {
1191  const char* status_code;
1192  int ret;
1193 
1194  (void) include_rcfile;
1195  if (id == NULL)
1196  {
1197  if (openvas_server_sendf (session,
1198  "<get_tasks details=\"%i\"/>",
1199  details)
1200  == -1)
1201  return -1;
1202  }
1203  else
1204  {
1205  if (openvas_server_sendf (session,
1206  "<get_tasks"
1207  " task_id=\"%s\""
1208  " details=\"%i\"/>",
1209  id,
1210  details)
1211  == -1)
1212  return -1;
1213  }
1214 
1215  /* Read the response. */
1216 
1217  *status = NULL;
1218  if (read_entity (session, status)) return -1;
1219 
1220  /* Check the response. */
1221 
1222  status_code = entity_attribute (*status, "status");
1223  if (status_code == NULL)
1224  {
1225  free_entity (*status);
1226  return -1;
1227  }
1228  if (strlen (status_code) == 0)
1229  {
1230  free_entity (*status);
1231  return -1;
1232  }
1233  if (status_code[0] == '2') return 0;
1234  ret = (int) strtol (status_code, NULL, 10);
1235  free_entity (*status);
1236  if (errno == ERANGE) return -1;
1237  return ret;
1238 }
int openvas_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
int read_entity(gnutls_session_t *session, entity_t *entity)
Read an XML entity tree from the manager.
Definition: xml.c:1004
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xml.c:241
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xml.c:148
Here is the call graph for this function:

◆ omp_get_tasks_ext()

int omp_get_tasks_ext ( gnutls_session_t *  session,
omp_get_tasks_opts_t  opts,
entity_t response 
)

Get all tasks (generic version).

Parameters
[in]sessionPointer to GNUTLS session.
[in]optsStruct containing the options to apply.
[out]responseTasks. On success contains GET_TASKS response.
Returns
0 on success, 2 on timeout, -1 or OMP response code on error.

Definition at line 1313 of file omp.c.

References entity_attribute(), omp_get_tasks_opts_t::filter, free_entity(), OMP_FMT_BOOL_ATTRIB, openvas_server_sendf(), omp_get_tasks_opts_t::timeout, and try_read_entity().

1316 {
1317  int ret;
1318  const char *status_code;
1319  gchar *cmd;
1320 
1321  if (response == NULL)
1322  return -1;
1323 
1324  cmd = g_markup_printf_escaped ("<get_tasks"
1325  " filter=\"%s\"",
1326  opts.filter);
1327 
1328  if (openvas_server_sendf (session,
1329  "%s%s/>",
1330  cmd,
1331  OMP_FMT_BOOL_ATTRIB (opts, details)))
1332  {
1333  g_free (cmd);
1334  return -1;
1335  }
1336  g_free (cmd);
1337 
1338  *response = NULL;
1339  switch (try_read_entity (session, opts.timeout, response))
1340  {
1341  case 0:
1342  break;
1343  case -4:
1344  return 2;
1345  default:
1346  return -1;
1347  }
1348 
1349  /* Check the response. */
1350 
1351  status_code = entity_attribute (*response, "status");
1352  if (status_code == NULL)
1353  {
1354  free_entity (*response);
1355  return -1;
1356  }
1357  if (strlen (status_code) == 0)
1358  {
1359  free_entity (*response);
1360  return -1;
1361  }
1362  if (status_code[0] == '2') return 0;
1363  ret = (int) strtol (status_code, NULL, 10);
1364  free_entity (*response);
1365  if (errno == ERANGE) return -1;
1366  return ret;
1367 }
int openvas_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
int try_read_entity(gnutls_session_t *session, int timeout, entity_t *entity)
Try read an XML entity tree from the manager.
Definition: xml.c:973
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xml.c:241
int timeout
Timeout for OMP response.
Definition: omp.h:116
#define OMP_FMT_BOOL_ATTRIB(var, attrib)
Definition: omp.c:59
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xml.c:148
const char * filter
Filter argument.
Definition: omp.h:115
Here is the call graph for this function:

◆ omp_modify_task_file()

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.

Parameters
[in]sessionPointer to GNUTLS session.
[in]idID of task.
[in]nameName of file.
[in]contentNew content. NULL to remove file.
[in]content_lenLength of content.
Returns
0 on success, -1 or OMP response code on error.

Definition at line 1381 of file omp.c.

References check_response(), name, and openvas_server_sendf().

1384 {
1385  if (name == NULL)
1386  return -1;
1387 
1388  if (openvas_server_sendf (session, "<modify_task task_id=\"%s\">", id))
1389  return -1;
1390 
1391  if (content)
1392  {
1393  if (openvas_server_sendf (session, "<file name=\"%s\" action=\"update\">",
1394  name))
1395  return -1;
1396 
1397  if (content_len)
1398  {
1399  gchar *base64_content = g_base64_encode ((guchar*) content,
1400  content_len);
1401  int ret = openvas_server_sendf (session,
1402  "%s",
1403  base64_content);
1404  g_free (base64_content);
1405  if (ret) return -1;
1406  }
1407 
1408  if (openvas_server_sendf (session, "</file>"))
1409  return -1;
1410  }
1411  else
1412  {
1413  if (openvas_server_sendf (session,
1414  "<file name=\"%s\" action=\"remove\" />",
1415  name))
1416  return -1;
1417  }
1418 
1419  if (openvas_server_sendf (session, "</modify_task>"))
1420  return -1;
1421 
1422  return check_response (session);
1423 }
int openvas_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
int check_response(gnutls_session_t *session)
Read response and convert status of response to a return value.
Definition: omp.c:863
const char * name
Definition: nasl_init.c:524
Here is the call graph for this function:

◆ omp_ping()

int omp_ping ( gnutls_session_t *  session,
int  timeout 
)

"Ping" the manager.

Parameters
[in]sessionPointer to GNUTLS session.
[in]timeoutServer idle time before giving up, in milliseconds. 0 to wait forever.
Returns
0 on success, 1 if manager closed connection, 2 on timeout, -1 on error.

Definition at line 141 of file omp.c.

References entity_attribute(), free_entity(), openvas_server_sendf(), and try_read_entity().

142 {
143  entity_t entity;
144  const char* status;
145  char first;
146  int ret;
147 
148  /* Send a GET_VERSION request. */
149 
150  ret = openvas_server_sendf (session, "<get_version/>");
151  if (ret)
152  return ret;
153 
154  /* Read the response, with a timeout. */
155 
156  entity = NULL;
157  switch (try_read_entity (session, timeout, &entity))
158  {
159  case 0:
160  break;
161  case -4:
162  return 2;
163  default:
164  return -1;
165  }
166 
167  /* Check the response. */
168 
169  status = entity_attribute (entity, "status");
170  if (status == NULL)
171  {
172  free_entity (entity);
173  return -1;
174  }
175  if (strlen (status) == 0)
176  {
177  free_entity (entity);
178  return -1;
179  }
180  first = status[0];
181  free_entity (entity);
182  if (first == '2') return 0;
183  return -1;
184 }
int openvas_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
XML element.
Definition: xml.h:48
int try_read_entity(gnutls_session_t *session, int timeout, entity_t *entity)
Try read an XML entity tree from the manager.
Definition: xml.c:973
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xml.c:241
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xml.c:148
Here is the call graph for this function:

◆ omp_ping_c()

int omp_ping_c ( openvas_connection_t connection,
int  timeout,
gchar **  version 
)

"Ping" the manager.

Parameters
[in]sessionPointer to GNUTLS session.
[in]timeoutServer idle time before giving up, in milliseconds. 0 to wait forever.
[out]versionReturn location for freshly allocated version if required, else NULL.
Returns
0 on success, 1 if manager closed connection, 2 on timeout, -1 on error.

Definition at line 199 of file omp.c.

References entity_attribute(), entity_child(), entity_text(), free_entity(), openvas_connection_sendf(), and try_read_entity_c().

200 {
201  entity_t entity;
202  const char* status;
203  int ret;
204 
205  if (*version)
206  *version = NULL;
207 
208  /* Send a GET_VERSION request. */
209 
210  ret = openvas_connection_sendf (connection, "<get_version/>");
211  if (ret)
212  return ret;
213 
214  /* Read the response, with a timeout. */
215 
216  entity = NULL;
217  switch (try_read_entity_c (connection, timeout, &entity))
218  {
219  case 0:
220  break;
221  case -4:
222  return 2;
223  default:
224  return -1;
225  }
226 
227  /* Check the response. */
228 
229  status = entity_attribute (entity, "status");
230  if (status == NULL)
231  {
232  free_entity (entity);
233  return -1;
234  }
235  if (strlen (status) == 0)
236  {
237  free_entity (entity);
238  return -1;
239  }
240  if (status[0] == '2')
241  {
242  if (version)
243  {
244  entity_t omp_version;
245  omp_version = entity_child (entity, "version");
246  if (omp_version == NULL)
247  {
248  free_entity (entity);
249  return -1;
250  }
251  *version = strdup (entity_text (omp_version));
252  }
253  free_entity (entity);
254  return 0;
255  }
256  free_entity (entity);
257  return -1;
258 }
int try_read_entity_c(openvas_connection_t *connection, int timeout, entity_t *entity)
Try read an XML entity tree from the manager.
Definition: xml.c:989
char * entity_text(entity_t entity)
Get the text an entity.
Definition: xml.c:178
XML element.
Definition: xml.h:48
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xml.c:241
entity_t entity_child(entity_t entity, const char *name)
Get a child of an entity.
Definition: xml.c:220
int openvas_connection_sendf(openvas_connection_t *connection, const char *format,...)
Format and send a string to the server.
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xml.c:148
Here is the call graph for this function:

◆ omp_read_create_response()

int omp_read_create_response ( gnutls_session_t *  session,
gchar **  uuid 
)

Read response status and resource UUID.

Parameters
[in]sessionPointer to GNUTLS session.
[out]uuidEither NULL or address for freshly allocated UUID of created response.
Returns
OMP response code on success, -1 on error.

Definition at line 951 of file omp.c.

References entity_attribute(), free_entity(), and read_entity().

Referenced by omp_create_lsc_credential(), omp_create_lsc_credential_ext(), omp_create_lsc_credential_key(), omp_create_target_ext(), omp_create_task(), and omp_create_task_ext().

952 {
953  int ret;
954  const char *status, *id;
955  entity_t entity;
956 
957  /* Read the response. */
958 
959  entity = NULL;
960  if (read_entity (session, &entity)) return -1;
961 
962  /* Parse the response. */
963 
964  status = entity_attribute (entity, "status");
965  if (status == NULL)
966  {
967  free_entity (entity);
968  return -1;
969  }
970  if (strlen (status) == 0)
971  {
972  free_entity (entity);
973  return -1;
974  }
975 
976  if (uuid)
977  {
978  id = entity_attribute (entity, "id");
979  if (id == NULL)
980  {
981  free_entity (entity);
982  return -1;
983  }
984  if (strlen (id) == 0)
985  {
986  free_entity (entity);
987  return -1;
988  }
989  *uuid = g_strdup (id);
990  }
991 
992  ret = atoi (status);
993  free_entity (entity);
994  return ret;
995 }
int read_entity(gnutls_session_t *session, entity_t *entity)
Read an XML entity tree from the manager.
Definition: xml.c:1004
XML element.
Definition: xml.h:48
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xml.c:241
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xml.c:148
Here is the call graph for this function:
Here is the caller graph for this function:

◆ omp_resume_task_report()

int omp_resume_task_report ( gnutls_session_t *  session,
const char *  task_id,
char **  report_id 
)

Resume a task and read the manager response.

Parameters
[in]sessionPointer to GNUTLS session.
[in]task_idID of task.
[out]report_idID of report.
Returns
0 on success, 1 on OMP failure, -1 on error.

Definition at line 1047 of file omp.c.

References entity_attribute(), entity_child(), entity_text(), free_entity(), openvas_server_sendf(), and read_entity().

1049 {
1050  if (openvas_server_sendf (session,
1051  "<resume_task task_id=\"%s\"/>",
1052  task_id)
1053  == -1)
1054  return -1;
1055 
1056  /* Read the response. */
1057 
1058  entity_t entity = NULL;
1059  if (read_entity (session, &entity)) return -1;
1060 
1061  /* Check the response. */
1062 
1063  const char* status = entity_attribute (entity, "status");
1064  if (status == NULL)
1065  {
1066  free_entity (entity);
1067  return -1;
1068  }
1069  if (strlen (status) == 0)
1070  {
1071  free_entity (entity);
1072  return -1;
1073  }
1074  char first = status[0];
1075  if (first == '2')
1076  {
1077  if (report_id)
1078  {
1079  entity_t report_id_xml = entity_child (entity, "report_id");
1080  if (report_id_xml)
1081  *report_id = g_strdup (entity_text (report_id_xml));
1082  else
1083  {
1084  free_entity (entity);
1085  return -1;
1086  }
1087  }
1088  free_entity (entity);
1089  return 0;
1090  }
1091  free_entity (entity);
1092  return 1;
1093 }
int openvas_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
int read_entity(gnutls_session_t *session, entity_t *entity)
Read an XML entity tree from the manager.
Definition: xml.c:1004
char * entity_text(entity_t entity)
Get the text an entity.
Definition: xml.c:178
XML element.
Definition: xml.h:48
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xml.c:241
entity_t entity_child(entity_t entity, const char *name)
Get a child of an entity.
Definition: xml.c:220
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xml.c:148
Here is the call graph for this function:

◆ omp_resume_task_report_c()

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.

Parameters
[in]connectionConnection.
[in]task_idID of task.
[out]report_idID of report.
Returns
0 on success, 1 on OMP failure, -1 on error.

Definition at line 1105 of file omp.c.

References entity_attribute(), entity_child(), entity_text(), free_entity(), openvas_connection_sendf(), and read_entity_c().

1107 {
1108  if (openvas_connection_sendf (connection,
1109  "<resume_task task_id=\"%s\"/>",
1110  task_id)
1111  == -1)
1112  return -1;
1113 
1114  /* Read the response. */
1115 
1116  entity_t entity = NULL;
1117  if (read_entity_c (connection, &entity)) return -1;
1118 
1119  /* Check the response. */
1120 
1121  const char* status = entity_attribute (entity, "status");
1122  if (status == NULL)
1123  {
1124  free_entity (entity);
1125  return -1;
1126  }
1127  if (strlen (status) == 0)
1128  {
1129  free_entity (entity);
1130  return -1;
1131  }
1132  char first = status[0];
1133  if (first == '2')
1134  {
1135  if (report_id)
1136  {
1137  entity_t report_id_xml = entity_child (entity, "report_id");
1138  if (report_id_xml)
1139  *report_id = g_strdup (entity_text (report_id_xml));
1140  else
1141  {
1142  free_entity (entity);
1143  return -1;
1144  }
1145  }
1146  free_entity (entity);
1147  return 0;
1148  }
1149  free_entity (entity);
1150  return 1;
1151 }
char * entity_text(entity_t entity)
Get the text an entity.
Definition: xml.c:178
XML element.
Definition: xml.h:48
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xml.c:241
entity_t entity_child(entity_t entity, const char *name)
Get a child of an entity.
Definition: xml.c:220
int read_entity_c(openvas_connection_t *connection, entity_t *entity)
Read an XML entity tree from the manager.
Definition: xml.c:1018
int openvas_connection_sendf(openvas_connection_t *connection, const char *format,...)
Format and send a string to the server.
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xml.c:148
Here is the call graph for this function:

◆ omp_start_task_report()

int omp_start_task_report ( gnutls_session_t *  session,
const char *  task_id,
char **  report_id 
)

Start a task and read the manager response.

Parameters
[in]sessionPointer to GNUTLS session.
[in]task_idID of task.
[out]report_idID of report.
Returns
0 on success, 1 on failure, -1 on error.

Definition at line 744 of file omp.c.

References entity_attribute(), entity_child(), entity_text(), free_entity(), openvas_server_sendf(), and read_entity().

746 {
747  if (openvas_server_sendf (session,
748  "<start_task task_id=\"%s\"/>",
749  task_id)
750  == -1)
751  return -1;
752 
753  /* Read the response. */
754 
755  entity_t entity = NULL;
756  if (read_entity (session, &entity)) return -1;
757 
758  /* Check the response. */
759 
760  const char* status = entity_attribute (entity, "status");
761  if (status == NULL)
762  {
763  free_entity (entity);
764  return -1;
765  }
766  if (strlen (status) == 0)
767  {
768  free_entity (entity);
769  return -1;
770  }
771  char first = status[0];
772  if (first == '2')
773  {
774  if (report_id)
775  {
776  entity_t report_id_xml = entity_child (entity, "report_id");
777  if (report_id_xml)
778  *report_id = g_strdup (entity_text (report_id_xml));
779  else
780  {
781  free_entity (entity);
782  return -1;
783  }
784  }
785  free_entity (entity);
786  return 0;
787  }
788  free_entity (entity);
789  return 1;
790 }
int openvas_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
int read_entity(gnutls_session_t *session, entity_t *entity)
Read an XML entity tree from the manager.
Definition: xml.c:1004
char * entity_text(entity_t entity)
Get the text an entity.
Definition: xml.c:178
XML element.
Definition: xml.h:48
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xml.c:241
entity_t entity_child(entity_t entity, const char *name)
Get a child of an entity.
Definition: xml.c:220
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xml.c:148
Here is the call graph for this function:

◆ omp_start_task_report_c()

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.

Parameters
[in]connectionConnection.
[in]task_idID of task.
[out]report_idID of report.
Returns
0 on success, 1 on failure, -1 on error.

Definition at line 802 of file omp.c.

References entity_attribute(), entity_child(), entity_text(), free_entity(), openvas_connection_sendf(), and read_entity_c().

804 {
805  entity_t entity;
806  const char *status;
807  char first;
808 
809  if (openvas_connection_sendf (connection,
810  "<start_task task_id=\"%s\"/>",
811  task_id)
812  == -1)
813  return -1;
814 
815  /* Read the response. */
816 
817  entity = NULL;
818  if (read_entity_c (connection, &entity)) return -1;
819 
820  /* Check the response. */
821 
822  status = entity_attribute (entity, "status");
823  if (status == NULL)
824  {
825  free_entity (entity);
826  return -1;
827  }
828  if (strlen (status) == 0)
829  {
830  free_entity (entity);
831  return -1;
832  }
833  first = status[0];
834  if (first == '2')
835  {
836  if (report_id)
837  {
838  entity_t report_id_xml = entity_child (entity, "report_id");
839  if (report_id_xml)
840  *report_id = g_strdup (entity_text (report_id_xml));
841  else
842  {
843  free_entity (entity);
844  return -1;
845  }
846  }
847  free_entity (entity);
848  return 0;
849  }
850  free_entity (entity);
851  return 1;
852 }
char * entity_text(entity_t entity)
Get the text an entity.
Definition: xml.c:178
XML element.
Definition: xml.h:48
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xml.c:241
entity_t entity_child(entity_t entity, const char *name)
Get a child of an entity.
Definition: xml.c:220
int read_entity_c(openvas_connection_t *connection, entity_t *entity)
Read an XML entity tree from the manager.
Definition: xml.c:1018
int openvas_connection_sendf(openvas_connection_t *connection, const char *format,...)
Format and send a string to the server.
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xml.c:148
Here is the call graph for this function:

◆ omp_stop_task()

int omp_stop_task ( gnutls_session_t *  session,
const char *  id 
)

Stop a task and read the manager response.

Parameters
[in]sessionPointer to GNUTLS session.
[in]idID of task.
Returns
0 on success, OMP response code on failure, -1 on error.

Definition at line 1006 of file omp.c.

References check_response(), and openvas_server_sendf().

1007 {
1008  if (openvas_server_sendf (session,
1009  "<stop_task task_id=\"%s\"/>",
1010  id)
1011  == -1)
1012  return -1;
1013 
1014  return check_response (session);
1015 }
int openvas_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
int check_response(gnutls_session_t *session)
Read response and convert status of response to a return value.
Definition: omp.c:863
Here is the call graph for this function:

◆ omp_stop_task_c()

int omp_stop_task_c ( openvas_connection_t connection,
const char *  id 
)

Stop a task and read the manager response.

Parameters
[in]sessionPointer to GNUTLS session.
[in]idID of task.
Returns
0 on success, OMP response code on failure, -1 on error.

Definition at line 1026 of file omp.c.

References check_response_c(), and openvas_connection_sendf().

1027 {
1028  if (openvas_connection_sendf (connection,
1029  "<stop_task task_id=\"%s\"/>",
1030  id)
1031  == -1)
1032  return -1;
1033 
1034  return check_response_c (connection);
1035 }
int check_response_c(openvas_connection_t *connection)
Read response and convert status of response to a return value.
Definition: omp.c:906
int openvas_connection_sendf(openvas_connection_t *connection, const char *format,...)
Format and send a string to the server.
Here is the call graph for this function:

◆ omp_task_status()

const char* omp_task_status ( entity_t  response)

Get the task status from an OMP GET_TASKS response.

Parameters
[in]responseGET_TASKS response.
Returns
The entity_text of the status entity if the entity is found, else NULL.

Definition at line 119 of file omp.c.

References entity_child(), and entity_text().

120 {
121  entity_t task = entity_child (response, "task");
122  if (task)
123  {
124  entity_t status = entity_child (task, "status");
125  if (status) return entity_text (status);
126  }
127  return NULL;
128 }
char * entity_text(entity_t entity)
Get the text an entity.
Definition: xml.c:178
XML element.
Definition: xml.h:48
entity_t entity_child(entity_t entity, const char *name)
Get a child of an entity.
Definition: xml.c:220
Here is the call graph for this function: