Greenbone Vulnerability Management Libraries 22.20.0
Data Structures | Typedefs | Enumerations | Functions
openvasd.h File Reference

API for Openvas Daemon communication. More...

#include "../base/nvti.h"
#include "../util/jsonpull.h"
#include <glib.h>
#include <stdio.h>
#include <time.h>

Go to the source code of this file.

Data Structures

struct  openvasd_result
 Struct to hold an scan result. More...
 
struct  openvasd_response
 
struct  openvasd_scan_status
 
struct  openvasd_get_performance_opts_t
 

Typedefs

typedef struct openvasd_responseopenvasd_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_resultopenvasd_result_t
 
typedef struct openvasd_connectoropenvasd_connector_t
 
typedef struct openvasd_scan_statusopenvasd_scan_status_t
 
typedef struct openvasd_param openvasd_param_t
 
typedef struct openvasd_target openvasd_target_t
 
typedef struct openvasd_vt_single openvasd_vt_single_t
 
typedef struct openvasd_credential openvasd_credential_t
 

Enumerations

enum  OPENVASD_ERROR {
  OPENVASD_INVALID_OPT , OPENVASD_NOT_INITIALIZED , OPENVASD_INVALID_VALUE , OPENVASD_ERROR ,
  OPENVASD_OK
}
 Openvasd Errors. More...
 
enum  OPENVASD_CONNECTOR_OPTS {
  OPENVASD_CA_CERT , OPENVASD_CERT , OPENVASD_KEY , OPENVASD_API_KEY ,
  OPENVASD_SERVER , OPENVASD_HOST , OPENVASD_SCAN_ID , OPENVASD_PORT
}
 Openvasd options for the connector builder. More...
 
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 }
 
enum  openvasd_status_t {
  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 scan status. More...
 

Functions

openvasd_connector_t openvasd_connector_new (void)
 Initialize an openvasd connector.
 
openvasd_error_t openvasd_connector_builder (openvasd_connector_t, openvasd_conn_opt_t, const void *)
 Build a openvasd connector.
 
openvasd_error_t openvasd_connector_free (openvasd_connector_t)
 Build a openvasd connector.
 
void openvasd_response_cleanup (openvasd_resp_t)
 Free an openvasd response struct.
 
openvasd_resp_t openvasd_get_version (openvasd_connector_t)
 Request HEAD.
 
openvasd_resp_t openvasd_get_vts (openvasd_connector_t)
 Get VT's metadata.
 
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)
 Return a struct with the general scan status.
 
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)
 
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 *)
 Free an openvasd parameter.
 
char * openvasd_param_id (openvasd_param_t *)
 Get the parameter id.
 
char * openvasd_param_name (openvasd_param_t *)
 Get the parameter default.
 
char * openvasd_param_desc (openvasd_param_t *)
 Get the parameter description.
 
int openvasd_param_mandatory (openvasd_param_t *)
 If the parameter is mandatory.
 
char * openvasd_param_type (openvasd_param_t *)
 Get the parameter type.
 
char * openvasd_param_default (openvasd_param_t *)
 Get the parameter default.
 
openvasd_target_topenvasd_target_new (const gchar *, const gchar *, const gchar *, const gchar *, int, int)
 Create a new openvasd target.
 
void openvasd_target_set_finished_hosts (openvasd_target_t *, const gchar *)
 Set the finished hosts of an openvasd target.
 
void openvasd_target_add_alive_test_methods (openvasd_target_t *, gboolean, gboolean, gboolean, gboolean, gboolean)
 Add alive test methods to openvasd target.
 
void openvasd_target_free (openvasd_target_t *)
 Free an openvasd target, including all added credentials.
 
openvasd_credential_topenvasd_credential_new (const gchar *, const gchar *, const gchar *)
 Allocate and initialize a new openvasd credential.
 
void openvasd_credential_set_auth_data (openvasd_credential_t *, const gchar *, const gchar *)
 Get authentication data from an openvasd credential.
 
void openvasd_credential_free (openvasd_credential_t *)
 Free an openvasd credential.
 
void openvasd_target_add_credential (openvasd_target_t *, openvasd_credential_t *)
 Add a credential to an openvasd target.
 
openvasd_vt_single_topenvasd_vt_single_new (const gchar *)
 Create a new single openvasd VT.
 
void openvasd_vt_single_free (openvasd_vt_single_t *)
 Free a single openvasd VT, including all preference values.
 
void openvasd_vt_single_add_value (openvasd_vt_single_t *, const gchar *, const gchar *)
 Add a preference value to an openvasd VT.
 
char * openvasd_build_scan_config_json (openvasd_target_t *, GHashTable *, GSList *)
 Build a json object with data necessary to start a scan.
 
