Greenbone Vulnerability Management Libraries  11.0.1
osp.h File Reference

API for Open Scanner Protocol communication. More...

#include <glib.h>
#include "../util/xmlutils.h"
Include dependency graph for osp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  osp_get_scan_status_opts_t
 
struct  osp_get_performance_opts_t
 
struct  osp_get_vts_opts_t
 
struct  osp_start_scan_opts_t
 

Typedefs

typedef struct osp_connection osp_connection_t
 
typedef struct osp_credential osp_credential_t
 
typedef struct osp_target osp_target_t
 
typedef struct osp_vt_group osp_vt_group_t
 
typedef struct osp_vt_single osp_vt_single_t
 
typedef struct osp_param osp_param_t
 

Enumerations

enum  osp_param_type_t {
  OSP_PARAM_TYPE_INT = 0, OSP_PARAM_TYPE_STR, OSP_PARAM_TYPE_PASSWORD, OSP_PARAM_TYPE_FILE,
  OSP_PARAM_TYPE_BOOLEAN, OSP_PARAM_TYPE_OVALDEF_FILE, OSP_PARAM_TYPE_SELECTION, OSP_PARAM_TYPE_CRD_UP
}
 OSP parameter types. More...
 
enum  osp_scan_status_t {
  OSP_SCAN_STATUS_ERROR = -1, OSP_SCAN_STATUS_INIT, OSP_SCAN_STATUS_RUNNING, OSP_SCAN_STATUS_STOPPED,
  OSP_SCAN_STATUS_FINISHED
}
 OSP scan status. More...
 

Functions

osp_connection_tosp_connection_new (const char *, int, const char *, const char *, const char *)
 
void osp_connection_close (osp_connection_t *)
 Close a connection to an OSP server. More...
 
int osp_get_version (osp_connection_t *, char **, char **, char **, char **, char **, char **)
 Get the scanner version from an OSP server. More...
 
int osp_get_vts_version (osp_connection_t *, char **)
 Get the VTs version from an OSP server. More...
 
int osp_get_vts (osp_connection_t *, entity_t *)
 Get all VTs from an OSP server. More...
 
int osp_get_vts_ext (osp_connection_t *, osp_get_vts_opts_t, entity_t *)
 Get filtered set of VTs from an OSP server. More...
 
int osp_start_scan (osp_connection_t *, const char *, const char *, GHashTable *, const char *, char **)
 Start an OSP scan against a target. More...
 
int osp_start_scan_ext (osp_connection_t *, osp_start_scan_opts_t, char **)
 Start an OSP scan against a target. More...
 
int osp_get_scan (osp_connection_t *, const char *, char **, int, char **)
 Get a scan from an OSP server. More...
 
int osp_get_scan_pop (osp_connection_t *, const char *, char **, int, int, char **)
 Get a scan from an OSP server, optionally removing the results. More...
 
osp_scan_status_t osp_get_scan_status_ext (osp_connection_t *, osp_get_scan_status_opts_t, char **)
 Get a scan status from an OSP server. More...
 
int osp_delete_scan (osp_connection_t *, const char *)
 Delete a scan from an OSP server. More...
 
int osp_stop_scan (osp_connection_t *, const char *, char **)
 Stop a scan on an OSP server. More...
 
int osp_get_scanner_details (osp_connection_t *, char **, GSList **)
 Get an OSP scanner's details. More...
 
int osp_get_performance_ext (osp_connection_t *, osp_get_performance_opts_t, char **, char **)
 Get performance graphics from an OSP server. More...
 
osp_param_tosp_param_new (void)
 Create a new OSP parameter. More...
 
const char * osp_param_id (const osp_param_t *)
 Get an OSP parameter's id. More...
 
const char * osp_param_name (const osp_param_t *)
 Get an OSP parameter's name. More...
 
const char * osp_param_desc (const osp_param_t *)
 Get an OSP parameter's description. More...
 
const char * osp_param_default (const osp_param_t *)
 Get an OSP parameter's default value. More...
 
const char * osp_param_type_str (const osp_param_t *)
 Get an OSP parameter in string format form its type. More...
 
int osp_param_mandatory (const osp_param_t *)
 Get an OSP parameter's mandatory value. More...
 
void osp_param_free (osp_param_t *)
 Free an OSP parameter. More...
 
osp_credential_tosp_credential_new (const char *, const char *, const char *)
 Allocate and initialize a new OSP credential. More...
 
void osp_credential_free (osp_credential_t *)
 Free an OSP credential. More...
 
const gchar * osp_credential_get_auth_data (osp_credential_t *, const char *)
 Get authentication data from an OSP credential. More...
 
void osp_credential_set_auth_data (osp_credential_t *, const char *, const char *)
 Get authentication data from an OSP credential. More...
 
osp_target_tosp_target_new (const char *, const char *, const char *)
 
void osp_target_set_finished_hosts (osp_target_t *, const char *)
 
void osp_target_free (osp_target_t *)
 
void osp_target_add_credential (osp_target_t *, osp_credential_t *)
 
osp_vt_group_tosp_vt_group_new (const char *)
 
void osp_vt_group_free (osp_vt_group_t *)
 
osp_vt_single_tosp_vt_single_new (const char *)
 
void osp_vt_single_free (osp_vt_single_t *)
 
