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

Greenbone Vulnerability Management Libraries 23.7.0

gmp.c
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009-2023 Greenbone AG
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later
4 */
5
15
16#include "gmp.h"
17
18#include "../util/serverutils.h" /* for gvm_server_sendf, gvm_server_sendf_xml */
19
20#include <errno.h> /* for ERANGE, errno */
21#include <stdlib.h> /* for NULL, strtol, atoi */
22#include <strings.h>
23
24#undef G_LOG_DOMAIN
28#define G_LOG_DOMAIN "libgvm gmp"
29
30#define GMP_FMT_BOOL_ATTRIB(var, attrib) \
31 (var.attrib == 0 ? " " #attrib "=\"0\"" : " " #attrib "=\"1\"")
32
33#define GMP_FMT_STRING_ATTRIB(var, attrib) \
34 (var.attrib ? " " #attrib "= \"" : ""), (var.attrib ? var.attrib : ""), \
35 (var.attrib ? "\"" : "")
36
37/* GMP. */
38
47const char *
48gmp_task_status (entity_t response)
49{
50 entity_t task = entity_child (response, "task");
51 if (task)
52 {
53 entity_t status = entity_child (task, "status");
54 if (status)
55 return entity_text (status);
56 }
57 return NULL;
58}
59
69static int
70gmp_check_response (gnutls_session_t *session, entity_t *entity)
71{
72 int ret;
73 const char *status;
74
75 /* Read the response. */
76
77 *entity = NULL;
78 if (read_entity (session, entity))
79 return -1;
80
81 /* Check the response. */
82
83 status = entity_attribute (*entity, "status");
84 if (status == NULL)
85 {
86 free_entity (*entity);
87 *entity = NULL;
88 return -1;
89 }
90 if (strlen (status) == 0)
91 {
92 free_entity (*entity);
93 *entity = NULL;
94 return -1;
95 }
96 if (status[0] == '2')
97 {
98 return 0;
99 }
100 ret = (int) strtol (status, NULL, 10);
101 free_entity (*entity);
102 *entity = NULL;
103 if (errno == ERANGE)
104 return -1;
105 return ret;
106}
107
118static int
119check_response_c (gvm_connection_t *connection, int convert_99)
120{
121 int ret;
122 const char *status;
123 entity_t entity;
124
125 /* Read the response. */
126
127 entity = NULL;
128 if (read_entity_c (connection, &entity))
129 return -1;
130
131 /* Check the response. */
132
133 status = entity_attribute (entity, "status");
134 if (status == NULL)
135 {
136 free_entity (entity);
137 return -1;
138 }
139 if (strlen (status) == 0)
140 {
141 free_entity (entity);
142 return -1;
143 }
144 if (status[0] == '2')
145 {
146 free_entity (entity);
147 return 0;
148 }
149 ret = (int) strtol (status, NULL, 10);
150 if (errno == ERANGE)
151 {
152 free_entity (entity);
153 return -1;
154 }
155
156 if (convert_99 && entity_attribute (entity, "status_text")
157 && strcasecmp (entity_attribute (entity, "status_text"),
158 "Permission denied")
159 == 0)
160 ret = 99;
161
162 free_entity (entity);
163 return ret;
164}
165
173static int
174gmp_check_response_c (gvm_connection_t *connection)
175{
176 return check_response_c (connection, 0);
177}
178
189int
190gmp_ping (gnutls_session_t *session, int timeout)
191{
192 entity_t entity;
193 const char *status;
194 char first;
195 int ret;
196
197 /* Send a GET_VERSION request. */
198
199 ret = gvm_server_sendf (session, "<get_version/>");
200 if (ret)
201 return ret;
202
203 /* Read the response, with a timeout. */
204
205 entity = NULL;
206 switch (try_read_entity (session, timeout, &entity))
207 {
208 case 0:
209 break;
210 case -4:
211 return 2;
212 default:
213 return -1;
214 }
215
216 /* Check the response. */
217
218 status = entity_attribute (entity, "status");
219 if (status == NULL)
220 {
221 free_entity (entity);
222 return -1;
223 }
224 if (strlen (status) == 0)
225 {
226 free_entity (entity);
227 return -1;
228 }
229 first = status[0];
230 free_entity (entity);
231 if (first == '2')
232 return 0;
233 return -1;
234}
235
248int
249gmp_ping_c (gvm_connection_t *connection, int timeout, gchar **version)
250{
251 entity_t entity;
252 const char *status;
253 int ret;
254
255 if (version && *version)
256 *version = NULL;
257
258 /* Send a GET_VERSION request. */
259
260 ret = gvm_connection_sendf (connection, "<get_version/>");
261 if (ret)
262 return ret;
263
264 /* Read the response, with a timeout. */
265
266 entity = NULL;
267 switch (try_read_entity_c (connection, timeout, &entity))
268 {
269 case 0:
270 break;
271 case -4:
272 return 2;
273 default:
274 return -1;
275 }
276
277 /* Check the response. */
278
279 status = entity_attribute (entity, "status");
280 if (status == NULL)
281 {
282 free_entity (entity);
283 return -1;
284 }
285 if (strlen (status) == 0)
286 {
287 free_entity (entity);
288 return -1;
289 }
290 if (status[0] == '2')
291 {
292 if (version)
293 {
294 entity_t omp_version;
295 omp_version = entity_child (entity, "version");
296 if (omp_version == NULL)
297 {
298 free_entity (entity);
299 return -1;
300 }
301 *version = strdup (entity_text (omp_version));
302 }
303 free_entity (entity);
304 return 0;
305 }
306 free_entity (entity);
307 return -1;
308}
309
320int
321gmp_authenticate (gnutls_session_t *session, const char *username,
322 const char *password)
323{
324 entity_t entity;
325 int ret;
326
327 /* Send the auth request. */
328 ret = gvm_server_sendf_xml_quiet (session,
329 "<authenticate><credentials>"
330 "<username>%s</username>"
331 "<password>%s</password>"
332 "</credentials></authenticate>",
333 username ? username : "",
334 password ? password : "");
335 if (ret)
336 return ret;
337
338 /* Read the response. */
339
340 entity = NULL;
341 ret = gmp_check_response (session, &entity);
342 if (ret == 0)
343 {
344 free_entity (entity);
345 return ret;
346 }
347 else if (ret == -1)
348 return ret;
349 return 2;
350}
351
363int
364gmp_authenticate_info_ext (gnutls_session_t *session,
365 gmp_authenticate_info_opts_t opts)
366{
367 entity_t entity;
368 const char *status;
369 char first;
370 int ret;
371
372 *(opts.timezone) = NULL;
373
374 /* Send the auth request. */
375
376 ret = gvm_server_sendf_xml_quiet (session,
377 "<authenticate><credentials>"
378 "<username>%s</username>"
379 "<password>%s</password>"
380 "</credentials></authenticate>",
381 opts.username, opts.password);
382 if (ret)
383 return ret;
384
385 /* Read the response. */
386
387 entity = NULL;
388 switch (try_read_entity (session, opts.timeout, &entity))
389 {
390 case 0:
391 break;
392 case -4:
393 return 3;
394 default:
395 return -1;
396 }
397
398 /* Check the response. */
399
400 status = entity_attribute (entity, "status");
401 if (status == NULL)
402 {
403 free_entity (entity);
404 return -1;
405 }
406 if (strlen (status) == 0)
407 {
408 free_entity (entity);
409 return -1;
410 }
411 first = status[0];
412 if (first == '2')
413 {
414 entity_t timezone_entity, role_entity, pw_warn_entity;
415 /* Get the extra info. */
416 timezone_entity = entity_child (entity, "timezone");
417 if (timezone_entity)
418 *opts.timezone = g_strdup (entity_text (timezone_entity));
419 role_entity = entity_child (entity, "role");
420 if (role_entity)
421 *opts.role = g_strdup (entity_text (role_entity));
422 pw_warn_entity = entity_child (entity, "password_warning");
423 if (pw_warn_entity)
424 *(opts.pw_warning) = g_strdup (entity_text (pw_warn_entity));
425 else
426 *(opts.pw_warning) = NULL;
427
428 free_entity (entity);
429 return 0;
430 }
431 free_entity (entity);
432 return 2;
433}
434
444int
445gmp_authenticate_info_ext_c (gvm_connection_t *connection,
446 gmp_authenticate_info_opts_t opts)
447{
448 entity_t entity;
449 const char *status;
450 char first;
451 int ret;
452
453 if (opts.role)
454 *opts.role = NULL;
455 if (opts.timezone)
456 *opts.timezone = NULL;
457 if (opts.pw_warning)
458 *opts.pw_warning = NULL;
459 if (opts.jwt)
460 *opts.jwt = NULL;
461
462 /* Send the auth request. */
463
464 ret = gvm_connection_sendf_xml_quiet (connection,
465 "<authenticate token=\"%d\">"
466 "<credentials>"
467 "<username>%s</username>"
468 "<password>%s</password>"
469 "</credentials>"
470 "</authenticate>",
471 opts.jwt_requested, opts.username,
472 opts.password);
473 if (ret)
474 return ret;
475
476 /* Read the response. */
477
478 entity = NULL;
479 switch (try_read_entity_c (connection, opts.timeout, &entity))
480 {
481 case 0:
482 break;
483 case -4:
484 return 3;
485 default:
486 return -1;
487 }
488
489 /* Check the response. */
490
491 status = entity_attribute (entity, "status");
492 if (status == NULL)
493 {
494 free_entity (entity);
495 return -1;
496 }
497 if (strlen (status) == 0)
498 {
499 free_entity (entity);
500 return -1;
501 }
502 first = status[0];
503 if (first == '2')
504 {
505 entity_t timezone_entity, role_entity, token_entity;
506 /* Get the extra info. */
507 timezone_entity = entity_child (entity, "timezone");
508 if (timezone_entity && opts.timezone)
509 *opts.timezone = g_strdup (entity_text (timezone_entity));
510 role_entity = entity_child (entity, "role");
511 if (role_entity && opts.role)
512 *opts.role = g_strdup (entity_text (role_entity));
513 if (opts.pw_warning)
514 {
515 entity_t pw_warn_entity;
516 pw_warn_entity = entity_child (entity, "password_warning");
517 if (pw_warn_entity)
518 *(opts.pw_warning) = g_strdup (entity_text (pw_warn_entity));
519 else
520 *(opts.pw_warning) = NULL;
521 }
522 token_entity = entity_child (entity, "token");
523 if (token_entity && opts.jwt_requested == 1 && opts.jwt)
524 *opts.jwt = g_strdup (entity_text (token_entity));
525
526 free_entity (entity);
527 return 0;
528 }
529 free_entity (entity);
530 return 2;
531}
532
546int
547gmp_create_task_ext (gnutls_session_t *session, gmp_create_task_opts_t opts,
548 gchar **id)
549{
550 /* Create the GMP request. */
551
552 gchar *prefs, *start, *scanner, *schedule, *slave;
553 GString *alerts, *observers;
554 int ret;
555 if ((opts.config_id == NULL) || (opts.target_id == NULL))
556 return -1;
557
558 prefs = NULL;
559 start = g_markup_printf_escaped (
560 "<create_task>"
561 "<config id=\"%s\"/>"
562 "<target id=\"%s\"/>"
563 "<name>%s</name>"
564 "<comment>%s</comment>"
565 "<alterable>%d</alterable>",
566 opts.config_id, opts.target_id, opts.name ? opts.name : "unnamed",
567 opts.comment ? opts.comment : "", opts.alterable ? 1 : 0);
568
569 if (opts.scanner_id)
570 scanner = g_strdup_printf ("<scanner id=\"%s\"/>", opts.scanner_id);
571 else
572 scanner = NULL;
573
574 if (opts.schedule_id)
575 schedule = g_strdup_printf ("<schedule id=\"%s\"/>"
576 "<schedule_periods>%d</schedule_periods>",
577 opts.schedule_id, opts.schedule_periods);
578 else
579 schedule = NULL;
580
581 if (opts.slave_id)
582 slave = g_strdup_printf ("<slave id=\"%s\"/>", opts.slave_id);
583 else
584 slave = NULL;
585
586 if (opts.max_checks || opts.max_hosts || opts.in_assets || opts.source_iface)
587 {
588 gchar *in_assets, *checks, *hosts, *source_iface;
589
590 in_assets = checks = hosts = source_iface = NULL;
591
592 if (opts.in_assets)
593 in_assets = g_markup_printf_escaped ("<preference>"
594 "<scanner_name>"
595 "in_assets"
596 "</scanner_name>"
597 "<value>"
598 "%s"
599 "</value>"
600 "</preference>",
601 opts.in_assets);
602
603 if (opts.max_hosts)
604 hosts = g_markup_printf_escaped ("<preference>"
605 "<scanner_name>"
606 "max_hosts"
607 "</scanner_name>"
608 "<value>"
609 "%s"
610 "</value>"
611 "</preference>",
612 opts.max_hosts);
613
614 if (opts.max_checks)
615 checks = g_markup_printf_escaped ("<preference>"
616 "<scanner_name>"
617 "max_checks"
618 "</scanner_name>"
619 "<value>"
620 "%s"
621 "</value>"
622 "</preference>",
623 opts.max_checks);
624
625 if (opts.source_iface)
626 source_iface = g_markup_printf_escaped ("<preference>"
627 "<scanner_name>"
628 "source_iface"
629 "</scanner_name>"
630 "<value>"
631 "%s"
632 "</value>"
633 "</preference>",
634 opts.source_iface);
635
636 prefs =
637 g_strdup_printf ("<preferences>%s%s%s%s</preferences>",
638 in_assets ? in_assets : "", checks ? checks : "",
639 hosts ? hosts : "", source_iface ? source_iface : "");
640 g_free (in_assets);
641 g_free (checks);
642 g_free (hosts);
643 g_free (source_iface);
644 }
645
646 if (opts.alert_ids)
647 {
648 unsigned int i;
649 alerts = g_string_new ("");
650 for (i = 0; i < opts.alert_ids->len; i++)
651 {
652 char *alert = (char *) g_ptr_array_index (opts.alert_ids, i);
653 g_string_append_printf (alerts, "<alert id=\"%s\"/>", alert);
654 }
655 }
656 else
657 alerts = g_string_new ("");
658
659 if (opts.observers || opts.observer_groups)
660 {
661 observers = g_string_new ("<observers>");
662
663 if (opts.observers)
664 g_string_append (observers, opts.observers);
665
666 if (opts.observer_groups)
667 {
668 unsigned int i;
669 for (i = 0; i < opts.observer_groups->len; i++)
670 {
671 char *group =
672 (char *) g_ptr_array_index (opts.observer_groups, i);
673 g_string_append_printf (observers, "<group id=\"%s\"/>", group);
674 }
675 }
676 g_string_append (observers, "</observers>");
677 }
678 else
679 observers = g_string_new ("");
680
681 /* Send the request. */
682 ret = gvm_server_sendf (
683 session, "%s%s%s%s%s%s%s</create_task>", start, prefs ? prefs : "",
684 scanner ? scanner : "", schedule ? schedule : "", slave ? slave : "",
685 alerts ? alerts->str : "", observers ? observers->str : "");
686 g_free (start);
687 g_free (prefs);
688 g_free (scanner);
689 g_free (schedule);
690 g_free (slave);
691 g_string_free (alerts, TRUE);
692 g_string_free (observers, TRUE);
693
694 if (ret)
695 return -1;
696
697 /* Read the response. */
698
699 ret = gmp_read_create_response (session, id);
700 if (ret == 201)
701 return 0;
702 return ret;
703}
704
718int
719gmp_create_task (gnutls_session_t *session, const char *name,
720 const char *config, const char *target, const char *comment,
721 gchar **id)
722{
723 int ret;
724
725 ret = gvm_server_sendf_xml (session,
726 "<create_task>"
727 "<config id=\"%s\"/>"
728 "<target id=\"%s\"/>"
729 "<name>%s</name>"
730 "<comment>%s</comment>"
731 "</create_task>",
732 config, target, name, comment);
733 if (ret)
734 return -1;
735
736 /* Read the response. */
737
738 ret = gmp_read_create_response (session, id);
739 if (ret == 201)
740 return 0;
741 return ret;
742}
743
753int
754gmp_start_task_report (gnutls_session_t *session, const char *task_id,
755 char **report_id)
756{
757 int ret;
758 entity_t entity;
759 if (gvm_server_sendf (session, "<start_task task_id=\"%s\"/>", task_id) == -1)
760 return -1;
761
762 /* Read the response. */
763
764 entity = NULL;
765 ret = gmp_check_response (session, &entity);
766
767 if (ret == 0)
768 {
769 if (report_id)
770 {
771 entity_t report_id_xml = entity_child (entity, "report_id");
772 if (report_id_xml)
773 *report_id = g_strdup (entity_text (report_id_xml));
774 else
775 {
776 free_entity (entity);
777 return -1;
778 }
779 }
780 free_entity (entity);
781 return ret;
782 }
783 else if (ret == -1)
784 return ret;
785
786 return 1;
787}
788
798int
799gmp_start_task_report_c (gvm_connection_t *connection, const char *task_id,
800 char **report_id)
801{
802 entity_t entity;
803 const char *status;
804 char first;
805
806 if (gvm_connection_sendf (connection, "<start_task task_id=\"%s\"/>", task_id)
807 == -1)
808 return -1;
809
810 /* Read the response. */
811
812 entity = NULL;
813 if (read_entity_c (connection, &entity))
814 return -1;
815
816 /* Check the response. */
817
818 status = entity_attribute (entity, "status");
819 if (status == NULL)
820 {
821 free_entity (entity);
822 return -1;
823 }
824 if (strlen (status) == 0)
825 {
826 free_entity (entity);
827 return -1;
828 }
829 first = status[0];
830 if (first == '2')
831 {
832 if (report_id)
833 {
834 entity_t report_id_xml = entity_child (entity, "report_id");
835 if (report_id_xml)
836 *report_id = g_strdup (entity_text (report_id_xml));
837 else
838 {
839 free_entity (entity);
840 return -1;
841 }
842 }
843 free_entity (entity);
844 return 0;
845 }
846 free_entity (entity);
847 return 1;
848}
849
858int
859gmp_start_task_ext_c (gvm_connection_t *connection, gmp_start_task_opts_t opts)
860{
861 int ret;
862
863 /* Check args. */
864
865 if (opts.task_id == NULL)
866 return -1;
867
868 /* Send request. */
869
870 ret = gvm_connection_sendf (connection, "<start_task task_id=\"%s\"/>",
871 opts.task_id);
872 if (ret)
873 return -1;
874
875 /* Read response. */
876
877 return check_response_c (connection, 1);
878}
879
889int
890gmp_read_create_response (gnutls_session_t *session, gchar **uuid)
891{
892 int ret;
893 const char *status;
894 entity_t entity;
895
896 /* Read the response. */
897
898 entity = NULL;
899 if (read_entity (session, &entity))
900 return -1;
901
902 /* Parse the response. */
903
904 status = entity_attribute (entity, "status");
905 if (status == NULL)
906 {
907 free_entity (entity);
908 return -1;
909 }
910 if (strlen (status) == 0)
911 {
912 free_entity (entity);
913 return -1;
914 }
915
916 if (uuid)
917 {
918 const char *id;
919
920 id = entity_attribute (entity, "id");
921 if (id == NULL)
922 {
923 free_entity (entity);
924 return -1;
925 }
926 if (strlen (id) == 0)
927 {
928 free_entity (entity);
929 return -1;
930 }
931 *uuid = g_strdup (id);
932 }
933
934 ret = atoi (status);
935 free_entity (entity);
936 return ret;
937}
938
947int
948gmp_stop_task (gnutls_session_t *session, const char *id)
949{
950 entity_t entity;
951 int ret;
952
953 if (gvm_server_sendf (session, "<stop_task task_id=\"%s\"/>", id) == -1)
954 return -1;
955
956 entity = NULL;
957 ret = gmp_check_response (session, &entity);
958 if (ret == 0)
959 free_entity (entity);
960 return ret;
961}
962
971int
972gmp_stop_task_c (gvm_connection_t *connection, const char *id)
973{
974 if (gvm_connection_sendf (connection, "<stop_task task_id=\"%s\"/>", id)
975 == -1)
976 return -1;
977
978 return gmp_check_response_c (connection);
979}
980
990int
991gmp_resume_task_report (gnutls_session_t *session, const char *task_id,
992 char **report_id)
993{
994 int ret;
995 entity_t entity;
996 if (gvm_server_sendf (session, "<resume_task task_id=\"%s\"/>", task_id)
997 == -1)
998 return -1;
999
1000 /* Read the response. */
1001
1002 entity = NULL;
1003 ret = gmp_check_response (session, &entity);
1004
1005 if (ret == 0)
1006 {
1007 if (report_id)
1008 {
1009 entity_t report_id_xml = entity_child (entity, "report_id");
1010 if (report_id_xml)
1011 *report_id = g_strdup (entity_text (report_id_xml));
1012 else
1013 {
1014 free_entity (entity);
1015 return -1;
1016 }
1017 }
1018 free_entity (entity);
1019 return 0;
1020 }
1021 else if (ret == -1)
1022 return ret;
1023 return 1;
1024}
1025
1035int
1036gmp_resume_task_report_c (gvm_connection_t *connection, const char *task_id,
1037 char **report_id)
1038{
1039 if (gvm_connection_sendf (connection, "<resume_task task_id=\"%s\"/>",
1040 task_id)
1041 == -1)
1042 return -1;
1043
1044 /* Read the response. */
1045
1046 entity_t entity = NULL;
1047 if (read_entity_c (connection, &entity))
1048 return -1;
1049
1050 /* Check the response. */
1051
1052 const char *status = entity_attribute (entity, "status");
1053 if (status == NULL)
1054 {
1055 free_entity (entity);
1056 return -1;
1057 }
1058 if (strlen (status) == 0)
1059 {
1060 free_entity (entity);
1061 return -1;
1062 }
1063 char first = status[0];
1064 if (first == '2')
1065 {
1066 if (report_id)
1067 {
1068 entity_t report_id_xml = entity_child (entity, "report_id");
1069 if (report_id_xml)
1070 *report_id = g_strdup (entity_text (report_id_xml));
1071 else
1072 {
1073 free_entity (entity);
1074 return -1;
1075 }
1076 }
1077 free_entity (entity);
1078 return 0;
1079 }
1080 free_entity (entity);
1081 return 1;
1082}
1083
1093int
1094gmp_delete_task_ext (gnutls_session_t *session, const char *id,
1095 gmp_delete_opts_t opts)
1096{
1097 entity_t entity;
1098 int ret;
1099
1100 if (gvm_server_sendf (session,
1101 "<delete_task task_id=\"%s\" ultimate=\"%d\"/>", id,
1102 opts.ultimate)
1103 == -1)
1104 return -1;
1105
1106 entity = NULL;
1107 ret = gmp_check_response (session, &entity);
1108 if (ret == 0)
1109 free_entity (entity);
1110 return ret;
1111}
1112
1125int
1126gmp_get_tasks (gnutls_session_t *session, const char *id, int details,
1127 int include_rcfile, entity_t *status)
1128{
1129 (void) include_rcfile;
1130 if (id == NULL)
1131 {
1132 if (gvm_server_sendf (session, "<get_tasks details=\"%i\"/>", details)
1133 == -1)
1134 return -1;
1135 }
1136 else
1137 {
1138 if (gvm_server_sendf (session,
1139 "<get_tasks"
1140 " task_id=\"%s\""
1141 " details=\"%i\"/>",
1142 id, details)
1143 == -1)
1144 return -1;
1145 }
1146
1147 /* Read the response. */
1148 return gmp_check_response (session, status);
1149}
1150
1160int
1161gmp_get_task_ext (gnutls_session_t *session, gmp_get_task_opts_t opts,
1162 entity_t *response)
1163{
1164 if ((response == NULL) || (opts.task_id == NULL))
1165 return -1;
1166
1167 if (opts.actions)
1168 {
1169 if (gvm_server_sendf (session,
1170 "<get_tasks"
1171 " task_id=\"%s\""
1172 " actions=\"%s\""
1173 "%s/>",
1174 opts.task_id, opts.actions,
1175 GMP_FMT_BOOL_ATTRIB (opts, details)))
1176 return -1;
1177 }
1178 else if (gvm_server_sendf (session,
1179 "<get_tasks"
1180 " task_id=\"%s\""
1181 "%s/>",
1182 opts.task_id, GMP_FMT_BOOL_ATTRIB (opts, details)))
1183 return -1;
1184
1185 return gmp_check_response (session, response);
1186}
1187
1197int
1198gmp_get_tasks_ext (gnutls_session_t *session, gmp_get_tasks_opts_t opts,
1199 entity_t *response)
1200{
1201 int ret;
1202 const char *status_code;
1203 gchar *cmd;
1204
1205 if (response == NULL)
1206 return -1;
1207
1208 cmd = g_markup_printf_escaped ("<get_tasks"
1209 " filter=\"%s\"",
1210 opts.filter);
1211
1212 if (gvm_server_sendf (session, "%s%s/>", cmd,
1213 GMP_FMT_BOOL_ATTRIB (opts, details)))
1214 {
1215 g_free (cmd);
1216 return -1;
1217 }
1218 g_free (cmd);
1219
1220 *response = NULL;
1221 switch (try_read_entity (session, opts.timeout, response))
1222 {
1223 case 0:
1224 break;
1225 case -4:
1226 return 2;
1227 default:
1228 return -1;
1229 }
1230
1231 /* Check the response. */
1232
1233 status_code = entity_attribute (*response, "status");
1234 if (status_code == NULL)
1235 {
1236 free_entity (*response);
1237 return -1;
1238 }
1239 if (strlen (status_code) == 0)
1240 {
1241 free_entity (*response);
1242 return -1;
1243 }
1244 if (status_code[0] == '2')
1245 return 0;
1246 ret = (int) strtol (status_code, NULL, 10);
1247 free_entity (*response);
1248 if (errno == ERANGE)
1249 return -1;
1250 return ret;
1251}
1252
1264int
1265gmp_modify_task_file (gnutls_session_t *session, const char *id,
1266 const char *name, const void *content, gsize content_len)
1267{
1268 entity_t entity;
1269 int ret;
1270
1271 if (name == NULL)
1272 return -1;
1273
1274 if (gvm_server_sendf (session, "<modify_task task_id=\"%s\">", id))
1275 return -1;
1276
1277 if (content)
1278 {
1279 if (gvm_server_sendf (session, "<file name=\"%s\" action=\"update\">",
1280 name))
1281 return -1;
1282
1283 if (content_len)
1284 {
1285 gchar *base64_content =
1286 g_base64_encode ((guchar *) content, content_len);
1287 ret = gvm_server_sendf (session, "%s", base64_content);
1288 g_free (base64_content);
1289 if (ret)
1290 return -1;
1291 }
1292
1293 if (gvm_server_sendf (session, "</file>"))
1294 return -1;
1295 }
1296 else
1297 {
1298 if (gvm_server_sendf (session, "<file name=\"%s\" action=\"remove\" />",
1299 name))
1300 return -1;
1301 }
1302
1303 if (gvm_server_sendf (session, "</modify_task>"))
1304 return -1;
1305
1306 entity = NULL;
1307 ret = gmp_check_response (session, &entity);
1308 if (ret == 0)
1309 free_entity (entity);
1310 return ret;
1311}
1312
1321int
1322gmp_delete_task (gnutls_session_t *session, const char *id)
1323{
1324 entity_t entity;
1325 int ret;
1326
1327 if (gvm_server_sendf (session, "<delete_task task_id=\"%s\"/>", id) == -1)
1328 return -1;
1329
1330 entity = NULL;
1331 ret = gmp_check_response (session, &entity);
1332 if (ret == 0)
1333 free_entity (entity);
1334 return ret;
1335}
1336
1349int
1350gmp_get_targets (gnutls_session_t *session, const char *id, int tasks,
1351 int include_rcfile, entity_t *target)
1352{
1353 (void) include_rcfile;
1354 if (id == NULL)
1355 {
1356 if (gvm_server_sendf (session, "<get_targets tasks=\"%i\"/>", tasks)
1357 == -1)
1358 return -1;
1359 }
1360 else
1361 {
1362 if (gvm_server_sendf (session,
1363 "<get_targets"
1364 " target_id=\"%s\""
1365 " tasks=\"%i\"/>",
1366 id, tasks)
1367 == -1)
1368 return -1;
1369 }
1370
1371 /* Read the response. */
1372 return gmp_check_response (session, target);
1373}
1374
1387int
1388gmp_get_report_ext (gnutls_session_t *session, gmp_get_report_opts_t opts,
1389 entity_t *response)
1390{
1391 int ret;
1392 const char *status_code;
1393
1394 if (response == NULL)
1395 return -1;
1396
1397 if (gvm_server_sendf (
1398 session,
1399 "<get_reports"
1400 " details=\"1\""
1401 " report_id=\"%s\""
1402 " format_id=\"%s\""
1403 " host_first_result=\"%i\""
1404 " host_max_results=\"%i\""
1405 "%s%s%s"
1406 "%s%s%s"
1407 "%s%s%s"
1408 "%s%s%s"
1409 "%s%s%s"
1410 "%s%s%s"
1411 "%s%s%s"
1412 "%s%s%s"
1413 "%s%s%s"
1414 "%s%s%s"
1415 "%s%s%s"
1416 "%s%s%s"
1417 "%s%s%s"
1418 "%s%s%s"
1419 "%s%s%s%s%s%s%s/>",
1420 opts.report_id, opts.format_id, opts.host_first_result,
1421 opts.host_max_results, GMP_FMT_STRING_ATTRIB (opts, type),
1422 GMP_FMT_STRING_ATTRIB (opts, filter),
1423 GMP_FMT_STRING_ATTRIB (opts, filt_id),
1424 GMP_FMT_STRING_ATTRIB (opts, host), GMP_FMT_STRING_ATTRIB (opts, pos),
1425 GMP_FMT_STRING_ATTRIB (opts, timezone),
1426 GMP_FMT_STRING_ATTRIB (opts, alert_id),
1427 GMP_FMT_STRING_ATTRIB (opts, delta_report_id),
1428 GMP_FMT_STRING_ATTRIB (opts, delta_states),
1429 GMP_FMT_STRING_ATTRIB (opts, host_levels),
1430 GMP_FMT_STRING_ATTRIB (opts, search_phrase),
1431 GMP_FMT_STRING_ATTRIB (opts, host_search_phrase),
1432 GMP_FMT_STRING_ATTRIB (opts, min_cvss_base),
1433 GMP_FMT_STRING_ATTRIB (opts, min_qod),
1434 GMP_FMT_BOOL_ATTRIB (opts, notes),
1435 GMP_FMT_BOOL_ATTRIB (opts, notes_details),
1436 GMP_FMT_BOOL_ATTRIB (opts, overrides),
1437 GMP_FMT_BOOL_ATTRIB (opts, override_details),
1438 GMP_FMT_BOOL_ATTRIB (opts, apply_overrides),
1439 GMP_FMT_BOOL_ATTRIB (opts, result_hosts_only),
1440 GMP_FMT_BOOL_ATTRIB (opts, ignore_pagination)))
1441 return -1;
1442
1443 *response = NULL;
1444 switch (try_read_entity (session, opts.timeout, response))
1445 {
1446 case 0:
1447 break;
1448 case -4:
1449 return 2;
1450 default:
1451 return -1;
1452 }
1453
1454 /* Check the response. */
1455
1456 status_code = entity_attribute (*response, "status");
1457 if (status_code == NULL)
1458 {
1459 free_entity (*response);
1460 return -1;
1461 }
1462 if (strlen (status_code) == 0)
1463 {
1464 free_entity (*response);
1465 return -1;
1466 }
1467 if (status_code[0] == '2')
1468 return 0;
1469 ret = (int) strtol (status_code, NULL, 10);
1470 free_entity (*response);
1471 if (errno == ERANGE)
1472 return -1;
1473 return ret;
1474}
1475
1485int
1486gmp_delete_port_list_ext (gnutls_session_t *session, const char *id,
1487 gmp_delete_opts_t opts)
1488{
1489 entity_t entity;
1490 int ret;
1491
1492 if (gvm_server_sendf (
1493 session, "<delete_port_list port_list_id=\"%s\" ultimate=\"%d\"/>", id,
1494 opts.ultimate)
1495 == -1)
1496 return -1;
1497
1498 entity = NULL;
1499 ret = gmp_check_response (session, &entity);
1500 if (ret == 0)
1501 free_entity (entity);
1502 return ret;
1503}
1504
1513int
1514gmp_delete_report (gnutls_session_t *session, const char *id)
1515{
1516 entity_t entity;
1517 int ret;
1518
1519 if (gvm_server_sendf (session, "<delete_report report_id=\"%s\"/>", id))
1520 return -1;
1521
1522 entity = NULL;
1523 ret = gmp_check_response (session, &entity);
1524 if (ret == 0)
1525 free_entity (entity);
1526 return ret;
1527}
1528
1543int
1544gmp_create_target_ext (gnutls_session_t *session, gmp_create_target_opts_t opts,
1545 gchar **id)
1546{
1547 gchar *comment, *ssh, *smb, *esxi, *snmp, *port_range, *start;
1548 gchar *exclude_hosts, *alive_tests;
1549 int ret;
1550
1551 /* Create the GMP request. */
1552
1553 if (opts.hosts == NULL)
1554 return -1;
1555
1556 start =
1557 g_markup_printf_escaped ("<create_target>"
1558 "<name>%s</name>"
1559 "<hosts>%s</hosts>",
1560 opts.name ? opts.name : "unnamed", opts.hosts);
1561
1562 if (opts.exclude_hosts)
1563 exclude_hosts = g_markup_printf_escaped ("<exclude_hosts>"
1564 "%s"
1565 "</exclude_hosts>",
1566 opts.exclude_hosts);
1567 else
1568 exclude_hosts = NULL;
1569
1570 if (opts.alive_tests)
1571 alive_tests = g_markup_printf_escaped ("<alive_tests>"
1572 "%s"
1573 "</alive_tests>",
1574 opts.alive_tests);
1575 else
1576 alive_tests = NULL;
1577
1578 if (opts.comment)
1579 comment = g_markup_printf_escaped ("<comment>"
1580 "%s"
1581 "</comment>",
1582 opts.comment);
1583 else
1584 comment = NULL;
1585
1586 if (opts.ssh_credential_id)
1587 {
1588 if (opts.ssh_credential_port)
1589 ssh = g_markup_printf_escaped ("<ssh_lsc_credential id=\"%s\">"
1590 "<port>%i</port>"
1591 "</ssh_lsc_credential>",
1592 opts.ssh_credential_id,
1593 opts.ssh_credential_port);
1594 else
1595 ssh = g_markup_printf_escaped ("<ssh_lsc_credential id=\"%s\"/>",
1596 opts.ssh_credential_id);
1597 }
1598 else
1599 ssh = NULL;
1600
1601 if (opts.smb_credential_id)
1602 smb = g_markup_printf_escaped ("<smb_lsc_credential id=\"%s\"/>",
1603 opts.smb_credential_id);
1604 else
1605 smb = NULL;
1606
1607 if (opts.esxi_credential_id)
1608 esxi = g_markup_printf_escaped ("<esxi_lsc_credential id=\"%s\"/>",
1609 opts.esxi_credential_id);
1610 else
1611 esxi = NULL;
1612
1613 if (opts.snmp_credential_id)
1614 snmp = g_markup_printf_escaped ("<snmp_credential id=\"%s\"/>",
1615 opts.snmp_credential_id);
1616 else
1617 snmp = NULL;
1618
1619 if (opts.port_range)
1620 port_range =
1621 g_markup_printf_escaped ("<port_range>%s</port_range>", opts.port_range);
1622 else
1623 port_range = NULL;
1624
1625 /* Send the request. */
1626 ret = gvm_server_sendf (session,
1627 "%s%s%s%s%s%s%s%s%s"
1628 "<reverse_lookup_only>%d</reverse_lookup_only>"
1629 "<reverse_lookup_unify>%d</reverse_lookup_unify>"
1630 "</create_target>",
1631 start, exclude_hosts ? exclude_hosts : "",
1632 alive_tests ? alive_tests : "", ssh ? ssh : "",
1633 smb ? smb : "", esxi ? esxi : "", snmp ? snmp : "",
1634 port_range ? port_range : "", comment ? comment : "",
1635 opts.reverse_lookup_only, opts.reverse_lookup_unify);
1636 g_free (start);
1637 g_free (exclude_hosts);
1638 g_free (alive_tests);
1639 g_free (ssh);
1640 g_free (smb);
1641 g_free (esxi);
1642 g_free (port_range);
1643 g_free (comment);
1644 if (ret)
1645 return -2;
1646
1647 /* Read the response. */
1648
1649 ret = gmp_read_create_response (session, id);
1650 if (ret == 201)
1651 return 0;
1652 return ret;
1653}
1654
1664int
1665gmp_delete_target_ext (gnutls_session_t *session, const char *id,
1666 gmp_delete_opts_t opts)
1667{
1668 entity_t entity;
1669 int ret;
1670
1671 if (gvm_server_sendf (session,
1672 "<delete_target target_id=\"%s\" ultimate=\"%d\"/>", id,
1673 opts.ultimate)
1674 == -1)
1675 return -1;
1676
1677 entity = NULL;
1678 ret = gmp_check_response (session, &entity);
1679 if (ret == 0)
1680 free_entity (entity);
1681 return ret;
1682}
1683
1693int
1694gmp_delete_config_ext (gnutls_session_t *session, const char *id,
1695 gmp_delete_opts_t opts)
1696{
1697 entity_t entity;
1698 int ret;
1699
1700 if (gvm_server_sendf (session,
1701 "<delete_config config_id=\"%s\" ultimate=\"%d\"/>", id,
1702 opts.ultimate)
1703 == -1)
1704 return -1;
1705
1706 entity = NULL;
1707 ret = gmp_check_response (session, &entity);
1708 if (ret == 0)
1709 free_entity (entity);
1710 return ret;
1711}
1712
1725int
1726gmp_create_lsc_credential (gnutls_session_t *session, const char *name,
1727 const char *login, const char *password,
1728 const char *comment, gchar **uuid)
1729{
1730 int ret;
1731
1732 if (password)
1733 {
1734 if (comment)
1735 ret = gvm_server_sendf_xml_quiet (session,
1736 "<create_credential>"
1737 "<name>%s</name>"
1738 "<login>%s</login>"
1739 "<password>%s</password>"
1740 "<comment>%s</comment>"
1741 "</create_credential>",
1742 name, login, password, comment);
1743 else
1744 ret = gvm_server_sendf_xml_quiet (session,
1745 "<create_credential>"
1746 "<name>%s</name>"
1747 "<login>%s</login>"
1748 "<password>%s</password>"
1749 "</create_credential>",
1750 name, login, password);
1751 }
1752 else
1753 {
1754 if (comment)
1755 ret = gvm_server_sendf_xml (session,
1756 "<create_credential>"
1757 "<name>%s</name>"
1758 "<login>%s</login>"
1759 "<comment>%s</comment>"
1760 "</create_credential>",
1761 name, login, comment);
1762 else
1763 ret = gvm_server_sendf_xml (session,
1764 "<create_credential>"
1765 "<name>%s</name>"
1766 "<login>%s</login>"
1767 "</create_credential>",
1768 name, login);
1769 }
1770 if (ret)
1771 return -1;
1772
1773 ret = gmp_read_create_response (session, uuid);
1774 if (ret == 201)
1775 return 0;
1776 return ret;
1777}
1778
1793int
1794gmp_create_lsc_credential_key (gnutls_session_t *session, const char *name,
1795 const char *login, const char *passphrase,
1796 const char *private_key, const char *comment,
1797 gchar **uuid)
1798{
1799 int ret;
1800
1801 if (comment)
1802 ret = gvm_server_sendf_xml (session,
1803 "<create_credential>"
1804 "<name>%s</name>"
1805 "<login>%s</login>"
1806 "<key>"
1807 "<phrase>%s</phrase>"
1808 "<private>%s</private>"
1809 "</key>"
1810 "<comment>%s</comment>"
1811 "</create_credential>",
1812 name, login, passphrase ? passphrase : "",
1813 private_key, comment);
1814 else
1815 ret = gvm_server_sendf_xml (session,
1816 "<create_credential>"
1817 "<name>%s</name>"
1818 "<login>%s</login>"
1819 "<key>"
1820 "<phrase>%s</phrase>"
1821 "<private>%s</private>"
1822 "</key>"
1823 "</create_credential>",
1824 name, login, passphrase ? passphrase : "",
1825 private_key);
1826
1827 if (ret)
1828 return -1;
1829
1830 ret = gmp_read_create_response (session, uuid);
1831 if (ret == 201)
1832 return 0;
1833 return ret;
1834}
1835
1846int
1847gmp_create_lsc_credential_ext (gnutls_session_t *session,
1848 gmp_create_lsc_credential_opts_t opts,
1849 gchar **id)
1850{
1851 gchar *comment, *pass, *start, *snmp_elems;
1852 int ret;
1853
1854 /* Create the GMP request. */
1855
1856 if (opts.login == NULL)
1857 return -1;
1858
1859 start =
1860 g_markup_printf_escaped ("<create_credential>"
1861 "<name>%s</name>"
1862 "<login>%s</login>",
1863 opts.name ? opts.name : "unnamed", opts.login);
1864
1865 if (opts.comment)
1866 comment = g_markup_printf_escaped ("<comment>"
1867 "%s"
1868 "</comment>",
1869 opts.comment);
1870 else
1871 comment = NULL;
1872
1873 if (opts.private_key)
1874 pass = g_markup_printf_escaped ("<key>"
1875 "<phrase>%s</phrase>"
1876 "<private>%s</private>"
1877 "</key>",
1878 opts.passphrase ? opts.passphrase : "",
1879 opts.private_key);
1880 else
1881 {
1882 if (opts.passphrase)
1883 pass = g_markup_printf_escaped ("<password>"
1884 "%s"
1885 "</password>",
1886 opts.passphrase);
1887 else
1888 pass = NULL;
1889 }
1890
1891 if (opts.community && opts.auth_algorithm && opts.privacy_password
1892 && opts.privacy_algorithm)
1893 snmp_elems =
1894 g_markup_printf_escaped ("<community>"
1895 "%s"
1896 "</community>"
1897 "<auth_algorithm>"
1898 "%s"
1899 "</auth_algorithm>"
1900 "<privacy>"
1901 "<password>%s</password>"
1902 "<algorithm>%s</algorithm>"
1903 "</privacy>",
1904 opts.community, opts.auth_algorithm,
1905 opts.privacy_password, opts.privacy_algorithm);
1906 else
1907 snmp_elems = NULL;
1908
1909 /* Send the request. */
1910
1911 ret = gvm_server_sendf (session, "%s%s%s%s</create_credential>", start,
1912 comment ? comment : "", pass ? pass : "",
1913 snmp_elems ? snmp_elems : "");
1914
1915 g_free (start);
1916 g_free (comment);
1917 g_free (pass);
1918 if (ret)
1919 return -1;
1920
1921 /* Read the response. */
1922
1923 ret = gmp_read_create_response (session, id);
1924 if (ret == 201)
1925 return 0;
1926 return ret;
1927}
1928
1938int
1939gmp_delete_lsc_credential_ext (gnutls_session_t *session, const char *id,
1940 gmp_delete_opts_t opts)
1941{
1942 entity_t entity;
1943 int ret;
1944
1945 if (gvm_server_sendf (session,
1946 "<delete_credential credential_id=\"%s\""
1947 " ultimate=\"%d\"/>",
1948 id, opts.ultimate)
1949 == -1)
1950 return -1;
1951
1952 entity = NULL;
1953 ret = gmp_check_response (session, &entity);
1954 if (ret == 0)
1955 free_entity (entity);
1956 return ret;
1957}
1958
1970int
1971gmp_get_system_reports (gnutls_session_t *session, const char *name, int brief,
1972 entity_t *reports)
1973{
1974 if (name)
1975 {
1976 if (gvm_server_sendf (session,
1977 "<get_system_reports name=\"%s\" brief=\"%i\"/>",
1978 name, brief)
1979 == -1)
1980 return -1;
1981 }
1982 else if (gvm_server_sendf (session, "<get_system_reports brief=\"%i\"/>",
1983 brief)
1984 == -1)
1985 return -1;
1986
1987 /* Read and check the response. */
1988 return gmp_check_response (session, reports);
1989}
1990
2001int
2002gmp_get_system_reports_ext (gnutls_session_t *session,
2003 gmp_get_system_reports_opts_t opts,
2004 entity_t *reports)
2005{
2006 GString *request;
2007
2008 request = g_string_new ("<get_system_reports");
2009
2010 if (opts.slave_id)
2011 xml_string_append (request, " slave_id=\"%s\"", opts.slave_id);
2012
2013 if (opts.name)
2014 xml_string_append (request, " name=\"%s\"", opts.name);
2015
2016 if (opts.duration)
2017 xml_string_append (request, " duration=\"%s\"", opts.duration);
2018
2019 if (opts.start_time)
2020 xml_string_append (request, " start_time=\"%s\"", opts.start_time);
2021
2022 if (opts.end_time)
2023 xml_string_append (request, " end_time=\"%s\"", opts.end_time);
2024
2025 g_string_append (request, "/>");
2026
2027 /* Create the GMP request. */
2028
2029 if (gvm_server_sendf (session, "%s", request->str) == -1)
2030 {
2031 g_string_free (request, 1);
2032 return -1;
2033 }
2034 g_string_free (request, 1);
2035
2036 /* Read and check the response. */
2037 return gmp_check_response (session, reports);
2038}
gmp_get_system_reports
int gmp_get_system_reports(gnutls_session_t *session, const char *name, int brief, entity_t *reports)
Get system reports.
Definition gmp.c:1971
gmp_start_task_report
int gmp_start_task_report(gnutls_session_t *session, const char *task_id, char **report_id)
Start a task and read the manager response.
Definition gmp.c:754
gmp_ping_c
int gmp_ping_c(gvm_connection_t *connection, int timeout, gchar **version)
"Ping" the manager.
Definition gmp.c:249
GMP_FMT_BOOL_ATTRIB
#define GMP_FMT_BOOL_ATTRIB(var, attrib)
Definition gmp.c:30
gmp_delete_target_ext
int gmp_delete_target_ext(gnutls_session_t *session, const char *id, gmp_delete_opts_t opts)
Delete a target.
Definition gmp.c:1665
gmp_get_tasks_ext
int gmp_get_tasks_ext(gnutls_session_t *session, gmp_get_tasks_opts_t opts, entity_t *response)
Get all tasks (generic version).
Definition gmp.c:1198
gmp_task_status
const char * gmp_task_status(entity_t response)
Get the task status from a GMP GET_TASKS response.
Definition gmp.c:48
gmp_get_task_ext
int gmp_get_task_ext(gnutls_session_t *session, gmp_get_task_opts_t opts, entity_t *response)
Get a task (generic version).
Definition gmp.c:1161
gmp_create_lsc_credential_ext
int gmp_create_lsc_credential_ext(gnutls_session_t *session, gmp_create_lsc_credential_opts_t opts, gchar **id)
Create an LSC credential.
Definition gmp.c:1847
gmp_create_target_ext
int gmp_create_target_ext(gnutls_session_t *session, gmp_create_target_opts_t opts, gchar **id)
Create a target.
Definition gmp.c:1544
gmp_ping
int gmp_ping(gnutls_session_t *session, int timeout)
"Ping" the manager.
Definition gmp.c:190
gmp_create_task_ext
int gmp_create_task_ext(gnutls_session_t *session, gmp_create_task_opts_t opts, gchar **id)
Create a task.
Definition gmp.c:547
gmp_create_lsc_credential
int gmp_create_lsc_credential(gnutls_session_t *session, const char *name, const char *login, const char *password, const char *comment, gchar **uuid)
Create an LSC Credential.
Definition gmp.c:1726
gmp_delete_report
int gmp_delete_report(gnutls_session_t *session, const char *id)
Remove a report.
Definition gmp.c:1514
gmp_authenticate
int gmp_authenticate(gnutls_session_t *session, const char *username, const char *password)
Authenticate with the manager.
Definition gmp.c:321
gmp_stop_task_c
int gmp_stop_task_c(gvm_connection_t *connection, const char *id)
Stop a task and read the manager response.
Definition gmp.c:972
gmp_resume_task_report
int gmp_resume_task_report(gnutls_session_t *session, const char *task_id, char **report_id)
Resume a task and read the manager response.
Definition gmp.c:991
gmp_create_task
int gmp_create_task(gnutls_session_t *session, const char *name, const char *config, const char *target, const char *comment, gchar **id)
Create a task given a config and target.
Definition gmp.c:719
gmp_modify_task_file
int gmp_modify_task_file(gnutls_session_t *session, const char *id, const char *name, const void *content, gsize content_len)
Modify a file on a task.
Definition gmp.c:1265
gmp_start_task_report_c
int gmp_start_task_report_c(gvm_connection_t *connection, const char *task_id, char **report_id)
Start a task and read the manager response.
Definition gmp.c:799
gmp_check_response_c
static int gmp_check_response_c(gvm_connection_t *connection)
Read response and convert status of response to a return value.
Definition gmp.c:174
gmp_delete_task
int gmp_delete_task(gnutls_session_t *session, const char *id)
Delete a task and read the manager response.
Definition gmp.c:1322
gmp_delete_port_list_ext
int gmp_delete_port_list_ext(gnutls_session_t *session, const char *id, gmp_delete_opts_t opts)
Delete a port list.
Definition gmp.c:1486
check_response_c
static int check_response_c(gvm_connection_t *connection, int convert_99)
Read response and convert status of response to a return value.
Definition gmp.c:119
gmp_authenticate_info_ext_c
int gmp_authenticate_info_ext_c(gvm_connection_t *connection, gmp_authenticate_info_opts_t opts)
Authenticate with the manager.
Definition gmp.c:445
gmp_delete_task_ext
int gmp_delete_task_ext(gnutls_session_t *session, const char *id, gmp_delete_opts_t opts)
Delete a task and read the manager response.
Definition gmp.c:1094
gmp_resume_task_report_c
int gmp_resume_task_report_c(gvm_connection_t *connection, const char *task_id, char **report_id)
Resume a task and read the manager response.
Definition gmp.c:1036
gmp_delete_config_ext
int gmp_delete_config_ext(gnutls_session_t *session, const char *id, gmp_delete_opts_t opts)
Delete a config.
Definition gmp.c:1694
gmp_read_create_response
int gmp_read_create_response(gnutls_session_t *session, gchar **uuid)
Read response status and resource UUID.
Definition gmp.c:890
gmp_get_report_ext
int gmp_get_report_ext(gnutls_session_t *session, gmp_get_report_opts_t opts, entity_t *response)
Get a report (generic version).
Definition gmp.c:1388
gmp_delete_lsc_credential_ext
int gmp_delete_lsc_credential_ext(gnutls_session_t *session, const char *id, gmp_delete_opts_t opts)
Delete a LSC credential.
Definition gmp.c:1939
gmp_authenticate_info_ext
int gmp_authenticate_info_ext(gnutls_session_t *session, gmp_authenticate_info_opts_t opts)
Authenticate with the manager.
Definition gmp.c:364
gmp_start_task_ext_c
int gmp_start_task_ext_c(gvm_connection_t *connection, gmp_start_task_opts_t opts)
Start a task and read the manager response.
Definition gmp.c:859
gmp_get_tasks
int gmp_get_tasks(gnutls_session_t *session, const char *id, int details, int include_rcfile, entity_t *status)
Get the status of a task.
Definition gmp.c:1126
GMP_FMT_STRING_ATTRIB
#define GMP_FMT_STRING_ATTRIB(var, attrib)
Definition gmp.c:33
gmp_get_system_reports_ext
int gmp_get_system_reports_ext(gnutls_session_t *session, gmp_get_system_reports_opts_t opts, entity_t *reports)
Get system reports.
Definition gmp.c:2002
gmp_get_targets
int gmp_get_targets(gnutls_session_t *session, const char *id, int tasks, int include_rcfile, entity_t *target)
Get a target.
Definition gmp.c:1350
gmp_create_lsc_credential_key
int gmp_create_lsc_credential_key(gnutls_session_t *session, const char *name, const char *login, const char *passphrase, const char *private_key, const char *comment, gchar **uuid)
Create an LSC Credential with a key.
Definition gmp.c:1794
gmp_stop_task
int gmp_stop_task(gnutls_session_t *session, const char *id)
Stop a task and read the manager response.
Definition gmp.c:948
gmp_check_response
static int gmp_check_response(gnutls_session_t *session, entity_t *entity)
Read response and convert status of response to a return value.
Definition gmp.c:70
gmp.h
API for Greenbone Management Protocol communication.
gvm_connection_sendf
int gvm_connection_sendf(gvm_connection_t *connection, const char *format,...)
Format and send a string to the server.
Definition serverutils.c:823
gvm_server_sendf_xml_quiet
int gvm_server_sendf_xml_quiet(gnutls_session_t *session, const char *format,...)
Format and send an XML string to the server.
Definition serverutils.c:938
gvm_server_sendf_xml
int gvm_server_sendf_xml(gnutls_session_t *session, const char *format,...)
Format and send an XML string to the server.
Definition serverutils.c:886
gvm_server_sendf
int gvm_server_sendf(gnutls_session_t *session, const char *format,...)
Format and send a string to the server.
Definition serverutils.c:803
gvm_connection_sendf_xml_quiet
int gvm_connection_sendf_xml_quiet(gvm_connection_t *connection, const char *format,...)
Format and send an XML string to the server.
Definition serverutils.c:965
serverutils.h
GnuTLS based functions for server communication - header file.
strings.h
String utilities.
gmp_authenticate_info_opts_t
Struct holding options for authentication.
Definition gmp.h:27
gmp_authenticate_info_opts_t::password
const char * password
Username.
Definition gmp.h:30
gmp_authenticate_info_opts_t::timeout
int timeout
Timeout for authentication.
Definition gmp.h:28
gmp_authenticate_info_opts_t::jwt_requested
int jwt_requested
Flag for JWT. 0 = false, 1 = true.
Definition gmp.h:34
gmp_authenticate_info_opts_t::pw_warning
char ** pw_warning
[out] Password warning, NULL if password is okay.
Definition gmp.h:33
gmp_authenticate_info_opts_t::timezone
char ** timezone
[out] Timezone if any, else NULL.
Definition gmp.h:32
gmp_authenticate_info_opts_t::jwt
char ** jwt
[out] JWT token value, NULL if not requested.
Definition gmp.h:35
gmp_authenticate_info_opts_t::username
const char * username
Password.
Definition gmp.h:29
gmp_authenticate_info_opts_t::role
char ** role
[out] Role.
Definition gmp.h:31
gmp_create_lsc_credential_opts_t
Struct holding options for gmp create_lsc_credential command.
Definition gmp.h:242
gmp_create_lsc_credential_opts_t::privacy_password
const char * privacy_password
SNMP privacy password.
Definition gmp.h:249
gmp_create_lsc_credential_opts_t::privacy_algorithm
const char * privacy_algorithm
SNMP privacy algorithm.
Definition gmp.h:250
gmp_create_lsc_credential_opts_t::login
const char * login
Login.
Definition gmp.h:245
gmp_create_lsc_credential_opts_t::community
const char * community
SNMP community.
Definition gmp.h:244
gmp_create_lsc_credential_opts_t::passphrase
const char * passphrase
Passphrase.
Definition gmp.h:246
gmp_create_lsc_credential_opts_t::comment
const char * comment
Comment on LSC credential.
Definition gmp.h:251
gmp_create_lsc_credential_opts_t::private_key
const char * private_key
Private key.
Definition gmp.h:247
gmp_create_lsc_credential_opts_t::auth_algorithm
const char * auth_algorithm
SNMP authentication algorithm.
Definition gmp.h:248
gmp_create_lsc_credential_opts_t::name
const char * name
Name of LSC credential.
Definition gmp.h:243
gmp_create_target_opts_t
Struct holding options for gmp create_target command.
Definition gmp.h:196
gmp_create_target_opts_t::exclude_hosts
const char * exclude_hosts
Hosts to exclude.
Definition gmp.h:206
gmp_create_target_opts_t::comment
const char * comment
Comment on target.
Definition gmp.h:204
gmp_create_target_opts_t::smb_credential_id
const char * smb_credential_id
ID of SMB credential.
Definition gmp.h:199
gmp_create_target_opts_t::reverse_lookup_only
int reverse_lookup_only
Scanner pref reverse_lookup_only.
Definition gmp.h:209
gmp_create_target_opts_t::reverse_lookup_unify
int reverse_lookup_unify
Scanner pref reverse_lookup_unify.
Definition gmp.h:210
gmp_create_target_opts_t::esxi_credential_id
const char * esxi_credential_id
ID of ESXi credential.
Definition gmp.h:200
gmp_create_target_opts_t::snmp_credential_id
const char * snmp_credential_id
ID of SNMP credential.
Definition gmp.h:201
gmp_create_target_opts_t::hosts
const char * hosts
Name of target.
Definition gmp.h:205
gmp_create_target_opts_t::port_range
const char * port_range
Port range.
Definition gmp.h:202
gmp_create_target_opts_t::ssh_credential_port
int ssh_credential_port
Port for SSH access.
Definition gmp.h:197
gmp_create_target_opts_t::alive_tests
const char * alive_tests
Alive tests.
Definition gmp.h:207
gmp_create_target_opts_t::ssh_credential_id
const char * ssh_credential_id
ID of SSH credential.
Definition gmp.h:198
gmp_create_target_opts_t::name
const char * name
Name of target.
Definition gmp.h:203
gmp_create_task_opts_t
Struct holding options for gmp create_task command.
Definition gmp.h:163
gmp_create_task_opts_t::schedule_periods
int schedule_periods
Number of periods the schedule must run for.
Definition gmp.h:175
gmp_create_task_opts_t::max_checks
const char * max_checks
Max checks preference.
Definition gmp.h:179
gmp_create_task_opts_t::slave_id
const char * slave_id
ID of task schedule.
Definition gmp.h:168
gmp_create_task_opts_t::alert_ids
array_t * alert_ids
Array of alert IDs.
Definition gmp.h:164
gmp_create_task_opts_t::config_id
const char * config_id
ID of config.
Definition gmp.h:165
gmp_create_task_opts_t::in_assets
const char * in_assets
In assets preference.
Definition gmp.h:177
gmp_create_task_opts_t::schedule_id
const char * schedule_id
ID of task schedule.
Definition gmp.h:167
gmp_create_task_opts_t::source_iface
const char * source_iface
Source iface preference.
Definition gmp.h:180
gmp_create_task_opts_t::observer_groups
array_t * observer_groups
IDs of observer groups.
Definition gmp.h:174
gmp_create_task_opts_t::observers
const char * observers
Comma-separated string of observer users.
Definition gmp.h:173
gmp_create_task_opts_t::name
const char * name
Name of task.
Definition gmp.h:170
gmp_create_task_opts_t::target_id
const char * target_id
ID of target.
Definition gmp.h:169
gmp_create_task_opts_t::scanner_id
const char * scanner_id
ID of task scanner.
Definition gmp.h:166
gmp_create_task_opts_t::alterable
int alterable
Whether the task is alterable.
Definition gmp.h:182
gmp_create_task_opts_t::max_hosts
const char * max_hosts
Max hosts preference.
Definition gmp.h:178
gmp_create_task_opts_t::comment
const char * comment
Comment on task.
Definition gmp.h:171
gmp_delete_opts_t
Struct holding options for various gmp delete_[...] commands.
Definition gmp.h:265
gmp_delete_opts_t::ultimate
int ultimate
Definition gmp.h:266
gmp_get_report_opts_t
Struct holding options for gmp get_report command.
Definition gmp.h:48
gmp_get_report_opts_t::timeout
int timeout
Timeout for GMP response.
Definition gmp.h:56
gmp_get_report_opts_t::format_id
const char * format_id
ID of required report format.
Definition gmp.h:51
gmp_get_report_opts_t::host_max_results
int host_max_results
Maximum number of results to return.
Definition gmp.h:58
gmp_get_report_opts_t::report_id
const char * report_id
ID of single report to get.
Definition gmp.h:53
gmp_get_report_opts_t::host_first_result
int host_first_result
Skip over results before this result number.
Definition gmp.h:57
gmp_get_system_reports_opts_t
Struct holding options for gmp get_system_reports command.
Definition gmp.h:223
gmp_get_system_reports_opts_t::duration
const char * duration
Duration.
Definition gmp.h:225
gmp_get_system_reports_opts_t::slave_id
const char * slave_id
ID of the slave to get report from.
Definition gmp.h:228
gmp_get_system_reports_opts_t::end_time
const char * end_time
Time of last data point.
Definition gmp.h:227
gmp_get_system_reports_opts_t::name
const char * name
Name of report.
Definition gmp.h:224
gmp_get_system_reports_opts_t::start_time
const char * start_time
Time of first data point.
Definition gmp.h:226
gmp_get_task_opts_t
Struct holding options for gmp get_tasks command.
Definition gmp.h:145
gmp_get_task_opts_t::task_id
const char * task_id
ID of single task to get.
Definition gmp.h:147
gmp_get_task_opts_t::actions
const char * actions
Actions argument.
Definition gmp.h:146
gmp_get_tasks_opts_t
Struct holding options for gmp get_tasks command.
Definition gmp.h:126
gmp_get_tasks_opts_t::timeout
int timeout
Timeout for GMP response.
Definition gmp.h:128
gmp_get_tasks_opts_t::filter
const char * filter
Filter argument.
Definition gmp.h:127
gmp_start_task_opts_t
Struct holding options for gmp start_task command.
Definition gmp.h:318
gmp_start_task_opts_t::task_id
const char * task_id
ID of task.
Definition gmp.h:319
gvm_connection_t
Connection.
Definition serverutils.h:30
read_entity_c
int read_entity_c(gvm_connection_t *connection, entity_t *entity)
Read an XML entity tree from the manager.
Definition xmlutils.c:1497
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
try_read_entity
int try_read_entity(gnutls_session_t *session, int timeout, entity_t *entity)
Try read an XML entity tree from the manager.
Definition xmlutils.c:1436
free_entity
void free_entity(entity_t entity)
Free an entity, recursively.
Definition xmlutils.c:115
entity_child
entity_t entity_child(entity_t entity, const char *name)
Get a child of an entity.
Definition xmlutils.c:193
try_read_entity_c
int try_read_entity_c(gvm_connection_t *connection, int timeout, entity_t *entity)
Try read an XML entity tree from the manager.
Definition xmlutils.c:1452
xml_string_append
void xml_string_append(GString *xml, const char *format,...)
Append formatted escaped XML to a string.
Definition xmlutils.c:1849
entity_t
struct entity_s * entity_t
Definition xmlutils.h:58