openvasd_resp_t openvasd_get_vt_stream_init (openvasd_connector_t)
 Initialized an curl multiperform handler which allows fetch feed metadata chunk by chunk.
 
int openvasd_get_vt_stream (openvasd_connector_t)
 Get a new feed metadata chunk.
 
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_topenvasd_parse_vt (gvm_json_pull_parser_t *, gvm_json_pull_event_t *)
 Parse a VT element given in json format.
 

Detailed Description

API for Openvas Daemon communication.

Typedef Documentation

◆ openvasd_conn_opt_t

◆ openvasd_connector_t

◆ openvasd_credential_t

◆ openvasd_error_t

◆ openvasd_param_t

◆ openvasd_resp_t

◆ openvasd_result_member_int_t

◆ openvasd_result_member_string_t

◆ openvasd_result_t

◆ openvasd_scan_status_t

◆ openvasd_target_t

◆ openvasd_vt_single_t

Enumeration Type Documentation

◆ OPENVASD_CONNECTOR_OPTS

Openvasd options for the connector builder.

Enumerator
OPENVASD_CA_CERT 
OPENVASD_CERT 
OPENVASD_KEY 
OPENVASD_API_KEY 
OPENVASD_SERVER 
OPENVASD_HOST 
OPENVASD_SCAN_ID 
OPENVASD_PORT 

◆ OPENVASD_ERROR

Openvasd Errors.

Enumerator
OPENVASD_INVALID_OPT 
OPENVASD_NOT_INITIALIZED 
OPENVASD_INVALID_VALUE 
OPENVASD_ERROR 
OPENVASD_OK 

◆ OPENVASD_RESULT_MEMBER_INT

Enumerator
ID 
PORT 

◆ OPENVASD_RESULT_MEMBER_STRING

Enumerator
TYPE 
IP_ADDRESS 
HOSTNAME 
OID 
PROTOCOL 
MESSAGE 
DETAIL_NAME 
DETAIL_VALUE 
DETAIL_SOURCE_NAME 
DETAIL_SOURCE_TYPE 
DETAIL_SOURCE_DESCRIPTION 

◆ openvasd_status_t

Openvasd scan status.

Enumerator
OPENVASD_SCAN_STATUS_ERROR 

Error status.

OPENVASD_SCAN_STATUS_FAILED 

Failed status.

OPENVASD_SCAN_STATUS_STORED 

Stored status

OPENVASD_SCAN_STATUS_REQUESTED 

Queued status

OPENVASD_SCAN_STATUS_RUNNING 

Running status.

OPENVASD_SCAN_STATUS_STOPPED 

Stopped status.

OPENVASD_SCAN_STATUS_SUCCEEDED 

Succeeded status

Function Documentation

◆ openvasd_build_scan_config_json()

char * openvasd_build_scan_config_json ( openvasd_target_t target,
GHashTable *  scan_preferences,
GSList *  vts 
)

Build a json object with data necessary to start a scan.

JSON result consists of scan_id, message type, host ip, hostname, port, together with proto, OID, result message and uri.

Parameters
targettarget
scan_preferencesScan preferences to be added to the scan config
vtsVTS collection to be added to the scan config.
Returns
JSON string on success. Must be freed by caller. NULL on error.

◆ openvasd_connector_builder()

openvasd_error_t openvasd_connector_builder ( openvasd_connector_t  conn,
openvasd_conn_opt_t  opt,
const void *  val 
)

Build a openvasd connector.

Receive option name and value to build the openvasd connector

Parameters
connstruct holding the openvasd connector information
optoption to set
valvalue to set
Returns
Return OK on success, otherwise error;

◆ openvasd_connector_free()

openvasd_error_t openvasd_connector_free ( openvasd_connector_t  conn)

Build a openvasd connector.

Receive option name and value to build the openvasd connector

Parameters
connstruct holding the openvasd connector information
Returns
Return OPENVASD_OK

◆ openvasd_connector_new()

openvasd_connector_t openvasd_connector_new ( void  )

Initialize an openvasd connector.

Returns
An openvasd connector struct. It must be freed with openvasd_connector_free()

◆ openvasd_credential_free()

void openvasd_credential_free ( openvasd_credential_t credential)

Free an openvasd credential.

Parameters
credentialThe credential to free.

◆ openvasd_credential_new()

openvasd_credential_t * openvasd_credential_new ( const gchar *  type,
const gchar *  service,
const gchar *  port 
)

Allocate and initialize a new openvasd credential.

Parameters
typeThe credential type.
serviceThe service the credential is for.
portThe port.
Returns
New openvasd credential.

◆ openvasd_credential_set_auth_data()

