Merge commit 'release-4-0-0alpha1' into v4-0-test
[ira/wip.git] / source4 / torture / rpc / join.c
1 #include "includes.h"
2 #include "libnet/libnet.h"
3 #include "libcli/libcli.h"
4
5 #include "auth/credentials/credentials.h"
6 #include "torture/rpc/rpc.h"
7
8 #define TORTURE_NETBIOS_NAME "smbtorturejoin"
9
10
11 bool torture_rpc_join(struct torture_context *torture)
12 {
13         NTSTATUS status;
14         struct test_join *tj;
15         struct cli_credentials *machine_account;
16         struct smbcli_state *cli;
17         const char *host = torture_setting_string(torture, "host", NULL);
18
19         /* Join domain as a member server. */
20         tj = torture_join_domain(TORTURE_NETBIOS_NAME,
21                                  ACB_WSTRUST,
22                                  &machine_account);
23
24         if (!tj) {
25                 DEBUG(0, ("%s failed to join domain as workstation\n",
26                           TORTURE_NETBIOS_NAME));
27                 return false;
28         }
29
30         status = smbcli_full_connection(tj, &cli, host,
31                                         "IPC$", NULL,
32                                         machine_account,
33                                         NULL);
34         if (!NT_STATUS_IS_OK(status)) {
35                 DEBUG(0, ("%s failed to connect to IPC$ with workstation credentials\n",
36                           TORTURE_NETBIOS_NAME));
37                 return false;   
38         }
39         smbcli_tdis(cli);
40         
41         /* Leave domain. */                          
42         torture_leave_domain(tj);
43         
44         /* Join domain as a domain controller. */
45         tj = torture_join_domain(TORTURE_NETBIOS_NAME,
46                                  ACB_SVRTRUST,
47                                  &machine_account);
48         if (!tj) {
49                 DEBUG(0, ("%s failed to join domain as domain controller\n",
50                           TORTURE_NETBIOS_NAME));
51                 return false;
52         }
53
54         status = smbcli_full_connection(tj, &cli, host,
55                                         "IPC$", NULL,
56                                         machine_account,
57                                         NULL);
58         if (!NT_STATUS_IS_OK(status)) {
59                 DEBUG(0, ("%s failed to connect to IPC$ with workstation credentials\n",
60                           TORTURE_NETBIOS_NAME));
61                 return false;   
62         }
63
64         smbcli_tdis(cli);
65
66         /* Leave domain. */
67         torture_leave_domain(tj);
68
69         return true;
70 }
71