OpenVAS Scanner  7.0.0~git
nasl_scanner_glue.c File Reference

glue between openvas and nasl scripts. More...

#include "nasl_scanner_glue.h"
#include "../misc/network.h"
#include "../misc/plugutils.h"
#include "../misc/vendorversion.h"
#include "nasl_debug.h"
#include "nasl_func.h"
#include "nasl_global_ctxt.h"
#include "nasl_lex_ctxt.h"
#include "nasl_tree.h"
#include "nasl_var.h"
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <glib.h>
#include <gvm/base/logging.h>
#include <gvm/base/prefs.h>
#include <gvm/util/kb.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
Include dependency graph for nasl_scanner_glue.c:

Go to the source code of this file.

Macros

#define G_LOG_DOMAIN   "lib nasl"
 GLib logging domain. More...
 

Typedefs

typedef void(* proto_post_something_t) (const char *, struct script_infos *, int, const char *, const char *)
 
typedef void(* post_something_t) (const char *, struct script_infos *, int, const char *)
 

Functions

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

Detailed Description

glue between openvas and nasl scripts.

This file contains all the functions that make the "glue" between as NASL script and openvas. (script_*(), kb(), scanner_*())

Definition in file nasl_scanner_glue.c.

Macro Definition Documentation

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "lib nasl"

GLib logging domain.

Definition at line 56 of file nasl_scanner_glue.c.

Typedef Documentation

◆ post_something_t

typedef void(* post_something_t) (const char *, struct script_infos *, int, const char *)

Function is used when the script wants to report a problem back to openvas.

Definition at line 879 of file nasl_scanner_glue.c.

◆ proto_post_something_t

typedef void(* proto_post_something_t) (const char *, struct script_infos *, int, const char *, const char *)

Function is used when the script wants to report a problem back to openvas.

Definition at line 874 of file nasl_scanner_glue.c.

Function Documentation

◆ error_message()

tree_cell* error_message ( lex_ctxt lexic)

Definition at line 957 of file nasl_scanner_glue.c.

958 {
960 }

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 lexic)

Definition at line 742 of file nasl_scanner_glue.c.

743 {
744  struct script_infos *script_infos = lexic->script_infos;
745 
746  char *kb_entry = get_str_var_by_num (lexic, 0);
747  char *val;
748  tree_cell *retc;
749  int type, single = get_int_var_by_num (lexic, 1, 0);
750  size_t len;
751 
752  if (kb_entry == NULL)
753  return NULL;
754 
755  val = plug_get_key (script_infos, kb_entry, &type, &len, !!single);
756 
757  if (val == NULL && type == -1)
758  return NULL;
759 
760  retc = alloc_typed_cell (CONST_INT);
761  if (type == KB_TYPE_INT)
762  {
763  retc->x.i_val = GPOINTER_TO_SIZE (val);
764  g_free (val);
765  return retc;
766  }
767  else
768  {
769  retc->type = CONST_DATA;
770  if (val != NULL)
771  {
772  retc->size = len;
773  retc->x.str_val = val;
774  }
775  else
776  {
777  retc->size = 0;
778  retc->x.str_val = NULL;
779  }
780  }
781 
782  return retc;
783 }

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 lexic)

Definition at line 681 of file nasl_scanner_glue.c.

