--- bin/named/dlz_ldap_driver.c_ORIG	2005-03-25 20:32:52.000000000 +0100
+++ bin/named/dlz_ldap_driver.c	2005-03-25 20:31:37.000000000 +0100
@@ -587,6 +587,12 @@
 	int i;
 	int entries;
 
+   /* Extended Patch for Zone Extended Tag */
+   char *n_zone_domain;
+   char *n_zone_tld;
+   char n_buffer[strlen(zone)+1];
+
+
 		// get db instance / connection
 #ifdef ISC_PLATFORM_USETHREADS
 
@@ -608,10 +614,29 @@
 		// set fields
 	if(zone != NULL){
 		dbi->zone = isc_mem_strdup(ns_g_mctx, zone);
+ 
+        // Extended Patch for Zone Extended Tag
+        snprintf(n_buffer, strlen(zone)+1, "%s", zone);
+        n_zone_domain = strtok(n_buffer, ".");
+        n_zone_tld    = strtok(NULL, "");
+        //
+        dbi->zone_domain = isc_mem_strdup(ns_g_mctx, n_zone_domain);
+        dbi->zone_tld    = isc_mem_strdup(ns_g_mctx, n_zone_tld);
+
 		if(dbi->zone == NULL){
 			result = ISC_R_NOMEMORY;
 			goto cleanup;
 		}
+        if(dbi->zone_domain == NULL){
+            result = ISC_R_NOMEMORY;
+            goto cleanup;
+        }
+        if(dbi->zone_tld == NULL){
+            result = ISC_R_NOMEMORY;
+            goto cleanup;
+        }
+
+
 	} else {
 		dbi->zone = NULL;
 	}
@@ -822,6 +847,13 @@
 		// cleanup
 	if(dbi->zone != NULL)
 		isc_mem_free(ns_g_mctx, dbi->zone);
+        // free dbi->zone_domain string
+    if(dbi->zone_domain != NULL)
+        isc_mem_free(ns_g_mctx, dbi->zone_domain);
+         // free dbi->zone_tld string
+    if(dbi->zone_tld != NULL)
+        isc_mem_free(ns_g_mctx, dbi->zone_tld);
+
 	if(dbi->record != NULL)
 		isc_mem_free(ns_g_mctx, dbi->record);
 	if(dbi->client != NULL)
--- bin/named/dlz_mysql_driver.c_ORIG	2005-03-25 17:58:33.000000000 +0100
+++ bin/named/dlz_mysql_driver.c	2005-03-25 19:53:44.000000000 +0100
@@ -181,6 +181,11 @@
 	unsigned int j = 0;
 	int qres = 0;
 
+	/* Extended Patch for Zone Extended Tag */
+	char *n_zone_domain;
+	char *n_zone_tld;
+	char n_buffer[strlen(zone)+1];
+	
 	if(query != COUNTZONE)
 		REQUIRE(*rs == NULL);
 	else
@@ -260,10 +265,27 @@
 		// was a zone string passed?  If so, make it safe for use in queries.
 	if(zone != NULL){
 		dbi->zone = mysqldrv_escape_string((MYSQL *) dbi->dbconn, zone);
+
+		// Extended Patch for Zone Extended Tag
+		snprintf(n_buffer, strlen(zone)+1, "%s", zone);
+		n_zone_domain = strtok(n_buffer, ".");
+		n_zone_tld    = strtok(NULL, "");
+		//
+		dbi->zone_domain = mysqldrv_escape_string((MYSQL *) dbi->dbconn, n_zone_domain);
+		dbi->zone_tld    = mysqldrv_escape_string((MYSQL *) dbi->dbconn, n_zone_tld);
+
 		if(dbi->zone == NULL){
 			result = ISC_R_NOMEMORY;
 			goto cleanup;
 		}
+		if(dbi->zone_domain == NULL){
+			result = ISC_R_NOMEMORY;
+			goto cleanup;
+		}
+		if(dbi->zone_tld == NULL){
+			result = ISC_R_NOMEMORY;
+			goto cleanup;
+		}
 	} else {	// no string passed, set the string pointer to NULL
 		dbi->zone = NULL;
 	}