void osp_vt_single_add_value (osp_vt_single_t *, const char *, const char *)
 

Detailed Description

API for Open Scanner Protocol communication.

Definition in file osp.h.

Typedef Documentation

◆ osp_connection_t

Definition at line 33 of file osp.h.

◆ osp_credential_t

Definition at line 35 of file osp.h.

◆ osp_param_t

typedef struct osp_param osp_param_t

Definition at line 81 of file osp.h.

◆ osp_target_t

typedef struct osp_target osp_target_t

Definition at line 37 of file osp.h.

◆ osp_vt_group_t

typedef struct osp_vt_group osp_vt_group_t

Definition at line 39 of file osp.h.

◆ osp_vt_single_t

Definition at line 41 of file osp.h.

Enumeration Type Documentation

◆ osp_param_type_t

OSP parameter types.

Enumerator
OSP_PARAM_TYPE_INT 

Integer type.

OSP_PARAM_TYPE_STR 

String type.

OSP_PARAM_TYPE_PASSWORD 

Password type.

OSP_PARAM_TYPE_FILE 

File type.

OSP_PARAM_TYPE_BOOLEAN 

Boolean type.

OSP_PARAM_TYPE_OVALDEF_FILE 

Oval definition type.

OSP_PARAM_TYPE_SELECTION 

Selection type.

OSP_PARAM_TYPE_CRD_UP 

Credential user/pass type.

Definition at line 46 of file osp.h.

◆ osp_scan_status_t

OSP scan status.

Enumerator
OSP_SCAN_STATUS_ERROR 

Error status.

OSP_SCAN_STATUS_INIT 

Init status.

OSP_SCAN_STATUS_RUNNING 

Running status.

OSP_SCAN_STATUS_STOPPED 

Stopped status.

OSP_SCAN_STATUS_FINISHED 

Finished status.

Definition at line 61 of file osp.h.

Function Documentation

◆ osp_connection_close()

void osp_connection_close ( osp_connection_t connection)

Close a connection to an OSP server.

Parameters
[in]connectionConnection to OSP server to close.

Definition at line 224 of file osp.c.

225 {
226  if (!connection)
227  return;
228 
229  if (*connection->host == '/')
230  close (connection->socket);
231  else
232  gvm_server_close (connection->socket, connection->session);
233  g_free (connection->host);
234  g_free (connection);
235 }

References gvm_server_close(), osp_connection::host, osp_connection::session, and osp_connection::socket.

Here is the call graph for this function:

◆ osp_connection_new()

osp_connection_t* osp_connection_new ( const char *  ,
int  ,
const char *  ,
const char *  ,
const char *   
)

◆ osp_credential_free()

void osp_credential_free ( osp_credential_t credential)

Free an OSP credential.

Parameters
[in]credentialThe credential to free.

Definition at line 1325 of file osp.c.

1326 {
1327  if (!credential)
1328  return;
1329 
1330  g_free (credential->type);
1331  g_free (credential->service);
1332  g_free (credential->port);
1333  g_hash_table_destroy (credential->auth_data);
1334  g_free (credential);
1335 }

References osp_credential::auth_data, osp_credential::port, osp_credential::service, and osp_credential::type.

◆ 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]credentialThe credential to get the data from.
[in]nameThe name of the data item to get.
Returns
The requested authentication data or NULL if not available.

Definition at line 1346 of file osp.c.

1348 {
1349  if (credential == NULL || name == NULL)
1350  return NULL;
1351  return g_hash_table_lookup (credential->auth_data, name);
1352 }

References osp_credential::auth_data.

◆ 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]typeThe credential type.
[in]serviceThe service the credential is for.
[in]portThe port.
Returns
New osp credential.

Definition at line 1302 of file osp.c.

1303 {
1304  osp_credential_t *new_credential;
1305 
1306  new_credential = g_malloc0 (sizeof (osp_credential_t));
1307 
1308  new_credential->type = type ? g_strdup (type) : NULL;
1309  new_credential->service = service ? g_strdup (service) : NULL;
1310  new_credential->port = port ? g_strdup (port) : NULL;
1311  new_credential->auth_data = g_hash_table_new_full (g_str_hash,
1312  g_str_equal,
1313  g_free,
1314  g_free);
1315 
1316  return new_credential;
1317 }

References osp_credential::auth_data, osp_credential::port, osp_credential::service, and osp_credential::type.

◆ 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]credentialThe credential to get the data from.
[in]nameThe name of the data item to get.
[in]valueThe authentication data or NULL to unset.

Definition at line 1362 of file osp.c.

References osp_credential::auth_data.

◆ osp_delete_scan()

int osp_delete_scan ( osp_connection_t connection,
const char *  scan_id 
)

Delete a scan from an OSP server.

Parameters
[in]connectionConnection to an OSP server.
[in]scan_idID of scan to delete.
Returns
0 if success, 1 if error.

Definition at line 430 of file osp.c.

431 {
432  entity_t entity;
433  int ret = 0;
434  const char *status;
435 
436  if (!connection)
437  return 1;
438 
439  ret = osp_send_command (connection, &entity, "<delete_scan scan_id='%s'/>",
440  scan_id);
441  if (ret)
442  return 1;
443 
444  /* Check response status. */
445  status = entity_attribute (entity, "status");
446  assert (status);
447  if (strcmp (status, "200"))
448  ret = 1;
449 
450  free_entity (entity);
451  return ret;
452 }

