OpenVAS Libraries  9.0.1
Data Structures | Macros | Functions
network.c File Reference
#include <errno.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdarg.h>
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>
#include <signal.h>
#include <stdio.h>
#include <sys/time.h>
#include <glib.h>
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
#include "network.h"
#include "../base/kb.h"
#include "ids_send.h"
#include "prefs.h"
#include "plugutils.h"
#include "internal_com.h"
#include "support.h"
#include "openvas_logging.h"
#include "openvas_server.h"

Data Structures

struct  openvas_connection
 
struct  csc_hook_s
 Object to store a list of hooks for close_stream_connection. More...
 

Macros

#define TIMEOUT   20
 
#define INADDR_NONE   0xffffffff
 
#define OPENVAS_FD_MAX   1024
 
#define OPENVAS_FD_OFF   1000000
 
#define OPENVAS_STREAM(x)   (((x - OPENVAS_FD_OFF) < OPENVAS_FD_MAX) && ((x - OPENVAS_FD_OFF) >=0))
 
#define OVAS_CONNECTION_FROM_FD(fd)   (connections + ((fd) - OPENVAS_FD_OFF))
 
#define INCR_TIMEOUT   1
 

Functions

int stream_get_err (int fd)
 
int openvas_register_connection (int soc, void *ssl, gnutls_certificate_credentials_t certcred, openvas_encaps_t encaps)
 
int openvas_deregister_connection (int fd)
 
void tlserror (char *txt, int err)
 
int openvas_SSL_init ()
 Initializes SSL support. More...
 
int openvas_get_socket_from_connection (int fd)
 
gnutls_session_t ovas_get_tlssession_from_connection (int fd)
 
int socket_negotiate_ssl (int fd, openvas_encaps_t transport, struct arglist *args)
 
void socket_get_cert (int fd, void **cert, int *certlen)
 
int socket_get_ssl_version (int fd)
 
void socket_get_ssl_session_id (int fd, void **sid, size_t *ssize)
 
int socket_get_ssl_compression (int fd)
 
int socket_get_ssl_ciphersuite (int fd)
 
int open_stream_connection_ext (struct arglist *args, unsigned int port, int transport, int timeout, const char *priority)
 
int open_stream_connection (struct arglist *args, unsigned int port, int transport, int timeout)
 
int open_stream_auto_encaps_ext (struct arglist *args, unsigned int port, int timeout, int force)
 
int stream_set_timeout (int fd, int timeout)
 
int read_stream_connection_min (int fd, void *buf0, int min_len, int max_len)
 
int read_stream_connection (int fd, void *buf0, int len)
 
int write_stream_connection (int fd, void *buf0, int n)
 
int nsend (int fd, void *data, int length, int i_opt)
 
int nrecv (int fd, void *data, int length, int i_opt)
 
void add_close_stream_connection_hook (int(*fnc)(int fd))
 Register a hook function for close_stream_connection. More...
 
int close_stream_connection (int fd)
 
const char * get_encaps_name (openvas_encaps_t code)
 
const char * get_encaps_through (openvas_encaps_t code)
 
int open_sock_opt_hn (const char *hostname, unsigned int port, int type, int protocol, int timeout)
 
int open_sock_tcp (struct arglist *args, unsigned int port, int timeout)
 
int open_sock_option (struct arglist *args, unsigned int port, int type, int protocol, int timeout)
 
int recv_line (int soc, char *buf, size_t bufsiz)
 Reads a text from the socket stream into the argument buffer, always. More...
 
int socket_close (int soc)
 
int stream_zero (fd_set *set)
 
int stream_set (int fd, fd_set *set)
 
int fd_is_stream (int fd)
 
int stream_get_buffer_sz (int fd)
 
int stream_set_buffer (int fd, int sz)
 
int os_send (int soc, void *buf, int len, int opt)
 
int os_recv (int soc, void *buf, int len, int opt)
 
int internal_send (int soc, char *data, int msg_type)
 
int internal_recv (int soc, char **data, int *data_sz, int *msg_type)
 
int get_sock_infos (int sock, int *r_transport, void **r_tls_session)
 
unsigned short * getpts (char *origexpr, int *len)
 Converts a string like "-100,200-1024,3000-4000,60000-" into an array. More...
 
