forked from p15670423/monkey
Common: Improve the style of filename validation
This commit is contained in:
parent
2503e83dde
commit
068a7e3b1f
|
@ -12,20 +12,15 @@ from .agent_sub_configurations import (
|
||||||
TCPScanConfiguration,
|
TCPScanConfiguration,
|
||||||
)
|
)
|
||||||
from .utils import freeze_lists
|
from .utils import freeze_lists
|
||||||
from .validators.filenames import (
|
from .validators.filenames import validate_linux_filename, validate_windows_filename
|
||||||
valid_linux_custom_pba_filename_regex,
|
|
||||||
validate_windows_custom_pba_filename,
|
|
||||||
)
|
|
||||||
from .validators.ip_ranges import validate_ip, validate_subnet_range
|
from .validators.ip_ranges import validate_ip, validate_subnet_range
|
||||||
|
|
||||||
|
|
||||||
class CustomPBAConfigurationSchema(Schema):
|
class CustomPBAConfigurationSchema(Schema):
|
||||||
linux_command = fields.Str()
|
linux_command = fields.Str()
|
||||||
linux_filename = fields.Str(
|
linux_filename = fields.Str(validate=validate_linux_filename)
|
||||||
validate=validate.Regexp(regex=valid_linux_custom_pba_filename_regex)
|
|
||||||
)
|
|
||||||
windows_command = fields.Str()
|
windows_command = fields.Str()
|
||||||
windows_filename = fields.Str(validate=validate_windows_custom_pba_filename)
|
windows_filename = fields.Str(validate=validate_windows_filename)
|
||||||
|
|
||||||
@post_load
|
@post_load
|
||||||
def _make_custom_pba_configuration(self, data, **kwargs):
|
def _make_custom_pba_configuration(self, data, **kwargs):
|
||||||
|
|
|
@ -3,13 +3,18 @@ from pathlib import PureWindowsPath
|
||||||
|
|
||||||
from marshmallow import ValidationError
|
from marshmallow import ValidationError
|
||||||
|
|
||||||
valid_windows_custom_pba_filename_regex = re.compile(r"^[^<>:\"\\\/|?*]*[^<>:\"\\\/|?* \.]+$|^$")
|
_valid_windows_filename_regex = re.compile(r"^[^<>:\"\\\/|?*]*[^<>:\"\\\/|?* \.]+$|^$")
|
||||||
valid_linux_custom_pba_filename_regex = re.compile(r"^[^\0/]*$")
|
_valid_linux_filename_regex = re.compile(r"^[^\0/]*$")
|
||||||
|
|
||||||
|
|
||||||
def validate_windows_custom_pba_filename(windows_filename: str):
|
def validate_linux_filename(linux_filename: str):
|
||||||
|
if not re.match(_valid_linux_filename_regex, linux_filename):
|
||||||
|
raise ValidationError(f"Invalid Unix filename {linux_filename}: illegal characters")
|
||||||
|
|
||||||
|
|
||||||
|
def validate_windows_filename(windows_filename: str):
|
||||||
validate_windows_filename_not_reserved(windows_filename)
|
validate_windows_filename_not_reserved(windows_filename)
|
||||||
if not re.match(valid_windows_custom_pba_filename_regex, windows_filename):
|
if not re.match(_valid_windows_filename_regex, windows_filename):
|
||||||
raise ValidationError(f"Invalid Windows filename {windows_filename}: illegal characters")
|
raise ValidationError(f"Invalid Windows filename {windows_filename}: illegal characters")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue