Cope with API changes.
[kai/samba.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 #include "libcli/resolve/resolve.h"
9 #include "param/param.h"
10
11 #define TORTURE_NETBIOS_NAME "smbtorturejoin"
12
13
14 bool torture_rpc_join(struct torture_context *torture)
15 {
16         NTSTATUS status;
17         struct test_join *tj;
18         struct cli_credentials *machine_account;
19         struct smbcli_state *cli;
20         const char *host = torture_setting_string(torture, "host", NULL);
21         struct smbcli_options options;
22         struct smbcli_session_options session_options;
23
24         /* Join domain as a member server. */
25         tj = torture_join_domain(torture,
26                                  TORTURE_NETBIOS_NAME,
27                                  ACB_WSTRUST,
28                                  &machine_account);
29
30         if (!tj) {
31                 DEBUG(0, ("%s failed to join domain as workstation\n",
32                           TORTURE_NETBIOS_NAME));
33                 return false;
34         }
35
36         lp_smbcli_options(torture->lp_ctx, &options);
37         lp_smbcli_session_options(torture->lp_ctx, &session_options);
38
39         status = smbcli_full_connection(tj, &cli, host,
40                                         lp_smb_ports(torture->lp_ctx),
41                                         "IPC$", NULL,
42                                         machine_account,
43                                         lp_resolve_context(torture->lp_ctx),
44                                         torture->ev, &options, &session_options);
45         if (!NT_STATUS_IS_OK(status)) {
46                 DEBUG(0, ("%s failed to connect to IPC$ with workstation credentials\n",
47                           TORTURE_NETBIOS_NAME));
48                 return false;   
49         }
50         smbcli_tdis(cli);
51         
52         /* Leave domain. */                          
53         torture_leave_domain(torture, tj);
54         
55         /* Join domain as a domain controller. */
56         tj = torture_join_domain(torture, TORTURE_NETBIOS_NAME,
57                                  ACB_SVRTRUST,
58                                  &machine_account);
59         if (!tj) {
60                 DEBUG(0, ("%s failed to join domain as domain controller\n",
61                           TORTURE_NETBIOS_NAME));
62                 return false;
63         }
64
65         status = smbcli_full_connection(tj, &cli, host,
66                                         lp_smb_ports(torture->lp_ctx),
67                                         "IPC$", NULL,
68                                         machine_account,
69                                         lp_resolve_context(torture->lp_ctx),
70                                         torture->ev, &options, &session_options);
71         if (!NT_STATUS_IS_OK(status)) {
72                 DEBUG(0, ("%s failed to connect to IPC$ with workstation credentials\n",
73                           TORTURE_NETBIOS_NAME));
74                 return false;   
75         }
76
77         smbcli_tdis(cli);
78
79         /* Leave domain. */
80         torture_leave_domain(torture, tj);
81
82         return true;
83 }
84