struct host_infohost_info_init (const char *name, const struct in6_addr *ip, const char *vhosts, const char *fqdn)
 Initializes a host_info. More...
 
void host_info_free (struct host_info *hostinfo)
 Free a host_info struct. More...
 

Macro Definition Documentation

◆ INADDR_NONE

#define INADDR_NONE   0xffffffff

◆ INCR_TIMEOUT

#define INCR_TIMEOUT   1

◆ OPENVAS_FD_MAX

#define OPENVAS_FD_MAX   1024

The role of this offset is:

  1. To detect bugs when the program tries to write to a bad fd
  2. See if a fd is a real socket or a "openvas descriptor". This is a quick & dirty hack and should be changed!!!

◆ OPENVAS_FD_OFF

#define OPENVAS_FD_OFF   1000000

◆ OPENVAS_STREAM

#define OPENVAS_STREAM (   x)    (((x - OPENVAS_FD_OFF) < OPENVAS_FD_MAX) && ((x - OPENVAS_FD_OFF) >=0))

OPENVAS_STREAM(x) is TRUE if <x> is a OpenVAS-ified fd

◆ OVAS_CONNECTION_FROM_FD

#define OVAS_CONNECTION_FROM_FD (   fd)    (connections + ((fd) - OPENVAS_FD_OFF))

determine the openvas_connection* from the openvas fd

◆ TIMEOUT

#define TIMEOUT   20

Function Documentation

◆ add_close_stream_connection_hook()

void add_close_stream_connection_hook ( int(*)(int fd)  fnc)

Register a hook function for close_stream_connection.

The function adds the given hook function to the list of hooks to be run by close_stream_connection. These hooks are intended to test whether they need to close the stream them self. See argument to the hook function is the file descriptor of the stream. The hook shall return 0 if it has taken over control of that file descriptor. The same function is only aded once to the list of hooks.

Parameters
fncThe hook function. See above for details.

◆ close_stream_connection()

int close_stream_connection ( int  fd)

◆ fd_is_stream()

int fd_is_stream ( int  fd)

◆ get_encaps_name()

const char* get_encaps_name ( openvas_encaps_t  code)

◆ get_encaps_through()

const char* get_encaps_through ( openvas_encaps_t  code)

◆ get_sock_infos()

int get_sock_infos ( int  sock,
int *  r_transport,
void **  r_tls_session 
)

◆ getpts()

unsigned short* getpts ( char *  origexpr,
int *  len 
)

Converts a string like "-100,200-1024,3000-4000,60000-" into an array.

of port numbers

This function is (c) Fyodor fyodo.nosp@m.r@dh.nosp@m.p.com and was taken from his excellent and outstanding scanner Nmap See http://www.insecure.org/nmap/ for details about Nmap

◆ host_info_free()

void host_info_free ( struct host_info hostinfo)

Free a host_info struct.

Parameters
[in]hostinfoHost info to free.

◆ host_info_init()

struct host_info* host_info_init ( const char *  name,
const struct in6_addr *  ip,
const char *  vhosts,
const char *  fqdn 
)

Initializes a host_info.

Parameters
[in]nameHostname.
[in]ipIP address.
[in]vhostsVhosts list.
[in]fqdnFully qualified domain name.
Returns
host_info pointer.

◆ internal_recv()

int internal_recv ( int  soc,
char **  data,
int *  data_sz,
int *  msg_type 
)

internal_send() / internal_recv() :

When processes are passing messages to each other, the format is <length><msg>, with <length> being a long integer. The functions internal_send() and internal_recv() encapsulate and decapsulate the messages themselves.

Parameters
[in]socThe socket from which to receive message.
[out]dataWhere to allocate the reception buffer. Has to be set to NULL, and left untouched on failure or zero-length messages.
[out]data_szSize of the received message.
[out]msg_typeType of the message which was received.
Return values
Lengthof the received message on success (can be zero).
Negativevalue on error.

◆ internal_send()

int internal_send ( int  soc,
char *  data,
int  msg_type 
)
Todo:
internal_send and internal_recv. could make an own module (ipc), in which the type constants could be moved, too.

internal_send() / internal_recv() :

