openvasd.h
Go to the documentation of this file.
/* SPDX-FileCopyrightText: 2024 Greenbone AG
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef _GVM_OPENVASD_H
#define _GVM_OPENVASD_H
#include "../base/nvti.h"
#include "../util/jsonpull.h"
#include <glib.h>
#include <stdio.h>
#include <time.h>
struct openvasd_result
{
unsigned long id;
gchar *type;
gchar *ip_address;
gchar *hostname;
gchar *oid;
int port;
gchar *protocol;
gchar *message;
gchar *detail_name;
gchar *detail_value;
gchar *detail_source_type;
gchar *detail_source_name;
gchar *detail_source_description;
};
enum OPENVASD_ERROR
{
OPENVASD_INVALID_OPT,
OPENVASD_NOT_INITIALIZED,
OPENVASD_INVALID_VALUE,
OPENVASD_ERROR,
OPENVASD_OK,
};
enum OPENVASD_CONNECTOR_OPTS
{
OPENVASD_CA_CERT,
OPENVASD_CERT,
OPENVASD_KEY,
OPENVASD_API_KEY,
OPENVASD_SERVER,
OPENVASD_HOST,
OPENVASD_SCAN_ID,
OPENVASD_PORT,
};
enum OPENVASD_RESULT_MEMBER_STRING
{
TYPE,
IP_ADDRESS,
HOSTNAME,
OID,
PROTOCOL,
MESSAGE,
DETAIL_NAME,
DETAIL_VALUE,
DETAIL_SOURCE_NAME,
DETAIL_SOURCE_TYPE,
DETAIL_SOURCE_DESCRIPTION,
};
enum OPENVASD_RESULT_MEMBER_INT
{
ID,
PORT,
};
typedef enum
{
OPENVASD_SCAN_STATUS_ERROR = -2,
OPENVASD_SCAN_STATUS_FAILED = -1,
OPENVASD_SCAN_STATUS_STORED,
OPENVASD_SCAN_STATUS_REQUESTED,
OPENVASD_SCAN_STATUS_RUNNING,
OPENVASD_SCAN_STATUS_STOPPED,
OPENVASD_SCAN_STATUS_SUCCEEDED,
} openvasd_status_t;
struct openvasd_response
{
long code;
gchar *body;
gchar *header;
};
struct openvasd_scan_status
{
time_t start_time;
time_t end_time;
int progress;
openvasd_status_t status;
long response_code;
};
typedef struct
{
int start;
int end;
const gchar *titles;
} openvasd_get_performance_opts_t;
typedef struct openvasd_response *openvasd_resp_t;
typedef enum OPENVASD_RESULT_MEMBER_INT openvasd_result_member_int_t;
typedef enum OPENVASD_RESULT_MEMBER_STRING openvasd_result_member_string_t;
typedef enum OPENVASD_CONNECTOR_OPTS openvasd_conn_opt_t;
typedef enum OPENVASD_ERROR openvasd_error_t;
typedef struct openvasd_result *openvasd_result_t;
typedef struct openvasd_connector *openvasd_connector_t;
typedef struct openvasd_scan_status *openvasd_scan_status_t;
// Functions to build/free request data
openvasd_connector_t
openvasd_connector_new (void);
openvasd_error_t
openvasd_connector_builder (openvasd_connector_t, openvasd_conn_opt_t,
const void *);
openvasd_error_t openvasd_connector_free (openvasd_connector_t);
void openvasd_response_cleanup (openvasd_resp_t);
// Requests
openvasd_resp_t openvasd_get_version (openvasd_connector_t);
openvasd_resp_t openvasd_get_vts (openvasd_connector_t);
openvasd_resp_t
openvasd_start_scan (openvasd_connector_t, gchar *);
openvasd_resp_t openvasd_stop_scan (openvasd_connector_t);
openvasd_resp_t openvasd_delete_scan (openvasd_connector_t);
openvasd_resp_t
openvasd_get_scan_results (openvasd_connector_t, long, long);
openvasd_result_t
openvasd_result_new (unsigned long, gchar *, gchar *, gchar *, gchar *, int,
gchar *, gchar *, gchar *, gchar *, gchar *, gchar *,
gchar *);
void openvasd_result_free (openvasd_result_t);
char *openvasd_get_result_member_str (openvasd_result_t,
openvasd_result_member_string_t);
int openvasd_get_result_member_int (openvasd_result_t,
openvasd_result_member_int_t);
int
openvasd_parsed_results (openvasd_connector_t, unsigned long, unsigned long,
GSList **);
openvasd_resp_t openvasd_get_scan_status (openvasd_connector_t);
openvasd_scan_status_t openvasd_parsed_scan_status (openvasd_connector_t);
int openvasd_get_scan_progress (openvasd_connector_t);
openvasd_resp_t openvasd_get_health_alive (openvasd_connector_t);
openvasd_resp_t openvasd_get_health_ready (openvasd_connector_t);
openvasd_resp_t openvasd_get_health_started (openvasd_connector_t);
openvasd_resp_t openvasd_get_performance (openvasd_connector_t,
openvasd_get_performance_opts_t);
int
openvasd_parsed_performance (openvasd_connector_t,
openvasd_get_performance_opts_t, gchar **,
gchar **err);
/* Scanner preferences */
typedef struct openvasd_param openvasd_param_t;
openvasd_resp_t openvasd_get_scan_preferences (openvasd_connector_t);
int
openvasd_parsed_scans_preferences (openvasd_connector_t, GSList **);
void
openvasd_param_free (openvasd_param_t *);
char *
openvasd_param_id (openvasd_param_t *);
char *
openvasd_param_name (openvasd_param_t *);
char *
openvasd_param_desc (openvasd_param_t *);
int
openvasd_param_mandatory (openvasd_param_t *);
char *
openvasd_param_type (openvasd_param_t *);
char *
openvasd_param_default (openvasd_param_t *);
/* Target builder */
typedef struct openvasd_target openvasd_target_t;
typedef struct openvasd_vt_single openvasd_vt_single_t;
typedef struct openvasd_credential openvasd_credential_t;
openvasd_target_t *
openvasd_target_new (const gchar *, const gchar *, const gchar *, const gchar *,
int, int);
void
openvasd_target_set_finished_hosts (openvasd_target_t *, const gchar *);
void
openvasd_target_add_alive_test_methods (openvasd_target_t *, gboolean, gboolean,
gboolean, gboolean, gboolean);
void
openvasd_target_free (openvasd_target_t *);
openvasd_credential_t *
openvasd_credential_new (const gchar *, const gchar *, const gchar *);
void
openvasd_credential_set_auth_data (openvasd_credential_t *, const gchar *,
const gchar *);
void
openvasd_credential_free (openvasd_credential_t *);
void
openvasd_target_add_credential (openvasd_target_t *, openvasd_credential_t *);
openvasd_vt_single_t *
openvasd_vt_single_new (const gchar *);
void
openvasd_vt_single_free (openvasd_vt_single_t *);
void
openvasd_vt_single_add_value (openvasd_vt_single_t *, const gchar *,
const gchar *);
char *
openvasd_build_scan_config_json (openvasd_target_t *, GHashTable *, GSList *);
/* VT stream */
openvasd_resp_t openvasd_get_vt_stream_init (openvasd_connector_t);
int openvasd_get_vt_stream (openvasd_connector_t);
void openvasd_reset_vt_stream (openvasd_connector_t);
char *openvasd_vt_stream_str (openvasd_connector_t);
size_t openvasd_vt_stream_len (openvasd_connector_t);
nvti_t *
openvasd_parse_vt (gvm_json_pull_parser_t *, gvm_json_pull_event_t *);
#endif
openvasd_credential_set_auth_data
void openvasd_credential_set_auth_data(openvasd_credential_t *, const gchar *, const gchar *)
Get authentication data from an openvasd credential.
Definition openvasd.c:1798
openvasd_get_scan_preferences
openvasd_resp_t openvasd_get_scan_preferences(openvasd_connector_t)
Definition openvasd.c:1292
openvasd_get_version
openvasd_resp_t openvasd_get_version(openvasd_connector_t)
Request HEAD.
Definition openvasd.c:342
OPENVASD_RESULT_MEMBER_INT
OPENVASD_RESULT_MEMBER_INT
Definition openvasd.h:78
ID
@ ID
Definition openvasd.h:79
PORT
@ PORT
Definition openvasd.h:80
openvasd_param_desc
char * openvasd_param_desc(openvasd_param_t *)
Get the parameter description.
Definition openvasd.c:1383
openvasd_parsed_scan_status
openvasd_scan_status_t openvasd_parsed_scan_status(openvasd_connector_t)
Return a struct with the general scan status.
Definition openvasd.c:1087
openvasd_result_member_string_t
enum OPENVASD_RESULT_MEMBER_STRING openvasd_result_member_string_t
Definition openvasd.h:124
openvasd_get_health_ready
openvasd_resp_t openvasd_get_health_ready(openvasd_connector_t)
Definition openvasd.c:1172
openvasd_vt_stream_len
size_t openvasd_vt_stream_len(openvasd_connector_t)
Definition openvasd.c:445
openvasd_get_health_alive
openvasd_resp_t openvasd_get_health_alive(openvasd_connector_t)
Definition openvasd.c:1152
OPENVASD_ERROR
OPENVASD_ERROR
Openvasd Errors.
Definition openvasd.h:41
OPENVASD_NOT_INITIALIZED
@ OPENVASD_NOT_INITIALIZED
Definition openvasd.h:43
OPENVASD_INVALID_OPT
@ OPENVASD_INVALID_OPT
Definition openvasd.h:42
OPENVASD_INVALID_VALUE
@ OPENVASD_INVALID_VALUE
Definition openvasd.h:44
OPENVASD_OK
@ OPENVASD_OK
Definition openvasd.h:46
openvasd_target_add_credential
void openvasd_target_add_credential(openvasd_target_t *, openvasd_credential_t *)
Add a credential to an openvasd target.
Definition openvasd.c:1922
openvasd_get_vts
openvasd_resp_t openvasd_get_vts(openvasd_connector_t)
Get VT's metadata.
Definition openvasd.c:498
openvasd_target_free
void openvasd_target_free(openvasd_target_t *)
Free an openvasd target, including all added credentials.
Definition openvasd.c:1873
openvasd_get_vt_stream_init
openvasd_resp_t openvasd_get_vt_stream_init(openvasd_connector_t)
Initialized an curl multiperform handler which allows fetch feed metadata chunk by chunk.
Definition openvasd.c:365
openvasd_start_scan
openvasd_resp_t openvasd_start_scan(openvasd_connector_t, gchar *)
Definition openvasd.c:524
openvasd_parsed_results
int openvasd_parsed_results(openvasd_connector_t, unsigned long, unsigned long, GSList **)
Definition openvasd.c:863
openvasd_get_scan_status
openvasd_resp_t openvasd_get_scan_status(openvasd_connector_t)
Definition openvasd.c:881
openvasd_target_set_finished_hosts
void openvasd_target_set_finished_hosts(openvasd_target_t *, const gchar *)
Set the finished hosts of an openvasd target.
Definition openvasd.c:1860
openvasd_parsed_scans_preferences
int openvasd_parsed_scans_preferences(openvasd_connector_t, GSList **)
Definition openvasd.c:1434
openvasd_credential_new
openvasd_credential_t * openvasd_credential_new(const gchar *, const gchar *, const gchar *)
Allocate and initialize a new openvasd credential.
Definition openvasd.c:1756
openvasd_get_scan_progress
int openvasd_get_scan_progress(openvasd_connector_t)
Definition openvasd.c:1023
openvasd_vt_single_new
openvasd_vt_single_t * openvasd_vt_single_new(const gchar *)
Create a new single openvasd VT.
Definition openvasd.c:1939
openvasd_connector_new
openvasd_connector_t openvasd_connector_new(void)
Initialize an openvasd connector.
Definition openvasd.c:109
openvasd_get_result_member_int
int openvasd_get_result_member_int(openvasd_result_t, openvasd_result_member_int_t)
Definition openvasd.c:747
openvasd_get_performance
openvasd_resp_t openvasd_get_performance(openvasd_connector_t, openvasd_get_performance_opts_t)
Definition openvasd.c:1213
openvasd_get_health_started
openvasd_resp_t openvasd_get_health_started(openvasd_connector_t)
Definition openvasd.c:1193
openvasd_param_default
char * openvasd_param_default(openvasd_param_t *)
Get the parameter default.
Definition openvasd.c:1411
openvasd_parsed_performance
int openvasd_parsed_performance(openvasd_connector_t, openvasd_get_performance_opts_t, gchar **, gchar **err)
Definition openvasd.c:1253
openvasd_stop_scan
openvasd_resp_t openvasd_stop_scan(openvasd_connector_t)
Definition openvasd.c:606
openvasd_connector_free
openvasd_error_t openvasd_connector_free(openvasd_connector_t)
Build a openvasd connector.
Definition openvasd.c:185
openvasd_reset_vt_stream
void openvasd_reset_vt_stream(openvasd_connector_t)
Definition openvasd.c:433
openvasd_get_scan_results
openvasd_resp_t openvasd_get_scan_results(openvasd_connector_t, long, long)
Definition openvasd.c:640
openvasd_delete_scan
openvasd_resp_t openvasd_delete_scan(openvasd_connector_t)
Definition openvasd.c:1113
openvasd_get_result_member_str
char * openvasd_get_result_member_str(openvasd_result_t, openvasd_result_member_string_t)
Definition openvasd.c:711
openvasd_vt_single_free
void openvasd_vt_single_free(openvasd_vt_single_t *)
Free a single openvasd VT, including all preference values.
Definition openvasd.c:1957
openvasd_target_new
openvasd_target_t * openvasd_target_new(const gchar *, const gchar *, const gchar *, const gchar *, int, int)
Create a new openvasd target.
Definition openvasd.c:1831
openvasd_param_mandatory
int openvasd_param_mandatory(openvasd_param_t *)
If the parameter is mandatory.
Definition openvasd.c:1425
openvasd_response_cleanup
void openvasd_response_cleanup(openvasd_resp_t)
Free an openvasd response struct.
Definition openvasd.c:210
openvasd_target_add_alive_test_methods
void openvasd_target_add_alive_test_methods(openvasd_target_t *, gboolean, gboolean, gboolean, gboolean, gboolean)
Add alive test methods to openvasd target.
Definition openvasd.c:1900
openvasd_connector_t
struct openvasd_connector * openvasd_connector_t
Definition openvasd.h:132
OPENVASD_CONNECTOR_OPTS
OPENVASD_CONNECTOR_OPTS
Openvasd options for the connector builder.
Definition openvasd.h:51
OPENVASD_API_KEY
@ OPENVASD_API_KEY
Definition openvasd.h:55
OPENVASD_SERVER
@ OPENVASD_SERVER
Definition openvasd.h:56
OPENVASD_CA_CERT
@ OPENVASD_CA_CERT
Definition openvasd.h:52
OPENVASD_KEY
@ OPENVASD_KEY
Definition openvasd.h:54
OPENVASD_SCAN_ID
@ OPENVASD_SCAN_ID
Definition openvasd.h:58
OPENVASD_CERT
@ OPENVASD_CERT
Definition openvasd.h:53
OPENVASD_PORT
@ OPENVASD_PORT
Definition openvasd.h:59
OPENVASD_HOST
@ OPENVASD_HOST
Definition openvasd.h:57
openvasd_status_t
openvasd_status_t
Openvasd scan status.
Definition openvasd.h:87
OPENVASD_SCAN_STATUS_SUCCEEDED
@ OPENVASD_SCAN_STATUS_SUCCEEDED
Definition openvasd.h:94
OPENVASD_SCAN_STATUS_RUNNING
@ OPENVASD_SCAN_STATUS_RUNNING
Definition openvasd.h:92
OPENVASD_SCAN_STATUS_STOPPED
@ OPENVASD_SCAN_STATUS_STOPPED
Definition openvasd.h:93
OPENVASD_SCAN_STATUS_STORED
@ OPENVASD_SCAN_STATUS_STORED
Definition openvasd.h:90
OPENVASD_SCAN_STATUS_REQUESTED
@ OPENVASD_SCAN_STATUS_REQUESTED
Definition openvasd.h:91
OPENVASD_SCAN_STATUS_ERROR
@ OPENVASD_SCAN_STATUS_ERROR
Definition openvasd.h:88
OPENVASD_SCAN_STATUS_FAILED
@ OPENVASD_SCAN_STATUS_FAILED
Definition openvasd.h:89
openvasd_result_t
struct openvasd_result * openvasd_result_t
Definition openvasd.h:130
openvasd_vt_stream_str
char * openvasd_vt_stream_str(openvasd_connector_t)
Definition openvasd.c:439
openvasd_result_free
void openvasd_result_free(openvasd_result_t)
Definition openvasd.c:765
openvasd_conn_opt_t
enum OPENVASD_CONNECTOR_OPTS openvasd_conn_opt_t
Definition openvasd.h:126
openvasd_param_type
char * openvasd_param_type(openvasd_param_t *)
Get the parameter type.
Definition openvasd.c:1397
openvasd_param_id
char * openvasd_param_id(openvasd_param_t *)
Get the parameter id.
Definition openvasd.c:1355
openvasd_build_scan_config_json
char * openvasd_build_scan_config_json(openvasd_target_t *, GHashTable *, GSList *)
Build a json object with data necessary to start a scan.
Definition openvasd.c:1621
openvasd_param_free
void openvasd_param_free(openvasd_param_t *)
Free an openvasd parameter.
Definition openvasd.c:1338
openvasd_connector_builder
openvasd_error_t openvasd_connector_builder(openvasd_connector_t, openvasd_conn_opt_t, const void *)
Build a openvasd connector.
Definition openvasd.c:132
openvasd_result_member_int_t
enum OPENVASD_RESULT_MEMBER_INT openvasd_result_member_int_t
Definition openvasd.h:122
openvasd_parse_vt
nvti_t * openvasd_parse_vt(gvm_json_pull_parser_t *, gvm_json_pull_event_t *)
Parse a VT element given in json format.
Definition vtparser.c:246
openvasd_vt_single_add_value
void openvasd_vt_single_add_value(openvasd_vt_single_t *, const gchar *, const gchar *)
Add a preference value to an openvasd VT.
Definition openvasd.c:1978
openvasd_credential_free
void openvasd_credential_free(openvasd_credential_t *)
Free an openvasd credential.
Definition openvasd.c:1778
openvasd_param_name
char * openvasd_param_name(openvasd_param_t *)
Get the parameter default.
Definition openvasd.c:1369
openvasd_get_vt_stream
int openvasd_get_vt_stream(openvasd_connector_t)
Get a new feed metadata chunk.
Definition openvasd.c:462
openvasd_scan_status_t
struct openvasd_scan_status * openvasd_scan_status_t
Definition openvasd.h:134
openvasd_resp_t
struct openvasd_response * openvasd_resp_t
Definition openvasd.h:120
openvasd_result_new
openvasd_result_t openvasd_result_new(unsigned long, gchar *, gchar *, gchar *, gchar *, int, gchar *, gchar *, gchar *, gchar *, gchar *, gchar *, gchar *)
Definition openvasd.c:685
openvasd_error_t
enum OPENVASD_ERROR openvasd_error_t
Definition openvasd.h:128
OPENVASD_RESULT_MEMBER_STRING
OPENVASD_RESULT_MEMBER_STRING
Definition openvasd.h:63
DETAIL_NAME
@ DETAIL_NAME
Definition openvasd.h:70
DETAIL_VALUE
@ DETAIL_VALUE
Definition openvasd.h:71
DETAIL_SOURCE_DESCRIPTION
@ DETAIL_SOURCE_DESCRIPTION
Definition openvasd.h:74
PROTOCOL
@ PROTOCOL
Definition openvasd.h:68
DETAIL_SOURCE_NAME
@ DETAIL_SOURCE_NAME
Definition openvasd.h:72
DETAIL_SOURCE_TYPE
@ DETAIL_SOURCE_TYPE
Definition openvasd.h:73
HOSTNAME
@ HOSTNAME
Definition openvasd.h:66
MESSAGE
@ MESSAGE
Definition openvasd.h:69
TYPE
@ TYPE
Definition openvasd.h:64
IP_ADDRESS
@ IP_ADDRESS
Definition openvasd.h:65
OID
@ OID
Definition openvasd.h:67
gvm_json_pull_event_t
Event generated by the JSON pull parser.
Definition jsonpull.h:59
gvm_json_pull_parser_t
A json pull parser.
Definition jsonpull.h:86
nvti
The structure of a information record that corresponds to a NVT.
Definition nvti.c:358
openvasd_connector
Struct holding the data for connecting with openvasd.
Definition openvasd.c:38
openvasd_credential
Struct credential information for openvasd.
Definition openvasd.c:67
openvasd_get_performance_opts_t
Definition openvasd.h:114
openvasd_get_performance_opts_t::titles
const gchar * titles
Definition openvasd.h:117
openvasd_get_performance_opts_t::end
int end
Definition openvasd.h:116
openvasd_get_performance_opts_t::start
int start
Definition openvasd.h:115
openvasd_param
Struct holding options for openvasd parameters.
Definition openvasd.c:54
openvasd_response
Definition openvasd.h:98
openvasd_response::header
gchar * header
Definition openvasd.h:101
openvasd_response::body
gchar * body
Definition openvasd.h:100
openvasd_response::code
long code
Definition openvasd.h:99
openvasd_result
Struct to hold an scan result.
Definition openvasd.h:23
openvasd_result::port
int port
Definition openvasd.h:29
openvasd_result::ip_address
gchar * ip_address
Definition openvasd.h:26
openvasd_result::oid
gchar * oid
Definition openvasd.h:28
openvasd_result::protocol
gchar * protocol
Definition openvasd.h:30
openvasd_result::detail_source_name
gchar * detail_source_name
Definition openvasd.h:35
openvasd_result::message
gchar * message
Definition openvasd.h:31
openvasd_result::type
gchar * type
Definition openvasd.h:25
openvasd_result::detail_source_description
gchar * detail_source_description
Definition openvasd.h:36
openvasd_result::hostname
gchar * hostname
Definition openvasd.h:27
openvasd_result::detail_name
gchar * detail_name
Definition openvasd.h:32
openvasd_result::id
unsigned long id
Definition openvasd.h:24
openvasd_result::detail_value
gchar * detail_value
Definition openvasd.h:33
openvasd_result::detail_source_type
gchar * detail_source_type
Definition openvasd.h:34
openvasd_scan_status
Definition openvasd.h:105
openvasd_scan_status::progress
int progress
Definition openvasd.h:108
openvasd_scan_status::start_time
time_t start_time
Definition openvasd.h:106
openvasd_scan_status::response_code
long response_code
Definition openvasd.h:110
openvasd_scan_status::end_time
time_t end_time
Definition openvasd.h:107
openvasd_scan_status::status
openvasd_status_t status
Definition openvasd.h:109
openvasd_target
Struct holding target information.
Definition openvasd.c:78
openvasd_vt_single
Struct holding vt information.
Definition openvasd.c:98