Skip to content

Commit 8d9170d

Browse files
committed
lua: support lua rules
Add lua to the list of keywords that reference files and copy in place. Makes use of the filehash function, so make that function more generic for embedded files. Ticket: #6395
1 parent fd52465 commit 8d9170d

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

suricata/update/main.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
INDEX_EXPIRATION_TIME = 60 * 60 * 24 * 14
9898

9999
# Rule keywords that come with files
100-
file_kw = ["filemd5", "filesha1", "filesha256", "dataset"]
100+
file_kw = ["filemd5", "filesha1", "filesha256", "dataset", "lua"]
101101

102102
def strict_error(msg):
103103
logger.error(msg)
@@ -501,22 +501,22 @@ def handle_dataset_files(rule, dep_files):
501501
fp.write(dataset_contents.decode("utf-8"))
502502
return new_rule
503503

504-
def handle_filehash_files(rule, dep_files, fhash):
504+
def handle_embedded_file(rule, dep_files, kw):
505505
if not rule.enabled:
506506
return
507-
filehash_fname = rule.get(fhash)
507+
embedded_filename = rule.get(kw)
508508

509509
# Get the directory name the rule is from.
510510
prefix = os.path.dirname(rule.group)
511511

512-
source_filename = os.path.join(prefix, filehash_fname)
512+
source_filename = os.path.join(prefix, embedded_filename)
513513
dest_filename = source_filename[len(prefix) + len(os.path.sep):]
514514
logger.debug("dest_filename={}".format(dest_filename))
515515

516516
if source_filename not in dep_files:
517-
logger.error("{} file {} was not found".format(fhash, filehash_fname))
517+
logger.error("{} file {} was not found".format(kw, embedded_filename))
518518
else:
519-
logger.debug("Copying %s file %s to output directory" % (fhash, filehash_fname))
519+
logger.debug("Copying %s file %s to output directory" % (kw, embedded_filename))
520520
filepath = os.path.join(config.get_output_dir(), os.path.dirname(dest_filename))
521521
logger.debug("filepath: %s" % filepath)
522522
try:
@@ -525,7 +525,7 @@ def handle_filehash_files(rule, dep_files, fhash):
525525
if oserr.errno != errno.EEXIST:
526526
logger.error(oserr)
527527
sys.exit(1)
528-
output_filename = os.path.join(filepath, os.path.basename(filehash_fname))
528+
output_filename = os.path.join(filepath, os.path.basename(embedded_filename))
529529
logger.debug("output fname: %s" % output_filename)
530530
with open(output_filename, "w") as fp:
531531
fp.write(dep_files[source_filename].decode("utf-8"))
@@ -572,7 +572,7 @@ def write_merged(filename, rulemap, dep_files):
572572
if "dataset" == kw:
573573
reformatted = handle_dataset_files(rule, dep_files)
574574
else:
575-
handle_filehash_files(rule, dep_files, kw)
575+
handle_embedded_file(rule, dep_files, kw)
576576
if reformatted:
577577
print(reformatted, file=fileobj)
578578
else:
@@ -633,7 +633,7 @@ def write_to_directory(directory, files, rulemap, dep_files):
633633
if "dataset" == kw:
634634
reformatted = handle_dataset_files(rulemap[rule.id], dep_files)
635635
else:
636-
handle_filehash_files(rulemap[rule.id], dep_files, kw)
636+
handle_embedded_file(rulemap[rule.id], dep_files, kw)
637637
if reformatted:
638638
content.append(reformatted)
639639
else:

0 commit comments

Comments
 (0)