OpenVAS Libraries  9.0.3
osp.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct osp_connection osp_connection_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
}
 

Functions

osp_connection_tosp_connection_new (const char *, int, const char *, const char *, const char *)
 
int osp_get_version (osp_connection_t *, char **, char **, char **, char **, char **, char **)
 
int osp_start_scan (osp_connection_t *, const char *, const char *, GHashTable *, const char *, char **)
 
int osp_get_scan (osp_connection_t *, const char *, char **, int, char **)
 
int osp_delete_scan (osp_connection_t *, const char *)
 
int osp_stop_scan (osp_connection_t *, const char *, char **)
 
int osp_get_scanner_details (osp_connection_t *, char **, GSList **)
 
osp_param_tosp_param_new (void)
 
const char * osp_param_id (const osp_param_t *)
 
const char * osp_param_name (const osp_param_t *)
 
const char * osp_param_desc (const osp_param_t *)
 
const char * osp_param_default (const osp_param_t *)
 
const char * osp_param_type_str (const osp_param_t *)
 
int osp_param_mandatory (const osp_param_t *)
 
void osp_param_free (osp_param_t *)
 
void osp_connection_close (osp_connection_t *)
 

Typedef Documentation

◆ osp_connection_t

Definition at line 30 of file osp.h.

◆ osp_param_t

typedef struct osp_param osp_param_t

Definition at line 43 of file osp.h.

Enumeration Type Documentation

◆ osp_param_type_t

Enumerator
OSP_PARAM_TYPE_INT 
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 

Definition at line 32 of file osp.h.

Function Documentation

◆ osp_connection_close()

void osp_connection_close ( osp_connection_t )

Definition at line 134 of file osp.c.

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

135 {
136  if (!connection)
137  return;
138 
139  openvas_server_close (connection->socket, connection->session);
140  g_free (connection->host);
141  g_free (connection);
142 }
int openvas_server_close(int socket, gnutls_session_t session)
Close a server connection and its 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_delete_scan()

int osp_delete_scan ( osp_connection_t ,
const char *   
)

Definition at line 240 of file osp.c.

241 {
242  entity_t entity;
243  int ret = 0;
244  const char *status;
245 
246  if (!connection)
247  return 1;
248 
249  ret = osp_send_command (connection, &entity, "<delete_scan scan_id='%s'/>",
250  scan_id);
251  if (ret)
252  return 1;
253 
254  /* Check response status. */
255  status = entity_attribute (entity, "status");
256  assert (status);
257  if (strcmp (status, "200"))
258  ret = 1;
259 
260  free_entity (entity);
261  return ret;
262 }
XML element.
Definition: xml.h:48
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xml.c:241
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xml.c:148

◆ osp_get_scan()

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

Definition at line 274 of file osp.c.

276 {
277  entity_t entity, child;
278  GString *string;
279  int progress;
280  int rc;
281 
282  assert (connection);
283  assert (scan_id);
284  rc = osp_send_command
285  (connection, &entity, "<get_scans scan_id='%s' details='%d'/>",
286  scan_id, details ? 1 : 0);
287  if (rc)
288  {
289  if (error)
290  *error = g_strdup ("Couldn't send get_scans command to scanner");
291  return -1;
292  }
293 
294  child = entity_child (entity, "scan");
295  if (!child)
296  {
297  const char *text = entity_attribute (entity, "status_text");
298 
299  assert (text);
300  if (error)
301  *error = g_strdup (text);
302  free_entity (entity);
303  return -1;
304  }
305  progress = atoi (entity_attribute (child, "progress"));
306  if (report_xml)
307  {
308  string = g_string_new ("");
309  print_entity_to_string (child, string);
310  *report_xml = g_string_free (string, FALSE);
311  }
312  free_entity (entity);
313  return progress;
314 }
XML element.
Definition: xml.h:48
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xml.c:241
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: xml.c:1130
gchar * string
entity_t entity_child(entity_t entity, const char *name)
Get a child of an entity.
Definition: xml.c:220
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xml.c:148

◆ osp_get_scanner_details()

int osp_get_scanner_details ( osp_connection_t ,
char **  ,
GSList **   
)

Definition at line 497 of file osp.c.

