Browse Source
[__pf*] (~) __pf_ruleset (+)__pf_apply_anchor, deprecate __pf_apply See merge request ungleich-public/cdist!867merge-requests/846/merge
7 changed files with 103 additions and 127 deletions
@ -0,0 +1 @@
|
||||
Consider moving to __pf_apply_anchor. Get in touch if you need __pf_apply. |
@ -0,0 +1,62 @@
|
||||
cdist-type__pf_apply_anchor(7) |
||||
============================== |
||||
|
||||
NAME |
||||
---- |
||||
cdist-type__pf_apply_anchor - Apply a pf(4) anchor on $__target_host |
||||
|
||||
|
||||
DESCRIPTION |
||||
----------- |
||||
This type is used on \*BSD systems to manage anchors for the pf firewall. |
||||
|
||||
Notice this type does not take care of copying the ruleset, that must be |
||||
done by the user with, e.g. `__file`. |
||||
|
||||
|
||||
OPTIONAL PARAMETERS |
||||
------------------- |
||||
anchor_name |
||||
The name of the anchor to apply. If not set, `${__object_id}` is used. |
||||
This type requires `/etc/pf.d/${anchor_name}` to exist on |
||||
`$__target_host`. |
||||
|
||||
|
||||
EXAMPLES |
||||
-------- |
||||
|
||||
.. code-block:: sh |
||||
|
||||
# Copy anchor file to ${__target_host} |
||||
__file "/etc/pf.d/80_dns" --source - <<EOF |
||||
# Managed remotely, changes will be lost |
||||
|
||||
pass quick proto {tcp,udp} from any to any port domain |
||||
EOF |
||||
|
||||
# Apply the anchor |
||||
require="__file/etc/pf.d/80_dns" __pf_apply_anchor 80_dns |
||||
# This is roughly equivalent to: |
||||
# pfctl -a "${anchor_name}" -f "/etc/pf.d/${anchor_name}" |
||||
|
||||
|
||||
SEE ALSO |
||||
-------- |
||||
:strong:`pf`\ (4) |
||||
|
||||
|
||||
AUTHORS |
||||
------- |
||||
Evilham <contact--@--evilham.com> |
||||
Kamila Součková <coding--@--kamila.is> |
||||
Jake Guffey <jake.guffey--@--eprotex.com> |
||||
|
||||
|
||||
COPYING |
||||
------- |
||||
Copyright \(C) 2020 Evilham. |
||||
Copyright \(C) 2016 Kamila Součková. |
||||
Copyright \(C) 2012 Jake Guffey. You can redistribute it |
||||
and/or modify it under the terms of the GNU General Public License as |
||||
published by the Free Software Foundation, either version 3 of the |
||||
License, or (at your option) any later version. |
@ -0,0 +1 @@
|
||||
anchor_name |
@ -1,81 +0,0 @@
|
||||
#!/bin/sh -e |
||||
# |
||||
# 2012 Jake Guffey (jake.guffey at eprotex.com) |
||||
# |
||||
# This file is part of cdist. |
||||
# |
||||
# cdist is free software: you can redistribute it and/or modify |
||||
# it under the terms of the GNU General Public License as published by |
||||
# the Free Software Foundation, either version 3 of the License, or |
||||
# (at your option) any later version. |
||||
# |
||||
# cdist is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>. |
||||
# |
||||
# |
||||
# Manage pf(4) on *BSD |
||||
# |
||||
|
||||
# Debug |
||||
#exec >&2 |
||||
#set -x |
||||
|
||||
# Send files to $__target_host via $__remote_copy |
||||
|
||||
uname=$(uname) # Need to know what the cdist host is running so we know how to compute the ruleset's checksum |
||||
state=$(cat "$__object/parameter/state") |
||||
|
||||
if [ "$state" = "absent" ]; then # There is nothing more for a *local* script to do |
||||
exit 0 |
||||
fi |
||||
|
||||
if [ -f "$__object/parameter/source" ]; then |
||||
source=$(cat "$__object/parameter/source") |
||||
fi |
||||
|
||||
rcvar=$(cat "$__object/explorer/rcvar") |
||||
cksum=$(cat "$__object/explorer/cksum") |
||||
|
||||
|
||||
cat <<EOF |
||||
case $uname in |
||||
Darwin) |
||||
currentSum=\$(cksum -o 1 ${source} | cut '-d ' -f1) |
||||
;; |
||||
Linux) |
||||
currentSum=\$(cksum ${source} | cut '-d ' -f1) |
||||
;; |
||||
FreeBSD) |
||||
currentSum=\$(cksum -o 1 ${source} | cut -d= -f2 | sed 's/ //g') |
||||
;; |
||||
*) |
||||
echo "Sorry, I do not know how to find a cksum on ${uname}." >&2 |
||||
exit 1 |
||||
;; |
||||
esac |
||||
|
||||
# IPv6 fix |
||||
if $(echo "${__target_host}" | grep -q -E '^[0-9a-fA-F:]+$') |
||||
then |
||||
my_target_host="[${__target_host}]" |
||||
else |
||||
my_target_host="${__target_host}" |
||||
fi |
||||
|
||||
if [ -n "${cksum}" ]; then |
||||
if [ ! "\${currentSum}" = "${cksum}" ]; then |
||||
$__remote_copy "${source}" "\${my_target_host}:${rcvar}.new" |
||||
fi |
||||
else # File just doesn't exist yet |
||||
$__remote_copy "${source}" "\${my_target_host}:${rcvar}.new" |
||||
fi |
||||
EOF |
||||
|
||||
# Debug |
||||
#exec +x |
||||
|
Loading…
Reference in new issue