diff options
author | Amitay Isaacs <amitay@gmail.com> | 2011-10-24 17:07:45 +1100 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2011-11-02 15:26:54 +1100 |
commit | c1b45afcf254ed0bbb36b125e440a2731c253e63 (patch) | |
tree | c7fc80306a6543ed49d7090408f7e1782b83cacc | |
parent | c651b4e99b8bd70eb3be7b3d416c329b4d506f76 (diff) | |
download | samba-c1b45afcf254ed0bbb36b125e440a2731c253e63.tar.gz samba-c1b45afcf254ed0bbb36b125e440a2731c253e63.tar.bz2 samba-c1b45afcf254ed0bbb36b125e440a2731c253e63.zip |
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 <tridge@samba.org>
-rw-r--r-- | source4/rpc_server/dnsserver/dnsdata.c | 28 |
1 files changed, 26 insertions, 2 deletions
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); |