499 {
500  entity_t entity, child;
501  entities_t entities;
502 
503  assert (connection);
504 
505  if (osp_send_command (connection, &entity, "<get_scanner_details/>"))
506  return 1;
507  if (params)
508  {
509  child = entity_child (entity, "scanner_params");
510  if (!child)
511  {
512  free_entity (entity);
513  return 1;
514  }
515  entities = child->entities;
516  while (entities)
517  {
518  osp_param_t *param;
519 
520  child = entities->data;
521  param = osp_param_new ();
522  param->id = g_strdup (entity_attribute (child, "id"));
523  param->type = osp_param_str_to_type (entity_attribute (child, "type"));
524  param->name = g_strdup (entity_text (entity_child (child, "name")));
525  param->desc = g_strdup (entity_text (entity_child (child,
526  "description")));
527  param->def = g_strdup (entity_text (entity_child (child,
528  "default")));
529  if (entity_child (child, "mandatory"))
530  param->mandatory = atoi (entity_text
531  (entity_child (child, "mandatory")));
532  *params = g_slist_append (*params, param);
533  entities = next_entities (entities);
534  }
535  }
536  if (desc)
537  {
538  child = entity_child (entity, "description");
539  assert (child);
540  *desc = g_strdup (entity_text (child));
541  }
542 
543  free_entity (entity);
544  return 0;
545 }
Definition: osp.c:44
char * desc
Definition: osp.c:47
osp_param_t * osp_param_new(void)
Definition: osp.c:552
char * entity_text(entity_t entity)
Get the text an entity.
Definition: xml.c:178
XML element.
Definition: xml.h:48
entities_t entities
Children.
Definition: xml.h:53
char * name
Definition: osp.c:46
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xml.c:241
entities_t next_entities(entities_t entities)
Return all the entities from an entities_t after the first.
Definition: xml.c:100
osp_param_type_t type
Definition: osp.c:49
char * def
Definition: osp.c:48
GSList * entities_t
Definition: xml.h:43
entity_t entity_child(entity_t entity, const char *name)
Get a child of an entity.
Definition: xml.c:220
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xml.c:148
int mandatory
Definition: osp.c:50
char * id
Definition: osp.c:45

◆ osp_get_version()

int osp_get_version ( osp_connection_t ,
char **  ,
char **  ,
char **  ,
char **  ,
char **  ,
char **   
)

Definition at line 157 of file osp.c.

160 {
161  entity_t entity, child, gchild;
162 
163  if (!connection)
164  return 1;
165 
166  if (osp_send_command (connection, &entity, "<get_version/>"))
167  return 1;
168 
169  child = entity_child (entity, "scanner");
170  if (!child)
171  goto err_get_version;
172  gchild = entity_child (child, "name");
173  if (!gchild)
174  goto err_get_version;
175  if (s_name)
176  *s_name = g_strdup (entity_text (gchild));
177  gchild = entity_child (child, "version");
178  if (!gchild)
179  goto err_get_version;
180  if (s_version)
181  *s_version = g_strdup (entity_text (gchild));
182 
183  child = entity_child (entity, "daemon");
184  if (!child)
185  goto err_get_version;
186  gchild = entity_child (child, "name");
187  if (!gchild)
188  goto err_get_version;
189  if (d_name)
190  *d_name = g_strdup (entity_text (gchild));
191  gchild = entity_child (child, "version");
192  if (!gchild)
193  goto err_get_version;
194  if (d_version)
195  *d_version = g_strdup (entity_text (gchild));
196 
197  child = entity_child (entity, "protocol");
198  if (!child)
199  goto err_get_version;
200  gchild = entity_child (child, "name");
201  if (!gchild)
202  goto err_get_version;
203  if (p_name)
204  *p_name = g_strdup (entity_text (gchild));
205  gchild = entity_child (child, "version");
206  if (!gchild)
207  goto err_get_version;
208  if (p_version)
209  *p_version = g_strdup (entity_text (gchild));
210 
211  free_entity (entity);
212  return 0;
213 
214 err_get_version:
215  g_warning ("Erroneous OSP <get_version/> response.");
216  if (s_name)
217  g_free (*s_name);
218  if (s_version)
219  g_free (*s_version);
220  if (d_name)
221  g_free (*d_name);
222  if (d_version)
223  g_free (*d_version);
224  if (p_name)
225  g_free (*p_name);
226  if (p_version)
227  g_free (*p_version);
228  free_entity (entity);
229  return 1;
230 }
char * entity_text(entity_t entity)
Get the text an entity.
Definition: xml.c:178
XML element.
Definition: xml.h:48
entity_t entity_child(entity_t entity, const char *name)
Get a child of an entity.
Definition: xml.c:220
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xml.c:148

◆ osp_param_default()

const char* osp_param_default ( const osp_param_t )

Definition at line 606 of file osp.c.

References osp_param::def.

607 {
608  assert (param);
609 
610  return param->def;
611 }

◆ osp_param_desc()

const char* osp_param_desc ( const osp_param_t )

Definition at line 592 of file osp.c.

References osp_param::desc.

