OpenVAS Scanner  7.0.1~git
nasl_scanner_glue.h File Reference
#include "nasl_lex_ctxt.h"
Include dependency graph for nasl_scanner_glue.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

tree_cellscript_timeout (lex_ctxt *)
 
tree_cellscript_oid (lex_ctxt *)
 
tree_cellscript_cve_id (lex_ctxt *)
 
tree_cellscript_bugtraq_id (lex_ctxt *)
 
tree_cellscript_xref (lex_ctxt *)
 Add a cross reference to the meta data. More...
 
tree_cellscript_tag (lex_ctxt *)
 
tree_cellscript_name (lex_ctxt *)
 
tree_cellscript_version (lex_ctxt *)
 
tree_cellscript_copyright (lex_ctxt *)
 
tree_cellscript_category (lex_ctxt *)
 
tree_cellscript_family (lex_ctxt *)
 
tree_cellscript_dependencies (lex_ctxt *)
 
tree_cellscript_require_keys (lex_ctxt *)
 
tree_cellscript_mandatory_keys (lex_ctxt *)
 
tree_cellscript_exclude_keys (lex_ctxt *)
 
tree_cellscript_require_ports (lex_ctxt *)
 
tree_cellscript_require_udp_ports (lex_ctxt *)
 
tree_cellnasl_get_preference (lex_ctxt *)
 
tree_cellscript_add_preference (lex_ctxt *)
 
tree_cellscript_get_preference (lex_ctxt *)
 Get a preferences of the current script. More...
 
tree_cellscript_get_preference_file_content (lex_ctxt *)
 
tree_cellscript_get_preference_file_location (lex_ctxt *)
 
tree_cellsafe_checks (lex_ctxt *)
 
tree_cellscan_phase (lex_ctxt *)
 
tree_cellnetwork_targets (lex_ctxt *)
 
tree_cellget_script_oid (lex_ctxt *)
 Return the OID of the current script. More...
 
tree_cellget_kb_item (lex_ctxt *)
 
tree_cellget_kb_list (lex_ctxt *)
 
tree_cellset_kb_item (lex_ctxt *)
 
tree_cellreplace_kb_item (lex_ctxt *)
 
tree_cellsecurity_message (lex_ctxt *)
 Send a security message to the client. More...
 
tree_celllog_message (lex_ctxt *)
 
tree_cellerror_message (lex_ctxt *)
 
tree_cellnasl_scanner_get_port (lex_ctxt *)
 
tree_cellnasl_scanner_add_port (lex_ctxt *)
 
tree_cellnasl_scanner_status (lex_ctxt *)
 
tree_cellnasl_vendor_version (lex_ctxt *)
 

Function Documentation

◆ error_message()

tree_cell* error_message ( lex_ctxt )

Definition at line 981 of file nasl_scanner_glue.c.

982 {
984 }

References post_error(), proto_post_error(), and security_something().

Here is the call graph for this function:

◆ get_kb_item()

tree_cell* get_kb_item ( lex_ctxt )

Definition at line 766 of file nasl_scanner_glue.c.

767 {
768  struct script_infos *script_infos = lexic->script_infos;
769 
770  char *kb_entry = get_str_var_by_num (lexic, 0);
771  char *val;
772  tree_cell *retc;
773  int type, single = get_int_var_by_num (lexic, 1, 0);
774  size_t len;
775 
776  if (kb_entry == NULL)
777  return NULL;
778 
779  val = plug_get_key (script_infos, kb_entry, &type, &len, !!single);
780 
781  if (val == NULL && type == -1)
782  return NULL;
783 
784  retc = alloc_typed_cell (CONST_INT);
785  if (type == KB_TYPE_INT)
786  {
787  retc->x.i_val = GPOINTER_TO_SIZE (val);
788  g_free (val);
789  return retc;
790  }
791  else
792  {
793  retc->type = CONST_DATA;
794  if (val != NULL)
795  {
796  retc->size = len;
797  retc->x.str_val = val;
798  }
799  else
800  {
801  retc->size = 0;
802  retc->x.str_val = NULL;
803  }
804  }
805 
806  return retc;
807 }

References alloc_typed_cell(), CONST_DATA, CONST_INT, get_int_var_by_num(), get_str_var_by_num(), TC::i_val, plug_get_key(), struct_lex_ctxt::script_infos, TC::size, TC::str_val, TC::type, val, and TC::x.

Here is the call graph for this function:

◆ get_kb_list()

tree_cell* get_kb_list ( lex_ctxt )

Definition at line 705 of file nasl_scanner_glue.c.

