OpenVAS Scanner  7.0.0~git
nasl_init.c File Reference
#include "../misc/network.h"
#include "../misc/nvt_categories.h"
#include "exec.h"
#include "nasl.h"
#include "nasl_builtin_plugins.h"
#include "nasl_cert.h"
#include "nasl_cmd_exec.h"
#include "nasl_crypto.h"
#include "nasl_crypto2.h"
#include "nasl_debug.h"
#include "nasl_func.h"
#include "nasl_global_ctxt.h"
#include "nasl_host.h"
#include "nasl_http.h"
#include "nasl_isotime.h"
#include "nasl_lex_ctxt.h"
#include "nasl_misc_funcs.h"
#include "nasl_packet_forgery.h"
#include "nasl_packet_forgery_v6.h"
#include <stdlib.h>
#include <string.h>
#include "nasl_raw.h"
#include "nasl_scanner_glue.h"
#include "nasl_smb.h"
#include "nasl_snmp.h"
#include "nasl_socket.h"
#include "nasl_ssh.h"
#include "nasl_text_utils.h"
#include "nasl_tree.h"
#include "nasl_var.h"
#include "nasl_wmi.h"
Include dependency graph for nasl_init.c:

Go to the source code of this file.

Data Structures

struct  init_func
 

Functions

void init_nasl_library (lex_ctxt *lexic)
 Adds "built-in" variable and function definitions to a context. More...
 
nasl_funcfunc_is_internal (const char *name)
 
char * nasl_version ()
 
void add_nasl_library (GSList **list)
 Add "built-in" variables to a list. More...
 

Variables

static init_func libfuncs []
 
struct {
   const char *   name
 
   const char *   val
 
libsvars []
 
struct {
   const char *   name
 
   int   val
 
libivars []
 

Function Documentation

◆ add_nasl_library()

void add_nasl_library ( GSList **  list)

Add "built-in" variables to a list.

Definition at line 514 of file nasl_init.c.

515 {
516  int i;
517  for (i = 0; libivars[i].name != NULL; i++)
518  *list = g_slist_append (*list, g_strdup (libivars[i].name));
519  for (i = 0; libsvars[i].name != NULL; i++)
520  *list = g_slist_append (*list, g_strdup (libsvars[i].name));
521 }

References libivars, libsvars, and name.

Referenced by add_predef_varname().

Here is the caller graph for this function:

◆ func_is_internal()

nasl_func* func_is_internal ( const char *  name)

Definition at line 486 of file nasl_init.c.

487 {
488  size_t i;
489 
490  if (!name)
491  return NULL;
492 
493  for (i = 0; i < sizeof (libfuncs) / sizeof (libfuncs[0]) - 1; i++)
494  {
495  if (!strcmp (name, libfuncs[i].name))
496  return (nasl_func *) &libfuncs[i];
497  }
498  return NULL;
499 }

References libfuncs, and name.

Referenced by get_func(), and nasl_func_call().

Here is the caller graph for this function:

◆ init_nasl_library()

void init_nasl_library ( lex_ctxt lexic)

Adds "built-in" variable and function definitions to a context.

Definition at line 446 of file nasl_init.c.

447 {
448  tree_cell tc;
449  unsigned i;
450 
451  memset (&tc, 0, sizeof (tc));
452 
453  // Initialize constant integer terms
454  tc.type = CONST_INT;
455  for (i = 0; i < sizeof (libivars) / sizeof (libivars[0]) - 1; i++)
456  {
457  tc.x.i_val = libivars[i].val;
458  if (add_named_var_to_ctxt (lexic, libivars[i].name, &tc) == NULL)
459  {
460  nasl_perror (lexic, "init_nasl_library: could not define var '%s'\n",
461  libivars[i].name);
462  continue;
463  }
464  }
465 
466  // Initialize constant string terms
467  tc.type = CONST_DATA;
468  for (i = 0; i < sizeof (libsvars) / sizeof (libsvars[0]) - 1; i++)
469  {
470  tc.x.str_val = (char *) libsvars[i].val;
471  tc.size = strlen (libsvars[i].val);
472  if (add_named_var_to_ctxt (lexic, libsvars[i].name, &tc) == NULL)
473  {
474  nasl_perror (lexic, "init_nasl_library: could not define var '%s'\n",
475  libsvars[i].name);
476  continue;
477  }
478  }
479 
480  // Add the "NULL" variable
481  if (add_named_var_to_ctxt (lexic, "NULL", NULL) == NULL)
482  nasl_perror (lexic, "init_nasl_library: could not define var 'NULL'\n");
483 }

References add_named_var_to_ctxt(), CONST_DATA, CONST_INT, TC::i_val, libivars, libsvars, name, nasl_perror(), TC::size, TC::str_val, TC::type, val, and TC::x.

Referenced by init_empty_lex_ctxt().

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

◆ nasl_version()

char* nasl_version ( )

Definition at line 502 of file nasl_init.c.

503 {
504  static char vers[sizeof (OPENVASLIB_VERSION) + 1];
505  strncpy (vers, OPENVASLIB_VERSION, sizeof (vers) - 1);
506  vers[sizeof (vers) - 1] = '\0';
507  return vers;
508 }

Referenced by main().

Here is the caller graph for this function:

Variable Documentation

◆ libfuncs

init_func libfuncs[]
static

Mapping of function names in NASL (eg. script_name("english")) to the C function pointers (e.g. script_name (lex_ctx**) ), argument count and argument Meta-information (names).

Definition at line 67 of file nasl_init.c.

Referenced by func_is_internal().

◆ libivars

struct { ... } libivars[]

◆ libsvars

struct { ... } libsvars[]
Initial value:
= {
{"OPENVAS_VERSION", OPENVASLIB_VERSION},
{NULL, NULL},
}

Referenced by add_nasl_library(), and init_nasl_library().

◆ name

◆ val

CONST_DATA
@ CONST_DATA
Definition: nasl_tree.h:93
add_named_var_to_ctxt
named_nasl_var * add_named_var_to_ctxt(lex_ctxt *, const char *, tree_cell *)
Definition: nasl_var.c:825
libivars
static struct @1 libivars[]
libsvars
static struct @0 libsvars[]
TC::str_val
char * str_val
Definition: nasl_tree.h:112
libfuncs
static init_func libfuncs[]
Definition: nasl_init.c:67
st_nasl_func
Definition: nasl_func.h:25
TC::x
union TC::@2 x
name
const char * name
Definition: nasl_init.c:377
nasl_perror
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:120
TC::size
int size
Definition: nasl_tree.h:109
TC
Definition: nasl_tree.h:104
TC::type
short type
Definition: nasl_tree.h:106
CONST_INT
@ CONST_INT
Definition: nasl_tree.h:90
val
const char * val
Definition: nasl_init.c:378
list
Definition: nasl_builtin_synscan.c:259
TC::i_val
long int i_val
Definition: nasl_tree.h:113