#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 2894 of file nasl_grammar.tab.c.
2896 char *full_name = NULL, key_path[2048], *checksum, *filename;
2916 while (inc_dir != NULL) {
2919 full_name = g_build_filename(inc_dir->data,
name, NULL);
2921 if ((g_file_get_contents (full_name, &pc->
buffer, &flen, NULL)))
2924 inc_dir = g_slist_next(inc_dir);
2927 if (!full_name || !pc->
buffer) {
2928 g_message (
"%s: Not able to open nor to locate it in include paths",
2941 if (strstr (full_name,
".inc"))
2942 filename = basename (full_name);
2944 filename = full_name;
2945 snprintf (key_path,
sizeof (key_path),
"signaturecheck:%s", filename);
2946 timestamp = kb_item_get_int (pc->
kb, key_path);
2949 struct stat file_stat;
2951 if (stat (full_name, &file_stat) >= 0 && timestamp > file_stat.st_mtime)
2963 snprintf (key_path,
sizeof (key_path),
"md5sums:%s", filename);
2965 snprintf (key_path,
sizeof (key_path),
"sha256sums:%s", filename);
2968 checksum = kb_item_get_str (pc->
kb, key_path);
2971 g_warning (
"No checksum for %s", full_name);
2980 ret = strcmp (check, checksum);
2982 g_warning (
"checksum for %s not matching", full_name);
2985 snprintf (key_path,
sizeof (key_path),
"signaturecheck:%s", filename);
2986 kb_item_add_int (pc->
kb, key_path, time (NULL));
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().
◆ nasl_clean_ctx()