Initialize a NASL context for a NASL file.
2682{
2683 char *full_name = NULL, key_path[2048], *checksum, *filename;
2685 size_t flen = 0;
2686 time_t timestamp;
2687
2688
2690
2696 {
2699 }
2700 else
2702
2703
2705 while (inc_dir != NULL) {
2706 if (full_name)
2707 g_free (full_name);
2708 full_name = g_build_filename(inc_dir->data,
name, NULL);
2709
2710 if ((g_file_get_contents (full_name, &pc->
buffer, &flen, NULL)))
2711 break;
2712
2713 inc_dir = g_slist_next(inc_dir);
2714 }
2715
2716 if (!full_name || !pc->
buffer) {
2717 g_message ("%s: Not able to open nor to locate it in include paths",
2719 g_free(full_name);
2720 return -1;
2721 }
2722
2724 {
2725 g_free(full_name);
2726 return 0;
2727 }
2728
2729
2730 if (strstr (full_name, ".inc"))
2731 filename = basename (full_name);
2732 else
2733 filename = full_name;
2734 snprintf (key_path, sizeof (key_path), "signaturecheck:%s", filename);
2735 timestamp = kb_item_get_int (pc->
kb, key_path);
2736
2737
2738
2739
2740
2742 {
2743 struct stat file_stat;
2744
2745 if (stat (full_name, &file_stat) >= 0 && timestamp > file_stat.st_mtime)
2746 {
2747
2748 g_free (full_name);
2749 return 0;
2750 }
2751 }
2752
2755 return -1;
2757 snprintf (key_path, sizeof (key_path), "sha256sums:%s", filename);
2758 else
2759 abort ();
2760 checksum = kb_item_get_str (pc->
kb, key_path);
2761 if (!checksum)
2762 {
2763 g_warning ("No checksum for %s", full_name);
2764 g_free (full_name);
2765 return -1;
2766 }
2767 else
2768 {
2769 int ret;
2771
2772 snprintf (key_path, sizeof (key_path), "signaturecheck:%s", filename);
2773 ret = strcmp (check, checksum);
2774 if (ret)
2775 {
2776 kb_del_items (pc->
kb, key_path);
2777 g_warning ("checksum for %s not matching", full_name);
2778 }
2779 else
2780 {
2781 kb_del_items (pc->
kb, key_path);
2782 kb_item_add_int (pc->
kb, key_path, time (NULL));
2783 }
2784
2785 g_free (full_name);
2786 g_free (checksum);
2787 g_free (check);
2788 return ret;
2789 }
2790}
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