706 {
707  struct script_infos *script_infos = lexic->script_infos;
708  kb_t kb = plug_get_kb (script_infos);
709  char *kb_mask = get_str_var_by_num (lexic, 0);
710  tree_cell *retc;
711  int num_elems = 0;
712  nasl_array *a;
713  struct kb_item *res, *top;
714 
715  if (kb_mask == NULL)
716  {
717  nasl_perror (lexic, "get_kb_list() usage : get_kb_list(<NameOfItem>)\n");
718  return NULL;
719  }
720 
721  if (kb == NULL)
722  return NULL;
723 
724  retc = alloc_typed_cell (DYN_ARRAY);
725  retc->x.ref_val = a = g_malloc0 (sizeof (nasl_array));
726 
727  if (strchr (kb_mask, '*'))
728  top = res = kb_item_get_pattern (kb, kb_mask);
729  else
730  top = res = kb_item_get_all (kb, kb_mask);
731 
732  while (res != NULL)
733  {
734  anon_nasl_var v;
735  bzero (&v, sizeof (v));
736 
737  if (res->type == KB_TYPE_INT)
738  {
739  v.var_type = VAR2_INT;
740  v.v.v_int = res->v_int;
741  add_var_to_array (a, res->name, &v);
742  num_elems++;
743  }
744  else if (res->type == KB_TYPE_STR)
745  {
746  v.var_type = VAR2_DATA;
747  v.v.v_str.s_val = (unsigned char *) res->v_str;
748  v.v.v_str.s_siz = strlen (res->v_str);
749  add_var_to_array (a, res->name, &v);
750  num_elems++;
751  }
752  res = res->next;
753  }
754 
755  kb_item_free (top);
756 
757  if (num_elems == 0)
758  {
759  deref_cell (retc);
760  return FAKE_CELL;
761  }
762  return retc;
763 }

References add_var_to_array(), alloc_typed_cell(), deref_cell(), DYN_ARRAY, FAKE_CELL, get_str_var_by_num(), nasl_perror(), plug_get_kb(), TC::ref_val, st_nasl_string::s_siz, st_nasl_string::s_val, struct_lex_ctxt::script_infos, st_a_nasl_var::v, st_a_nasl_var::v_int, st_a_nasl_var::v_str, VAR2_DATA, VAR2_INT, st_a_nasl_var::var_type, and TC::x.

Here is the call graph for this function:

◆ get_script_oid()

tree_cell* get_script_oid ( lex_ctxt lexic)

Return the OID of the current script.

Parameters
[in]lexicNASL lexer.
Returns
lex cell containing the OID as a string.

Definition at line 687 of file nasl_scanner_glue.c.

688 {
689  const char *oid = lexic->oid;
690  tree_cell *retc = NULL;
691 
692  if (oid)
693  {
694  retc = alloc_typed_cell (CONST_DATA);
695  retc->x.str_val = g_strdup (oid);
696  retc->size = strlen (oid);
697  }
698 
699  return retc;
700 }

References alloc_typed_cell(), CONST_DATA, struct_lex_ctxt::oid, oid, TC::size, TC::str_val, and TC::x.

Here is the call graph for this function:

◆ log_message()

tree_cell* log_message ( lex_ctxt )

Definition at line 975 of file nasl_scanner_glue.c.

976 {
977  return security_something (lexic, proto_post_log, post_log);
978 }

References post_log(), proto_post_log(), and security_something().

Here is the call graph for this function:

◆ nasl_get_preference()

tree_cell* nasl_get_preference ( lex_ctxt )

Definition at line 987 of file nasl_scanner_glue.c.

988 {
989  tree_cell *retc;
990  char *name;
991  const char *value;
992 
993  name = get_str_var_by_num (lexic, 0);
994  if (name == NULL)
995  {
996  nasl_perror (lexic, "get_preference: no name\n");
997  return NULL;
998  }
999  value = prefs_get (name);
1000  if (value == NULL)
1001  return NULL;
1002 
1003  retc = alloc_typed_cell (CONST_DATA);
1004  retc->x.str_val = strdup (value);
1005  retc->size = strlen (value);
1006  return retc;
1007 }

References alloc_typed_cell(), CONST_DATA, get_str_var_by_num(), name, nasl_perror(), TC::size, TC::str_val, and TC::x.

Here is the call graph for this function:

◆ nasl_scanner_add_port()

tree_cell* nasl_scanner_add_port ( lex_ctxt )

Definition at line 1071 of file nasl_scanner_glue.c.

1072 {
1073  struct script_infos *script_infos = lexic->script_infos;
1074 
1075  int port = get_int_var_by_name (lexic, "port", -1);
1076  char *proto = get_str_var_by_name (lexic, "proto");
1077 
1078  if (port >= 0)
1079  {
1080  scanner_add_port (script_infos, port, proto ? proto : "tcp");
1081  }
1082 
1083  return FAKE_CELL;
1084 }

References FAKE_CELL, get_int_var_by_name(), get_str_var_by_name(), scanner_add_port(), and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ nasl_scanner_get_port()

tree_cell* nasl_scanner_get_port ( lex_ctxt lexic)

If the plugin is a port scanner, it needs to report the list of open ports back to openvas scanner, and it also needs to know which ports are to be scanned.

Definition at line 1031 of file nasl_scanner_glue.c.

1032 {
1033  tree_cell *retc;
1034  int idx = get_int_var_by_num (lexic, 0, -1);
1035  const char *prange = prefs_get ("port_range");
1036  static int num = 0;
1037  static u_short *ports = NULL;
1038 
1039  if (prange == NULL)
1040  return NULL;
1041 
1042  if (idx < 0)
1043  {
1044  nasl_perror (lexic, "Argument error in scanner_get_port()\n");
1045  nasl_perror (lexic, "Correct usage is : num = scanner_get_port(<num>)\n");
1046  nasl_perror (lexic,
1047  "Where <num> should be 0 the first time you call it\n");
1048  return NULL;
1049  }
1050 
1051  if (ports == NULL)
1052  {
1053  ports = (u_short *) getpts ((char *) prange, &num);
1054  if (ports == NULL)
1055  {
1056  return NULL;
1057  }
1058  }
1059 
1060  if (idx >= num)
1061  {
1062  return NULL;
1063  }
1064 
1065  retc = alloc_typed_cell (CONST_INT);
1066  retc->x.i_val = ports[idx];
1067  return retc;
1068 }

