OpenVAS Scanner
6.0.1
|
Network Functions. More...
#include "../nasl/nasl_debug.h"
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <glib.h>
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
#include <gvm/base/logging.h>
#include <gvm/base/networking.h>
#include <gvm/base/prefs.h>
#include <gvm/util/kb.h>
#include <gvm/util/serverutils.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include "network.h"
#include "plugutils.h"
#include "support.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 | G_LOG_DOMAIN "lib misc" |
GLib logging domain. More... | |
#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 | |
static void | renice_myself (void) |
static int | pid_perror (const char *error) |
int | stream_get_err (int fd) |
static int | get_connection_fd (void) |
Returns a free file descriptor. More... | |
static int | release_connection_fd (int fd, int already_closed) |
int | openvas_register_connection (int soc, void *ssl, gnutls_certificate_credentials_t certcred, openvas_encaps_t encaps) |
int | openvas_deregister_connection (int fd) |
static int | unblock_socket (int soc) |
static int | block_socket (int soc) |
void | tlserror (char *txt, int err) |
static void | log_message_gnutls (int level, const char *msg) |
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) |
static int | set_gnutls_protocol (gnutls_session_t session, openvas_encaps_t encaps, const char *priority) |
static int | load_cert_and_key (gnutls_certificate_credentials_t xcred, const char *cert, const char *key, const char *passwd) |
Loads a certificate and the corresponding private key from PEM files. More... | |
static int | is_ip_address (const char *str) |
static int | open_SSL_connection (openvas_connection *fp, const char *cert, const char *key, const char *passwd, const char *cafile, const char *hostname) |
int | socket_negotiate_ssl (int fd, openvas_encaps_t transport, struct script_infos *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_ciphersuite (int fd) |
int | open_stream_connection_ext (struct script_infos *args, unsigned int port, int transport, int timeout, const char *priority) |
int | open_stream_connection (struct script_infos *args, unsigned int port, int transport, int timeout) |
int | open_stream_auto_encaps_ext (struct script_infos *args, unsigned int port, int timeout, int force) |
int | stream_set_timeout (int fd, int timeout) |
static int | read_stream_connection_unbuffered (int fd, void *buf0, int min_len, int max_len) |
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) |
static int | write_stream_connection4 (int fd, void *buf0, int n, int i_opt) |
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... | |
static int | run_csc_hooks (int fd) |
Run the hooks 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) |
static int | open_socket (struct sockaddr *paddr, int type, int protocol, int timeout, int len) |
int | open_sock_opt_hn (const char *hostname, unsigned int port, int type, int protocol, int timeout) |
int | open_sock_tcp (struct script_infos *args, unsigned int port, int timeout) |
int | open_sock_option (struct script_infos *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 | 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 | get_sock_infos (int sock, int *r_transport, void **r_tls_session) |
static int | qsort_compar (const void *a, const void *b) |
unsigned short * | getpts (char *origexpr, int *len) |
Converts a string like "-100,200-1024,3000-4000,60000-" into an array. More... | |
Variables | |
static openvas_connection | connections [OPENVAS_FD_MAX] |
static struct csc_hook_s * | csc_hooks |
Linked list of hooks to be run by close_stream_connection. More... | |
static int | __port_closed |
Network Functions.
#define G_LOG_DOMAIN "lib misc" |
GLib logging domain.
#define INADDR_NONE 0xffffffff |
#define INCR_TIMEOUT 1 |
#define OPENVAS_FD_MAX 1024 |
The role of this offset is:
#define OPENVAS_FD_OFF 1000000 |
#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
#define OVAS_CONNECTION_FROM_FD | ( | fd | ) | (connections + ((fd) -OPENVAS_FD_OFF)) |
determine the openvas_connection* from the openvas fd
#define TIMEOUT 20 |
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. |
|
static |
int close_stream_connection | ( | int | fd | ) |
int fd_is_stream | ( | int | fd | ) |
|
static |
Returns a free file descriptor.
const char* get_encaps_name | ( | openvas_encaps_t | code | ) |
const char* get_encaps_through | ( | openvas_encaps_t | code | ) |
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.
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
|
static |
|
static |
Loads a certificate and the corresponding private key from PEM files.
The private key may be encrypted, in which case the password to decrypt the key should be given as the passwd parameter.
|
static |
int nrecv | ( | int | fd, |
void * | data, | ||
int | length, | ||
int | i_opt | ||
) |
int nsend | ( | int | fd, |
void * | data, | ||
int | length, | ||
int | i_opt | ||
) |
int open_sock_opt_hn | ( | const char * | hostname, |
unsigned int | port, | ||
int | type, | ||
int | protocol, | ||
int | timeout | ||
) |
int open_sock_option | ( | struct script_infos * | args, |
unsigned int | port, | ||
int | type, | ||
int | protocol, | ||
int | timeout | ||
) |
int open_sock_tcp | ( | struct script_infos * | args, |
unsigned int | port, | ||
int | timeout | ||
) |
|
static |
|
static |
int open_stream_auto_encaps_ext | ( | struct script_infos * | args, |
unsigned int | port, | ||
int | timeout, | ||
int | force | ||
) |
int open_stream_connection | ( | struct script_infos * | args, |
unsigned int | port, | ||
int | transport, | ||
int | timeout | ||
) |
int open_stream_connection_ext | ( | struct script_infos * | args, |
unsigned int | port, | ||
int | transport, | ||
int | timeout, | ||
const char * | priority | ||
) |
int openvas_deregister_connection | ( | int | fd | ) |
int openvas_get_socket_from_connection | ( | int | fd | ) |
int openvas_register_connection | ( | int | soc, |
void * | ssl, | ||
gnutls_certificate_credentials_t | certcred, | ||
openvas_encaps_t | encaps | ||
) |
int openvas_SSL_init | ( | void | ) |
Initializes SSL support.
int os_recv | ( | int | soc, |
void * | buf, | ||
int | len, | ||
int | opt | ||
) |
int os_send | ( | int | soc, |
void * | buf, | ||
int | len, | ||
int | opt | ||
) |
gnutls_session_t ovas_get_tlssession_from_connection | ( | int | fd | ) |
|
static |
Same as perror(), but prefixes the data by our pid.
|
static |
int read_stream_connection | ( | int | fd, |
void * | buf0, | ||
int | len | ||
) |
int read_stream_connection_min | ( | int | fd, |
void * | buf0, | ||
int | min_len, | ||
int | max_len | ||
) |
|
static |
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. |
|
static |
|
static |
|
static |
Run the hooks for close_stream_connection.
The function runs all registered hooks until the first hook returns with zero to indicate that it has taken over control of the socket. Further hooks are then not anymore run because the file descriptor is not anymore valid.
fd | The file descriptor of the stream. |
|
static |
Sets the priorities for the GnuTLS session according to encaps. PRIORITY is used to convey custom priorities; it is only used if ENCAPS is set to OPENVAS_ENCAPS_TLScustom.
int socket_close | ( | int | soc | ) |
void socket_get_cert | ( | int | fd, |
void ** | cert, | ||
int * | certlen | ||
) |
int socket_get_ssl_ciphersuite | ( | int | fd | ) |
void socket_get_ssl_session_id | ( | int | fd, |
void ** | sid, | ||
size_t * | ssize | ||
) |
int socket_get_ssl_version | ( | int | fd | ) |
int socket_negotiate_ssl | ( | int | fd, |
openvas_encaps_t | transport, | ||
struct script_infos * | args | ||
) |
int stream_get_buffer_sz | ( | int | fd | ) |
int stream_get_err | ( | int | fd | ) |
int stream_set_buffer | ( | int | fd, |
int | sz | ||
) |
int stream_set_timeout | ( | int | fd, |
int | timeout | ||
) |
void tlserror | ( | char * | txt, |
int | err | ||
) |
|
static |
int write_stream_connection | ( | int | fd, |
void * | buf0, | ||
int | n | ||
) |
|
static |
|
static |
|
static |
|
static |
Linked list of hooks to be run by close_stream_connection.