References entity_attribute(), free_entity(), and osp_send_command().

Here is the call graph for this function:

◆ 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]connectionConnection to an OSP server.
[in]optsStruct containing the options to apply.
[out]graphGraphic base64 encoded.
[out]errorPointer to error, if any.
Returns
0 if success, -1 if error.

Definition at line 465 of file osp.c.

468 {
469  entity_t entity;
470  int rc;
471  time_t now;
472 
473  if (!connection)
474  {
475  if (error)
476  *error = g_strdup ("Couldn't send get_performance command "
477  "to scanner. Not valid connection");
478  return -1;
479  }
480 
481  time (&now);
482 
483  if (!opts.titles || !strcmp (opts.titles, "") || opts.start < 0
484  || opts.start > now || opts.end < 0 || opts.end > now)
485  {
486  if (error)
487  *error = g_strdup ("Couldn't send get_performance command "
488  "to scanner. Bad or missing parameters.");
489  return -1;
490  }
491 
492  rc = osp_send_command (connection, &entity,
493  "<get_performance start='%d' "
494  "end='%d' titles='%s'/>",
495  opts.start, opts.end, opts.titles);
496 
497  if (rc)
498  {
499  if (error)
500  *error = g_strdup ("Couldn't send get_performance command to scanner");
501  return -1;
502  }
503 
504  if (graph && entity_text (entity) && strcmp (entity_text (entity), "\0"))
505  *graph = g_strdup (entity_text (entity));
506  else
507  {
508  const char *text = entity_attribute (entity, "status_text");
509 
510  assert (text);
511  if (error)
512  *error = g_strdup (text);
513  free_entity (entity);
514  return -1;
515  }
516 
517  free_entity (entity);
518  return 0;
519 }

References osp_get_performance_opts_t::end, entity_attribute(), entity_text(), free_entity(), osp_send_command(), osp_get_performance_opts_t::start, and osp_get_performance_opts_t::titles.

Here is the call graph for this function:

◆ 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]connectionConnection to an OSP server.
[in]scan_idID of scan to get.
[out]report_xmlScans report.
[in]details0 for no scan details, 1 otherwise.
[out]errorPointer to error, if any.
Returns
Scan progress if success, -1 if error.

Definition at line 664 of file osp.c.

666 {
667  return osp_get_scan_pop (connection, scan_id, report_xml, details, 0, error);
668 }

References osp_get_scan_pop().

Here is the call graph for this function:

◆ 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]connectionConnection to an OSP server.
[in]scan_idID of scan to get.
[out]report_xmlScans report.
[in]details0 for no scan details, 1 otherwise.
[in]pop_results0 to leave results, 1 to pop results from scanner.
[out]errorPointer to error, if any.
Returns
Scan progress if success, -1 if error.

Definition at line 598 of file osp.c.

601 {
602  entity_t entity, child;
603  int progress;
604  int rc;
605 
606  if (!connection)
607  {
608  if (error)
609  *error = g_strdup ("Couldn't send get_scan command "
610  "to scanner. Not valid connection");
611  return -1;
612  }
613  assert (scan_id);
614  rc = osp_send_command (connection, &entity,
615  "<get_scans scan_id='%s'"
616  " details='%d'"
617  " pop_results='%d'/>",
618  scan_id,
619  pop_results ? 1 : 0,
620  details ? 1 : 0);
621  if (rc)
622  {
623  if (error)
624  *error = g_strdup ("Couldn't send get_scans command to scanner");
625  return -1;
626  }
627 
628  child = entity_child (entity, "scan");
629  if (!child)
630  {
631  const char *text = entity_attribute (entity, "status_text");
632 
633  assert (text);
634  if (error)
635  *error = g_strdup (text);
636  free_entity (entity);
637  return -1;
638  }
639  progress = atoi (entity_attribute (child, "progress"));
640  if (report_xml)
641  {
642  GString *string;
643 
644  string = g_string_new ("");
645  print_entity_to_string (child, string);
646  *report_xml = g_string_free (string, FALSE);
647  }
648  free_entity (entity);
649  return progress;
650 }

References entity_attribute(), entity_child(), free_entity(), osp_send_command(), and print_entity_to_string().

Referenced by osp_get_scan().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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]connectionConnection to an OSP server.
[in]scan_idID of scan to get.
[out]errorPointer to error, if any.
Returns
Osp scan status

Definition at line 531 of file osp.c.

533 {
534  entity_t entity, child;
535  int rc;
537 
538  if (!connection)
539  {
540  if (error)
541  *error = g_strdup ("Couldn't send get_scans command "
542  "to scanner. Not valid connection");
543  return status;
544  }
545 
546  assert (opts.scan_id);
547  rc = osp_send_command (connection, &entity,
548  "<get_scans scan_id='%s'"
549  " details='0'"
550  " pop_results='0'/>",
551  opts.scan_id);
552 
553  if (rc)
554  {
555  if (error)
556  *error = g_strdup ("Couldn't send get_scans command to scanner");
557  return status;
558  }
559 
560  child = entity_child (entity, "scan");
561  if (!child)
562  {
563  const char *text = entity_attribute (entity, "status_text");
564 
565  assert (text);
566  if (error)
567  *error = g_strdup (text);
568  free_entity (entity);
569  return status;
570  }
571 
572  if (!strcmp (entity_attribute (child, "status"), "init"))
573  status = OSP_SCAN_STATUS_INIT;
574  else if (!strcmp (entity_attribute (child, "status"), "running"))
575  status = OSP_SCAN_STATUS_RUNNING;
576  else if (!strcmp (entity_attribute (child, "status"), "stopped"))
577  status = OSP_SCAN_STATUS_STOPPED;
578  else if (!strcmp (entity_attribute (child, "status"), "finished"))
579  status = OSP_SCAN_STATUS_FINISHED;
580 
581  free_entity (entity);
582  return status;
583 }

