OpenVAS Manager  7.0.3~git
omp.h File Reference
#include "types.h"
#include <openvas/misc/openvas_server.h>
#include <glib.h>
#include <gnutls/gnutls.h>
#include <sys/types.h>
Include dependency graph for omp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define TO_CLIENT_BUFFER_SIZE   26214400
 The size of the to_client data buffer, in bytes. More...
 

Functions

int init_omp (GSList *, int, const gchar *, int, int, int, int, void(*)(), int(*)(openvas_connection_t *, gchar *), int)
 Initialise OMP library. More...
 
void init_omp_process (int, const gchar *, int(*)(const char *, void *), void *, gchar **)
 Initialise OMP library data for a process. More...
 
int process_omp_client_input ()
 Process any XML available in from_client. More...
 
int process_omp_change ()
 Deal with any changes caused by other processes. More...
 

Variables

char to_client []
 Buffer of output to the client. More...
 
buffer_size_t to_client_start
 The start of the data in the to_client buffer. More...
 
buffer_size_t to_client_end
 The end of the data in the to_client buffer. More...
 

Macro Definition Documentation

◆ TO_CLIENT_BUFFER_SIZE

#define TO_CLIENT_BUFFER_SIZE   26214400

The size of the to_client data buffer, in bytes.

Definition at line 38 of file omp.h.

Referenced by ompd_send_to_client().

Function Documentation

◆ init_omp()

int init_omp ( GSList *  log_config,
int  nvt_cache_mode,
const gchar *  database,
int  max_ips_per_target,
int  max_email_attachment_size,
int  max_email_include_size,
int  max_email_message_size,
void(*)()  progress,
int(*)(openvas_connection_t *, gchar *)  fork_connection,
int  skip_db_check 
)

Initialise OMP library.

Parameters
[in]log_configLogging configuration list.
[in]nvt_cache_modeTrue when running in NVT caching mode.
[in]databaseLocation of manage database.
[in]max_ips_per_targetMax number of IPs per target.
[in]max_email_attachment_sizeMax size of email attachments.
[in]max_email_include_sizeMax size of email inclusions.
[in]max_email_message_sizeMax size of email user message text.
[in]progressFunction to update progress, or NULL.
[in]fork_connectionFunction to fork a connection to the OMP daemon layer, or NULL.
[in]skip_db_checkSkip DB check.
Returns
0 success, -1 error, -2 database is wrong version, -3 database needs to be initialized from server, -4 max_ips_per_target out of range.

Definition at line 30814 of file omp.c.

30820 {
30821  g_log_set_handler (G_LOG_DOMAIN,
30823  (GLogFunc) openvas_log_func,
30824  log_config);
30825  command_data_init (&command_data);
30826  return init_manage (log_config, nvt_cache_mode, database, max_ips_per_target,
30827  max_email_attachment_size, max_email_include_size,
30828  max_email_message_size,
30829  progress, fork_connection, skip_db_check);
30830 }
GSList * log_config
Logging parameters, as passed to setup_log_handlers.
Definition: openvasmd.c:310
int init_manage(GSList *, int, const gchar *, int, int, int, int, void(*)(), int(*)(openvas_connection_t *, gchar *), int)
Initialize the manage library.
Definition: manage_sql.c:17065
void(* progress)()
Function to mark progress.
Definition: manage_sql.c:352
command_data_t command_data
Parser callback data.
Definition: omp.c:4330
#define G_LOG_DOMAIN
GLib log domain.
Definition: omp.c:130
#define ALL_LOG_LEVELS
Flag with all Glib log levels.
Definition: manage.h:47

◆ init_omp_process()

void init_omp_process ( int  update_nvt_cache,
const gchar *  database,
int(*)(const char *, void *)  write_to_client,
void *  write_to_client_data,
gchar **  disable 
)

Initialise OMP library data for a process.

Parameters
[in]update_nvt_cache0 operate normally, -1 just update NVT cache, -2 just rebuild NVT cache.
[in]databaseLocation of manage database.
[in]write_to_clientFunction to write to client.
[in]write_to_client_dataArgument to write_to_client.
[in]disableCommands to disable.

This should run once per process, before the first call to process_omp_client_input.

Definition at line 30846 of file omp.c.

Referenced by init_ompd_process().

