Initialize a NASL context for a NASL file.
2724{
2725 char *full_name = NULL, key_path[2048], *checksum;
2726 const char *filename;
2728 size_t flen = 0;
2729 time_t timestamp;
2730
2731
2733
2739 {
2742 }
2743 else
2745
2746
2748 while (inc_dir != NULL) {
2749 if (full_name)
2750 g_free (full_name);
2751 full_name = g_build_filename(inc_dir->data,
name, NULL);
2752
2753 if ((g_file_get_contents (full_name, &pc->
buffer, &flen, NULL)))
2754 break;
2755
2756 inc_dir = g_slist_next(inc_dir);
2757 }
2758
2759
2760verify:
2761 if (!full_name || !pc->
buffer) {
2762 g_message ("%s: Not able to open nor to locate it in include paths",
2764 g_free(full_name);
2765 return -1;
2766 }
2767
2769 {
2770 g_free(full_name);
2771 return 0;
2772 }
2773
2774
2775
2777
2778
2779 snprintf (key_path, sizeof (key_path), "signaturecheck:%s", filename);
2780 timestamp = kb_item_get_int (pc->
kb, key_path);
2781
2782
2783
2784
2785
2787 {
2788 struct stat file_stat;
2789
2790 if (stat (full_name, &file_stat) >= 0 && timestamp > file_stat.st_mtime)
2791 {
2792
2793 g_free (full_name);
2794 return 0;
2795 }
2796 }
2797
2800 return -1;
2802 snprintf (key_path, sizeof (key_path), "sha256sums:%s", filename);
2803 else
2804 abort ();
2805 checksum = kb_item_get_str (pc->
kb, key_path);
2806 if (!checksum)
2807 {
2808
2809
2810
2811
2812 if (parent == NULL) {
2813 g_warning ("No checksum for %s (%s)", full_name, filename);
2814 g_free(full_name);
2815 return -1;
2816 }
2817 g_free(full_name);
2819 parent = NULL;
2820 goto verify;
2821 }
2822 else
2823 {
2824 int ret;
2826
2827 snprintf (key_path, sizeof (key_path), "signaturecheck:%s", filename);
2828 ret = strcmp (check, checksum);
2829 if (ret)
2830 {
2831 kb_del_items (pc->
kb, key_path);
2832 g_warning ("checksum for %s not matching (%s)", full_name, key_path);
2833 }
2834 else
2835 {
2836 kb_del_items (pc->
kb, key_path);
2837 kb_item_add_int (pc->
kb, key_path, time (NULL));
2838 }
2839
2840 g_free (full_name);
2841 g_free (checksum);
2842 g_free (check);
2843 return ret;
2844 }
2845}
void nasl_set_filename(const char *filename)
static char * file_checksum(const char *filename, int algorithm)
Get the checksum of a file.
static int checksum_algorithm
static char * parse_buffer
static char * fullname_based_on_parent(const char *path, const char *filename)
static const char * remove_base(const char *path)
int add_nasl_inc_dir(const char *dir)
Adds the given string as directory for searching for includes.
static void load_checksums(kb_t kb)
unsigned int include_order