r20293: implement store chunk hook for libnet_BecomeDC()
[kai/samba-autobuild/.git] / source4 / 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 static NTSTATUS test_become_dc_check_options(void *private_data,
33                                              const struct libnet_BecomeDC_CheckOptions *o)
34 {
35         DEBUG(0,("Become DC of Domain[%s]/[%s]\n",
36                 o->domain->netbios_name, o->domain->dns_name));
37
38         DEBUG(0,("Promotion Partner is Server[%s] from Site[%s]\n",
39                 o->source_dsa->dns_name, o->source_dsa->site_name));
40
41         DEBUG(0,("Options:crossRef behavior_version[%u]\n"
42                        "\tschema object_version[%u]\n"
43                        "\tdomain behavior_version[%u]\n"
44                        "\tdomain w2k3_update_revision[%u]\n", 
45                 o->forest->crossref_behavior_version,
46                 o->forest->schema_object_version,
47                 o->domain->behavior_version,
48                 o->domain->w2k3_update_revision));
49
50         return NT_STATUS_OK;
51 }
52
53 static NTSTATUS test_become_dc_prepare_db(void *private_data,
54                                           const struct libnet_BecomeDC_PrepareDB *p)
55 {
56         struct test_join *tj = talloc_get_type(private_data, struct test_join);
57
58         DEBUG(0,("New Server[%s] in Site[%s]\n",
59                 p->dest_dsa->dns_name, p->dest_dsa->site_name));
60
61         DEBUG(0,("DSA Instance [%s]\n"
62                 "\tobjectGUID[%s]\n"
63                 "\tinvocationId[%s]\n",
64                 p->dest_dsa->ntds_dn_str,
65                 GUID_string(tj, &p->dest_dsa->ntds_guid),
66                 GUID_string(tj, &p->dest_dsa->invocation_id)));
67
68         DEBUG(0,("Schema Partition[%s]\n",
69                 p->forest->schema_dn_str));
70
71         DEBUG(0,("Config Partition[%s]\n",
72                 p->forest->config_dn_str));
73
74         DEBUG(0,("Domain Partition[%s]\n",
75                 p->domain->dn_str));
76
77         return NT_STATUS_OK;
78 }
79
80 static NTSTATUS test_become_dc_store_chunk(void *private_data,
81                                            const struct libnet_BecomeDC_StoreChunk *c)
82 {
83         DEBUG(0,("Partition[%s]\n",
84                 c->partition->nc.dn));
85
86         return NT_STATUS_OK;
87 }
88
89 BOOL torture_net_become_dc(struct torture_context *torture)
90 {
91         BOOL ret = True;
92         NTSTATUS status;
93         struct libnet_context *ctx;
94         struct libnet_BecomeDC b;
95         struct libnet_UnbecomeDC u;
96         struct test_join *tj;
97         struct cli_credentials *machine_account;
98
99         /* Join domain as a member server. */
100         tj = torture_join_domain(TORTURE_NETBIOS_NAME,
101                                  ACB_WSTRUST,
102                                  &machine_account);
103         if (!tj) {
104                 DEBUG(0, ("%s failed to join domain as workstation\n",
105                           TORTURE_NETBIOS_NAME));
106                 return False;
107         }
108
109         ctx = libnet_context_init(event_context_init(torture));
110         ctx->cred = cmdline_credentials;
111
112         ZERO_STRUCT(b);
113         b.in.domain_dns_name            = torture_join_dom_dns_name(tj);
114         b.in.domain_netbios_name        = torture_join_dom_netbios_name(tj);
115         b.in.domain_sid                 = torture_join_sid(tj);
116         b.in.source_dsa_address         = lp_parm_string(-1, "torture", "host");
117         b.in.dest_dsa_netbios_name      = TORTURE_NETBIOS_NAME;
118
119         b.in.callbacks.private_data     = tj;
120         b.in.callbacks.check_options    = test_become_dc_check_options;
121         b.in.callbacks.prepare_db       = test_become_dc_prepare_db;
122         b.in.callbacks.schema_chunk     = test_become_dc_store_chunk;
123         b.in.callbacks.config_chunk     = test_become_dc_store_chunk;
124         b.in.callbacks.domain_chunk     = test_become_dc_store_chunk;
125
126         status = libnet_BecomeDC(ctx, ctx, &b);
127         if (!NT_STATUS_IS_OK(status)) {
128                 printf("libnet_BecomeDC() failed - %s\n", nt_errstr(status));
129                 ret = False;
130         }
131
132         ZERO_STRUCT(u);
133         u.in.domain_dns_name            = torture_join_dom_dns_name(tj);
134         u.in.domain_netbios_name        = torture_join_dom_netbios_name(tj);
135         u.in.source_dsa_address         = lp_parm_string(-1, "torture", "host");
136         u.in.dest_dsa_netbios_name      = TORTURE_NETBIOS_NAME;
137
138         status = libnet_UnbecomeDC(ctx, ctx, &u);
139         if (!NT_STATUS_IS_OK(status)) {
140                 printf("libnet_UnbecomeDC() failed - %s\n", nt_errstr(status));
141                 ret = False;
142         }
143
144         /* Leave domain. */                          
145         torture_leave_domain(tj);
146         
147         return ret;
148 }