s4-dnsserver: Compare two dns names using last uncommon name components
authorAmitay Isaacs <amitay@gmail.com>
Mon, 24 Oct 2011 06:07:45 +0000 (17:07 +1100)
committerAndrew Tridgell <tridge@samba.org>
Wed, 2 Nov 2011 04:26:54 +0000 (15:26 +1100)
When search_name is not NULL, use the second last component of name
instead of the last name.

e.g. To compare following two names,
   _ldap._tcp.gc, and
   _ldap._tcp.Default-First-Site-Name._sites.gc

with search_name=NULL, it is gc and gc
with search_name=gc, it is _tcp and _sites

Signed-off-by: Andrew Tridgell <tridge@samba.org>
source4/rpc_server/dnsserver/dnsdata.c

index 486290dd9b5f87513293b8914bc478c58b7eb2af..e1b7f356ff528fd1433de1697c8db6fcb2ae77ee 100644 (file)
@@ -707,18 +707,42 @@ int dns_name_compare(const struct ldb_message **m1, const struct ldb_message **m
                return 1;
        }
 
+       /* Compare the last components of names.
+        * If search_name is not NULL, compare the second last components of names */
        ptr1 = strrchr(name1, '.');
        if (ptr1 == NULL) {
                ptr1 = name1;
        } else {
-               ptr1 = &ptr1[1];
+               if (search_name && strcmp(ptr1+1, search_name) == 0) {
+                       ptr1--;
+                       while (ptr1 != name1) {
+                               ptr1--;
+                               if (*ptr1 == '.') {
+                                       break;
+                               }
+                       }
+               }
+               if (*ptr1 == '.') {
+                       ptr1 = &ptr1[1];
+               }
        }
 
        ptr2 = strrchr(name2, '.');
        if (ptr2 == NULL) {
                ptr2 = name2;
        } else {
-               ptr2 = &ptr2[1];
+               if (search_name && strcmp(ptr2+1, search_name) == 0) {
+                       ptr2--;
+                       while (ptr2 != name2) {
+                               ptr2--;
+                               if (*ptr2 == '.') {
+                                       break;
+                               }
+                       }
+               }
+               if (*ptr2 == '.') {
+                       ptr2 = &ptr2[1];
+               }
        }
 
        return strcasecmp(ptr1, ptr2);