diff options
author | Andreas Schneider <asn@samba.org> | 2014-12-03 15:45:00 +0100 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2014-12-05 23:32:06 +0100 |
commit | 849bfe09b8275c4f11258d5ecf530a56a6d7e883 (patch) | |
tree | e29acf8a88631bf4e0a72536b0e7c2b12018a75b /lib | |
parent | dab427e94eb4f21582ee9211ba4d837e4ed024a3 (diff) | |
download | samba-849bfe09b8275c4f11258d5ecf530a56a6d7e883.tar.gz samba-849bfe09b8275c4f11258d5ecf530a56a6d7e883.tar.xz samba-849bfe09b8275c4f11258d5ecf530a56a6d7e883.zip |
rwrap: Handle trailing dot in dns names.
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/resolv_wrapper/resolv_wrapper.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/lib/resolv_wrapper/resolv_wrapper.c b/lib/resolv_wrapper/resolv_wrapper.c index 07ec85ca99..3b94a36bfe 100644 --- a/lib/resolv_wrapper/resolv_wrapper.c +++ b/lib/resolv_wrapper/resolv_wrapper.c @@ -558,6 +558,8 @@ static int rwrap_res_fake_hosts(const char *hostfile, int rc = ENOENT; char *key = NULL; char *value = NULL; + char *query_name = NULL; + size_t qlen = strlen(query); RWRAP_LOG(RWRAP_LOG_TRACE, "Searching in fake hosts file %s\n", hostfile); @@ -570,6 +572,15 @@ static int rwrap_res_fake_hosts(const char *hostfile, return -1; } + if (qlen > 0 && query[qlen-1] == '.') { + qlen--; + } + + query_name = strndup(query, qlen); + if (query_name == NULL) { + return -1; + } + while (fgets(buf, sizeof(buf), fp) != NULL) { char *rec_type; char *q; @@ -593,23 +604,23 @@ static int rwrap_res_fake_hosts(const char *hostfile, continue; } - if (TYPE_MATCH(type, ns_t_a, rec_type, "A", key, query)) { + if (TYPE_MATCH(type, ns_t_a, rec_type, "A", key, query_name)) { rc = rwrap_fake_a(key, value, answer, anslen); break; } else if (TYPE_MATCH(type, ns_t_aaaa, - rec_type, "AAAA", key, query)) { + rec_type, "AAAA", key, query_name)) { rc = rwrap_fake_aaaa(key, value, answer, anslen); break; } else if (TYPE_MATCH(type, ns_t_srv, - rec_type, "SRV", key, query)) { + rec_type, "SRV", key, query_name)) { rc = rwrap_fake_srv(key, value, answer, anslen); break; } else if (TYPE_MATCH(type, ns_t_soa, - rec_type, "SOA", key, query)) { + rec_type, "SOA", key, query_name)) { rc = rwrap_fake_soa(key, value, answer, anslen); break; } else if (TYPE_MATCH(type, ns_t_cname, - rec_type, "CNAME", key, query)) { + rec_type, "CNAME", key, query_name)) { rc = rwrap_fake_cname(key, value, answer, anslen); break; } @@ -618,19 +629,20 @@ static int rwrap_res_fake_hosts(const char *hostfile, switch (rc) { case 0: RWRAP_LOG(RWRAP_LOG_TRACE, - "Successfully faked answer for [%s]\n", query); + "Successfully faked answer for [%s]\n", query_name); break; case -1: RWRAP_LOG(RWRAP_LOG_ERROR, - "Error faking answer for [%s]\n", query); + "Error faking answer for [%s]\n", query_name); break; case ENOENT: RWRAP_LOG(RWRAP_LOG_TRACE, - "Record for [%s] not found\n", query); + "Record for [%s] not found\n", query_name); rc = rwrap_fake_empty_query(key, type, answer, anslen); break; } + free(query_name); fclose(fp); return rc; } |