Greenbone Vulnerability Management Libraries  21.4.2
serverutils.h
Go to the documentation of this file.
1 /* Copyright (C) 2009-2021 Greenbone Networks GmbH
2  *
3  * SPDX-License-Identifier: GPL-2.0-or-later
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
28 #ifndef _GVM_SERVERUTILS_H
29 #define _GVM_SERVERUTILS_H
30 
31 #include <glib.h> /* for gchar, gboolean, gint */
32 #include <gnutls/gnutls.h> /* for gnutls_session_t, gnutls_certificate_cred... */
33 #include <stdarg.h> /* for va_list */
34 #include <sys/param.h>
35 #ifdef __FreeBSD__
36 #include <netinet/in.h>
37 #endif
38 #include <netinet/ip.h>
39 
43 typedef struct
44 {
45  int tls;
46  int socket;
47  gnutls_session_t session;
48  gnutls_certificate_credentials_t credentials;
49  gchar *username;
50  gchar *password;
51  gchar *host_string;
52  gchar *port_string;
53  gint port;
54  gboolean use_certs;
55  gchar *ca_cert;
56  gchar *pub_key;
57  gchar *priv_key;
59 
60 void
62 
63 void
65 
66 int gvm_server_verify (gnutls_session_t);
67 
68 int
69 gvm_server_open (gnutls_session_t *, const char *, int);
70 
71 int
72 gvm_server_open_verify (gnutls_session_t *, const char *, int, const char *,
73  const char *, const char *, int);
74 
75 int
76 gvm_server_open_with_cert (gnutls_session_t *, const char *, int, const char *,
77  const char *, const char *);
78 
79 int
80 gvm_server_close (int, gnutls_session_t);
81 
82 int
83 gvm_server_attach (int, gnutls_session_t *);
84 
85 int
86 gvm_server_sendf (gnutls_session_t *, const char *, ...)
87  __attribute__ ((format (printf, 2, 3)));
88 
89 int
90 gvm_server_vsendf (gnutls_session_t *, const char *, va_list);
91 int
92 gvm_socket_vsendf (int, const char *, va_list);
93 
94 int
95 gvm_server_sendf_xml (gnutls_session_t *, const char *, ...);
96 int
97 gvm_server_sendf_xml_quiet (gnutls_session_t *, const char *, ...);
98 
99 int
100 gvm_connection_sendf_xml (gvm_connection_t *, const char *, ...);
101 int
102 gvm_connection_sendf_xml_quiet (gvm_connection_t *, const char *, ...);
103 
104 int
105 gvm_connection_sendf (gvm_connection_t *, const char *, ...);
106 
107 int
108 gvm_server_new (unsigned int, gchar *, gchar *, gchar *, gnutls_session_t *,
109  gnutls_certificate_credentials_t *);
110 
111 int
112 gvm_server_new_mem (unsigned int, const char *, const char *, const char *,
113  gnutls_session_t *, gnutls_certificate_credentials_t *);
114 
115 int
116 gvm_server_free (int, gnutls_session_t, gnutls_certificate_credentials_t);
117 
118 int gvm_server_session_free (gnutls_session_t,
119  gnutls_certificate_credentials_t);
120 
121 int
122 load_gnutls_file (const char *, gnutls_datum_t *);
123 
124 void
125 unload_gnutls_file (gnutls_datum_t *);
126 
127 int
128 set_gnutls_dhparams (gnutls_certificate_credentials_t, const char *);
129 
130 #endif /* not _GVM_SERVERUTILS_H */
__attribute__((weak))
Definition: networking_tests.c:1015
int gvm_connection_sendf(gvm_connection_t *, const char *,...)
Format and send a string to the server.
Definition: serverutils.c:845
int gvm_server_new(unsigned int, gchar *, gchar *, gchar *, gnutls_session_t *, gnutls_certificate_credentials_t *)
Make a session for connecting to a server.
Definition: serverutils.c:1165
int gvm_server_verify(gnutls_session_t)
Verify certificate.
Definition: serverutils.c:130
int gvm_server_open_verify(gnutls_session_t *, const char *, int, const char *, const char *, const char *, int)
Connect to the server using a given host, port and cert.
Definition: serverutils.c:333
void unload_gnutls_file(gnutls_datum_t *)
Unloads a gnutls_datum_t struct's data.
Definition: serverutils.c:208
int load_gnutls_file(const char *, gnutls_datum_t *)
Loads a file's data into gnutls_datum_t struct.
Definition: serverutils.c:180
void gvm_connection_close(gvm_connection_t *)
Close a server connection and its socket.
Definition: serverutils.c:526
int gvm_server_new_mem(unsigned int, const char *, const char *, const char *, gnutls_session_t *, gnutls_certificate_credentials_t *)
Make a session for connecting to a server, with certificates stored in memory.
Definition: serverutils.c:1187
int gvm_server_sendf_xml(gnutls_session_t *, const char *,...)
Format and send an XML string to the server.
Definition: serverutils.c:908
int gvm_server_close(int, gnutls_session_t)
Close a server connection and its socket.
Definition: serverutils.c:513
int gvm_server_session_free(gnutls_session_t, gnutls_certificate_credentials_t)
void gvm_connection_free(gvm_connection_t *)
Free connection.
Definition: serverutils.c:111
int int gvm_server_vsendf(gnutls_session_t *, const char *, va_list)
Send a string to the server.
Definition: serverutils.c:749
int gvm_server_sendf_xml_quiet(gnutls_session_t *, const char *,...)
Format and send an XML string to the server.
Definition: serverutils.c:960
int gvm_server_open_with_cert(gnutls_session_t *, const char *, int, const char *, const char *, const char *)
Connect to the server using a given host, port and cert.
Definition: serverutils.c:481
int gvm_server_open(gnutls_session_t *, const char *, int)
Connect to the server using a given host and port.
Definition: serverutils.c:499
int gvm_socket_vsendf(int, const char *, va_list)
Send a string to the server.
Definition: serverutils.c:764
int gvm_server_attach(int, gnutls_session_t *)
Attach a socket to a session, and shake hands with the peer.
Definition: serverutils.c:591
int set_gnutls_dhparams(gnutls_certificate_credentials_t, const char *)
Set a gnutls session's Diffie-Hellman parameters.
Definition: serverutils.c:1249
int gvm_connection_sendf_xml(gvm_connection_t *, const char *,...)
Format and send an XML string to the server.
Definition: serverutils.c:933
int gvm_server_sendf(gnutls_session_t *, const char *,...) __attribute__((format(printf
int gvm_server_free(int, gnutls_session_t, gnutls_certificate_credentials_t)
Cleanup a server session.
Definition: serverutils.c:1292
int gvm_connection_sendf_xml_quiet(gvm_connection_t *, const char *,...)
Format and send an XML string to the server.
Definition: serverutils.c:987
Connection.
Definition: serverutils.h:44
gint port
Port of server.
Definition: serverutils.h:53
gboolean use_certs
Whether to use certs.
Definition: serverutils.h:54
gchar * username
Username with which to connect.
Definition: serverutils.h:49
gchar * ca_cert
CA certificate.
Definition: serverutils.h:55
gchar * password
Password for user with which to connect.
Definition: serverutils.h:50
gchar * priv_key
The private key.
Definition: serverutils.h:57
gchar * port_string
Server port string.
Definition: serverutils.h:52
int tls
Whether uses TCP-TLS (vs UNIX socket).
Definition: serverutils.h:45
gchar * pub_key
The public key.
Definition: serverutils.h:56
gnutls_certificate_credentials_t credentials
Credentials.
Definition: serverutils.h:48
int socket
Socket.
Definition: serverutils.h:46
gchar * host_string
Server host string.
Definition: serverutils.h:51
gnutls_session_t session
Session.
Definition: serverutils.h:47