-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This started out as a fix for the custom service filename but spiraled a bit further during debugging. * Auto-correct the filename for firewalld::custom_service * Add a function `firewalld::safe_filename` for munging filenames to safely work with firewalld. The allowed characters were determined by experimentation and are not documented. * Ensure that firewalld_zone resources automatically reload the firewall * Ensure that firewalld_zone names are no longer than 17 characters per the manual * Create firewalld::reload and firewalld::reload::complete classes to allow easier resource chaining * Fix spacing in init.pp * Ensure that all of the Execs that call firewall-cmd happen after the service is running * Ensure that all permanent configuration changes happen before the firewalld service is started/restarted. This is critical if switching from nft to iptables due to the segfault bug in nft * Ensure that all custom service declarations happen before all firewalld_zone resources are triggered. This is automatic in all native types * Updated the service.xml.erb to an EPP file Closes #265
- Loading branch information
1 parent
a4ef580
commit 26ec34f
Showing
13 changed files
with
425 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# @summary Returns a string that is safe for firewalld filenames | ||
# | ||
# @example Regular Filename | ||
# $filename = 'B@d Characters!' | ||
# firewalld::safe_filename($orig_string) | ||
# | ||
# Result => 'B_d_Characters_' | ||
# | ||
# @example Filename with Options | ||
# $filename = 'B@d Characters!.txt' | ||
# firewalld::safe_filename( | ||
# $filename, | ||
# { | ||
# 'replacement_string' => '@@', | ||
# 'file_extension' => '.txt' | ||
# } | ||
# ) | ||
# | ||
# Result => 'B@@d@@Characters@@.txt' | ||
# | ||
# @param filename | ||
# The String to process | ||
# | ||
# @param options | ||
# Various processing options | ||
# | ||
# @param options [String[1]] replacement_string | ||
# The String to use when replacing invalid characters | ||
# | ||
# @option options [String[1]] file_extension | ||
# This will be stripped from the end of the string prior to processing and | ||
# re-added afterwards | ||
# | ||
# @return [String] | ||
# Processed string | ||
# | ||
function firewalld::safe_filename( | ||
String[1] $filename, | ||
Struct[ | ||
{ | ||
'replacement_string' => String[1], | ||
'file_extension' => Optional[String[1]] | ||
} | ||
] $options = { 'replacement_string' => '_'} | ||
) { | ||
|
||
# If we have an extension defined | ||
if $options['file_extension'] { | ||
|
||
# See if the string ends with the extension | ||
$_extension_length = length($options['file_extension']) | ||
if $filename[-($_extension_length), -1] == $options['file_extension'] { | ||
|
||
# And extract the base filename | ||
$_basename = $filename[0, -($_extension_length) - 1] | ||
} | ||
} | ||
|
||
# If we extraced a base filename substitute on that and re-add the file extension | ||
if defined('$_basename') { | ||
sprintf('%s%s', | ||
regsubst($_basename, '[^\w-]', $options['replacement_string'], 'G'), | ||
$options['file_extension'] | ||
) | ||
} | ||
# Otherwise, just substitute on the original filename | ||
else { | ||
regsubst($filename, '[^\w-]', $options['replacement_string'], 'G') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.