Greenbone Vulnerability Manager  22.4.0~dev1
Macros | Functions | Variables
gmpd.c File Reference

The Greenbone Vulnerability Manager GMP daemon. More...

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

Macros

#define G_LOG_DOMAIN   "md main"
 GLib log domain.
 

Functions

int init_gmpd (GSList *log_config, const db_conn_info_t *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 db_conn_info_t *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 int get_nfds (int socket)
 Get nfds value. More...
 
int serve_gmp (gvm_connection_t *client_connection, const db_conn_info_t *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.
 
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.
 

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.

Function Documentation

◆ get_nfds()

static int get_nfds ( int  socket)
static

Get nfds value.

Parameters
[in]socketHighest socket number.
Returns
nfds value for select.

◆ 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,
const db_conn_info_t 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]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 db_conn_info_t 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 db_conn_info_t 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. Process the input with process_gmp_client_input. Write the results to the client.

Parameters
[in]client_connectionConnection.
[in]databaseLocation of manage database.
[in]disableCommands to disable.
Returns
0 success, -1 error.
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).

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