Greenbone Vulnerability Management Libraries 22.8.0
osp.c
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2014-2023 Greenbone AG
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later
4 */
5
11#include "osp.h"
12
13#include "../base/hosts.h" /* for gvm_get_host_type */
14#include "../util/serverutils.h" /* for gvm_server_close, gvm_server_open_w... */
15
16#include <assert.h> /* for assert */
17#include <gnutls/gnutls.h> /* for gnutls_session_int, gnutls_session_t */
18#include <stdarg.h> /* for va_list */
19#include <stdio.h> /* for FILE, fprintf and related functions */
20#include <stdlib.h> /* for NULL, atoi */
21#include <string.h> /* for strcmp, strlen, strncpy */
22#include <sys/socket.h> /* for AF_UNIX, connect, socket, SOCK_STREAM */
23#include <sys/un.h> /* for sockaddr_un, sa_family_t */
24#include <unistd.h> /* for close */
25
26#undef G_LOG_DOMAIN
30#define G_LOG_DOMAIN "libgvm osp"
31
36{
37 gnutls_session_t session;
38 int socket;
39 char *host;
40 int port;
41};
42
47{
48 char *id;
49 char *name;
50 char *desc;
51 char *def;
54};
55
60{
61 gchar *type;
62 gchar *service;
63 gchar *port;
64 GHashTable *auth_data;
65};
66
71{
72 GSList *credentials;
74 gchar *hosts;
75 gchar *ports;
77 /* Alive test methods can be specified either as bitfield or via selection of
78 individual methods */
80 gboolean icmp;
81 gboolean tcp_syn;
82 gboolean tcp_ack;
83 gboolean arp;
87};
88
93{
94 gchar *filter;
95};
96
101{
102 gchar *vt_id;
103 GHashTable *vt_values;
104};
105
106static int
108 __attribute__ ((__format__ (__printf__, 3, 4)));
109
110static int
111osp_send_command_str (osp_connection_t *, gchar **, const char *, ...)
112 __attribute__ ((__format__ (__printf__, 3, 4)));
113
126osp_connection_new (const char *host, int port, const char *cacert,
127 const char *cert, const char *key)
128{
129 osp_connection_t *connection;
130
131 if (host && *host == '/')
132 {
133 struct sockaddr_un addr;
134 int len;
135
136 if (strlen (host) >= sizeof (addr.sun_path))
137 {
138 g_warning ("%s: given host / socket path too long (%zu > %zu bytes)",
139 __func__, strlen (host), sizeof (addr.sun_path) - 1);
140 return NULL;
141 }
142
143 connection = g_malloc0 (sizeof (*connection));
144 connection->socket = socket (AF_UNIX, SOCK_STREAM, 0);
145 if (connection->socket == -1)
146 {
147 g_free (connection);
148 return NULL;
149 }
150
151 addr.sun_family = AF_UNIX;
152 memset (addr.sun_path, 0, sizeof (addr.sun_path));
153 memcpy (addr.sun_path, host, strlen (host));
154 #pragma GCC diagnostic push
155 #pragma GCC diagnostic ignored "-Wstringop-overread"
156 len = strlen (addr.sun_path) + sizeof (addr.sun_family);
157 #pragma GCC diagnostic pop
158 if (connect (connection->socket, (struct sockaddr *) &addr, len) == -1)
159 {
160 close (connection->socket);
161 g_free (connection);
162 return NULL;
163 }
164 }
165 else
166 {
167 if (port <= 0 || port > 65535)
168 return NULL;
169 if (!host || gvm_get_host_type (host) == -1)
170 return NULL;
171 if (!cert || !key || !cacert)
172 return NULL;
173
174 connection = g_malloc0 (sizeof (*connection));
175 connection->socket = gvm_server_open_with_cert (
176 &connection->session, host, port, cacert, cert, key);
177 }
178 if (connection->socket == -1)
179 {
180 g_free (connection);
181 return NULL;
182 }
183
184 connection->host = g_strdup (host);
185 connection->port = port;
186 return connection;
187}
188
198int
200 const char *fmt, ...)
201{
202 va_list ap;
203 int rc = 1;
204
205 va_start (ap, fmt);
206
207 if (!connection || !fmt || !response)
208 goto out;
209
210 if (*connection->host == '/')
211 {
212 if (gvm_socket_vsendf (connection->socket, fmt, ap) == -1)
213 goto out;
214 if (read_entity_s (connection->socket, response))
215 goto out;
216 }
217 else
218 {
219 if (gvm_server_vsendf (&connection->session, fmt, ap) == -1)
220 goto out;
221 if (read_entity (&connection->session, response))
222 goto out;
223 }
224
225 rc = 0;
226
227out:
228 va_end (ap);
229
230 return rc;
231}
232
242static int
243osp_send_command_str (osp_connection_t *connection, gchar **str,
244 const char *fmt, ...)
245{
246 va_list ap;
247 int rc;
248 gvm_connection_t conn;
249
250 rc = 1;
251 *str = NULL;
252
253 va_start (ap, fmt);
254
255 if (!connection || !fmt)
256 goto out;
257
258 if (*connection->host == '/')
259 {
260 if (gvm_socket_vsendf (connection->socket, fmt, ap) == -1)
261 goto out;
262 conn.tls = 0;
263 }
264 else
265 {
266 if (gvm_server_vsendf (&connection->session, fmt, ap) == -1)
267 goto out;
268 conn.tls = 1;
269 }
270
271 conn.socket = connection->socket;
272 conn.session = connection->session;
273 conn.host_string = connection->host;
274 conn.port = connection->port;
275
276 if (read_text_c (&conn, str))
277 goto out;
278
279 rc = 0;
280
281out:
282 va_end (ap);
283
284 return rc;
285}
286
292void
294{
295 if (!connection)
296 return;
297
298 if (*connection->host == '/')
299 close (connection->socket);
300 else
301 gvm_server_close (connection->socket, connection->session);
302 g_free (connection->host);
303 g_free (connection);
304}
305
320int
321osp_check_feed (osp_connection_t *connection, int *lockfile_in_use,
322 int *self_test_exit_error, char **self_test_error_msg,
323 char **cmd_error)
324{
325 entity_t entity, feed, lockfile_entity, exit_error_entity, error_msg_entity;
326 const char *status, *status_text;
327
328 if (!connection)
329 return 1;
330
331 if (osp_send_command (connection, &entity, "<check_feed/>"))
332 return 1;
333
334 status = entity_attribute (entity, "status");
335
336 if (status != NULL && !strcmp (status, "400"))
337 {
338 status_text = entity_attribute (entity, "status_text");
339 g_debug ("%s: %s - %s.", __func__, status, status_text);
340 if (cmd_error)
341 *cmd_error = g_strdup (status_text);
342 free_entity (entity);
343 return 1;
344 }
345
346 feed = entity_child (entity, "feed");
347 if (!feed)
348 {
349 g_warning ("%s: element FEED missing.", __func__);
350 free_entity (entity);
351 return 1;
352 }
353
354 lockfile_entity = entity_child (feed, "lockfile_in_use");
355 exit_error_entity = entity_child (feed, "self_test_exit_error");
356 error_msg_entity = entity_child (feed, "self_test_error_msg");
357
358 if (lockfile_in_use)
359 {
360 if (lockfile_entity)
361 *lockfile_in_use = atoi (entity_text (lockfile_entity));
362 else
363 {
364 g_warning ("%s: element LOCKFILE_IN_USE missing.", __func__);
365 *lockfile_in_use = -1;
366 }
367 }
368
369 if (self_test_exit_error)
370 {
371 if (exit_error_entity)
372 *self_test_exit_error = atoi (entity_text (exit_error_entity));
373 else
374 {
375 g_warning ("%s: element SELF_TEST_EXIT_ERROR missing.", __func__);
376 *self_test_exit_error = -1;
377 }
378 }
379
380 if (self_test_error_msg)
381 {
382 if (self_test_error_msg)
383 {
384 if (entity_text (error_msg_entity))
385 *self_test_error_msg = g_strdup (entity_text (error_msg_entity));
386 else
387 *self_test_error_msg = NULL;
388 }
389 else
390 {
391 g_warning ("%s: element SELF_TEST_ERROR_MSG missing.", __func__);
392 *self_test_error_msg = NULL;
393 }
394 }
395
396 free_entity (entity);
397 return 0;
398}
399
413int
414osp_get_version (osp_connection_t *connection, char **s_name, char **s_version,
415 char **d_name, char **d_version, char **p_name,
416 char **p_version)
417{
418 entity_t entity, child, gchild;
419
420 if (!connection)
421 return 1;
422
423 if (osp_send_command (connection, &entity, "<get_version/>"))
424 return 1;
425
426 child = entity_child (entity, "scanner");
427 if (!child)
428 goto err_get_version;
429 gchild = entity_child (child, "name");
430 if (!gchild)
431 goto err_get_version;
432 if (s_name)
433 *s_name = g_strdup (entity_text (gchild));
434 gchild = entity_child (child, "version");
435 if (!gchild)
436 goto err_get_version;
437 if (s_version)
438 *s_version = g_strdup (entity_text (gchild));
439
440 child = entity_child (entity, "daemon");
441 if (!child)
442 goto err_get_version;
443 gchild = entity_child (child, "name");
444 if (!gchild)
445 goto err_get_version;
446 if (d_name)
447 *d_name = g_strdup (entity_text (gchild));
448 gchild = entity_child (child, "version");
449 if (!gchild)
450 goto err_get_version;
451 if (d_version)
452 *d_version = g_strdup (entity_text (gchild));
453
454 child = entity_child (entity, "protocol");
455 if (!child)
456 goto err_get_version;
457 gchild = entity_child (child, "name");
458 if (!gchild)
459 goto err_get_version;
460 if (p_name)
461 *p_name = g_strdup (entity_text (gchild));
462 gchild = entity_child (child, "version");
463 if (!gchild)
464 goto err_get_version;
465 if (p_version)
466 *p_version = g_strdup (entity_text (gchild));
467
468 free_entity (entity);
469 return 0;
470
471err_get_version:
472 g_warning ("Erroneous OSP <get_version/> response.");
473 if (s_name)
474 g_free (*s_name);
475 if (s_version)
476 g_free (*s_version);
477 if (d_name)
478 g_free (*d_name);
479 if (d_version)
480 g_free (*d_version);
481 if (p_name)
482 g_free (*p_name);
483 if (p_version)
484 g_free (*p_version);
485 free_entity (entity);
486 return 1;
487}
488
498int
499osp_get_vts_version (osp_connection_t *connection, char **vts_version,
500 char **error)
501{
502 entity_t entity, vts;
503 const char *version;
504 const char *status, *status_text;
505 osp_get_vts_opts_t get_vts_opts;
506
507 if (!connection)
508 return 1;
509
510 get_vts_opts = osp_get_vts_opts_default;
511 get_vts_opts.version_only = 1;
512 if (osp_get_vts_ext (connection, get_vts_opts, &entity))
513 return 1;
514
515 status = entity_attribute (entity, "status");
516
517 if (status != NULL && !strcmp (status, "400"))
518 {
519 status_text = entity_attribute (entity, "status_text");
520 g_debug ("%s: %s - %s.", __func__, status, status_text);
521 if (error)
522 *error = g_strdup (status_text);
523 free_entity (entity);
524 return 1;
525 }
526
527 vts = entity_child (entity, "vts");
528 if (!vts)
529 {
530 g_warning ("%s: element VTS missing.", __func__);
531 free_entity (entity);
532 return 1;
533 }
534
535 version = entity_attribute (vts, "vts_version");
536
537 if (vts_version)
538 *vts_version = g_strdup (version);
539
540 free_entity (entity);
541 return 0;
542}
543
556int
557osp_get_vts_feed_info (osp_connection_t *connection, char **vts_version,
558 char **feed_name, char **feed_vendor, char **feed_home,
559 char **error)
560{
561 entity_t entity, vts;
562 const char *version, *name, *vendor, *home;
563 const char *status, *status_text;
564 osp_get_vts_opts_t get_vts_opts;
565
566 if (!connection)
567 return 1;
568
569 get_vts_opts = osp_get_vts_opts_default;
570 get_vts_opts.version_only = 1;
571 if (osp_get_vts_ext (connection, get_vts_opts, &entity))
572 return 1;
573
574 status = entity_attribute (entity, "status");
575
576 if (status != NULL && !strcmp (status, "400"))
577 {
578 status_text = entity_attribute (entity, "status_text");
579 g_debug ("%s: %s - %s.", __func__, status, status_text);
580 if (error)
581 *error = g_strdup (status_text);
582 free_entity (entity);
583 return 1;
584 }
585
586 vts = entity_child (entity, "vts");
587 if (!vts)
588 {
589 g_warning ("%s: element VTS missing.", __func__);
590 free_entity (entity);
591 return 1;
592 }
593
594 version = entity_attribute (vts, "vts_version");
595 name = entity_attribute (vts, "feed_name");
596 vendor = entity_attribute (vts, "feed_vendor");
597 home = entity_attribute (vts, "feed_home");
598
599 if (vts_version)
600 *vts_version = version ? g_strdup (version) : NULL;
601 if (feed_name)
602 *feed_name = name ? g_strdup (name) : NULL;
603 if (feed_vendor)
604 *feed_vendor = vendor ? g_strdup (vendor) : NULL;
605 if (feed_home)
606 *feed_home = home ? g_strdup (home) : NULL;
607
608 free_entity (entity);
609 return 0;
610}
611
620int
622{
623 if (!connection)
624 return 1;
625
626 if (vts == NULL)
627 return 1;
628
629 if (osp_send_command (connection, vts, "<get_vts/>"))
630 return 1;
631
632 return 0;
633}
634
644int
646 entity_t *vts)
647{
648 if (!connection)
649 return 1;
650
651 if (vts == NULL)
652 return 1;
653
654 if (opts.version_only == 1)
655 {
656 if (osp_send_command (connection, vts, "<get_vts version_only='1'/>"))
657 return 1;
658 return 0;
659 }
660
661 if (opts.filter)
662 {
663 if (osp_send_command (connection, vts, "<get_vts filter='%s'/>",
664 opts.filter))
665 return 1;
666 return 0;
667 }
668
669 if (osp_send_command (connection, vts, "<get_vts/>"))
670 return 1;
671 return 0;
672}
673
683int
685 gchar **str)
686{
687 if (!connection)
688 return 1;
689
690 if (str == NULL)
691 return 1;
692
693 if (opts.version_only == 1)
694 {
695 if (osp_send_command_str (connection, str, "<get_vts version_only='1'/>"))
696 return 1;
697 return 0;
698 }
699
700 if (opts.filter)
701 {
702 if (osp_send_command_str (connection, str, "<get_vts filter='%s'/>",
703 opts.filter))
704 return 1;
705 return 0;
706 }
707
708 if (osp_send_command_str (connection, str, "<get_vts/>"))
709 return 1;
710 return 0;
711}
712
721int
722osp_delete_scan (osp_connection_t *connection, const char *scan_id)
723{
724 entity_t entity;
725 int ret = 0;
726 const char *status;
727
728 if (!connection)
729 return 1;
730
731 ret = osp_send_command (connection, &entity, "<delete_scan scan_id='%s'/>",
732 scan_id);
733 if (ret)
734 return 1;
735
736 /* Check response status. */
737 status = entity_attribute (entity, "status");
738 assert (status);
739 if (strcmp (status, "200"))
740 ret = 1;
741
742 free_entity (entity);
743 return ret;
744}
745
756int
758 osp_get_performance_opts_t opts, char **graph,
759 char **error)
760{
761 entity_t entity;
762 int rc;
763 time_t now;
764
765 if (!connection)
766 {
767 if (error)
768 *error = g_strdup ("Couldn't send get_performance command "
769 "to scanner. Not valid connection");
770 return -1;
771 }
772
773 time (&now);
774
775 if (!opts.titles || !strcmp (opts.titles, "") || opts.start < 0
776 || opts.start > now || opts.end < 0 || opts.end > now)
777 {
778 if (error)
779 *error = g_strdup ("Couldn't send get_performance command "
780 "to scanner. Bad or missing parameters.");
781 return -1;
782 }
783
784 rc = osp_send_command (connection, &entity,
785 "<get_performance start='%d' "
786 "end='%d' titles='%s'/>",
787 opts.start, opts.end, opts.titles);
788
789 if (rc)
790 {
791 if (error)
792 *error = g_strdup ("Couldn't send get_performance command to scanner");
793 return -1;
794 }
795
796 if (graph && entity_text (entity) && strcmp (entity_text (entity), "\0"))
797 *graph = g_strdup (entity_text (entity));
798 else
799 {
800 const char *text = entity_attribute (entity, "status_text");
801
802 assert (text);
803 if (error)
804 *error = g_strdup (text);
805 free_entity (entity);
806 return -1;
807 }
808
809 free_entity (entity);
810 return 0;
811}
812
824 osp_get_scan_status_opts_t opts, char **error)
825{
826 entity_t entity, child;
827 int rc;
829
830 if (!connection)
831 {
832 if (error)
833 *error = g_strdup ("Couldn't send get_scans command "
834 "to scanner. Not valid connection");
835 return status;
836 }
837
838 assert (opts.scan_id);
839 rc = osp_send_command (connection, &entity,
840 "<get_scans scan_id='%s'"
841 " details='0'"
842 " pop_results='0'/>",
843 opts.scan_id);
844
845 if (rc)
846 {
847 if (error)
848 *error = g_strdup ("Couldn't send get_scans command to scanner");
849 return status;
850 }
851
852 child = entity_child (entity, "scan");
853 if (!child)
854 {
855 const char *text = entity_attribute (entity, "status_text");
856
857 assert (text);
858 if (error)
859 *error = g_strdup (text);
860 free_entity (entity);
861 return status;
862 }
863
864 if (!strcmp (entity_attribute (child, "status"), "queued"))
865 status = OSP_SCAN_STATUS_QUEUED;
866 else if (!strcmp (entity_attribute (child, "status"), "init"))
867 status = OSP_SCAN_STATUS_INIT;
868 else if (!strcmp (entity_attribute (child, "status"), "running"))
870 else if (!strcmp (entity_attribute (child, "status"), "stopped"))
872 else if (!strcmp (entity_attribute (child, "status"), "finished"))
874 else if (!strcmp (entity_attribute (child, "status"), "interrupted"))
876
877 free_entity (entity);
878 return status;
879}
880
893int
894osp_get_scan_pop (osp_connection_t *connection, const char *scan_id,
895 char **report_xml, int details, int pop_results, char **error)
896{
897 entity_t entity, child;
898 int progress;
899 int rc;
900
901 if (!connection)
902 {
903 if (error)
904 *error = g_strdup ("Couldn't send get_scan command "
905 "to scanner. Not valid connection");
906 return -1;
907 }
908 assert (scan_id);
909 rc = osp_send_command (connection, &entity,
910 "<get_scans scan_id='%s'"
911 " details='%d'"
912 " pop_results='%d'/>",
913 scan_id, pop_results ? 1 : 0, details ? 1 : 0);
914 if (rc)
915 {
916 if (error)
917 *error = g_strdup ("Couldn't send get_scans command to scanner");
918 return -1;
919 }
920
921 child = entity_child (entity, "scan");
922 if (!child)
923 {
924 const char *text = entity_attribute (entity, "status_text");
925
926 assert (text);
927 if (error)
928 *error = g_strdup (text);
929 free_entity (entity);
930 return -1;
931 }
932 progress = atoi (entity_attribute (child, "progress"));
933 if (report_xml)
934 {
935 GString *string;
936
937 string = g_string_new ("");
938 print_entity_to_string (child, string);
939 *report_xml = g_string_free (string, FALSE);
940 }
941 free_entity (entity);
942 return progress;
943}
944
956int
957osp_get_scan (osp_connection_t *connection, const char *scan_id,
958 char **report_xml, int details, char **error)
959{
960 return osp_get_scan_pop (connection, scan_id, report_xml, details, 0, error);
961}
962
972int
973osp_stop_scan (osp_connection_t *connection, const char *scan_id, char **error)
974{
975 entity_t entity;
976 int rc;
977
978 if (!connection)
979 {
980 if (error)
981 *error = g_strdup ("Couldn't send stop_scan command "
982 "to scanner. Not valid connection");
983 return -1;
984 }
985 assert (scan_id);
986 rc = osp_send_command (connection, &entity, "<stop_scan scan_id='%s'/>",
987 scan_id);
988 if (rc)
989 {
990 if (error)
991 *error = g_strdup ("Couldn't send stop_scan command to scanner");
992 return -1;
993 }
994
995 rc = atoi (entity_attribute (entity, "status"));
996 if (rc == 200)
997 {
998 free_entity (entity);
999 return 0;
1000 }
1001 else
1002 {
1003 const char *text = entity_attribute (entity, "status_text");
1004
1005 assert (text);
1006 if (error)
1007 *error = g_strdup (text);
1008 free_entity (entity);
1009 return -1;
1010 }
1011}
1012
1021static void
1022option_concat_as_xml (gpointer key, gpointer value, gpointer pstr)
1023{
1024 char *options_str, *tmp, *key_escaped, *value_escaped;
1025
1026 options_str = *(char **) pstr;
1027
1028 key_escaped = g_markup_escape_text ((char *) key, -1);
1029 value_escaped = g_markup_escape_text ((char *) value, -1);
1030 tmp = g_strdup_printf ("%s<%s>%s</%s>", options_str ? options_str : "",
1031 key_escaped, value_escaped, key_escaped);
1032
1033 g_free (options_str);
1034 g_free (key_escaped);
1035 g_free (value_escaped);
1036 *(char **) pstr = tmp;
1037}
1038
1051int
1052osp_start_scan (osp_connection_t *connection, const char *target,
1053 const char *ports, GHashTable *options, const char *scan_id,
1054 char **error)
1055{
1056 entity_t entity;
1057 char *options_str = NULL;
1058 int status;
1059 int rc;
1060
1061 if (!connection)
1062 {
1063 if (error)
1064 *error = g_strdup ("Couldn't send start_scan command "
1065 "to scanner. Not valid connection");
1066 return -1;
1067 }
1068
1069 assert (target);
1070 /* Construct options string. */
1071 if (options)
1072 g_hash_table_foreach (options, option_concat_as_xml, &options_str);
1073
1074 rc = osp_send_command (connection, &entity,
1075 "<start_scan target='%s' ports='%s' scan_id='%s'>"
1076 "<scanner_params>%s</scanner_params></start_scan>",
1077 target, ports ? ports : "", scan_id ? scan_id : "",
1078 options_str ? options_str : "");
1079 g_free (options_str);
1080 if (rc)
1081 {
1082 if (error)
1083 *error = g_strdup ("Couldn't send start_scan command to scanner");
1084 return -1;
1085 }
1086
1087 status = atoi (entity_attribute (entity, "status"));
1088 if (status == 200)
1089 {
1090 free_entity (entity);
1091 return 0;
1092 }
1093 else
1094 {
1095 const char *text = entity_attribute (entity, "status_text");
1096
1097 assert (text);
1098 if (error)
1099 *error = g_strdup (text);
1100 free_entity (entity);
1101 return -1;
1102 }
1103}
1104
1112static void
1113credential_append_as_xml (osp_credential_t *credential, GString *xml_string)
1114
1115{
1116 GHashTableIter auth_data_iter;
1117 gchar *auth_data_name, *auth_data_value;
1118
1119 xml_string_append (xml_string,
1120 "<credential type=\"%s\" service=\"%s\" port=\"%s\">",
1121 credential->type ? credential->type : "",
1122 credential->service ? credential->service : "",
1123 credential->port ? credential->port : "");
1124
1125 g_hash_table_iter_init (&auth_data_iter, credential->auth_data);
1126 while (g_hash_table_iter_next (&auth_data_iter, (gpointer *) &auth_data_name,
1127 (gpointer *) &auth_data_value))
1128 {
1129 xml_string_append (xml_string, "<%s>%s</%s>", auth_data_name,
1130 auth_data_value, auth_data_name);
1131 }
1132
1133 xml_string_append (xml_string, "</credential>");
1134}
1135
1143static void
1144target_append_as_xml (osp_target_t *target, GString *xml_string)
1145{
1146 xml_string_append (xml_string,
1147 "<target>"
1148 "<hosts>%s</hosts>"
1149 "<exclude_hosts>%s</exclude_hosts>"
1150 "<finished_hosts>%s</finished_hosts>"
1151 "<ports>%s</ports>",
1152 target->hosts ? target->hosts : "",
1153 target->exclude_hosts ? target->exclude_hosts : "",
1154 target->finished_hosts ? target->finished_hosts : "",
1155 target->ports ? target->ports : "");
1156
1157 /* Alive test specified as bitfield */
1158 if (target->alive_test > 0)
1159 xml_string_append (xml_string, "<alive_test>%d</alive_test>",
1160 target->alive_test);
1161 /* Alive test specified via dedicated methods. Dedicted methods are ignored if
1162 * alive test was already specified as bitfield.*/
1163 else if (target->icmp == TRUE || target->tcp_syn == TRUE
1164 || target->tcp_ack == TRUE || target->arp == TRUE
1165 || target->consider_alive == TRUE)
1166 {
1167 xml_string_append (xml_string,
1168 "<alive_test_methods>"
1169 "<icmp>%d</icmp>"
1170 "<tcp_syn>%d</tcp_syn>"
1171 "<tcp_ack>%d</tcp_ack>"
1172 "<arp>%d</arp>"
1173 "<consider_alive>%d</consider_alive>"
1174 "</alive_test_methods>",
1175 target->icmp, target->tcp_syn, target->tcp_ack,
1176 target->arp, target->consider_alive);
1177 }
1178
1179 if (target->reverse_lookup_unify == 1)
1180 xml_string_append (xml_string,
1181 "<reverse_lookup_unify>%d</reverse_lookup_unify>",
1182 target->reverse_lookup_unify);
1183 if (target->reverse_lookup_only == 1)
1184 xml_string_append (xml_string,
1185 "<reverse_lookup_only>%d</reverse_lookup_only>",
1186 target->reverse_lookup_only);
1187
1188 if (target->credentials)
1189 {
1190 g_string_append (xml_string, "<credentials>");
1191 g_slist_foreach (target->credentials, (GFunc) credential_append_as_xml,
1192 xml_string);
1193 g_string_append (xml_string, "</credentials>");
1194 }
1195 xml_string_append (xml_string, "</target>");
1196}
1197
1204static void
1205vt_group_append_as_xml (osp_vt_group_t *vt_group, GString *xml_string)
1206{
1207 xml_string_append (xml_string, "<vt_group filter=\"%s\"/>", vt_group->filter);
1208}
1209
1218static void
1219vt_value_append_as_xml (gpointer id, gchar *value, GString *xml_string)
1220{
1221 xml_string_append (xml_string, "<vt_value id=\"%s\">%s</vt_value>",
1222 id ? id : "", value ? value : "");
1223}
1224
1231static void
1232vt_single_append_as_xml (osp_vt_single_t *vt_single, GString *xml_string)
1233{
1234 xml_string_append (xml_string, "<vt_single id=\"%s\">", vt_single->vt_id);
1235 g_hash_table_foreach (vt_single->vt_values, (GHFunc) vt_value_append_as_xml,
1236 xml_string);
1237 xml_string_append (xml_string, "</vt_single>");
1238}
1239
1249int
1251 char **error)
1252{
1253 gchar *scanner_params_xml = NULL;
1254 GString *xml;
1255 GSList *list_item;
1256 int list_count;
1257 int rc, status;
1258 entity_t entity;
1259 gchar *cmd;
1260 char filename[] = "/tmp/osp-cmd-XXXXXX";
1261 int fd;
1262
1263 if (!connection)
1264 {
1265 if (error)
1266 *error = g_strdup ("Couldn't send start_scan command "
1267 "to scanner. Not valid connection");
1268 return -1;
1269 }
1270
1271 fd = mkstemp (filename);
1272 FILE *file = fdopen (fd, "w");
1273
1274 xml = g_string_sized_new (10240);
1275 g_string_append (xml, "<start_scan");
1276 xml_string_append (xml, " scan_id=\"%s\">", opts.scan_id ? opts.scan_id : "");
1277
1278 g_string_append (xml, "<targets>");
1279 g_slist_foreach (opts.targets, (GFunc) target_append_as_xml, xml);
1280 g_string_append (xml, "</targets>");
1281
1282 g_string_append (xml, "<scanner_params>");
1283 if (opts.scanner_params)
1284 {
1285 scanner_params_xml = NULL;
1286 g_hash_table_foreach (opts.scanner_params, (GHFunc) option_concat_as_xml,
1287 &scanner_params_xml);
1288 if (scanner_params_xml)
1289 g_string_append (xml, scanner_params_xml);
1290 g_free (scanner_params_xml);
1291 }
1292 g_string_append (xml, "</scanner_params>");
1293
1294 g_string_append (xml, "<vt_selection>");
1295 g_slist_foreach (opts.vt_groups, (GFunc) vt_group_append_as_xml, xml);
1296
1297 fprintf (file, "%s", xml->str);
1298
1299 g_string_free (xml, TRUE);
1300
1301 xml = g_string_new ("");
1302 list_item = opts.vts;
1303 list_count = 0;
1304 while (list_item)
1305 {
1306 list_count++;
1307 vt_single_append_as_xml (list_item->data, xml);
1308
1309 list_item = list_item->next;
1310
1311 if (list_count == 1000)
1312 {
1313 fprintf (file, "%s", xml->str);
1314
1315 g_string_free (xml, TRUE);
1316 xml = g_string_new ("");
1317 list_count = 0;
1318 }
1319 }
1320
1321 g_string_append (xml, "</vt_selection>");
1322 g_string_append (xml, "</start_scan>");
1323
1324 fprintf (file, "%s", xml->str);
1325 fflush (file);
1326 fclose (file);
1327 g_string_free (xml, TRUE);
1328
1329 g_file_get_contents (filename, &cmd, NULL, NULL);
1330
1331 rc = osp_send_command (connection, &entity, "%s", cmd);
1332
1333 g_free (cmd);
1334 unlink (filename);
1335
1336 if (rc)
1337 {
1338 if (error)
1339 *error = g_strdup ("Could not send start_scan command to scanner");
1340 return -1;
1341 }
1342
1343 status = atoi (entity_attribute (entity, "status"));
1344 if (status == 200)
1345 {
1346 free_entity (entity);
1347 return 0;
1348 }
1349 else
1350 {
1351 const char *text = entity_attribute (entity, "status_text");
1352
1353 assert (text);
1354 if (error)
1355 *error = g_strdup (text);
1356 free_entity (entity);
1357 return -1;
1358 }
1359
1360 if (error)
1361 *error = NULL;
1362 free_entity (entity);
1363 return 0;
1364}
1365
1373static osp_param_type_t
1374osp_param_str_to_type (const char *str)
1375{
1376 assert (str);
1377 if (!strcmp (str, "integer"))
1378 return OSP_PARAM_TYPE_INT;
1379 else if (!strcmp (str, "string"))
1380 return OSP_PARAM_TYPE_STR;
1381 else if (!strcmp (str, "password"))
1383 else if (!strcmp (str, "file"))
1384 return OSP_PARAM_TYPE_FILE;
1385 else if (!strcmp (str, "boolean"))
1387 else if (!strcmp (str, "ovaldef_file"))
1389 else if (!strcmp (str, "selection"))
1391 else if (!strcmp (str, "credential_up"))
1392 return OSP_PARAM_TYPE_CRD_UP;
1393 assert (0);
1394 return 0;
1395}
1396
1404const char *
1406{
1407 osp_param_type_t type;
1408
1409 assert (param);
1410 type = param->type;
1411 if (type == OSP_PARAM_TYPE_INT)
1412 return "integer";
1413 else if (type == OSP_PARAM_TYPE_STR)
1414 return "string";
1415 else if (type == OSP_PARAM_TYPE_PASSWORD)
1416 return "password";
1417 else if (type == OSP_PARAM_TYPE_FILE)
1418 return "file";
1419 else if (type == OSP_PARAM_TYPE_BOOLEAN)
1420 return "boolean";
1421 else if (type == OSP_PARAM_TYPE_OVALDEF_FILE)
1422 return "ovaldef_file";
1423 else if (type == OSP_PARAM_TYPE_SELECTION)
1424 return "selection";
1425 else if (type == OSP_PARAM_TYPE_CRD_UP)
1426 return "credential_up";
1427 assert (0);
1428 return NULL;
1429}
1430
1440int
1442 GSList **params)
1443{
1444 entity_t entity, child;
1445 entities_t entities;
1446
1447 assert (connection);
1448
1449 if (osp_send_command (connection, &entity, "<get_scanner_details/>"))
1450 return 1;
1451 if (params)
1452 {
1453 child = entity_child (entity, "scanner_params");
1454 if (!child)
1455 {
1456 free_entity (entity);
1457 return 1;
1458 }
1459 entities = child->entities;
1460 while (entities)
1461 {
1462 osp_param_t *param;
1463
1464 child = entities->data;
1465 param = osp_param_new ();
1466 param->id = g_strdup (entity_attribute (child, "id"));
1467 param->type =
1468 osp_param_str_to_type (entity_attribute (child, "type"));
1469 param->name = g_strdup (entity_text (entity_child (child, "name")));
1470 param->desc =
1471 g_strdup (entity_text (entity_child (child, "description")));
1472 param->def = g_strdup (entity_text (entity_child (child, "default")));
1473 if (entity_child (child, "mandatory"))
1474 param->mandatory =
1475 atoi (entity_text (entity_child (child, "mandatory")));
1476 *params = g_slist_append (*params, param);
1477 entities = next_entities (entities);
1478 }
1479 }
1480 if (desc)
1481 {
1482 child = entity_child (entity, "description");
1483 assert (child);
1484 *desc = g_strdup (entity_text (child));
1485 }
1486
1487 free_entity (entity);
1488 return 0;
1489}
1490
1498{
1499 return g_malloc0 (sizeof (osp_param_t));
1500}
1501
1509const char *
1511{
1512 assert (param);
1513
1514 return param->id;
1515}
1516
1524const char *
1526{
1527 assert (param);
1528
1529 return param->name;
1530}
1531
1539const char *
1541{
1542 assert (param);
1543
1544 return param->desc;
1545}
1546
1554const char *
1556{
1557 assert (param);
1558
1559 return param->def;
1560}
1561
1569int
1571{
1572 assert (param);
1573
1574 return param->mandatory;
1575}
1576
1582void
1584{
1585 if (!param)
1586 return;
1587 g_free (param->id);
1588 g_free (param->name);
1589 g_free (param->desc);
1590 g_free (param->def);
1591 g_free (param);
1592}
1593
1604osp_credential_new (const char *type, const char *service, const char *port)
1605{
1606 osp_credential_t *new_credential;
1607
1608 new_credential = g_malloc0 (sizeof (osp_credential_t));
1609
1610 new_credential->type = type ? g_strdup (type) : NULL;
1611 new_credential->service = service ? g_strdup (service) : NULL;
1612 new_credential->port = port ? g_strdup (port) : NULL;
1613 new_credential->auth_data =
1614 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
1615
1616 return new_credential;
1617}
1618
1624void
1626{
1627 if (!credential)
1628 return;
1629
1630 g_free (credential->type);
1631 g_free (credential->service);
1632 g_free (credential->port);
1633 g_hash_table_destroy (credential->auth_data);
1634 g_free (credential);
1635}
1636
1645const gchar *
1646osp_credential_get_auth_data (osp_credential_t *credential, const char *name)
1647{
1648 if (credential == NULL || name == NULL)
1649 return NULL;
1650 return g_hash_table_lookup (credential->auth_data, name);
1651}
1652
1660void
1661osp_credential_set_auth_data (osp_credential_t *credential, const char *name,
1662 const char *value)
1663{
1664 if (credential == NULL || name == NULL)
1665 return;
1666
1667 if (g_regex_match_simple ("^[[:alpha:]][[:alnum:]_]*$", name, 0, 0))
1668 {
1669 if (value)
1670 g_hash_table_replace (credential->auth_data, g_strdup (name),
1671 g_strdup (value));
1672 else
1673 g_hash_table_remove (credential->auth_data, name);
1674 }
1675 else
1676 {
1677 g_warning ("%s: Invalid auth data name: %s", __func__, name);
1678 }
1679}
1680
1694osp_target_new (const char *hosts, const char *ports, const char *exclude_hosts,
1695 int alive_test, int reverse_lookup_unify,
1696 int reverse_lookup_only)
1697{
1698 osp_target_t *new_target;
1699 new_target = g_malloc0 (sizeof (osp_target_t));
1700
1701 new_target->exclude_hosts = exclude_hosts ? g_strdup (exclude_hosts) : NULL;
1702 new_target->hosts = hosts ? g_strdup (hosts) : NULL;
1703 new_target->ports = ports ? g_strdup (ports) : NULL;
1704 new_target->finished_hosts = NULL;
1705 new_target->alive_test = alive_test ? alive_test : 0;
1706 new_target->reverse_lookup_unify =
1707 reverse_lookup_unify ? reverse_lookup_unify : 0;
1708 new_target->reverse_lookup_only =
1709 reverse_lookup_only ? reverse_lookup_only : 0;
1710
1711 return new_target;
1712}
1713
1720void
1721osp_target_set_finished_hosts (osp_target_t *target, const char *finished_hosts)
1722{
1723 g_free (target->finished_hosts);
1724 target->finished_hosts = finished_hosts ? g_strdup (finished_hosts) : NULL;
1725}
1726
1732void
1734{
1735 if (!target)
1736 return;
1737
1738 g_slist_free_full (target->credentials, (GDestroyNotify) osp_credential_free);
1739 g_free (target->exclude_hosts);
1740 g_free (target->hosts);
1741 g_free (target->ports);
1742 g_free (target);
1743}
1744
1755void
1757 gboolean tcp_syn, gboolean tcp_ack,
1758 gboolean arp, gboolean consider_alive)
1759{
1760 if (!target)
1761 return;
1762
1763 target->icmp = icmp;
1764 target->tcp_syn = tcp_syn;
1765 target->tcp_ack = tcp_ack;
1766 target->arp = arp;
1767 target->consider_alive = consider_alive;
1768}
1769
1776void
1778{
1779 if (!target || !credential)
1780 return;
1781
1782 target->credentials = g_slist_prepend (target->credentials, credential);
1783}
1784
1793osp_vt_group_new (const char *filter)
1794{
1795 osp_vt_group_t *new_vt_group;
1796 new_vt_group = g_malloc0 (sizeof (osp_vt_group_t));
1797
1798 new_vt_group->filter = filter ? g_strdup (filter) : NULL;
1799
1800 return new_vt_group;
1801}
1802
1808void
1810{
1811 if (!vt_group)
1812 return;
1813
1814 g_free (vt_group->filter);
1815 g_free (vt_group);
1816}
1817
1826osp_vt_single_new (const char *vt_id)
1827{
1828 osp_vt_single_t *new_vt_single;
1829 new_vt_single = g_malloc0 (sizeof (osp_vt_single_t));
1830
1831 new_vt_single->vt_id = vt_id ? g_strdup (vt_id) : NULL;
1832 new_vt_single->vt_values =
1833 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
1834
1835 return new_vt_single;
1836}
1837
1843void
1845{
1846 if (!vt_single)
1847 return;
1848
1849 g_hash_table_destroy (vt_single->vt_values);
1850
1851 g_free (vt_single->vt_id);
1852 g_free (vt_single);
1853}
1854
1863void
1864osp_vt_single_add_value (osp_vt_single_t *vt_single, const char *name,
1865 const char *value)
1866{
1867 g_hash_table_replace (vt_single->vt_values, g_strdup (name),
1868 g_strdup (value));
1869}
int gvm_get_host_type(const gchar *str_stripped)
Determines the host type in a buffer.
Definition: hosts.c:810
__attribute__((weak))
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.
Definition: osp.c:321
void osp_credential_set_auth_data(osp_credential_t *credential, const char *name, const char *value)
Get authentication data from an OSP credential.
Definition: osp.c:1661
void osp_connection_close(osp_connection_t *connection)
Close a connection to an OSP server.
Definition: osp.c:293
void osp_credential_free(osp_credential_t *credential)
Free an OSP credential.
Definition: osp.c:1625
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.
Definition: osp.c:684
static int osp_send_command(osp_connection_t *, entity_t *, static intosp_send_command_str(osp_connection_t const char *,...)
Definition: osp.c:107
int osp_start_scan_ext(osp_connection_t *connection, osp_start_scan_opts_t opts, char **error)
Start an OSP scan against a target.
Definition: osp.c:1250
void osp_vt_group_free(osp_vt_group_t *vt_group)
Free a OSP VT group.
Definition: osp.c:1809
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.
Definition: osp.c:1756
osp_vt_group_t * osp_vt_group_new(const char *filter)
Create a new OSP VT group.
Definition: osp.c:1793
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.
Definition: osp.c:557
void osp_target_set_finished_hosts(osp_target_t *target, const char *finished_hosts)
Set the finished hosts of an OSP target.
Definition: osp.c:1721
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:1374
int osp_get_vts(osp_connection_t *connection, entity_t *vts)
Get all VTs from an OSP server.
Definition: osp.c:621
int osp_get_scanner_details(osp_connection_t *connection, char **desc, GSList **params)
Get an OSP scanner's details.
Definition: osp.c:1441
static void credential_append_as_xml(osp_credential_t *credential, GString *xml_string)
Concatenate a credential as XML.
Definition: osp.c:1113
const char * osp_param_desc(const osp_param_t *param)
Get an OSP parameter's description.
Definition: osp.c:1540
void osp_target_add_credential(osp_target_t *target, osp_credential_t *credential)
Add a credential to an OSP target.
Definition: osp.c:1777
int osp_delete_scan(osp_connection_t *connection, const char *scan_id)
Delete a scan from an OSP server.
Definition: osp.c:722
void osp_target_free(osp_target_t *target)
Free an OSP target, including all added credentials.
Definition: osp.c:1733
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.
Definition: osp.c:645
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.
Definition: osp.c:1864
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:1232
osp_vt_single_t * osp_vt_single_new(const char *vt_id)
Create a new single OSP VT.
Definition: osp.c:1826
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.
Definition: osp.c:957
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:894
static void vt_value_append_as_xml(gpointer id, gchar *value, GString *xml_string)
Append VT values as XML to a string buffer.
Definition: osp.c:1219
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.
Definition: osp.c:1052
static void target_append_as_xml(osp_target_t *target, GString *xml_string)
Concatenate a target as XML.
Definition: osp.c:1144
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:1205
void osp_vt_single_free(osp_vt_single_t *vt_single)
Free a single OSP VT, including all preference values.
Definition: osp.c:1844
static void option_concat_as_xml(gpointer key, gpointer value, gpointer pstr)
Concatenate options as xml.
Definition: osp.c:1022
osp_credential_t * osp_credential_new(const char *type, const char *service, const char *port)
Allocate and initialize a new OSP credential.
Definition: osp.c:1604
osp_param_t * osp_param_new(void)
Create a new OSP parameter.
Definition: osp.c:1497
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.
Definition: osp.c:1694
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.
Definition: osp.c:414
const gchar * osp_credential_get_auth_data(osp_credential_t *credential, const char *name)
Get authentication data from an OSP credential.
Definition: osp.c:1646
const char * osp_param_type_str(const osp_param_t *param)
Get an OSP parameter in string format form its type.
Definition: osp.c:1405
static int osp_send_command_str(osp_connection_t *connection, gchar **str, const char *fmt,...)
Send a command to an OSP server.
Definition: osp.c:243
int osp_stop_scan(osp_connection_t *connection, const char *scan_id, char **error)
Stop a scan on an OSP server.
Definition: osp.c:973
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.
Definition: osp.c:757
const char * osp_param_name(const osp_param_t *param)
Get an OSP parameter's name.
Definition: osp.c:1525
int osp_param_mandatory(const osp_param_t *param)
Get an OSP parameter's mandatory value.
Definition: osp.c:1570
void osp_param_free(osp_param_t *param)
Free an OSP parameter.
Definition: osp.c:1583
int osp_get_vts_version(osp_connection_t *connection, char **vts_version, char **error)
Get the VTs version from an OSP server.
Definition: osp.c:499
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.
Definition: osp.c:823
const char * osp_param_id(const osp_param_t *param)
Get an OSP parameter's id.
Definition: osp.c:1510
const char * osp_param_default(const osp_param_t *param)
Get an OSP parameter's default value.
Definition: osp.c:1555
API for Open Scanner Protocol communication.
static const osp_get_vts_opts_t osp_get_vts_opts_default
Sensible default values for osp_get_vts_opts_t.
Definition: osp.h:109
osp_scan_status_t
OSP scan status.
Definition: osp.h:49
@ OSP_SCAN_STATUS_QUEUED
Definition: osp.h:55
@ OSP_SCAN_STATUS_STOPPED
Definition: osp.h:53
@ OSP_SCAN_STATUS_INTERRUPTED
Definition: osp.h:56
@ OSP_SCAN_STATUS_FINISHED
Definition: osp.h:54
@ OSP_SCAN_STATUS_RUNNING
Definition: osp.h:52
@ OSP_SCAN_STATUS_ERROR
Definition: osp.h:50
@ OSP_SCAN_STATUS_INIT
Definition: osp.h:51
osp_connection_t * osp_connection_new(const char *, int, const char *, const char *, const char *)
osp_param_type_t
OSP parameter types.
Definition: osp.h:34
@ OSP_PARAM_TYPE_BOOLEAN
Definition: osp.h:39
@ OSP_PARAM_TYPE_STR
Definition: osp.h:36
@ OSP_PARAM_TYPE_INT
Definition: osp.h:35
@ OSP_PARAM_TYPE_SELECTION
Definition: osp.h:41
@ OSP_PARAM_TYPE_PASSWORD
Definition: osp.h:37
@ OSP_PARAM_TYPE_FILE
Definition: osp.h:38
@ OSP_PARAM_TYPE_CRD_UP
Definition: osp.h:42
@ OSP_PARAM_TYPE_OVALDEF_FILE
Definition: osp.h:40
int gvm_server_open_with_cert(gnutls_session_t *session, const char *host, int port, const char *ca_mem, const char *pub_mem, const char *priv_mem)
Connect to the server using a given host, port and cert.
Definition: serverutils.c:462
int gvm_server_vsendf(gnutls_session_t *session, const char *fmt, va_list ap)
Send a string to the server.
Definition: serverutils.c:728
int gvm_server_close(int socket, gnutls_session_t session)
Close a server connection and its socket.
Definition: serverutils.c:494
int gvm_socket_vsendf(int socket, const char *fmt, va_list ap)
Send a string to the server.
Definition: serverutils.c:743
XML element.
Definition: xmlutils.h:52
entities_t entities
Children.
Definition: xmlutils.h:56
Connection.
Definition: serverutils.h:30
gint port
Port of server.
Definition: serverutils.h:39
int tls
Whether uses TCP-TLS (vs UNIX socket).
Definition: serverutils.h:31
int socket
Socket.
Definition: serverutils.h:32
gchar * host_string
Server host string.
Definition: serverutils.h:37
gnutls_session_t session
Session.
Definition: serverutils.h:33
Struct holding options for OSP connection.
Definition: osp.c:36
int port
Definition: osp.c:40
int socket
Definition: osp.c:38
char * host
Definition: osp.c:39
gnutls_session_t session
Definition: osp.c:37
Struct credential information for OSP.
Definition: osp.c:60
gchar * service
Definition: osp.c:62
GHashTable * auth_data
Definition: osp.c:64
gchar * type
Definition: osp.c:61
gchar * port
Definition: osp.c:63
const char * scan_id
UUID of the scan which get the status from.
Definition: osp.h:61
char * filter
the filter to apply for a vt sub-selection.
Definition: osp.h:102
int version_only
if get only feed info or the vt collection
Definition: osp.h:103
Struct holding options for OSP parameters.
Definition: osp.c:47
char * def
Definition: osp.c:51
char * id
Definition: osp.c:48
int mandatory
Definition: osp.c:53
char * name
Definition: osp.c:49
osp_param_type_t type
Definition: osp.c:52
char * desc
Definition: osp.c:50
GSList * targets
Target hosts to scan.
Definition: osp.h:123
GSList * vts
Single VTs to use for the scan.
Definition: osp.h:125
GSList * vt_groups
VT groups to use for the scan.
Definition: osp.h:124
GHashTable * scanner_params
Table of scanner parameters.
Definition: osp.h:126
const char * scan_id
UUID to set for scan, null otherwise.
Definition: osp.h:127
Struct holding target information.
Definition: osp.c:71
int reverse_lookup_only
Definition: osp.c:86
gchar * hosts
Definition: osp.c:74
GSList * credentials
Definition: osp.c:72
gboolean tcp_syn
Definition: osp.c:81
int reverse_lookup_unify
Definition: osp.c:85
int alive_test
Definition: osp.c:79
gboolean arp
Definition: osp.c:83
gchar * exclude_hosts
Definition: osp.c:73
gboolean icmp
Definition: osp.c:80
gboolean consider_alive
Definition: osp.c:84
gchar * ports
Definition: osp.c:75
gboolean tcp_ack
Definition: osp.c:82
gchar * finished_hosts
Definition: osp.c:76
Struct holding vt_group information.
Definition: osp.c:93
gchar * filter
Definition: osp.c:94
Struct holding vt_group information.
Definition: osp.c:101
GHashTable * vt_values
Definition: osp.c:103
gchar * vt_id
Definition: osp.c:102
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition: xmlutils.c:216
char * entity_text(entity_t entity)
Get the text an entity.
Definition: xmlutils.c:145
int read_entity(gnutls_session_t *session, entity_t *entity)
Read an XML entity tree from the manager.
Definition: xmlutils.c:1469
entities_t next_entities(entities_t entities)
Return all the entities from an entities_t after the first.
Definition: xmlutils.c:67
void free_entity(entity_t entity)
Free an entity, recursively.
Definition: xmlutils.c:115
int read_text_c(gvm_connection_t *connection, char **text)
Read text from the server.
Definition: xmlutils.c:1366
entity_t entity_child(entity_t entity, const char *name)
Get a child of an entity.
Definition: xmlutils.c:193
int read_entity_s(int socket, entity_t *entity)
Read an XML entity tree from the socket.
Definition: xmlutils.c:1483
void xml_string_append(GString *xml, const char *format,...)
Append formatted escaped XML to a string.
Definition: xmlutils.c:1845
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:1612
GSList * entities_t
Entities.
Definition: xmlutils.h:46