OpenVAS Libraries
9.0.3
|
#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"
Go to the source code of this file.
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_info * | host_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... | |
#define INCR_TIMEOUT 1 |
#define OPENVAS_FD_MAX 1024 |
#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
Definition at line 122 of file network.c.
Referenced by close_stream_connection(), fd_is_stream(), get_sock_infos(), nrecv(), nsend(), openvas_deregister_connection(), openvas_get_socket_from_connection(), ovas_get_tlssession_from_connection(), read_stream_connection_min(), recv_line(), stream_get_buffer_sz(), stream_get_err(), stream_set_buffer(), and stream_set_timeout().
#define OVAS_CONNECTION_FROM_FD | ( | fd | ) | (connections + ((fd) - OPENVAS_FD_OFF)) |
determine the openvas_connection* from the openvas fd
Definition at line 127 of file network.c.
Referenced by close_stream_connection(), read_stream_connection_min(), socket_negotiate_ssl(), stream_get_buffer_sz(), stream_get_err(), stream_set_buffer(), and stream_set_timeout().
#define TIMEOUT 20 |
Definition at line 58 of file network.c.
Referenced by open_stream_connection_ext().
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.
fnc | The hook function. See above for details. |
Definition at line 1660 of file network.c.
int close_stream_connection | ( | int | fd | ) |
Definition at line 1699 of file network.c.
References log_legacy_write(), OPENVAS_STREAM, OVAS_CONNECTION_FROM_FD, openvas_connection::port, and socket_close().
Referenced by nasl_end_denial(), and nasl_start_denial().
int fd_is_stream | ( | int | fd | ) |
Definition at line 2146 of file network.c.
References OPENVAS_STREAM.
Referenced by nasl_close_socket(), nasl_get_source_port(), nasl_recv(), nasl_recv_line(), nasl_send(), nasl_socket_get_error(), socket_get_cert(), socket_get_ssl_ciphersuite(), socket_get_ssl_compression(), socket_get_ssl_session_id(), socket_get_ssl_version(), and socket_negotiate_ssl().
const char* get_encaps_name | ( | openvas_encaps_t | code | ) |
Definition at line 1729 of file network.c.
References code, OPENVAS_ENCAPS_AUTO, OPENVAS_ENCAPS_IP, OPENVAS_ENCAPS_SSLv2, OPENVAS_ENCAPS_SSLv23, OPENVAS_ENCAPS_SSLv3, OPENVAS_ENCAPS_TLScustom, OPENVAS_ENCAPS_TLSv1, OPENVAS_ENCAPS_TLSv11, and OPENVAS_ENCAPS_TLSv12.
Referenced by get_port_transport(), and nasl_get_sock_info().
const char* get_encaps_through | ( | openvas_encaps_t | code | ) |
Definition at line 1759 of file network.c.
References code, OPENVAS_ENCAPS_IP, OPENVAS_ENCAPS_SSLv2, OPENVAS_ENCAPS_SSLv23, OPENVAS_ENCAPS_SSLv3, OPENVAS_ENCAPS_TLScustom, OPENVAS_ENCAPS_TLSv1, OPENVAS_ENCAPS_TLSv11, and OPENVAS_ENCAPS_TLSv12.
int get_sock_infos | ( | int | sock, |
int * | r_transport, | ||
void ** | r_tls_session | ||
) |
Definition at line 2376 of file network.c.
References OPENVAS_STREAM.
Referenced by nasl_get_sock_info().
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 and was taken from his excellent and outstanding scanner Nmap See r@dh p.comhttp://www.insecure.org/nmap/ for details about Nmap
Definition at line 2416 of file network.c.
Referenced by nasl_scanner_get_port(), and scan().
void host_info_free | ( | struct host_info * | hostinfo | ) |
Free a host_info struct.
[in] | hostinfo | Host info to free. |
Definition at line 2567 of file network.c.
References host_info::fqdn, host_info::ip, host_info::name, and host_info::vhosts.
struct host_info* host_info_init | ( | const char * | name, |
const struct in6_addr * | ip, | ||
const char * | vhosts, | ||
const char * | fqdn | ||
) |
Initializes a host_info.
[in] | name | Hostname. |
[in] | ip | IP address. |
[in] | vhosts | Vhosts list. |
[in] | fqdn | Fully qualified domain name. |
Definition at line 2544 of file network.c.
References host_info::fqdn, host_info::ip, host_info::name, name, and host_info::vhosts.
Referenced by init().
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.
[in] | soc | The socket from which to receive message. |
[out] | data | Where to allocate the reception buffer. Has to be set to NULL, and left untouched on failure or zero-length messages. |
[out] | data_sz | Size of the received message. |
[out] | msg_type | Type of the message which was received. |
Length | of the received message on success (can be zero). |
Negative | value on error. |
Definition at line 2318 of file network.c.
References INTERNAL_COMM_CTRL_ACK, INTERNAL_COMM_MSG_TYPE_CTRL, log_legacy_write(), os_recv(), and os_send().
int internal_send | ( | int | soc, |
char * | data, | ||
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.
Definition at line 2263 of file network.c.
References INTERNAL_COMM_MSG_TYPE_CTRL, log_legacy_write(), os_recv(), and os_send().
int nrecv | ( | int | fd, |
void * | data, | ||
int | length, | ||
int | i_opt | ||
) |
Definition at line 1618 of file network.c.
References log_legacy_write(), and OPENVAS_STREAM.
int nsend | ( | int | fd, |
void * | data, | ||
int | length, | ||
int | i_opt | ||
) |
Definition at line 1577 of file network.c.
References OPENVAS_STREAM.
Referenced by nasl_end_denial().
int open_sock_opt_hn | ( | const char * | hostname, |
unsigned int | port, | ||
int | type, | ||
int | protocol, | ||
int | timeout | ||
) |
Definition at line 1888 of file network.c.
References openvas_resolve_as_addr6().
Referenced by nasl_open_sock_kdc().
int open_sock_option | ( | struct arglist * | args, |
unsigned int | port, | ||
int | type, | ||
int | protocol, | ||
int | timeout | ||
) |
Definition at line 1960 of file network.c.
References arg_dump(), host_get_port_state(), log_legacy_write(), and plug_get_host_ip().
Referenced by open_sock_tcp().
int open_sock_tcp | ( | struct arglist * | args, |
unsigned int | port, | ||
int | timeout | ||
) |
Definition at line 1918 of file network.c.
References open_sock_option(), plug_get_host_ip_str(), plug_get_kb(), and prefs_get().
Referenced by ids_open_sock_tcp().
int open_stream_auto_encaps_ext | ( | struct arglist * | args, |
unsigned int | port, | ||
int | timeout, | ||
int | force | ||
) |
Definition at line 1127 of file network.c.
References open_stream_connection(), OPENVAS_ENCAPS_IP, OPENVAS_ENCAPS_TLScustom, plug_get_port_transport(), and plug_set_port_transport().
int open_stream_connection | ( | struct arglist * | args, |
unsigned int | port, | ||
int | transport, | ||
int | timeout | ||
) |
Definition at line 1117 of file network.c.
References open_stream_connection_ext().
Referenced by nasl_end_denial(), nasl_start_denial(), and open_stream_auto_encaps_ext().
int open_stream_connection_ext | ( | struct arglist * | args, |
unsigned int | port, | ||
int | transport, | ||
int | timeout, | ||
const char * | priority | ||
) |
Definition at line 1004 of file network.c.
References log_legacy_write(), OPENVAS_ENCAPS_IP, OPENVAS_ENCAPS_SSLv2, OPENVAS_ENCAPS_SSLv23, OPENVAS_ENCAPS_SSLv3, OPENVAS_ENCAPS_TLScustom, OPENVAS_ENCAPS_TLSv1, OPENVAS_ENCAPS_TLSv11, OPENVAS_ENCAPS_TLSv12, and TIMEOUT.
Referenced by open_stream_connection().
int openvas_deregister_connection | ( | int | fd | ) |
int openvas_get_socket_from_connection | ( | int | fd | ) |
Definition at line 395 of file network.c.
References log_legacy_fflush(), log_legacy_write(), and OPENVAS_STREAM.
Referenced by nasl_get_source_port(), and stream_set().
int openvas_register_connection | ( | int | soc, |
void * | ssl, | ||
gnutls_certificate_credentials_t | certcred, | ||
openvas_encaps_t | encaps | ||
) |
soc | Socket to use. |
Definition at line 267 of file network.c.
int openvas_SSL_init | ( | void | ) |
Initializes SSL support.
Definition at line 376 of file network.c.
References tlserror().
int os_recv | ( | int | soc, |
void * | buf, | ||
int | len, | ||
int | opt | ||
) |
Definition at line 2233 of file network.c.
Referenced by internal_recv(), and internal_send().
int os_send | ( | int | soc, |
void * | buf, | ||
int | len, | ||
int | opt | ||
) |
Definition at line 2214 of file network.c.
Referenced by internal_recv(), and internal_send().
gnutls_session_t ovas_get_tlssession_from_connection | ( | int | fd | ) |
Definition at line 418 of file network.c.
References OPENVAS_STREAM.
Referenced by socket_get_cert(), socket_get_ssl_ciphersuite(), socket_get_ssl_compression(), socket_get_ssl_session_id(), and socket_get_ssl_version().
int read_stream_connection | ( | int | fd, |
void * | buf0, | ||
int | len | ||
) |
Definition at line 1421 of file network.c.
References read_stream_connection_min().
Referenced by nasl_telnet_init().
int read_stream_connection_min | ( | int | fd, |
void * | buf0, | ||
int | min_len, | ||
int | max_len | ||
) |
Definition at line 1360 of file network.c.
References openvas_connection::buf, openvas_connection::bufcnt, openvas_connection::bufptr, openvas_connection::bufsz, OPENVAS_STREAM, and OVAS_CONNECTION_FROM_FD.
Referenced by nasl_recv_line(), nasl_telnet_init(), read_stream_connection(), and 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.
buf | Buffer to read into. |
Definition at line 2017 of file network.c.
References OPENVAS_STREAM, and read_stream_connection_min().
Referenced by ftp_get_pasv_address().
int socket_close | ( | int | soc | ) |
Definition at line 2120 of file network.c.
Referenced by close_stream_connection().
void socket_get_cert | ( | int | fd, |
void ** | cert, | ||
int * | certlen | ||
) |
Definition at line 813 of file network.c.
References fd_is_stream(), log_legacy_write(), and ovas_get_tlssession_from_connection().
Referenced by nasl_socket_get_cert().
int socket_get_ssl_ciphersuite | ( | int | fd | ) |
Definition at line 965 of file network.c.
References fd_is_stream(), log_legacy_write(), and ovas_get_tlssession_from_connection().
Referenced by nasl_socket_get_ssl_ciphersuite().
int socket_get_ssl_compression | ( | int | fd | ) |
Definition at line 930 of file network.c.
References fd_is_stream(), log_legacy_write(), and ovas_get_tlssession_from_connection().
Referenced by nasl_socket_get_ssl_compression().
void socket_get_ssl_session_id | ( | int | fd, |
void ** | sid, | ||
size_t * | ssize | ||
) |
Definition at line 890 of file network.c.
References fd_is_stream(), log_legacy_write(), ovas_get_tlssession_from_connection(), and tlserror().
Referenced by nasl_socket_get_ssl_session_id().
int socket_get_ssl_version | ( | int | fd | ) |
Definition at line 849 of file network.c.
References fd_is_stream(), log_legacy_write(), OPENVAS_ENCAPS_SSLv3, OPENVAS_ENCAPS_TLSv1, OPENVAS_ENCAPS_TLSv11, OPENVAS_ENCAPS_TLSv12, and ovas_get_tlssession_from_connection().
Referenced by nasl_socket_get_ssl_version().
int socket_negotiate_ssl | ( | int | fd, |
openvas_encaps_t | transport, | ||
struct arglist * | args | ||
) |
Definition at line 771 of file network.c.
References fd_is_stream(), log_legacy_write(), OVAS_CONNECTION_FROM_FD, and plug_get_kb().
Referenced by nasl_socket_negotiate_ssl().
int stream_get_buffer_sz | ( | int | fd | ) |
Definition at line 2153 of file network.c.
References openvas_connection::bufsz, OPENVAS_STREAM, and OVAS_CONNECTION_FROM_FD.
Referenced by nasl_recv_line().
int stream_get_err | ( | int | fd | ) |
Definition at line 161 of file network.c.
References openvas_connection::last_err, OPENVAS_STREAM, and OVAS_CONNECTION_FROM_FD.
Referenced by nasl_socket_get_error().
int stream_set | ( | int | fd, |
fd_set * | set | ||
) |
Definition at line 2137 of file network.c.
References openvas_get_socket_from_connection().
int stream_set_buffer | ( | int | fd, |
int | sz | ||
) |
Definition at line 2163 of file network.c.
References openvas_connection::buf, openvas_connection::bufcnt, openvas_connection::bufptr, openvas_connection::bufsz, OPENVAS_STREAM, and OVAS_CONNECTION_FROM_FD.
Referenced by nasl_recv_line().
int stream_set_timeout | ( | int | fd, |
int | timeout | ||
) |
Definition at line 1158 of file network.c.
References OPENVAS_STREAM, OVAS_CONNECTION_FROM_FD, and openvas_connection::timeout.
int stream_zero | ( | fd_set * | set | ) |
void tlserror | ( | char * | txt, |
int | err | ||
) |
Definition at line 359 of file network.c.
References err, and log_legacy_write().
Referenced by openvas_SSL_init(), and socket_get_ssl_session_id().
int write_stream_connection | ( | int | fd, |
void * | buf0, | ||
int | n | ||
) |
Definition at line 1571 of file network.c.
Referenced by ftp_get_pasv_address(), and nasl_telnet_init().