s4 dns: Add libaddns-based simple tests
authorKai Blin <kai@samba.org>
Mon, 10 Sep 2012 20:22:43 +0000 (22:22 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 12 Sep 2012 14:51:29 +0000 (16:51 +0200)
source4/selftest/tests.py
source4/torture/dns/dlz_bind9.c
source4/torture/dns/internal_dns.c [new file with mode: 0644]
source4/torture/dns/wscript_build

index b7b9d45abdcd74de1dac17547384b3ef65152c43..575d61b65228c8b77ce018a1b8768a421e069187 100755 (executable)
@@ -296,6 +296,8 @@ for f in sorted(os.listdir(os.path.join(samba4srcdir, "../pidl/tests"))):
 
 # DNS tests
 planpythontestsuite("fl2003dc", "samba.tests.dns")
+for t in smb4torture_testsuites("dns_internal."):
+    plansmbtorturetestsuite(t, "dc:local", '//$SERVER/whavever')
 
 # Local tests
 for t in smb4torture_testsuites("dlz_bind9."):
index 6372ca8df624d27db365819fed6a34eea8bc478a..18d65a32689bcefd9f968414ab7fba32ce22500c 100644 (file)
@@ -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 (file)
index 0000000..b1cb967
--- /dev/null
@@ -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;
+}
index 674a3a0c2bd78a391e9db37d02d3cde90626b562..a6773831be97ad36c89e9882015cafca154ca0fa 100644 (file)
@@ -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
+               )