30849 {
30850  forked = 0;
30851  client_state = CLIENT_TOP;
30852  command_data_init (&command_data);
30853  init_manage_process (update_nvt_cache, database);
30855  /* Create the XML parser. */
30856  xml_parser.start_element = omp_xml_handle_start_element;
30857  xml_parser.end_element = omp_xml_handle_end_element;
30858  xml_parser.text = omp_xml_handle_text;
30859  xml_parser.passthrough = NULL;
30860  xml_parser.error = omp_xml_handle_error;
30861  if (xml_context)
30862  g_markup_parse_context_free (xml_context);
30863  xml_context = g_markup_parse_context_new
30864  (&xml_parser,
30865  0,
30866  omp_parser_new (write_to_client, write_to_client_data,
30867  disable),
30868  (GDestroyNotify) omp_parser_free);
30869 }
void init_manage_process(int, const gchar *)
Initialize the manage library for a process.
Definition: manage_sql.c:14303
void omp_parser_free(omp_parser_t *omp_parser)
Free an OMP parser.
Definition: omp.c:748
void manage_reset_currents()
Cleanup as immediately as possible.
Definition: manage_sql.c:17173
command_data_t command_data
Parser callback data.
Definition: omp.c:4330
omp_parser_t * omp_parser_new(int(*write_to_client)(const char *, void *), void *write_to_client_data, gchar **disable)
Create an OMP parser.
Definition: omp.c:729
int forked
Hack for returning fork status to caller.
Definition: omp.c:4974
Here is the caller graph for this function:

◆ process_omp_change()

int process_omp_change ( )

Deal with any changes caused by other processes.

Returns
0 success, 1 did something, -1 too little space in the scanner output buffer.

Definition at line 31098 of file omp.c.

References manage_check_current_task().

31099 {
31100  return manage_check_current_task ();
31101 }
int manage_check_current_task()
Handle state changes to current task made by other processes.
Definition: manage.c:5733
Here is the call graph for this function:

◆ process_omp_client_input()

int process_omp_client_input ( )

Process any XML available in from_client.

Todo:
The -2 return has been replaced by send_to_client trying to write the to_client buffer to the client when it is full. This is necessary, as the to_client buffer may fill up halfway through the processing of an OMP element.
Returns
0 success, -1 error, -2 or -3 too little space in to_client or the scanner output buffer (respectively), -4 XML syntax error.

Definition at line 30895 of file omp.c.

References current_error, g_info, and manage_transaction_stop().

30896 {
30897  gboolean success;
30898  GError* error = NULL;
30899 
30900  /* Terminate any pending transaction. (force close = TRUE). */
30901  manage_transaction_stop (TRUE);
30902 
30903  /* In the XML parser handlers all writes to the to_scanner buffer must be
30904  * complete OTP commands, because the caller may also write into to_scanner
30905  * between calls to this function (via manage_check_current_task). */
30906 
30907  if (xml_context == NULL) return -1;
30908 
30909  current_error = 0;
30910  success = g_markup_parse_context_parse (xml_context,
30913  &error);
30914  if (success == FALSE)
30915  {
30916  int err;
30917  if (error)
30918  {
30919  err = -4;
30920  if (g_error_matches (error,
30921  G_MARKUP_ERROR,
30922  G_MARKUP_ERROR_UNKNOWN_ELEMENT))
30923  g_debug (" client error: G_MARKUP_ERROR_UNKNOWN_ELEMENT\n");
30924  else if (g_error_matches (error,
30925  G_MARKUP_ERROR,
30926  G_MARKUP_ERROR_INVALID_CONTENT))
30927  {
30928  if (current_error)
30929  {
30930  /* This is the return status for a forked child. */
30931  forked = 2; /* Prevent further forking. */
30932  g_error_free (error);
30933  return current_error;
30934  }
30935  g_debug (" client error: G_MARKUP_ERROR_INVALID_CONTENT\n");
30936  }
30937  else if (g_error_matches (error,
30938  G_MARKUP_ERROR,
30939  G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE))
30940  g_debug (" client error: G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE\n");
30941  else
30942  err = -1;
30943  g_info (" Failed to parse client XML: %s\n", error->message);
30944  g_error_free (error);
30945  }
30946  else
30947  err = -1;
30948  /* In all error cases the caller must cease to call this function as it
30949  * would be too hard, if possible at all, to figure out the position of
30950  * start of the next command. */
30951  return err;
30952  }
30954  if (forked)
30955  return 3;
30956  return 0;
30957 }
buffer_size_t from_client_start
The start of the data in the from_client buffer.
Definition: ompd.c:84
#define g_info(...)
Defines g_info for glib versions older than 2.40.
Definition: manage.h:55
int current_error
Hack for returning forked process status from the callbacks.
Definition: omp.c:4969
buffer_size_t from_client_end
The end of the data in the from_client buffer.
Definition: ompd.c:89
void manage_transaction_stop(gboolean)
Commit the current transaction, if any.
Definition: manage_sql.c:32976
int forked
Hack for returning fork status to caller.
Definition: omp.c:4974
char from_client[]
Buffer of input from the client.
Definition: ompd.c:74
Here is the call graph for this function:

Variable Documentation

◆ to_client

char to_client[]

Buffer of output to the client.

Todo:
As described in omp.c, probably should be replaced by omp_parser_t.

Definition at line 4979 of file omp.c.

◆ to_client_end

buffer_size_t to_client_end

The end of the data in the to_client buffer.

Definition at line 4988 of file omp.c.

◆ to_client_start

buffer_size_t to_client_start

The start of the data in the to_client buffer.

Definition at line 4984 of file omp.c.