r20144: add NET-API-BECOME-DC test that tests libnet_BecomeDC()/libnet_UnbecomeDC()
authorStefan Metzmacher <metze@samba.org>
Tue, 12 Dec 2006 23:23:50 +0000 (23:23 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:29:14 +0000 (14:29 -0500)
metze

source/torture/config.mk
source/torture/libnet/libnet.c
source/torture/libnet/libnet_BecomeDC.c [new file with mode: 0644]

index 01f095e146f85857174fdfc4f122fc8aa6bb79ac..cc05709377fbc9f152fbf3b56ff0ac90cfbfab96 100644 (file)
@@ -256,7 +256,8 @@ OBJ_FILES = \
                libnet/libnet_user.o \
                libnet/libnet_share.o \
                libnet/libnet_rpc.o \
-               libnet/libnet_domain.o
+               libnet/libnet_domain.o \
+               libnet/libnet_BecomeDC.o
 PUBLIC_DEPENDENCIES = \
                LIBSAMBA-NET \
                POPT_CREDENTIALS
index ec06cea0f1820e62890113eada7aa160bb8ae119..9a8d61e98edb0de94a7d6a486c16c58ef7c007d8 100644 (file)
@@ -24,9 +24,7 @@
 
 NTSTATUS torture_net_init(void)
 {
-       struct torture_suite *suite = torture_suite_create(
-                                                                               talloc_autofree_context(),
-                                                                               "NET");
+       struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "NET");
 
        torture_suite_add_simple_test(suite, "USERINFO", torture_userinfo);
        torture_suite_add_simple_test(suite, "USERADD", torture_useradd);
@@ -53,9 +51,9 @@ NTSTATUS torture_net_init(void)
        torture_suite_add_simple_test(suite, "API-DOMCLOSELSA", torture_domain_close_lsa);
        torture_suite_add_simple_test(suite, "API-DOMOPENSAMR", torture_domain_open_samr);
        torture_suite_add_simple_test(suite, "API-DOMCLOSESAMR", torture_domain_close_samr);
+       torture_suite_add_simple_test(suite, "API-BECOME-DC", torture_net_become_dc);
 
-       suite->description = talloc_strdup(suite, 
-                                               "libnet convenience interface tests");
+       suite->description = talloc_strdup(suite, "libnet convenience interface tests");
 
        torture_register_suite(suite);
 
diff --git a/source/torture/libnet/libnet_BecomeDC.c b/source/torture/libnet/libnet_BecomeDC.c
new file mode 100644 (file)
index 0000000..48ba1fe
--- /dev/null
@@ -0,0 +1,82 @@
+/* 
+   Unix SMB/CIFS implementation.
+
+   libnet_BecomeDC() tests
+
+   Copyright (C) Stefan (metze) Metzmacher 2006
+   
+   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 2 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, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+#include "lib/cmdline/popt_common.h"
+#include "torture/torture.h"
+#include "torture/rpc/rpc.h"
+#include "libnet/libnet.h"
+#include "lib/events/events.h"
+
+#define TORTURE_NETBIOS_NAME "smbtorturedc"
+
+BOOL torture_net_become_dc(struct torture_context *torture)
+{
+       BOOL ret = True;
+       NTSTATUS status;
+       struct libnet_context *ctx;
+       struct libnet_BecomeDC b;
+       struct libnet_UnbecomeDC u;
+       struct test_join *tj;
+       struct cli_credentials *machine_account;
+
+       /* Join domain as a member server. */
+       tj = torture_join_domain(TORTURE_NETBIOS_NAME,
+                                ACB_WSTRUST,
+                                &machine_account);
+       if (!tj) {
+               DEBUG(0, ("%s failed to join domain as workstation\n",
+                         TORTURE_NETBIOS_NAME));
+               return False;
+       }
+
+       ctx = libnet_context_init(event_context_init(torture));
+       ctx->cred = cmdline_credentials;
+
+       b.in.domain_dns_name            = torture_join_dom_dns_name(tj);
+       b.in.domain_netbios_name        = torture_join_dom_netbios_name(tj);
+       b.in.domain_sid                 = torture_join_sid(tj);
+       b.in.source_dsa_address         = lp_parm_string(-1, "torture", "host");
+       b.in.dest_dsa_netbios_name      = TORTURE_NETBIOS_NAME;
+
+       status = libnet_BecomeDC(ctx, ctx, &b);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("libnet_BecomeDC() failed - %s\n", nt_errstr(status));
+               ret = False;
+       }
+
+       u.in.domain_dns_name            = torture_join_dom_dns_name(tj);
+       u.in.domain_netbios_name        = torture_join_dom_netbios_name(tj);
+       u.in.source_dsa_address         = lp_parm_string(-1, "torture", "host");
+       u.in.dest_dsa_netbios_name      = TORTURE_NETBIOS_NAME;
+
+       status = libnet_UnbecomeDC(ctx, ctx, &u);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("libnet_UnbecomeDC() failed - %s\n", nt_errstr(status));
+               ret = False;
+       }
+
+       /* Leave domain. */                          
+       torture_leave_domain(tj);
+       
+       return ret;
+}