r20144: add NET-API-BECOME-DC test that tests libnet_BecomeDC()/libnet_UnbecomeDC()
[jelmer/samba4-debian.git] / source / torture / libnet / libnet_BecomeDC.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    libnet_BecomeDC() tests
5
6    Copyright (C) Stefan (metze) Metzmacher 2006
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24 #include "lib/cmdline/popt_common.h"
25 #include "torture/torture.h"
26 #include "torture/rpc/rpc.h"
27 #include "libnet/libnet.h"
28 #include "lib/events/events.h"
29
30 #define TORTURE_NETBIOS_NAME "smbtorturedc"
31
32 BOOL torture_net_become_dc(struct torture_context *torture)
33 {
34         BOOL ret = True;
35         NTSTATUS status;
36         struct libnet_context *ctx;
37         struct libnet_BecomeDC b;
38         struct libnet_UnbecomeDC u;
39         struct test_join *tj;
40         struct cli_credentials *machine_account;
41
42         /* Join domain as a member server. */
43         tj = torture_join_domain(TORTURE_NETBIOS_NAME,
44                                  ACB_WSTRUST,
45                                  &machine_account);
46         if (!tj) {
47                 DEBUG(0, ("%s failed to join domain as workstation\n",
48                           TORTURE_NETBIOS_NAME));
49                 return False;
50         }
51
52         ctx = libnet_context_init(event_context_init(torture));
53         ctx->cred = cmdline_credentials;
54
55         b.in.domain_dns_name            = torture_join_dom_dns_name(tj);
56         b.in.domain_netbios_name        = torture_join_dom_netbios_name(tj);
57         b.in.domain_sid                 = torture_join_sid(tj);
58         b.in.source_dsa_address         = lp_parm_string(-1, "torture", "host");
59         b.in.dest_dsa_netbios_name      = TORTURE_NETBIOS_NAME;
60
61         status = libnet_BecomeDC(ctx, ctx, &b);
62         if (!NT_STATUS_IS_OK(status)) {
63                 printf("libnet_BecomeDC() failed - %s\n", nt_errstr(status));
64                 ret = False;
65         }
66
67         u.in.domain_dns_name            = torture_join_dom_dns_name(tj);
68         u.in.domain_netbios_name        = torture_join_dom_netbios_name(tj);
69         u.in.source_dsa_address         = lp_parm_string(-1, "torture", "host");
70         u.in.dest_dsa_netbios_name      = TORTURE_NETBIOS_NAME;
71
72         status = libnet_UnbecomeDC(ctx, ctx, &u);
73         if (!NT_STATUS_IS_OK(status)) {
74                 printf("libnet_UnbecomeDC() failed - %s\n", nt_errstr(status));
75                 ret = False;
76         }
77
78         /* Leave domain. */                          
79         torture_leave_domain(tj);
80         
81         return ret;
82 }