682 {
683  struct script_infos *script_infos = lexic->script_infos;
684  kb_t kb = plug_get_kb (script_infos);
685  char *kb_mask = get_str_var_by_num (lexic, 0);
686  tree_cell *retc;
687  int num_elems = 0;
688  nasl_array *a;
689  struct kb_item *res, *top;
690 
691  if (kb_mask == NULL)
692  {
693  nasl_perror (lexic, "get_kb_list() usage : get_kb_list(<NameOfItem>)\n");
694  return NULL;
695  }
696 
697  if (kb == NULL)
698  return NULL;
699 
700  retc = alloc_typed_cell (DYN_ARRAY);
701  retc->x.ref_val = a = g_malloc0 (sizeof (nasl_array));
702 
703  if (strchr (kb_mask, '*'))
704  top = res = kb_item_get_pattern (kb, kb_mask);
705  else
706  top = res = kb_item_get_all (kb, kb_mask);
707 
708  while (res != NULL)
709  {
710  anon_nasl_var v;
711  bzero (&v, sizeof (v));
712 
713  if (res->type == KB_TYPE_INT)
714  {
715  v.var_type = VAR2_INT;
716  v.v.v_int = res->v_int;
717  add_var_to_array (a, res->name, &v);
718  num_elems++;
719  }
720  else if (res->type == KB_TYPE_STR)
721  {
722  v.var_type = VAR2_DATA;
723  v.v.v_str.s_val = (unsigned char *) res->v_str;
724  v.v.v_str.s_siz = strlen (res->v_str);
725  add_var_to_array (a, res->name, &v);
726  num_elems++;
727  }
728  res = res->next;
729  }
730 
731  kb_item_free (top);
732 
733  if (num_elems == 0)
734  {
735  deref_cell (retc);
736  return FAKE_CELL;
737  }
738  return retc;
739 }

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 663 of file nasl_scanner_glue.c.

664 {
665  const char *oid = lexic->oid;
666  tree_cell *retc = NULL;
667 
668  if (oid)
669  {
670  retc = alloc_typed_cell (CONST_DATA);
671  retc->x.str_val = g_strdup (oid);
672  retc->size = strlen (oid);
673  }
674 
675  return retc;
676 }

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:

◆ isalldigit()

static int isalldigit ( char *  str,
int  len 
)
static

Definition at line 61 of file nasl_scanner_glue.c.

62 {
63  int i;
64  char buf[1024];
65  for (i = 0; i < len; i++)
66  {
67  if (!isdigit (str[i]))
68  return 0;
69  }
70 
71  snprintf (buf, sizeof (buf), "%d", atoi (str));
72  if (strcmp (buf, str) != 0)
73  return 0;
74  else
75  return 1;
76 }

Referenced by script_get_preference().

Here is the caller graph for this function:

◆ log_message()

tree_cell* log_message ( lex_ctxt lexic)

Definition at line 951 of file nasl_scanner_glue.c.

952 {
953  return security_something (lexic, proto_post_log, post_log);
954 }

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 lexic)

Definition at line 963 of file nasl_scanner_glue.c.

964 {
965  tree_cell *retc;
966  char *name;
967  const char *value;
968 
969  name = get_str_var_by_num (lexic, 0);
970  if (name == NULL)
971  {
972  nasl_perror (lexic, "get_preference: no name\n");
973  return NULL;
974  }
975  value = prefs_get (name);
976  if (value == NULL)
977  return NULL;
978 
979  retc = alloc_typed_cell (CONST_DATA);
980  retc->x.str_val = strdup (value);
981  retc->size = strlen (value);
982  return retc;
983 }

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 lexic)

Definition at line 1047 of file nasl_scanner_glue.c.

1048 {
1049  struct script_infos *script_infos = lexic->script_infos;
1050 
1051  int port = get_int_var_by_name (lexic, "port", -1);
1052  char *proto = get_str_var_by_name (lexic, "proto");
1053 
1054  if (port >= 0)
1055  {
1056  scanner_add_port (script_infos, port, proto ? proto : "tcp");
1057  }
1058 
1059  return FAKE_CELL;
1060 }

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 1007 of file nasl_scanner_glue.c.