References entity_attribute(), entity_child(), free_entity(), OSP_SCAN_STATUS_ERROR, OSP_SCAN_STATUS_FINISHED, OSP_SCAN_STATUS_INIT, OSP_SCAN_STATUS_RUNNING, OSP_SCAN_STATUS_STOPPED, osp_send_command(), and osp_get_scan_status_opts_t::scan_id.

Here is the call graph for this function:

◆ 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]connectionConnection to an OSP server.
[out]descScanner's description.
[out]paramsScanner's parameters.
Returns
0 if success, 1 if failure.

Definition at line 1138 of file osp.c.

1140 {
1141  entity_t entity, child;
1142  entities_t entities;
1143 
1144  assert (connection);
1145 
1146  if (osp_send_command (connection, &entity, "<get_scanner_details/>"))
1147  return 1;
1148  if (params)
1149  {
1150  child = entity_child (entity, "scanner_params");
1151  if (!child)
1152  {
1153  free_entity (entity);
1154  return 1;
1155  }
1156  entities = child->entities;
1157  while (entities)
1158  {
1159  osp_param_t *param;
1160 
1161  child = entities->data;
1162  param = osp_param_new ();
1163  param->id = g_strdup (entity_attribute (child, "id"));
1164  param->type =
1165  osp_param_str_to_type (entity_attribute (child, "type"));
1166  param->name = g_strdup (entity_text (entity_child (child, "name")));
1167  param->desc =
1168  g_strdup (entity_text (entity_child (child, "description")));
1169  param->def = g_strdup (entity_text (entity_child (child, "default")));
1170  if (entity_child (child, "mandatory"))
1171  param->mandatory =
1172  atoi (entity_text (entity_child (child, "mandatory")));
1173  *params = g_slist_append (*params, param);
1174  entities = next_entities (entities);
1175  }
1176  }
1177  if (desc)
1178  {
1179  child = entity_child (entity, "description");
1180  assert (child);
1181  *desc = g_strdup (entity_text (child));
1182  }
1183 
1184  free_entity (entity);
1185  return 0;
1186 }

References osp_param::def, osp_param::desc, entity_s::entities, entity_attribute(), entity_child(), entity_text(), free_entity(), osp_param::id, osp_param::mandatory, osp_param::name, next_entities(), osp_param_new(), osp_param_str_to_type(), osp_send_command(), and osp_param::type.

Here is the call graph for this function:

◆ 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]connectionConnection to an OSP server.
[out]s_nameParsed scanner name.
[out]s_versionParsed scanner version.
[out]d_nameParsed scanner name.
[out]d_versionParsed scanner version.
[out]p_nameParsed scanner name.
[out]p_versionParsed scanner version.
Returns
0 if success, 1 if error.

Definition at line 251 of file osp.c.

254 {
255  entity_t entity, child, gchild;
256 
257  if (!connection)
258  return 1;
259 
260  if (osp_send_command (connection, &entity, "<get_version/>"))
261  return 1;
262 
263  child = entity_child (entity, "scanner");
264  if (!child)
265  goto err_get_version;
266  gchild = entity_child (child, "name");
267  if (!gchild)
268  goto err_get_version;
269  if (s_name)
270  *s_name = g_strdup (entity_text (gchild));
271  gchild = entity_child (child, "version");
272  if (!gchild)
273  goto err_get_version;
274  if (s_version)
275  *s_version = g_strdup (entity_text (gchild));
276 
277  child = entity_child (entity, "daemon");
278  if (!child)
279  goto err_get_version;
280  gchild = entity_child (child, "name");
281  if (!gchild)
282  goto err_get_version;
283  if (d_name)
284  *d_name = g_strdup (entity_text (gchild));
285  gchild = entity_child (child, "version");
286  if (!gchild)
287  goto err_get_version;
288  if (d_version)
289  *d_version = g_strdup (entity_text (gchild));
290 
291  child = entity_child (entity, "protocol");
292  if (!child)
293  goto err_get_version;
294  gchild = entity_child (child, "name");
295  if (!gchild)
296  goto err_get_version;
297  if (p_name)
298  *p_name = g_strdup (entity_text (gchild));
299  gchild = entity_child (child, "version");
300  if (!gchild)
301  goto err_get_version;
302  if (p_version)
303  *p_version = g_strdup (entity_text (gchild));
304 
305  free_entity (entity);
306  return 0;
307 
308 err_get_version:
309  g_warning ("Erroneous OSP <get_version/> response.");
310  if (s_name)
311  g_free (*s_name);
312  if (s_version)
313  g_free (*s_version);
314  if (d_name)
315  g_free (*d_name);
316  if (d_version)
317  g_free (*d_version);
318  if (p_name)
319  g_free (*p_name);
320  if (p_version)
321  g_free (*p_version);
322  free_entity (entity);
323  return 1;
324 }

