OpenVAS Scanner  7.0.0~git
nasl.h File Reference
#include "../misc/scanneraux.h"
#include <glib.h>
Include dependency graph for nasl.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define NASL_EXEC_DESCR   (1 << 0)
 
#define NASL_EXEC_PARSE_ONLY   (1 << 1)
 
#define NASL_ALWAYS_SIGNED   (1 << 2)
 
#define NASL_COMMAND_LINE   (1 << 3)
 
#define NASL_LINT   (1 << 4)
 
#define NASL_ERR_NOERR   0
 
#define NASL_ERR_ETIMEDOUT   1
 
#define NASL_ERR_ECONNRESET   2
 
#define NASL_ERR_EUNREACH   3
 
#define NASL_ERR_EUNKNOWN   99
 

Functions

int nasl_verify_signature (const char *filename)
 
char * nasl_extract_signature_fprs (const char *filename)
 
GSList * nasl_get_all_certificates (void)
 
int add_nasl_inc_dir (const char *)
 Adds the given string as directory for searching for includes. More...
 
void nasl_clean_inc (void)
 
int exec_nasl_script (struct script_infos *, int)
 Execute a NASL script. More...
 
char * nasl_version (void)
 
pid_t nasl_server_start (char *, char *)
 
void nasl_server_recompile (char *, char *)
 

Macro Definition Documentation

◆ NASL_ALWAYS_SIGNED

#define NASL_ALWAYS_SIGNED   (1 << 2)

Definition at line 59 of file nasl.h.

◆ NASL_COMMAND_LINE

#define NASL_COMMAND_LINE   (1 << 3)

Definition at line 60 of file nasl.h.

◆ NASL_ERR_ECONNRESET

#define NASL_ERR_ECONNRESET   2

Definition at line 65 of file nasl.h.

◆ NASL_ERR_ETIMEDOUT

#define NASL_ERR_ETIMEDOUT   1

Definition at line 64 of file nasl.h.

◆ NASL_ERR_EUNKNOWN

#define NASL_ERR_EUNKNOWN   99

Definition at line 67 of file nasl.h.

◆ NASL_ERR_EUNREACH

#define NASL_ERR_EUNREACH   3

Definition at line 66 of file nasl.h.

◆ NASL_ERR_NOERR

#define NASL_ERR_NOERR   0

Definition at line 63 of file nasl.h.

◆ NASL_EXEC_DESCR

#define NASL_EXEC_DESCR   (1 << 0)

Definition at line 57 of file nasl.h.

◆ NASL_EXEC_PARSE_ONLY

#define NASL_EXEC_PARSE_ONLY   (1 << 1)

Definition at line 58 of file nasl.h.

◆ NASL_LINT

#define NASL_LINT   (1 << 4)

Definition at line 61 of file nasl.h.

Function Documentation

◆ add_nasl_inc_dir()

int add_nasl_inc_dir ( const char *  dir)

Adds the given string as directory for searching for includes.

Parameters
dirA directory path. This function will add a copy of this parameter to the list of include folders. This means the parameter can be freed elsewhere without affecting the list.
Returns
0 in case of success. -1 if the stat on the given directory path was unsuccessful. -2 if the given directory path was not a directory.

Definition at line 2738 of file nasl_grammar.tab.c.

2739 {
2740  if (dir == NULL)
2741  {
2742  return 0;
2743  }
2744 
2745  // Allow initialization with empty element
2746  if (*dir == '\0')
2747  {
2748  inc_dirs = g_slist_append (inc_dirs, g_strdup((gchar *)dir));
2749  return 0;
2750  }
2751 
2752  struct stat stat_buf;
2753 
2754  if (stat (dir, &stat_buf) != 0)
2755  return -1;
2756 
2757  if (S_ISDIR(stat_buf.st_mode) != 0)
2758  {
2759  inc_dirs = g_slist_append (inc_dirs, g_strdup((gchar *)dir));
2760  return 0;
2761  }
2762  else
2763  return -2;
2764 }

References inc_dirs.

Referenced by include_dirs(), init_nasl_ctx(), and main().

Here is the caller graph for this function:

◆ exec_nasl_script()

int exec_nasl_script ( struct script_infos script_infos,
int  mode 
)

Execute a NASL script.

"mode" is a bit field: bit #0 (1) is "description" Bit #1 (2) is "parse only"

Parameters
script_infosThe plugin script_infos. #param mode Flags for different execution modes (Description, parse-only, always-signed, command-line, lint)
Returns
0 if the script was executed successfully, negative values if an error occurred.

Definition at line 1624 of file exec.c.

