#!/usr/bin/perl -w
# compares cached embargo state against SMASH
use strict;

my $dn = `dirname $0`;chomp($dn);
my $pwd = `pwd`;chomp($pwd);
if ($dn !~ /^\//) { $dn = $pwd . "/" . $dn; }
push @INC,$dn;

require CanDBReader;
require SMASHData;

#foreach my $cve (sort keys %CanDBReader::embargoed) {
#	if (!defined($SMASHData::embargoedcves{$cve})) {
#		next if (defined($CanDBReader::advisoryids{$cve})); 	# if we released an update, the page is not hidden
#		print "$cve: embargoed in local db, but not in SMASH\n";
#	}
#}

#foreach my $cve (sort keys %SMASHData::embargoedcves) {
#	if (!defined($CanDBReader::embargoed{$cve})) {
#		print "$cve: embargoed in smash db, but not in local db?\n";
#	}
#}

# avoid warnings
delete $SMASHData::references{"0"};
delete $SMASHData::embargoedcves{"0"};


my @text = ();

foreach my $cve (sort keys %SMASHData::embargoedcves) {
	&SMASHData::read_smash_issue($cve,1);

	my %references = %{$SMASHData::references{$cve}};
	my $printed = 0;
	foreach my $reference (sort keys %references) {
		next if ($references{$reference} =~ /smash.suse.de/);
		next if ($references{$reference} =~ /bugzilla.suse.com/);
		next if ($references{$reference} =~ /jira.suse.com/);
		next if ($references{$reference} =~ /web.nvd.nist.gov/);	# autoinjected by SMASH even if not there
		if (!$printed) {
			push @text,"$cve has following references:\n";
			$printed = 1;
		}
		push @text, "\t$reference: ". $references{$reference} . "\n";
	}
}

if (@text) {
	print "Hi,\nFound embargoed CVE entries which have public references.\nPlease check if the bugs can be made public or if there was a leak.\n";
	print @text;
	print "\nCiao, $0\n";
}
