mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
DNS CAA record type implementation and tests for https://bugs.php.net/bug.php?id=73850
This commit is contained in:
parent
e7e96fe2e0
commit
280e9cb28d
2 changed files with 59 additions and 2 deletions
|
@ -114,6 +114,9 @@
|
|||
#ifndef DNS_T_A6
|
||||
#define DNS_T_A6 38
|
||||
#endif
|
||||
#ifndef DNS_T_CAA
|
||||
#define DNS_T_CAA 257
|
||||
#endif
|
||||
|
||||
#ifndef DNS_T_ANY
|
||||
#define DNS_T_ANY 255
|
||||
|
@ -286,7 +289,7 @@ static zend_string *php_gethostbyname(char *name)
|
|||
/* }}} */
|
||||
|
||||
#if HAVE_FULL_DNS_FUNCS || defined(PHP_WIN32)
|
||||
# define PHP_DNS_NUM_TYPES 12 /* Number of DNS Types Supported by PHP currently */
|
||||
# define PHP_DNS_NUM_TYPES 13 /* Number of DNS Types Supported by PHP currently */
|
||||
|
||||
# define PHP_DNS_A 0x00000001
|
||||
# define PHP_DNS_NS 0x00000002
|
||||
|
@ -294,6 +297,7 @@ static zend_string *php_gethostbyname(char *name)
|
|||
# define PHP_DNS_SOA 0x00000020
|
||||
# define PHP_DNS_PTR 0x00000800
|
||||
# define PHP_DNS_HINFO 0x00001000
|
||||
# define PHP_DNS_CAA 0x00002000
|
||||
# define PHP_DNS_MX 0x00004000
|
||||
# define PHP_DNS_TXT 0x00008000
|
||||
# define PHP_DNS_A6 0x01000000
|
||||
|
@ -301,7 +305,7 @@ static zend_string *php_gethostbyname(char *name)
|
|||
# define PHP_DNS_NAPTR 0x04000000
|
||||
# define PHP_DNS_AAAA 0x08000000
|
||||
# define PHP_DNS_ANY 0x10000000
|
||||
# define PHP_DNS_ALL (PHP_DNS_A|PHP_DNS_NS|PHP_DNS_CNAME|PHP_DNS_SOA|PHP_DNS_PTR|PHP_DNS_HINFO|PHP_DNS_MX|PHP_DNS_TXT|PHP_DNS_A6|PHP_DNS_SRV|PHP_DNS_NAPTR|PHP_DNS_AAAA)
|
||||
# define PHP_DNS_ALL (PHP_DNS_A|PHP_DNS_NS|PHP_DNS_CNAME|PHP_DNS_SOA|PHP_DNS_PTR|PHP_DNS_HINFO|PHP_DNS_CAA|PHP_DNS_MX|PHP_DNS_TXT|PHP_DNS_A6|PHP_DNS_SRV|PHP_DNS_NAPTR|PHP_DNS_AAAA)
|
||||
#endif /* HAVE_FULL_DNS_FUNCS || defined(PHP_WIN32) */
|
||||
|
||||
/* Note: These functions are defined in ext/standard/dns_win32.c for Windows! */
|
||||
|
@ -384,6 +388,7 @@ PHP_FUNCTION(dns_check_record)
|
|||
else if (!strcasecmp("PTR", rectype)) type = DNS_T_PTR;
|
||||
else if (!strcasecmp("ANY", rectype)) type = DNS_T_ANY;
|
||||
else if (!strcasecmp("SOA", rectype)) type = DNS_T_SOA;
|
||||
else if (!strcasecmp("CAA", rectype)) type = DNS_T_CAA;
|
||||
else if (!strcasecmp("TXT", rectype)) type = DNS_T_TXT;
|
||||
else if (!strcasecmp("CNAME", rectype)) type = DNS_T_CNAME;
|
||||
else if (!strcasecmp("AAAA", rectype)) type = DNS_T_AAAA;
|
||||
|
@ -529,6 +534,23 @@ static u_char *php_parserr(u_char *cp, u_char *end, querybuf *answer, int type_t
|
|||
add_assoc_stringl(subarray, "os", (char*)cp, n);
|
||||
cp += n;
|
||||
break;
|
||||
case DNS_T_CAA:
|
||||
/* See RFC 6844 for values https://tools.ietf.org/html/rfc6844 */
|
||||
add_assoc_string(subarray, "type", "CAA");
|
||||
// 1 flag byte
|
||||
CHECKCP(1);
|
||||
n = *cp & 0xFF;
|
||||
add_assoc_long(subarray, "flags", n);
|
||||
cp++;
|
||||
// Tag length (1 byte)
|
||||
CHECKCP(1);
|
||||
n = *cp & 0xFF;
|
||||
cp++;
|
||||
CHECKCP(n);
|
||||
add_assoc_stringl(subarray, "tag", (char*)cp, n);
|
||||
cp += n;
|
||||
add_assoc_string(subarray, "value", (char*)cp);
|
||||
break;
|
||||
case DNS_T_TXT:
|
||||
{
|
||||
int l1 = 0, l2 = 0;
|
||||
|
@ -879,6 +901,9 @@ PHP_FUNCTION(dns_get_record)
|
|||
case 11:
|
||||
type_to_fetch = type_param&PHP_DNS_A6 ? DNS_T_A6 : 0;
|
||||
break;
|
||||
case 12:
|
||||
type_to_fetch = type_param&PHP_DNS_CAA ? DNS_T_CAA : 0;
|
||||
break;
|
||||
case PHP_DNS_NUM_TYPES:
|
||||
store_results = 0;
|
||||
continue;
|
||||
|
@ -1095,6 +1120,7 @@ PHP_MINIT_FUNCTION(dns) {
|
|||
REGISTER_LONG_CONSTANT("DNS_SOA", PHP_DNS_SOA, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("DNS_PTR", PHP_DNS_PTR, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("DNS_HINFO", PHP_DNS_HINFO, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("DNS_CAA", PHP_DNS_CAA, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("DNS_MX", PHP_DNS_MX, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("DNS_TXT", PHP_DNS_TXT, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("DNS_SRV", PHP_DNS_SRV, CONST_CS | CONST_PERSISTENT);
|
||||
|
|
31
ext/standard/tests/network/dns_get_record_caa.phpt
Normal file
31
ext/standard/tests/network/dns_get_record_caa.phpt
Normal file
|
@ -0,0 +1,31 @@
|
|||
--TEST--
|
||||
dns_get_record() CAA tests
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
|
||||
if (getenv("SKIP_ONLINE_TESTS")) die("skip online test");
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
/* This must be a domain that publishes an RFC6844 CAA-type DNS record */
|
||||
$domain = 'google.com';
|
||||
$match = false;
|
||||
$dns = dns_get_record($domain, DNS_CAA);
|
||||
if (count($dns) > 0) {
|
||||
if (array_key_exists('type', $dns[0])
|
||||
and $dns[0]['type'] == 'CAA'
|
||||
and array_key_exists('flags', $dns[0])
|
||||
and array_key_exists('tag', $dns[0])
|
||||
and array_key_exists('value', $dns[0])
|
||||
) {
|
||||
$match = true;
|
||||
}
|
||||
}
|
||||
if ($match) {
|
||||
echo "CAA record found\n";
|
||||
} else {
|
||||
echo "CAA Lookup failed\n";
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
CAA record found
|
Loading…
Add table
Add a link
Reference in a new issue