]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Enforce malware database download from Abuse.ch
authorEric Bollengier <eric@baculasystems.com>
Wed, 17 Apr 2024 07:39:31 +0000 (09:39 +0200)
committerEric Bollengier <eric@baculasystems.com>
Wed, 17 Apr 2024 07:41:18 +0000 (09:41 +0200)
bacula/scripts/get_malware_abuse.ch
bacula/scripts/md5tobase64.py

index 22d4536aa96d16cb088b72c53fc8a1094f4d7898..0f310fe53f9994223195334e1a53007032ca554c 100755 (executable)
@@ -78,7 +78,7 @@ open(FP, "curl --silent $url $uncompress | $dir/md5tobase64.py|") or die "Unable
 while (my $l = <FP>) {
     print FP2 $l;
 }
-close(FP);
+close(FP) or die "Unable to download $url database";
 close(FP2);
 
 print "$dest\n";
index 893cb0fc8c8d41ea627803c75392d333bdfb7cf8..7e376afca31ac3cd7d6325d0dfd1ba30a1afbb23 100755 (executable)
@@ -18,6 +18,7 @@ parser.add_argument('--keep-padding', action='store_true', help="keep the '=' at
 args=parser.parse_args()
 
 def handle_file(input_file, remove_padding):
+    nb=0
     for line in input_file:
         line=line.rstrip()
         if md5_re.match(line):
@@ -27,13 +28,19 @@ def handle_file(input_file, remove_padding):
             if remove_padding:
                 b64=b64.rstrip('=')
             print(b64)
+            nb = nb + 1
+    return nb
 
+nb=0
 remove_padding=not args.keep_padding
 if args.file:
     for filename in args.file:
         input_file=open(filename)
-        handle_file(input_file, remove_padding)
+        nb += handle_file(input_file, remove_padding)
 else:
     # use stdin
-    handle_file(sys.stdin, remove_padding)
+    nb += handle_file(sys.stdin, remove_padding)
+
+# Raise an error if we have converted nothing
+sys.exit(nb == 0)