593 {
594  assert (param);
595 
596  return param->desc;
597 }

◆ osp_param_free()

void osp_param_free ( osp_param_t )

Definition at line 632 of file osp.c.

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

633 {
634  if (!param)
635  return;
636  g_free (param->id);
637  g_free (param->name);
638  g_free (param->desc);
639  g_free (param->def);
640  g_free (param);
641 }

◆ osp_param_id()

const char* osp_param_id ( const osp_param_t )

Definition at line 564 of file osp.c.

References osp_param::id.

565 {
566  assert (param);
567 
568  return param->id;
569 }

◆ osp_param_mandatory()

int osp_param_mandatory ( const osp_param_t )

Definition at line 620 of file osp.c.

References osp_param::mandatory.

621 {
622  assert (param);
623 
624  return param->mandatory;
625 }

◆ osp_param_name()

const char* osp_param_name ( const osp_param_t )

Definition at line 578 of file osp.c.

References osp_param::name.

579 {
580  assert (param);
581 
582  return param->name;
583 }

◆ osp_param_new()

osp_param_t* osp_param_new ( void  )

Definition at line 552 of file osp.c.

553 {
554  return g_malloc0 (sizeof (osp_param_t));
555 }
Definition: osp.c:44

◆ osp_param_type_str()

const char* osp_param_type_str ( const osp_param_t )

Definition at line 462 of file osp.c.

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.

463 {
464  osp_param_type_t type;
465 
466  assert (param);
467  type = param->type;
468  if (type == OSP_PARAM_TYPE_INT)
469  return "integer";
470  else if (type == OSP_PARAM_TYPE_STR)
471  return "string";
472  else if (type == OSP_PARAM_TYPE_PASSWORD)
473  return "password";
474  else if (type == OSP_PARAM_TYPE_FILE)
475  return "file";
476  else if (type == OSP_PARAM_TYPE_BOOLEAN)
477  return "boolean";
478  else if (type == OSP_PARAM_TYPE_OVALDEF_FILE)
479  return "ovaldef_file";
480  else if (type == OSP_PARAM_TYPE_SELECTION)
481  return "selection";
482  else if (type == OSP_PARAM_TYPE_CRD_UP)
483  return "credential_up";
484  assert (0);
485  return NULL;
486 }
osp_param_type_t
Definition: osp.h:32

◆ osp_start_scan()

int osp_start_scan ( osp_connection_t ,
const char *  ,
const char *  ,
GHashTable *  ,
const char *  ,
char **   
)

Definition at line 386 of file osp.c.

389 {
390  entity_t entity;
391  char *options_str = NULL;
392  int status;
393  int rc;
394 
395  assert (connection);
396  assert (target);
397  /* Construct options string. */
398  if (options)
399  g_hash_table_foreach (options, option_concat_as_xml, &options_str);
400 
401  rc = osp_send_command (connection, &entity,
402  "<start_scan target='%s' ports='%s' scan_id='%s'>"
403  "<scanner_params>%s</scanner_params></start_scan>",
404  target, ports ?: "", scan_id ?: "", options_str ?: "");
405  g_free (options_str);
406  if (rc)
407  {
408  if (error)
409  *error = g_strdup ("Couldn't send start_scan command to scanner");
410  return -1;
411  }
412 
413  status = atoi (entity_attribute (entity, "status"));
414  if (status == 200)
415  {
416  free_entity (entity);
417  return 0;
418  }
419  else
420  {
421  const char *text = entity_attribute (entity, "status_text");
422 
423  assert (text);
424  if (error)
425  *error = g_strdup (text);
426  free_entity (entity);
427  return -1;
428  }
429 }
XML element.
Definition: xml.h:48
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xml.c:241
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xml.c:148

◆ osp_stop_scan()

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

Definition at line 324 of file osp.c.

325 {
326  entity_t entity;
327  int rc;
328 
329  assert (connection);
330  assert (scan_id);
331  rc = osp_send_command
332  (connection, &entity, "<stop_scan scan_id='%s'/>", scan_id);
333  if (rc)
334  {
335  if (error)
336  *error = g_strdup ("Couldn't send stop_scan command to scanner");
337  return -1;
338  }
339 
340  rc = atoi (entity_attribute (entity, "status"));
341  if (rc == 200)
342  {
343  free_entity (entity);
344  return 0;
345  }
346  else
347  {
348  const char *text = entity_attribute (entity, "status_text");
349 
350  assert (text);
351  if (error)
352  *error = g_strdup (text);
353  free_entity (entity);
354  return -1;
355  }
356 }
XML element.
Definition: xml.h:48
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xml.c:241
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xml.c:148