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