When processes are passing messages to each other, the format is <length><msg>, with <length> being a long integer. The functions internal_send() and internal_recv() encapsulate and decapsulate the messages themselves.

◆ nrecv()

int nrecv ( int  fd,
void *  data,
int  length,
int  i_opt 
)

◆ nsend()

int nsend ( int  fd,
void *  data,
int  length,
int  i_opt 
)

◆ open_sock_opt_hn()

int open_sock_opt_hn ( const char *  hostname,
unsigned int  port,
int  type,
int  protocol,
int  timeout 
)

◆ open_sock_option()

int open_sock_option ( struct arglist args,
unsigned int  port,
int  type,
int  protocol,
int  timeout 
)

◆ open_sock_tcp()

int open_sock_tcp ( struct arglist args,
unsigned int  port,
int  timeout 
)

◆ open_stream_auto_encaps_ext()

int open_stream_auto_encaps_ext ( struct arglist args,
unsigned int  port,
int  timeout,
int  force 
)

◆ open_stream_connection()

int open_stream_connection ( struct arglist args,
unsigned int  port,
int  transport,
int  timeout 
)

◆ open_stream_connection_ext()

int open_stream_connection_ext ( struct arglist args,
unsigned int  port,
int  transport,
int  timeout,
const char *  priority 
)

◆ openvas_deregister_connection()

int openvas_deregister_connection ( int  fd)

◆ openvas_get_socket_from_connection()

int openvas_get_socket_from_connection ( int  fd)

◆ openvas_register_connection()

int openvas_register_connection ( int  soc,
void *  ssl,
gnutls_certificate_credentials_t  certcred,
openvas_encaps_t  encaps 
)
Todo:
TLS FIXME: migrate this to TLS
Todo:
Fix the voidness of the ssl parameter (problematic in 64bit env.) here or on caller-side
Parameters
socSocket to use.

◆ openvas_SSL_init()

int openvas_SSL_init ( void  )

Initializes SSL support.

◆ os_recv()

int os_recv ( int  soc,
void *  buf,
int  len,
int  opt 
)

◆ os_send()

int os_send ( int  soc,
void *  buf,
int  len,
int  opt 
)

◆ ovas_get_tlssession_from_connection()

gnutls_session_t ovas_get_tlssession_from_connection ( int  fd)

◆ read_stream_connection()

int read_stream_connection ( int  fd,
void *  buf0,
int  len 
)

◆ read_stream_connection_min()

int read_stream_connection_min ( int  fd,
void *  buf0,
int  min_len,
int  max_len 
)

◆ recv_line()

int recv_line ( int  soc,
char *  buf,
size_t  bufsiz 
)

Reads a text from the socket stream into the argument buffer, always.

appending a '\0' byte.

Parameters
bufBuffer to read into.
Returns
Number of bytes read, without the trailing '\0'.

◆ socket_close()

int socket_close ( int  soc)

◆ socket_get_cert()

void socket_get_cert ( int  fd,
void **  cert,
int *  certlen 
)

◆ socket_get_ssl_ciphersuite()

int socket_get_ssl_ciphersuite ( int  fd)

◆ socket_get_ssl_compression()

int socket_get_ssl_compression ( int  fd)

◆ socket_get_ssl_session_id()

void socket_get_ssl_session_id ( int  fd,
void **  sid,
size_t *  ssize 
)

◆ socket_get_ssl_version()

int socket_get_ssl_version ( int  fd)

◆ socket_negotiate_ssl()

int socket_negotiate_ssl ( int  fd,
openvas_encaps_t  transport,
struct arglist args 
)

◆ stream_get_buffer_sz()

int stream_get_buffer_sz ( int  fd)

◆ stream_get_err()

int stream_get_err ( int  fd)

◆ stream_set()

int stream_set ( int  fd,
fd_set *  set 
)

◆ stream_set_buffer()

int stream_set_buffer ( int  fd,
int  sz 
)

◆ stream_set_timeout()

int stream_set_timeout ( int  fd,
int  timeout 
)

◆ stream_zero()

int stream_zero ( fd_set *  set)

◆ tlserror()

void tlserror ( char *  txt,
int  err 
)

◆ write_stream_connection()

int write_stream_connection ( int  fd,
void *  buf0,
int  n 
)