OpenVAS Libraries  9.0.1
Macros | Functions
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"

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_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.

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.

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "lib omp"

GLib log domain.

◆ OMP_FMT_BOOL_ATTRIB

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

◆ OMP_FMT_STRING_ATTRIB

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

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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.