References alloc_typed_cell(), CONST_INT, get_int_var_by_num(), getpts(), TC::i_val, nasl_perror(), and TC::x.

Here is the call graph for this function:

◆ nasl_scanner_status()

tree_cell* nasl_scanner_status ( lex_ctxt )

Definition at line 1087 of file nasl_scanner_glue.c.

1088 {
1089  /* Kept for backward compatibility. */
1090  (void) lexic;
1091  return FAKE_CELL;
1092 }

References FAKE_CELL.

◆ nasl_vendor_version()

tree_cell* nasl_vendor_version ( lex_ctxt )

Definition at line 1010 of file nasl_scanner_glue.c.

1011 {
1012  tree_cell *retc;
1013  gchar *version = g_strdup (vendor_version_get ());
1014  (void) lexic;
1015  retc = alloc_typed_cell (CONST_DATA);
1016  retc->x.str_val = strdup (version);
1017  retc->size = strlen (version);
1018  g_free (version);
1019 
1020  return retc;
1021 }

References alloc_typed_cell(), CONST_DATA, TC::size, TC::str_val, vendor_version_get(), and TC::x.

Here is the call graph for this function:

◆ network_targets()

tree_cell* network_targets ( lex_ctxt )

Definition at line 659 of file nasl_scanner_glue.c.

660 {
661  struct script_infos *script_infos = lexic->script_infos;
662  struct scan_globals *globals = script_infos->globals;
663  char *value;
664  tree_cell *retc;
665 
666  value = globals->network_targets;
667  retc = alloc_typed_cell (CONST_DATA);
668  if (value)
669  {
670  retc->x.str_val = strdup (value);
671  retc->size = strlen (value);
672  }
673  else
674  return NULL;
675 
676  return retc;
677 }

References alloc_typed_cell(), CONST_DATA, script_infos::globals, scan_globals::network_targets, struct_lex_ctxt::script_infos, TC::size, TC::str_val, and TC::x.

Referenced by attack_network().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ replace_kb_item()

tree_cell* replace_kb_item ( lex_ctxt )

Definition at line 810 of file nasl_scanner_glue.c.

811 {
812  struct script_infos *script_infos = lexic->script_infos;
813  char *name = get_str_var_by_name (lexic, "name");
814  int type = get_var_type_by_name (lexic, "value");
815 
816  if (name == NULL)
817  {
818  nasl_perror (lexic, "Syntax error with replace_kb_item() [null name]\n",
819  name);
820  return FAKE_CELL;
821  }
822 
823  if (type == VAR2_INT)
824  {
825  int value = get_int_var_by_name (lexic, "value", -1);
826  if (value != -1)
828  GSIZE_TO_POINTER (value));
829  else
830  nasl_perror (
831  lexic, "Syntax error with replace_kb_item(%s) [value=-1]\n", name);
832  }
833  else
834  {
835  char *value = get_str_var_by_name (lexic, "value");
836  int len = get_var_size_by_name (lexic, "value");
837 
838  if (value == NULL)
839  {
840  nasl_perror (lexic,
841  "Syntax error with replace_kb_item(%s) [null value]\n",
842  name);
843  return FAKE_CELL;
844  }
846  }
847 
848  return FAKE_CELL;
849 }

References ARG_INT, ARG_STRING, FAKE_CELL, get_int_var_by_name(), get_str_var_by_name(), get_var_size_by_name(), get_var_type_by_name(), name, nasl_perror(), plug_replace_key(), plug_replace_key_len(), struct_lex_ctxt::script_infos, and VAR2_INT.

Here is the call graph for this function:

◆ safe_checks()

tree_cell* safe_checks ( lex_ctxt )

Definition at line 626 of file nasl_scanner_glue.c.

627 {
628  (void) lexic;
630 
631  retc->x.i_val = prefs_get_bool ("safe_checks");
632 
633  return retc;
634 }

References alloc_typed_cell(), CONST_INT, TC::i_val, and TC::x.

Referenced by plugin_run_openvas_tcp_scanner().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scan_phase()

tree_cell* scan_phase ( lex_ctxt )

Definition at line 637 of file nasl_scanner_glue.c.

638 {
639  struct script_infos *script_infos = lexic->script_infos;
640  struct scan_globals *globals = script_infos->globals;
641  char *value;
643 
644  value = globals->network_scan_status;
645  if (value)
646  {
647  if (strcmp (value, "busy") == 0)
648  retc->x.i_val = 1;
649  else
650  retc->x.i_val = 2;
651  }
652  else
653  retc->x.i_val = 0;
654 
655  return retc;
656 }

References alloc_typed_cell(), CONST_INT, script_infos::globals, TC::i_val, scan_globals::network_scan_status, struct_lex_ctxt::script_infos, and TC::x.

Here is the call graph for this function:

◆ script_add_preference()

tree_cell* script_add_preference ( lex_ctxt )

Definition at line 449 of file nasl_scanner_glue.c.