1625 {
1626  naslctxt ctx;
1627  nasl_func *pf;
1628  int err = 0, to, process_id;
1629  tree_cell *ret;
1630  lex_ctxt *lexic;
1631  gchar *old_dir;
1632  gchar *newdir;
1633  tree_cell tc;
1634  const char *str, *name = script_infos->name, *oid = script_infos->oid;
1635  gchar *short_name = g_path_get_basename (name);
1636 
1637  nasl_set_plugin_filename (short_name);
1638  g_free (short_name);
1639 
1640  srand48 (getpid () + getppid () + (long) time (NULL));
1641 
1642  old_dir = g_get_current_dir ();
1643 
1644  newdir = g_path_get_dirname (name);
1645 
1646  if (g_chdir (newdir) != 0)
1647  {
1648  g_message ("%s: Not able to open nor to locate it in include paths",
1649  name);
1650  g_free (old_dir);
1651  g_free (newdir);
1652  return -1;
1653  }
1654  g_free (newdir);
1655 
1656  bzero (&ctx, sizeof (ctx));
1657  if (mode & NASL_ALWAYS_SIGNED)
1658  ctx.always_signed = 1;
1659  if (nvticache_initialized ())
1660  ctx.kb = nvticache_get_kb ();
1661  else
1662  ctx.kb = plug_get_kb (script_infos);
1663 
1664  if (init_nasl_ctx (&ctx, name) == 0)
1665  {
1666  if (naslparse (&ctx))
1667  {
1668  g_message ("%s: Parse error at or near line %d", name, ctx.line_nb);
1669  nasl_clean_ctx (&ctx);
1670  g_chdir (old_dir);
1671  g_free (old_dir);
1672  return -1;
1673  }
1674  }
1675  else
1676  {
1677  g_chdir (old_dir);
1678  g_free (old_dir);
1679  return -1;
1680  }
1681 
1682  lexic = init_empty_lex_ctxt ();
1683  lexic->script_infos = script_infos;
1684  lexic->oid = oid;
1686 
1687  str = prefs_get ("checks_read_timeout");
1688  if (str != NULL)
1689  to = atoi (str);
1690  else
1691  to = 5;
1692 
1693  if (to <= 0)
1694  to = 5;
1695 
1696  lexic->recv_timeout = to;
1697 
1698  process_id = getpid ();
1699  if (mode & NASL_LINT)
1700  {
1701  if (nasl_lint (lexic, ctx.tree) == NULL)
1702  err--;
1703  }
1704  else if (!(mode & NASL_EXEC_PARSE_ONLY))
1705  {
1706  char *p;
1707 
1708  bzero (&tc, sizeof (tc));
1709  tc.type = CONST_INT;
1710  tc.x.i_val = (mode & NASL_COMMAND_LINE) != 0;
1711  add_named_var_to_ctxt (lexic, "COMMAND_LINE", &tc);
1712 
1713  bzero (&tc, sizeof (tc));
1714  tc.type = CONST_INT;
1715  tc.x.i_val = (mode & NASL_EXEC_DESCR) != 0;
1716  add_named_var_to_ctxt (lexic, "description", &tc);
1717 
1718  tc.type = CONST_DATA;
1719  p = strrchr (name, '/');
1720  if (p == NULL)
1721  p = (char *) name;
1722  else
1723  p++;
1724  tc.x.str_val = p;
1725  tc.size = strlen (p);
1726  add_named_var_to_ctxt (lexic, "SCRIPT_NAME", &tc);
1727 
1728  truc = (lex_ctxt *) ctx.tree;
1729  if ((ret = nasl_exec (lexic, ctx.tree)) == NULL)
1730  err = -1;
1731  else
1732  deref_cell (ret);
1733 
1734  if ((pf = get_func_ref_by_name (lexic, "on_exit")) != NULL)
1735  nasl_func_call (lexic, pf, NULL);
1736  }
1737 
1738  if (g_chdir (old_dir) != 0)
1739  {
1740  g_free (old_dir);
1741  return -1;
1742  }
1743  g_free (old_dir);
1744 
1745  nasl_clean_ctx (&ctx);
1746  free_lex_ctxt (lexic);
1747  if (process_id != getpid ())
1748  exit (0);
1749 
1750  return err;
1751 }

References add_named_var_to_ctxt(), naslctxt::always_signed, CONST_DATA, CONST_INT, deref_cell(), free_lex_ctxt(), get_func_ref_by_name(), TC::i_val, init_empty_lex_ctxt(), init_nasl_ctx(), naslctxt::kb, naslctxt::line_nb, script_infos::name, name, NASL_ALWAYS_SIGNED, nasl_clean_ctx(), NASL_COMMAND_LINE, nasl_exec(), NASL_EXEC_DESCR, NASL_EXEC_PARSE_ONLY, nasl_func_call(), NASL_LINT, nasl_lint(), nasl_set_filename(), nasl_set_plugin_filename(), naslparse(), struct_lex_ctxt::oid, script_infos::oid, oid, plug_get_kb(), struct_lex_ctxt::recv_timeout, struct_lex_ctxt::script_infos, TC::size, TC::str_val, naslctxt::tree, truc, TC::type, and TC::x.

Referenced by main(), nasl_plugin_add(), nasl_thread(), parse_script_infos(), and process_file().

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

