OpenVAS Libraries  9.0.3
nasl_scanner_glue.c
Go to the documentation of this file.
1 /* Nessus Attack Scripting Language
2  *
3  * Copyright (C) 2002 - 2004 Tenable Network Security
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2,
7  * as published by the Free Software Foundation
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  *
18  */
19 
27 #include <ctype.h> /* for isdigit */
28 #include <errno.h> /* for errno */
29 #include <fcntl.h> /* for open */
30 #include <stdlib.h> /* for atoi */
31 #include <string.h> /* for strcmp */
32 #include <sys/stat.h> /* for stat */
33 #include <unistd.h> /* for close */
34 
35 #include <glib.h>
36 
37 #include "../base/kb.h" /* for KB_TYPE_INT */
38 #include "../misc/plugutils.h" /* for plug_set_id */
39 #include "../misc/network.h" /* for getpts */
40 #include "../misc/vendorversion.h" /* for vendor_version_get */
41 
42 #include "nasl_tree.h"
43 #include "nasl_global_ctxt.h"
44 #include "nasl_func.h"
45 #include "nasl_var.h"
46 #include "nasl_lex_ctxt.h"
47 #include "../misc/openvas_logging.h"
48 
49 #include "nasl_debug.h"
50 #include "nasl_scanner_glue.h"
51 
52 #include "../base/nvticache.h"
53 
54 #include "../misc/prefs.h" /* for prefs_get */
55 
56 #ifndef NASL_DEBUG
57 #define NASL_DEBUG 0
58 #endif
59 
60 /*------------------- Private utilities ---------------------------------*/
61 
62 static int
63 isalldigit (char *str, int len)
64 {
65  int i;
66  char buf[1024];
67  for (i = 0; i < len; i++)
68  {
69  if (!isdigit (str[i]))
70  return 0;
71  }
72 
73  snprintf (buf, sizeof (buf), "%d", atoi (str));
74  if (strcmp (buf, str) != 0)
75  return 0;
76  else
77  return 1;
78 }
79 
80 
81 
82 /*-------------------[ script_*() functions ]----------------------------*/
83 
84  /*
85  * These functions are used when the script registers itself to openvas
86  * scanner.
87  */
88 
89 tree_cell *
91 {
92  nvti_t *nvti = arg_get_value (lexic->script_infos, "NVTI");
93  int to = get_int_var_by_num (lexic, 0, -65535);
94 
95  if (to == -65535)
96  return FAKE_CELL;
97 
98  nvti_set_timeout (nvti, to ? to : -1);
99  return FAKE_CELL;
100 }
101 
102 
103 tree_cell *
105 {
106  int id;
107  char * oid;
108 
109  id = get_int_var_by_num (lexic, 0, -1);
110  if (id > 0)
111  {
112  oid = g_strdup_printf ("%s%i", LEGACY_OID, id);
113  nvti_set_oid (arg_get_value (lexic->script_infos, "NVTI"), oid);
114  g_free (oid);
115  }
116 
117  return FAKE_CELL;
118 }
119 
120 tree_cell *
122 {
123  nvti_set_oid (arg_get_value (lexic->script_infos, "NVTI"),
124  get_str_var_by_num (lexic, 0));
125  return FAKE_CELL;
126 }
127 
128 /*
129  * TODO: support multiple CVE entries
130  */
131 tree_cell *
133 {
134  struct arglist *script_infos = lexic->script_infos;
135  char *cve = get_str_var_by_num (lexic, 0);
136  int i;
137 
138  for (i = 0; cve != NULL; i++)
139  {
140  nvti_add_cve (arg_get_value (script_infos, "NVTI"), cve);
141  cve = get_str_var_by_num (lexic, i + 1);
142  }
143 
144  return FAKE_CELL;
145 }
146 
147 /*
148  * TODO: support multiple bugtraq entries
149  */
150 tree_cell *
152 {
153  struct arglist *script_infos = lexic->script_infos;
154  char *bid = get_str_var_by_num (lexic, 0);
155  int i;
156 
157  for (i = 0; bid != NULL; i++)
158  {
159  nvti_add_bid (arg_get_value (script_infos, "NVTI"), bid);
160  bid = get_str_var_by_num (lexic, i + 1);
161  }
162 
163  return FAKE_CELL;
164 }
165 
166 
167 tree_cell *
169 {
170  struct arglist *script_infos = lexic->script_infos;
171  char *name = get_str_var_by_name (lexic, "name");
172  char *value = get_str_var_by_name (lexic, "value");
173 
174 
175  if (value == NULL || name == NULL)
176  {
177  nasl_perror (lexic,
178  "script_xref() syntax error - should be"
179  " script_xref(name:<name>, value:<value>)\n");
180  if (name == NULL)
181  {
182  nasl_perror (lexic, " <name> is empty\n");
183  }
184  else
185  {
186  nasl_perror (lexic, " <name> is %s\n", name);
187  }
188  if (value == NULL)
189  {
190  nasl_perror (lexic, " <value> is empty)\n");
191  }
192  else
193  {
194  nasl_perror (lexic, " <value> is %s\n)", value);
195  }
196  return FAKE_CELL;
197  }
198 
199  plug_set_xref (script_infos, name, value);
200 
201  return FAKE_CELL;
202 }
203 
204 tree_cell *
206 {
207  struct arglist *script_infos = lexic->script_infos;
208  char *name = get_str_var_by_name (lexic, "name");
209  char *value = get_str_var_by_name (lexic, "value");
210 
211  if (value == NULL || name == NULL)
212  {
213  nasl_perror (lexic, "script_tag() syntax error - should be"
214  " script_tag(name:<name>, value:<value>)\n");
215  if (name == NULL)
216  {
217  nasl_perror (lexic, " <name> is empty\n");
218  }
219  else
220  {
221  nasl_perror (lexic, " <name> is %s\n", name);
222  }
223  if (value == NULL)
224  {
225  nasl_perror (lexic, " <value> is empty)\n");
226  }
227  else
228  {
229  nasl_perror (lexic, " <value> is %s\n)", value);
230  }
231  return FAKE_CELL;
232  }
233 
234  if (strchr (value, '|'))
235  {
236  nasl_perror (lexic, "%s tag contains | separator", name);
237  return FAKE_CELL;
238  }
239  plug_set_tag (script_infos, name, value);
240 
241  return FAKE_CELL;
242 }
243 
244 
245 tree_cell *
247 {
248  nvti_set_name (arg_get_value (lexic->script_infos, "NVTI"),
249  get_str_var_by_num (lexic, 0));
250  return FAKE_CELL;
251 }
252 
253 
254 tree_cell *
256 {
257  nvti_t *nvti = arg_get_value (lexic->script_infos, "NVTI");
258 
259  char *version = get_str_var_by_num (lexic, 0);
260  if (version == NULL)
261  {
262  nasl_perror (lexic, "Argument error in function script_version()\n");
263  nasl_perror (lexic, "Function usage is : script_version(<version>)\n");
264  nasl_perror (lexic, "Where <version> is the version of this script\n");
265  }
266  else
267  nvti_set_version (nvti, version);
268 
269  return FAKE_CELL;
270 }
271 
272 tree_cell *
274 {
276  get_str_var_by_num (lexic, 0));
277  return FAKE_CELL;
278 }
279 
280 tree_cell *
282 {
283  /* XXX: For backward compatibility. */
284  return FAKE_CELL;
285 }
286 
287 tree_cell *
289 {
290  struct arglist *script_infos = lexic->script_infos;
291 
292  int category = get_int_var_by_num (lexic, 0, -1);
293 
294  if (category < 0)
295  {
296  nasl_perror (lexic, "Argument error in function script_category()\n");
297  nasl_perror (lexic, "Function usage is : script_category(<category>)\n");
298  return FAKE_CELL;
299  }
300  nvti_set_category (arg_get_value (script_infos, "NVTI"), category);
301  return FAKE_CELL;
302 }
303 
304 tree_cell *
306 {
307  nvti_set_family (arg_get_value (lexic->script_infos, "NVTI"),
308  get_str_var_by_num (lexic, 0));
309  return FAKE_CELL;
310 }
311 
312 tree_cell *
314 {
315  struct arglist *script_infos = lexic->script_infos;
316  char *dep = get_str_var_by_num (lexic, 0);
317  int i;
318 
319  if (dep == NULL)
320  {
321  nasl_perror (lexic, "Argument error in function script_dependencies()\n");
322  nasl_perror (lexic, "Function usage is : script_dependencies(<name>)\n");
323  nasl_perror (lexic, "Where <name> is the name of another script\n");
324 
325  return FAKE_CELL;
326  }
327 
328  for (i = 0; dep != NULL; i++)
329  {
330  dep = get_str_var_by_num (lexic, i);
331  if (dep != NULL)
332  plug_set_dep (script_infos, dep);
333  }
334 
335  return FAKE_CELL;
336 }
337 
338 
339 tree_cell *
341 {
342  char *keys = get_str_var_by_num (lexic, 0);
343  int i;
344 
345  if (keys == NULL)
346  {
347  nasl_perror (lexic, "Argument error in function script_require_keys()\n");
348  nasl_perror (lexic, "Function usage is : script_require_keys(<name>)\n");
349  nasl_perror (lexic, "Where <name> is the name of a key\n");
350  return FAKE_CELL;
351  }
352 
353  for (i = 0; keys != NULL; i++)
354  {
355  keys = get_str_var_by_num (lexic, i);
356  nvti_add_required_keys (arg_get_value (lexic->script_infos, "NVTI"), keys);
357  }
358 
359  return FAKE_CELL;
360 }
361 
362 tree_cell *
364 {
365  char *keys = get_str_var_by_num (lexic, 0);
366  char **splits = NULL, *re = get_str_var_by_name (lexic, "re");
367  int i;
368 
369  if (keys == NULL)
370  {
371  nasl_perror (lexic,
372  "Argument error in function script_mandatory_keys()\n");
373  nasl_perror (lexic,
374  "Function usage is : script_mandatory_keys(<name>)\n");
375  nasl_perror (lexic, "Where <name> is the name of a key\n");
376  return FAKE_CELL;
377  }
378 
379  if (re)
380  {
381  splits = g_strsplit (re, "=", 0);
382 
383  if (!splits[0] || !splits[1] || !*splits[1] || splits[2])
384  {
385  nasl_perror (lexic, "Erroneous re argument");
386  return FAKE_CELL;
387  }
388  }
389  for (i = 0; keys != NULL; i++)
390  {
391  keys = get_str_var_by_num (lexic, i);
392 
393  if (splits && keys && !strcmp (keys, splits[0]))
394  {
396  re);
397  re = NULL;
398  }
399  else
401  keys);
402  }
403  if (re)
404  nvti_add_mandatory_keys (arg_get_value (lexic->script_infos, "NVTI"), re);
405 
406  g_strfreev (splits);
407  return FAKE_CELL;
408 }
409 
410 tree_cell *
412 {
413  char *keys = get_str_var_by_num (lexic, 0);
414  int i;
415 
416  if (keys == NULL)
417  {
418  nasl_perror (lexic, "Argument error in function script_exclude_keys()\n");
419  nasl_perror (lexic, "Function usage is : script_exclude_keys(<name>)\n");
420  nasl_perror (lexic, "Where <name> is the name of a key\n");
421  return FAKE_CELL;
422  }
423 
424  for (i = 0; keys != NULL; i++)
425  {
426  keys = get_str_var_by_num (lexic, i);
427  nvti_add_excluded_keys (arg_get_value (lexic->script_infos, "NVTI"), keys);
428  }
429 
430  return FAKE_CELL;
431 }
432 
433 
434 tree_cell *
436 {
437  char *port;
438  int i;
439 
440  for (i = 0;; i++)
441  {
442  port = get_str_var_by_num (lexic, i);
443  if (port != NULL)
444  nvti_add_required_ports (arg_get_value (lexic->script_infos, "NVTI"), port);
445  else
446  break;
447  }
448 
449  return FAKE_CELL;
450 }
451 
452 
453 tree_cell *
455 {
456  int i;
457  char *port;
458 
459  for (i = 0;; i++)
460  {
461  port = get_str_var_by_num (lexic, i);
462  if (port != NULL)
463  nvti_add_required_udp_ports (arg_get_value (lexic->script_infos, "NVTI"), port);
464  else
465  break;
466  }
467 
468  return FAKE_CELL;
469 }
470 
471 tree_cell *
473 {
474  char *name = get_str_local_var_by_name (lexic, "name");
475  char *type = get_str_local_var_by_name (lexic, "type");
476  char *value = get_str_local_var_by_name (lexic, "value");
477  struct arglist *script_infos = lexic->script_infos;
478 
479  if (name == NULL || type == NULL || value == NULL)
480  {
481  nasl_perror (lexic,
482  "Argument error in the call to script_add_preference()\n");
483  }
484  else
485  add_plugin_preference (script_infos, name, type, value);
486 
487  return FAKE_CELL;
488 }
489 
490 tree_cell *
492 {
493  tree_cell *retc;
494  char *pref = get_str_var_by_num (lexic, 0);
495  char *value;
496 
497  if (pref == NULL)
498  {
499  nasl_perror (lexic,
500  "Argument error in the function script_get_preference()\n");
501  nasl_perror (lexic,
502  "Function usage is : pref = script_get_preference(<name>)\n");
503  return FAKE_CELL;
504  }
505 
506  value = get_plugin_preference (lexic->oid, pref);
507  if (value != NULL)
508  {
509  retc = alloc_tree_cell (0, NULL);
510  if (isalldigit (value, strlen (value)))
511  {
512  retc->type = CONST_INT;
513  retc->x.i_val = atoi (value);
514  }
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 
528 tree_cell *
530 {
531  struct arglist *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,
543  "Function usage is : pref = script_get_preference_file_content(<name>)\n");
544  return NULL;
545  }
546 
547  value = get_plugin_preference (lexic->oid, pref);
548  if (value == NULL)
549  return NULL;
550 
551  content = get_plugin_preference_file_content (script_infos, value);
552  if (content == NULL)
553  return FAKE_CELL;
554  contentsize = get_plugin_preference_file_size (script_infos, value);
555  if (contentsize <= 0)
556  {
557  nasl_perror (lexic, "script_get_preference_file_content: could not get "
558  " size of file from preference %s\n", pref);
559  return NULL;
560  }
561 
562  retc = alloc_tree_cell (0, NULL);
563  retc->type = CONST_DATA;
564  retc->size = contentsize;
565  retc->x.str_val = content;
566 
567  return retc;
568 }
569 
570 
571 tree_cell *
573 {
574  struct arglist *script_infos = lexic->script_infos;
575  tree_cell *retc;
576  char *pref = get_str_var_by_num (lexic, 0);
577  const char *value, *local;
578  int len;
579 
580  if (pref == NULL)
581  {
582  nasl_perror (lexic,
583  "script_get_preference_file_location: no preference name!\n");
584  return NULL;
585  }
586 
587  value = get_plugin_preference (lexic->oid, pref);
588  if (value == NULL)
589  {
590  nasl_perror (lexic,
591  "script_get_preference_file_location: could not get preference %s\n",
592  pref);
593  return NULL;
594  }
595  local = get_plugin_preference_fname (script_infos, value);
596  if (local == NULL)
597  return NULL;
598 
599  len = strlen (local);
600  retc = alloc_typed_cell (CONST_DATA);
601  retc->size = len;
602  retc->x.str_val = g_malloc0 (len + 1);
603  memcpy (retc->x.str_val, local, len + 1);
604 
605  return retc;
606 }
607 
608 /* Are safe checks enabled ? */
609 tree_cell *
611 {
612  tree_cell *retc = alloc_tree_cell (0, NULL);
613 
614  retc->type = CONST_INT;
615  retc->x.i_val = prefs_get_bool ("safe_checks");
616 
617  return retc;
618 }
619 
620 tree_cell *
622 {
623  struct arglist *script_infos = lexic->script_infos;
624  struct arglist *globals = arg_get_value (script_infos, "globals");
625  char *value;
626  tree_cell *retc = alloc_tree_cell (0, NULL);
627 
628  retc->type = CONST_INT;
629  value = arg_get_value (globals, "network_scan_status");
630  if (value)
631  {
632  if (strcmp (value, "busy") == 0)
633  retc->x.i_val = 1;
634  else
635  retc->x.i_val = 2;
636  }
637  else
638  retc->x.i_val = 0;
639 
640  return retc;
641 }
642 
643 tree_cell *
645 {
646  struct arglist *script_infos = lexic->script_infos;
647  struct arglist *globals = arg_get_value (script_infos, "globals");
648  char *value;
649  tree_cell *retc;
650 
651  value = arg_get_value (globals, "network_targets");
652  retc = alloc_typed_cell (CONST_DATA);
653  if (value)
654  {
655  retc->x.str_val = strdup (value);
656  retc->size = strlen (value);
657  }
658  else
659  return NULL;
660 
661  return retc;
662 }
663 
671 tree_cell *
673 {
674  const char *oid = lexic->oid;
675  tree_cell *retc = NULL;
676 
677  if (oid)
678  {
679  retc = alloc_typed_cell (CONST_DATA);
680  retc->x.str_val = g_strdup (oid);
681  retc->size = strlen (oid);
682  }
683 
684  return retc;
685 }
686 
687 /*--------------------[ KB ]---------------------------------------*/
688 
689 tree_cell *
691 {
692  struct arglist *script_infos = lexic->script_infos;
693  kb_t kb = plug_get_kb (script_infos);
694  char *kb_mask = get_str_var_by_num (lexic, 0);
695  tree_cell *retc;
696  int num_elems = 0;
697  nasl_array *a;
698  struct kb_item *res, *top;
699 
700  if (kb_mask == NULL)
701  {
702  nasl_perror (lexic, "get_kb_list() usage : get_kb_list(<NameOfItem>)\n");
703  return NULL;
704  }
705 
706  if (kb == NULL)
707  return NULL;
708 
709  retc = alloc_tree_cell (0, NULL);
710  retc->type = DYN_ARRAY;
711  retc->x.ref_val = a = g_malloc0 (sizeof (nasl_array));
712 
713  top = res = kb_item_get_pattern (kb, kb_mask);
714 
715  while (res != NULL)
716  {
717  anon_nasl_var v;
718  bzero (&v, sizeof (v));
719 
720  if (res->type == KB_TYPE_INT)
721  {
722  v.var_type = VAR2_INT;
723  v.v.v_int = res->v_int;
724  add_var_to_array (a, res->name, &v);
725  num_elems++;
726  }
727  else if (res->type == KB_TYPE_STR)
728  {
729  v.var_type = VAR2_DATA;
730  v.v.v_str.s_val = (unsigned char *) res->v_str;
731  v.v.v_str.s_siz = strlen (res->v_str);
732  add_var_to_array (a, res->name, &v);
733  num_elems++;
734  }
735  res = res->next;
736  }
737 
738  kb_item_free (top);
739 
740  if (num_elems == 0)
741  {
742  deref_cell (retc);
743  return FAKE_CELL;
744  }
745  return retc;
746 }
747 
748 tree_cell *
750 {
751  struct arglist *script_infos = lexic->script_infos;
752 
753  char *kb_entry = get_str_var_by_num (lexic, 0);
754  char *val;
755  tree_cell *retc;
756  int type, single = get_int_var_by_num (lexic, 1, 0);
757 
758  if (kb_entry == NULL)
759  return NULL;
760 
761  val = plug_get_key (script_infos, kb_entry, &type, single);
762 
763 
764  if (val == NULL && type == -1)
765  return NULL;
766 
767 
768  retc = alloc_tree_cell (0, NULL);
769  if (type == KB_TYPE_INT)
770  {
771  retc->type = CONST_INT;
772  retc->x.i_val = GPOINTER_TO_SIZE (val);
773  g_free (val);
774  return retc;
775  }
776  else
777  {
778  retc->type = CONST_DATA;
779  if (val != NULL)
780  {
781  retc->size = strlen (val);
782  retc->x.str_val = val;
783  }
784  else
785  {
786  retc->size = 0;
787  retc->x.str_val = NULL;
788  }
789  }
790 
791  return retc;
792 }
793 
794 tree_cell *
796 {
797  struct arglist *script_infos = lexic->script_infos;
798  char *name = get_str_local_var_by_name (lexic, "name");
799  int type = get_local_var_type_by_name (lexic, "value");
800 
801  if (name == NULL)
802  {
803  nasl_perror (lexic, "Syntax error with replace_kb_item() [null name]\n",
804  name);
805  return FAKE_CELL;
806  }
807 
808  if (type == VAR2_INT)
809  {
810  int value = get_int_local_var_by_name (lexic, "value", -1);
811  if (value != -1)
812  plug_replace_key (script_infos, name, ARG_INT,
813  GSIZE_TO_POINTER (value));
814  else
815  nasl_perror (lexic,
816  "Syntax error with replace_kb_item(%s) [value=-1]\n",
817  name);
818  }
819  else
820  {
821  char *value = get_str_local_var_by_name (lexic, "value");
822  if (value == NULL)
823  {
824  nasl_perror (lexic,
825  "Syntax error with replace_kb_item(%s) [null value]\n",
826  name);
827  return FAKE_CELL;
828  }
829  plug_replace_key (script_infos, name, ARG_STRING, value);
830  }
831 
832  return FAKE_CELL;
833 }
834 
835 tree_cell *
837 {
838  struct arglist *script_infos = lexic->script_infos;
839  char *name = get_str_local_var_by_name (lexic, "name");
840  int type = get_local_var_type_by_name (lexic, "value");
841 
842  if (name == NULL)
843  {
844  nasl_perror (lexic, "Syntax error with set_kb_item() [null name]\n",
845  name);
846  return FAKE_CELL;
847  }
848 
849  if (type == VAR2_INT)
850  {
851  int value = get_int_local_var_by_name (lexic, "value", -1);
852  if (value != -1)
853  plug_set_key (script_infos, name, ARG_INT, GSIZE_TO_POINTER (value));
854  else
855  nasl_perror (lexic,
856  "Syntax error with set_kb_item() [value=-1 for name '%s']\n",
857  name);
858  }
859  else
860  {
861  char *value = get_str_local_var_by_name (lexic, "value");
862  if (value == NULL)
863  {
864  nasl_perror (lexic,
865  "Syntax error with set_kb_item() [null value for name '%s']\n",
866  name);
867  return FAKE_CELL;
868  }
869  plug_set_key (script_infos, name, ARG_STRING, value);
870  }
871 
872  return FAKE_CELL;
873 }
874 
875 /*------------------------[ Reporting a problem ]---------------------------*/
876 
877 
881 typedef void (*proto_post_something_t) (const char *, struct arglist *, int,
882  const char *, const char *);
886 typedef void (*post_something_t) (const char *, struct arglist *, int, const char *);
887 
888 
889 static tree_cell *
890 security_something (lex_ctxt * lexic, proto_post_something_t proto_post_func,
891  post_something_t post_func)
892 {
893  struct arglist *script_infos = lexic->script_infos;
894 
895  char *proto = get_str_local_var_by_name (lexic, "protocol");
896  char *data = get_str_local_var_by_name (lexic, "data");
897  int port = get_int_local_var_by_name (lexic, "port", -1);
898  char *dup = NULL;
899 
900  if (data != NULL)
901  {
902  int len = get_local_var_size_by_name (lexic, "data");
903  int i;
904 
905  dup = g_memdup (data, len + 1);
906  for (i = 0; i < len; i++)
907  if (dup[i] == 0)
908  dup[i] = ' ';
909  }
910 
911  if ((arg_get_value (script_infos, "standalone")) != NULL)
912  {
913  if (data != NULL)
914  fprintf (stdout, "%s\n", dup);
915  else
916  fprintf (stdout, "Success\n");
917  }
918 
919  if (proto == NULL)
920  proto = get_str_local_var_by_name (lexic, "proto");
921 
922  if (port < 0)
923  port = get_int_var_by_num (lexic, 0, -1);
924 
925  if (dup != NULL)
926  {
927  if (proto == NULL)
928  post_func (lexic->oid, script_infos, port, dup);
929  else
930  proto_post_func (lexic->oid, script_infos, port, proto, dup);
931 
932  g_free (dup);
933  return FAKE_CELL;
934  }
935 
936  if (proto == NULL)
937  post_func (lexic->oid, script_infos, port, NULL);
938  else
939  proto_post_func (lexic->oid, script_infos, port, proto, NULL);
940 
941  return FAKE_CELL;
942 }
943 
951 tree_cell *
953 {
954  return security_something (lexic, proto_post_alarm, post_alarm);
955 }
956 
957 tree_cell *
959 {
960  return security_something (lexic, proto_post_log, post_log);
961 }
962 
963 tree_cell *
965 {
966  return security_something (lexic, proto_post_error, post_error);
967 }
968 
969 tree_cell *
971 {
972  tree_cell *retc;
973  char *name;
974  const char *value;
975 
976  name = get_str_var_by_num (lexic, 0);
977  if (name == NULL)
978  {
979  nasl_perror (lexic, "get_preference: no name\n");
980  return NULL;
981  }
982  value = prefs_get (name);
983  if (value == NULL)
984  return NULL;
985 
986  retc = alloc_typed_cell (CONST_DATA);
987  retc->x.str_val = strdup (value);
988  retc->size = strlen (value);
989  return retc;
990 }
991 
992 tree_cell *
994 {
995  tree_cell *retc;
996  gchar *version = g_strdup (vendor_version_get ());
997  (void) lexic;
998  retc = alloc_typed_cell (CONST_DATA);
999  retc->x.str_val = strdup (version);
1000  retc->size = strlen (version);
1001  g_free (version);
1002 
1003  return retc;
1004 }
1005 
1006 /*-------------------------[ Reporting an open port ]---------------------*/
1007 
1013 tree_cell *
1015 {
1016  tree_cell *retc;
1017  int idx = get_int_var_by_num (lexic, 0, -1);
1018  const char *prange = prefs_get ("port_range");
1019  static int num = 0;
1020  static u_short *ports = NULL;
1021 
1022  if (prange == NULL)
1023  return NULL;
1024 
1025  if (idx < 0)
1026  {
1027  nasl_perror (lexic, "Argument error in scanner_get_port()\n");
1028  nasl_perror (lexic, "Correct usage is : num = scanner_get_port(<num>)\n");
1029  nasl_perror (lexic,
1030  "Where <num> should be 0 the first time you call it\n");
1031  return NULL;
1032  }
1033 
1034  if (ports == NULL)
1035  {
1036  ports = (u_short *) getpts ((char *)prange, &num);
1037  if (ports == NULL)
1038  {
1039  return NULL;
1040  }
1041  }
1042 
1043  if (idx >= num)
1044  {
1045  return NULL;
1046  }
1047 
1048  retc = alloc_tree_cell (0, NULL);
1049  retc->type = CONST_INT;
1050  retc->x.i_val = ports[idx];
1051  return retc;
1052 }
1053 
1054 
1055 tree_cell *
1057 {
1058  struct arglist *script_infos = lexic->script_infos;
1059 
1060  int port = get_int_local_var_by_name (lexic, "port", -1);
1061  char *proto = get_str_local_var_by_name (lexic, "proto");
1062 
1063  if (port >= 0)
1064  {
1065  scanner_add_port (script_infos, port, proto ? proto : "tcp");
1066  }
1067 
1068  return FAKE_CELL;
1069 }
1070 
1071 tree_cell *
1073 {
1074  /* Kept for backward compatibility. */
1075  return FAKE_CELL;
1076 }
tree_cell * nasl_scanner_get_port(lex_ctxt *lexic)
tree_cell * script_get_preference_file_content(lex_ctxt *lexic)
#define FAKE_CELL
Definition: nasl_tree.h:120
int nvti_set_category(nvti_t *n, const gint category)
Set the category type of a NVT Info.
Definition: nvti.c:880
void proto_post_error(const char *oid, struct arglist *desc, int port, const char *proto, const char *action)
Definition: plugutils.c:451
#define ARG_INT
Definition: arglists.h:40
tree_cell * get_script_oid(lex_ctxt *lexic)
Return the OID of the current script.
void proto_post_alarm(const char *oid, struct arglist *desc, int port, const char *proto, const char *action)
Definition: plugutils.c:418
tree_cell * script_exclude_keys(lex_ctxt *lexic)
tree_cell * script_oid(lex_ctxt *lexic)
Definition: kb.h:49
void plug_replace_key(struct arglist *args, char *name, int type, void *value)
Definition: plugutils.c:681
int nvti_set_copyright(nvti_t *n, const gchar *copyright)
Set the copyright of a NVT.
Definition: nvti.c:561
void kb_item_free(struct kb_item *)
Release a KB item (or a list).
Definition: kb_redis.c:501
void plug_set_dep(struct arglist *desc, const char *depname)
Definition: plugutils.c:87
tree_cell * scan_phase(lex_ctxt *lexic)
const char * val
Definition: nasl_init.c:525
void plug_set_tag(struct arglist *desc, char *name, char *value)
Definition: plugutils.c:72
int nvti_set_family(nvti_t *n, const gchar *family)
Set the family of a NVT.
Definition: nvti.c:840
void post_error(const char *oid, struct arglist *desc, int port, const char *action)
Definition: plugutils.c:459
void plug_set_key(struct arglist *args, char *name, int type, const void *value)
Definition: plugutils.c:658
void * plug_get_key(struct arglist *args, char *name, int *type, int single)
Definition: plugutils.c:767
The structure of a information record that corresponds to a NVT.
Definition: nvti.h:64
tree_cell * script_family(lex_ctxt *lexic)
short type
Definition: nasl_tree.h:107
tree_cell * script_require_ports(lex_ctxt *lexic)
Knowledge base item (defined by name, type (int/char*) and value). Implemented as a singly linked lis...
Definition: kb.h:81
tree_cell * get_kb_item(lex_ctxt *lexic)
struct kb_item * next
Definition: kb.h:91
#define LEGACY_OID
Definition: plugutils.h:35
union st_a_nasl_var::@9 v
tree_cell * script_bugtraq_id(lex_ctxt *lexic)
char * str_val
Definition: nasl_tree.h:113
const char * oid
enum kb_item_type type
Definition: kb.h:83
int nvti_set_timeout(nvti_t *n, const gint timeout)
Set the timout of a NVT Info.
Definition: nvti.c:861
int nvti_add_required_udp_ports(nvti_t *n, const gchar *port)
Add a required udp port of a NVT.
Definition: nvti.c:1079
void deref_cell(tree_cell *c)
Definition: nasl_tree.c:202
tree_cell * nasl_scanner_status(lex_ctxt *lexic)
int nvti_add_cve(nvti_t *n, const gchar *cve_id)
Add a single CVE ID of a NVT.
Definition: nvti.c:899
tree_cell * script_version(lex_ctxt *lexic)
int add_var_to_array(nasl_array *a, char *name, const anon_nasl_var *v)
Definition: nasl_var.c:1432
void * ref_val
Definition: nasl_tree.h:115
nasl_string_t v_str
Definition: nasl_var.h:60
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
tree_cell * script_add_preference(lex_ctxt *lexic)
const gchar * prefs_get(const gchar *key)
Get a string preference value via a key.
Definition: prefs.c:86
tree_cell * script_cve_id(lex_ctxt *lexic)
int get_local_var_size_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1298
char * get_str_local_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1262
union TC::@7 x
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1255
int type
Definition: arglists.h:34
const char * get_plugin_preference_fname(struct arglist *desc, const char *filename)
Get the file name of a plugins preference that is of type "file".
Definition: plugutils.c:551
tree_cell * log_message(lex_ctxt *lexic)
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:53
tree_cell * nasl_scanner_add_port(lex_ctxt *lexic)
int var_type
Definition: nasl_var.h:54
void * value
Definition: arglists.h:32
tree_cell * get_kb_list(lex_ctxt *lexic)
tree_cell * script_dependencies(lex_ctxt *lexic)
kb_t plug_get_kb(struct arglist *args)
Definition: plugutils.c:710
void post_log(const char *oid, struct arglist *desc, int port, const char *action)
Post a log message about a tcp port.
Definition: plugutils.c:445
Definition: kb.h:48
unsigned short * getpts(char *origexpr, int *len)
Converts a string like "-100,200-1024,3000-4000,60000-" into an array.
Definition: network.c:2416
tree_cell * set_kb_item(lex_ctxt *lexic)
tree_cell * script_timeout(lex_ctxt *lexic)
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:102
const gchar * vendor_version_get()
Get vendor version.
Definition: vendorversion.c:52
tree_cell * script_require_keys(lex_ctxt *lexic)
Definition: nasl_tree.h:105
int nvti_set_oid(nvti_t *n, const gchar *oid)
Set the OID of a NVT Info.
Definition: nvti.c:498
int nvti_add_mandatory_keys(nvti_t *n, const gchar *key)
Add a mandatory key of a NVT.
Definition: nvti.c:989
int nvti_set_version(nvti_t *n, const gchar *version)
Set the version of a NVT.
Definition: nvti.c:519
tree_cell * script_tag(lex_ctxt *lexic)
int nvti_add_bid(nvti_t *n, const gchar *bid_id)
Add a single BID ID of a NVT.
Definition: nvti.c:929
int nvti_set_name(nvti_t *n, const gchar *name)
Set the name of a NVT.
Definition: nvti.c:540
void(* post_something_t)(const char *, struct arglist *, int, const char *)
tree_cell * safe_checks(lex_ctxt *lexic)
void(* proto_post_something_t)(const char *, struct arglist *, int, const char *, const char *)
void post_alarm(const char *oid, struct arglist *desc, int port, const char *action)
Definition: plugutils.c:425
void plug_set_xref(struct arglist *desc, char *name, char *value)
Definition: plugutils.c:57
tree_cell * script_id(lex_ctxt *lexic)
const char * name
Definition: nasl_init.c:524
void scanner_add_port(struct arglist *args, int port, char *proto)
Definition: plugutils.c:703
int get_local_var_type_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1322
tree_cell * script_name(lex_ctxt *lexic)
long int get_int_var_by_num(lex_ctxt *, int, int)
Definition: nasl_var.c:1226
char * get_plugin_preference_file_content(struct arglist *desc, const char *identifier)
Get the file contents of a plugins preference that is of type "file".
Definition: plugutils.c:605
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
int v_int
Definition: kb.h:88
tree_cell * script_get_preference_file_location(lex_ctxt *lexic)
char * get_str_var_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1248
int nvti_add_excluded_keys(nvti_t *n, const gchar *key)
Add a excluded key of a NVT.
Definition: nvti.c:1019
long int i_val
Definition: nasl_tree.h:114
#define ARG_STRING
Definition: arglists.h:38
tree_cell * script_mandatory_keys(lex_ctxt *lexic)
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
void add_plugin_preference(struct arglist *desc, const char *name, const char *type, const char *defaul)
Definition: plugutils.c:465
tree_cell * nasl_get_preference(lex_ctxt *lexic)
unsigned char * s_val
Definition: nasl_var.h:35
tree_cell * replace_kb_item(lex_ctxt *lexic)
const char * oid
Definition: nasl_lex_ctxt.h:40
struct arglist * script_infos
Definition: nasl_lex_ctxt.h:39
long get_plugin_preference_file_size(struct arglist *desc, const char *identifier)
Get the file size of a plugins preference that is of type "file".
Definition: plugutils.c:637
tree_cell * script_category(lex_ctxt *lexic)
char name[0]
Definition: kb.h:94
void proto_post_log(const char *oid, struct arglist *desc, int port, const char *proto, const char *action)
Post a log message.
Definition: plugutils.c:435
int nvti_add_required_ports(nvti_t *n, const gchar *port)
Add a required port of a NVT.
Definition: nvti.c:1049
tree_cell * script_get_preference(lex_ctxt *lexic)
int nvti_add_required_keys(nvti_t *n, const gchar *key)
Add a required key of a NVT.
Definition: nvti.c:959
tree_cell * network_targets(lex_ctxt *lexic)
tree_cell * script_require_udp_ports(lex_ctxt *lexic)
tree_cell * error_message(lex_ctxt *lexic)
void * arg_get_value(struct arglist *args, const char *name)
Definition: arglists.c:252
tree_cell * nasl_vendor_version(lex_ctxt *lexic)
long int v_int
Definition: nasl_var.h:61
int prefs_get_bool(const gchar *key)
Get a boolean expression of a preference value via a key.
Definition: prefs.c:109
tree_cell * security_message(lex_ctxt *lexic)
Send a security message to the client.
char * v_str
Definition: kb.h:87
tree_cell * script_copyright(lex_ctxt *lexic)
char * get_plugin_preference(const char *oid, const char *name)
Definition: plugutils.c:476
int size
Definition: nasl_tree.h:110
tree_cell * script_summary(lex_ctxt *lexic)
tree_cell * script_xref(lex_ctxt *lexic)