diff --git a/LICENSE b/LICENSE.txt index 10926e8..10926e8 100644 --- a/LICENSE +++ b/LICENSE.txt diff --git a/dyndns.pl b/dyndns.pl index f6e1a21..504608c 100755 --- a/dyndns.pl +++ b/dyndns.pl @@ -138,7 +138,28 @@ sub expand_CNAME($;$) { return $host; } -# Method to perform an DNS Update for a single host +# Get signer and key CGI paramseters, abort with HTTP 400 error if not present +sub get_authinfo($$) { + my ($cgi, $host) = @_; + + # Get signer and key parameters + my $signer = ($AuthMode eq 'static') ? $StaticSigner : ($cgi->param('user') + || (($AuthMode eq 'both') ? $StaticSigner : $host)); + my $key = ($AuthMode eq 'static') ? $StaticKey : ($cgi->param('secret') + || (($AuthMode eq 'both') ? $StaticSigner : undef)); + + # Ensure we have a value for signer and key, otherwise abort the processing + if($signer eq '' or $key eq '') { + print $cgi->header(-status=>400, -type=>'text/plain'), + "ERROR - No/incomplete authentication information provided\n"; + exit + } + + # and return the values + return($signer, $key); +} + +# Perform an DNS Update for a single host sub DNS_Update($$$$$$$) { my ($dnsdomain, $dnshost, $ipv4, $ipv6, $signer, $key, $debug) = @_; my $dnsupdate = Net::DNS::Update->new($dnsdomain); @@ -190,12 +211,7 @@ sub DNS_Update($$$$$$$) { # Handlers for the different requests sub handle_update($$$$$$) { my ($cgi, $mode, $host, $dnshost, $dnsdomain, $debug) = @_; - - # Get signer and key parameters - my $signer = ($AuthMode eq 'static') ? $StaticSigner : ($cgi->param('user') - || (($AuthMode eq 'both') ? $StaticSigner : $host)); - my $key = ($AuthMode eq 'static') ? $StaticKey : ($cgi->param('secret') - || (($AuthMode eq 'both') ? $StaticSigner : undef)); + my ($signer, $key) = get_authinfo($cgi, $host); # perform the action my ($statuscode, $statusmessage); @@ -221,13 +237,8 @@ sub handle_update($$$$$$) { sub handle_expire($$$$$$) { my ($cgi, $mode, $host, $dnshost, $dnsdomain, $debug) = @_; + my ($signer, $key) = get_authinfo($cgi, $host); - # Get signer and key parameters - my $signer = ($AuthMode eq 'static') ? $StaticSigner : ($cgi->param('user') - || (($AuthMode eq 'both') ? $StaticSigner : $host)); - my $key = ($AuthMode eq 'static') ? $StaticKey : ($cgi->param('secret') - || (($AuthMode eq 'both') ? $StaticSigner : undef)); - my $debugmsg = ($debug) ? "\n" : ''; # perform the action