1008 {
1009  tree_cell *retc;
1010  int idx = get_int_var_by_num (lexic, 0, -1);
1011  const char *prange = prefs_get ("port_range");
1012  static int num = 0;
1013  static u_short *ports = NULL;
1014 
1015  if (prange == NULL)
1016  return NULL;
1017 
1018  if (idx < 0)
1019  {
1020  nasl_perror (lexic, "Argument error in scanner_get_port()\n");
1021  nasl_perror (lexic, "Correct usage is : num = scanner_get_port(<num>)\n");
1022  nasl_perror (lexic,
1023  "Where <num> should be 0 the first time you call it\n");
1024  return NULL;
1025  }
1026 
1027  if (ports == NULL)
1028  {
1029  ports = (u_short *) getpts ((char *) prange, &num);
1030  if (ports == NULL)
1031  {
1032  return NULL;
1033  }
1034  }
1035 
1036  if (idx >= num)
1037  {
1038  return NULL;
1039  }
1040 
1041  retc = alloc_typed_cell (CONST_INT);
1042  retc->x.i_val = ports[idx];
1043  return retc;
1044 }

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 lexic)

Definition at line 1063 of file nasl_scanner_glue.c.

1064 {
1065  /* Kept for backward compatibility. */
1066  (void) lexic;
1067  return FAKE_CELL;
1068 }

References FAKE_CELL.

◆ nasl_vendor_version()

tree_cell* nasl_vendor_version ( lex_ctxt lexic)

Definition at line 986 of file nasl_scanner_glue.c.

987 {
988  tree_cell *retc;
989  gchar *version = g_strdup (vendor_version_get ());
990  (void) lexic;
991  retc = alloc_typed_cell (CONST_DATA);
992  retc->x.str_val = strdup (version);
993  retc->size = strlen (version);
994  g_free (version);
995 
996  return retc;
997 }

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 lexic)

Definition at line 635 of file nasl_scanner_glue.c.

636 {
637  struct script_infos *script_infos = lexic->script_infos;
638  struct scan_globals *globals = script_infos->globals;
639  char *value;
640  tree_cell *retc;
641 
642  value = globals->network_targets;
643  retc = alloc_typed_cell (CONST_DATA);
644  if (value)
645  {
646  retc->x.str_val = strdup (value);
647  retc->size = strlen (value);
648  }
649  else
650  return NULL;
651 
652  return retc;
653 }

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 lexic)

Definition at line 786 of file nasl_scanner_glue.c.

787 {
788  struct script_infos *script_infos = lexic->script_infos;
789  char *name = get_str_var_by_name (lexic, "name");
790  int type = get_var_type_by_name (lexic, "value");
791 
792  if (name == NULL)
793  {
794  nasl_perror (lexic, "Syntax error with replace_kb_item() [null name]\n",
795  name);
796  return FAKE_CELL;
797  }
798 
799  if (type == VAR2_INT)
800  {
801  int value = get_int_var_by_name (lexic, "value", -1);
802  if (value != -1)
804  GSIZE_TO_POINTER (value));
805  else
806  nasl_perror (
807  lexic, "Syntax error with replace_kb_item(%s) [value=-1]\n", name);
808  }
809  else
810  {
811  char *value = get_str_var_by_name (lexic, "value");
812  int len = get_var_size_by_name (lexic, "value");
813 
814  if (value == NULL)
815  {
816  nasl_perror (lexic,
817  "Syntax error with replace_kb_item(%s) [null value]\n",
818  name);
819  return FAKE_CELL;
820  }
822  }
823 
824  return FAKE_CELL;
825 }

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 lexic)

Definition at line 602 of file nasl_scanner_glue.c.

603 {
604  (void) lexic;
606 
607  retc->x.i_val = prefs_get_bool ("safe_checks");
608 
609  return retc;
610 }

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 lexic)

Definition at line 613 of file nasl_scanner_glue.c.

614 {
615  struct script_infos *script_infos = lexic->script_infos;
616  struct scan_globals *globals = script_infos->globals;
617  char *value;
619 
620  value = globals->network_scan_status;
621  if (value)
622  {
623  if (strcmp (value, "busy") == 0)
624  retc->x.i_val = 1;
625  else
626  retc->x.i_val = 2;
627  }
628  else
629  retc->x.i_val = 0;
630 
631  return retc;
632 }

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 lexic)

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 (!name || !type || !value)
464  {
465  nasl_perror (lexic,
466  "Argument error in the call to script_add_preference()\n");
467  return FAKE_CELL;
468  }
469  for (i = 0; i < nvti_pref_len (script_infos->nvti); i++)
470  {
471  if (!strcmp (name, nvtpref_name (nvti_pref (script_infos->nvti, i))))
472  {
473  nasl_perror (lexic, "Preference '%s' already exists\n", name);
474  return FAKE_CELL;
475  }
476  }
477 
478  np = nvtpref_new (id, name, type, value);
479  nvti_add_pref (script_infos->nvti, np);
480  return FAKE_CELL;
481 }

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 lexic)

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 lexic)

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 lexic)

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 lexic)

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 lexic)

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 lexic)

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 lexic)

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)

