php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #78008
Patch 78008-dns_check_record-74.patch revision 2020-07-14 01:58 UTC by apostnikov at gmail dot com
Patch dns_check_record_patch_light revision 2019-05-13 16:13 UTC by a dot suharevs at dyninno dot lv
Patch dns_check_record_patch revision 2019-05-13 14:58 UTC by a dot suharevs at dyninno dot lv

Patch dns_check_record_patch for *Network Functions Bug #78008

Patch version 2019-05-13 14:58 UTC

Return to Bug #78008 | Download this patch
This patch is obsolete

Obsoleted by patches:

Patch Revisions:

Developer: a.suharevs@dyninno.lv

diff --git a/ext/standard/dns.c b/ext/standard/dns.c
index 3f34ba67ee..a1312bf99e 100644
--- a/ext/standard/dns.c
+++ b/ext/standard/dns.c
@@ -345,82 +345,6 @@ static void _php_dns_free_res(struct __res_state *res) { /* {{{ */
 #define php_dns_free_res(__res__)
 #endif
 
-/* {{{ proto bool dns_check_record(string host [, string type])
-   Check DNS records corresponding to a given Internet host name or IP address */
-PHP_FUNCTION(dns_check_record)
-{
-#ifndef MAXPACKET
-#define MAXPACKET  8192 /* max packet size used internally by BIND */
-#endif
-	u_char ans[MAXPACKET];
-	char *hostname, *rectype = NULL;
-	size_t hostname_len, rectype_len = 0;
-	int type = DNS_T_MX, i;
-#if defined(HAVE_DNS_SEARCH)
-	struct sockaddr_storage from;
-	uint32_t fromsize = sizeof(from);
-	dns_handle_t handle;
-#elif defined(HAVE_RES_NSEARCH)
-	struct __res_state state;
-	struct __res_state *handle = &state;
-#endif
-
-	ZEND_PARSE_PARAMETERS_START(1, 2)
-		Z_PARAM_STRING(hostname, hostname_len)
-		Z_PARAM_OPTIONAL
-		Z_PARAM_STRING(rectype, rectype_len)
-	ZEND_PARSE_PARAMETERS_END();
-
-	if (hostname_len == 0) {
-		php_error_docref(NULL, E_WARNING, "Host cannot be empty");
-		RETURN_FALSE;
-	}
-
-	if (rectype) {
-		if (!strcasecmp("A",     rectype)) type = DNS_T_A;
-		else if (!strcasecmp("NS",    rectype)) type = DNS_T_NS;
-		else if (!strcasecmp("MX",    rectype)) type = DNS_T_MX;
-		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;
-		else if (!strcasecmp("SRV",   rectype)) type = DNS_T_SRV;
-		else if (!strcasecmp("NAPTR", rectype)) type = DNS_T_NAPTR;
-		else if (!strcasecmp("A6",    rectype)) type = DNS_T_A6;
-		else {
-			php_error_docref(NULL, E_WARNING, "Type '%s' not supported", rectype);
-			RETURN_FALSE;
-		}
-	}
-
-#if defined(HAVE_DNS_SEARCH)
-	handle = dns_open(NULL);
-	if (handle == NULL) {
-		RETURN_FALSE;
-	}
-#elif defined(HAVE_RES_NSEARCH)
-    memset(&state, 0, sizeof(state));
-    if (res_ninit(handle)) {
-			RETURN_FALSE;
-	}
-#else
-	res_init();
-#endif
-
-	RETVAL_TRUE;
-	i = php_dns_search(handle, hostname, C_IN, type, ans, sizeof(ans));
-
-	if (i < 0) {
-		RETVAL_FALSE;
-	}
-
-	php_dns_free_handle(handle);
-}
-/* }}} */
-
 #if HAVE_FULL_DNS_FUNCS
 
 #define CHECKCP(n) do { \
@@ -788,6 +712,95 @@ static u_char *php_parserr(u_char *cp, u_char *end, querybuf *answer, int type_t
 }
 /* }}} */
 
+/* {{{ proto bool dns_check_record(string host [, string type])
+   Check DNS records corresponding to a given Internet host name or IP address */
+PHP_FUNCTION(dns_check_record)
+{
+#ifndef MAXPACKET
+#define MAXPACKET 8192
+#endif
+	querybuf answer;
+	char *hostname, *rectype = NULL;
+	size_t hostname_len, rectype_len = 0;
+	int type = T_MX, n;
+
+#if defined(HAVE_DNS_SEARCH)
+	struct sockaddr_storage from;
+	uint32_t fromsize = sizeof(from);
+	dns_handle_t handle;
+#elif defined(HAVE_RES_NSEARCH)
+	struct __res_state state;
+	struct __res_state *handle = &state;
+#endif
+
+	ZEND_PARSE_PARAMETERS_START(1, 2)
+		Z_PARAM_STRING(hostname, hostname_len)
+		Z_PARAM_OPTIONAL
+		Z_PARAM_STRING(rectype, rectype_len)
+	ZEND_PARSE_PARAMETERS_END();
+
+	if (hostname_len == 0) {
+		php_error_docref(NULL, E_WARNING, "Host cannot be empty");
+		RETURN_FALSE;
+	}
+
+	if (rectype) {
+		if (!strcasecmp("A",     rectype)) type = T_A;
+		else if (!strcasecmp("NS",    rectype)) type = DNS_T_NS;
+		else if (!strcasecmp("MX",    rectype)) type = DNS_T_MX;
+		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;
+		else if (!strcasecmp("SRV",   rectype)) type = DNS_T_SRV;
+		else if (!strcasecmp("NAPTR", rectype)) type = DNS_T_NAPTR;
+		else if (!strcasecmp("A6",    rectype)) type = DNS_T_A6;
+		else {
+			php_error_docref(NULL, E_WARNING, "Type '%s' not supported", rectype);
+			RETURN_FALSE;
+		}
+	}
+
+#if defined(HAVE_DNS_SEARCH)
+	handle = dns_open(NULL);
+	if (handle == NULL) {
+		RETURN_FALSE;
+	}
+#elif defined(HAVE_RES_NSEARCH)
+    memset(&state, 0, sizeof(state));
+    if (res_ninit(handle)) {
+			RETURN_FALSE;
+	}
+#else
+	res_init();
+#endif
+
+	RETVAL_TRUE;
+	n = php_dns_search(handle, hostname, C_IN, type, answer.qb2, sizeof answer);
+
+	if (n < 0) {
+		RETVAL_FALSE;
+	}
+
+#if defined(HAVE_RES_SEARCH)
+	HEADER *hp;
+	int an;
+
+	hp = (HEADER *)&answer;
+	an = ntohs(hp->ancount);
+
+	if (an == 0) {
+		RETVAL_FALSE;
+	}
+#endif
+
+	php_dns_free_handle(handle);
+}
+/* }}} */
+
 /* {{{ proto array|false dns_get_record(string hostname [, int type[, array &authns[, array &addtl[, bool raw]]]])
    Get any Resource Record corresponding to a given Internet host name */
 PHP_FUNCTION(dns_get_record)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 01:01:28 2024 UTC