Greenbone Vulnerability Manager  8.0.0~git
Macros | Functions | Variables
gmpd.c File Reference

The Greenbone Vulnerability Manager GMP daemon. More...

#include "gmpd.h"
#include "gmp.h"
#include "scanner.h"
#include "comm.h"
#include "otp.h"
#include <assert.h>
#include <dirent.h>
#include <errno.h>
#include <gvm/util/serverutils.h>
#include <string.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

Macros

#define G_LOG_DOMAIN   "md main"
 GLib log domain. More...
 

Functions

int init_gmpd (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, manage_connection_forker_t fork_connection, int skip_db_check)
 Initialise the GMP library for the GMP daemon. More...
 
void init_gmpd_process (const gchar *database, gchar **disable)
 Initialise a process forked within the GMP daemon. More...
 
static int read_from_client_unix (int client_socket)
 Read as much from the client as the from_client buffer will hold. More...
 
static int read_from_client_tls (gnutls_session_t *client_session)
 Read as much from the client as the from_client buffer will hold. More...
 
static int read_from_client (gvm_connection_t *client_connection)
 Read as much from the client as the from_client buffer will hold. More...
 
static int write_to_client_tls (gnutls_session_t *client_session)
 Write as much as possible from to_client to the client. More...
 
static int write_to_client_unix (int client_socket)
 Write as much as possible from to_client to the client. More...
 
static int write_to_client (gvm_connection_t *client_connection)
 Write as much as possible from to_client to the client. More...
 
static gboolean gmpd_send_to_client (const char *msg, void *write_to_client_data)
 Send a response message to the client. More...
 
static void session_clean (gvm_connection_t *client_connection)
 Clean session. More...
 
int serve_gmp (gvm_connection_t *client_connection, const gchar *database, gchar **disable)
 Serve the Greenbone Management Protocol (GMP). More...
 

Variables

char from_client [FROM_BUFFER_SIZE]
 Buffer of input from the client. More...
 
buffer_size_t from_buffer_size = FROM_BUFFER_SIZE
 Size of from_client data buffer, in bytes. More...
 
buffer_size_t from_client_start = 0
 The start of the data in the from_client buffer.
 
buffer_size_t from_client_end = 0
 The end of the data in the from_client buffer.
 
static int gmpd_nvt_cache_mode = 0
 Flag for running in NVT cache mode.
 

Detailed Description

The Greenbone Vulnerability Manager GMP daemon.

This file defines the Greenbone Vulnerability Manager daemon. The Manager serves the Greenbone Management Protocol (GMP) to clients such as the Greenbone Security Assistant (GSA). The Manager and GMP give clients full access to an OpenVAS Scanner.

The library provides two functions: init_gmpd and serve_gmp. init_gmpd initialises the daemon. serve_gmp serves GMP to a single client socket until end of file is reached on the socket.

Macro Definition Documentation

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "md main"

GLib log domain.

Todo:
For scanner_init_state.

Function Documentation

◆ gmpd_send_to_client()

static gboolean gmpd_send_to_client ( const char *  msg,
void *  write_to_client_data 
)
static

Send a response message to the client.

Queue a message in to_client.

Parameters
[in]msgThe message, a string.
[in]write_to_client_dataArgument to write_to_client.
Returns
TRUE if write to client failed, else FALSE.

◆ init_gmpd()

int init_gmpd ( 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,
manage_connection_forker_t  fork_connection,
int  skip_db_check 
)

Initialise the GMP library for the GMP daemon.

Parameters
[in]log_configLog configuration
[in]nvt_cache_mode0 operate normally, -1 just update NVT cache.
[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]fork_connectionFunction to fork a connection to the GMP daemon layer, or NULL.
[in]skip_db_checkSkip DB check.
Returns
0 success, -1 error, -2 database is wrong version, -4 max_ips_per_target out of range.

◆ init_gmpd_process()

void init_gmpd_process ( const gchar *  database,
gchar **  disable 
)

Initialise a process forked within the GMP daemon.

Parameters
[in]databaseLocation of manage database.
[in]disableCommands to disable.

◆ read_from_client()

static int read_from_client ( gvm_connection_t *  client_connection)
static

Read as much from the client as the from_client buffer will hold.

Parameters
[in]client_connectionThe connection with the client.
Returns
0 on reading everything available, -1 on error, -2 if from_client buffer is full or -3 on reaching end of file.

◆ read_from_client_tls()

static int read_from_client_tls ( gnutls_session_t *  client_session)
static

Read as much from the client as the from_client buffer will hold.

Parameters
[in]client_sessionThe TLS session with the client.
Returns
0 on reading everything available, -1 on error, -2 if from_client buffer is full or -3 on reaching end of file.
Todo:
Rehandshake.

◆ read_from_client_unix()

static int read_from_client_unix ( int  client_socket)
static

Read as much from the client as the from_client buffer will hold.

Parameters
[in]client_socketThe socket.
Returns
0 on reading everything available, -1 on error, -2 if from_client buffer is full or -3 on reaching end of file.

◆ serve_gmp()

int serve_gmp ( gvm_connection_t *  client_connection,
const gchar *  database,
gchar **  disable 
)

Serve the Greenbone Management Protocol (GMP).

Loop reading input from the sockets, processing the input, and writing any results to the appropriate socket. Exit the loop on reaching end of file on the client socket.

Read input from the client and scanner. Process the input with process_gmp_client_input and process_otp_scanner_input. Write the results to the client.

If client socket is 0 or less, then update the NVT cache and exit.

Parameters
[in]client_connectionConnection.
[in]databaseLocation of manage database.
[in]disableCommands to disable.
Returns
0 success, 1 scanner still loading, -1 error, -2 scanner has no cert.
Todo:
Confirm and clarify complications, especially last one.
Todo:
nfds must only include a socket if it's in >= one set.
Todo:
Shutdown on failure (for example, if a read fails).
Todo:
Then should get EOF (-3).
Todo:
This may be because the scanner closed the connection at the end of a command?

◆ session_clean()

static void session_clean ( gvm_connection_t *  client_connection)
static

Clean session.

Parameters
[in]client_connectionConnection.

◆ write_to_client()

static int write_to_client ( gvm_connection_t *  client_connection)
static

Write as much as possible from to_client to the client.

Parameters
[in]client_connectionThe client connection.
Returns
0 wrote everything, -1 error, -2 wrote as much as client accepted.

◆ write_to_client_tls()

static int write_to_client_tls ( gnutls_session_t *  client_session)
static

Write as much as possible from to_client to the client.

Todo:
Move to openvas-libraries?
Parameters
[in]client_sessionThe client session.
Returns
0 wrote everything, -1 error, -2 wrote as much as client accepted.
Todo:
Rehandshake.

◆ write_to_client_unix()

static int write_to_client_unix ( int  client_socket)
static

Write as much as possible from to_client to the client.

Parameters
[in]client_socketThe client socket.
Returns
0 wrote everything, -1 error, -2 wrote as much as client accepted.

Variable Documentation

◆ from_buffer_size

buffer_size_t from_buffer_size = FROM_BUFFER_SIZE

Size of from_client data buffer, in bytes.

Todo:
As with the GMP version, this should most likely be passed to and from the client in a data structure like an otp_parser_t.

◆ from_client

char from_client[FROM_BUFFER_SIZE]

Buffer of input from the client.

Todo:
Most likely the client should get these from init_gmp_process inside an gmp_parser_t and should pass the gmp_parser_t to process_gmp_client_input. process_gmp_client_input can pass then pass them on to the other Manager "libraries".