Definition at line 484 of file nasl_scanner_glue.c.

485 {
486  tree_cell *retc;
487  char *pref = get_str_var_by_num (lexic, 0);
488  char *value;
489 
490  if (pref == NULL)
491  {
492  nasl_perror (lexic,
493  "Argument error in the function script_get_preference()\n");
494  nasl_perror (
495  lexic, "Function usage is : pref = script_get_preference(<name>)\n");
496  return FAKE_CELL;
497  }
498 
499  value = get_plugin_preference (lexic->oid, pref);
500  if (value != NULL)
501  {
502  retc = alloc_typed_cell (CONST_INT);
503  if (isalldigit (value, strlen (value)))
504  retc->x.i_val = atoi (value);
505  else
506  {
507  retc->type = CONST_DATA;
508  retc->size = strlen (value);
509  retc->x.str_val = g_strdup (value);
510  }
511  g_free (value);
512  return retc;
513  }
514  else
515  return FAKE_CELL;
516 }

References alloc_typed_cell(), CONST_DATA, CONST_INT, FAKE_CELL, 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 lexic)

Definition at line 519 of file nasl_scanner_glue.c.

520 {
521  struct script_infos *script_infos = lexic->script_infos;
522  tree_cell *retc;
523  char *pref = get_str_var_by_num (lexic, 0);
524  char *value;
525  char *content;
526  int contentsize = 0;
527 
528  if (pref == NULL)
529  {
530  nasl_perror (lexic,
531  "Argument error in the function script_get_preference()\n");
532  nasl_perror (lexic, "Function usage is : pref = "
533  "script_get_preference_file_content(<name>)\n");
534  return NULL;
535  }
536 
537  value = get_plugin_preference (lexic->oid, pref);
538  if (value == NULL)
539  return NULL;
540 
542  contentsize = get_plugin_preference_file_size (script_infos, value);
543  g_free (value);
544  if (content == NULL)
545  return FAKE_CELL;
546  if (contentsize <= 0)
547  {
548  nasl_perror (lexic,
549  "script_get_preference_file_content: could not get "
550  " size of file from preference %s\n",
551  pref);
552  return NULL;
553  }
554 
555  retc = alloc_typed_cell (CONST_DATA);
556  retc->size = contentsize;
557  retc->x.str_val = content;
558 
559  return retc;
560 }

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 lexic)

Definition at line 563 of file nasl_scanner_glue.c.

564 {
565  struct script_infos *script_infos = lexic->script_infos;
566  tree_cell *retc;
567  char *pref = get_str_var_by_num (lexic, 0);
568  const char *value, *local;
569  int len;
570 
571  if (pref == NULL)
572  {
573  nasl_perror (
574  lexic, "script_get_preference_file_location: no preference name!\n");
575  return NULL;
576  }
577 
578  value = get_plugin_preference (lexic->oid, pref);
579  if (value == NULL)
580  {
581  nasl_perror (
582  lexic,
583  "script_get_preference_file_location: could not get preference %s\n",
584  pref);
585  return NULL;
586  }
587  local = get_plugin_preference_fname (script_infos, value);
588  if (local == NULL)
589  return NULL;
590 
591  len = strlen (local);
592  retc = alloc_typed_cell (CONST_DATA);
593  retc->size = len;
594  retc->x.str_val = g_malloc0 (len + 1);
595  memcpy (retc->x.str_val, local, len + 1);
596 
597  return retc;
598 }

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 lexic)

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 lexic)

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 lexic)

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 lexic)

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 lexic)

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 lexic)

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 lexic)

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 lexic)

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 lexic)

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 945 of file nasl_scanner_glue.c.