@@ -361,6 +383,14 @@
 	if(dbi->zone != NULL)
 		isc_mem_free(ns_g_mctx, dbi->zone);
 
+		// free dbi->zone_domain string
+	if(dbi->zone_domain != NULL)
+		isc_mem_free(ns_g_mctx, dbi->zone_domain);
+	
+		// free dbi->zone_tld string
+	if(dbi->zone_tld != NULL)
+		isc_mem_free(ns_g_mctx, dbi->zone_tld);
+	
 		// free dbi->record string
 	if(dbi->record != NULL)
 		isc_mem_free(ns_g_mctx, dbi->record);
--- bin/named/dlz_odbc_driver.c_ORIG	2005-03-25 20:25:12.000000000 +0100
+++ ./bin/named/dlz_odbc_driver.c	2005-03-25 20:24:31.000000000 +0100
@@ -534,6 +534,11 @@
 	unsigned int j = 0;
 	SQLRETURN sqlRes;
 
+    /* Extended Patch for Zone Extended Tag */
+    char *n_zone_domain;
+    char *n_zone_tld;
+    char n_buffer[strlen(zone)+1];
+	
 	REQUIRE(*r_dbi == NULL);
 
 		// get db instance / connection
@@ -614,10 +619,27 @@
 		// was a zone string passed?  If so, make it safe for use in queries.
 	if(zone != NULL){
 		dbi->zone = odbc_escape_string(zone);
+ 
+        // Extended Patch for Zone Extended Tag
+        snprintf(n_buffer, strlen(zone)+1, "%s", zone);
+        n_zone_domain = strtok(n_buffer, ".");
+        n_zone_tld    = strtok(NULL, "");
+        //
+        dbi->zone_domain = odbc_escape_string(n_zone_domain);
+        dbi->zone_tld    = odbc_escape_string(n_zone_tld);
+		
 		if(dbi->zone == NULL){
 			result = ISC_R_NOMEMORY;
 			goto cleanup;
 		}
+        if(dbi->zone_domain == NULL){
+            result = ISC_R_NOMEMORY;
+            goto cleanup;
+        }
+        if(dbi->zone_tld == NULL){
+            result = ISC_R_NOMEMORY;
+            goto cleanup;
+        }
 	} else {	// no string passed, set the string pointer to NULL
 		dbi->zone = NULL;
 	}
@@ -718,6 +740,14 @@
 	if(dbi->zone != NULL)
 		isc_mem_free(ns_g_mctx, dbi->zone);
 
+        // free dbi->zone_domain string
+    if(dbi->zone_domain != NULL)
+        isc_mem_free(ns_g_mctx, dbi->zone_domain);
+ 
+        // free dbi->zone_tld string
+    if(dbi->zone_tld != NULL)
+        isc_mem_free(ns_g_mctx, dbi->zone_tld);
+	
 		// free dbi->record string
 	if(dbi->record != NULL)
 		isc_mem_free(ns_g_mctx, dbi->record);
--- bin/named/dlz_postgres_driver.c_ORIG	2005-03-25 20:16:37.000000000 +0100
+++ bin/named/dlz_postgres_driver.c	2005-03-25 20:21:07.000000000 +0100
@@ -339,6 +339,12 @@
 	unsigned int i = 0;
 	unsigned int j = 0;
 
+    /* Extended Patch for Zone Extended Tag */
+	char *n_zone_domain;
+	char *n_zone_tld;
+	char n_buffer[strlen(zone)+1];
+
+	
 //** temporarily get a unique thread #
 unsigned int dlz_thread_num = 1+(int) (1000.0*rand()/(RAND_MAX+1.0)); 
 
