Greenbone Vulnerability Management Libraries 22.5.0
serverutils.h
Go to the documentation of this file.
1/* Copyright (C) 2009-2022 Greenbone AG
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
43typedef 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
60void
62
63void
65
66int gvm_server_verify (gnutls_session_t);
67
68int
69gvm_server_open (gnutls_session_t *, const char *, int);
70
71int
72gvm_server_open_verify (gnutls_session_t *, const char *, int, const char *,
73 const char *, const char *, int);
74
75int
76gvm_server_open_with_cert (gnutls_session_t *, const char *, int, const char *,
77 const char *, const char *);
78
79int
80gvm_server_close (int, gnutls_session_t);
81
82int
83gvm_server_attach (int, gnutls_session_t *);
84
85int
86gvm_server_sendf (gnutls_session_t *, const char *, ...)
87 __attribute__ ((format (printf, 2, 3)));
88
89int
90gvm_server_vsendf (gnutls_session_t *, const char *, va_list);
91int
92gvm_socket_vsendf (int, const char *, va_list);
93
94int
95gvm_server_sendf_xml (gnutls_session_t *, const char *, ...);
96int
97gvm_server_sendf_xml_quiet (gnutls_session_t *, const char *, ...);
98
99int
100gvm_connection_sendf_xml (gvm_connection_t *, const char *, ...);
101int
103
104int
105gvm_connection_sendf (gvm_connection_t *, const char *, ...);
106
107int
108gvm_server_new (unsigned int, gchar *, gchar *, gchar *, gnutls_session_t *,
109 gnutls_certificate_credentials_t *);
110
111int
112gvm_server_new_mem (unsigned int, const char *, const char *, const char *,
113 gnutls_session_t *, gnutls_certificate_credentials_t *);
114
115int
116gvm_server_free (int, gnutls_session_t, gnutls_certificate_credentials_t);
117
118int gvm_server_session_free (gnutls_session_t,
119 gnutls_certificate_credentials_t);
120
121int
122load_gnutls_file (const char *, gnutls_datum_t *);
123
124void
125unload_gnutls_file (gnutls_datum_t *);
126
127int
128set_gnutls_dhparams (gnutls_certificate_credentials_t, const char *);
129
130#endif /* not _GVM_SERVERUTILS_H */
__attribute__((weak))
Definition: networking_tests.c:1017
int gvm_connection_sendf(gvm_connection_t *, const char *,...)
Format and send a string to the server.
Definition: serverutils.c:840
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:1160
int gvm_server_verify(gnutls_session_t)
Verify certificate.
Definition: serverutils.c:125
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:328
void unload_gnutls_file(gnutls_datum_t *)
Unloads a gnutls_datum_t struct's data.
Definition: serverutils.c:203
int load_gnutls_file(const char *, gnutls_datum_t *)
Loads a file's data into gnutls_datum_t struct.
Definition: serverutils.c:175
void gvm_connection_close(gvm_connection_t *)
Close a server connection and its socket.
Definition: serverutils.c:521
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:1182
int gvm_server_sendf_xml(gnutls_session_t *, const char *,...)
Format and send an XML string to the server.
Definition: serverutils.c:903
int gvm_server_close(int, gnutls_session_t)
Close a server connection and its socket.
Definition: serverutils.c:508
int gvm_server_session_free(gnutls_session_t, gnutls_certificate_credentials_t)
void gvm_connection_free(gvm_connection_t *)
Free connection.
Definition: serverutils.c:106
int int gvm_server_vsendf(gnutls_session_t *, const char *, va_list)
Send a string to the server.
Definition: serverutils.c:744
int gvm_server_sendf_xml_quiet(gnutls_session_t *, const char *,...)
Format and send an XML string to the server.
Definition: serverutils.c:955
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:476
int gvm_server_open(gnutls_session_t *, const char *, int)
Connect to the server using a given host and port.
Definition: serverutils.c:494
int gvm_socket_vsendf(int, const char *, va_list)
Send a string to the server.
Definition: serverutils.c:759
int gvm_server_attach(int, gnutls_session_t *)
Attach a socket to a session, and shake hands with the peer.
Definition: serverutils.c:586
int set_gnutls_dhparams(gnutls_certificate_credentials_t, const char *)
Set a gnutls session's Diffie-Hellman parameters.
Definition: serverutils.c:1244
int gvm_connection_sendf_xml(gvm_connection_t *, const char *,...)
Format and send an XML string to the server.
Definition: serverutils.c:928
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:1287
int gvm_connection_sendf_xml_quiet(gvm_connection_t *, const char *,...)
Format and send an XML string to the server.
Definition: serverutils.c:982
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