946 {
948 }

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

Here is the call graph for this function:

◆ security_something()

static tree_cell* security_something ( lex_ctxt lexic,
proto_post_something_t  proto_post_func,
post_something_t  post_func 
)
static

Definition at line 883 of file nasl_scanner_glue.c.

885 {
886  struct script_infos *script_infos = lexic->script_infos;
887 
888  char *proto = get_str_var_by_name (lexic, "protocol");
889  char *data = get_str_var_by_name (lexic, "data");
890  int port = get_int_var_by_name (lexic, "port", -1);
891  char *dup = NULL;
892 
893  if (data != NULL)
894  {
895  int len = get_var_size_by_name (lexic, "data");
896  int i;
897 
898  dup = g_memdup (data, len + 1);
899  for (i = 0; i < len; i++)
900  if (dup[i] == 0)
901  dup[i] = ' ';
902  }
903 
905  {
906  if (data != NULL)
907  fprintf (stdout, "%s\n", dup);
908  else
909  fprintf (stdout, "Success\n");
910  }
911 
912  if (proto == NULL)
913  proto = get_str_var_by_name (lexic, "proto");
914 
915  if (port < 0)
916  port = get_int_var_by_num (lexic, 0, -1);
917 
918  if (dup != NULL)
919  {
920  if (proto == NULL)
921  post_func (lexic->oid, script_infos, port, dup);
922  else
923  proto_post_func (lexic->oid, script_infos, port, proto, dup);
924 
925  g_free (dup);
926  return FAKE_CELL;
927  }
928 
929  if (proto == NULL)
930  post_func (lexic->oid, script_infos, port, NULL);
931  else
932  proto_post_func (lexic->oid, script_infos, port, proto, NULL);
933 
934  return FAKE_CELL;
935 }

References FAKE_CELL, get_int_var_by_name(), get_int_var_by_num(), get_str_var_by_name(), get_var_size_by_name(), struct_lex_ctxt::oid, struct_lex_ctxt::script_infos, and script_infos::standalone.

Referenced by error_message(), log_message(), and security_message().

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

◆ set_kb_item()

tree_cell* set_kb_item ( lex_ctxt lexic)

Definition at line 828 of file nasl_scanner_glue.c.

829 {
830  struct script_infos *script_infos = lexic->script_infos;
831  char *name = get_str_var_by_name (lexic, "name");
832  int type = get_var_type_by_name (lexic, "value");
833 
834  if (name == NULL)
835  {
836  nasl_perror (lexic, "Syntax error with set_kb_item() [null name]\n",
837  name);
838  return FAKE_CELL;
839  }
840 
841  if (type == VAR2_INT)
842  {
843  int value = get_int_var_by_name (lexic, "value", -1);
844  if (value != -1)
845  plug_set_key (script_infos, name, ARG_INT, GSIZE_TO_POINTER (value));
846  else
847  nasl_perror (
848  lexic, "Syntax error with set_kb_item() [value=-1 for name '%s']\n",
849  name);
850  }
851  else
852  {
853  char *value = get_str_var_by_name (lexic, "value");
854  int len = get_var_size_by_name (lexic, "value");
855  if (value == NULL)
856  {
857  nasl_perror (
858  lexic,
859  "Syntax error with set_kb_item() [null value for name '%s']\n",
860  name);
861  return FAKE_CELL;
862  }
864  }
865 
866  return FAKE_CELL;
867 }

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:
script_infos::standalone
int standalone
Definition: scanneraux.h:53
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:615
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:699
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:627
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:510
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:592
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:563
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
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:621
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:455
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:585
get_plugin_preference
char * get_plugin_preference(const char *oid, const char *name)
Definition: plugutils.c:396
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:541
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:883
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