@@ -433,10 +439,27 @@
 		// was a zone string passed?  If so, make it safe for use in queries.
 	if(zone != NULL){
 		dbi->zone = postgres_escape_string(zone);
+
+        // Extended Patch for Zone Extended Tag
+		snprintf(n_buffer, strlen(zone)+1, "%s", zone);
+		n_zone_domain = strtok(n_buffer, ".");
+		n_zone_tld    = strtok(NULL, "");
+		//
+		dbi->zone_domain = postgres_escape_string(n_zone_domain);
+		dbi->zone_tld    = postgres_escape_string(n_zone_tld);
+		
 		if(dbi->zone == NULL){
 			result = ISC_R_NOMEMORY;
 			goto cleanup;
 		}
+        if(dbi->zone_domain == NULL){
+			result = ISC_R_NOMEMORY;
+			goto cleanup;
+		}
+		if(dbi->zone_tld == NULL){
+			result = ISC_R_NOMEMORY;
+			goto cleanup;
+		}
 	} else {	// no string passed, set the string pointer to NULL
 		dbi->zone = NULL;
 	}
@@ -570,6 +593,14 @@
 	if(dbi->zone != NULL)
 		isc_mem_free(ns_g_mctx, dbi->zone);
 
+		// free dbi->zone_domain string
+    if(dbi->zone_domain != NULL)
+        isc_mem_free(ns_g_mctx, dbi->zone_domain);
+ 
+        // free dbi->zone_tld string
+    if(dbi->zone_tld != NULL)
+        isc_mem_free(ns_g_mctx, dbi->zone_tld);
+	
 		// free dbi->record string
 	if(dbi->record != NULL)
 		isc_mem_free(ns_g_mctx, dbi->record);
--- bin/named/sdlz_helper.c_ORIG	2005-03-25 17:24:42.000000000 +0100
+++ bin/named/sdlz_helper.c	2005-03-25 20:09:45.000000000 +0100
@@ -75,7 +75,7 @@
 destroy_querylist(isc_mem_t *mctx, query_list_t **querylist);
 
 isc_result_t
-build_querylist(isc_mem_t *mctx, const char *query_str, char **zone,
+build_querylist(isc_mem_t *mctx, const char *query_str, char **zone, char **zone_domain, char **zone_tld,
 				char **record, char **client, query_list_t **querylist,
 				unsigned int flags);
 
@@ -118,12 +118,14 @@
 
 	/* constructs a query list by parsing a string into query segments */
 isc_result_t
-build_querylist(isc_mem_t *mctx, const char *query_str, char **zone,
+build_querylist(isc_mem_t *mctx, const char *query_str, char **zone, char **zone_domain, char **zone_tld,
 				char **record, char **client, query_list_t **querylist,
 				unsigned int flags)
 {
 	isc_result_t result;
 	isc_boolean_t foundzone = isc_boolean_false;
+	isc_boolean_t foundzone_domain = isc_boolean_false;
+	isc_boolean_t foundzone_tld = isc_boolean_false;
 	isc_boolean_t foundrecord = isc_boolean_false;
 	isc_boolean_t foundclient = isc_boolean_false;
 	char *temp_str = NULL;
@@ -213,6 +215,26 @@
                  // tseg->sql points in-directly poinsts to a string
 			tseg->direct = isc_boolean_false;  
 			foundclient = isc_boolean_true;
+			// check if we encountered zone_domain token (Extended patch)
+		} else if(strcasecmp(tseg->sql, "zone_domain") == 0){
+			// we don't really need, or want the "zone_domain" text, so get rid of it.
+			isc_mem_free(mctx, tseg->sql);
+			tseg->sql = (char **) zone_domain;
+			tseg->strlen = 0;
+			// tseg->sql points in-directly to a string
+			tseg->direct = isc_boolean_false;	
+			foundzone_domain = isc_boolean_true; // isn't usefull ... :-P
+			foundzone = isc_boolean_true; // no segfault
+			// check if we encountered zone_tld token (Extended patch)
+		} else if(strcasecmp(tseg->sql, "zone_tld") == 0){
+			// we don't really need, or want the "zone_tld" text, so get rid of it.
+			isc_mem_free(mctx, tseg->sql);
+			tseg->sql = (char **) zone_tld;
+			tseg->strlen = 0;
+			// tseg->sql points in-directly to a string
+			tseg->direct = isc_boolean_false;	
+			foundzone_tld = isc_boolean_true; // isn't usefull ...  :-P
+			foundzone = isc_boolean_true; // no segfault
 		}
 	}
 
@@ -346,6 +368,8 @@
 	db->client = NULL;
 	db->record = NULL;
 	db->zone = NULL;
+	db->zone_domain = NULL;
+	db->zone_tld = NULL;
 	db->mctx = NULL;
 	db->query_buf = NULL;
 	db->allnodes_q = NULL;
@@ -368,7 +392,7 @@
 	}
 
 		// build the all nodes query list
