OpenVAS Scanner 22.7.9
nasl_scanner_glue.c
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Greenbone AG
2 * SPDX-FileCopyrightText: 2002-2004 Tenable Network Security
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
16#include "nasl_scanner_glue.h"
17
18#include "../misc/network.h" /* for getpts */
19#include "../misc/plugutils.h" /* for plug_set_id */
20#include "../misc/support.h" /* for the g_memdup2 workaround */
21#include "../misc/vendorversion.h" /* for vendor_version_get */
22#include "nasl_debug.h"
23#include "nasl_func.h"
24#include "nasl_global_ctxt.h"
25#include "nasl_lex_ctxt.h"
26#include "nasl_tree.h"
27#include "nasl_var.h"
28
29#include <ctype.h> /* for isdigit */
30#include <errno.h> /* for errno */
31#include <fcntl.h> /* for open */
32#include <glib.h>
33#include <gvm/base/logging.h>
34#include <gvm/base/prefs.h> /* for prefs_get */
35#include <gvm/util/kb.h> /* for KB_TYPE_INT */
36#include <stdlib.h> /* for atoi */
37#include <string.h> /* for strcmp */
38#include <sys/stat.h> /* for stat */
39#include <unistd.h> /* for close */
40
41#undef G_LOG_DOMAIN
45#define G_LOG_DOMAIN "lib nasl"
46
47/*------------------- Private utilities ---------------------------------*/
48
49static int
50isalldigit (char *str, int len)
51{
52 int i;
53 char buf[1024];
54 for (i = 0; i < len; i++)
55 {
56 if (!isdigit (str[i]))
57 return 0;
58 }
59
60 snprintf (buf, sizeof (buf), "%d", atoi (str));
61 if (strcmp (buf, str) != 0)
62 return 0;
63 else
64 return 1;
65}
66
67/*-------------------[ script_*() functions ]----------------------------*/
68
69/*
70 * These functions are used when the script registers itself to openvas
71 * scanner.
72 */
73
88{
89 nvti_t *nvti = lexic->script_infos->nvti;
90 int to = get_int_var_by_num (lexic, 0, -65535);
91 nvtpref_t *np;
92 gchar *timeout;
93
94 if (to == -65535)
95 return FAKE_CELL;
96
97 timeout = g_strdup_printf ("%d", to);
98
99 np = nvtpref_new (NVTPREF_TIMEOUT_ID, "timeout", "entry", timeout);
100 nvti_add_pref (nvti, np);
101 return FAKE_CELL;
102}
103
104tree_cell *
106{
107 nvti_set_oid (lexic->script_infos->nvti, get_str_var_by_num (lexic, 0));
108 return FAKE_CELL;
109}
110
111tree_cell *
113{
114 struct script_infos *script_infos = lexic->script_infos;
115 char *cve = get_str_var_by_num (lexic, 0);
116 int i;
117
118 for (i = 0; cve != NULL; i++)
119 {
120 nvti_add_vtref (script_infos->nvti, vtref_new ("cve", cve, ""));
121 cve = get_str_var_by_num (lexic, i + 1);
122 }
123
124 return FAKE_CELL;
125}
126
149tree_cell *
151{
152 struct script_infos *script_infos = lexic->script_infos;
153 char *name = get_str_var_by_name (lexic, "name");
154 char *value = get_str_var_by_name (lexic, "value");
155 char *csv = get_str_var_by_name (lexic, "csv");
156
157 if (((value == NULL) && (csv == NULL)) || name == NULL)
158 {
159 nasl_perror (lexic,
160 "script_xref() syntax error - should be"
161 " script_xref(name:<name>, value:<value>) or"
162 " script_xref(name:<name>, value:<value>, csv:<CSVs>) or"
163 " script_xref(name:<name>, csv:<CSVs>)\n");
164 if (name == NULL)
165 {
166 nasl_perror (lexic, " <name> is empty\n");
167 }
168 else
169 {
170 nasl_perror (lexic, " <name> is %s\n", name);
171 }
172 if ((value == NULL) && (csv == NULL))
173 {
174 nasl_perror (lexic, " <value> and <csv> is empty)\n");
175 }
176 else
177 {
178 nasl_perror (lexic, " <value> is %s\n)", value);
179 nasl_perror (lexic, " <csv> is %s\n)", csv);
180 }
181 return FAKE_CELL;
182 }
183
184 if (csv)
185 nvti_add_refs (script_infos->nvti, name, csv, "");
186
187 if (value)
188 nvti_add_vtref (script_infos->nvti, vtref_new (name, value, ""));
189
190 return FAKE_CELL;
191}
192
193tree_cell *
195{
196 struct script_infos *script_infos = lexic->script_infos;
197 char *name = get_str_var_by_name (lexic, "name");
198 char *value = get_str_var_by_name (lexic, "value");
199
200 if (value == NULL || name == NULL)
201 {
202 nasl_perror (lexic, "script_tag() syntax error - should be"
203 " script_tag(name:<name>, value:<value>)\n");
204 if (name == NULL)
205 {
206 nasl_perror (lexic, " <name> is empty\n");
207 }
208 else
209 {
210 nasl_perror (lexic, " <name> is %s\n", name);
211 }
212 if (value == NULL)
213 {
214 nasl_perror (lexic, " <value> is empty)\n");
215 }
216 else
217 {
218 nasl_perror (lexic, " <value> is %s\n)", value);
219 }
220 return FAKE_CELL;
221 }
222
223 if (strchr (value, '|'))
224 {
225 nasl_perror (lexic, "%s tag contains | separator", name);
226 return FAKE_CELL;
227 }
228 nvti_add_tag (script_infos->nvti, name, value);
229
230 return FAKE_CELL;
231}
232
233tree_cell *
235{
236 nvti_set_name (lexic->script_infos->nvti, get_str_var_by_num (lexic, 0));
237 return FAKE_CELL;
238}
239
240tree_cell *
242{
243 (void) lexic;
244 return FAKE_CELL;
245}
246
247tree_cell *
249{
250 (void) lexic;
251 return FAKE_CELL;
252}
253
254tree_cell *
256{
257 struct script_infos *script_infos = lexic->script_infos;
258
259 int category = get_int_var_by_num (lexic, 0, -1);
260
261 if (category < 0)
262 {
263 nasl_perror (lexic, "Argument error in function script_category()\n");
264 nasl_perror (lexic, "Function usage is : script_category(<category>)\n");
265 return FAKE_CELL;
266 }
267 nvti_set_category (script_infos->nvti, category);
268 return FAKE_CELL;
269}
270
271tree_cell *
273{
274 nvti_set_family (lexic->script_infos->nvti, get_str_var_by_num (lexic, 0));
275 return FAKE_CELL;
276}
277
278tree_cell *
280{
281 struct script_infos *script_infos = lexic->script_infos;
282 char *dep = get_str_var_by_num (lexic, 0);
283 int i;
284
285 if (dep == NULL)
286 {
287 nasl_perror (lexic, "Argument error in function script_dependencies()\n");
288 nasl_perror (lexic, "Function usage is : script_dependencies(<name>)\n");
289 nasl_perror (lexic, "Where <name> is the name of another script\n");
290
291 return FAKE_CELL;
292 }
293
294 for (i = 0; dep != NULL; i++)
295 {
296 dep = get_str_var_by_num (lexic, i);
297 if (dep != NULL)
299 }
300
301 return FAKE_CELL;
302}
303
304tree_cell *
306{
307 char *keys = get_str_var_by_num (lexic, 0);
308 int i;
309
310 if (keys == NULL)
311 {
312 nasl_perror (lexic, "Argument error in function script_require_keys()\n");
313 nasl_perror (lexic,
314 "Function usage is : script_require_keys(<name>...)\n");
315 nasl_perror (lexic, "Where <name> is the name of a key\n");
316 return FAKE_CELL;
317 }
318
319 for (i = 0; keys != NULL; i++)
320 {
321 keys = get_str_var_by_num (lexic, i);
322 nvti_add_required_keys (lexic->script_infos->nvti, keys);
323 }
324
325 return FAKE_CELL;
326}
327
328tree_cell *
330{
331 char *keys = get_str_var_by_num (lexic, 0);
332 char **splits = NULL, *re = get_str_var_by_name (lexic, "re");
333 int i;
334
335 if (keys == NULL)
336 {
337 nasl_perror (lexic,
338 "Argument error in function script_mandatory_keys()\n");
339 nasl_perror (lexic, "Function usage is: script_mandatory_keys(<name>... "
340 "[, re: '<name>=<regex>'])\n");
341 nasl_perror (lexic, "Where <name> is the name of a key and <regex> is a "
342 "regular expression for a value of a key.\n");
343 return FAKE_CELL;
344 }
345
346 if (re)
347 {
348 splits = g_strsplit (re, "=", 0);
349
350 if (!splits[0] || !splits[1] || !*splits[1] || splits[2])
351 {
352 nasl_perror (lexic, "Erroneous re argument");
353 return FAKE_CELL;
354 }
355 }
356 for (i = 0; keys != NULL; i++)
357 {
358 keys = get_str_var_by_num (lexic, i);
359
360 if (splits && keys && !strcmp (keys, splits[0]))
361 {
362 nvti_add_mandatory_keys (lexic->script_infos->nvti, re);
363 re = NULL;
364 }
365 else
366 nvti_add_mandatory_keys (lexic->script_infos->nvti, keys);
367 }
368 if (re)
369 nvti_add_mandatory_keys (lexic->script_infos->nvti, re);
370
371 g_strfreev (splits);
372 return FAKE_CELL;
373}
374
375tree_cell *
377{
378 char *keys = get_str_var_by_num (lexic, 0);
379 int i;
380
381 if (keys == NULL)
382 {
383 nasl_perror (lexic, "Argument error in function script_exclude_keys()\n");
384 nasl_perror (lexic, "Function usage is : script_exclude_keys(<name>)\n");
385 nasl_perror (lexic, "Where <name> is the name of a key\n");
386 return FAKE_CELL;
387 }
388
389 for (i = 0; keys != NULL; i++)
390 {
391 keys = get_str_var_by_num (lexic, i);
392 nvti_add_excluded_keys (lexic->script_infos->nvti, keys);
393 }
394
395 return FAKE_CELL;
396}
397
398tree_cell *
400{
401 char *port;
402 int i;
403
404 for (i = 0;; i++)
405 {
406 port = get_str_var_by_num (lexic, i);
407 if (port != NULL)
408 nvti_add_required_ports (lexic->script_infos->nvti, port);
409 else
410 break;
411 }
412
413 return FAKE_CELL;
414}
415
416tree_cell *
418{
419 int i;
420 char *port;
421
422 for (i = 0;; i++)
423 {
424 port = get_str_var_by_num (lexic, i);
425 if (port != NULL)
426 nvti_add_required_udp_ports (lexic->script_infos->nvti, port);
427 else
428 break;
429 }
430
431 return FAKE_CELL;
432}
433
434tree_cell *
436{
437 int id = get_int_var_by_name (lexic, "id", -1);
438 char *name = get_str_var_by_name (lexic, "name");
439 char *type = get_str_var_by_name (lexic, "type");
440 char *value = get_str_var_by_name (lexic, "value");
441 struct script_infos *script_infos = lexic->script_infos;
442 nvtpref_t *np;
443 unsigned int i;
444
445 if (!script_infos->nvti)
446 return FAKE_CELL;
447 if (id < 0)
448 id = nvti_pref_len (script_infos->nvti) + 1;
449 if (id == 0)
450 {
451 nasl_perror (lexic,
452 "Invalid id or not allowed id value in the call to %s()\n",
453 __func__);
454 return FAKE_CELL;
455 }
456 if (!name || !type || !value)
457 {
458 nasl_perror (lexic,
459 "Argument error in the call to script_add_preference()\n");
460 return FAKE_CELL;
461 }
462 for (i = 0; i < nvti_pref_len (script_infos->nvti); i++)
463 {
464 if (!strcmp (name, nvtpref_name (nvti_pref (script_infos->nvti, i))))
465 {
466 nasl_perror (lexic, "Preference '%s' already exists\n", name);
467 return FAKE_CELL;
468 }
469 if (id == nvtpref_id (nvti_pref (script_infos->nvti, i)))
470 {
471 nasl_perror (lexic, "Invalid or already existent preference id\n");
472 return FAKE_CELL;
473 }
474 }
475
476 np = nvtpref_new (id, name, type, value);
477 nvti_add_pref (script_infos->nvti, np);
478 return FAKE_CELL;
479}
480
491tree_cell *
493{
494 tree_cell *retc;
495 int id = get_int_var_by_name (lexic, "id", -1);
496 char *pref = get_str_var_by_num (lexic, 0);
497 char *value;
498
499 if (pref == NULL && id == -1)
500 {
501 nasl_perror (lexic,
502 "Argument error in the function script_get_preference()\n");
503 nasl_perror (lexic,
504 "Function usage is : pref = script_get_preference(<name>, "
505 "id:<id>)\n");
506 return FAKE_CELL;
507 }
508
509 value = get_plugin_preference (lexic->oid, pref, id);
510 if (value != NULL)
511 {
513 if (isalldigit (value, strlen (value)))
514 retc->x.i_val = atoi (value);
515 else
516 {
517 retc->type = CONST_DATA;
518 retc->size = strlen (value);
519 retc->x.str_val = g_strdup (value);
520 }
521 g_free (value);
522 return retc;
523 }
524 else
525 return FAKE_CELL;
526}
527
528tree_cell *
530{
531 struct script_infos *script_infos = lexic->script_infos;
532 tree_cell *retc;
533 char *pref = get_str_var_by_num (lexic, 0);
534 char *value;
535 char *content;
536 int contentsize = 0;
537
538 if (pref == NULL)
539 {
540 nasl_perror (lexic,
541 "Argument error in the function script_get_preference()\n");
542 nasl_perror (lexic, "Function usage is : pref = "
543 "script_get_preference_file_content(<name>)\n");
544 return NULL;
545 }
546
547 value = get_plugin_preference (lexic->oid, pref, -1);
548 if (value == NULL)
549 return NULL;
550
552 contentsize = get_plugin_preference_file_size (script_infos, value);
553 g_free (value);
554 if (content == NULL)
555 return FAKE_CELL;
556 if (contentsize <= 0)
557 {
558 nasl_perror (lexic,
559 "script_get_preference_file_content: could not get "
560 " size of file from preference %s\n",
561 pref);
562 return NULL;
563 }
564
566 retc->size = contentsize;
567 retc->x.str_val = content;
568
569 return retc;
570}
571
572tree_cell *
574{
575 struct script_infos *script_infos = lexic->script_infos;
576 tree_cell *retc;
577 char *pref = get_str_var_by_num (lexic, 0);
578 const char *value, *local;
579 int len;
580
581 if (pref == NULL)
582 {
584 lexic, "script_get_preference_file_location: no preference name!\n");
585 return NULL;
586 }
587
588 value = get_plugin_preference (lexic->oid, pref, -1);
589 if (value == NULL)
590 {
592 lexic,
593 "script_get_preference_file_location: could not get preference %s\n",
594 pref);
595 return NULL;
596 }
598 if (local == NULL)
599 return NULL;
600
601 len = strlen (local);
603 retc->size = len;
604 retc->x.str_val = g_malloc0 (len + 1);
605 memcpy (retc->x.str_val, local, len + 1);
606
607 return retc;
608}
609
610/* Are safe checks enabled ? */
611tree_cell *
613{
614 (void) lexic;
616
617 retc->x.i_val = prefs_get_bool ("safe_checks");
618
619 return retc;
620}
621
629tree_cell *
631{
632 const char *oid = lexic->oid;
633 tree_cell *retc = NULL;
634
635 if (oid)
636 {
638 retc->x.str_val = g_strdup (oid);
639 retc->size = strlen (oid);
640 }
641
642 return retc;
643}
644
645/*--------------------[ KB ]---------------------------------------*/
646
647tree_cell *
649{
650 struct script_infos *script_infos = lexic->script_infos;
651 kb_t kb = plug_get_kb (script_infos);
652 char *kb_mask = get_str_var_by_num (lexic, 0);
653 tree_cell *retc;
654 int num_elems = 0;
655 nasl_array *a;
656 struct kb_item *res, *top;
657
658 if (kb_mask == NULL)
659 {
660 nasl_perror (lexic, "get_kb_list() usage : get_kb_list(<NameOfItem>)\n");
661 return NULL;
662 }
663
664 if (kb == NULL)
665 return NULL;
666
668 retc->x.ref_val = a = g_malloc0 (sizeof (nasl_array));
669
670 if (strchr (kb_mask, '*'))
671 top = res = kb_item_get_pattern (kb, kb_mask);
672 else
673 top = res = kb_item_get_all (kb, kb_mask);
674
675 while (res != NULL)
676 {
678 bzero (&v, sizeof (v));
679
680 if (res->type == KB_TYPE_INT)
681 {
682 v.var_type = VAR2_INT;
683 v.v.v_int = res->v_int;
684 add_var_to_array (a, res->name, &v);
685 num_elems++;
686 }
687 else if (res->type == KB_TYPE_STR)
688 {
690 v.v.v_str.s_val = (unsigned char *) res->v_str;
691 v.v.v_str.s_siz = strlen (res->v_str);
692 add_var_to_array (a, res->name, &v);
693 num_elems++;
694 }
695 res = res->next;
696 }
697
698 kb_item_free (top);
699
700 if (num_elems == 0)
701 {
702 deref_cell (retc);
703 return FAKE_CELL;
704 }
705 return retc;
706}
707
708tree_cell *
710{
711 struct script_infos *script_infos = lexic->script_infos;
712
713 char *kb_entry = get_str_var_by_num (lexic, 0);
714 char *val;
715 tree_cell *retc;
716 int type, single = get_int_var_by_num (lexic, 1, 0);
717 size_t len;
718
719 if (kb_entry == NULL)
720 return NULL;
721
722 val = plug_get_key (script_infos, kb_entry, &type, &len, !!single);
723
724 if (val == NULL && type == -1)
725 return NULL;
726
728 if (type == KB_TYPE_INT)
729 {
730 retc->x.i_val = GPOINTER_TO_SIZE (val);
731 g_free (val);
732 return retc;
733 }
734 else
735 {
736 retc->type = CONST_DATA;
737 if (val != NULL)
738 {
739 retc->size = len;
740 retc->x.str_val = val;
741 }
742 else
743 {
744 retc->size = 0;
745 retc->x.str_val = NULL;
746 }
747 }
748
749 return retc;
750}
751
760tree_cell *
762{
763 struct script_infos *script_infos = lexic->script_infos;
764 int val;
765 tree_cell *retc;
766
767 val = kb_get_kb_index (script_infos->key);
768 if (val >= 0)
769 {
771 retc->x.i_val = val;
772 }
773 else
774 return NULL;
775
776 return retc;
777}
778
779tree_cell *
781{
782 struct script_infos *script_infos = lexic->script_infos;
783 char *name = get_str_var_by_name (lexic, "name");
784 int type = get_var_type_by_name (lexic, "value");
785
786 if (name == NULL)
787 {
788 nasl_perror (lexic, "Syntax error with replace_kb_item() [null name]\n",
789 name);
790 return FAKE_CELL;
791 }
792
793 if (type == VAR2_INT)
794 {
795 int value = get_int_var_by_name (lexic, "value", -1);
796 if (value != -1)
798 GSIZE_TO_POINTER (value));
799 else
801 lexic, "Syntax error with replace_kb_item(%s) [value=-1]\n", name);
802 }
803 else
804 {
805 char *value = get_str_var_by_name (lexic, "value");
806 int len = get_var_size_by_name (lexic, "value");
807
808 if (value == NULL)
809 {
810 nasl_perror (lexic,
811 "Syntax error with replace_kb_item(%s) [null value]\n",
812 name);
813 return FAKE_CELL;
814 }
816 }
817
818 return FAKE_CELL;
819}
820
831static tree_cell *
833{
834 struct script_infos *script_infos = lexic->script_infos;
835 char *name = get_str_var_by_name (lexic, "name");
836 int type = get_var_type_by_name (lexic, "value");
837 int expire = get_int_var_by_name (lexic, "expire", -1);
838
839 if (name == NULL)
840 {
841 nasl_perror (lexic, "Syntax error with set_kb_item() [null name]\n",
842 name);
843 return FAKE_CELL;
844 }
845
846 if (type == VAR2_INT)
847 {
848 int value = get_int_var_by_name (lexic, "value", -1);
849 if (value != -1 && expire != -1)
851 GSIZE_TO_POINTER (value), expire);
852 else
853 nasl_perror (lexic,
854 "Syntax error with set_kb_item() [value=-1 or expire=-1 "
855 "for name '%s']\n",
856 name);
857 }
858 else
859 {
860 char *value = get_str_var_by_name (lexic, "value");
861 int len = get_var_size_by_name (lexic, "value");
862 if (value == NULL || expire == -1)
863 {
864 nasl_perror (lexic,
865 "Syntax error with set_kb_item() [null value or "
866 "expire=-1 for name '%s']\n",
867 name);
868 return FAKE_CELL;
869 }
871 len);
872 }
873
874 return FAKE_CELL;
875}
876
889tree_cell *
891{
892 struct script_infos *script_infos = lexic->script_infos;
893 char *name = get_str_var_by_name (lexic, "name");
894 int type = get_var_type_by_name (lexic, "value");
895 int expire = get_int_var_by_name (lexic, "expire", -1);
896
897 if (expire != -1)
898 return set_kb_item_volatile (lexic);
899
900 if (name == NULL)
901 {
902 nasl_perror (lexic, "Syntax error with set_kb_item() [null name]\n",
903 name);
904 return FAKE_CELL;
905 }
906
907 if (type == VAR2_INT)
908 {
909 int value = get_int_var_by_name (lexic, "value", -1);
910 if (value != -1)
911 plug_set_key (script_infos, name, ARG_INT, GSIZE_TO_POINTER (value));
912 else
914 lexic, "Syntax error with set_kb_item() [value=-1 for name '%s']\n",
915 name);
916 }
917 else
918 {
919 char *value = get_str_var_by_name (lexic, "value");
920 int len = get_var_size_by_name (lexic, "value");
921 if (value == NULL)
922 {
924 lexic,
925 "Syntax error with set_kb_item() [null value for name '%s']\n",
926 name);
927 return FAKE_CELL;
928 }
930 }
931
932 return FAKE_CELL;
933}
934
935/*------------------------[ Reporting a problem ]---------------------------*/
936
940typedef void (*proto_post_something_t) (const char *, struct script_infos *,
941 int, const char *, const char *,
942 const char *);
946typedef void (*post_something_t) (const char *, struct script_infos *, int,
947 const char *, const char *);
948
949static tree_cell *
951 post_something_t post_func)
952{
953 struct script_infos *script_infos = lexic->script_infos;
954
955 char *proto = get_str_var_by_name (lexic, "protocol");
956 char *data = get_str_var_by_name (lexic, "data");
957 char *uri = get_str_var_by_name (lexic, "uri");
958 int port = get_int_var_by_name (lexic, "port", -1);
959 char *dup = NULL;
960
961 if (data != NULL)
962 {
963 int len = get_var_size_by_name (lexic, "data");
964 int i;
965
966 dup = g_malloc0 ((len + 1) * sizeof (char *));
967 memcpy (dup, data, len + 1);
968
969 for (i = 0; i < len; i++)
970 if (dup[i] == '\0')
971 dup[i] = ' ';
972 }
973
975 {
976 if (data != NULL)
977 fprintf (stdout, "%s\n", dup);
978 else
979 fprintf (stdout, "Success\n");
980 }
981
982 if (proto == NULL)
983 proto = get_str_var_by_name (lexic, "proto");
984
985 if (port < 0)
986 port = get_int_var_by_num (lexic, 0, -1);
987
988 if (dup != NULL)
989 {
990 if (proto == NULL)
991 post_func (lexic->oid, script_infos, port, dup, uri);
992 else
993 proto_post_func (lexic->oid, script_infos, port, proto, dup, uri);
994
995 g_free (dup);
996 return FAKE_CELL;
997 }
998
999 if (proto == NULL)
1000 post_func (lexic->oid, script_infos, port, NULL, uri);
1001 else
1002 proto_post_func (lexic->oid, script_infos, port, proto, NULL, uri);
1003
1004 return FAKE_CELL;
1005}
1006
1014tree_cell *
1016{
1018}
1019
1020tree_cell *
1022{
1024}
1025
1026tree_cell *
1028{
1030}
1031
1032tree_cell *
1034{
1035 tree_cell *retc;
1036 char *name;
1037 const char *value;
1038
1039 name = get_str_var_by_num (lexic, 0);
1040 if (name == NULL)
1041 {
1042 nasl_perror (lexic, "get_preference: no name\n");
1043 return NULL;
1044 }
1045 value = prefs_get (name);
1046 if (value == NULL)
1047 return NULL;
1048
1050 retc->x.str_val = strdup (value);
1051 retc->size = strlen (value);
1052 return retc;
1053}
1054
1055tree_cell *
1057{
1058 tree_cell *retc;
1059 gchar *version = g_strdup (vendor_version_get ());
1060 (void) lexic;
1062 retc->x.str_val = strdup (version);
1063 retc->size = strlen (version);
1064 g_free (version);
1065
1066 return retc;
1067}
1068
1069/*-------------------------[ Reporting an open port ]---------------------*/
1070
1076tree_cell *
1078{
1079 tree_cell *retc;
1080 int idx = get_int_var_by_num (lexic, 0, -1);
1081 const char *prange = prefs_get ("port_range");
1082 static int num = 0;
1083 static u_short *ports = NULL;
1084
1085 if (prange == NULL)
1086 return NULL;
1087
1088 if (idx < 0)
1089 {
1090 nasl_perror (lexic, "Argument error in scanner_get_port()\n");
1091 nasl_perror (lexic, "Correct usage is : num = scanner_get_port(<num>)\n");
1092 nasl_perror (lexic,
1093 "Where <num> should be 0 the first time you call it\n");
1094 return NULL;
1095 }
1096
1097 if (ports == NULL)
1098 {
1099 ports = (u_short *) getpts ((char *) prange, &num);
1100 if (ports == NULL)
1101 {
1102 return NULL;
1103 }
1104 }
1105
1106 if (idx >= num)
1107 {
1108 return NULL;
1109 }
1110
1111 retc = alloc_typed_cell (CONST_INT);
1112 retc->x.i_val = ports[idx];
1113 return retc;
1114}
1115
1116tree_cell *
1118{
1119 struct script_infos *script_infos = lexic->script_infos;
1120
1121 int port = get_int_var_by_name (lexic, "port", -1);
1122 char *proto = get_str_var_by_name (lexic, "proto");
1123
1124 if (port >= 0)
1125 {
1126 scanner_add_port (script_infos, port, proto ? proto : "tcp");
1127 }
1128
1129 return FAKE_CELL;
1130}
1131
1132tree_cell *
1134{
1135 /* Kept for backward compatibility. */
1136 (void) lexic;
1137 return FAKE_CELL;
1138}
const char * oid
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:111
const char * name
Definition: nasl_init.c:411
const char * val
Definition: nasl_init.c:412
int get_var_size_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1138
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1118
char * get_str_var_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1111
long int get_int_var_by_num(lex_ctxt *, int, int)
Definition: nasl_var.c:1097
long int get_int_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1104
int get_var_type_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1162
uint8_t len
tree_cell * script_tag(lex_ctxt *lexic)
tree_cell * log_message(lex_ctxt *lexic)
tree_cell * nasl_scanner_status(lex_ctxt *lexic)
static tree_cell * set_kb_item_volatile(lex_ctxt *lexic)
Set a volate kb item.
void(* post_something_t)(const char *, struct script_infos *, int, const char *, const char *)
tree_cell * script_family(lex_ctxt *lexic)
tree_cell * script_get_preference(lex_ctxt *lexic)
Get a preferences of the current script.
tree_cell * script_get_preference_file_content(lex_ctxt *lexic)
void(* proto_post_something_t)(const char *, struct script_infos *, int, const char *, const char *, const char *)
static tree_cell * security_something(lex_ctxt *lexic, proto_post_something_t proto_post_func, post_something_t post_func)
tree_cell * script_get_preference_file_location(lex_ctxt *lexic)
tree_cell * script_xref(lex_ctxt *lexic)
Add a cross reference to the meta data.
tree_cell * security_message(lex_ctxt *lexic)
Send a security message to the client.
tree_cell * nasl_scanner_add_port(lex_ctxt *lexic)
tree_cell * get_host_kb_index(lex_ctxt *lexic)
Get the kb index of the host running the current script.
tree_cell * safe_checks(lex_ctxt *lexic)
tree_cell * script_name(lex_ctxt *lexic)
tree_cell * script_copyright(lex_ctxt *lexic)
tree_cell * script_add_preference(lex_ctxt *lexic)
tree_cell * nasl_scanner_get_port(lex_ctxt *lexic)
tree_cell * get_script_oid(lex_ctxt *lexic)
Return the OID of the current script.
tree_cell * script_oid(lex_ctxt *lexic)
tree_cell * nasl_vendor_version(lex_ctxt *lexic)
tree_cell * script_category(lex_ctxt *lexic)
tree_cell * get_kb_list(lex_ctxt *lexic)
tree_cell * error_message(lex_ctxt *lexic)
tree_cell * script_timeout(lex_ctxt *lexic)
Add timeout preference to VT preferences.
tree_cell * script_require_udp_ports(lex_ctxt *lexic)
tree_cell * get_kb_item(lex_ctxt *lexic)
static int isalldigit(char *str, int len)
tree_cell * script_mandatory_keys(lex_ctxt *lexic)
tree_cell * script_dependencies(lex_ctxt *lexic)
tree_cell * script_exclude_keys(lex_ctxt *lexic)
tree_cell * set_kb_item(lex_ctxt *lexic)
Set a kb item.
tree_cell * replace_kb_item(lex_ctxt *lexic)
tree_cell * script_require_ports(lex_ctxt *lexic)
tree_cell * script_require_keys(lex_ctxt *lexic)
tree_cell * script_cve_id(lex_ctxt *lexic)
tree_cell * script_version(lex_ctxt *lexic)
tree_cell * nasl_get_preference(lex_ctxt *lexic)
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:28
void deref_cell(tree_cell *c)
Definition: nasl_tree.c:181
@ CONST_DATA
Definition: nasl_tree.h:82
@ DYN_ARRAY
Definition: nasl_tree.h:90
@ CONST_INT
Definition: nasl_tree.h:79
#define FAKE_CELL
Definition: nasl_tree.h:110
int add_var_to_array(nasl_array *a, char *name, const anon_nasl_var *v)
Definition: nasl_var.c:1277
@ VAR2_DATA
Definition: nasl_var.h:18
@ VAR2_INT
Definition: nasl_var.h:16
unsigned short * getpts(char *origexpr, int *len)
Converts a string like "-100,200-1024,3000-4000,60000-" into an array.
Definition: network.c:2296
void plug_replace_key_len(struct script_infos *args, char *name, int type, void *value, size_t len)
Definition: plugutils.c:1020
void post_alarm(const char *oid, struct script_infos *desc, int port, const char *action, const char *uri)
Definition: plugutils.c:680
void plug_set_key_volatile(struct script_infos *args, char *name, int type, const void *value, int expire)
Set volatile key with expire.
Definition: plugutils.c:1013
void scanner_add_port(struct script_infos *args, int port, char *proto)
Definition: plugutils.c:1049
void proto_post_alarm(const char *oid, struct script_infos *desc, int port, const char *proto, const char *action, const char *uri)
Definition: plugutils.c:673
void plug_set_key_len(struct script_infos *args, char *name, int type, const void *value, size_t len)
Definition: plugutils.c:939
void plug_set_dep(struct script_infos *args, const char *depname)
Definition: plugutils.c:55
void proto_post_error(const char *oid, struct script_infos *desc, int port, const char *proto, const char *action, const char *uri)
Definition: plugutils.c:717
void proto_post_log(const char *oid, struct script_infos *desc, int port, const char *proto, const char *action, const char *uri)
Post a log message.
Definition: plugutils.c:690
void plug_set_key_len_volatile(struct script_infos *args, char *name, int type, const void *value, int expire, size_t len)
Set volatile key with expire.
Definition: plugutils.c:979
void plug_replace_key(struct script_infos *args, char *name, int type, void *value)
Definition: plugutils.c:1043
char * get_plugin_preference(const char *oid, const char *name, int pref_id)
Get the a plugins preference.
Definition: plugutils.c:743
void post_error(const char *oid, struct script_infos *desc, int port, const char *action, const char *uri)
Definition: plugutils.c:724
void plug_set_key(struct script_infos *args, char *name, int type, const void *value)
Definition: plugutils.c:962
void * plug_get_key(struct script_infos *args, char *name, int *type, size_t *len, int single)
Get values from a kb under the given key name.
Definition: plugutils.c:1129
const char * get_plugin_preference_fname(struct script_infos *desc, const char *filename)
Get the file name of a plugins preference that is of type "file".
Definition: plugutils.c:831
void post_log_with_uri(const char *oid, struct script_infos *desc, int port, const char *action, const char *uri)
Post a log message about a tcp port with a uri.
Definition: plugutils.c:710
char * get_plugin_preference_file_content(struct script_infos *desc, const char *identifier)
Get the file contents of a plugins preference that is of type "file".
Definition: plugutils.c:886
kb_t plug_get_kb(struct script_infos *args)
Definition: plugutils.c:1055
long get_plugin_preference_file_size(struct script_infos *desc, const char *identifier)
Get the file size of a plugins preference that is of type "file".
Definition: plugutils.c:917
#define ARG_STRING
Definition: plugutils.h:19
#define ARG_INT
Definition: plugutils.h:20
Definition: nasl_tree.h:94
union TC::@5 x
int size
Definition: nasl_tree.h:99
long int i_val
Definition: nasl_tree.h:104
char * str_val
Definition: nasl_tree.h:103
void * ref_val
Definition: nasl_tree.h:105
short type
Definition: nasl_tree.h:95
int standalone
Definition: scanneraux.h:39
nvti_t * nvti
Definition: scanneraux.h:33
nasl_string_t v_str
Definition: nasl_var.h:47
int var_type
Definition: nasl_var.h:41
union st_a_nasl_var::@7 v
long int v_int
Definition: nasl_var.h:48
unsigned char * s_val
Definition: nasl_var.h:26
struct script_infos * script_infos
Definition: nasl_lex_ctxt.h:30
const char * oid
Definition: nasl_lex_ctxt.h:31
const gchar * vendor_version_get()
Get vendor version.
Definition: vendorversion.c:38