OpenVAS Libraries  9.0.1
network.h
Go to the documentation of this file.
1 /* OpenVAS
2  * $Id$
3  * Description: Header file for module network.
4  *
5  * Authors:
6  * Renaud Deraison <deraison@nessus.org> (Original pre-fork development)
7  *
8  * Copyright:
9  * Based on work Copyright (C) 1998 - 2007 Tenable Network Security, Inc.
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25 
26 #ifndef OPENVAS_NETWORK_H
27 #define OPENVAS_NETWORK_H
28 
29 #include <sys/select.h> /* at least for fd_set */
30 #include <netinet/in.h> /* struct in_addr, struct in6_addr */
31 
32 #include <gnutls/gnutls.h>
33 #include <gnutls/x509.h>
34 
35 #include "arglists.h"
36 #include "../base/openvas_networking.h"
37 
38 /*
39  * Type of "transport layer", for encapsulated connections
40  * Only SSL is supported at this time.
41  * (Bad) examples of other layers could be SOCKS, httptunnel, icmptunnel,
42  * RMI over HTTP, DCOM over HTTP, TCP over TCP, etc.
43  */
44 typedef enum openvas_encaps {
45  OPENVAS_ENCAPS_AUTO = 0, /* Request auto detection. */
47  OPENVAS_ENCAPS_SSLv23, /* Ask for compatibility options */
53  OPENVAS_ENCAPS_TLScustom, /* SSL/TLS using custom priorities. */
56 
57 struct host_info {
58  char *name; /* Hostname. */
59  char *fqdn; /* Fully qualified domain name, e.g. host.domain.net */
60  char *vhosts; /* Comma separated list of vhosts */
61  struct in6_addr *ip; /* IP address. */
62 };
63 
64 #define IS_ENCAPS_SSL(x) ((x) >= OPENVAS_ENCAPS_SSLv23 && (x) <= OPENVAS_ENCAPS_TLScustom)
65 
66 /* Plugin specific network functions */
67 int open_sock_tcp (struct arglist *, unsigned int, int);
68 int open_sock_option (struct arglist *, unsigned int, int, int, int);
69 int recv_line (int, char *, size_t);
70 int nrecv (int, void *, int, int);
71 int socket_close (int);
72 int get_sock_infos (int sock, int *r_transport, void **r_tls_session);
73 unsigned short *getpts (char *, int *);
74 
75 int open_stream_connection (struct arglist *, unsigned int, int, int);
76 int open_stream_connection_ext (struct arglist *, unsigned int, int, int,
77  const char *);
78 int open_stream_auto_encaps_ext (struct arglist *args, unsigned int port,
79  int timeout, int force);
80 
81 int write_stream_connection (int, void *buf, int n);
82 int read_stream_connection (int, void *, int);
83 int read_stream_connection_min (int, void *, int, int);
84 int nsend (int, void *, int, int);
85 void add_close_stream_connection_hook (int (*)(int));
86 int close_stream_connection (int);
87 
88 const char *get_encaps_name (openvas_encaps_t);
90 
91 /* Additional functions -- should not be used by the plugins */
92 int open_sock_opt_hn (const char *, unsigned int, int, int, int);
93 
94 struct host_info *
95 host_info_init (const char *name, const struct in6_addr *,
96  const char *, const char *);
97 
98 void
99 host_info_free (struct host_info *);
100 
101 int openvas_SSL_init (void);
102 
103 int stream_set_buffer (int, int);
104 int stream_get_buffer_sz (int);
105 int stream_get_err (int);
106 
107 int openvas_register_connection (int s, void *ssl,
108  gnutls_certificate_credentials_t certcred,
109  openvas_encaps_t encaps);
112 gnutls_session_t ovas_get_tlssession_from_connection (int);
113 
114 int stream_zero (fd_set *);
115 int stream_set (int, fd_set *);
116 
117 int os_send (int, void *, int, int);
118 int os_recv (int, void *, int, int);
119 
120 int internal_send (int, char *, int);
121 int internal_recv (int, char **, int *, int *);
122 
123 int fd_is_stream (int);
124 
125 int stream_set_timeout (int, int);
126 
127 int socket_negotiate_ssl (int, openvas_encaps_t, struct arglist *);
128 void socket_get_cert (int, void **, int *);
129 int socket_get_ssl_version (int);
130 void socket_get_ssl_session_id (int, void **, size_t *);
133 
134 #endif
int socket_close(int)
Definition: network.c:2130
int open_sock_option(struct arglist *, unsigned int, int, int, int)
Definition: network.c:1965
int read_stream_connection(int, void *, int)
Definition: network.c:1425
int openvas_register_connection(int s, void *ssl, gnutls_certificate_credentials_t certcred, openvas_encaps_t encaps)
Definition: network.c:267
const char * get_encaps_through(openvas_encaps_t)
Definition: network.c:1763
int internal_recv(int, char **, int *, int *)
Definition: network.c:2328
unsigned short * getpts(char *, int *)
Converts a string like "-100,200-1024,3000-4000,60000-" into an array.
Definition: network.c:2426
int stream_zero(fd_set *)
Definition: network.c:2140
int read_stream_connection_min(int, void *, int, int)
Definition: network.c:1364
int recv_line(int, char *, size_t)
Reads a text from the socket stream into the argument buffer, always.
Definition: network.c:2022
int stream_get_err(int)
Definition: network.c:161
Definition: network.h:50
Definition: network.h:47
enum openvas_encaps openvas_encaps_t
struct host_info * host_info_init(const char *name, const struct in6_addr *, const char *, const char *)
Initializes a host_info.
Definition: network.c:2554
int stream_set_buffer(int, int)
Definition: network.c:2173
int nrecv(int, void *, int, int)
Definition: network.c:1622
Definition: network.h:52
int open_stream_auto_encaps_ext(struct arglist *args, unsigned int port, int timeout, int force)
Definition: network.c:1131
char * vhosts
Definition: network.h:60
int get_sock_infos(int sock, int *r_transport, void **r_tls_session)
Definition: network.c:2386
gnutls_session_t ovas_get_tlssession_from_connection(int)
Definition: network.c:418
int close_stream_connection(int)
Definition: network.c:1703
Definition: network.h:51
int open_stream_connection_ext(struct arglist *, unsigned int, int, int, const char *)
Definition: network.c:1009
int openvas_SSL_init(void)
Initializes SSL support.
Definition: network.c:376
char * name
Definition: network.h:58
int socket_negotiate_ssl(int, openvas_encaps_t, struct arglist *)
Definition: network.c:776
struct in6_addr * ip
Definition: network.h:61
int os_send(int, void *, int, int)
Definition: network.c:2224
void socket_get_cert(int, void **, int *)
Definition: network.c:818
Definition: network.h:54
int socket_get_ssl_version(int)
Definition: network.c:854
int open_sock_tcp(struct arglist *, unsigned int, int)
Definition: network.c:1923
openvas_encaps
Definition: network.h:44
int open_sock_opt_hn(const char *, unsigned int, int, int, int)
Definition: network.c:1893
void host_info_free(struct host_info *)
Free a host_info struct.
Definition: network.c:2577
Definition: arglists.h:29
int open_stream_connection(struct arglist *, unsigned int, int, int)
Definition: network.c:1122
int stream_set(int, fd_set *)
Definition: network.c:2147
int internal_send(int, char *, int)
Definition: network.c:2273
Definition: network.h:57
Definition: network.h:46
const char * get_encaps_name(openvas_encaps_t)
Definition: network.c:1733
int socket_get_ssl_ciphersuite(int)
Definition: network.c:970
int write_stream_connection(int, void *buf, int n)
Definition: network.c:1575
void socket_get_ssl_session_id(int, void **, size_t *)
Definition: network.c:895
Definition: network.h:48
Definition: network.h:49
int openvas_deregister_connection(int)
Definition: network.c:292
int nsend(int, void *, int, int)
Definition: network.c:1581
int openvas_get_socket_from_connection(int)
Definition: network.c:395
int os_recv(int, void *, int, int)
Definition: network.c:2243
char * fqdn
Definition: network.h:59
void add_close_stream_connection_hook(int(*)(int))
int socket_get_ssl_compression(int)
Definition: network.c:935
int stream_get_buffer_sz(int)
Definition: network.c:2163
int fd_is_stream(int)
Definition: network.c:2156
Definition: network.h:53
int stream_set_timeout(int, int)
Definition: network.c:1162
Definition: network.h:45