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

dns/rfc2136: delete cache files if nsupdate failed #4057

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
16 changes: 14 additions & 2 deletions dns/rfc2136/src/etc/inc/plugins.inc.d/rfc2136.inc
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,26 @@ function rfc2136_configure_do($verbose = false, $int = '', $updatehost = '', $fo
if ($need_update) {
@file_put_contents("/var/etc/nsupdatecmds{$i}", $upinst);
unset($upinst);

/* invoke nsupdate */
$cmd = "/usr/local/bin/nsupdate -k {$keyfile}";
if (isset($dnsupdate['usetcp'])) {
$cmd .= " -v";
}

$cmd .= " /var/etc/nsupdatecmds{$i}";
Copy link
Member

Choose a reason for hiding this comment

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

Looking at the code, this stuff could really use a rewrite. The current code actually has a race condition if you ask me, the cache files(s) should only be written after an successful update, which currently isn't the case.

A short term solution could be to keep the mwexec_bg($cmd); and wrap the update action in a new shell script (src/bin/nsupdate.sh), although Ideally one should then also change the rfc2136_cache_file function to something easily predictable using the same key. If these cache files are not used anywhere else, it might be an option to calculate one key which is then used for all files (e.g. {$dnsupdate['interface']}_{$dnsupdate['host']}_{$dnsupdate['server']}{$ipver}).

The files being /var/etc/nsupdatecmds{$key}, /var/etc/nsupdatekey{$key}, /var/cache/rfc2136_{$key}_4.cache and /var/cache/rfc2136_{$key}_6.cache.

I'm not sure how to feed the complete action to /usr/sbin/daemon, but if we push it in a simple script, we only need to pass the new key and the value of usetcp, after which we could do something like:

/usr/local/bin/nsupdate -k ... || rm {both cache files}

I'm not using this myself (also don't have a test setup), but this is a direction that could work in my opinion.

Copy link
Author

Choose a reason for hiding this comment

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

You're right, creating the cache files after the nsupdate was successful would be a better way. I try to implement that in the next week.

mwexec_bg($cmd);
unset($cmd);

//mwexec_bg($cmd);
$out = shell_exec($cmd." 2>&1; echo $?");
$status = ((int)trim(end(explode("\n", trim($out)))));

if ($status > 0) {
@unlink($cacheFile);
@unlink($cacheFile6);
log_error("Dynamic DNS: update failed, delete cache files");
}

unset($cmd, $status);
}
}

Expand Down