450 {
451  int id = get_int_var_by_name (lexic, "id", -1);
452  char *name = get_str_var_by_name (lexic, "name");
453  char *type = get_str_var_by_name (lexic, "type");
454  char *value = get_str_var_by_name (lexic, "value");
455  struct script_infos *script_infos = lexic->script_infos;
456  nvtpref_t *np;
457  unsigned int i;
458 
459  if (!script_infos->nvti)
460  return FAKE_CELL;
461  if (id < 0)
462  id = nvti_pref_len (script_infos->nvti) + 1;
463  if (id == 0)
464  {
465  nasl_perror (lexic,
466  "Invalid id or not allowed id value in the call to %s()\n",
467  __func__);
468  return FAKE_CELL;
469  }
470  if (!name || !type || !value)
471  {
472  nasl_perror (lexic,
473  "Argument error in the call to script_add_preference()\n");
474  return FAKE_CELL;
475  }
476  for (i = 0; i < nvti_pref_len (script_infos->nvti); i++)
477  {
478  if (!strcmp (name, nvtpref_name (nvti_pref (script_infos->nvti, i))))
479  {
480  nasl_perror (lexic, "Preference '%s' already exists\n", name);
481  return FAKE_CELL;
482  }
483  if (id == nvtpref_id (nvti_pref (script_infos->nvti, i)))
484  {
485  nasl_perror (lexic, "Invalid or already existent preference id\n");
486  return FAKE_CELL;
487  }
488  }
489 
490  np = nvtpref_new (id, name, type, value);
491  nvti_add_pref (script_infos->nvti, np);
492  return FAKE_CELL;
493 }

References FAKE_CELL, get_int_var_by_name(), get_str_var_by_name(), name, nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_bugtraq_id()

tree_cell* script_bugtraq_id ( lex_ctxt )

Definition at line 122 of file nasl_scanner_glue.c.

123 {
124  struct script_infos *script_infos = lexic->script_infos;
125  char *bid = get_str_var_by_num (lexic, 0);
126  int i;
127 
128  for (i = 0; bid != NULL; i++)
129  {
130  nvti_add_vtref (script_infos->nvti, vtref_new ("bid", bid, ""));
131  bid = get_str_var_by_num (lexic, i + 1);
132  }
133 
134  return FAKE_CELL;
135 }

References FAKE_CELL, get_str_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_category()

tree_cell* script_category ( lex_ctxt )

Definition at line 271 of file nasl_scanner_glue.c.

272 {
273  struct script_infos *script_infos = lexic->script_infos;
274 
275  int category = get_int_var_by_num (lexic, 0, -1);
276 
277  if (category < 0)
278  {
279  nasl_perror (lexic, "Argument error in function script_category()\n");
280  nasl_perror (lexic, "Function usage is : script_category(<category>)\n");
281  return FAKE_CELL;
282  }
283  nvti_set_category (script_infos->nvti, category);
284  return FAKE_CELL;
285 }

References FAKE_CELL, get_int_var_by_num(), nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_copyright()

tree_cell* script_copyright ( lex_ctxt )

Definition at line 264 of file nasl_scanner_glue.c.

265 {
266  (void) lexic;
267  return FAKE_CELL;
268 }

References FAKE_CELL.

◆ script_cve_id()

tree_cell* script_cve_id ( lex_ctxt )

Definition at line 106 of file nasl_scanner_glue.c.

107 {
108  struct script_infos *script_infos = lexic->script_infos;
109  char *cve = get_str_var_by_num (lexic, 0);
110  int i;
111 
112  for (i = 0; cve != NULL; i++)
113  {
114  nvti_add_vtref (script_infos->nvti, vtref_new ("cve", cve, ""));
115  cve = get_str_var_by_num (lexic, i + 1);
116  }
117 
118  return FAKE_CELL;
119 }

References FAKE_CELL, get_str_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_dependencies()

tree_cell* script_dependencies ( lex_ctxt )

Definition at line 295 of file nasl_scanner_glue.c.

296 {
297  struct script_infos *script_infos = lexic->script_infos;
298  char *dep = get_str_var_by_num (lexic, 0);
299  int i;
300 
301  if (dep == NULL)
302  {
303  nasl_perror (lexic, "Argument error in function script_dependencies()\n");
304  nasl_perror (lexic, "Function usage is : script_dependencies(<name>)\n");
305  nasl_perror (lexic, "Where <name> is the name of another script\n");
306 
307  return FAKE_CELL;
308  }
309 
310  for (i = 0; dep != NULL; i++)
311  {
312  dep = get_str_var_by_num (lexic, i);
313  if (dep != NULL)
314  plug_set_dep (script_infos, dep);
315  }
316 
317  return FAKE_CELL;
318 }

References FAKE_CELL, get_str_var_by_num(), nasl_perror(), plug_set_dep(), and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_exclude_keys()

tree_cell* script_exclude_keys ( lex_ctxt )

Definition at line 390 of file nasl_scanner_glue.c.

391 {
392  char *keys = get_str_var_by_num (lexic, 0);
393  int i;
394 
395  if (keys == NULL)
396  {
397  nasl_perror (lexic, "Argument error in function script_exclude_keys()\n");
398  nasl_perror (lexic, "Function usage is : script_exclude_keys(<name>)\n");
399  nasl_perror (lexic, "Where <name> is the name of a key\n");
400  return FAKE_CELL;
401  }
402 
403  for (i = 0; keys != NULL; i++)
404  {
405  keys = get_str_var_by_num (lexic, i);
406  nvti_add_excluded_keys (lexic->script_infos->nvti, keys);
407  }
408 
409  return FAKE_CELL;
410 }

