r26654: libcli/smb_composite: Rather than specifying each of the gazillion options...
[jelmer/samba4-debian.git] / source / 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
23         /* Join domain as a member server. */
24         tj = torture_join_domain(torture,
25                                  TORTURE_NETBIOS_NAME,
26                                  ACB_WSTRUST,
27                                  &machine_account);
28
29         if (!tj) {
30                 DEBUG(0, ("%s failed to join domain as workstation\n",
31                           TORTURE_NETBIOS_NAME));
32                 return false;
33         }
34
35         lp_smbcli_options(torture->lp_ctx, &options);
36
37         status = smbcli_full_connection(tj, &cli, host,
38                                         lp_smb_ports(torture->lp_ctx),
39                                         "IPC$", NULL,
40                                         machine_account,
41                                         lp_resolve_context(torture->lp_ctx),
42                                         NULL, &options);
43         if (!NT_STATUS_IS_OK(status)) {
44                 DEBUG(0, ("%s failed to connect to IPC$ with workstation credentials\n",
45                           TORTURE_NETBIOS_NAME));
46                 return false;   
47         }
48         smbcli_tdis(cli);
49         
50         /* Leave domain. */                          
51         torture_leave_domain(tj);
52         
53         /* Join domain as a domain controller. */
54         tj = torture_join_domain(torture, TORTURE_NETBIOS_NAME,
55                                  ACB_SVRTRUST,
56                                  &machine_account);
57         if (!tj) {
58                 DEBUG(0, ("%s failed to join domain as domain controller\n",
59                           TORTURE_NETBIOS_NAME));
60                 return false;
61         }
62
63         status = smbcli_full_connection(tj, &cli, host,
64                                         lp_smb_ports(torture->lp_ctx),
65                                         "IPC$", NULL,
66                                         machine_account,
67                                         lp_resolve_context(torture->lp_ctx),
68                                         NULL, &options);
69         if (!NT_STATUS_IS_OK(status)) {
70                 DEBUG(0, ("%s failed to connect to IPC$ with workstation credentials\n",
71                           TORTURE_NETBIOS_NAME));
72                 return false;   
73         }
74
75         smbcli_tdis(cli);
76
77         /* Leave domain. */
78         torture_leave_domain(tj);
79
80         return true;
81 }
82