From c1b45afcf254ed0bbb36b125e440a2731c253e63 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Mon, 24 Oct 2011 17:07:45 +1100 Subject: s4-dnsserver: Compare two dns names using last uncommon name components 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 --- source4/rpc_server/dnsserver/dnsdata.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'source4/rpc_server/dnsserver') diff --git a/source4/rpc_server/dnsserver/dnsdata.c b/source4/rpc_server/dnsserver/dnsdata.c index 486290dd9b..e1b7f356ff 100644 --- a/source4/rpc_server/dnsserver/dnsdata.c +++ b/source4/rpc_server/dnsserver/dnsdata.c @@ -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); -- cgit