From 23dad564bea051efec2ed104d943539bdd63a0d8 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Wed, 17 Jul 2024 22:52:33 -0400 Subject: [PATCH 1/2] dyndns2: Expand rationale for not checking returned IP --- ddclient.in | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ddclient.in b/ddclient.in index 409bd3b..5b493b7 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4129,8 +4129,11 @@ sub nic_dyndns2_update { failed("updating %s: Could not connect to %s.", $hosts, $groupcfg{'server'}); next; } - # The IP address normally comes after the status, but we ignore it. (Some services do not - # return the IP so we can't rely on it anyway.) + # The IP address normally comes after the status, but we ignore it. We could compare it + # with the expected address and mark the update as failed if it differs, but (1) some + # services do not return the IP; and (2) comparison is brittle (e.g., 192.000.002.001 + # vs. 192.0.2.1) and false errors could cause high load on the service (an update attempt + # every min-error-interval instead of every max-interval). (my $status = $line) =~ s/ .*$//; if ($status eq 'nochg') { warning("updating %s: %s: %s", $hosts, $status, $errors{$status}); From d88e6438efbc53e977546693f6835f7517072a06 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Thu, 18 Jul 2024 03:30:34 -0400 Subject: [PATCH 2/2] Revert "Merge pull request #702 from rhansen/dyndns2" I misread the original code and introduced a bug. This reverts the entire PR so that I can redo it. This reverts commit 9eff7404e3902aa74bc9af38f246662056baf152, reversing changes made to 60f931e7da1dc8e57b1d79d44cd01029ad2e3480. --- ddclient.in | 111 +++++++++++++++++++++++++--------------------------- 1 file changed, 53 insertions(+), 58 deletions(-) diff --git a/ddclient.in b/ddclient.in index 5b493b7..c13e355 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4050,6 +4050,7 @@ EoEXAMPLE ###################################################################### sub nic_dyndns2_update { debug("\nnic_dyndns2_update -------------------"); + my @groups = group_hosts_by(\@_, qw(login password server script static custom wildcard mx backupmx wantipv4 wantipv6)); my %errors = ( 'badauth' => 'Bad authorization (username or password)', 'badsys' => 'The system parameter given was not valid', @@ -4063,20 +4064,7 @@ sub nic_dyndns2_update { 'dnserr' => 'System error: DNS error encountered. Contact support@dyndns.org', 'nochg' => 'No update required; unnecessary attempts to change to the current address are considered abusive', ); - my @group_by_attrs = qw( - backupmx - custom - login - mx - password - script - server - static - wantipv4 - wantipv6 - wildcard - ); - for my $group (group_hosts_by(\@_, @group_by_attrs)) { + for my $group (@groups) { my @hosts = @{$group->{hosts}}; my %groupcfg = %{$group->{cfg}}; my $hosts = join(',', @hosts); @@ -4121,54 +4109,61 @@ sub nic_dyndns2_update { next; } next if !header_ok($hosts, $reply); - # Some services can return 200 OK even if there is an error (e.g., bad authentication, - # updates too frequent) so the body of the response must also be checked. - (my $body = $reply) =~ s/^.*?\n\n//s; - my ($line) = grep(qr/^results/, split(qr/\n/, $body)); - if (!$line) { - failed("updating %s: Could not connect to %s.", $hosts, $groupcfg{'server'}); - next; - } - # The IP address normally comes after the status, but we ignore it. We could compare it - # with the expected address and mark the update as failed if it differs, but (1) some - # services do not return the IP; and (2) comparison is brittle (e.g., 192.000.002.001 - # vs. 192.0.2.1) and false errors could cause high load on the service (an update attempt - # every min-error-interval instead of every max-interval). - (my $status = $line) =~ s/ .*$//; - if ($status eq 'nochg') { - warning("updating %s: %s: %s", $hosts, $status, $errors{$status}); - $status = 'good'; - } - for my $h (@hosts) { - $config{$h}{'status-ipv4'} = $status if $ipv4; - $config{$h}{'status-ipv6'} = $status if $ipv6; - } - if ($status ne 'good') { - if (exists($errors{$status})) { - failed("updating %s: %s: %s", $hosts, $status, $errors{$status}); - } elsif ($status =~ qr/w(\d+)(.)/) { - my ($wait, $units) = ($1, lc $2); - my ($sec, $scale) = ($wait, 1); - ($scale, $units) = (1, 'seconds') if $units eq 's'; - ($scale, $units) = (60, 'minutes') if $units eq 'm'; - ($scale, $units) = (60*60, 'hours') if $units eq 'h'; - $sec = $wait * $scale; + my @reply = split /\n/, $reply; + my $state = 'header'; + for my $line (@reply) { + if ($state eq 'header') { + $state = 'body'; + } elsif ($state eq 'body') { + $state = 'results' if $line eq ''; + } elsif ($state =~ /^results/) { + $state = 'results2'; + # bug #10: some dyndns providers does not return the IP so + # we can't use the returned IP + my ($status, $returnedips) = split / /, lc $line; for my $h (@hosts) { - $config{$h}{'wtime'} = $now + $sec; + $config{$h}{'status-ipv4'} = $status if $ipv4; + $config{$h}{'status-ipv6'} = $status if $ipv6; + } + if ($status eq 'good') { + for my $h (@hosts) { + $config{$h}{'ipv4'} = $ipv4 if $ipv4; + $config{$h}{'ipv6'} = $ipv6 if $ipv6; + $config{$h}{'mtime'} = $now; + } + success("updating %s: %s: IPv4 address set to %s", $hosts, $status, $ipv4) if $ipv4; + success("updating %s: %s: IPv6 address set to %s", $hosts, $status, $ipv6) if $ipv6; + } elsif (exists $errors{$status}) { + if ($status eq 'nochg') { + warning("updating %s: %s: %s", $hosts, $status, $errors{$status}); + for my $h (@hosts) { + $config{$h}{'ipv4'} = $ipv4 if $ipv4; + $config{$h}{'ipv6'} = $ipv6 if $ipv6; + $config{$h}{'mtime'} = $now; + $config{$h}{'status-ipv4'} = 'good' if $ipv4; + $config{$h}{'status-ipv6'} = 'good' if $ipv6; + } + } else { + failed("updating %s: %s: %s", $hosts, $status, $errors{$status}); + } + } elsif ($status =~ /w(\d+)(.)/) { + my ($wait, $units) = ($1, lc $2); + my ($sec, $scale) = ($wait, 1); + ($scale, $units) = (1, 'seconds') if $units eq 's'; + ($scale, $units) = (60, 'minutes') if $units eq 'm'; + ($scale, $units) = (60*60, 'hours') if $units eq 'h'; + $sec = $wait * $scale; + for my $h (@hosts) { + $config{$h}{'wtime'} = $now + $sec; + } + warning("updating %s: %s: wait %s %s before further updates", $hosts, $status, $wait, $units); + } else { + failed("updating %s: unexpected status (%s)", $hosts, $line); } - warning("updating %s: %s: wait %s %s before further updates", $hosts, $status, $wait, $units); - } else { - failed("updating %s: unexpected status (%s)", $hosts, $line); } - next; } - for my $h (@hosts) { - $config{$h}{'ipv4'} = $ipv4 if $ipv4; - $config{$h}{'ipv6'} = $ipv6 if $ipv6; - $config{$h}{'mtime'} = $now; - } - success("updating %s: %s: IPv4 address set to %s", $hosts, $status, $ipv4) if $ipv4; - success("updating %s: %s: IPv6 address set to %s", $hosts, $status, $ipv6) if $ipv6; + failed("updating %s: Could not connect to %s.", $hosts, $groupcfg{'server'}) + if $state ne 'results2'; } }