#include <gvm/util/kb.h>
#include <stdio.h>
Go to the source code of this file.
◆ init_nasl_ctx()
int init_nasl_ctx |
( |
naslctxt * |
pc, |
|
|
const char * |
name |
|
) |
| |
Initialize a NASL context for a NASL file.
- Parameters
-
pc | The NASL context handler. |
name | The filename of the NASL script. |
- Returns
- 0 in case of success. Then, file content is set in pc->buffer. -1 if either the filename was not found/accessible or the signature verification failed (provided signature checking is enabled. In any case, various elements of pc are modified (initialized);
Definition at line 2792 of file nasl_grammar.tab.c.
References add_nasl_inc_dir(), naslctxt::always_signed, naslctxt::buffer, checksum_algorithm, file_checksum(), inc_dirs, naslctxt::kb, naslctxt::line_nb, load_checksums(), name, nasl_set_filename(), parse_buffer, parse_len, and naslctxt::tree.
Referenced by exec_nasl_script(), and yyparse().
2794 char *full_name = NULL, key_path[2048], *checksum, *filename;
2814 while (inc_dir != NULL) {
2817 full_name = g_build_filename(inc_dir->data,
name, NULL);
2819 if ((g_file_get_contents (full_name, &pc->
buffer, &flen, NULL)))
2822 inc_dir = g_slist_next(inc_dir);
2825 if (!full_name || !pc->
buffer) {
2826 g_message (
"%s: Not able to open nor to locate it in include paths",
2839 if (strstr (full_name,
".inc"))
2840 filename = basename (full_name);
2842 filename = full_name;
2843 snprintf (key_path,
sizeof (key_path),
"signaturecheck:%s", filename);
2844 timestamp = kb_item_get_int (pc->
kb, key_path);
2847 struct stat file_stat;
2849 if (stat (full_name, &file_stat) >= 0 && timestamp > file_stat.st_mtime)
2861 snprintf (key_path,
sizeof (key_path),
"md5sums:%s", filename);
2863 snprintf (key_path,
sizeof (key_path),
"sha256sums:%s", filename);
2866 checksum = kb_item_get_str (pc->
kb, key_path);
2869 g_warning (
"No checksum for %s", full_name);
2878 ret = strcmp (check, checksum);
2880 g_warning (
"checksum for %s not matching", full_name);
2883 snprintf (key_path,
sizeof (key_path),
"signaturecheck:%s", filename);
2884 kb_item_add_int (pc->
kb, key_path, time (NULL));
static void load_checksums(kb_t kb)
static int checksum_algorithm
void nasl_set_filename(const char *filename)
int add_nasl_inc_dir(const char *dir)
Adds the given string as directory for searching for includes.
static char * parse_buffer
static char * file_checksum(const char *filename, int algorithm)
Get the checksum of a file.
◆ nasl_clean_ctx()