References entity_child(), entity_text(), free_entity(), and osp_send_command().

Here is the call graph for this function:

◆ osp_get_vts()

int osp_get_vts ( osp_connection_t connection,
entity_t vts 
)

Get all VTs from an OSP server.

Parameters
[in]connectionConnection to an OSP server.
[out]vtsVTs.
Returns
0 if success, 1 if error.

Definition at line 377 of file osp.c.

378 {
379  if (!connection)
380  return 1;
381 
382  if (vts == NULL)
383  return 1;
384 
385  if (osp_send_command (connection, vts, "<get_vts/>"))
386  return 1;
387 
388  return 0;
389 }

References osp_send_command().

Here is the call graph for this function:

◆ 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]connectionConnection to an OSP server.
[in]optsStruct containing the options to apply.
[out]vtsVTs.
Returns
0 if success, 1 if error.

Definition at line 401 of file osp.c.

402 {
403  if (!connection)
404  return 1;
405 
406  if (vts == NULL)
407  return 1;
408 
409  if (opts.filter)
410  {
411  if (osp_send_command (connection, vts, "<get_vts filter='%s'/>", opts.filter))
412  return 1;
413  return 0;
414  }
415 
416  if (osp_send_command (connection, vts, "<get_vts/>"))
417  return 1;
418  return 0;
419 }

References osp_get_vts_opts_t::filter, and osp_send_command().

Here is the call graph for this function:

◆ osp_get_vts_version()

int osp_get_vts_version ( osp_connection_t connection,
char **  vts_version 
)

Get the VTs version from an OSP server.

Parameters
[in]connectionConnection to an OSP server.
[out]vts_versionParsed scanner version.
Returns
0 if success, 1 if error.

Definition at line 335 of file osp.c.

336 {
337  entity_t entity, vts, version;
338 
339  if (!connection)
340  return 1;
341 
342  if (osp_send_command (connection, &entity, "<get_version/>"))
343  return 1;
344 
345  vts = entity_child (entity, "vts");
346  if (!vts)
347  {
348  g_warning ("%s: element VTS missing.", __FUNCTION__);
349  free_entity (entity);
350  return 1;
351  }
352 
353  version = entity_child (vts, "version");
354  if (!version)
355  {
356  g_warning ("%s: element VERSION missing.", __FUNCTION__);
357  free_entity (entity);
358  return 1;
359  }
360 
361  if (vts_version)
362  *vts_version = g_strdup (entity_text (version));
363 
364  free_entity (entity);
365  return 0;
366 }

References entity_child(), entity_text(), free_entity(), and osp_send_command().

Here is the call graph for this function:

◆ osp_param_default()

const char* osp_param_default ( const osp_param_t param)

Get an OSP parameter's default value.

Parameters
[in]paramOSP parameter.
Returns
Default value of OSP parameter.

Definition at line 1252 of file osp.c.

1253 {
1254  assert (param);
1255 
1256  return param->def;
1257 }

References osp_param::def.

◆ osp_param_desc()

const char* osp_param_desc ( const osp_param_t param)

Get an OSP parameter's description.

Parameters
[in]paramOSP parameter.
Returns
Description of OSP parameter.

Definition at line 1237 of file osp.c.

1238 {
1239  assert (param);
1240 
1241  return param->desc;
1242 }

References osp_param::desc.

◆ osp_param_free()

void osp_param_free ( osp_param_t param)

Free an OSP parameter.

Parameters
[in]paramOSP parameter to destroy.

Definition at line 1280 of file osp.c.

1281 {
1282  if (!param)
1283  return;
1284  g_free (param->id);
1285  g_free (param->name);
1286  g_free (param->desc);
1287  g_free (param->def);
1288  g_free (param);
1289 }

References osp_param::def, osp_param::desc, osp_param::id, and osp_param::name.

◆ osp_param_id()

const char* osp_param_id ( const osp_param_t param)

Get an OSP parameter's id.

Parameters
[in]paramOSP parameter.
Returns
ID of OSP parameter.

Definition at line 1207 of file osp.c.

1208 {
1209  assert (param);
1210 
1211  return param->id;
1212 }

References osp_param::id.

◆ osp_param_mandatory()

int osp_param_mandatory ( const osp_param_t param)

Get an OSP parameter's mandatory value.

Parameters
[in]paramOSP parameter.
Returns
Mandatory value of OSP parameter.

Definition at line 1267 of file osp.c.

1268 {
1269  assert (param);
1270 
1271  return param->mandatory;
1272 }

References osp_param::mandatory.

◆ osp_param_name()

const char* osp_param_name ( const osp_param_t param)

Get an OSP parameter's name.

Parameters
[in]paramOSP parameter.
Returns
Name of OSP parameter.

Definition at line 1222 of file osp.c.

1223 {
1224  assert (param);
1225 
1226  return param->name;
1227 }

References osp_param::name.

◆ osp_param_new()

osp_param_t* osp_param_new ( void  )

Create a new OSP parameter.

Returns
New OSP parameter.

Definition at line 1194 of file osp.c.

1195 {
1196  return g_malloc0 (sizeof (osp_param_t));
1197 }

