Skip to content

Commit f485aca

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

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
@@ -109,6 +109,9 @@
109109
#ifndef DNS_T_A6
110110
#define DNS_T_A6 38
111111
#endif
112+
#ifndef DNS_T_CAA
113+
#define DNS_T_CAA 257
114+
#endif
112115

113116
#ifndef DNS_T_ANY
114117
#define DNS_T_ANY 255
@@ -281,22 +284,23 @@ static zend_string *php_gethostbyname(char *name)
281284
/* }}} */
282285

283286
#if HAVE_FULL_DNS_FUNCS || defined(PHP_WIN32)
284-
# define PHP_DNS_NUM_TYPES 12 /* Number of DNS Types Supported by PHP currently */
287+
# define PHP_DNS_NUM_TYPES 13 /* Number of DNS Types Supported by PHP currently */
285288

286289
# define PHP_DNS_A 0x00000001
287290
# define PHP_DNS_NS 0x00000002
288291
# define PHP_DNS_CNAME 0x00000010
289292
# define PHP_DNS_SOA 0x00000020
290293
# define PHP_DNS_PTR 0x00000800
291294
# define PHP_DNS_HINFO 0x00001000
295+
# define PHP_DNS_CAA 0x00002000
292296
# define PHP_DNS_MX 0x00004000
293297
# define PHP_DNS_TXT 0x00008000
294298
# define PHP_DNS_A6 0x01000000
295299
# define PHP_DNS_SRV 0x02000000
296300
# define PHP_DNS_NAPTR 0x04000000
297301
# define PHP_DNS_AAAA 0x08000000
298302
# define PHP_DNS_ANY 0x10000000
299-
# 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)
303+
# 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)
300304
#endif /* HAVE_FULL_DNS_FUNCS || defined(PHP_WIN32) */
301305

302306
/* Note: These functions are defined in ext/standard/dns_win32.c for Windows! */
@@ -381,6 +385,7 @@ PHP_FUNCTION(dns_check_record)
381385
else if (!strcasecmp("PTR", rectype)) type = DNS_T_PTR;
382386
else if (!strcasecmp("ANY", rectype)) type = DNS_T_ANY;
383387
else if (!strcasecmp("SOA", rectype)) type = DNS_T_SOA;
388+
else if (!strcasecmp("CAA", rectype)) type = DNS_T_CAA;
384389
else if (!strcasecmp("TXT", rectype)) type = DNS_T_TXT;
385390
else if (!strcasecmp("CNAME", rectype)) type = DNS_T_CNAME;
386391
else if (!strcasecmp("AAAA", rectype)) type = DNS_T_AAAA;
@@ -526,6 +531,23 @@ static u_char *php_parserr(u_char *cp, u_char *end, querybuf *answer, int type_t
526531
add_assoc_stringl(subarray, "os", (char*)cp, n);
527532
cp += n;
528533
break;
534+
case DNS_T_CAA:
535+
/* See RFC 6844 for values https://tools.ietf.org/html/rfc6844 */
536+
add_assoc_string(subarray, "type", "CAA");
537+
// 1 flag byte
538+
CHECKCP(1);
539+
n = *cp & 0xFF;
540+
add_assoc_long(subarray, "flags", n);
541+
cp++;
542+
// Tag length (1 byte)
543+
CHECKCP(1);
544+
n = *cp & 0xFF;
545+
cp++;
546+
CHECKCP(n);
547+
add_assoc_stringl(subarray, "tag", (char*)cp, n);
548+
cp += n;
549+
add_assoc_string(subarray, "value", (char*)cp);
550+
break;
529551
case DNS_T_TXT:
530552
{
531553
int l1 = 0, l2 = 0;
@@ -880,6 +902,9 @@ PHP_FUNCTION(dns_get_record)
880902
case 11:
881903
type_to_fetch = type_param&PHP_DNS_A6 ? DNS_T_A6 : 0;
882904
break;
905+
case 12:
906+
type_to_fetch = type_param&PHP_DNS_CAA ? DNS_T_CAA : 0;
907+
break;
883908
case PHP_DNS_NUM_TYPES:
884909
store_results = 0;
885910
continue;
@@ -1099,6 +1124,7 @@ PHP_MINIT_FUNCTION(dns) {
10991124
REGISTER_LONG_CONSTANT("DNS_SOA", PHP_DNS_SOA, CONST_CS | CONST_PERSISTENT);
11001125
REGISTER_LONG_CONSTANT("DNS_PTR", PHP_DNS_PTR, CONST_CS | CONST_PERSISTENT);
11011126
REGISTER_LONG_CONSTANT("DNS_HINFO", PHP_DNS_HINFO, CONST_CS | CONST_PERSISTENT);
1127+
REGISTER_LONG_CONSTANT("DNS_CAA", PHP_DNS_CAA, CONST_CS | CONST_PERSISTENT);
11021128
REGISTER_LONG_CONSTANT("DNS_MX", PHP_DNS_MX, CONST_CS | CONST_PERSISTENT);
11031129
REGISTER_LONG_CONSTANT("DNS_TXT", PHP_DNS_TXT, CONST_CS | CONST_PERSISTENT);
11041130
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)