osp.c File Reference

API for Open Scanner Protocol communication. More...

`#include "osp.h"`
`#include "../base/hosts.h"`
`#include "../util/serverutils.h"`
`#include <assert.h>`
`#include <gnutls/gnutls.h>`
`#include <stdarg.h>`
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include <sys/socket.h>`
`#include <sys/un.h>`
`#include <unistd.h>`

Go to the source code of this file.

## Data Structures

struct | osp_connection
| Struct holding options for OSP connection. More...
struct | osp_param
| Struct holding options for OSP parameters. More...
struct | osp_credential
| Struct credential information for OSP. More...
struct | osp_target
| Struct holding target information. More...
struct | osp_vt_group
| Struct holding vt_group information. More...
struct | osp_vt_single
| Struct holding vt_group information. More...

## Macros

#define | G_LOG_DOMAIN "libgvm osp"
| GLib log domain.

## Functions

static int | osp_send_command (osp_connection_t *, entity_t *, static intosp_send_command_str(osp_connection_t const char *,...)
int | osp_send_command (osp_connection_t *connection, entity_t *response, const char *fmt,...)
| Send a command to an OSP server.
static int | osp_send_command_str (osp_connection_t *connection, gchar **str, const char *fmt,...)
| Send a command to an OSP server.
void | osp_connection_close (osp_connection_t *connection)
| Close a connection to an OSP server.
int | osp_check_feed (osp_connection_t *connection, int *lockfile_in_use, int *self_test_exit_error, char **self_test_error_msg, char **cmd_error)
| Gets additional status info about the feed.
int | osp_get_version (osp_connection_t *connection, char **s_name, char **s_version, char **d_name, char **d_version, char **p_name, char **p_version)
| Get the scanner version from an OSP server.
int | osp_get_vts_version (osp_connection_t *connection, char **vts_version, char **error)
| Get the VTs version from an OSP server.
int | osp_get_vts_feed_info (osp_connection_t *connection, char **vts_version, char **feed_name, char **feed_vendor, char **feed_home, char **error)
| Get the VTs version as well as other feed info from an OSP server.
int | osp_get_vts (osp_connection_t *connection, entity_t *vts)
| Get all VTs from an OSP server.
int | osp_get_vts_ext (osp_connection_t *connection, osp_get_vts_opts_t opts, entity_t *vts)
| Get filtered set of VTs from an OSP server.
int | osp_get_vts_ext_str (osp_connection_t *connection, osp_get_vts_opts_t opts, gchar **str)
| Get filtered set of VTs from an OSP server.
int | osp_delete_scan (osp_connection_t *connection, const char *scan_id)
| Delete a scan from an OSP server.
int | osp_get_performance_ext (osp_connection_t *connection, osp_get_performance_opts_t opts, char **graph, char **error)
| Get performance graphics from an OSP server.
osp_scan_status_t | osp_get_scan_status_ext (osp_connection_t *connection, osp_get_scan_status_opts_t opts, char **error)
| Get a scan status from an OSP server.
int | osp_get_scan_pop (osp_connection_t *connection, const char *scan_id, char **report_xml, int details, int pop_results, char **error)
| Get a scan from an OSP server, optionally removing the results.
int | osp_get_scan (osp_connection_t *connection, const char *scan_id, char **report_xml, int details, char **error)
| Get a scan from an OSP server.
int | osp_stop_scan (osp_connection_t *connection, const char *scan_id, char **error)
| Stop a scan on an OSP server.
static void | option_concat_as_xml (gpointer key, gpointer value, gpointer pstr)
| Concatenate options as xml.
int | osp_start_scan (osp_connection_t *connection, const char *target, const char *ports, GHashTable *options, const char *scan_id, char **error)
| Start an OSP scan against a target.
static void | credential_append_as_xml (osp_credential_t *credential, GString *xml_string)
| Concatenate a credential as XML.
static void | target_append_as_xml (osp_target_t *target, GString *xml_string)
| Concatenate a target as XML.
static void | vt_group_append_as_xml (osp_vt_group_t *vt_group, GString *xml_string)
| Append VT groups as XML to a string buffer.
static void | vt_value_append_as_xml (gpointer id, gchar *value, GString *xml_string)
| Append VT values as XML to a string buffer.
static void | vt_single_append_as_xml (osp_vt_single_t *vt_single, GString *xml_string)
| Append single VTs as XML to a string buffer.
int | osp_start_scan_ext (osp_connection_t *connection, osp_start_scan_opts_t opts, char **error)
| Start an OSP scan against a target.
static osp_param_type_t | osp_param_str_to_type (const char *str)
| Get an OSP parameter's type from its string format.
const char * | osp_param_type_str (const osp_param_t *param)
| Get an OSP parameter in string format form its type.
int | osp_get_scanner_details (osp_connection_t *connection, char **desc, GSList **params)
| Get an OSP scanner's details.
osp_param_t * | osp_param_new (void)
| Create a new OSP parameter.
const char * | osp_param_id (const osp_param_t *param)
| Get an OSP parameter's id.
const char * | osp_param_name (const osp_param_t *param)
| Get an OSP parameter's name.
const char * | osp_param_desc (const osp_param_t *param)
| Get an OSP parameter's description.
const char * | osp_param_default (const osp_param_t *param)
| Get an OSP parameter's default value.
int | osp_param_mandatory (const osp_param_t *param)
| Get an OSP parameter's mandatory value.
void | osp_param_free (osp_param_t *param)
| Free an OSP parameter.
osp_credential_t * | osp_credential_new (const char *type, const char *service, const char *port)
| Allocate and initialize a new OSP credential.
void | osp_credential_free (osp_credential_t *credential)
| Free an OSP credential.
const gchar * | osp_credential_get_auth_data (osp_credential_t *credential, const char *name)
| Get authentication data from an OSP credential.
void | osp_credential_set_auth_data (osp_credential_t *credential, const char *name, const char *value)
| Get authentication data from an OSP credential.
osp_target_t * | osp_target_new (const char *hosts, const char *ports, const char *exclude_hosts, int alive_test, int reverse_lookup_unify, int reverse_lookup_only)
| Create a new OSP target.
void | osp_target_set_finished_hosts (osp_target_t *target, const char *finished_hosts)
| Set the finished hosts of an OSP target.
void | osp_target_free (osp_target_t *target)
| Free an OSP target, including all added credentials.
void | osp_target_add_alive_test_methods (osp_target_t *target, gboolean icmp, gboolean tcp_syn, gboolean tcp_ack, gboolean arp, gboolean consider_alive)
| Add alive test methods to OSP target.
void | osp_target_add_credential (osp_target_t *target, osp_credential_t *credential)
| Add a credential to an OSP target.
osp_vt_group_t * | osp_vt_group_new (const char *filter)
| Create a new OSP VT group.
void | osp_vt_group_free (osp_vt_group_t *vt_group)
| Free a OSP VT group.
osp_vt_single_t * | osp_vt_single_new (const char *vt_id)
| Create a new single OSP VT.
void | osp_vt_single_free (osp_vt_single_t *vt_single)
| Free a single OSP VT, including all preference values.
void | osp_vt_single_add_value (osp_vt_single_t *vt_single, const char *name, const char *value)
| Add a preference value to an OSP VT. This creates a copy of the name and value.

## Detailed Description

API for Open Scanner Protocol communication.

## Macro Definition Documentation

## G_LOG_DOMAIN

#define G_LOG_DOMAIN "libgvm osp"

GLib log domain.

## Function Documentation

## credential_append_as_xml()

void credential_append_as_xml | ( | osp_credential_t * | credential,
|  | GString * | xml_string )

static

Concatenate a credential as XML.

Parameters

  [in] | credential | Credential data.
  [in,out] | xml_string | XML string buffer to append to.

## option_concat_as_xml()

void option_concat_as_xml | ( | gpointer | key,
|  | gpointer | value,
|  | gpointer | pstr )

static

Concatenate options as xml.

Parameters

  [in] | key | Tag name for xml element.
  [in] | value | Text for xml element.
  [in,out] | pstr | Parameters as xml concatenated xml elements.

## osp_check_feed()

int osp_check_feed | ( | osp_connection_t * | connection,
|  | int * | lockfile_in_use,
|  | int * | self_test_exit_error,
|  | char ** | self_test_error_msg,
|  | char ** | cmd_error )

Gets additional status info about the feed.

The lockfile_in_use and self_test_exit_error fields will be set to -1 if the corresponding elements are missing.

Parameters

  [in] | connection | Connection to an OSP server.
  [out] | lockfile_in_use | Whether the lockfile is in use.
  [out] | self_test_exit_error | Whether the sync script self check failed.
  [out] | self_test_error_msg | Self check error message if one occurred.
  [out] | cmd_error | Error message of the OSP command.

Returns
  0 if success, 1 if error.

## osp_connection_close()

void osp_connection_close | ( | osp_connection_t * | connection | ) |

Close a connection to an OSP server.

Parameters

  [in] | connection | Connection to OSP server to close.

## osp_credential_free()

void osp_credential_free | ( | osp_credential_t * | credential | ) |

Free an OSP credential.

Parameters

  [in] | credential | The credential to free.

## osp_credential_get_auth_data()

const gchar * osp_credential_get_auth_data | ( | osp_credential_t * | credential,
|  | const char * | name )

Get authentication data from an OSP credential.

Parameters

  [in] | credential | The credential to get the data from.
  [in] | name | The name of the data item to get.

Returns
  The requested authentication data or NULL if not available.

## osp_credential_new()

osp_credential_t * osp_credential_new | ( | const char * | type,
|  | const char * | service,
|  | const char * | port )

Allocate and initialize a new OSP credential.

Parameters

  [in] | type | The credential type.
  [in] | service | The service the credential is for.
  [in] | port | The port.

Returns
  New osp credential.

## osp_credential_set_auth_data()

void osp_credential_set_auth_data | ( | osp_credential_t * | credential,
|  | const char * | name,
|  | const char * | value )

Get authentication data from an OSP credential.

Parameters

  [in] | credential | The credential to get the data from.
  [in] | name | The name of the data item to get.
  [in] | value | The authentication data or NULL to unset.

## osp_delete_scan()

int osp_delete_scan | ( | osp_connection_t * | connection,
|  | const char * | scan_id )

Delete a scan from an OSP server.

Parameters

  [in] | connection | Connection to an OSP server.
  [in] | scan_id | ID of scan to delete.

Returns
  0 if success, 1 if error.

## osp_get_performance_ext()

int osp_get_performance_ext | ( | osp_connection_t * | connection,
|  | osp_get_performance_opts_t | opts,
|  | char ** | graph,
|  | char ** | error )

Get performance graphics from an OSP server.

Parameters

  [in] | connection | Connection to an OSP server.
  [in] | opts | Struct containing the options to apply.
  [out] | graph | Graphic base64 encoded.
  [out] | error | Pointer to error, if any.

Returns
  0 if success, -1 if error.

## osp_get_scan()

int osp_get_scan | ( | osp_connection_t * | connection,
|  | const char * | scan_id,
|  | char ** | report_xml,
|  | int | details,
|  | char ** | error )

Get a scan from an OSP server.

Parameters

  [in] | connection | Connection to an OSP server.
  [in] | scan_id | ID of scan to get.
  [out] | report_xml | Scans report.
  [in] | details | 0 for no scan details, 1 otherwise.
  [out] | error | Pointer to error, if any.

Returns
  Scan progress if success, -1 if error.

## osp_get_scan_pop()

int osp_get_scan_pop | ( | osp_connection_t * | connection,
|  | const char * | scan_id,
|  | char ** | report_xml,
|  | int | details,
|  | int | pop_results,
|  | char ** | error )

Get a scan from an OSP server, optionally removing the results.

Parameters

  [in] | connection | Connection to an OSP server.
  [in] | scan_id | ID of scan to get.
  [out] | report_xml | Scans report.
  [in] | details | 0 for no scan details, 1 otherwise.
  [in] | pop_results | 0 to leave results, 1 to pop results from scanner.
  [out] | error | Pointer to error, if any.

Returns
  Scan progress if success, -1 if error.

## osp_get_scan_status_ext()

osp_scan_status_t osp_get_scan_status_ext | ( | osp_connection_t * | connection,
|  | osp_get_scan_status_opts_t | opts,
|  | char ** | error )

Get a scan status from an OSP server.

Parameters

  [in] | connection | Connection to an OSP server.
  [in] | opts | Struct containing the options to apply.
  [out] | error | Pointer to error, if any.

Returns
  Osp scan status

## osp_get_scanner_details()

int osp_get_scanner_details | ( | osp_connection_t * | connection,
|  | char ** | desc,
|  | GSList ** | params )

Get an OSP scanner's details.

Parameters

  [in] | connection | Connection to an OSP server.
  [out] | desc | Scanner's description.
  [out] | params | Scanner's parameters.

Returns
  0 if success, 1 if failure.

## osp_get_version()

int osp_get_version | ( | osp_connection_t * | connection,
|  | char ** | s_name,
|  | char ** | s_version,
|  | char ** | d_name,
|  | char ** | d_version,
|  | char ** | p_name,
|  | char ** | p_version )

Get the scanner version from an OSP server.

Parameters

  [in] | connection | Connection to an OSP server.
  [out] | s_name | Parsed scanner name.
  [out] | s_version | Parsed scanner version.
  [out] | d_name | Parsed scanner name.
  [out] | d_version | Parsed scanner version.
  [out] | p_name | Parsed scanner name.
  [out] | p_version | Parsed scanner version.

Returns
  0 if success, 1 if error.

## osp_get_vts()

int osp_get_vts | ( | osp_connection_t * | connection,
|  | entity_t * | vts )

Get all VTs from an OSP server.

Parameters

  [in] | connection | Connection to an OSP server.
  [out] | vts | VTs.

Returns
  0 if success, 1 if error.

## osp_get_vts_ext()

int osp_get_vts_ext | ( | osp_connection_t * | connection,
|  | osp_get_vts_opts_t | opts,
|  | entity_t * | vts )

Get filtered set of VTs from an OSP server.

Parameters

  [in] | connection | Connection to an OSP server.
  [in] | opts | Struct containing the options to apply.
  [out] | vts | VTs.

Returns
  0 if success, 1 if error.

## osp_get_vts_ext_str()

int osp_get_vts_ext_str | ( | osp_connection_t * | connection,
|  | osp_get_vts_opts_t | opts,
|  | gchar ** | str )

Get filtered set of VTs from an OSP server.

Parameters

  [in] | connection | Connection to an OSP server.
  [in] | opts | Struct containing the options to apply.
  [out] | str | Response.

Returns
  0 if success, 1 if error.

## osp_get_vts_feed_info()

int osp_get_vts_feed_info | ( | osp_connection_t * | connection,
|  | char ** | vts_version,
|  | char ** | feed_name,
|  | char ** | feed_vendor,
|  | char ** | feed_home,
|  | char ** | error )

Get the VTs version as well as other feed info from an OSP server.

Parameters

  [in] | connection | Connection to an OSP server.
  [out] | vts_version | Parsed VTs feed version.
  [out] | feed_name | Parsed VTs feed name.
  [out] | feed_vendor | Parsed VTs feed vendor.
  [out] | feed_home | Parsed VTs feed home URL.
  [out] | error | Pointer to error, if any.

Returns
  0 if success, 1 if error.

## osp_get_vts_version()

int osp_get_vts_version | ( | osp_connection_t * | connection,
|  | char ** | vts_version,
|  | char ** | error )

Get the VTs version from an OSP server.

Parameters

  [in] | connection | Connection to an OSP server.
  [out] | vts_version | Parsed scanner version.
  [out] | error | Pointer to error, if any.

Returns
  0 if success, 1 if error.

## osp_param_default()

const char * osp_param_default | ( | const osp_param_t * | param | ) |

Get an OSP parameter's default value.

Parameters

  [in] | param | OSP parameter.

Returns
  Default value of OSP parameter.

## osp_param_desc()

const char * osp_param_desc | ( | const osp_param_t * | param | ) |

Get an OSP parameter's description.

Parameters

  [in] | param | OSP parameter.

Returns
  Description of OSP parameter.

## osp_param_free()

void osp_param_free | ( | osp_param_t * | param | ) |

Free an OSP parameter.

Parameters

  [in] | param | OSP parameter to destroy.

## osp_param_id()

const char * osp_param_id | ( | const osp_param_t * | param | ) |

Get an OSP parameter's id.

Parameters

  [in] | param | OSP parameter.

Returns
  ID of OSP parameter.

## osp_param_mandatory()

int osp_param_mandatory | ( | const osp_param_t * | param | ) |

Get an OSP parameter's mandatory value.

Parameters

  [in] | param | OSP parameter.

Returns
  Mandatory value of OSP parameter.

## osp_param_name()

const char * osp_param_name | ( | const osp_param_t * | param | ) |

Get an OSP parameter's name.

Parameters

  [in] | param | OSP parameter.

Returns
  Name of OSP parameter.

## osp_param_new()

osp_param_t * osp_param_new | ( | void |  | ) |

Create a new OSP parameter.

Returns
  New OSP parameter.

## osp_param_str_to_type()

osp_param_type_t osp_param_str_to_type | ( | const char * | str | ) |

static

Get an OSP parameter's type from its string format.

Parameters

  [in] | str | OSP parameter in string format.

Returns
  OSP parameter type.

## osp_param_type_str()

const char * osp_param_type_str | ( | const osp_param_t * | param | ) |

Get an OSP parameter in string format form its type.

Parameters

  [in] | param | OSP parameter.

Returns
  OSP parameter in string format.

## osp_send_command() [1/2]

int osp_send_command | ( | osp_connection_t * | ,
|  | entity_t * | ,
|  | static intosp_send_command_str (osp_connection_t | const char *,
|  |  | ... )

static

## osp_send_command() [2/2]

int osp_send_command | ( | osp_connection_t * | connection,
|  | entity_t * | response,
|  | const char * | fmt,
|  |  | ... )

Send a command to an OSP server.

Parameters

  [in] | connection | Connection to OSP server.
  [out] | response | Response from OSP server.
  [in] | fmt | OSP Command to send.

Returns
  0 and response, 1 if error.

## osp_send_command_str()

int osp_send_command_str | ( | osp_connection_t * | connection,
|  | gchar ** | str,
|  | const char * | fmt,
|  |  | ... )

static

Send a command to an OSP server.

Parameters

  [in] | connection | Connection to OSP server.
  [out] | str | Response from OSP server.
  [in] | fmt | OSP Command to send.

Returns
  0 and response, 1 if error.

## osp_start_scan()

int osp_start_scan | ( | osp_connection_t * | connection,
|  | const char * | target,
|  | const char * | ports,
|  | GHashTable * | options,
|  | const char * | scan_id,
|  | char ** | error )

Start an OSP scan against a target.

Parameters

  [in] | connection | Connection to an OSP server.
  [in] | target | Target host to scan.
  [in] | ports | List of ports to scan.
  [in] | options | Table of scan options.
  [in] | scan_id | uuid to set for scan, null otherwise.
  [out] | error | Pointer to error, if any.

Returns
  0 on success, -1 otherwise.

## osp_start_scan_ext()

int osp_start_scan_ext | ( | osp_connection_t * | connection,
|  | osp_start_scan_opts_t | opts,
|  | char ** | error )

Start an OSP scan against a target.

Parameters

  [in] | connection | Connection to an OSP server.
  [in] | opts | Struct containing the options to apply.
  [out] | error | Pointer to error, if any.

Returns
  0 on success, -1 otherwise.

## osp_stop_scan()

int osp_stop_scan | ( | osp_connection_t * | connection,
|  | const char * | scan_id,
|  | char ** | error )

Stop a scan on an OSP server.

Parameters

  [in] | connection | Connection to an OSP server.
  [in] | scan_id | ID of scan to delete.
  [out] | error | Pointer to error, if any.

Returns
  Scan progress if success, -1 if error.

## osp_target_add_alive_test_methods()

void osp_target_add_alive_test_methods | ( | osp_target_t * | target,
|  | gboolean | icmp,
|  | gboolean | tcp_syn,
|  | gboolean | tcp_ack,
|  | gboolean | arp,
|  | gboolean | consider_alive )

Add alive test methods to OSP target.

Parameters

  [in] | target | The OSP target to add the methods to.
  [in] | icmp | Use ICMP ping.
  [in] | tcp_syn | Use TCP-SYN ping.
  [in] | tcp_ack | Use TCP-ACK ping.
  [in] | arp | Use ARP ping.
  [in] | consider_alive | Consider host to be alive.

## osp_target_add_credential()

void osp_target_add_credential | ( | osp_target_t * | target,
|  | osp_credential_t * | credential )

Add a credential to an OSP target.

Parameters

  [in] | target | The OSP target to add the credential to.
  [in] | credential | The credential to add. Will be freed with target.

## osp_target_free()

void osp_target_free | ( | osp_target_t * | target | ) |

Free an OSP target, including all added credentials.

Parameters

  [in] | target | The OSP target to free.

## osp_target_new()

osp_target_t * osp_target_new | ( | const char * | hosts,
|  | const char * | ports,
|  | const char * | exclude_hosts,
|  | int | alive_test,
|  | int | reverse_lookup_unify,
|  | int | reverse_lookup_only )

Create a new OSP target.

Parameters

  [in] | hosts | The hostnames of the target.
  [in] | ports | The ports of the target.
  [in] | exclude_hosts | The excluded hosts of the target.
  [in] | alive_test | The alive test method of the target.
  [in] | reverse_lookup_unify | Lookup flag.
  [in] | reverse_lookup_only | Lookup flag.

Returns
  The newly allocated osp_target_t.

## osp_target_set_finished_hosts()

void osp_target_set_finished_hosts | ( | osp_target_t * | target,
|  | const char * | finished_hosts )

Set the finished hosts of an OSP target.

Parameters

  [in] | target | The OSP target to modify.
  [in] | finished_hosts | The hostnames to consider finished.

## osp_vt_group_free()

void osp_vt_group_free | ( | osp_vt_group_t * | vt_group | ) |

Free a OSP VT group.

Parameters

  [in] | vt_group | The VT group to free.

## osp_vt_group_new()

osp_vt_group_t * osp_vt_group_new | ( | const char * | filter | ) |

Create a new OSP VT group.

Parameters

  [in] | filter | The filter string for the VT group.

Returns
  The newly allocated VT group.

## osp_vt_single_add_value()

void osp_vt_single_add_value | ( | osp_vt_single_t * | vt_single,
|  | const char * | name,
|  | const char * | value )

Add a preference value to an OSP VT. This creates a copy of the name and value.

Parameters

  [in] | vt_single | The VT to add the preference to.
  [in] | name | The name / identifier of the preference.
  [in] | value | The value of the preference.

## osp_vt_single_free()

void osp_vt_single_free | ( | osp_vt_single_t * | vt_single | ) |

Free a single OSP VT, including all preference values.

Parameters

  [in] | vt_single | The OSP VT to free.

## osp_vt_single_new()

osp_vt_single_t * osp_vt_single_new | ( | const char * | vt_id | ) |

Create a new single OSP VT.

Parameters

  [in] | vt_id | The id of the VT.

Returns
  The newly allocated single VT.

## target_append_as_xml()

void target_append_as_xml | ( | osp_target_t * | target,
|  | GString * | xml_string )

static

Concatenate a target as XML.

Parameters

  [in] | target | Target data.
  [in,out] | xml_string | XML string buffer to append to.

## vt_group_append_as_xml()

void vt_group_append_as_xml | ( | osp_vt_group_t * | vt_group,
|  | GString * | xml_string )

static

Append VT groups as XML to a string buffer.

Parameters

  [in] | vt_group | VT group data.
  [in,out] | xml_string | XML string buffer to append to.

## vt_single_append_as_xml()

void vt_single_append_as_xml | ( | osp_vt_single_t * | vt_single,
|  | GString * | xml_string )

static

Append single VTs as XML to a string buffer.

Parameters

  [in] | vt_single | Single VT data.
  [in,out] | xml_string | XML string buffer to append to.

## vt_value_append_as_xml()

void vt_value_append_as_xml | ( | gpointer | id,
|  | gchar * | value,
|  | GString * | xml_string )

static

Append VT values as XML to a string buffer.

Parameters

  [in] | id | Identifier of the vt_value.
  [in] | value | The value of the vt_value.
  [in,out] | xml_string | XML string buffer to append to.