Referenced by osp_get_scanner_details().

Here is the caller graph for this function:

◆ 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]paramOSP parameter.
Returns
OSP parameter in string format.

Definition at line 1102 of file osp.c.

1103 {
1104  osp_param_type_t type;
1105 
1106  assert (param);
1107  type = param->type;
1108  if (type == OSP_PARAM_TYPE_INT)
1109  return "integer";
1110  else if (type == OSP_PARAM_TYPE_STR)
1111  return "string";
1112  else if (type == OSP_PARAM_TYPE_PASSWORD)
1113  return "password";
1114  else if (type == OSP_PARAM_TYPE_FILE)
1115  return "file";
1116  else if (type == OSP_PARAM_TYPE_BOOLEAN)
1117  return "boolean";
1118  else if (type == OSP_PARAM_TYPE_OVALDEF_FILE)
1119  return "ovaldef_file";
1120  else if (type == OSP_PARAM_TYPE_SELECTION)
1121  return "selection";
1122  else if (type == OSP_PARAM_TYPE_CRD_UP)
1123  return "credential_up";
1124  assert (0);
1125  return NULL;
1126 }

References OSP_PARAM_TYPE_BOOLEAN, OSP_PARAM_TYPE_CRD_UP, OSP_PARAM_TYPE_FILE, OSP_PARAM_TYPE_INT, OSP_PARAM_TYPE_OVALDEF_FILE, OSP_PARAM_TYPE_PASSWORD, OSP_PARAM_TYPE_SELECTION, OSP_PARAM_TYPE_STR, and osp_param::type.

◆ 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]connectionConnection to an OSP server.
[in]targetTarget host to scan.
[in]portsList of ports to scan.
[in]optionsTable of scan options.
[in]scan_iduuid to set for scan, null otherwise.
[out]errorPointer to error, if any.
Returns
0 on success, -1 otherwise.

Definition at line 759 of file osp.c.

762 {
763  entity_t entity;
764  char *options_str = NULL;
765  int status;
766  int rc;
767 
768  if (!connection)
769  {
770  if (error)
771  *error = g_strdup ("Couldn't send start_scan command "
772  "to scanner. Not valid connection");
773  return -1;
774  }
775 
776  assert (target);
777  /* Construct options string. */
778  if (options)
779  g_hash_table_foreach (options, option_concat_as_xml, &options_str);
780 
781  rc = osp_send_command (connection, &entity,
782  "<start_scan target='%s' ports='%s' scan_id='%s'>"
783  "<scanner_params>%s</scanner_params></start_scan>",
784  target, ports ? ports : "", scan_id ? scan_id : "",
785  options_str ? options_str : "");
786  g_free (options_str);
787  if (rc)
788  {
789  if (error)
790  *error = g_strdup ("Couldn't send start_scan command to scanner");
791  return -1;
792  }
793 
794  status = atoi (entity_attribute (entity, "status"));
795  if (status == 200)
796  {
797  free_entity (entity);
798  return 0;
799  }
800  else
801  {
802  const char *text = entity_attribute (entity, "status_text");
803 
804  assert (text);
805  if (error)
806  *error = g_strdup (text);
807  free_entity (entity);
808  return -1;
809  }
810 }

References entity_attribute(), free_entity(), option_concat_as_xml(), and osp_send_command().

Here is the call graph for this function:

◆ 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]connectionConnection to an OSP server.
[in]optsStruct containing the options to apply.
[out]errorPointer to error, if any.
Returns
0 on success, -1 otherwise.

Definition at line 941 of file osp.c.

944 {
945  gchar *scanner_params_xml = NULL;
946  GString *xml;
947  GSList *list_item;
948  int list_count;
949  int rc, status;
950  entity_t entity;
951  gchar *cmd;
952  char filename[] = "/tmp/osp-cmd-XXXXXX";
953  int fd;
954 
955  if (!connection)
956  {
957  if (error)
958  *error = g_strdup ("Couldn't send start_scan command "
959  "to scanner. Not valid connection");
960  return -1;
961  }
962 
963  fd = mkstemp (filename);
964  FILE *file = fdopen (fd, "w");
965 
966  xml = g_string_sized_new (10240);
967  g_string_append (xml, "<start_scan");
968  if (opts.parallel)
969  xml_string_append (xml, " parallel=\"%d\"", opts.parallel);
970  xml_string_append (xml,
971  " scan_id=\"%s\">",
972  opts.scan_id ? opts.scan_id : "");
973 
974  g_string_append (xml, "<targets>");
975  g_slist_foreach (opts.targets, (GFunc) target_append_as_xml, xml);
976  g_string_append (xml, "</targets>");
977 
978  g_string_append (xml, "<scanner_params>");
979  if (opts.scanner_params)
980  {
981  scanner_params_xml = NULL;
982  g_hash_table_foreach (opts.scanner_params,
983  (GHFunc) option_concat_as_xml,
984  &scanner_params_xml);
985  if (scanner_params_xml)
986  g_string_append (xml, scanner_params_xml);
987  g_free (scanner_params_xml);
988  }
989  g_string_append (xml, "</scanner_params>");
990 
991  g_string_append (xml, "<vt_selection>");
992  g_slist_foreach (opts.vt_groups, (GFunc)vt_group_append_as_xml, xml);
993 
994  fprintf (file, "%s", xml->str);
995 
996  g_string_free (xml, TRUE);
997 
998  xml = g_string_new ("");
999  list_item = opts.vts;
1000  list_count = 0;
1001  while (list_item)
1002  {
1003  list_count ++;
1004  vt_single_append_as_xml (list_item->data, xml);
1005 
1006  list_item = list_item->next;
1007 
1008  if (list_count == 1000)
1009  {
1010  fprintf (file, "%s", xml->str);
1011 
1012  g_string_free (xml, TRUE);
1013  xml = g_string_new ("");
1014  list_count = 0;
1015  }
1016  }
1017 
1018  g_string_append (xml, "</vt_selection>");
1019  g_string_append (xml, "</start_scan>");
1020 
1021  fprintf (file, "%s", xml->str);
1022  fflush (file);
1023  fclose (file);
1024  g_string_free (xml, TRUE);
1025 
1026  g_file_get_contents (filename, &cmd, NULL, NULL);
1027 
1028  rc = osp_send_command (connection, &entity, "%s", cmd);
1029 
1030  g_free (cmd);
1031  unlink (filename);
1032 
1033  if (rc)
1034  {
1035  if (error)
1036  *error = g_strdup ("Could not send start_scan command to scanner");
1037  return -1;
1038  }
1039 
1040  status = atoi (entity_attribute (entity, "status"));
1041  if (status == 200)
1042  {
1043  free_entity (entity);
1044  return 0;
1045  }
1046  else
1047  {
1048  const char *text = entity_attribute (entity, "status_text");
1049 
1050  assert (text);
1051  if (error)
1052  *error = g_strdup (text);
1053  free_entity (entity);
1054  return -1;
1055  }
1056 
1057  if (error)
1058  *error = NULL;
1059  free_entity (entity);
1060  return 0;
1061 }

