Skip to content

Commit bce548d

Browse files
committed
Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0: DNS CAA record type implementation and tests for https://bugs.php.net/bug.php?id=73850
2 parents 85589ca + 280e9cb commit bce548d

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

ext/standard/dns.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@
114114
#ifndef DNS_T_A6
115115
#define DNS_T_A6 38
116116
#endif
117+
#ifndef DNS_T_CAA
118+
#define DNS_T_CAA 257
119+
#endif
117120

118121
#ifndef DNS_T_ANY
119122
#define DNS_T_ANY 255
@@ -286,22 +289,23 @@ static zend_string *php_gethostbyname(char *name)
286289
/* }}} */
287290

288291
#if HAVE_FULL_DNS_FUNCS || defined(PHP_WIN32)
289-
# define PHP_DNS_NUM_TYPES 12 /* Number of DNS Types Supported by PHP currently */
292+
# define PHP_DNS_NUM_TYPES 13 /* Number of DNS Types Supported by PHP currently */
290293

291294
# define PHP_DNS_A 0x00000001
292295
# define PHP_DNS_NS 0x00000002
293296
# define PHP_DNS_CNAME 0x00000010
294297
# define PHP_DNS_SOA 0x00000020
295298
# define PHP_DNS_PTR 0x00000800
296299
# define PHP_DNS_HINFO 0x00001000
300+
# define PHP_DNS_CAA 0x00002000
297301
# define PHP_DNS_MX 0x00004000
298302
# define PHP_DNS_TXT 0x00008000
299303
# define PHP_DNS_A6 0x01000000
300304
# define PHP_DNS_SRV 0x02000000
301305
# define PHP_DNS_NAPTR 0x04000000
302306
# define PHP_DNS_AAAA 0x08000000
303307
# define PHP_DNS_ANY 0x10000000
304-
# 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)
308+
# 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)
305309
#endif /* HAVE_FULL_DNS_FUNCS || defined(PHP_WIN32) */
306310

307311
/* Note: These functions are defined in ext/standard/dns_win32.c for Windows! */
@@ -384,6 +388,7 @@ PHP_FUNCTION(dns_check_record)
384388
else if (!strcasecmp("PTR", rectype)) type = DNS_T_PTR;
385389
else if (!strcasecmp("ANY", rectype)) type = DNS_T_ANY;
386390
else if (!strcasecmp("SOA", rectype)) type = DNS_T_SOA;
391+
else if (!strcasecmp("CAA", rectype)) type = DNS_T_CAA;
387392
else if (!strcasecmp("TXT", rectype)) type = DNS_T_TXT;
388393
else if (!strcasecmp("CNAME", rectype)) type = DNS_T_CNAME;
389394
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
529534
add_assoc_stringl(subarray, "os", (char*)cp, n);
530535
cp += n;
531536
break;
537+
case DNS_T_CAA:
538+
/* See RFC 6844 for values https://tools.ietf.org/html/rfc6844 */
539+
add_assoc_string(subarray, "type", "CAA");
540+
// 1 flag byte
541+
CHECKCP(1);
542+
n = *cp & 0xFF;
543+
add_assoc_long(subarray, "flags", n);
544+
cp++;
545+
// Tag length (1 byte)
546+
CHECKCP(1);
547+
n = *cp & 0xFF;
548+
cp++;
549+
CHECKCP(n);
550+
add_assoc_stringl(subarray, "tag", (char*)cp, n);
551+
cp += n;
552+
add_assoc_string(subarray, "value", (char*)cp);
553+
break;
532554
case DNS_T_TXT:
533555
{
534556
int l1 = 0, l2 = 0;
@@ -879,6 +901,9 @@ PHP_FUNCTION(dns_get_record)
879901
case 11:
880902
type_to_fetch = type_param&PHP_DNS_A6 ? DNS_T_A6 : 0;
881903
break;
904+
case 12:
905+
type_to_fetch = type_param&PHP_DNS_CAA ? DNS_T_CAA : 0;
906+
break;
882907
case PHP_DNS_NUM_TYPES:
883908
store_results = 0;
884909
continue;
@@ -1095,6 +1120,7 @@ PHP_MINIT_FUNCTION(dns) {
10951120
REGISTER_LONG_CONSTANT("DNS_SOA", PHP_DNS_SOA, CONST_CS | CONST_PERSISTENT);
10961121
REGISTER_LONG_CONSTANT("DNS_PTR", PHP_DNS_PTR, CONST_CS | CONST_PERSISTENT);
10971122
REGISTER_LONG_CONSTANT("DNS_HINFO", PHP_DNS_HINFO, CONST_CS | CONST_PERSISTENT);
1123+
REGISTER_LONG_CONSTANT("DNS_CAA", PHP_DNS_CAA, CONST_CS | CONST_PERSISTENT);
10981124
REGISTER_LONG_CONSTANT("DNS_MX", PHP_DNS_MX, CONST_CS | CONST_PERSISTENT);
10991125
REGISTER_LONG_CONSTANT("DNS_TXT", PHP_DNS_TXT, CONST_CS | CONST_PERSISTENT);
11001126
REGISTER_LONG_CONSTANT("DNS_SRV", PHP_DNS_SRV, CONST_CS | CONST_PERSISTENT);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
dns_get_record() CAA tests
3+
--SKIPIF--
4+
<?php
5+
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
6+
if (getenv("SKIP_ONLINE_TESTS")) die("skip online test");
7+
?>
8+
--FILE--
9+
<?php
10+
/* This must be a domain that publishes an RFC6844 CAA-type DNS record */
11+
$domain = 'google.com';
12+
$match = false;
13+
$dns = dns_get_record($domain, DNS_CAA);
14+
if (count($dns) > 0) {
15+
if (array_key_exists('type', $dns[0])
16+
and $dns[0]['type'] == 'CAA'
17+
and array_key_exists('flags', $dns[0])
18+
and array_key_exists('tag', $dns[0])
19+
and array_key_exists('value', $dns[0])
20+
) {
21+
$match = true;
22+
}
23+
}
24+
if ($match) {
25+
echo "CAA record found\n";
26+
} else {
27+
echo "CAA Lookup failed\n";
28+
}
29+
?>
30+
--EXPECT--
31+
CAA record found

0 commit comments

Comments
 (0)