Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
30 changes: 28 additions & 2 deletions ext/standard/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,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
Expand Down Expand Up @@ -281,22 +284,23 @@ 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
# define PHP_DNS_CNAME 0x00000010
# 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
# define PHP_DNS_SRV 0x02000000
# 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! */
Expand Down Expand Up @@ -381,6 +385,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;
Expand Down Expand Up @@ -526,6 +531,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;
Expand Down Expand Up @@ -880,6 +902,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;
Expand Down Expand Up @@ -1099,6 +1124,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);
Expand Down
31 changes: 31 additions & 0 deletions ext/standard/tests/network/dns_get_record_caa.phpt
Original file line number Diff line number Diff line change
@@ -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