References FAKE_CELL, get_str_var_by_num(), nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_family()

tree_cell* script_family ( lex_ctxt )

Definition at line 288 of file nasl_scanner_glue.c.

289 {
290  nvti_set_family (lexic->script_infos->nvti, get_str_var_by_num (lexic, 0));
291  return FAKE_CELL;
292 }

References FAKE_CELL, get_str_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_get_preference()

tree_cell* script_get_preference ( lex_ctxt lexic)

Get a preferences of the current script.

Search the preference by preference name or by preferences id.

Parameters
[in]lexicNASL lexer.
Returns
lex cell containing the preferences value as a string. Fake cell otherwise

Definition at line 506 of file nasl_scanner_glue.c.

507 {
508  tree_cell *retc;
509  int id = get_int_var_by_name (lexic, "id", -1);
510  char *pref = get_str_var_by_num (lexic, 0);
511  char *value;
512 
513  if (pref == NULL && id == -1)
514  {
515  nasl_perror (lexic,
516  "Argument error in the function script_get_preference()\n");
517  nasl_perror (lexic,
518  "Function usage is : pref = script_get_preference(<name>, "
519  "id:<id>)\n");
520  return FAKE_CELL;
521  }
522 
523  value = get_plugin_preference (lexic->oid, pref, id);
524  if (value != NULL)
525  {
526  retc = alloc_typed_cell (CONST_INT);
527  if (isalldigit (value, strlen (value)))
528  retc->x.i_val = atoi (value);
529  else
530  {
531  retc->type = CONST_DATA;
532  retc->size = strlen (value);
533  retc->x.str_val = g_strdup (value);
534  }
535  g_free (value);
536  return retc;
537  }
538  else
539  return FAKE_CELL;
540 }

References alloc_typed_cell(), CONST_DATA, CONST_INT, FAKE_CELL, get_int_var_by_name(), get_plugin_preference(), get_str_var_by_num(), TC::i_val, isalldigit(), nasl_perror(), struct_lex_ctxt::oid, TC::size, TC::str_val, TC::type, and TC::x.

Here is the call graph for this function:

◆ script_get_preference_file_content()

tree_cell* script_get_preference_file_content ( lex_ctxt )

Definition at line 543 of file nasl_scanner_glue.c.

544 {
545  struct script_infos *script_infos = lexic->script_infos;
546  tree_cell *retc;
547  char *pref = get_str_var_by_num (lexic, 0);
548  char *value;
549  char *content;
550  int contentsize = 0;
551 
552  if (pref == NULL)
553  {
554  nasl_perror (lexic,
555  "Argument error in the function script_get_preference()\n");
556  nasl_perror (lexic, "Function usage is : pref = "
557  "script_get_preference_file_content(<name>)\n");
558  return NULL;
559  }
560 
561  value = get_plugin_preference (lexic->oid, pref, -1);
562  if (value == NULL)
563  return NULL;
564 
566  contentsize = get_plugin_preference_file_size (script_infos, value);
567  g_free (value);
568  if (content == NULL)
569  return FAKE_CELL;
570  if (contentsize <= 0)
571  {
572  nasl_perror (lexic,
573  "script_get_preference_file_content: could not get "
574  " size of file from preference %s\n",
575  pref);
576  return NULL;
577  }
578 
579  retc = alloc_typed_cell (CONST_DATA);
580  retc->size = contentsize;
581  retc->x.str_val = content;
582 
583  return retc;
584 }

References alloc_typed_cell(), CONST_DATA, FAKE_CELL, get_plugin_preference(), get_plugin_preference_file_content(), get_plugin_preference_file_size(), get_str_var_by_num(), nasl_perror(), struct_lex_ctxt::oid, struct_lex_ctxt::script_infos, TC::size, TC::str_val, and TC::x.

Here is the call graph for this function:

◆ script_get_preference_file_location()

tree_cell* script_get_preference_file_location ( lex_ctxt )

Definition at line 587 of file nasl_scanner_glue.c.

588 {
589  struct script_infos *script_infos = lexic->script_infos;
590  tree_cell *retc;
591  char *pref = get_str_var_by_num (lexic, 0);
592  const char *value, *local;
593  int len;
594 
595  if (pref == NULL)
596  {
597  nasl_perror (
598  lexic, "script_get_preference_file_location: no preference name!\n");
599  return NULL;
600  }
601 
602  value = get_plugin_preference (lexic->oid, pref, -1);
603  if (value == NULL)
604  {
605  nasl_perror (
606  lexic,
607  "script_get_preference_file_location: could not get preference %s\n",
608  pref);
609  return NULL;
610  }
611  local = get_plugin_preference_fname (script_infos, value);
612  if (local == NULL)
613  return NULL;
614 
615  len = strlen (local);
616  retc = alloc_typed_cell (CONST_DATA);
617  retc->size = len;
618  retc->x.str_val = g_malloc0 (len + 1);
619  memcpy (retc->x.str_val, local, len + 1);
620 
621  return retc;
622 }

References alloc_typed_cell(), CONST_DATA, get_plugin_preference(), get_plugin_preference_fname(), get_str_var_by_num(), nasl_perror(), struct_lex_ctxt::oid, struct_lex_ctxt::script_infos, TC::size, TC::str_val, and TC::x.

Here is the call graph for this function:

◆ script_mandatory_keys()

tree_cell* script_mandatory_keys ( lex_ctxt )

Definition at line 344 of file nasl_scanner_glue.c.

