OpenVAS Scanner 22.7.9
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.
 
void nasl_clean_inc (void)
 
int exec_nasl_script (struct script_infos *, int)
 Execute a NASL script.
 
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 47 of file nasl.h.

◆ NASL_COMMAND_LINE

#define NASL_COMMAND_LINE   (1 << 3)

Definition at line 48 of file nasl.h.

◆ NASL_ERR_ECONNRESET

#define NASL_ERR_ECONNRESET   2

Definition at line 53 of file nasl.h.

◆ NASL_ERR_ETIMEDOUT

#define NASL_ERR_ETIMEDOUT   1

Definition at line 52 of file nasl.h.

◆ NASL_ERR_EUNKNOWN

#define NASL_ERR_EUNKNOWN   99

Definition at line 55 of file nasl.h.

◆ NASL_ERR_EUNREACH

#define NASL_ERR_EUNREACH   3

Definition at line 54 of file nasl.h.

◆ NASL_ERR_NOERR

#define NASL_ERR_NOERR   0

Definition at line 51 of file nasl.h.

◆ NASL_EXEC_DESCR

#define NASL_EXEC_DESCR   (1 << 0)

Definition at line 45 of file nasl.h.

◆ NASL_EXEC_PARSE_ONLY

#define NASL_EXEC_PARSE_ONLY   (1 << 1)

Definition at line 46 of file nasl.h.

◆ NASL_LINT

#define NASL_LINT   (1 << 4)

Definition at line 49 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 2551 of file nasl_grammar.tab.c.

2552{
2553 if (dir == NULL)
2554 {
2555 return 0;
2556 }
2557
2558 // Allow initialization with empty element
2559 if (*dir == '\0')
2560 {
2561 inc_dirs = g_slist_append (inc_dirs, g_strdup((gchar *)dir));
2562 return 0;
2563 }
2564
2565 struct stat stat_buf;
2566
2567 if (stat (dir, &stat_buf) != 0)
2568 return -1;
2569
2570 if (S_ISDIR(stat_buf.st_mode) != 0)
2571 {
2572 inc_dirs = g_slist_append (inc_dirs, g_strdup((gchar *)dir));
2573 return 0;
2574 }
2575 else
2576 return -2;
2577}
static GSList * inc_dirs

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. Return number of errors if mode is NASL_LINT and no none linting errors occurred.

Definition at line 1614 of file exec.c.