-	result = build_querylist(mctx, allnodes_str, &db->zone, &db->record, &db->client, 
+	result = build_querylist(mctx, allnodes_str, &db->zone, &db->zone_domain, &db->zone_tld, &db->record, &db->client, 
 				&db->allnodes_q, SDLZH_REQUIRE_ZONE);
 		// if unsuccessful, log err msg and cleanup
 	if(result != ISC_R_SUCCESS){
@@ -379,7 +403,7 @@
 	}
 
 		// build the allow zone transfer query list
-	result = build_querylist(mctx, allowxfr_str, &db->zone, &db->record, &db->client, 
+	result = build_querylist(mctx, allowxfr_str, &db->zone, &db->zone_domain, &db->zone_tld, &db->record, &db->client, 
 				&db->allowxfr_q, SDLZH_REQUIRE_ZONE | SDLZH_REQUIRE_CLIENT);
 		// if unsuccessful, log err msg and cleanup
 	if(result != ISC_R_SUCCESS){
@@ -390,7 +414,7 @@
 	}
 
 		// build the authority query, query list
-	result = build_querylist(mctx, authority_str, &db->zone, &db->record, &db->client, 
+	result = build_querylist(mctx, authority_str, &db->zone, &db->zone_domain, &db->zone_tld, &db->record, &db->client, 
 				&db->authority_q, SDLZH_REQUIRE_ZONE);
 		// if unsuccessful, log err msg and cleanup
 	if(result != ISC_R_SUCCESS){
@@ -401,7 +425,7 @@
 	}
 
 		// build findzone query, query list
-	result = build_querylist(mctx, findzone_str, &db->zone, &db->record, &db->client, 
+	result = build_querylist(mctx, findzone_str, &db->zone, &db->zone_domain, &db->zone_tld, &db->record, &db->client, 
 				&db->findzone_q, SDLZH_REQUIRE_ZONE);
 		// if unsuccessful, log err msg and cleanup
 	if(result != ISC_R_SUCCESS){
@@ -412,7 +436,7 @@
 	}
 
 		// build countzone query, query list
-	result = build_querylist(mctx, countzone_str, &db->zone, &db->record, &db->client, 
+	result = build_querylist(mctx, countzone_str, &db->zone, &db->zone_domain, &db->zone_tld, &db->record, &db->client, 
 				&db->countzone_q, SDLZH_REQUIRE_ZONE);
 		// if unsuccessful, log err msg and cleanup
 	if(result != ISC_R_SUCCESS){
@@ -423,7 +447,7 @@
 	}
 	
 		// build lookup query, query list
-	result = build_querylist(mctx, lookup_str, &db->zone, &db->record, &db->client, 
+	result = build_querylist(mctx, lookup_str, &db->zone, &db->zone_domain, &db->zone_tld, &db->record, &db->client, 
 				&db->lookup_q, SDLZH_REQUIRE_RECORD);
 		// if unsuccessful, log err msg and cleanup
 	if(result != ISC_R_SUCCESS){
--- bin/named/include/named/sdlz_helper.h~	2005-04-11 11:08:57.000000000 +0200
+++ bin/named/include/named/sdlz_helper.h	2005-04-11 11:23:47.000000000 +0200
@@ -76,6 +76,8 @@
 	query_list_t	*countzone_q;
 	char				*query_buf;
 	char				*zone;
+	char				*zone_domain;
+	char				*zone_tld;
 	char				*record;
 	char				*client;
 	isc_mem_t		*mctx;