345 {
346  char *keys = get_str_var_by_num (lexic, 0);
347  char **splits = NULL, *re = get_str_var_by_name (lexic, "re");
348  int i;
349 
350  if (keys == NULL)
351  {
352  nasl_perror (lexic,
353  "Argument error in function script_mandatory_keys()\n");
354  nasl_perror (lexic,
355  "Function usage is : script_mandatory_keys(<name>)\n");
356  nasl_perror (lexic, "Where <name> is the name of a key\n");
357  return FAKE_CELL;
358  }
359 
360  if (re)
361  {
362  splits = g_strsplit (re, "=", 0);
363 
364  if (!splits[0] || !splits[1] || !*splits[1] || splits[2])
365  {
366  nasl_perror (lexic, "Erroneous re argument");
367  return FAKE_CELL;
368  }
369  }
370  for (i = 0; keys != NULL; i++)
371  {
372  keys = get_str_var_by_num (lexic, i);
373 
374  if (splits && keys && !strcmp (keys, splits[0]))
375  {
376  nvti_add_mandatory_keys (lexic->script_infos->nvti, re);
377  re = NULL;
378  }
379  else
380  nvti_add_mandatory_keys (lexic->script_infos->nvti, keys);
381  }
382  if (re)
383  nvti_add_mandatory_keys (lexic->script_infos->nvti, re);
384 
385  g_strfreev (splits);
386  return FAKE_CELL;
387 }

References FAKE_CELL, get_str_var_by_name(), get_str_var_by_num(), nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_name()

tree_cell* script_name ( lex_ctxt )

Definition at line 250 of file nasl_scanner_glue.c.

251 {
252  nvti_set_name (lexic->script_infos->nvti, get_str_var_by_num (lexic, 0));
253  return FAKE_CELL;
254 }

References FAKE_CELL, get_str_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Referenced by nasl_perror(), and nasl_trace().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ script_oid()

tree_cell* script_oid ( lex_ctxt )

Definition at line 99 of file nasl_scanner_glue.c.

100 {
101  nvti_set_oid (lexic->script_infos->nvti, get_str_var_by_num (lexic, 0));
102  return FAKE_CELL;
103 }

References FAKE_CELL, get_str_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_require_keys()

tree_cell* script_require_keys ( lex_ctxt )

Definition at line 321 of file nasl_scanner_glue.c.

322 {
323  char *keys = get_str_var_by_num (lexic, 0);
324  int i;
325 
326  if (keys == NULL)
327  {
328  nasl_perror (lexic, "Argument error in function script_require_keys()\n");
329  nasl_perror (lexic, "Function usage is : script_require_keys(<name>)\n");
330  nasl_perror (lexic, "Where <name> is the name of a key\n");
331  return FAKE_CELL;
332  }
333 
334  for (i = 0; keys != NULL; i++)
335  {
336  keys = get_str_var_by_num (lexic, i);
337  nvti_add_required_keys (lexic->script_infos->nvti, keys);
338  }
339 
340  return FAKE_CELL;
341 }

References FAKE_CELL, get_str_var_by_num(), nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_require_ports()

tree_cell* script_require_ports ( lex_ctxt )

Definition at line 413 of file nasl_scanner_glue.c.

414 {
415  char *port;
416  int i;
417 
418  for (i = 0;; i++)
419  {
420  port = get_str_var_by_num (lexic, i);
421  if (port != NULL)
422  nvti_add_required_ports (lexic->script_infos->nvti, port);
423  else
424  break;
425  }
426 
427  return FAKE_CELL;
428 }

References FAKE_CELL, get_str_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_require_udp_ports()

tree_cell* script_require_udp_ports ( lex_ctxt )

Definition at line 431 of file nasl_scanner_glue.c.

432 {
433  int i;
434  char *port;
435 
436  for (i = 0;; i++)
437  {
438  port = get_str_var_by_num (lexic, i);
439  if (port != NULL)
440  nvti_add_required_udp_ports (lexic->script_infos->nvti, port);
441  else
442  break;
443  }
444 
445  return FAKE_CELL;
446 }

References FAKE_CELL, get_str_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_tag()

tree_cell* script_tag ( lex_ctxt )

Definition at line 210 of file nasl_scanner_glue.c.

211 {
212  struct script_infos *script_infos = lexic->script_infos;
213  char *name = get_str_var_by_name (lexic, "name");
214  char *value = get_str_var_by_name (lexic, "value");
215 
216  if (value == NULL || name == NULL)
217  {
218  nasl_perror (lexic, "script_tag() syntax error - should be"
219  " script_tag(name:<name>, value:<value>)\n");
220  if (name == NULL)
221  {
222  nasl_perror (lexic, " <name> is empty\n");
223  }
224  else
225  {
226  nasl_perror (lexic, " <name> is %s\n", name);
227  }
228  if (value == NULL)
229  {
230  nasl_perror (lexic, " <value> is empty)\n");
231  }
232  else
233  {
234  nasl_perror (lexic, " <value> is %s\n)", value);
235  }
236  return FAKE_CELL;
237  }
238 
239  if (strchr (value, '|'))
240  {
241  nasl_perror (lexic, "%s tag contains | separator", name);
242  return FAKE_CELL;
243  }
244  nvti_add_tag (script_infos->nvti, name, value);
245 
246  return FAKE_CELL;
247 }

References FAKE_CELL, get_str_var_by_name(), name, nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_timeout()