◆ nasl_clean_inc()

void nasl_clean_inc ( void  )

Definition at line 3003 of file nasl_grammar.tab.c.

3004 {
3005  if (!includes_hash)
3006  return;
3007  g_hash_table_destroy (includes_hash);
3008  includes_hash = NULL;
3009 }

References includes_hash.

Referenced by plugins_reload_from_dir().

Here is the caller graph for this function:

◆ nasl_extract_signature_fprs()

char* nasl_extract_signature_fprs ( const char *  filename)

◆ nasl_get_all_certificates()

GSList* nasl_get_all_certificates ( void  )

◆ nasl_server_recompile()

void nasl_server_recompile ( char *  ,
char *   
)

◆ nasl_server_start()

pid_t nasl_server_start ( char *  ,
char *   
)

◆ nasl_verify_signature()

int nasl_verify_signature ( const char *  filename)

Referenced by load_checksums().

Here is the caller graph for this function:

◆ nasl_version()

char* nasl_version ( void  )

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 }
script_infos
Definition: scanneraux.h:43
get_func_ref_by_name
nasl_func * get_func_ref_by_name(lex_ctxt *ctxt, const char *name)
Definition: nasl_func.c:94
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
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
naslctxt
Definition: nasl_global_ctxt.h:26
inc_dirs
static GSList * inc_dirs
Definition: nasl_grammar.tab.c:2724
script_infos::name
char * name
Definition: scanneraux.h:49
nasl_exec
tree_cell * nasl_exec(lex_ctxt *lexic, tree_cell *st)
Execute a parse tree.
Definition: exec.c:781
st_nasl_func
Definition: nasl_func.h:25
TC::x
union TC::@2 x
name
const char * name
Definition: nasl_init.c:377
naslctxt::kb
kb_t kb
Definition: nasl_global_ctxt.h:33
nasl_lint
tree_cell * nasl_lint(lex_ctxt *, tree_cell *)
Search for errors in a nasl script.
Definition: lint.c:497
naslparse
int naslparse(naslctxt *)
NASL_EXEC_DESCR
#define NASL_EXEC_DESCR
Definition: nasl.h:57
oid
const char * oid
Definition: nasl_builtin_find_service.c:57
TC::size
int size
Definition: nasl_tree.h:109
nasl_clean_ctx
void nasl_clean_ctx(naslctxt *)
Definition: nasl_grammar.tab.c:2996
struct_lex_ctxt::oid
const char * oid
Definition: nasl_lex_ctxt.h:42
free_lex_ctxt
void free_lex_ctxt(lex_ctxt *c)
Definition: nasl_lex_ctxt.c:55
script_infos::oid
char * oid
Definition: scanneraux.h:48
init_nasl_ctx
int init_nasl_ctx(naslctxt *, const char *)
Initialize a NASL context for a NASL file.
Definition: nasl_grammar.tab.c:2894
struct_lex_ctxt::script_infos
struct script_infos * script_infos
Definition: nasl_lex_ctxt.h:41
NASL_COMMAND_LINE
#define NASL_COMMAND_LINE
Definition: nasl.h:60
TC
Definition: nasl_tree.h:104
struct_lex_ctxt
Definition: nasl_lex_ctxt.h:33
TC::type
short type
Definition: nasl_tree.h:106
naslctxt::tree
tree_cell * tree
Definition: nasl_global_ctxt.h:31
naslctxt::always_signed
int always_signed
Definition: nasl_global_ctxt.h:29
nasl_set_plugin_filename
void nasl_set_plugin_filename(const char *filename)
Set the current launched plugin filename.
Definition: nasl_debug.c:63
CONST_INT
@ CONST_INT
Definition: nasl_tree.h:90
nasl_func_call
tree_cell * nasl_func_call(lex_ctxt *lexic, const nasl_func *f, tree_cell *arg_list)
Definition: nasl_func.c:107
struct_lex_ctxt::recv_timeout
int recv_timeout
Definition: nasl_lex_ctxt.h:43
NASL_ALWAYS_SIGNED
#define NASL_ALWAYS_SIGNED
Definition: nasl.h:59
nasl_set_filename
void nasl_set_filename(const char *filename)
Definition: nasl_debug.c:97
NASL_EXEC_PARSE_ONLY
#define NASL_EXEC_PARSE_ONLY
Definition: nasl.h:58
deref_cell
void deref_cell(tree_cell *c)
Definition: nasl_tree.c:192
truc
lex_ctxt * truc
Definition: exec.c:370
init_empty_lex_ctxt
lex_ctxt * init_empty_lex_ctxt()
Definition: nasl_lex_ctxt.c:32
NASL_LINT
#define NASL_LINT
Definition: nasl.h:61
includes_hash
GHashTable * includes_hash
Definition: nasl_grammar.tab.c:126
naslctxt::line_nb
int line_nb
Definition: nasl_global_ctxt.h:28
TC::i_val
long int i_val
Definition: nasl_tree.h:113