Greenbone Vulnerability Management Libraries  11.0.0
serverutils.h
Go to the documentation of this file.
1 /* Copyright (C) 2009-2019 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 */
gvm_socket_vsendf
int gvm_socket_vsendf(int, const char *, va_list)
Send a string to the server.
Definition: serverutils.c:758
load_gnutls_file
int load_gnutls_file(const char *, gnutls_datum_t *)
Loads a file's data into gnutls_datum_t struct.
Definition: serverutils.c:180
set_gnutls_dhparams
int set_gnutls_dhparams(gnutls_certificate_credentials_t, const char *)
Set a gnutls session's Diffie-Hellman parameters.
Definition: serverutils.c:1239
gvm_server_new
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:1155
gvm_connection_t::ca_cert
gchar * ca_cert
CA certificate.
Definition: serverutils.h:55
gvm_server_sendf_xml_quiet
int gvm_server_sendf_xml_quiet(gnutls_session_t *, const char *,...)
Format and send an XML string to the server.
Definition: serverutils.c:954
gvm_server_open_with_cert
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:475
gvm_server_session_free
int gvm_server_session_free(gnutls_session_t, gnutls_certificate_credentials_t)
gvm_connection_t::priv_key
gchar * priv_key
The private key.
Definition: serverutils.h:57
gvm_server_attach
int gvm_server_attach(int, gnutls_session_t *)
Attach a socket to a session, and shake hands with the peer.
Definition: serverutils.c:585
gvm_connection_t::port
gint port
Port of server.
Definition: serverutils.h:53
gvm_connection_free
void gvm_connection_free(gvm_connection_t *)
Free connection.
Definition: serverutils.c:111
gvm_connection_sendf_xml
int gvm_connection_sendf_xml(gvm_connection_t *, const char *,...)
Format and send an XML string to the server.
Definition: serverutils.c:927
gvm_server_free
int gvm_server_free(int, gnutls_session_t, gnutls_certificate_credentials_t)
Cleanup a server session.
Definition: serverutils.c:1273
gvm_connection_t::pub_key
gchar * pub_key
The public key.
Definition: serverutils.h:56
gvm_connection_t::username
gchar * username
Username with which to connect.
Definition: serverutils.h:49
gvm_connection_sendf_xml_quiet
int gvm_connection_sendf_xml_quiet(gvm_connection_t *, const char *,...)
Format and send an XML string to the server.
Definition: serverutils.c:981
gvm_server_new_mem
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:1177
gvm_server_sendf_xml
int gvm_server_sendf_xml(gnutls_session_t *, const char *,...)
Format and send an XML string to the server.
Definition: serverutils.c:902
gvm_connection_sendf
int gvm_connection_sendf(gvm_connection_t *, const char *,...)
Format and send a string to the server.
Definition: serverutils.c:839
gvm_connection_t::password
gchar * password
Password for user with which to connect.
Definition: serverutils.h:50
gvm_server_open
int gvm_server_open(gnutls_session_t *, const char *, int)
Connect to the server using a given host and port.
Definition: serverutils.c:493
gvm_connection_t::socket
int socket
Socket.
Definition: serverutils.h:46
gvm_connection_t::tls
int tls
Whether uses TCP-TLS (vs UNIX socket).
Definition: serverutils.h:45
gvm_server_sendf
int gvm_server_sendf(gnutls_session_t *, const char *,...) __attribute__((format(printf
gvm_connection_t::credentials
gnutls_certificate_credentials_t credentials
Credentials.
Definition: serverutils.h:48
gvm_connection_t::use_certs
gboolean use_certs
Whether to use certs.
Definition: serverutils.h:54
unload_gnutls_file
void unload_gnutls_file(gnutls_datum_t *)
Unloads a gnutls_datum_t struct's data.
Definition: serverutils.c:208
gvm_server_vsendf
int int gvm_server_vsendf(gnutls_session_t *, const char *, va_list)
Send a string to the server.
Definition: serverutils.c:743
gvm_server_verify
int gvm_server_verify(gnutls_session_t)
Verify certificate.
Definition: serverutils.c:130
gvm_connection_t::host_string
gchar * host_string
Server host string.
Definition: serverutils.h:51
gvm_server_open_verify
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:327
gvm_server_close
int gvm_server_close(int, gnutls_session_t)
Close a server connection and its socket.
Definition: serverutils.c:507
gvm_connection_t::session
gnutls_session_t session
Session.
Definition: serverutils.h:47
gvm_connection_t
Connection.
Definition: serverutils.h:43
gvm_connection_t::port_string
gchar * port_string
Server port string.
Definition: serverutils.h:52
gvm_connection_close
void gvm_connection_close(gvm_connection_t *)
Close a server connection and its socket.
Definition: serverutils.c:520