Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use cookie to ensure write to a valid rule dir #302

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions suricata/update/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,13 @@ def write_to_directory(directory, files, rulemap, dep_files):
modified = []

oldset = {}

cookie_path = os.path.join(directory, ".suricata-update")
if os.path.exists(directory):
if not os.path.exists(cookie_path) and os.listdir(directory):
logger.error("{} -- doesn't look like a suricata-update rule directory".format(directory))
sys.exit(1)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasonish do you think this is as per your expectations?
Questions:

  1. How do we ensure that this does not break the current setups? Because we don't have a cookie already in the rule dir.
  2. Is checking for dir good enough for determining "first run"?
  3. Should the cookie be in say <prefix>/suricata or <prefix>/suricata/rules


if not args.quiet:
for file in files:
outpath = os.path.join(
Expand All @@ -535,6 +542,7 @@ def write_to_directory(directory, files, rulemap, dep_files):
len(removed),
len(modified)))

open(cookie_path).close()
for file in sorted(files):
outpath = os.path.join(
directory, os.path.basename(file.filename))
Expand Down