diff options
author | Kai Blin <kai@samba.org> | 2012-09-10 22:22:43 +0200 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2012-09-12 16:51:29 +0200 |
commit | 2af8129085042b51ac052653942116ad5998f701 (patch) | |
tree | e86960a328a1dcc412a393292bfe3b12616b0cb5 /source4/torture | |
parent | 76801b502dd06d13e384ff495c82d0924aa0b6f8 (diff) | |
download | samba-2af8129085042b51ac052653942116ad5998f701.tar.gz samba-2af8129085042b51ac052653942116ad5998f701.tar.bz2 samba-2af8129085042b51ac052653942116ad5998f701.zip |
s4 dns: Add libaddns-based simple tests
Diffstat (limited to 'source4/torture')
-rw-r--r-- | source4/torture/dns/dlz_bind9.c | 2 | ||||
-rw-r--r-- | source4/torture/dns/internal_dns.c | 190 | ||||
-rw-r--r-- | source4/torture/dns/wscript_build | 12 |
3 files changed, 201 insertions, 3 deletions
diff --git a/source4/torture/dns/dlz_bind9.c b/source4/torture/dns/dlz_bind9.c index 6372ca8df6..18d65a3268 100644 --- a/source4/torture/dns/dlz_bind9.c +++ b/source4/torture/dns/dlz_bind9.c @@ -138,7 +138,7 @@ static struct torture_suite *dlz_bind9_suite(TALLOC_CTX *ctx) /** * DNS torture module initialization */ -NTSTATUS torture_dns_init(void) +NTSTATUS torture_bind_dns_init(void) { struct torture_suite *suite; TALLOC_CTX *mem_ctx = talloc_autofree_context(); diff --git a/source4/torture/dns/internal_dns.c b/source4/torture/dns/internal_dns.c new file mode 100644 index 0000000000..b1cb9672e8 --- /dev/null +++ b/source4/torture/dns/internal_dns.c @@ -0,0 +1,190 @@ +/* + Unix SMB/CIFS implementation. + SMB torture tester + Copyright (C) Kai Blin 2012 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" +#include "torture/smbtorture.h" +#include <talloc.h> +#include "lib/addns/dns.h" + +static struct dns_connection *setup_connection(struct torture_context *tctx) +{ + DNS_ERROR err; + struct dns_connection *conn; + + err = dns_open_connection(getenv("DC_SERVER_IP"), DNS_TCP, tctx, &conn); + if (!ERR_DNS_IS_OK(err)) { + printf("Failed to open connection to DNS server\n"); + return NULL; + } + + return conn; +} + +static char *get_dns_domain(struct torture_context *tctx) +{ + return strlower_talloc(tctx, getenv("REALM")); +} + +static struct sockaddr_storage *str_to_sockaddr(TALLOC_CTX *mem_ctx, const char *ip_string) +{ + struct sockaddr_storage *ss = talloc_zero(mem_ctx, struct sockaddr_storage); + int ret; + + if (ss == NULL) { + return NULL; + } + + ss->ss_family = AF_INET; + + ret = inet_pton(AF_INET, ip_string, &(((struct sockaddr_in *)ss)->sin_addr)); + if (ret != 1) { + return NULL; + } + + return ss; +} + +static bool test_internal_dns_query_self(struct torture_context *tctx) +{ + struct dns_connection *conn; + struct dns_request *req, *resp; + char *host; + DNS_ERROR err; + + conn = setup_connection(tctx); + if (conn == NULL) { + return false; + } + + host = talloc_asprintf(tctx, "%s.%s", getenv("DC_SERVER"), get_dns_domain(tctx)); + if (host == NULL) { + return false; + } + + err = dns_create_query(conn, host, QTYPE_A, DNS_CLASS_IN, &req); + if (!ERR_DNS_IS_OK(err)) { + printf("Failed to create A record query\n"); + return false; + } + + err = dns_transaction(conn, conn, req, &resp); + if (!ERR_DNS_IS_OK(err)) { + printf("Failed to query DNS server\n"); + return false; + } + + if (dns_response_code(resp->flags) != DNS_NO_ERROR) { + printf("Query returned %u\n", dns_response_code(resp->flags)); + return false; + } + + /* FIXME: is there _any_ way to unmarshal the response to check this? */ + + return true; +} + +static bool test_internal_dns_update_self(struct torture_context *tctx) +{ + struct dns_connection *conn; + struct dns_update_request *req, *resp; + struct dns_rrec *rec = NULL; + char *host; + DNS_ERROR err; + struct sockaddr_storage *ss; + + conn = setup_connection(tctx); + if (conn == NULL) { + return false; + } + + host = talloc_asprintf(tctx, "%s.%s", getenv("DC_SERVER"), get_dns_domain(tctx)); + if (host == NULL) { + return false; + } + + err = dns_create_update(conn, get_dns_domain(tctx), &req); + if (!ERR_DNS_IS_OK(err)) { + printf("Failed to update packet\n"); + return false; + } + + ss = str_to_sockaddr(conn, getenv("DC_SERVER_IP")); + if (ss == NULL) { + printf("Converting '%s' to sockaddr_storage failed\n", getenv("DC_SERVER_IP")); + return false; + } + + err = dns_create_a_record(req, host, 300, ss, &rec); + if (!ERR_DNS_IS_OK(err)) { + printf("Failed to create A update record\n"); + return false; + } + + err = dns_add_rrec(req, rec, &req->num_updates, &req->updates); + if (!ERR_DNS_IS_OK(err)) { + printf("Failed to add A update record to update packet\n"); + return false; + } + + err = dns_update_transaction(conn, conn, req, &resp); + if (!ERR_DNS_IS_OK(err)) { + printf("Failed to send update\n"); + return false; + } + + if (dns_response_code(resp->flags) != DNS_REFUSED) { + printf("Update returned %u\n", dns_response_code(resp->flags)); + return false; + } + + /* FIXME: is there _any_ way to unmarshal the response to check this? */ + + return true; +} + +static struct torture_suite *internal_dns_suite(TALLOC_CTX *ctx) +{ + struct torture_suite *suite = torture_suite_create(ctx, "dns_internal"); + + suite->description = talloc_strdup(suite, + "Tests for the internal DNS server"); + torture_suite_add_simple_test(suite, "queryself", test_internal_dns_query_self); + torture_suite_add_simple_test(suite, "updateself", test_internal_dns_update_self); + return suite; +} + + +/* Silence silly compiler warning */ +NTSTATUS torture_internal_dns_init(void); + +/** + * DNS torture module initialization + */ +NTSTATUS torture_internal_dns_init(void) +{ + struct torture_suite *suite; + TALLOC_CTX *mem_ctx = talloc_autofree_context(); + + /* register internal DNS torture test cases */ + suite = internal_dns_suite(mem_ctx); + if (!suite) return NT_STATUS_NO_MEMORY; + torture_register_suite(suite); + + return NT_STATUS_OK; +} diff --git a/source4/torture/dns/wscript_build b/source4/torture/dns/wscript_build index 674a3a0c2b..a6773831be 100644 --- a/source4/torture/dns/wscript_build +++ b/source4/torture/dns/wscript_build @@ -1,11 +1,19 @@ #!/usr/bin/env python if bld.AD_DC_BUILD_IS_ENABLED(): - bld.SAMBA_MODULE('TORTURE_DNS', + bld.SAMBA_MODULE('TORTURE_BIND_DNS', source='dlz_bind9.c', subsystem='smbtorture', - init_function='torture_dns_init', + init_function='torture_bind_dns_init', cflags='-DBIND_VERSION_9_8', deps='torture talloc torturemain dlz_bind9_for_torture', internal_module=True ) + + bld.SAMBA_MODULE('TORTURE_INTERNAL_DNS', + source='internal_dns.c', + subsystem='smbtorture', + init_function='torture_internal_dns_init', + deps='torture talloc torturemain', + internal_module=True + ) |