tree_cell* script_timeout ( lex_ctxt )

Definition at line 86 of file nasl_scanner_glue.c.

87 {
88  nvti_t *nvti = lexic->script_infos->nvti;
89  int to = get_int_var_by_num (lexic, 0, -65535);
90 
91  if (to == -65535)
92  return FAKE_CELL;
93 
94  nvti_set_timeout (nvti, to ? to : -1);
95  return FAKE_CELL;
96 }

References FAKE_CELL, get_int_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_version()

tree_cell* script_version ( lex_ctxt )

Definition at line 257 of file nasl_scanner_glue.c.

258 {
259  (void) lexic;
260  return FAKE_CELL;
261 }

References FAKE_CELL.

◆ script_xref()

tree_cell* script_xref ( lex_ctxt lexic)

Add a cross reference to the meta data.

The parameter "name" of the command defines actually the type, for example "URL" or "OSVDB". The parameter "value" is the actual reference. Alternative to "value", "csv" can be used with a list of comma-separated values.

In fact, if name is "cve" or "bid", it is equivalent to call script_cve_id() or script_bugtraq_id(), for example script_cve_id ("CVE-2019-12345"); is identical to script_xref (name: "cve", value: "CVE-2019-12345");

And also: script_bugtraq_id (12345); is identical to script_xref (name: "bid", value: "12345"); (watch out that the number now needs to be a string).

This even works with multiple comma-separated elements like script_xref (name: "cve", csv: "CVE-2019-12345,CVE-2019-54321");

Parameters
lexicThe parser context.
Returns
Always FAKE_CELL.

Definition at line 166 of file nasl_scanner_glue.c.