References entity_attribute(), free_entity(), option_concat_as_xml(), osp_send_command(), osp_start_scan_opts_t::parallel, osp_start_scan_opts_t::scan_id, osp_start_scan_opts_t::scanner_params, target_append_as_xml(), osp_start_scan_opts_t::targets, vt_group_append_as_xml(), osp_start_scan_opts_t::vt_groups, vt_single_append_as_xml(), osp_start_scan_opts_t::vts, and xml_string_append().

Here is the call graph for this function:

◆ 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]connectionConnection to an OSP server.
[in]scan_idID of scan to delete.
[out]errorPointer to error, if any.
Returns
Scan progress if success, -1 if error.

Definition at line 680 of file osp.c.

681 {
682  entity_t entity;
683  int rc;
684 
685  if (!connection)
686  {
687  if (error)
688  *error = g_strdup ("Couldn't send stop_scan command "
689  "to scanner. Not valid connection");
690  return -1;
691  }
692  assert (scan_id);
693  rc = osp_send_command (connection, &entity, "<stop_scan scan_id='%s'/>",
694  scan_id);
695  if (rc)
696  {
697  if (error)
698  *error = g_strdup ("Couldn't send stop_scan command to scanner");
699  return -1;
700  }
701 
702  rc = atoi (entity_attribute (entity, "status"));
703  if (rc == 200)
704  {
705  free_entity (entity);
706  return 0;
707  }
708  else
709  {
710  const char *text = entity_attribute (entity, "status_text");
711 
712  assert (text);
713  if (error)
714  *error = g_strdup (text);
715  free_entity (entity);
716  return -1;
717  }
718 }

References entity_attribute(), free_entity(), and osp_send_command().

Here is the call graph for this function:

◆ osp_target_add_credential()

void osp_target_add_credential ( osp_target_t ,
osp_credential_t  
)

◆ osp_target_free()

void osp_target_free ( osp_target_t )

◆ osp_target_new()

osp_target_t* osp_target_new ( const char *  ,
const char *  ,
const char *   
)

◆ osp_target_set_finished_hosts()

void osp_target_set_finished_hosts ( osp_target_t ,
const char *   
)

◆ osp_vt_group_free()

void osp_vt_group_free ( osp_vt_group_t )

◆ osp_vt_group_new()

osp_vt_group_t* osp_vt_group_new ( const char *  )

◆ osp_vt_single_add_value()

void osp_vt_single_add_value ( osp_vt_single_t ,
const char *  ,
const char *   
)

◆ osp_vt_single_free()

void osp_vt_single_free ( osp_vt_single_t )

◆ osp_vt_single_new()

