OpenVAS Scanner 22.7.9
nasl_init.c File Reference
#include "nasl_init.h"
#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_frame_forgery.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.
 
nasl_funcfunc_is_internal (const char *name)
 
char * nasl_version ()
 
void add_nasl_library (GSList **list)
 Add "built-in" variables to a list.
 

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 554 of file nasl_init.c.

555{
556 int i;
557 for (i = 0; libivars[i].name != NULL; i++)
558 *list = g_slist_append (*list, g_strdup (libivars[i].name));
559 for (i = 0; libsvars[i].name != NULL; i++)
560 *list = g_slist_append (*list, g_strdup (libsvars[i].name));
561}
static struct @4 libivars[]
const char * name
Definition: nasl_init.c:411
static struct @3 libsvars[]

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 526 of file nasl_init.c.

527{
528 size_t i;
529
530 if (!name)
531 return NULL;
532
533 for (i = 0; i < sizeof (libfuncs) / sizeof (libfuncs[0]) - 1; i++)
534 {
535 if (!strcmp (name, libfuncs[i].name))
536 return (nasl_func *) &libfuncs[i];
537 }
538 return NULL;
539}
static init_func libfuncs[]
Definition: nasl_init.c:58

References libfuncs, and name.

Referenced by get_func(), nasl_func_call(), and nasl_lint_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 486 of file nasl_init.c.

487{
488 tree_cell tc;
489 unsigned i;
490
491 memset (&tc, 0, sizeof (tc));
492
493 // Initialize constant integer terms
494 tc.type = CONST_INT;
495 for (i = 0; i < sizeof (libivars) / sizeof (libivars[0]) - 1; i++)
496 {
497 tc.x.i_val = libivars[i].val;
498 if (add_named_var_to_ctxt (lexic, libivars[i].name, &tc) == NULL)
499 {
500 nasl_perror (lexic, "init_nasl_library: could not define var '%s'\n",
501 libivars[i].name);
502 continue;
503 }
504 }
505
506 // Initialize constant string terms
507 tc.type = CONST_DATA;
508 for (i = 0; i < sizeof (libsvars) / sizeof (libsvars[0]) - 1; i++)
509 {
510 tc.x.str_val = (char *) libsvars[i].val;
511 tc.size = strlen (libsvars[i].val);
512 if (add_named_var_to_ctxt (lexic, libsvars[i].name, &tc) == NULL)
513 {
514 nasl_perror (lexic, "init_nasl_library: could not define var '%s'\n",
515 libsvars[i].name);
516 continue;
517 }
518 }
519
520 // Add the "NULL" variable
521 if (add_named_var_to_ctxt (lexic, "NULL", NULL) == NULL)
522 nasl_perror (lexic, "init_nasl_library: could not define var 'NULL'\n");
523}
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:111
const char * val
Definition: nasl_init.c:412
named_nasl_var * add_named_var_to_ctxt(lex_ctxt *, const char *, tree_cell *)
Definition: nasl_var.c:813
@ CONST_DATA
Definition: nasl_tree.h:82
@ CONST_INT
Definition: nasl_tree.h:79
Definition: nasl_tree.h:94
union TC::@5 x
int size
Definition: nasl_tree.h:99
long int i_val
Definition: nasl_tree.h:104
char * str_val
Definition: nasl_tree.h:103
short type
Definition: nasl_tree.h:95

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 ( void  )

Definition at line 542 of file nasl_init.c.

543{
544 static char vers[sizeof (OPENVASLIB_VERSION) + 1];
545 strncpy (vers, OPENVASLIB_VERSION, sizeof (vers) - 1);
546 vers[sizeof (vers) - 1] = '\0';
547 return vers;
548}

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 58 of file nasl_init.c.

Referenced by func_is_internal().

◆ 

struct { ... } libivars[]

◆ 

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

Referenced by add_nasl_library(), and init_nasl_library().

◆ name

const char* name

Definition at line 411 of file nasl_init.c.

Referenced by __wrap_redis_push_str(), add_named_var_to_ctxt(), add_nasl_library(), add_var_to_array(), build_encode_URL(), check_dependency_cycles(), create_named_var(), exec_nasl_script(), find_charset_functions_ntlmssp(), func_is_internal(), get_argument_by_name(), get_array_elem(), get_func(), get_func_ref_by_name(), get_int_var_by_name(), get_plugin_preference(), get_str_var_by_name(), get_var_ref_by_name(), get_var_size_by_name(), get_var_type_by_name(), get_variable_by_name(), getinterfaces(), getipv4routes(), getipv6routes(), hosts_get(), hosts_new(), hosts_set_pid(), init_capture_device(), init_nasl_ctx(), init_nasl_library(), init_v6_capture_device(), ipaddr2devname(), is_utf16_ntlmssp(), kb_item_add_int_unique_with_main_kb_check(), kb_item_add_int_with_main_kb_check(), kb_item_add_str_unique_with_main_kb_check(), kb_item_push_str_with_main_kb_check(), kb_item_set_int_with_main_kb_check(), kb_item_set_str_with_main_kb_check(), launch_plugin(), nasl_get_preference(), nasl_pcap_next(), nasl_send_capture(), nasl_send_v6packet(), plug_get_key(), plug_replace_key(), plug_replace_key_len(), plug_set_key(), plug_set_key_len(), plug_set_key_len_volatile(), plug_set_key_volatile(), plugin_add(), plugins_reload_from_dir(), replace_kb_item(), routethrough(), script_add_preference(), script_tag(), script_xref(), set_kb_item(), set_kb_item_volatile(), simple_register_host_detail(), update_running_processes(), v6_getinterfaces(), v6_getsourceip(), v6_ipaddr2devname(), v6_is_local_ip(), validate_script_xref(), and yyparse().

◆ val