Greenbone Vulnerability Management Libraries: osp/osp.c Source File

Greenbone Vulnerability Management Libraries 23.1.2

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
10
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
35 struct osp_connection
36{
37 gnutls_session_t session;
38 int socket;
39 char *host;
40 int port;
41};
42
46 struct osp_param
47{
48 char *id;
49 char *name;
50 char *desc;
51 char *def;
52 osp_param_type_t type;
53 int mandatory;
54};
55
59 struct osp_target
60{
61 GSList *credentials;
62 gchar *exclude_hosts;
63 gchar *hosts;
64 gchar *ports;
65 gchar *finished_hosts;
66 /* Alive test methods can be specified either as bitfield or via selection of
67 individual methods */
68 int alive_test;
69 gboolean icmp;
70 gboolean tcp_syn;
71 gboolean tcp_ack;
72 gboolean arp;
73 gboolean consider_alive;
74 int reverse_lookup_unify;
75 int reverse_lookup_only;
76};
77
81 struct osp_vt_group
82{
83 gchar *filter;
84};
85
89 struct osp_vt_single
90{
91 gchar *vt_id;
92 GHashTable *vt_values;
93};
94
95static int
96osp_send_command (osp_connection_t *, entity_t *, const char *, ...)
97 __attribute__ ((__format__ (__printf__, 3, 4)));
98
99static int
100 osp_send_command_str (osp_connection_t *, gchar **, const char *, ...)
101 __attribute__ ((__format__ (__printf__, 3, 4)));
102
114 osp_connection_t *
115 osp_connection_new (const char *host, int port, const char *cacert,
116 const char *cert, const char *key)
117{
118 osp_connection_t *connection;
119
120 if (host && *host == '/')
121 {
122 struct sockaddr_un addr;
123 int len;
124
125 if (strlen (host) >= sizeof (addr.sun_path))
126 {
127 g_warning ("%s: given host / socket path too long (%zu > %zu bytes)",
128 __func__, strlen (host), sizeof (addr.sun_path) - 1);
129 return NULL;
130 }
131
132 connection = g_malloc0 (sizeof (*connection));
133 connection->socket = socket (AF_UNIX, SOCK_STREAM, 0);
134 if (connection->socket == -1)
135 {
136 g_free (connection);
137 return NULL;
138 }
139
140 addr.sun_family = AF_UNIX;
141 memset (addr.sun_path, 0, sizeof (addr.sun_path));
142 memcpy (addr.sun_path, host, strlen (host));
143 len = strlen (addr.sun_path) + sizeof (addr.sun_family);
144 if (connect (connection->socket, (struct sockaddr *) &addr, len) == -1)
145 {
146 close (connection->socket);
147 g_free (connection);
148 return NULL;
149 }
150 }
151 else
152 {
153 if (port <= 0 || port > 65535)
154 return NULL;
155 if (!host || gvm_get_host_type (host) == -1)
156 return NULL;
157 if (!cert || !key || !cacert)
158 return NULL;
159
160 connection = g_malloc0 (sizeof (*connection));
161 connection->socket = gvm_server_open_with_cert (
162 &connection->session, host, port, cacert, cert, key);
163 }
164 if (connection->socket == -1)
165 {
166 g_free (connection);
167 return NULL;
168 }
169
170 connection->host = g_strdup (host);
171 connection->port = port;
172 return connection;
173}
174
184int
185 osp_send_command (osp_connection_t *connection, entity_t *response,
186 const char *fmt, ...)
187{
188 va_list ap;
189 int rc = 1;
190
191 va_start (ap, fmt);
192
193 if (!connection || !fmt || !response)
194 goto out;
195
196 if (*connection->host == '/')
197 {
198 if (gvm_socket_vsendf (connection->socket, fmt, ap) == -1)
199 goto out;
200 if (read_entity_s (connection->socket, response))
201 goto out;
202 }
203 else
204 {
205 if (gvm_server_vsendf (&connection->session, fmt, ap) == -1)
206 goto out;
207 if (read_entity (&connection->session, response))
208 goto out;
209 }
210
211 rc = 0;
212
213out:
214 va_end (ap);
215
216 return rc;
217}
218
228static int
229osp_send_command_str (osp_connection_t *connection, gchar **str,
230 const char *fmt, ...)
231{
232 va_list ap;
233 int rc;
234 gvm_connection_t conn;
235
236 rc = 1;
237 *str = NULL;
238
239 va_start (ap, fmt);
240
241 if (!connection || !fmt)
242 goto out;
243
244 if (*connection->host == '/')
245 {
246 if (gvm_socket_vsendf (connection->socket, fmt, ap) == -1)
247 goto out;
248 conn.tls = 0;
249 }
250 else
251 {
252 if (gvm_server_vsendf (&connection->session, fmt, ap) == -1)
253 goto out;
254 conn.tls = 1;
255 }
256
257 conn.socket = connection->socket;
258 conn.session = connection->session;
259 conn.host_string = connection->host;
260 conn.port = connection->port;
261
262 if (read_text_c (&conn, str))
263 goto out;
264
265 rc = 0;
266
267out:
268 va_end (ap);
269
270 return rc;
271}
272
278void
279osp_connection_close (osp_connection_t *connection)
280{
281 if (!connection)
282 return;
283
284 if (*connection->host == '/')
285 close (connection->socket);
286 else
287 gvm_server_close (connection->socket, connection->session);
288 g_free (connection->host);
289 g_free (connection);
290}
291
306int
307osp_check_feed (osp_connection_t *connection, int *lockfile_in_use,
308 int *self_test_exit_error, char **self_test_error_msg,
309 char **cmd_error)
310{
311 entity_t entity, feed, lockfile_entity, exit_error_entity, error_msg_entity;
312 const char *status, *status_text;
313
314 if (!connection)
315 return 1;
316
317 if (osp_send_command (connection, &entity, "<check_feed/>"))
318 return 1;
319
320 status = entity_attribute (entity, "status");
321
322 if (status != NULL && !strcmp (status, "400"))
323 {
324 status_text = entity_attribute (entity, "status_text");
325 g_debug ("%s: %s - %s.", __func__, status, status_text);
326 if (cmd_error)
327 *cmd_error = g_strdup (status_text);
328 free_entity (entity);
329 return 1;
330 }
331
332 feed = entity_child (entity, "feed");
333 if (!feed)
334 {
335 g_warning ("%s: element FEED missing.", __func__);
336 free_entity (entity);
337 return 1;
338 }
339
340 lockfile_entity = entity_child (feed, "lockfile_in_use");
341 exit_error_entity = entity_child (feed, "self_test_exit_error");
342 error_msg_entity = entity_child (feed, "self_test_error_msg");
343
344 if (lockfile_in_use)
345 {
346 if (lockfile_entity)
347 *lockfile_in_use = atoi (entity_text (lockfile_entity));
348 else
349 {
350 g_warning ("%s: element LOCKFILE_IN_USE missing.", __func__);
351 *lockfile_in_use = -1;
352 }
353 }
354
355 if (self_test_exit_error)
356 {
357 if (exit_error_entity)
358 *self_test_exit_error = atoi (entity_text (exit_error_entity));
359 else
360 {
361 g_warning ("%s: element SELF_TEST_EXIT_ERROR missing.", __func__);
362 *self_test_exit_error = -1;
363 }
364 }
365
366 if (self_test_error_msg)
367 {
368 if (error_msg_entity)
369 {
370 if (entity_text (error_msg_entity))
371 *self_test_error_msg = g_strdup (entity_text (error_msg_entity));
372 else
373 *self_test_error_msg = NULL;
374 }
375 else
376 {
377 g_warning ("%s: element SELF_TEST_ERROR_MSG missing.", __func__);
378 *self_test_error_msg = NULL;
379 }
380 }
381
382 free_entity (entity);
383 return 0;
384}
385
399int
400osp_get_version (osp_connection_t *connection, char **s_name, char **s_version,
401 char **d_name, char **d_version, char **p_name,
402 char **p_version)
403{
404 entity_t entity, child, gchild;
405
406 if (!connection)
407 return 1;
408
409 if (osp_send_command (connection, &entity, "<get_version/>"))
410 return 1;
411
412 child = entity_child (entity, "scanner");
413 if (!child)
414 goto err_get_version;
415 gchild = entity_child (child, "name");
416 if (!gchild)
417 goto err_get_version;
418 if (s_name)
419 *s_name = g_strdup (entity_text (gchild));
420 gchild = entity_child (child, "version");
421 if (!gchild)
422 goto err_get_version;
423 if (s_version)
424 *s_version = g_strdup (entity_text (gchild));
425
426 child = entity_child (entity, "daemon");
427 if (!child)
428 goto err_get_version;
429 gchild = entity_child (child, "name");
430 if (!gchild)
431 goto err_get_version;
432 if (d_name)
433 *d_name = g_strdup (entity_text (gchild));
434 gchild = entity_child (child, "version");
435 if (!gchild)
436 goto err_get_version;
437 if (d_version)
438 *d_version = g_strdup (entity_text (gchild));
439
440 child = entity_child (entity, "protocol");
441 if (!child)
442 goto err_get_version;
443 gchild = entity_child (child, "name");
444 if (!gchild)
445 goto err_get_version;
446 if (p_name)
447 *p_name = g_strdup (entity_text (gchild));
448 gchild = entity_child (child, "version");
449 if (!gchild)
450 goto err_get_version;
451 if (p_version)
452 *p_version = g_strdup (entity_text (gchild));
453
454 free_entity (entity);
455 return 0;
456
457err_get_version:
458 g_warning ("Erroneous OSP <get_version/> response.");
459 if (s_name)
460 g_free (*s_name);
461 if (s_version)
462 g_free (*s_version);
463 if (d_name)
464 g_free (*d_name);
465 if (d_version)
466 g_free (*d_version);
467 if (p_name)
468 g_free (*p_name);
469 if (p_version)
470 g_free (*p_version);
471 free_entity (entity);
472 return 1;
473}
474
484int
485osp_get_vts_version (osp_connection_t *connection, char **vts_version,
486 char **error)
487{
488 entity_t entity, vts;
489 const char *version;
490 const char *status, *status_text;
491 osp_get_vts_opts_t get_vts_opts;
492
493 if (!connection)
494 return 1;
495
496 get_vts_opts = osp_get_vts_opts_default;
497 get_vts_opts.version_only = 1;
498 if (osp_get_vts_ext (connection, get_vts_opts, &entity))
499 return 1;
500
501 status = entity_attribute (entity, "status");
502
503 if (status != NULL && !strcmp (status, "400"))
504 {
505 status_text = entity_attribute (entity, "status_text");
506 g_debug ("%s: %s - %s.", __func__, status, status_text);
507 if (error)
508 *error = g_strdup (status_text);
509 free_entity (entity);
510 return 1;
511 }
512
513 vts = entity_child (entity, "vts");
514 if (!vts)
515 {
516 g_warning ("%s: element VTS missing.", __func__);
517 free_entity (entity);
518 return 1;
519 }
520
521 version = entity_attribute (vts, "vts_version");
522
523 if (vts_version)
524 *vts_version = g_strdup (version);
525
526 free_entity (entity);
527 return 0;
528}
529
542int
543osp_get_vts_feed_info (osp_connection_t *connection, char **vts_version,
544 char **feed_name, char **feed_vendor, char **feed_home,
545 char **error)
546{
547 entity_t entity, vts;
548 const char *version, *name, *vendor, *home;
549 const char *status, *status_text;
550 osp_get_vts_opts_t get_vts_opts;
551
552 if (!connection)
553 return 1;
554
555 get_vts_opts = osp_get_vts_opts_default;
556 get_vts_opts.version_only = 1;
557 if (osp_get_vts_ext (connection, get_vts_opts, &entity))
558 return 1;
559
560 status = entity_attribute (entity, "status");
561
562 if (status != NULL && !strcmp (status, "400"))
563 {
564 status_text = entity_attribute (entity, "status_text");
565 g_debug ("%s: %s - %s.", __func__, status, status_text);
566 if (error)
567 *error = g_strdup (status_text);
568 free_entity (entity);
569 return 1;
570 }
571
572 vts = entity_child (entity, "vts");
573 if (!vts)
574 {
575 g_warning ("%s: element VTS missing.", __func__);
576 free_entity (entity);
577 return 1;
578 }
579
580 version = entity_attribute (vts, "vts_version");
581 name = entity_attribute (vts, "feed_name");
582 vendor = entity_attribute (vts, "feed_vendor");
583 home = entity_attribute (vts, "feed_home");
584
585 if (vts_version)
586 *vts_version = version ? g_strdup (version) : NULL;
587 if (feed_name)
588 *feed_name = name ? g_strdup (name) : NULL;
589 if (feed_vendor)
590 *feed_vendor = vendor ? g_strdup (vendor) : NULL;
591 if (feed_home)
592 *feed_home = home ? g_strdup (home) : NULL;
593
594 free_entity (entity);
595 return 0;
596}
597
606int
607osp_get_vts (osp_connection_t *connection, entity_t *vts)
608{
609 if (!connection)
610 return 1;
611
612 if (vts == NULL)
613 return 1;
614
615 if (osp_send_command (connection, vts, "<get_vts/>"))
616 return 1;
617
618 return 0;
619}
620
630int
631osp_get_vts_ext (osp_connection_t *connection, osp_get_vts_opts_t opts,
632 entity_t *vts)
633{
634 if (!connection)
635 return 1;
636
637 if (vts == NULL)
638 return 1;
639
640 if (opts.version_only == 1)
641 {
642 if (osp_send_command (connection, vts, "<get_vts version_only='1'/>"))
643 return 1;
644 return 0;
645 }
646
647 if (opts.filter)
648 {
649 if (osp_send_command (connection, vts, "<get_vts filter='%s'/>",
650 opts.filter))
651 return 1;
652 return 0;
653 }
654
655 if (osp_send_command (connection, vts, "<get_vts/>"))
656 return 1;
657 return 0;
658}
659
669int
670osp_get_vts_ext_str (osp_connection_t *connection, osp_get_vts_opts_t opts,
671 gchar **str)
672{
673 if (!connection)
674 return 1;
675
676 if (str == NULL)
677 return 1;
678
679 if (opts.version_only == 1)
680 {
681 if (osp_send_command_str (connection, str, "<get_vts version_only='1'/>"))
682 return 1;
683 return 0;
684 }
685
686 if (opts.filter)
687 {
688 if (osp_send_command_str (connection, str, "<get_vts filter='%s'/>",
689 opts.filter))
690 return 1;
691 return 0;
692 }
693
694 if (osp_send_command_str (connection, str, "<get_vts/>"))
695 return 1;
696 return 0;
697}
698
707int
708osp_delete_scan (osp_connection_t *connection, const char *scan_id)
709{
710 entity_t entity;
711 int ret = 0;
712 const char *status;
713
714 if (!connection)
715 return 1;
716
717 ret = osp_send_command (connection, &entity, "<delete_scan scan_id='%s'/>",
718 scan_id);
719 if (ret)
720 return 1;
721
722 /* Check response status. */
723 status = entity_attribute (entity, "status");
724 assert (status);
725 if (strcmp (status, "200"))
726 ret = 1;
727
728 free_entity (entity);
729 return ret;
730}
731
742int
743osp_get_performance_ext (osp_connection_t *connection,
744 osp_get_performance_opts_t opts, char **graph,
745 char **error)
746{
747 entity_t entity;
748 int rc;
749 time_t now;
750
751 if (!connection)
752 {
753 if (error)
754 *error = g_strdup ("Couldn't send get_performance command "
755 "to scanner. Not valid connection");
756 return -1;
757 }
758
759 time (&now);
760
761 if (!opts.titles || !strcmp (opts.titles, "") || opts.start < 0
762 || opts.start > now || opts.end < 0 || opts.end > now)
763 {
764 if (error)
765 *error = g_strdup ("Couldn't send get_performance command "
766 "to scanner. Bad or missing parameters.");
767 return -1;
768 }
769
770 rc = osp_send_command (connection, &entity,
771 "<get_performance start='%d' "
772 "end='%d' titles='%s'/>",
773 opts.start, opts.end, opts.titles);
774
775 if (rc)
776 {
777 if (error)
778 *error = g_strdup ("Couldn't send get_performance command to scanner");
779 return -1;
780 }
781
782 if (graph && entity_text (entity) && strcmp (entity_text (entity), "\0"))
783 *graph = g_strdup (entity_text (entity));
784 else
785 {
786 const char *text = entity_attribute (entity, "status_text");
787
788 assert (text);
789 if (error)
790 *error = g_strdup (text);
791 free_entity (entity);
792 return -1;
793 }
794
795 free_entity (entity);
796 return 0;
797}
798
808 osp_scan_status_t
809osp_get_scan_status_ext (osp_connection_t *connection,
810 osp_get_scan_status_opts_t opts, char **error)
811{
812 entity_t entity, child;
813 int rc;
814 osp_scan_status_t status = OSP_SCAN_STATUS_ERROR;
815
816 if (!connection)
817 {
818 if (error)
819 *error = g_strdup ("Couldn't send get_scans command "
820 "to scanner. Not valid connection");
821 return status;
822 }
823
824 assert (opts.scan_id);
825 rc = osp_send_command (connection, &entity,
826 "<get_scans scan_id='%s'"
827 " details='0'"
828 " pop_results='0'/>",
829 opts.scan_id);
830
831 if (rc)
832 {
833 if (error)
834 *error = g_strdup ("Couldn't send get_scans command to scanner");
835 return status;
836 }
837
838 child = entity_child (entity, "scan");
839 if (!child)
840 {
841 const char *text = entity_attribute (entity, "status_text");
842
843 assert (text);
844 if (error)
845 *error = g_strdup (text);
846 free_entity (entity);
847 return status;
848 }
849
850 if (!strcmp (entity_attribute (child, "status"), "queued"))
851 status = OSP_SCAN_STATUS_QUEUED;
852 else if (!strcmp (entity_attribute (child, "status"), "init"))
853 status = OSP_SCAN_STATUS_INIT;
854 else if (!strcmp (entity_attribute (child, "status"), "running"))
855 status = OSP_SCAN_STATUS_RUNNING;
856 else if (!strcmp (entity_attribute (child, "status"), "stopped"))
857 status = OSP_SCAN_STATUS_STOPPED;
858 else if (!strcmp (entity_attribute (child, "status"), "finished"))
859 status = OSP_SCAN_STATUS_FINISHED;
860 else if (!strcmp (entity_attribute (child, "status"), "interrupted"))
861 status = OSP_SCAN_STATUS_INTERRUPTED;
862
863 free_entity (entity);
864 return status;
865}
866
879int
880osp_get_scan_pop (osp_connection_t *connection, const char *scan_id,
881 char **report_xml, int details, int pop_results, char **error)
882{
883 entity_t entity, child;
884 int progress;
885 int rc;
886
887 if (!connection)
888 {
889 if (error)
890 *error = g_strdup ("Couldn't send get_scan command "
891 "to scanner. Not valid connection");
892 return -1;
893 }
894 assert (scan_id);
895 rc = osp_send_command (connection, &entity,
896 "<get_scans scan_id='%s'"
897 " details='%d'"
898 " pop_results='%d'/>",
899 scan_id, pop_results ? 1 : 0, details ? 1 : 0);
900 if (rc)
901 {
902 if (error)
903 *error = g_strdup ("Couldn't send get_scans command to scanner");
904 return -1;
905 }
906
907 child = entity_child (entity, "scan");
908 if (!child)
909 {
910 const char *text = entity_attribute (entity, "status_text");
911
912 assert (text);
913 if (error)
914 *error = g_strdup (text);
915 free_entity (entity);
916 return -1;
917 }
918 progress = atoi (entity_attribute (child, "progress"));
919 if (report_xml)
920 {
921 GString *string;
922
923 string = g_string_new ("");
924 print_entity_to_string (child, string);
925 *report_xml = g_string_free (string, FALSE);
926 }
927 free_entity (entity);
928 return progress;
929}
930
942int
943osp_get_scan (osp_connection_t *connection, const char *scan_id,
944 char **report_xml, int details, char **error)
945{
946 return osp_get_scan_pop (connection, scan_id, report_xml, details, 0, error);
947}
948
958int
959osp_stop_scan (osp_connection_t *connection, const char *scan_id, char **error)
960{
961 entity_t entity;
962 int rc;
963
964 if (!connection)
965 {
966 if (error)
967 *error = g_strdup ("Couldn't send stop_scan command "
968 "to scanner. Not valid connection");
969 return -1;
970 }
971 assert (scan_id);
972 rc = osp_send_command (connection, &entity, "<stop_scan scan_id='%s'/>",
973 scan_id);
974 if (rc)
975 {
976 if (error)
977 *error = g_strdup ("Couldn't send stop_scan command to scanner");
978 return -1;
979 }
980
981 rc = atoi (entity_attribute (entity, "status"));
982 if (rc == 200)
983 {
984 free_entity (entity);
985 return 0;
986 }
987 else
988 {
989 const char *text = entity_attribute (entity, "status_text");
990
991 assert (text);
992 if (error)
993 *error = g_strdup (text);
994 free_entity (entity);
995 return -1;
996 }
997}
998
1007static void
1008option_concat_as_xml (gpointer key, gpointer value, gpointer pstr)
1009{
1010 char *options_str, *tmp, *key_escaped, *value_escaped;
1011
1012 options_str = *(char **) pstr;
1013
1014 key_escaped = g_markup_escape_text ((char *) key, -1);
1015 value_escaped = g_markup_escape_text ((char *) value, -1);
1016 tmp = g_strdup_printf ("%s<%s>%s</%s>", options_str ? options_str : "",
1017 key_escaped, value_escaped, key_escaped);
1018
1019 g_free (options_str);
1020 g_free (key_escaped);
1021 g_free (value_escaped);
1022 *(char **) pstr = tmp;
1023}
1024
1037int
1038osp_start_scan (osp_connection_t *connection, const char *target,
1039 const char *ports, GHashTable *options, const char *scan_id,
1040 char **error)
1041{
1042 entity_t entity;
1043 char *options_str = NULL;
1044 int status;
1045 int rc;
1046
1047 if (!connection)
1048 {
1049 if (error)
1050 *error = g_strdup ("Couldn't send start_scan command "
1051 "to scanner. Not valid connection");
1052 return -1;
1053 }
1054
1055 assert (target);
1056 /* Construct options string. */
1057 if (options)
1058 g_hash_table_foreach (options, option_concat_as_xml, &options_str);
1059
1060 rc = osp_send_command (connection, &entity,
1061 "<start_scan target='%s' ports='%s' scan_id='%s'>"
1062 "<scanner_params>%s</scanner_params></start_scan>",
1063 target, ports ? ports : "", scan_id ? scan_id : "",
1064 options_str ? options_str : "");
1065 g_free (options_str);
1066 if (rc)
1067 {
1068 if (error)
1069 *error = g_strdup ("Couldn't send start_scan command to scanner");
1070 return -1;
1071 }
1072
1073 status = atoi (entity_attribute (entity, "status"));
1074 if (status == 200)
1075 {
1076 free_entity (entity);
1077 return 0;
1078 }
1079 else
1080 {
1081 const char *text = entity_attribute (entity, "status_text");
1082
1083 assert (text);
1084 if (error)
1085 *error = g_strdup (text);
1086 free_entity (entity);
1087 return -1;
1088 }
1089}
1090
1098static void
1099add_auth_data_key_value_as_xml (const char *key, const char *value,
1100 void *xml_string)
1101{
1102 if (!key || !value || !xml_string)
1103 return;
1104 xml_string_append ((GString *) xml_string, "<%s>%s</%s>", key, value, key);
1105}
1106
1114static void
1115credential_append_as_xml (scan_credential_t *credential, GString *xml_string)
1116
1117{
1118 const gchar *type = scan_credential_get_type (credential);
1119 const gchar *service = scan_credential_get_service (credential);
1120 const gchar *port = scan_credential_get_port (credential);
1121
1122 xml_string_append (
1123 xml_string, "<credential type=\"%s\" service=\"%s\" port=\"%s\">",
1124 type ? type : "", service ? service : "", port ? port : "");
1125
1126 scan_credential_foreach_auth_data (credential, add_auth_data_key_value_as_xml,
1127 xml_string);
1128
1129 xml_string_append (xml_string, "</credential>");
1130}
1131
1139static void
1140target_append_as_xml (osp_target_t *target, GString *xml_string)
1141{
1142 xml_string_append (xml_string,
1143 "<target>"
1144 "<hosts>%s</hosts>"
1145 "<exclude_hosts>%s</exclude_hosts>"
1146 "<finished_hosts>%s</finished_hosts>"
1147 "<ports>%s</ports>",
1148 target->hosts ? target->hosts : "",
1149 target->exclude_hosts ? target->exclude_hosts : "",
1150 target->finished_hosts ? target->finished_hosts : "",
1151 target->ports ? target->ports : "");
1152
1153 /* Alive test specified as bitfield */
1154 if (target->alive_test > 0)
1155 xml_string_append (xml_string, "<alive_test>%d</alive_test>",
1156 target->alive_test);
1157 /* Alive test specified via dedicated methods. Dedicted methods are ignored if
1158 * alive test was already specified as bitfield.*/
1159 else if (target->icmp == TRUE || target->tcp_syn == TRUE
1160 || target->tcp_ack == TRUE || target->arp == TRUE
1161 || target->consider_alive == TRUE)
1162 {
1163 xml_string_append (xml_string,
1164 "<alive_test_methods>"
1165 "<icmp>%d</icmp>"
1166 "<tcp_syn>%d</tcp_syn>"
1167 "<tcp_ack>%d</tcp_ack>"
1168 "<arp>%d</arp>"
1169 "<consider_alive>%d</consider_alive>"
1170 "</alive_test_methods>",
1171 target->icmp, target->tcp_syn, target->tcp_ack,
1172 target->arp, target->consider_alive);
1173 }
1174
1175 if (target->reverse_lookup_unify == 1)
1176 xml_string_append (xml_string,
1177 "<reverse_lookup_unify>%d</reverse_lookup_unify>",
1178 target->reverse_lookup_unify);
1179 if (target->reverse_lookup_only == 1)
1180 xml_string_append (xml_string,
1181 "<reverse_lookup_only>%d</reverse_lookup_only>",
1182 target->reverse_lookup_only);
1183
1184 if (target->credentials)
1185 {
1186 g_string_append (xml_string, "<credentials>");
1187 g_slist_foreach (target->credentials, (GFunc) credential_append_as_xml,
1188 xml_string);
1189 g_string_append (xml_string, "</credentials>");
1190 }
1191 xml_string_append (xml_string, "</target>");
1192}
1193
1200static void
1201vt_group_append_as_xml (osp_vt_group_t *vt_group, GString *xml_string)
1202{
1203 xml_string_append (xml_string, "<vt_group filter=\"%s\"/>", vt_group->filter);
1204}
1205
1214static void
1215vt_value_append_as_xml (gpointer id, gchar *value, GString *xml_string)
1216{
1217 xml_string_append (xml_string, "<vt_value id=\"%s\">%s</vt_value>",
1218 id ? id : "", value ? value : "");
1219}
1220
1227static void
1228vt_single_append_as_xml (osp_vt_single_t *vt_single, GString *xml_string)
1229{
1230 xml_string_append (xml_string, "<vt_single id=\"%s\">", vt_single->vt_id);
1231 g_hash_table_foreach (vt_single->vt_values, (GHFunc) vt_value_append_as_xml,
1232 xml_string);
1233 xml_string_append (xml_string, "</vt_single>");
1234}
1235
1245int
1246osp_start_scan_ext (osp_connection_t *connection, osp_start_scan_opts_t opts,
1247 char **error)
1248{
1249 gchar *scanner_params_xml = NULL;
1250 GString *xml;
1251 GSList *list_item;
1252 int list_count;
1253 int rc, status;
1254 entity_t entity;
1255 gchar *cmd;
1256 char filename[] = "/tmp/osp-cmd-XXXXXX";
1257 int fd;
1258
1259 if (!connection)
1260 {
1261 if (error)
1262 *error = g_strdup ("Couldn't send start_scan command "
1263 "to scanner. Not valid connection");
1264 return -1;
1265 }
1266
1267 fd = mkstemp (filename);
1268 FILE *file = fdopen (fd, "w");
1269
1270 xml = g_string_sized_new (10240);
1271 g_string_append (xml, "<start_scan");
1272 xml_string_append (xml, " scan_id=\"%s\">", opts.scan_id ? opts.scan_id : "");
1273
1274 g_string_append (xml, "<targets>");
1275 g_slist_foreach (opts.targets, (GFunc) target_append_as_xml, xml);
1276 g_string_append (xml, "</targets>");
1277
1278 g_string_append (xml, "<scanner_params>");
1279 if (opts.scanner_params)
1280 {
1281 scanner_params_xml = NULL;
1282 g_hash_table_foreach (opts.scanner_params, (GHFunc) option_concat_as_xml,
1283 &scanner_params_xml);
1284 if (scanner_params_xml)
1285 g_string_append (xml, scanner_params_xml);
1286 g_free (scanner_params_xml);
1287 }
1288 g_string_append (xml, "</scanner_params>");
1289
1290 g_string_append (xml, "<vt_selection>");
1291 g_slist_foreach (opts.vt_groups, (GFunc) vt_group_append_as_xml, xml);
1292
1293 fprintf (file, "%s", xml->str);
1294
1295 g_string_free (xml, TRUE);
1296
1297 xml = g_string_new ("");
1298 list_item = opts.vts;
1299 list_count = 0;
1300 while (list_item)
1301 {
1302 list_count++;
1303 vt_single_append_as_xml (list_item->data, xml);
1304
1305 list_item = list_item->next;
1306
1307 if (list_count == 1000)
1308 {
1309 fprintf (file, "%s", xml->str);
1310
1311 g_string_free (xml, TRUE);
1312 xml = g_string_new ("");
1313 list_count = 0;
1314 }
1315 }
1316
1317 g_string_append (xml, "</vt_selection>");
1318 g_string_append (xml, "</start_scan>");
1319
1320 fprintf (file, "%s", xml->str);
1321 fflush (file);
1322 fclose (file);
1323 g_string_free (xml, TRUE);
1324
1325 g_file_get_contents (filename, &cmd, NULL, NULL);
1326
1327 rc = osp_send_command (connection, &entity, "%s", cmd);
1328
1329 g_free (cmd);
1330 unlink (filename);
1331
1332 if (rc)
1333 {
1334 if (error)
1335 *error = g_strdup ("Could not send start_scan command to scanner");
1336 return -1;
1337 }
1338
1339 status = atoi (entity_attribute (entity, "status"));
1340 if (status == 200)
1341 {
1342 free_entity (entity);
1343 return 0;
1344 }
1345 else
1346 {
1347 const char *text = entity_attribute (entity, "status_text");
1348
1349 assert (text);
1350 if (error)
1351 *error = g_strdup (text);
1352 free_entity (entity);
1353 return -1;
1354 }
1355
1356 if (error)
1357 *error = NULL;
1358 free_entity (entity);
1359 return 0;
1360}
1361
1369static osp_param_type_t
1370osp_param_str_to_type (const char *str)
1371{
1372 assert (str);
1373 if (!strcmp (str, "integer"))
1374 return OSP_PARAM_TYPE_INT;
1375 else if (!strcmp (str, "string"))
1376 return OSP_PARAM_TYPE_STR;
1377 else if (!strcmp (str, "password"))
1378 return OSP_PARAM_TYPE_PASSWORD;
1379 else if (!strcmp (str, "file"))
1380 return OSP_PARAM_TYPE_FILE;
1381 else if (!strcmp (str, "boolean"))
1382 return OSP_PARAM_TYPE_BOOLEAN;
1383 else if (!strcmp (str, "ovaldef_file"))
1384 return OSP_PARAM_TYPE_OVALDEF_FILE;
1385 else if (!strcmp (str, "selection"))
1386 return OSP_PARAM_TYPE_SELECTION;
1387 else if (!strcmp (str, "credential_up"))
1388 return OSP_PARAM_TYPE_CRD_UP;
1389 assert (0);
1390 return 0;
1391}
1392
1400const char *
1401osp_param_type_str (const osp_param_t *param)
1402{
1403 osp_param_type_t type;
1404
1405 assert (param);
1406 type = param->type;
1407 if (type == OSP_PARAM_TYPE_INT)
1408 return "integer";
1409 else if (type == OSP_PARAM_TYPE_STR)
1410 return "string";
1411 else if (type == OSP_PARAM_TYPE_PASSWORD)
1412 return "password";
1413 else if (type == OSP_PARAM_TYPE_FILE)
1414 return "file";
1415 else if (type == OSP_PARAM_TYPE_BOOLEAN)
1416 return "boolean";
1417 else if (type == OSP_PARAM_TYPE_OVALDEF_FILE)
1418 return "ovaldef_file";
1419 else if (type == OSP_PARAM_TYPE_SELECTION)
1420 return "selection";
1421 else if (type == OSP_PARAM_TYPE_CRD_UP)
1422 return "credential_up";
1423 assert (0);
1424 return NULL;
1425}
1426
1436int
1437osp_get_scanner_details (osp_connection_t *connection, char **desc,
1438 GSList **params)
1439{
1440 entity_t entity, child;
1441 entities_t entities;
1442
1443 assert (connection);
1444
1445 if (osp_send_command (connection, &entity, "<get_scanner_details/>"))
1446 return 1;
1447 if (params)
1448 {
1449 child = entity_child (entity, "scanner_params");
1450 if (!child)
1451 {
1452 free_entity (entity);
1453 return 1;
1454 }
1455 entities = child->entities;
1456 while (entities)
1457 {
1458 osp_param_t *param;
1459
1460 child = entities->data;
1461 param = osp_param_new ();
1462 param->id = g_strdup (entity_attribute (child, "id"));
1463 param->type =
1464 osp_param_str_to_type (entity_attribute (child, "type"));
1465 param->name = g_strdup (entity_text (entity_child (child, "name")));
1466 param->desc =
1467 g_strdup (entity_text (entity_child (child, "description")));
1468 param->def = g_strdup (entity_text (entity_child (child, "default")));
1469 if (entity_child (child, "mandatory"))
1470 param->mandatory =
1471 atoi (entity_text (entity_child (child, "mandatory")));
1472 *params = g_slist_append (*params, param);
1473 entities = next_entities (entities);
1474 }
1475 }
1476 if (desc)
1477 {
1478 child = entity_child (entity, "description");
1479 assert (child);
1480 *desc = g_strdup (entity_text (child));
1481 }
1482
1483 free_entity (entity);
1484 return 0;
1485}
1486
1492 osp_param_t *
1493osp_param_new (void)
1494{
1495 return g_malloc0 (sizeof (osp_param_t));
1496}
1497
1505const char *
1506osp_param_id (const osp_param_t *param)
1507{
1508 assert (param);
1509
1510 return param->id;
1511}
1512
1520const char *
1521osp_param_name (const osp_param_t *param)
1522{
1523 assert (param);
1524
1525 return param->name;
1526}
1527
1535const char *
1536osp_param_desc (const osp_param_t *param)
1537{
1538 assert (param);
1539
1540 return param->desc;
1541}
1542
1550const char *
1551osp_param_default (const osp_param_t *param)
1552{
1553 assert (param);
1554
1555 return param->def;
1556}
1557
1565int
1566osp_param_mandatory (const osp_param_t *param)
1567{
1568 assert (param);
1569
1570 return param->mandatory;
1571}
1572
1578void
1579osp_param_free (osp_param_t *param)
1580{
1581 if (!param)
1582 return;
1583 g_free (param->id);
1584 g_free (param->name);
1585 g_free (param->desc);
1586 g_free (param->def);
1587 g_free (param);
1588}
1589
1602 osp_target_t *
1603osp_target_new (const char *hosts, const char *ports, const char *exclude_hosts,
1604 int alive_test, int reverse_lookup_unify,
1605 int reverse_lookup_only)
1606{
1607 osp_target_t *new_target;
1608 new_target = g_malloc0 (sizeof (osp_target_t));
1609
1610 new_target->exclude_hosts = exclude_hosts ? g_strdup (exclude_hosts) : NULL;
1611 new_target->hosts = hosts ? g_strdup (hosts) : NULL;
1612 new_target->ports = ports ? g_strdup (ports) : NULL;
1613 new_target->finished_hosts = NULL;
1614 new_target->alive_test = alive_test ? alive_test : 0;
1615 new_target->reverse_lookup_unify =
1616 reverse_lookup_unify ? reverse_lookup_unify : 0;
1617 new_target->reverse_lookup_only =
1618 reverse_lookup_only ? reverse_lookup_only : 0;
1619
1620 return new_target;
1621}
1622
1629void
1630osp_target_set_finished_hosts (osp_target_t *target, const char *finished_hosts)
1631{
1632 g_free (target->finished_hosts);
1633 target->finished_hosts = finished_hosts ? g_strdup (finished_hosts) : NULL;
1634}
1635
1641void
1642osp_target_free (osp_target_t *target)
1643{
1644 if (!target)
1645 return;
1646
1647 g_slist_free_full (target->credentials,
1648 (GDestroyNotify) scan_credential_free);
1649 g_free (target->exclude_hosts);
1650 g_free (target->hosts);
1651 g_free (target->ports);
1652 g_free (target);
1653}
1654
1665void
1666osp_target_add_alive_test_methods (osp_target_t *target, gboolean icmp,
1667 gboolean tcp_syn, gboolean tcp_ack,
1668 gboolean arp, gboolean consider_alive)
1669{
1670 if (!target)
1671 return;
1672
1673 target->icmp = icmp;
1674 target->tcp_syn = tcp_syn;
1675 target->tcp_ack = tcp_ack;
1676 target->arp = arp;
1677 target->consider_alive = consider_alive;
1678}
1679
1686void
1687osp_target_add_credential (osp_target_t *target, scan_credential_t *credential)
1688{
1689 if (!target || !credential)
1690 return;
1691
1692 target->credentials = g_slist_prepend (target->credentials, credential);
1693}
1694
1702 osp_vt_group_t *
1703osp_vt_group_new (const char *filter)
1704{
1705 osp_vt_group_t *new_vt_group;
1706 new_vt_group = g_malloc0 (sizeof (osp_vt_group_t));
1707
1708 new_vt_group->filter = filter ? g_strdup (filter) : NULL;
1709
1710 return new_vt_group;
1711}
1712
1718void
1719osp_vt_group_free (osp_vt_group_t *vt_group)
1720{
1721 if (!vt_group)
1722 return;
1723
1724 g_free (vt_group->filter);
1725 g_free (vt_group);
1726}
1727
1735 osp_vt_single_t *
1736osp_vt_single_new (const char *vt_id)
1737{
1738 osp_vt_single_t *new_vt_single;
1739 new_vt_single = g_malloc0 (sizeof (osp_vt_single_t));
1740
1741 new_vt_single->vt_id = vt_id ? g_strdup (vt_id) : NULL;
1742 new_vt_single->vt_values =
1743 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
1744
1745 return new_vt_single;
1746}
1747
1753void
1754osp_vt_single_free (osp_vt_single_t *vt_single)
1755{
1756 if (!vt_single)
1757 return;
1758
1759 g_hash_table_destroy (vt_single->vt_values);
1760
1761 g_free (vt_single->vt_id);
1762 g_free (vt_single);
1763}
1764
1773void
1774osp_vt_single_add_value (osp_vt_single_t *vt_single, const char *name,
1775 const char *value)
1776{
1777 g_hash_table_replace (vt_single->vt_values, g_strdup (name),
1778 g_strdup (value));
1779}
scan_credential_get_port
const gchar * scan_credential_get_port(scan_credential_t *credential)
Get the port of a scan credential.
Definition credentialutils.c:93
scan_credential_free
void scan_credential_free(scan_credential_t *credential)
Free a scan credential.
Definition credentialutils.c:134
scan_credential_get_type
const gchar * scan_credential_get_type(scan_credential_t *credential)
Get the type of a scan credential.
Definition credentialutils.c:63
scan_credential_foreach_auth_data
void scan_credential_foreach_auth_data(scan_credential_t *credential, void(*func)(const char *name, const char *value, void *user_data), void *user_data)
Iterate over each authentication data item in a scan credential.
Definition credentialutils.c:109
scan_credential_get_service
const gchar * scan_credential_get_service(scan_credential_t *credential)
Get the service of a scan credential.
Definition credentialutils.c:78
scan_credential_t
struct scan_credential scan_credential_t
Definition credentialutils.h:16
gvm_get_host_type
int gvm_get_host_type(const gchar *str_stripped)
Determines the host type in a buffer.
Definition hosts.c:814
hosts.h
Protos and data structures for Hosts collections and single hosts objects.
__attribute__
__attribute__((weak))
Definition networking_tests.c:1036
osp_target_add_credential
void osp_target_add_credential(osp_target_t *target, scan_credential_t *credential)
Add a credential to an OSP target.
Definition osp.c:1687
osp_check_feed
int osp_check_feed(osp_connection_t *connection, int *lockfile_in_use, int *self_test_exit_error, char **self_test_error_msg, char **cmd_error)
Gets additional status info about the feed.
Definition osp.c:307
osp_connection_close
void osp_connection_close(osp_connection_t *connection)
Close a connection to an OSP server.
Definition osp.c:279
osp_get_vts_ext_str
int osp_get_vts_ext_str(osp_connection_t *connection, osp_get_vts_opts_t opts, gchar **str)
Get filtered set of VTs from an OSP server.
Definition osp.c:670
osp_send_command
static int osp_send_command(osp_connection_t *, entity_t *, static intosp_send_command_str(osp_connection_t const char *,...)
Definition osp.c:96
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.
Definition osp.c:1246
osp_vt_group_free
void osp_vt_group_free(osp_vt_group_t *vt_group)
Free a OSP VT group.
Definition osp.c:1719
osp_target_add_alive_test_methods
void osp_target_add_alive_test_methods(osp_target_t *target, gboolean icmp, gboolean tcp_syn, gboolean tcp_ack, gboolean arp, gboolean consider_alive)
Add alive test methods to OSP target.
Definition osp.c:1666
osp_vt_group_new
osp_vt_group_t * osp_vt_group_new(const char *filter)
Create a new OSP VT group.
Definition osp.c:1703
osp_get_vts_feed_info
int osp_get_vts_feed_info(osp_connection_t *connection, char **vts_version, char **feed_name, char **feed_vendor, char **feed_home, char **error)
Get the VTs version as well as other feed info from an OSP server.
Definition osp.c:543
osp_target_set_finished_hosts
void osp_target_set_finished_hosts(osp_target_t *target, const char *finished_hosts)
Set the finished hosts of an OSP target.
Definition osp.c:1630
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:1370
add_auth_data_key_value_as_xml
static void add_auth_data_key_value_as_xml(const char *key, const char *value, void *xml_string)
Add authentication data key value as XML.
Definition osp.c:1099
osp_get_vts
int osp_get_vts(osp_connection_t *connection, entity_t *vts)
Get all VTs from an OSP server.
Definition osp.c:607
osp_get_scanner_details
int osp_get_scanner_details(osp_connection_t *connection, char **desc, GSList **params)
Get an OSP scanner's details.
Definition osp.c:1437
osp_param_desc
const char * osp_param_desc(const osp_param_t *param)
Get an OSP parameter's description.
Definition osp.c:1536
osp_delete_scan
int osp_delete_scan(osp_connection_t *connection, const char *scan_id)
Delete a scan from an OSP server.
Definition osp.c:708
osp_target_free
void osp_target_free(osp_target_t *target)
Free an OSP target, including all added credentials.
Definition osp.c:1642
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.
Definition osp.c:631
osp_vt_single_add_value
void osp_vt_single_add_value(osp_vt_single_t *vt_single, const char *name, const char *value)
Add a preference value to an OSP VT. This creates a copy of the name and value.
Definition osp.c:1774
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:1228
osp_vt_single_new
osp_vt_single_t * osp_vt_single_new(const char *vt_id)
Create a new single OSP VT.
Definition osp.c:1736
credential_append_as_xml
static void credential_append_as_xml(scan_credential_t *credential, GString *xml_string)
Concatenate a credential as XML.
Definition osp.c:1115
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.
Definition osp.c:943
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:880
vt_value_append_as_xml
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:1215
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.
Definition osp.c:1038
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:1140
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:1201
osp_vt_single_free
void osp_vt_single_free(osp_vt_single_t *vt_single)
Free a single OSP VT, including all preference values.
Definition osp.c:1754
option_concat_as_xml
static void option_concat_as_xml(gpointer key, gpointer value, gpointer pstr)
Concatenate options as xml.
Definition osp.c:1008
osp_param_new
osp_param_t * osp_param_new(void)
Create a new OSP parameter.
Definition osp.c:1493
osp_target_new
osp_target_t * osp_target_new(const char *hosts, const char *ports, const char *exclude_hosts, int alive_test, int reverse_lookup_unify, int reverse_lookup_only)
Create a new OSP target.
Definition osp.c:1603
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.
Definition osp.c:400
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.
Definition osp.c:1401
osp_send_command_str
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:229
osp_stop_scan
int osp_stop_scan(osp_connection_t *connection, const char *scan_id, char **error)
Stop a scan on an OSP server.
Definition osp.c:959
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.
Definition osp.c:743
osp_param_name
const char * osp_param_name(const osp_param_t *param)
Get an OSP parameter's name.
Definition osp.c:1521
osp_param_mandatory
int osp_param_mandatory(const osp_param_t *param)
Get an OSP parameter's mandatory value.
Definition osp.c:1566
osp_param_free
void osp_param_free(osp_param_t *param)
Free an OSP parameter.
Definition osp.c:1579
osp_get_vts_version
int osp_get_vts_version(osp_connection_t *connection, char **vts_version, char **error)
Get the VTs version from an OSP server.
Definition osp.c:485
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.
Definition osp.c:809
osp_param_id
const char * osp_param_id(const osp_param_t *param)
Get an OSP parameter's id.
Definition osp.c:1506
osp_param_default
const char * osp_param_default(const osp_param_t *param)
Get an OSP parameter's default value.
Definition osp.c:1551
osp.h
API for Open Scanner Protocol communication.
osp_connection_t
struct osp_connection osp_connection_t
Definition osp.h:21
osp_target_t
struct osp_target osp_target_t
Definition osp.h:23
osp_get_vts_opts_default
static const osp_get_vts_opts_t osp_get_vts_opts_default
Sensible default values for osp_get_vts_opts_t.
Definition osp.h:108
osp_vt_group_t
struct osp_vt_group osp_vt_group_t
Definition osp.h:25
osp_scan_status_t
osp_scan_status_t
OSP scan status.
Definition osp.h:48
OSP_SCAN_STATUS_QUEUED
@ OSP_SCAN_STATUS_QUEUED
Definition osp.h:54
OSP_SCAN_STATUS_STOPPED
@ OSP_SCAN_STATUS_STOPPED
Definition osp.h:52
OSP_SCAN_STATUS_INTERRUPTED
@ OSP_SCAN_STATUS_INTERRUPTED
Definition osp.h:55
OSP_SCAN_STATUS_FINISHED
@ OSP_SCAN_STATUS_FINISHED
Definition osp.h:53
OSP_SCAN_STATUS_RUNNING
@ OSP_SCAN_STATUS_RUNNING
Definition osp.h:51
OSP_SCAN_STATUS_ERROR
@ OSP_SCAN_STATUS_ERROR
Definition osp.h:49
OSP_SCAN_STATUS_INIT
@ OSP_SCAN_STATUS_INIT
Definition osp.h:50
osp_vt_single_t
struct osp_vt_single osp_vt_single_t
Definition osp.h:27
osp_connection_new
osp_connection_t * osp_connection_new(const char *, int, const char *, const char *, const char *)
osp_param_t
struct osp_param osp_param_t
Definition osp.h:70
osp_param_type_t
osp_param_type_t
OSP parameter types.
Definition osp.h:33
OSP_PARAM_TYPE_BOOLEAN
@ OSP_PARAM_TYPE_BOOLEAN
Definition osp.h:38
OSP_PARAM_TYPE_STR
@ OSP_PARAM_TYPE_STR
Definition osp.h:35
OSP_PARAM_TYPE_INT
@ OSP_PARAM_TYPE_INT
Definition osp.h:34
OSP_PARAM_TYPE_SELECTION
@ OSP_PARAM_TYPE_SELECTION
Definition osp.h:40
OSP_PARAM_TYPE_PASSWORD
@ OSP_PARAM_TYPE_PASSWORD
Definition osp.h:36
OSP_PARAM_TYPE_FILE
@ OSP_PARAM_TYPE_FILE
Definition osp.h:37
OSP_PARAM_TYPE_CRD_UP
@ OSP_PARAM_TYPE_CRD_UP
Definition osp.h:41
OSP_PARAM_TYPE_OVALDEF_FILE
@ OSP_PARAM_TYPE_OVALDEF_FILE
Definition osp.h:39
gvm_server_open_with_cert
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:461
gvm_server_vsendf
int gvm_server_vsendf(gnutls_session_t *session, const char *fmt, va_list ap)
Send a string to the server.
Definition serverutils.c:727
gvm_server_close
int gvm_server_close(int socket, gnutls_session_t session)
Close a server connection and its socket.
Definition serverutils.c:493
gvm_socket_vsendf
int gvm_socket_vsendf(int socket, const char *fmt, va_list ap)
Send a string to the server.
Definition serverutils.c:742
serverutils.h
GnuTLS based functions for server communication - header file.
entity_s::entities
entities_t entities
Children.
Definition xmlutils.h:56
gvm_connection_t
Connection.
Definition serverutils.h:30
gvm_connection_t::port
gint port
Port of server.
Definition serverutils.h:39
gvm_connection_t::tls
int tls
Whether uses TCP-TLS (vs UNIX socket).
Definition serverutils.h:31
gvm_connection_t::socket
int socket
Socket.
Definition serverutils.h:32
gvm_connection_t::host_string
gchar * host_string
Server host string.
Definition serverutils.h:37
gvm_connection_t::session
gnutls_session_t session
Session.
Definition serverutils.h:33
osp_connection
Struct holding options for OSP connection.
Definition osp.c:36
osp_connection::port
int port
Definition osp.c:40
osp_connection::socket
int socket
Definition osp.c:38
osp_connection::host
char * host
Definition osp.c:39
osp_connection::session
gnutls_session_t session
Definition osp.c:37
osp_get_performance_opts_t
Definition osp.h:64
osp_get_performance_opts_t::start
int start
Definition osp.h:65
osp_get_performance_opts_t::titles
char * titles
Definition osp.h:67
osp_get_performance_opts_t::end
int end
Definition osp.h:66
osp_get_scan_status_opts_t
Definition osp.h:59
osp_get_scan_status_opts_t::scan_id
const char * scan_id
UUID of the scan which get the status from.
Definition osp.h:60
osp_get_vts_opts_t
Definition osp.h:100
osp_get_vts_opts_t::filter
char * filter
the filter to apply for a vt sub-selection.
Definition osp.h:101
osp_get_vts_opts_t::version_only
int version_only
if get only feed info or the vt collection
Definition osp.h:102
osp_param
Struct holding options for OSP parameters.
Definition osp.c:47
osp_param::def
char * def
Definition osp.c:51
osp_param::id
char * id
Definition osp.c:48
osp_param::mandatory
int mandatory
Definition osp.c:53
osp_param::name
char * name
Definition osp.c:49
osp_param::type
osp_param_type_t type
Definition osp.c:52
osp_param::desc
char * desc
Definition osp.c:50
osp_start_scan_opts_t
Definition osp.h:121
osp_start_scan_opts_t::targets
GSList * targets
Target hosts to scan.
Definition osp.h:122
osp_start_scan_opts_t::vts
GSList * vts
Single VTs to use for the scan.
Definition osp.h:124
osp_start_scan_opts_t::vt_groups
GSList * vt_groups
VT groups to use for the scan.
Definition osp.h:123
osp_start_scan_opts_t::scanner_params
GHashTable * scanner_params
Table of scanner parameters.
Definition osp.h:125
osp_start_scan_opts_t::scan_id
const char * scan_id
UUID to set for scan, null otherwise.
Definition osp.h:126
osp_target
Struct holding target information.
Definition osp.c:60
osp_target::reverse_lookup_only
int reverse_lookup_only
Definition osp.c:75
osp_target::hosts
gchar * hosts
Definition osp.c:63
osp_target::credentials
GSList * credentials
Definition osp.c:61
osp_target::tcp_syn
gboolean tcp_syn
Definition osp.c:70
osp_target::reverse_lookup_unify
int reverse_lookup_unify
Definition osp.c:74
osp_target::alive_test
int alive_test
Definition osp.c:68
osp_target::arp
gboolean arp
Definition osp.c:72
osp_target::exclude_hosts
gchar * exclude_hosts
Definition osp.c:62
osp_target::icmp
gboolean icmp
Definition osp.c:69
osp_target::consider_alive
gboolean consider_alive
Definition osp.c:73
osp_target::ports
gchar * ports
Definition osp.c:64
osp_target::tcp_ack
gboolean tcp_ack
Definition osp.c:71
osp_target::finished_hosts
gchar * finished_hosts
Definition osp.c:65
osp_vt_group
Struct holding vt_group information.
Definition osp.c:82
osp_vt_group::filter
gchar * filter
Definition osp.c:83
osp_vt_single
Struct holding vt_group information.
Definition osp.c:90
osp_vt_single::vt_values
GHashTable * vt_values
Definition osp.c:92
osp_vt_single::vt_id
gchar * vt_id
Definition osp.c:91
entity_attribute
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
Definition xmlutils.c:216
entity_text
char * entity_text(entity_t entity)
Get the text an entity.
Definition xmlutils.c:145
read_entity
int read_entity(gnutls_session_t *session, entity_t *entity)
Read an XML entity tree from the manager.
Definition xmlutils.c:1469
next_entities
entities_t next_entities(entities_t entities)
Return all the entities from an entities_t after the first.
Definition xmlutils.c:67
free_entity
void free_entity(entity_t entity)
Free an entity, recursively.
Definition xmlutils.c:115
read_text_c
int read_text_c(gvm_connection_t *connection, char **text)
Read text from the server.
Definition xmlutils.c:1366
entity_child
entity_t entity_child(entity_t entity, const char *name)
Get a child of an entity.
Definition xmlutils.c:193
read_entity_s
int read_entity_s(int socket, entity_t *entity)
Read an XML entity tree from the socket.
Definition xmlutils.c:1483
xml_string_append
void xml_string_append(GString *xml, const char *format,...)
Append formatted escaped XML to a string.
Definition xmlutils.c:1849
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:1616
entity_t
struct entity_s * entity_t
Definition xmlutils.h:58
entities_t
GSList * entities_t
Entities.
Definition xmlutils.h:46