Initialize a NASL context for a NASL file.
2697{
2698 char *full_name = NULL, key_path[2048], *checksum, *filename;
2700 size_t flen = 0;
2701 time_t timestamp;
2702
2703
2705
2711 {
2714 }
2715 else
2717
2718
2720 while (inc_dir != NULL) {
2721 if (full_name)
2722 g_free (full_name);
2723 full_name = g_build_filename(inc_dir->data,
name, NULL);
2724
2725 if ((g_file_get_contents (full_name, &pc->
buffer, &flen, NULL)))
2726 break;
2727
2728 inc_dir = g_slist_next(inc_dir);
2729 }
2730
2731 if (!full_name || !pc->
buffer) {
2732 g_message ("%s: Not able to open nor to locate it in include paths",
2734 g_free(full_name);
2735 return -1;
2736 }
2737
2739 {
2740 g_free(full_name);
2741 return 0;
2742 }
2743
2744
2745 if (strstr (full_name, ".inc"))
2746 filename = basename (full_name);
2747 else
2748 filename = full_name;
2749 snprintf (key_path, sizeof (key_path), "signaturecheck:%s", filename);
2750 timestamp = kb_item_get_int (pc->
kb, key_path);
2751
2752
2753
2754
2755
2757 {
2758 struct stat file_stat;
2759
2760 if (stat (full_name, &file_stat) >= 0 && timestamp > file_stat.st_mtime)
2761 {
2762
2763 g_free (full_name);
2764 return 0;
2765 }
2766 }
2767
2770 return -1;
2772 snprintf (key_path, sizeof (key_path), "sha256sums:%s", filename);
2773 else
2774 abort ();
2775 checksum = kb_item_get_str (pc->
kb, key_path);
2776 if (!checksum)
2777 {
2778 g_warning ("No checksum for %s", full_name);
2779 g_free (full_name);
2780 return -1;
2781 }
2782 else
2783 {
2784 int ret;
2786
2787 snprintf (key_path, sizeof (key_path), "signaturecheck:%s", filename);
2788 ret = strcmp (check, checksum);
2789 if (ret)
2790 {
2791 kb_del_items (pc->
kb, key_path);
2792 g_warning ("checksum for %s not matching", full_name);
2793 }
2794 else
2795 {
2796 kb_del_items (pc->
kb, key_path);
2797 kb_item_add_int (pc->
kb, key_path, time (NULL));
2798 }
2799
2800 g_free (full_name);
2801 g_free (checksum);
2802 g_free (check);
2803 return ret;
2804 }
2805}
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
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