1615{
1616 naslctxt ctx;
1617 nasl_func *pf;
1618 int err = 0, to;
1619 tree_cell *ret;
1620 lex_ctxt *lexic;
1621 gchar *old_dir;
1622 gchar *newdir;
1623 tree_cell tc;
1624 const char *str, *name = script_infos->name, *oid = script_infos->oid;
1625 gchar *short_name = g_path_get_basename (name);
1626 int error_counter = 0;
1627
1628 nasl_set_plugin_filename (short_name);
1629 g_free (short_name);
1630
1631 srand48 (getpid () + getppid () + (long) time (NULL));
1632
1633 old_dir = g_get_current_dir ();
1634
1635 newdir = g_path_get_dirname (name);
1636
1637 if (g_chdir (newdir) != 0)
1638 {
1639 g_message ("%s: Not able to change working directory to %s (%d [%s]).",
1640 __func__, newdir, errno, strerror (errno));
1641 g_free (old_dir);
1642 g_free (newdir);
1643 return -1;
1644 }
1645 g_free (newdir);
1646
1647 bzero (&ctx, sizeof (ctx));
1648 if (mode & NASL_ALWAYS_SIGNED)
1649 ctx.always_signed = 1;
1650 if ((mode & NASL_EXEC_DESCR) != 0)
1651 ctx.exec_descr = 1;
1652 if (nvticache_initialized ())
1653 ctx.kb = nvticache_get_kb ();
1654 else
1655 ctx.kb = plug_get_kb (script_infos);
1656
1657 if (init_nasl_ctx (&ctx, name) == 0)
1658 {
1659 err = naslparse (&ctx, &error_counter);
1660 if (err != 0 || error_counter > 0)
1661 {
1662 g_message ("%s. There were %d parse errors.", name, error_counter);
1663 nasl_clean_ctx (&ctx);
1664 g_chdir (old_dir);
1665 g_free (old_dir);
1666 return -1;
1667 }
1668 }
1669 else
1670 {
1671 g_chdir (old_dir);
1672 g_free (old_dir);
1673 return -1;
1674 }
1675
1676 lexic = init_empty_lex_ctxt ();
1677 lexic->script_infos = script_infos;
1678 lexic->oid = oid;
1680
1681 str = prefs_get ("checks_read_timeout");
1682 if (str != NULL)
1683 to = atoi (str);
1684 else
1685 to = 5;
1686
1687 if (to <= 0)
1688 to = 5;
1689
1690 lexic->recv_timeout = to;
1691
1692 if (mode & NASL_LINT)
1693 {
1694 /* ret is set to the number of errors the linter finds.
1695 ret will be overwritten with -1 if any errors occur in the steps
1696 after linting so we do not break other behaviour dependent on a
1697 negative return value when doing more than just linting. */
1698 tree_cell *lintret = nasl_lint (lexic, ctx.tree);
1699 if (lintret == NULL)
1700 err--;
1701 else if (lintret != FAKE_CELL && lintret->x.i_val > 0)
1702 {
1703 err = lintret->x.i_val;
1704 g_free (lintret);
1705 }
1706 }
1707 else if (!(mode & NASL_EXEC_PARSE_ONLY))
1708 {
1709 char *p;
1710
1711 bzero (&tc, sizeof (tc));
1712 tc.type = CONST_INT;
1713 tc.x.i_val = (mode & NASL_COMMAND_LINE) != 0;
1714 add_named_var_to_ctxt (lexic, "COMMAND_LINE", &tc);
1715
1716 bzero (&tc, sizeof (tc));
1717 tc.type = CONST_INT;
1718 tc.x.i_val = (mode & NASL_EXEC_DESCR) != 0;
1719 add_named_var_to_ctxt (lexic, "description", &tc);
1720
1721 tc.type = CONST_DATA;
1722 p = strrchr (name, '/');
1723 if (p == NULL)
1724 p = (char *) name;
1725 else
1726 p++;
1727 tc.x.str_val = p;
1728 tc.size = strlen (p);
1729 add_named_var_to_ctxt (lexic, "SCRIPT_NAME", &tc);
1730
1731 truc = (lex_ctxt *) ctx.tree;
1732 if ((ret = nasl_exec (lexic, ctx.tree)) == NULL)
1733 err = -1;
1734 else
1735 deref_cell (ret);
1736
1737 if ((pf = get_func_ref_by_name (lexic, "on_exit")) != NULL)
1738 nasl_func_call (lexic, pf, NULL);
1739 }
1740
1741 if (g_chdir (old_dir) != 0)
1742 {
1743 g_free (old_dir);
1744 return -1;
1745 }
1746 g_free (old_dir);
1747
1748 nasl_clean_ctx (&ctx);
1749 free_lex_ctxt (lexic);
1750 return err;
1751}
int naslparse(naslctxt *, int *)
tree_cell * nasl_exec(lex_ctxt *lexic, tree_cell *st)
Execute a parse tree.
Definition: exec.c:770
lex_ctxt * truc
Definition: exec.c:359
tree_cell * nasl_lint(lex_ctxt *lexic, tree_cell *st)
Search for errors in a nasl script.
Definition: lint.c:811
#define NASL_ALWAYS_SIGNED
Definition: nasl.h:47
#define NASL_EXEC_DESCR
Definition: nasl.h:45
#define NASL_EXEC_PARSE_ONLY
Definition: nasl.h:46
#define NASL_COMMAND_LINE
Definition: nasl.h:48
#define NASL_LINT
Definition: nasl.h:49
const char * oid
void nasl_set_filename(const char *filename)
Definition: nasl_debug.c:88
void nasl_set_plugin_filename(const char *filename)
Set the current launched plugin filename.
Definition: nasl_debug.c:53
tree_cell * nasl_func_call(lex_ctxt *lexic, const nasl_func *f, tree_cell *arg_list)
Definition: nasl_func.c:95
nasl_func * get_func_ref_by_name(lex_ctxt *ctxt, const char *name)
Definition: nasl_func.c:82
int init_nasl_ctx(naslctxt *, const char *)
Initialize a NASL context for a NASL file.
void nasl_clean_ctx(naslctxt *)
const char * name
Definition: nasl_init.c:411
void free_lex_ctxt(lex_ctxt *c)
Definition: nasl_lex_ctxt.c:43
lex_ctxt * init_empty_lex_ctxt()
Definition: nasl_lex_ctxt.c:20
named_nasl_var * add_named_var_to_ctxt(lex_ctxt *, const char *, tree_cell *)
Definition: nasl_var.c:813
void deref_cell(tree_cell *c)
Definition: nasl_tree.c:181
@ CONST_DATA
Definition: nasl_tree.h:82
@ CONST_INT
Definition: nasl_tree.h:79
#define FAKE_CELL
Definition: nasl_tree.h:110
kb_t plug_get_kb(struct script_infos *args)
Definition: plugutils.c:1055
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
tree_cell * tree
char * oid
Definition: scanneraux.h:34
char * name
Definition: scanneraux.h:35
struct script_infos * script_infos
Definition: nasl_lex_ctxt.h:30
const char * oid
Definition: nasl_lex_ctxt.h:31

References add_named_var_to_ctxt(), naslctxt::always_signed, CONST_DATA, CONST_INT, deref_cell(), naslctxt::exec_descr, FAKE_CELL, free_lex_ctxt(), get_func_ref_by_name(), TC::i_val, init_empty_lex_ctxt(), init_nasl_ctx(), naslctxt::kb, 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(), script_infos::oid, oid, struct_lex_ctxt::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_file_check(), 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 2818 of file nasl_grammar.tab.c.

2819{
2820 if (!includes_hash)
2821 return;
2822 g_hash_table_destroy (includes_hash);
2823 includes_hash = NULL;
2824}
GHashTable * includes_hash

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 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}