osp_vt_single_t* osp_vt_single_new ( const char *  )
OSP_SCAN_STATUS_FINISHED
@ OSP_SCAN_STATUS_FINISHED
Definition: osp.h:67
osp_start_scan_opts_t::parallel
int parallel
Number of parallel scans.
Definition: osp.h:119
osp_param_new
osp_param_t * osp_param_new(void)
Create a new OSP parameter.
Definition: osp.c:1194
osp_param::mandatory
int mandatory
Definition: osp.c:67
entity_attribute
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xmlutils.c:230
osp_scan_status_t
osp_scan_status_t
OSP scan status.
Definition: osp.h:61
entity_child
entity_t entity_child(entity_t entity, const char *name)
Get a child of an entity.
Definition: xmlutils.c:207
OSP_SCAN_STATUS_RUNNING
@ OSP_SCAN_STATUS_RUNNING
Definition: osp.h:65
OSP_PARAM_TYPE_SELECTION
@ OSP_PARAM_TYPE_SELECTION
Definition: osp.h:54
osp_connection::socket
int socket
Definition: osp.c:52
gvm_server_close
int gvm_server_close(int socket, gnutls_session_t session)
Close a server connection and its socket.
Definition: serverutils.c:513
OSP_PARAM_TYPE_OVALDEF_FILE
@ OSP_PARAM_TYPE_OVALDEF_FILE
Definition: osp.h:53
osp_get_performance_opts_t::end
int end
Definition: osp.h:77
osp_start_scan_opts_t::scanner_params
GHashTable * scanner_params
Table of scanner parameters.
Definition: osp.h:118
entity_s::entities
entities_t entities
Children.
Definition: xmlutils.h:70
osp_credential::auth_data
GHashTable * auth_data
Definition: osp.c:78
osp_send_command
static int osp_send_command(osp_connection_t *, entity_t *, const char *,...)
Send a command to an OSP server.
Definition: osp.c:111
osp_credential::service
gchar * service
Definition: osp.c:76
entity_text
char * entity_text(entity_t entity)
Get the text an entity.
Definition: xmlutils.c:159
vt_group_append_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.
Definition: osp.c:887
osp_get_scan_status_opts_t::scan_id
const char * scan_id
UUID of the scan which get the status from.
Definition: osp.h:72
osp_credential::port
gchar * port
Definition: osp.c:77
osp_start_scan_opts_t::scan_id
const char * scan_id
UUID to set for scan, null otherwise.
Definition: osp.h:120
osp_get_performance_opts_t::start
int start
Definition: osp.h:76
free_entity
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xmlutils.c:129
OSP_PARAM_TYPE_PASSWORD
@ OSP_PARAM_TYPE_PASSWORD
Definition: osp.h:50
OSP_PARAM_TYPE_FILE
@ OSP_PARAM_TYPE_FILE
Definition: osp.h:51
xml_string_append
void xml_string_append(GString *xml, const char *format,...)
Append formatted escaped XML to a string.
Definition: xmlutils.c:1527
osp_get_vts_opts_t::filter
char * filter
the filter to apply for a vt sub-selection.
Definition: osp.h:104
OSP_PARAM_TYPE_BOOLEAN
@ OSP_PARAM_TYPE_BOOLEAN
Definition: osp.h:52
next_entities
entities_t next_entities(entities_t entities)
Return all the entities from an entities_t after the first.
Definition: xmlutils.c:81
osp_start_scan_opts_t::vt_groups
GSList * vt_groups
VT groups to use for the scan.
Definition: osp.h:116
OSP_SCAN_STATUS_ERROR
@ OSP_SCAN_STATUS_ERROR
Definition: osp.h:63
target_append_as_xml
static void target_append_as_xml(osp_target_t *target, GString *xml_string)
Concatenate a target as XML.
Definition: osp.c:856
osp_param_str_to_type
static osp_param_type_t osp_param_str_to_type(const char *str)
Get an OSP parameter's type from its string format.
Definition: osp.c:1071
osp_connection::session
gnutls_session_t session
Definition: osp.c:51
osp_credential::type
gchar * type
Definition: osp.c:75
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.
Definition: osp.c:598
osp_param
Struct holding options for OSP parameters.
Definition: osp.c:60
osp_param::type
osp_param_type_t type
Definition: osp.c:66
osp_param::name
char * name
Definition: osp.c:63
osp_connection::host
char * host
Definition: osp.c:53
osp_get_performance_opts_t::titles
char * titles
Definition: osp.h:78
OSP_PARAM_TYPE_CRD_UP
@ OSP_PARAM_TYPE_CRD_UP
Definition: osp.h:55
OSP_PARAM_TYPE_STR
@ OSP_PARAM_TYPE_STR
Definition: osp.h:49
osp_param::def
char * def
Definition: osp.c:65
OSP_SCAN_STATUS_INIT
@ OSP_SCAN_STATUS_INIT
Definition: osp.h:64
option_concat_as_xml
static void option_concat_as_xml(gpointer key, gpointer value, gpointer pstr)
Concatenate options as xml.
Definition: osp.c:729
entity_s
XML element.
Definition: xmlutils.h:65
osp_param_type_t
osp_param_type_t
OSP parameter types.
Definition: osp.h:46
osp_param::id
char * id
Definition: osp.c:62
OSP_PARAM_TYPE_INT
@ OSP_PARAM_TYPE_INT
Definition: osp.h:48
osp_credential
Struct credential information for OSP.
Definition: osp.c:73
osp_start_scan_opts_t::targets
GSList * targets
Target hosts to scan.
Definition: osp.h:115
vt_single_append_as_xml
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.
Definition: osp.c:918
print_entity_to_string
void print_entity_to_string(entity_t entity, GString *string)
Print an XML entity tree to a GString, appending it if string is not.
Definition: xmlutils.c:1292
OSP_SCAN_STATUS_STOPPED
@ OSP_SCAN_STATUS_STOPPED
Definition: osp.h:66
osp_start_scan_opts_t::vts
GSList * vts
Single VTs to use for the scan.
Definition: osp.h:117
entities_t
GSList * entities_t
Entities.
Definition: xmlutils.h:60
osp_param::desc
char * desc
Definition: osp.c:64