Commit version 24.12.13800

This commit is contained in:
2025-01-06 17:35:06 -05:00
parent b7f6a79c2c
commit 55d9218816
6133 changed files with 4239740 additions and 1374287 deletions

View File

@ -120,8 +120,11 @@ class Net_DNS2_BitMap
//
// get the type id for the RR
//
$type = @Net_DNS2_Lookups::$rr_types_by_name[$rr];
if (isset($type)) {
$type = null;
if (isset(Net_DNS2_Lookups::$rr_types_by_name[$rr]) == true) {
$type = Net_DNS2_Lookups::$rr_types_by_name[$rr];
//
// skip meta types or qtypes
@ -138,8 +141,12 @@ class Net_DNS2_BitMap
// if it's not found, then it must be defined as TYPE<id>, per
// RFC3845 section 2.2, if it's not, we ignore it.
//
list($name, $type) = explode('TYPE', $rr);
if (!isset($type)) {
list($name, $index) = explode('TYPE', $rr);
if ( (strlen($index) > 0) && (is_numeric($index) == true) ) {
$type = $index;
} else {
continue;
}

View File

@ -44,10 +44,17 @@ class Net_DNS2_Cache_File extends Net_DNS2_Cache
//
// check that the file exists first
//
if ( ($this->cache_opened == false)
&& (file_exists($this->cache_file) == true)
&& (filesize($this->cache_file) > 0)
) {
if ( ($this->cache_opened == false) && (file_exists($this->cache_file) == true) ) {
//
// check the file size
//
$file_size = filesize($this->cache_file);
if ( ($file_size === false) || ($file_size <= 0) ) {
return;
}
//
// open the file for reading
//
@ -62,7 +69,7 @@ class Net_DNS2_Cache_File extends Net_DNS2_Cache
//
// read the file contents
//
$data = fread($fp, filesize($this->cache_file));
$data = fread($fp, $file_size);
$decoded = null;
@ -137,29 +144,39 @@ class Net_DNS2_Cache_File extends Net_DNS2_Cache
fseek($fp, 0, SEEK_SET);
//
// read the file contents
//
$data = @fread($fp, filesize($this->cache_file));
if ( ($data !== false) && (strlen($data) > 0) ) {
// get the file size first; in PHP 8.0 fread() was changed to throw an exception if you try
// and read 0 bytes from a file.
//
$file_size = @filesize($this->cache_file);
if ( ($file_size !== false) && ($file_size > 0) ) {
//
// unserialize and store the data
// read the file contents
//
$c = $this->cache_data;
$decoded = null;
if ($this->cache_serializer == 'json') {
$decoded = json_decode($data, true);
} else {
$decoded = unserialize($data);
}
$data = @fread($fp, $file_size);
if (is_array($decoded) == true) {
if ( ($data !== false) && (strlen($data) > 0) ) {
$this->cache_data = array_merge($c, $decoded);
//
// unserialize and store the data
//
$c = $this->cache_data;
$decoded = null;
if ($this->cache_serializer == 'json') {
$decoded = json_decode($data, true);
} else {
$decoded = unserialize($data);
}
if (is_array($decoded) == true) {
$this->cache_data = array_merge($c, $decoded);
}
}
}

View File

@ -253,8 +253,13 @@ class Net_DNS2_Cache_Shm extends Net_DNS2_Cache
//
// close the segment
//
// shmop_close() is deprecated in v8.0.0
//
shmop_close($this->_cache_id);
if (version_compare(PHP_VERSION, '8.0.0', '<') == true)
{
shmop_close($this->_cache_id);
}
//
// unlock

View File

@ -30,11 +30,11 @@ class Net_DNS2_Exception extends Exception
* Constructor - overload the constructor so we can pass in the request
* and response object (when it's available)
*
* @param string $message the exception message
* @param int $code the exception code
* @param object $previous the previous Exception object
* @param object $request the Net_DNS2_Packet_Request object for this request
* @param object $response the Net_DNS2_Packet_Response object for this request
* @param string $message the exception message
* @param int $code the exception code
* @param object $previous the previous Exception object
* @param Net_DNS2_Packet_Request $request the Net_DNS2_Packet_Request object for this request
* @param Net_DNS2_Packet_Response $response the Net_DNS2_Packet_Response object for this request
*
* @access public
*

View File

@ -63,7 +63,7 @@ class Net_DNS2_Header
/**
* Constructor - builds a new Net_DNS2_Header object
*
* @param mixed &$packet either a Net_DNS2_Packet object or null
* @param Net_DNS2_Packet &$packet either a Net_DNS2_Packet object or null
*
* @throws Net_DNS2_Exception
* @access public

View File

@ -1,33 +1,28 @@
Net_DNS2 - DNS Library for handling lookups and updates.
Copyright (c) 2010-2020, Mike Pultz <mike@mikepultz.com>.
All rights reserved.
Copyright (c) 2010-2023, Mike Pultz <mike@mikepultz.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Mike Pultz nor the names of his contributors
may be used to endorse or promote products derived from this
software without specific prior written permission.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -398,6 +398,7 @@ class Net_DNS2_Lookups
60 => 'Net_DNS2_RR_CDNSKEY',
61 => 'Net_DNS2_RR_OPENPGPKEY',
62 => 'Net_DNS2_RR_CSYNC',
63 => 'Net_DNS2_RR_ZONEMD',
99 => 'Net_DNS2_RR_SPF',
104 => 'Net_DNS2_RR_NID',
105 => 'Net_DNS2_RR_L32',

View File

@ -0,0 +1,106 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2022, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2022 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.5.3
*
*/
/**
* text compression/expansion and labeling class
*
*/
class Net_DNS2_Names
{
/**
* pack a text string
*
* @param string $name a name to be packed
*
* @return string
* @access public
*
*/
public static function pack($name)
{
return (is_null($name) == true) ? null : pack('Ca*', strlen($name), $name);
}
/**
* returns the canonical wire-format representation of the domain name
*
* @param string $name a name to be packed
*
* @return string
* @access public
*
*/
public static function canonical($name)
{
$names = explode('.', $name);
$compname = '';
while (!empty($names)) {
$first = array_shift($names);
$length = strlen($first);
$compname .= pack('Ca*', $length, $first);
}
$compname .= "\0";
return $compname;
}
/**
* parses a domain string into a single string
*
* @param string $rdata the DNS packet to look in for the domain name
* @param integer &$offset the offset into the given packet object
*
* @return mixed either a name string or null if it's not found.
* @access public
*
*/
public static function unpack($rdata, &$offset)
{
if ($offset > strlen($rdata))
{
return null;
}
$name = '';
$len = ord($rdata[$offset]);
if ($len == 0)
{
return null;
}
$offset++;
if ( ($len + $offset) > strlen($rdata)) {
$name = substr($rdata, $offset);
} else {
$name = substr($rdata, $offset, $len);
}
$offset += strlen($name);
return $name;
}
}

View File

@ -41,7 +41,7 @@ class Net_DNS2_Notifier extends Net_DNS2
* DNS notification for a changed zone
*
* @param string $zone the domain name to use for DNS updates
* @param mixed $options an array of config options or null
* @param array $options an array of config options or null
*
* @throws Net_DNS2_Exception
* @access public
@ -115,6 +115,7 @@ class Net_DNS2_Notifier extends Net_DNS2
*
* @param string $keyname the key name to use for the TSIG RR
* @param string $signature the key to sign the request.
* @param string $algorithm the algorithm to use for the request.
*
* @return boolean
* @access public

View File

@ -214,39 +214,6 @@ class Net_DNS2_Packet
return $compname;
}
/**
* applies a standard DNS name compression on the given name/offset
*
* This logic was based on the Net::DNS::Packet::dn_comp() function
* by Michanel Fuhr
*
* @param string $name the name to be compressed
*
* @return string
* @access public
*
*/
public static function pack($name)
{
$offset = 0;
$names = explode('.', $name);
$compname = '';
while (!empty($names)) {
$first = array_shift($names);
$length = strlen($first);
$compname .= pack('Ca*', $length, $first);
$offset += $length + 1;
}
$compname .= "\0";
$offset++;
return $compname;
}
/**
* expands the domain name stored at a given offset in a DNS Packet
*
@ -322,39 +289,56 @@ class Net_DNS2_Packet
return trim($name, '.');
}
/**
* applies a standard DNS name compression on the given name/offset
*
* This logic was based on the Net::DNS::Packet::dn_comp() function
* by Michanel Fuhr
*
* @param string $name the name to be compressed
*
* @return string
* @access public
*
*/
public static function pack($name)
{
return (is_null($name) == true) ? null : pack('Ca*', strlen($name), $name);
}
/**
* parses a domain label from a DNS Packet at the given offset
*
* @param Net_DNS2_Packet &$packet the DNS packet to look in for the domain name
* @param integer &$offset the offset into the given packet object
* @param string $rdata the DNS packet to look in for the domain name
* @param integer &$offset the offset into the given packet object
*
* @return mixed either the domain name or null if it's not found.
* @access public
*
*/
public static function label(Net_DNS2_Packet &$packet, &$offset)
public static function label($rdata, &$offset)
{
$name = '';
if ($packet->rdlength < ($offset + 1)) {
if (strlen($rdata) < ($offset + 1))
{
return null;
}
$xlen = ord($packet->rdata[$offset]);
$xlen = ord($rdata[$offset]);
++$offset;
if (($xlen + $offset) > $packet->rdlength) {
if (($xlen + $offset) > strlen($rdata)) {
$name = substr($packet->rdata, $offset);
$offset = $packet->rdlength;
$name = substr($rdata, $offset);
$offset = strlen($rdata);
} else {
$name = substr($packet->rdata, $offset, $xlen);
$name = substr($rdata, $offset, $xlen);
$offset += $xlen;
}
return $name;
return trim($name, '.');
}
/**

View File

@ -66,7 +66,7 @@ class Net_DNS2_Question
/**
* Constructor - builds a new Net_DNS2_Question object
*
* @param mixed &$packet either a Net_DNS2_Packet object, or null to
* @param Net_DNS2_Packet &$packet either a Net_DNS2_Packet object, or null to
* build an empty object
*
* @throws Net_DNS2_Exception
@ -132,25 +132,26 @@ class Net_DNS2_Question
ord($packet->rdata[$packet->offset++]);
//
// validate it
// validate it
//
$type_name = Net_DNS2_Lookups::$rr_types_by_id[$type];
$class_name = Net_DNS2_Lookups::$classes_by_id[$class];
if ( (!isset($type_name)) || (!isset($class_name)) ) {
if (isset(Net_DNS2_Lookups::$rr_types_by_id[$type]) == false)
{
throw new Net_DNS2_Exception(
'invalid question section: invalid type (' . $type .
') or class (' . $class . ') specified.',
Net_DNS2_Lookups::E_QUESTION_INVALID
'invalid question section: invalid type (' . $type . ') specified.', Net_DNS2_Lookups::E_QUESTION_INVALID
);
}
if (isset(Net_DNS2_Lookups::$classes_by_id[$class]) == false)
{
throw new Net_DNS2_Exception(
'invalid question section: invalid class (' . $class . ') specified.', Net_DNS2_Lookups::E_QUESTION_INVALID
);
}
//
//
// store it
//
$this->qtype = $type_name;
$this->qclass = $class_name;
$this->qtype = Net_DNS2_Lookups::$rr_types_by_id[$type];
$this->qclass = Net_DNS2_Lookups::$classes_by_id[$class];
return true;
}

View File

@ -55,7 +55,7 @@ abstract class Net_DNS2_RR
/*
* The name of the resource record
*/
public $name;
public $name = '';
/*
* The resource record type
@ -374,7 +374,13 @@ abstract class Net_DNS2_RR
//
// add the RR
//
$data .= pack('n', strlen($rdata)) . $rdata;
if ( (is_null($rdata) == false) && (strlen($rdata) > 0) ) {
$data .= pack('n', strlen($rdata)) . $rdata;
} else
{
$data .= pack('n', 0);
}
return $data;
}
@ -432,31 +438,27 @@ abstract class Net_DNS2_RR
ord($packet->rdata[$packet->offset++]);
if ($packet->rdlength < ($packet->offset + $object['rdlength'])) {
return null;
throw new Net_DNS2_Exception(
'failed to parse resource record: packet too small.',
Net_DNS2_Lookups::E_PARSE_ERROR
);
}
//
// lookup the class to use
//
$o = null;
$class = Net_DNS2_Lookups::$rr_types_id_to_class[$object['type']];
if ( (isset(Net_DNS2_Lookups::$rr_types_id_to_class[$object['type']]) == true) &&
(class_exists(Net_DNS2_Lookups::$rr_types_id_to_class[$object['type']]) == true) ) {
if (isset($class)) {
$o = new Net_DNS2_Lookups::$rr_types_id_to_class[$object['type']]($packet, $object);
$o = new $class($packet, $object);
if ($o) {
$packet->offset += $object['rdlength'];
$packet->offset += $object['rdlength'];
}
} else {
throw new Net_DNS2_Exception(
'un-implemented resource record type: ' . $object['type'],
Net_DNS2_Lookups::E_RR_INVALID
);
return $o;
}
return $o;
throw new Net_DNS2_Exception('un-implemented resource record type: ' . $object['type'], Net_DNS2_Lookups::E_RR_INVALID);
}
/**
@ -471,7 +473,7 @@ abstract class Net_DNS2_RR
*/
public function cleanString($data)
{
return strtolower(rtrim($data, '.'));
return (is_null($data) == true) ? null : strtolower(rtrim($data, '.'));
}
/**
@ -495,7 +497,8 @@ abstract class Net_DNS2_RR
*/
public static function fromString($line)
{
if (strlen($line) == 0) {
if ( (is_null($line) == true) || (strlen($line) == 0) ) {
throw new Net_DNS2_Exception(
'empty config line provided.',
Net_DNS2_Lookups::E_PARSE_ERROR
@ -575,31 +578,22 @@ abstract class Net_DNS2_RR
if (isset($class_name)) {
$o = new $class_name;
if (!is_null($o)) {
//
// set the parsed values
//
$o->name = $name;
$o->class = $class;
$o->ttl = $ttl;
//
// set the parsed values
//
$o->name = $name;
$o->class = $class;
$o->ttl = $ttl;
//
// parse the rdata
//
if ($o->rrFromString($values) === false) {
throw new Net_DNS2_Exception(
'failed to parse rdata for config: ' . $line,
Net_DNS2_Lookups::E_PARSE_ERROR
);
}
} else {
//
// parse the rdata
//
if ($o->rrFromString($values) === false) {
throw new Net_DNS2_Exception(
'failed to create new RR record for type: ' . $type,
Net_DNS2_Lookups::E_RR_INVALID
'failed to parse rdata for config: ' . $line,
Net_DNS2_Lookups::E_PARSE_ERROR
);
}

View File

@ -195,9 +195,7 @@ class Net_DNS2_RR_AMTRELAY extends Net_DNS2_RR
break;
case self::AMTRELAY_TYPE_DOMAIN:
$doffset = $packet->offset + $offset;
$this->relay = Net_DNS2_Packet::label($packet, $doffset);
$this->relay = Net_DNS2_Names::unpack($this->rdata, $offset);
break;
default:
@ -245,7 +243,8 @@ class Net_DNS2_RR_AMTRELAY extends Net_DNS2_RR
break;
case self::AMTRELAY_TYPE_DOMAIN:
$data .= pack('Ca*', strlen($this->relay), $this->relay);
$data .= Net_DNS2_Names::pack($this->relay);
$packet->offset += 1;
break;
default:

View File

@ -86,7 +86,7 @@ class Net_DNS2_RR_APL extends Net_DNS2_RR
];
$address = $this->_trimZeros(
$i['address_family'], $i['afd_part']
intval($i['address_family']), $i['afd_part']
);
$i['afd_length'] = count(explode('.', $address));
@ -217,7 +217,7 @@ class Net_DNS2_RR_APL extends Net_DNS2_RR
);
foreach ($address as $b) {
$data .= chr($b);
$data .= chr(intval($b));
}
break;
case 2:

View File

@ -90,8 +90,6 @@ class Net_DNS2_RR_CERT extends Net_DNS2_RR
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
* @param array $rr a array with parsed RR values
*
* @return
*
*/
public function __construct(Net_DNS2_Packet &$packet = null, array $rr = null)
{

View File

@ -130,7 +130,7 @@ class Net_DNS2_RR_EUI48 extends Net_DNS2_RR
$a = explode('-', $this->address);
foreach ($a as $b) {
$data .= chr(hexdec($b));
$data .= chr(intval(hexdec($b)));
}
$packet->offset += 6;

View File

@ -131,7 +131,7 @@ class Net_DNS2_RR_EUI64 extends Net_DNS2_RR
$a = explode('-', $this->address);
foreach ($a as $b) {
$data .= chr(hexdec($b));
$data .= chr(intval(hexdec($b)));
}
$packet->offset += 8;

View File

@ -89,8 +89,8 @@ class Net_DNS2_RR_HINFO extends Net_DNS2_RR
$offset = $packet->offset;
$this->cpu = Net_DNS2_Packet::label($packet, $offset);
$this->os = Net_DNS2_Packet::label($packet, $offset);
$this->cpu = Net_DNS2_Names::unpack($packet->rdata, $offset);
$this->os = Net_DNS2_Names::unpack($packet->rdata, $offset);
return true;
}
@ -113,7 +113,7 @@ class Net_DNS2_RR_HINFO extends Net_DNS2_RR
{
if (strlen($this->cpu) > 0) {
$data = pack('Ca*Ca*', strlen($this->cpu), $this->cpu, strlen($this->os), $this->os);
$data = Net_DNS2_Names::pack($this->cpu) . Net_DNS2_Names::pack($this->os);
$packet->offset += strlen($data);

View File

@ -91,14 +91,15 @@ class Net_DNS2_RR_ISDN extends Net_DNS2_RR
{
if ($this->rdlength > 0) {
$this->isdnaddress = Net_DNS2_Packet::label($packet, $packet->offset);
$offset = $packet->offset;
$this->isdnaddress = Net_DNS2_Names::unpack($packet->rdata, $offset);
//
// look for a SA (sub address) - it's optional
//
if ( (strlen($this->isdnaddress) + 1) < $this->rdlength) {
$this->sa = Net_DNS2_Packet::label($packet, $packet->offset);
$this->sa = Net_DNS2_Names::unpack($packet->rdata, $offset);
} else {
$this->sa = '';
@ -125,11 +126,10 @@ class Net_DNS2_RR_ISDN extends Net_DNS2_RR
{
if (strlen($this->isdnaddress) > 0) {
$data = chr(strlen($this->isdnaddress)) . $this->isdnaddress;
$data = Net_DNS2_Names::pack($this->isdnaddress);
if (!empty($this->sa)) {
$data .= chr(strlen($this->sa));
$data .= $this->sa;
$data .= Net_DNS2_Names::pack($this->sa);
}
$packet->offset += strlen($data);

View File

@ -20,8 +20,7 @@
/**
* KX Resource Record - RFC2230 section 3.1
*
* This class is almost identical to MX, except that the the exchanger
* domain is not compressed, it's added as a label
* This class is almost identical to MX
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | PREFERENCE |
@ -95,7 +94,7 @@ class Net_DNS2_RR_KX extends Net_DNS2_RR
// get the exchange entry server)
//
$offset = $packet->offset + 2;
$this->exchange = Net_DNS2_Packet::label($packet, $offset);
$this->exchange = Net_DNS2_Packet::expand($packet, $offset);
return true;
}
@ -117,12 +116,11 @@ class Net_DNS2_RR_KX extends Net_DNS2_RR
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->exchange) > 0) {
$data = pack('nC', $this->preference, strlen($this->exchange)) .
$this->exchange;
$packet->offset += strlen($data);
$data = pack('n', $this->preference);
$packet->offset += 2;
$data .= $packet->compress($this->exchange, $packet->offset);
return $data;
}

View File

@ -76,8 +76,7 @@ class Net_DNS2_RR_LOC extends Net_DNS2_RR
/*
* used for quick power-of-ten lookups
*/
private $_powerOfTen = [ 1, 10, 100, 1000, 10000, 100000,
1000000,10000000,100000000,1000000000 ];
private $_powerOfTen = [ 0.01, 0.1, 1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 0, 0, 0, 0, 0 ];
/*
* some conversion values
@ -140,9 +139,9 @@ class Net_DNS2_RR_LOC extends Net_DNS2_RR
//
// latitude
//
$latdeg = $x[1];
$latmin = (isset($x[3])) ? $x[3] : 0;
$latsec = (isset($x[5])) ? $x[5] : 0;
$latdeg = floatval($x[1]);
$latmin = floatval((isset($x[3])) ? $x[3] : 0);
$latsec = floatval((isset($x[5])) ? $x[5] : 0);
$lathem = strtoupper($x[6]);
$this->latitude = $this->_dms2d($latdeg, $latmin, $latsec, $lathem);
@ -150,9 +149,9 @@ class Net_DNS2_RR_LOC extends Net_DNS2_RR
//
// longitude
//
$londeg = $x[7];
$lonmin = (isset($x[9])) ? $x[9] : 0;
$lonsec = (isset($x[11])) ? $x[11] : 0;
$londeg = floatval($x[7]);
$lonmin = floatval((isset($x[9])) ? $x[9] : 0);
$lonsec = floatval((isset($x[11])) ? $x[11] : 0);
$lonhem = strtoupper($x[12]);
$this->longitude = $this->_dms2d($londeg, $lonmin, $lonsec, $lonhem);
@ -198,6 +197,7 @@ class Net_DNS2_RR_LOC extends Net_DNS2_RR
// version must be 0 per RFC 1876 section 2
//
$this->version = $x['ver'];
if ($this->version == 0) {
$this->size = $this->_precsizeNtoA($x['size']);
@ -307,10 +307,9 @@ class Net_DNS2_RR_LOC extends Net_DNS2_RR
*/
private function _precsizeNtoA($prec)
{
$mantissa = (($prec >> 4) & 0x0f) % 10;
$exponent = (($prec >> 0) & 0x0f) % 10;
$mantissa = $prec >> 4;
return $mantissa * $this->_powerOfTen[$exponent];
return strval($mantissa * $this->_powerOfTen[$prec & 0x0F]);
}
/**
@ -326,22 +325,24 @@ class Net_DNS2_RR_LOC extends Net_DNS2_RR
private function _precsizeAtoN($prec)
{
$exponent = 0;
while ($prec >= 10) {
$prec /= 10;
++$exponent;
while($prec > $this->_powerOfTen[1 + $exponent]) {
$exponent++;
}
return ($prec << 4) | ($exponent & 0x0f);
$mantissa = intval(0.5 + ($prec / $this->_powerOfTen[$exponent]));
return ($mantissa & 0xF) << 4 | $exponent;
}
/**
* convert lat/lng in deg/min/sec/hem to decimal value
*
* @param integer $deg the degree value
* @param integer $min the minutes value
* @param integer $sec the seconds value
* @param string $hem the hemisphere (N/E/S/W)
* @param float $deg the degree value
* @param float $min the minutes value
* @param float $sec the seconds value
* @param string $hem the hemisphere (N/E/S/W)
*
* @return float the decinmal value
* @access private

View File

@ -138,9 +138,9 @@ class Net_DNS2_RR_NAPTR extends Net_DNS2_RR
$offset = $packet->offset + 4;
$this->flags = Net_DNS2_Packet::label($packet, $offset);
$this->services = Net_DNS2_Packet::label($packet, $offset);
$this->regexp = Net_DNS2_Packet::label($packet, $offset);
$this->flags = Net_DNS2_Names::unpack($packet->rdata, $offset);
$this->services = Net_DNS2_Names::unpack($packet->rdata, $offset);
$this->regexp = Net_DNS2_Names::unpack($packet->rdata, $offset);
$this->replacement = Net_DNS2_Packet::expand($packet, $offset);
@ -167,9 +167,9 @@ class Net_DNS2_RR_NAPTR extends Net_DNS2_RR
$data = pack('nn', $this->order, $this->preference);
$data .= chr(strlen($this->flags)) . $this->flags;
$data .= chr(strlen($this->services)) . $this->services;
$data .= chr(strlen($this->regexp)) . $this->regexp;
$data .= Net_DNS2_Names::pack($this->flags);
$data .= Net_DNS2_Names::pack($this->services);
$data .= Net_DNS2_Names::pack($this->regexp);
$packet->offset += strlen($data);

View File

@ -33,7 +33,6 @@ class Net_DNS2_RR_NSEC3PARAM extends Net_DNS2_RR
/*
* Algorithm to use
*
* TODO: same as the NSEC3
*/
public $algorithm;

View File

@ -248,8 +248,8 @@ class Net_DNS2_RR_RRSIG extends Net_DNS2_RR
$this->algorithm,
$this->labels,
$this->origttl,
gmmktime($e[4], $e[5], $e[6], $e[2], $e[3], $e[1]),
gmmktime($i[4], $i[5], $i[6], $i[2], $i[3], $i[1]),
gmmktime(intval($e[4]), intval($e[5]), intval($e[6]), intval($e[2]), intval($e[3]), intval($e[1])),
gmmktime(intval($i[4]), intval($i[5]), intval($i[6]), intval($i[2]), intval($i[3]), intval($i[1])),
$this->keytag
);

View File

@ -251,8 +251,8 @@ class Net_DNS2_RR_SIG extends Net_DNS2_RR
$this->algorithm,
$this->labels,
$this->origttl,
gmmktime($e[4], $e[5], $e[6], $e[2], $e[3], $e[1]),
gmmktime($i[4], $i[5], $i[6], $i[2], $i[3], $i[1]),
gmmktime(intval($e[4]), intval($e[5]), intval($e[6]), intval($e[2]), intval($e[3]), intval($e[1])),
gmmktime(intval($i[4]), intval($i[5]), intval($i[6]), intval($i[2]), intval($i[3]), intval($i[1])),
$this->keytag
);
@ -267,7 +267,7 @@ class Net_DNS2_RR_SIG extends Net_DNS2_RR
$data .= $name;
}
$data .= chr('0');
$data .= chr(0);
//
// if the signature is empty, and $this->private_key is an instance of a

View File

@ -84,8 +84,8 @@ class Net_DNS2_RR_TALINK extends Net_DNS2_RR
$offset = $packet->offset;
$this->previous = Net_DNS2_Packet::label($packet, $offset);
$this->next = Net_DNS2_Packet::label($packet, $offset);
$this->previous = Net_DNS2_Packet::expand($packet, $offset);
$this->next = Net_DNS2_Packet::expand($packet, $offset);
return true;
}
@ -108,12 +108,7 @@ class Net_DNS2_RR_TALINK extends Net_DNS2_RR
{
if ( (strlen($this->previous) > 0) || (strlen($this->next) > 0) ) {
$data = chr(strlen($this->previous)) . $this->previous .
chr(strlen($this->next)) . $this->next;
$packet->offset += strlen($data);
return $data;
return $packet->compress($this->previous, $packet->offset) . $packet->compress($this->next, $packet->offset);
}
return null;

View File

@ -213,6 +213,8 @@ class Net_DNS2_RR_TKEY extends Net_DNS2_RR
{
if (strlen($this->algorithm) > 0) {
$offset = 0;
//
// make sure the size values are correct
//
@ -222,7 +224,7 @@ class Net_DNS2_RR_TKEY extends Net_DNS2_RR
//
// add the algorithm without compression
//
$data = Net_DNS2_Packet::pack($this->algorithm);
$data = $packet->compress($this->algorithm, $packet->offset);
//
// pack in the inception, expiration, mode, error and key size

View File

@ -62,7 +62,7 @@ class Net_DNS2_RR_TLSA extends Net_DNS2_RR
protected function rrToString()
{
return $this->cert_usage . ' ' . $this->selector . ' ' .
$this->matching_type . ' ' . base64_encode($this->certificate);
$this->matching_type . ' ' . implode('', unpack('H*', $this->certificate));
}
/**
@ -79,7 +79,7 @@ class Net_DNS2_RR_TLSA extends Net_DNS2_RR
$this->cert_usage = array_shift($rdata);
$this->selector = array_shift($rdata);
$this->matching_type = array_shift($rdata);
$this->certificate = base64_decode(implode('', $rdata));
$this->certificate = pack('H*', implode('', $rdata));
return true;
}
@ -132,9 +132,7 @@ class Net_DNS2_RR_TLSA extends Net_DNS2_RR
{
if (strlen($this->certificate) > 0) {
$data = pack(
'CCC', $this->cert_usage, $this->selector, $this->matching_type
) . $this->certificate;
$data = pack('CCCa*', $this->cert_usage, $this->selector, $this->matching_type, $this->certificate);
$packet->offset += strlen($data);

View File

@ -306,7 +306,7 @@ class Net_DNS2_RR_TSIG extends Net_DNS2_RR
//
// add the name without compressing
//
$sig_data .= Net_DNS2_Packet::pack($this->name);
$sig_data .= Net_DNS2_Names::canonical($this->name);
//
// add the class and TTL
@ -318,7 +318,7 @@ class Net_DNS2_RR_TSIG extends Net_DNS2_RR
//
// add the algorithm name without compression
//
$sig_data .= Net_DNS2_Packet::pack(strtolower($this->algorithm));
$sig_data .= Net_DNS2_Names::canonical(strtolower($this->algorithm));
//
// add the rest of the values
@ -343,7 +343,7 @@ class Net_DNS2_RR_TSIG extends Net_DNS2_RR
//
// compress the algorithm
//
$data = Net_DNS2_Packet::pack(strtolower($this->algorithm));
$data = $packet->compress(strtolower($this->algorithm), $offset);
//
// pack the time, fudge and mac size
@ -363,6 +363,7 @@ class Net_DNS2_RR_TSIG extends Net_DNS2_RR
return null;
}
} else {
$this->other_length = 0;

View File

@ -87,13 +87,13 @@ class Net_DNS2_RR_TXT extends Net_DNS2_RR
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
$length = $packet->offset + $this->rdlength;
$offset = $packet->offset;
$limit = $offset + $this->rdlength;
while ($length > $offset) {
$this->text[] = Net_DNS2_Packet::label($packet, $offset);
while($offset < $limit) {
$this->text[] = Net_DNS2_Names::unpack($packet->rdata, $offset);
}
return true;
@ -115,11 +115,11 @@ class Net_DNS2_RR_TXT extends Net_DNS2_RR
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
$data = null;
$data = '';
foreach ($this->text as $t) {
foreach($this->text as $text) {
$data .= chr(strlen($t)) . $t;
$data .= Net_DNS2_Names::pack($text);
}
$packet->offset += strlen($data);

View File

@ -171,7 +171,7 @@ class Net_DNS2_RR_WKS extends Net_DNS2_RR
if ($n == 8) {
$data .= chr(bindec($string));
$data .= chr(intval(bindec($string)));
$string = '';
$n = 0;
}

View File

@ -78,7 +78,10 @@ class Net_DNS2_RR_X25 extends Net_DNS2_RR
{
if ($this->rdlength > 0) {
$this->psdnaddress = Net_DNS2_Packet::label($packet, $packet->offset);
$offset = $packet->offset;
$this->psdnaddress = Net_DNS2_Names::unpack($packet->rdata, $offset);
return true;
}
@ -100,7 +103,7 @@ class Net_DNS2_RR_X25 extends Net_DNS2_RR
{
if (strlen($this->psdnaddress) > 0) {
$data = chr(strlen($this->psdnaddress)) . $this->psdnaddress;
$data = Net_DNS2_Names::pack($this->psdnaddress);
$packet->offset += strlen($data);

View File

@ -0,0 +1,162 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2022, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2022 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.5.3
*
*/
/**
*
* ZONEMD Resource Record - RFC8976 section 2.2
*
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Serial |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Scheme |Hash Algorithm | |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
* | Digest |
* / /
* / /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
class Net_DNS2_RR_ZONEMD extends Net_DNS2_RR
{
/*
* ZONEMD schemes - there is currently only one defined.
*/
const ZONEMD_SCHEME_SIMPLE = 1;
/*
* ZONEMD hash algorithms
*/
const ZONEMD_HASH_ALGORITHM_SHA384 = 1;
const ZONEMD_HASH_ALGORITHM_SHA512 = 2;
/*
* the serial number from the zone's SOA record
*/
public $serial;
/*
* the methods by which data is collated and presented as input to the hashing function.
*/
public $scheme;
/*
* the cryptographic hash algorithm used to construct the digest.
*/
public $hash_algorithm;
/*
* the output of the hash algorithm.
*/
public $digest;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->serial . ' ' . $this->scheme . ' ' . $this->hash_algorithm .
' ' . implode('', unpack('H*', $this->digest));
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->serial = array_shift($rdata);
$this->scheme = array_shift($rdata);
$this->hash_algorithm = array_shift($rdata);
//
// digest must be provided as base64 encoded.
//
$this->digest = pack('H*', implode('', $rdata));
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// unpack the serial, scheme, and hash algorithm
//
$x = unpack('Nserial/Cscheme/Chash_algorithm', $this->rdata);
$this->serial = $x['serial'];
$this->scheme = $x['scheme'];
$this->hash_algorithm = $x['hash_algorithm'];
//
// copy the digest
//
$this->digest = substr($this->rdata, 6, $this->rdlength - 6);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->digest) > 0) {
$data = pack('NCCa*', $this->serial, $this->scheme, $this->hash_algorithm, $this->digest);
$packet->offset += strlen($data);
return $data;
}
return null;
}
}

View File

@ -26,7 +26,7 @@ class Net_DNS2_Resolver extends Net_DNS2
/**
* Constructor - creates a new Net_DNS2_Resolver object
*
* @param mixed $options either an array with options or null
* @param array $options either an array with options or null
*
* @access public
*
@ -232,7 +232,7 @@ class Net_DNS2_Resolver extends Net_DNS2
*
* @param Net_DNS2_RR $rr the RR object to lookup
*
* @return Net_DNS2_RR object
* @return Net_DNS2_Packet_Response
* @throws Net_DNS2_Exception
* @access public
*

View File

@ -43,8 +43,8 @@ class Net_DNS2_Socket
/*
* the local IP and port we'll send the request from
*/
private $local_host;
private $local_port;
private $local_host = '';
private $local_port = 0;
/*
* the last error message on the object
@ -129,12 +129,46 @@ class Net_DNS2_Socket
//
// bind to a local IP/port if it's set
//
if (strlen($this->local_host) > 0) {
if ( ((is_null($this->local_host) == false) && (strlen($this->local_host) > 0)) || ($this->local_port > 0) ) {
$opts['socket']['bindto'] = $this->local_host;
//
// build the host
//
if ( (is_null($this->local_host) == false) && (strlen($this->local_host) > 0) ) {
//
// it's possible users are already setting the IPv6 brackets, so I'll just clean them off first
//
$host = str_replace([ '[', ']' ], '', $this->local_host);
if (Net_DNS2::isIPv4($this->local_host) == true) {
$opts['socket']['bindto'] = $this->local_host;
} else if (Net_DNS2::isIPv6($this->local_host) == true) {
$opts['socket']['bindto'] = '[' . $this->local_host . ']';
} else
{
$this->last_error = 'invalid bind address value: ' . $this->local_host;
return false;
}
} else
{
$opts['socket']['bindto'] = '0';
}
//
// then add the port
//
if ($this->local_port > 0) {
$opts['socket']['bindto'] .= ':' . $this->local_port;
} else {
$opts['socket']['bindto'] .= ':0';
}
}
@ -146,9 +180,6 @@ class Net_DNS2_Socket
//
// create socket
//
$errno;
$errstr;
switch($this->type) {
case Net_DNS2_Socket::SOCK_STREAM:
@ -212,7 +243,7 @@ class Net_DNS2_Socket
//
// set it to non-blocking and set the timeout
//
@stream_set_blocking($this->sock, 0);
@stream_set_blocking($this->sock, false);
@stream_set_timeout($this->sock, $this->timeout);
return true;
@ -264,7 +295,7 @@ class Net_DNS2_Socket
//
// select on write
//
$result = stream_select($read, $write, $except, $this->timeout);
$result = @stream_select($read, $write, $except, $this->timeout);
if ($result === false) {
$this->last_error = 'failed on write select()';
@ -328,12 +359,12 @@ class Net_DNS2_Socket
//
// make sure our socket is non-blocking
//
@stream_set_blocking($this->sock, 0);
@stream_set_blocking($this->sock, false);
//
// select on read
//
$result = stream_select($read, $write, $except, $this->timeout);
$result = @stream_select($read, $write, $except, $this->timeout);
if ($result === false) {
$this->last_error = 'error on read select()';
@ -360,8 +391,8 @@ class Net_DNS2_Socket
$this->last_error = 'failed on fread() for data length';
return false;
}
if (strlen($data) == 0)
{
if (strlen($data) < 2) {
$this->last_error = 'failed on fread() for data length';
return false;
}
@ -380,7 +411,7 @@ class Net_DNS2_Socket
// so the easiest thing to do, is just turn off socket blocking, and
// wait for the data.
//
@stream_set_blocking($this->sock, 1);
@stream_set_blocking($this->sock, true);
//
// read the data from the socket
@ -404,7 +435,7 @@ class Net_DNS2_Socket
//
while (1) {
$chunk = fread($this->sock, $chunk_size);
$chunk = fread($this->sock, max(0, $chunk_size));
if ($chunk === false) {
$this->last_error = 'failed on fread() for data';
@ -425,8 +456,8 @@ class Net_DNS2_Socket
// if it's UDP, it's a single fixed-size frame, and the streams library
// doesn't seem to have a problem reading it.
//
$data = fread($this->sock, $length);
if ($length === false) {
$data = fread($this->sock, max(0, $length));
if ($data === false) {
$this->last_error = 'failed on fread() for data';
return false;

View File

@ -42,7 +42,7 @@ class Net_DNS2_Updater extends Net_DNS2
* dynamic DNS updates
*
* @param string $zone the domain name to use for DNS updates
* @param mixed $options an array of config options or null
* @param array $options an array of config options or null
*
* @throws Net_DNS2_Exception
* @access public