summaryrefslogtreecommitdiff
path: root/source4/torture/rpc/join.c
blob: 23c43c525ed808ad723430a6b88ade40e4536139 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "includes.h"
#include "libnet/libnet.h"
#include "libcli/libcli.h"

#include "auth/credentials/credentials.h"
#include "torture/rpc/rpc.h"

#define TORTURE_NETBIOS_NAME "smbtorturejoin"


BOOL torture_rpc_join(struct torture_context *torture)
{
	NTSTATUS status;
	struct test_join *tj;
	struct cli_credentials *machine_account;
	struct smbcli_state *cli;
	const char *host = torture_setting_string(torture, "host", NULL);

	/* Join domain as a member server. */
	tj = torture_join_domain(TORTURE_NETBIOS_NAME,
				 ACB_WSTRUST,
				 &machine_account);

	if (!tj) {
		DEBUG(0, ("%s failed to join domain as workstation\n",
			  TORTURE_NETBIOS_NAME));
		return False;
	}

	status = smbcli_full_connection(tj, &cli, host,
					"IPC$", NULL,
					machine_account,
					NULL);
	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(0, ("%s failed to connect to IPC$ with workstation credentials\n",
			  TORTURE_NETBIOS_NAME));
		return False;	
	}
	smbcli_tdis(cli);
        
	/* Leave domain. */                          
	torture_leave_domain(tj);
        
	/* Join domain as a domain controller. */
	tj = torture_join_domain(TORTURE_NETBIOS_NAME,
				 ACB_SVRTRUST,
				 &machine_account);
	if (!tj) {
		DEBUG(0, ("%s failed to join domain as domain controller\n",
			  TORTURE_NETBIOS_NAME));
		return False;
	}

	status = smbcli_full_connection(tj, &cli, host,
					"IPC$", NULL,
					machine_account,
					NULL);
	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(0, ("%s failed to connect to IPC$ with workstation credentials\n",
			  TORTURE_NETBIOS_NAME));
		return False;	
	}

	smbcli_tdis(cli);

	/* Leave domain. */
	torture_leave_domain(tj);

	return True;
}