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

Added zone-serial increment support for dns_nsd challenge #5241

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
22 changes: 22 additions & 0 deletions dnsapi/dns_nsd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ Options:
Issues: github.com/acmesh-official/acme.sh/issues/2245
'

# args: zonefile
_local_nsd_get_serial()
{
local _zone_file="$1"
cat "$_zone_file" | \
sed -n '/IN[ \t]*SOA.*/,/[)]/p' | \
sed 's/\([^;]\);\(.*\)/\1/g' | \
sed -z 's/\n//g' | \
sed 's/\([^(]*\)[(]\([^)]*\)[)]/\2/g' | \
sed 's/\([ \t]*\)\([0-9]*\)\(.*\)/\2/g'
}

# args: fulldomain txtvalue
dns_nsd_add() {
fulldomain=$1
Expand Down Expand Up @@ -37,6 +49,16 @@ dns_nsd_add() {
_savedomainconf Nsd_Command "$Nsd_Command"

echo "$fulldomain. $ttlvalue IN TXT \"$txtvalue\"" >>"$Nsd_ZoneFile"

# Updating serial. The idea is that we'll parse out the old serial first,
# generate a new one by incrementing, then sed-replace the old by the new one.
local zone_serial=$(_local_nsd_get_serial "$Nsd_ZoneFile")
local zone_serial_next=$[$zone_serial+1]
local tmp_zonefile=$(mktemp)
cat "$Nsd_ZoneFile" | sed "s/$zone_serial/$zone_serial_next/" > "$tmp_zonefile"
cat "$tmp_zonefile" > "$Nsd_ZoneFile"
rm -rf "$tmp_zonefile"

_info "Added TXT record for $fulldomain"
_debug "Running $Nsd_Command"
if eval "$Nsd_Command"; then
Expand Down