summaryrefslogtreecommitdiff
path: root/source4/torture/rpc/frsapi.c
blob: 9ea139bf400921711c1be07456941c57db9d37ea (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/*
   Unix SMB/CIFS implementation.
   test suite for rpc frsapi operations

   Copyright (C) Guenther Deschner 2007

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "includes.h"
#include "torture/torture.h"
#include "torture/rpc/rpc.h"
#include "librpc/gen_ndr/ndr_frsapi_c.h"
#include "torture/util.h"
#include "param/param.h"

static bool test_GetDsPollingIntervalW(struct torture_context *tctx,
				       struct dcerpc_pipe *p,
				       uint32_t *CurrentInterval,
				       uint32_t *DsPollingLongInterval,
				       uint32_t *DsPollingShortInterval)
{
	struct frsapi_GetDsPollingIntervalW r;

	ZERO_STRUCT(r);

	r.out.CurrentInterval = CurrentInterval;
	r.out.DsPollingLongInterval = DsPollingLongInterval;
	r.out.DsPollingShortInterval = DsPollingShortInterval;

	torture_assert_ntstatus_ok(tctx,
		dcerpc_frsapi_GetDsPollingIntervalW(p, tctx, &r),
		"GetDsPollingIntervalW failed");

	torture_assert_werr_ok(tctx, r.out.result,
			       "GetDsPollingIntervalW failed");

	return true;
}

static bool test_SetDsPollingIntervalW(struct torture_context *tctx,
				       struct dcerpc_pipe *p,
				       uint32_t CurrentInterval,
				       uint32_t DsPollingLongInterval,
				       uint32_t DsPollingShortInterval)
{
	struct frsapi_SetDsPollingIntervalW r;

	ZERO_STRUCT(r);

	r.in.CurrentInterval = CurrentInterval;
	r.in.DsPollingLongInterval = DsPollingLongInterval;
	r.in.DsPollingShortInterval = DsPollingShortInterval;

	torture_assert_ntstatus_ok(tctx,
		dcerpc_frsapi_SetDsPollingIntervalW(p, tctx, &r),
		"SetDsPollingIntervalW failed");

	torture_assert_werr_ok(tctx, r.out.result,
			       "SetDsPollingIntervalW failed");

	return true;
}

static bool test_DsPollingIntervalW(struct torture_context *tctx,
				    struct dcerpc_pipe *p)
{
	uint32_t i1, i2, i3;
	uint32_t k1, k2, k3;

	if (!test_GetDsPollingIntervalW(tctx, p, &i1, &i2, &i3)) {
		return false;
	}

	if (!test_SetDsPollingIntervalW(tctx, p, i1, i2, i3)) {
		return false;
	}

	k1 = i1;
	k2 = k3 = 0;

	if (!test_SetDsPollingIntervalW(tctx, p, k1, k2, k3)) {
		return false;
	}

	if (!test_GetDsPollingIntervalW(tctx, p, &k1, &k2, &k3)) {
		return false;
	}

	if ((i1 != k1) || (i2 != k2) || (i3 != k3)) {
		return false;
	}

	return true;
}

static bool test_IsPathReplicated_err(struct torture_context *tctx,
				      struct dcerpc_pipe *p,
				      const char *path,
				      uint32_t type,
				      WERROR werr)
{
	struct frsapi_IsPathReplicated r;
	struct GUID guid;
	uint32_t unknown1, unknown2, unknown3 = 0;

	ZERO_STRUCT(r);

	r.in.path = path;
	r.in.replica_set_type = type;
	r.out.unknown1 = &unknown1;
	r.out.unknown2 = &unknown2;
	r.out.unknown3 = &unknown3;
	r.out.replica_set_guid = &guid;

	torture_assert_ntstatus_ok(tctx,
		dcerpc_frsapi_IsPathReplicated(p, tctx, &r),
		"IsPathReplicated failed");

	torture_assert_werr_equal(tctx, r.out.result, werr,
			          "GetDsPollingIntervalW failed");

	return true;
}

static bool _test_IsPathReplicated(struct torture_context *tctx,
				  struct dcerpc_pipe *p,
				  const char *path,
				  uint32_t type)
{
	return test_IsPathReplicated_err(tctx, p, path, type, WERR_OK);
}

static bool test_IsPathReplicated(struct torture_context *tctx,
				  struct dcerpc_pipe *p)
{
	const uint32_t lvls[] = {
		FRSAPI_REPLICA_SET_TYPE_0,
		FRSAPI_REPLICA_SET_TYPE_DOMAIN,
		FRSAPI_REPLICA_SET_TYPE_DFS };
	int i;
	bool ret = true;

	if (!test_IsPathReplicated_err(tctx, p, NULL, 0,
				       WERR_FRS_INVALID_SERVICE_PARAMETER)) {
		ret = false;
	}

	for (i=0; i<ARRAY_SIZE(lvls); i++) {
		if (!_test_IsPathReplicated(tctx, p, dcerpc_server_name(p),
					    lvls[i])) {
			ret = false;
		}
	}

	for (i=0; i<ARRAY_SIZE(lvls); i++) {
		const char *path = talloc_asprintf(tctx, "\\\\%s\\SYSVOL",
						   dcerpc_server_name(p));
		if (!_test_IsPathReplicated(tctx, p, path, lvls[i])) {
			ret = false;
		}
	}

	for (i=0; i<ARRAY_SIZE(lvls); i++) {
		if (!_test_IsPathReplicated(tctx, p,
					    "C:\\windows\\sysvol\\domain",
					    lvls[i])) {
			ret = false;
		}
	}

	return ret;
}

static bool test_ForceReplication(struct torture_context *tctx,
				  struct dcerpc_pipe *p)
{
	struct frsapi_ForceReplication r;

	ZERO_STRUCT(r);

	r.in.guid1 = NULL;
	r.in.guid2 = NULL;
	r.in.replica_set = talloc_asprintf(tctx, "%s",
					   lp_realm(global_loadparm));
	r.in.partner_name = dcerpc_server_name(p);

	torture_assert_ntstatus_ok(tctx,
		dcerpc_frsapi_ForceReplication(p, tctx, &r),
		"ForceReplication failed");

	torture_assert_werr_ok(tctx, r.out.result,
			       "ForceReplication failed");

	return true;
}

struct torture_suite *torture_rpc_frsapi(TALLOC_CTX *mem_ctx)
{
	struct torture_rpc_tcase *tcase;
	struct torture_suite *suite = torture_suite_create(mem_ctx, "FRSAPI");
	struct torture_test *test;

	tcase = torture_suite_add_rpc_iface_tcase(suite, "frsapi",
						  &ndr_table_frsapi);

	test = torture_rpc_tcase_add_test(tcase, "DsPollingIntervalW",
					  test_DsPollingIntervalW);

	test = torture_rpc_tcase_add_test(tcase, "IsPathReplicated",
					  test_IsPathReplicated);

	test = torture_rpc_tcase_add_test(tcase, "ForceReplication",
					  test_ForceReplication);


	return suite;
}