167 {
168  struct script_infos *script_infos = lexic->script_infos;
169  char *name = get_str_var_by_name (lexic, "name");
170  char *value = get_str_var_by_name (lexic, "value");
171  char *csv = get_str_var_by_name (lexic, "csv");
172 
173  if (((value == NULL) && (csv == NULL)) || name == NULL)
174  {
175  nasl_perror (lexic,
176  "script_xref() syntax error - should be"
177  " script_xref(name:<name>, value:<value>) or"
178  " script_xref(name:<name>, value:<value>, csv:<CSVs>) or"
179  " script_xref(name:<name>, csv:<CSVs>)\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) && (csv == NULL))
189  {
190  nasl_perror (lexic, " <value> and <csv> is empty)\n");
191  }
192  else
193  {
194  nasl_perror (lexic, " <value> is %s\n)", value);
195  nasl_perror (lexic, " <csv> is %s\n)", csv);
196  }
197  return FAKE_CELL;
198  }
199 
200  if (csv)
201  nvti_add_refs (script_infos->nvti, name, csv, "");
202 
203  if (value)
204  nvti_add_vtref (script_infos->nvti, vtref_new (name, value, ""));
205 
206  return FAKE_CELL;
207 }

References FAKE_CELL, get_str_var_by_name(), name, nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ security_message()

tree_cell* security_message ( lex_ctxt lexic)

Send a security message to the client.

Parameters
[in]lexicNASL lexer.
Returns
FAKE_CELL.

Definition at line 969 of file nasl_scanner_glue.c.

970 {
972 }

References post_alarm(), proto_post_alarm(), and security_something().

Here is the call graph for this function:

◆ set_kb_item()

tree_cell* set_kb_item ( lex_ctxt )

Definition at line 852 of file nasl_scanner_glue.c.

853 {
854  struct script_infos *script_infos = lexic->script_infos;
855  char *name = get_str_var_by_name (lexic, "name");
856  int type = get_var_type_by_name (lexic, "value");
857 
858  if (name == NULL)
859  {
860  nasl_perror (lexic, "Syntax error with set_kb_item() [null name]\n",
861  name);
862  return FAKE_CELL;
863  }
864 
865  if (type == VAR2_INT)
866  {
867  int value = get_int_var_by_name (lexic, "value", -1);
868  if (value != -1)
869  plug_set_key (script_infos, name, ARG_INT, GSIZE_TO_POINTER (value));
870  else
871  nasl_perror (
872  lexic, "Syntax error with set_kb_item() [value=-1 for name '%s']\n",
873  name);
874  }
875  else
876  {
877  char *value = get_str_var_by_name (lexic, "value");
878  int len = get_var_size_by_name (lexic, "value");
879  if (value == NULL)
880  {
881  nasl_perror (
882  lexic,
883  "Syntax error with set_kb_item() [null value for name '%s']\n",
884  name);
885  return FAKE_CELL;
886  }
888  }
889 
890  return FAKE_CELL;
891 }

References ARG_INT, ARG_STRING, FAKE_CELL, get_int_var_by_name(), get_str_var_by_name(), get_var_size_by_name(), get_var_type_by_name(), name, nasl_perror(), plug_set_key(), plug_set_key_len(), struct_lex_ctxt::script_infos, and VAR2_INT.

Here is the call graph for this function:
st_a_nasl_var
Definition: nasl_var.h:50
scan_globals::network_targets
char * network_targets
Definition: scanneraux.h:34
plug_set_dep
void plug_set_dep(struct script_infos *args, const char *depname)
Definition: plugutils.c:65
script_infos
Definition: scanneraux.h:43
CONST_DATA
@ CONST_DATA
Definition: nasl_tree.h:93
plug_replace_key
void plug_replace_key(struct script_infos *args, char *name, int type, void *value)
Definition: plugutils.c:646
vendor_version_get
const gchar * vendor_version_get()
Get vendor version.
Definition: vendorversion.c:52
post_alarm
void post_alarm(const char *oid, struct script_infos *desc, int port, const char *action)
Definition: plugutils.c:355
plug_get_key
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:730
get_var_size_by_name
int get_var_size_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1147
plug_get_kb
kb_t plug_get_kb(struct script_infos *args)
Definition: plugutils.c:658
TC::str_val
char * str_val
Definition: nasl_tree.h:112
isalldigit
static int isalldigit(char *str, int len)
Definition: nasl_scanner_glue.c:61
script_infos::nvti
nvti_t * nvti
Definition: scanneraux.h:47
DYN_ARRAY
@ DYN_ARRAY
Definition: nasl_tree.h:101
FAKE_CELL
#define FAKE_CELL
Definition: nasl_tree.h:119
post_error
void post_error(const char *oid, struct script_infos *desc, int port, const char *action)
Definition: plugutils.c:389
TC::x
union TC::@2 x
get_str_var_by_name
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1127
st_a_nasl_var::v_str
nasl_string_t v_str
Definition: nasl_var.h:58
proto_post_error
void proto_post_error(const char *oid, struct script_infos *desc, int port, const char *proto, const char *action)
Definition: plugutils.c:382
get_plugin_preference_file_content
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:541
plug_replace_key_len
void plug_replace_key_len(struct script_infos *args, char *name, int type, void *value, size_t len)
Definition: plugutils.c:623
post_log
void post_log(const char *oid, struct script_infos *desc, int port, const char *action)
Post a log message about a tcp port.
Definition: plugutils.c:375
st_nasl_string::s_siz
int s_siz
Definition: nasl_var.h:38
name
const char * name
Definition: nasl_init.c:377
st_nasl_array
Definition: nasl_var.h:43
plug_set_key_len
void plug_set_key_len(struct script_infos *args, char *name, int type, const void *value, size_t len)
Definition: plugutils.c:594
oid
const char * oid
Definition: nasl_builtin_find_service.c:57
getpts
unsigned short * getpts(char *origexpr, int *len)
Converts a string like "-100,200-1024,3000-4000,60000-" into an array.
Definition: network.c:2103
script_infos::globals
struct scan_globals * globals
Definition: scanneraux.h:45
nasl_perror
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:120
get_var_type_by_name
int get_var_type_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1171
add_var_to_array
int add_var_to_array(nasl_array *a, char *name, const anon_nasl_var *v)
Definition: nasl_var.c:1286
TC::size
int size
Definition: nasl_tree.h:109
get_plugin_preference
char * get_plugin_preference(const char *oid, const char *name, int pref_id)
Get the a plugins preference.
Definition: plugutils.c:408
struct_lex_ctxt::oid
const char * oid
Definition: nasl_lex_ctxt.h:42
get_int_var_by_name
long int get_int_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1113
VAR2_DATA
@ VAR2_DATA
Definition: nasl_var.h:29
scanner_add_port
void scanner_add_port(struct script_infos *args, int port, char *proto)
Definition: plugutils.c:652
TC::ref_val
void * ref_val
Definition: nasl_tree.h:114
get_int_var_by_num
long int get_int_var_by_num(lex_ctxt *, int, int)
Definition: nasl_var.c:1106
scan_globals
Definition: scanneraux.h:32
get_str_var_by_num
char * get_str_var_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1120
st_a_nasl_var::var_type
int var_type
Definition: nasl_var.h:52
struct_lex_ctxt::script_infos
struct script_infos * script_infos
Definition: nasl_lex_ctxt.h:41
TC
Definition: nasl_tree.h:104
TC::type
short type
Definition: nasl_tree.h:106
scan_globals::network_scan_status
char * network_scan_status
Definition: scanneraux.h:35
get_plugin_preference_fname
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:486
ARG_INT
#define ARG_INT
Definition: plugutils.h:34
CONST_INT
@ CONST_INT
Definition: nasl_tree.h:90
val
const char * val
Definition: nasl_init.c:378
st_a_nasl_var::v
union st_a_nasl_var::@4 v
plug_set_key
void plug_set_key(struct script_infos *args, char *name, int type, const void *value)
Definition: plugutils.c:616
st_a_nasl_var::v_int
long int v_int
Definition: nasl_var.h:59
get_plugin_preference_file_size
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:572
deref_cell
void deref_cell(tree_cell *c)
Definition: nasl_tree.c:192
alloc_typed_cell
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:40
VAR2_INT
@ VAR2_INT
Definition: nasl_var.h:27
ARG_STRING
#define ARG_STRING
Definition: plugutils.h:33
proto_post_log
void proto_post_log(const char *oid, struct script_infos *desc, int port, const char *proto, const char *action)
Post a log message.
Definition: plugutils.c:365
security_something
static tree_cell * security_something(lex_ctxt *lexic, proto_post_something_t proto_post_func, post_something_t post_func)
Definition: nasl_scanner_glue.c:907
proto_post_alarm
void proto_post_alarm(const char *oid, struct script_infos *desc, int port, const char *proto, const char *action)
Definition: plugutils.c:348
st_nasl_string::s_val
unsigned char * s_val
Definition: nasl_var.h:37
TC::i_val
long int i_val
Definition: nasl_tree.h:113