void openvasd_credential_set_auth_data ( openvasd_credential_t credential,
const gchar *  name,
const gchar *  value 
)

Get authentication data from an openvasd credential.

Parameters
credentialThe credential to get the data from.
nameThe name of the data item to get.
valueThe authentication data or NULL to unset.

◆ openvasd_delete_scan()

openvasd_resp_t openvasd_delete_scan ( openvasd_connector_t  conn)

◆ openvasd_get_health_alive()

openvasd_resp_t openvasd_get_health_alive ( openvasd_connector_t  conn)

◆ openvasd_get_health_ready()

openvasd_resp_t openvasd_get_health_ready ( openvasd_connector_t  conn)

◆ openvasd_get_health_started()

openvasd_resp_t openvasd_get_health_started ( openvasd_connector_t  conn)

◆ openvasd_get_performance()

openvasd_resp_t openvasd_get_performance ( openvasd_connector_t  conn,
openvasd_get_performance_opts_t  opts 
)

◆ openvasd_get_result_member_int()

int openvasd_get_result_member_int ( openvasd_result_t  result,
openvasd_result_member_int_t  member 
)

◆ openvasd_get_result_member_str()

char * openvasd_get_result_member_str ( openvasd_result_t  result,
openvasd_result_member_string_t  member 
)

◆ openvasd_get_scan_preferences()

openvasd_resp_t openvasd_get_scan_preferences ( openvasd_connector_t  conn)

◆ openvasd_get_scan_progress()

int openvasd_get_scan_progress ( openvasd_connector_t  conn)

◆ openvasd_get_scan_results()

openvasd_resp_t openvasd_get_scan_results ( openvasd_connector_t  conn,
long  first,
long  last 
)

◆ openvasd_get_scan_status()

openvasd_resp_t openvasd_get_scan_status ( openvasd_connector_t  conn)

◆ openvasd_get_version()

openvasd_resp_t openvasd_get_version ( openvasd_connector_t  conn)

Request HEAD.

Parameters
connConnector struct with the data necessary for the connection
Returns
Response containing the header information

◆ openvasd_get_vt_stream()

int openvasd_get_vt_stream ( openvasd_connector_t  conn)

Get a new feed metadata chunk.

This function must be call until the return value is 0, meaning there is no more data to fetch.

Parameters
mhndCurl multiperfom for requesting the feed metadata
Returns
greather than 0 if the handler is still getting data. 0 if the transmision finished. -1 on error

◆ openvasd_get_vt_stream_init()

openvasd_resp_t openvasd_get_vt_stream_init ( openvasd_connector_t  conn)

Initialized an curl multiperform handler which allows fetch feed metadata chunk by chunk.

Parameters
connConnector struct with the data necessary for the connection
mhndThe curl multiperform handler. It the caller doesn't provide it initialized, it will be initialized. The caller has to free it with gvm_http_multi_free().
respThe stringstream struct for the write callback function.
Returns
The response.

◆ openvasd_get_vts()

openvasd_resp_t openvasd_get_vts ( openvasd_connector_t  conn)

Get VT's metadata.

Parameters
connConnector struct with the data necessary for the connection
Returns
Response Struct containing the feed metadata in json format in the body.

◆ openvasd_param_default()

char * openvasd_param_default ( openvasd_param_t param)

Get the parameter default.

Parameters
paramopenvasd parameter

◆ openvasd_param_desc()

char * openvasd_param_desc ( openvasd_param_t param)

Get the parameter description.

Parameters
paramopenvasd parameter

◆ openvasd_param_free()

void openvasd_param_free ( openvasd_param_t param)

Free an openvasd parameter.

Parameters
paramopenvasd parameter to destroy.

◆ openvasd_param_id()

char * openvasd_param_id ( openvasd_param_t param)

Get the parameter id.

Parameters
paramopenvasd parameter

◆ openvasd_param_mandatory()

int openvasd_param_mandatory ( openvasd_param_t param)

If the parameter is mandatory.

Parameters
paramopenvasd parameter

◆ openvasd_param_name()

char * openvasd_param_name ( openvasd_param_t param)

Get the parameter default.

Parameters
paramopenvasd parameter

◆ openvasd_param_type()

char * openvasd_param_type ( openvasd_param_t param)

Get the parameter type.

Parameters
paramopenvasd parameter

◆ openvasd_parse_vt()

nvti_t * openvasd_parse_vt ( gvm_json_pull_parser_t parser,
gvm_json_pull_event_t event 
)

Parse a VT element given in json format.

Parameters
parserJson pull parser.
eventJson pull event.
Returns
nvti structure containing the VT metadata, NULL otherwise. The nvti struct must be freed with nvti_free() by the caller.

◆ openvasd_parsed_performance()

int openvasd_parsed_performance ( openvasd_connector_t  conn,
openvasd_get_performance_opts_t  opts,
gchar **  graph,
gchar **  err 
)

◆ openvasd_parsed_results()

int openvasd_parsed_results ( openvasd_connector_t  conn,
unsigned long  first,
unsigned long  last,
GSList **  results 
)

◆ openvasd_parsed_scan_status()

openvasd_scan_status_t openvasd_parsed_scan_status ( openvasd_connector_t  conn)

Return a struct with the general scan status.

Parameters
connopenvasd connector data
Returns
The data in a struct. The struct must be freed by the caller.

◆ openvasd_parsed_scans_preferences()

int openvasd_parsed_scans_preferences ( openvasd_connector_t  conn,
GSList **  params 
)

◆ openvasd_reset_vt_stream()

void openvasd_reset_vt_stream ( openvasd_connector_t  conn)

◆ openvasd_response_cleanup()

void openvasd_response_cleanup ( openvasd_resp_t  resp)

Free an openvasd response struct.

Parameters
respResponse to be freed

◆ openvasd_result_free()

void openvasd_result_free ( openvasd_result_t  result)

◆ openvasd_result_new()

openvasd_result_t openvasd_result_new ( 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 
)

◆ openvasd_start_scan()

openvasd_resp_t openvasd_start_scan ( openvasd_connector_t  conn,
gchar *  data 
)

@Brief Get VT's metadata

Parameters
connConnector struct with the data necessary for the connection
dataString containing the scan config in JSON format.
Returns
Response Struct containing the resonse.

◆ openvasd_stop_scan()

openvasd_resp_t openvasd_stop_scan ( openvasd_connector_t  conn)

◆ openvasd_target_add_alive_test_methods()

void openvasd_target_add_alive_test_methods ( openvasd_target_t target,
gboolean  icmp,
gboolean  tcp_syn,
gboolean  tcp_ack,
gboolean  arp,
gboolean  consider_alive 
)

Add alive test methods to openvasd target.

Parameters
targetThe openvasd target to add the methods to.
icmpUse ICMP ping.
tcp_synUse TCP-SYN ping.
tcp_ackUse TCP-ACK ping.
arpUse ARP ping.
consider_aliveConsider host to be alive.

◆ openvasd_target_add_credential()

void openvasd_target_add_credential ( openvasd_target_t target,
openvasd_credential_t credential 
)

Add a credential to an openvasd target.

Parameters
targetThe openvasd target to add the credential to.
credentialThe credential to add. Will be freed with target.

◆ openvasd_target_free()

void openvasd_target_free ( openvasd_target_t target)

Free an openvasd target, including all added credentials.

Parameters
targetThe openvasd target to free.

◆ openvasd_target_new()

openvasd_target_t * openvasd_target_new ( const gchar *  scanid,
const gchar *  hosts,
const gchar *  ports,
const gchar *  exclude_hosts,
int  reverse_lookup_unify,
int  reverse_lookup_only 
)

Create a new openvasd target.

Parameters
scanidScan ID.
hostsThe hostnames of the target.
portsThe ports of the target.
exclude_hostsThe excluded hosts of the target.
reverse_lookup_unifyLookup flag.
reverse_lookup_onlyLookup flag.
Returns
The newly allocated openvasd_target_t.

◆ openvasd_target_set_finished_hosts()

void openvasd_target_set_finished_hosts ( openvasd_target_t target,
const gchar *  finished_hosts 
)

Set the finished hosts of an openvasd target.

Parameters
targetThe openvasd target to modify.
finished_hostsThe hostnames to consider finished.

◆ openvasd_vt_single_add_value()

void openvasd_vt_single_add_value ( openvasd_vt_single_t vt_single,
const gchar *  name,
const gchar *  value 
)

Add a preference value to an openvasd VT.

This creates a copy of the name and value.

Parameters
vt_singleThe VT to add the preference to.
nameThe name / identifier of the preference.
valueThe value of the preference.

◆ openvasd_vt_single_free()

void openvasd_vt_single_free ( openvasd_vt_single_t vt_single)

Free a single openvasd VT, including all preference values.

Parameters
vt_singleThe openvasd VT to free.

◆ openvasd_vt_single_new()

openvasd_vt_single_t * openvasd_vt_single_new ( const gchar *  vt_id)

Create a new single openvasd VT.

Parameters
vt_idThe id of the VT.
Returns
The newly allocated single VT.

◆ openvasd_vt_stream_len()

size_t openvasd_vt_stream_len ( openvasd_connector_t  conn)

◆ openvasd_vt_stream_str()

char * openvasd_vt_stream_str ( openvasd_connector_t  conn)