summaryrefslogtreecommitdiffstats
path: root/source4/torture/rpc/frsapi.c
blob: 710826a5adeae3144602667f40d3b3188423bea7 (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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/*
   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 3 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/rpc/torture_rpc.h"
#include "librpc/gen_ndr/ndr_frsapi_c.h"
#include "param/param.h"

static bool test_GetDsPollingIntervalW(struct torture_context *tctx,
				       struct dcerpc_binding_handle *b,
				       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_r(b, 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_binding_handle *b,
				       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_r(b, 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)
{
	struct dcerpc_binding_handle *b = p->binding_handle;
	uint32_t i1, i2, i3;
	uint32_t k1, k2, k3;

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

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

	k1 = i1;
	k2 = k3 = 0;

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

	if (!test_GetDsPollingIntervalW(tctx, b, &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_binding_handle *b,
				      const char *path,
				      uint32_t type,
				      WERROR werr)
{
	struct frsapi_IsPathReplicated r;
	struct GUID guid;
	uint32_t replicated, primary, root;

	ZERO_STRUCT(r);

	r.in.path = path;
	r.in.replica_set_type = type;
	r.out.replicated = &replicated;
	r.out.primary = &primary;
	r.out.root = &root;
	r.out.replica_set_guid = &guid;

	torture_assert_ntstatus_ok(tctx,
		dcerpc_frsapi_IsPathReplicated_r(b, 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_binding_handle *b,
				  const char *path,
				  uint32_t type)
{
	return test_IsPathReplicated_err(tctx, b, path, type, WERR_OK);
}

static bool test_IsPathReplicated(struct torture_context *tctx,
				  struct dcerpc_pipe *p)
{
	struct dcerpc_binding_handle *b = p->binding_handle;
	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, b, NULL, 0,
				       WERR_FRS_ERR_INVALID_SERVICE_PARAMETER)) {
		ret = false;
	}

	for (i=0; i<ARRAY_SIZE(lvls); i++) {
		if (!_test_IsPathReplicated(tctx, b, 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, b, path, lvls[i])) {
			ret = false;
		}
	}

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

	return ret;
}

static bool test_ForceReplication(struct torture_context *tctx,
				  struct dcerpc_pipe *p)
{
	struct dcerpc_binding_handle *b = p->binding_handle;
	struct frsapi_ForceReplication r;

	ZERO_STRUCT(r);

	r.in.replica_set_guid = NULL;
	r.in.connection_guid = NULL;
	r.in.replica_set_name = lpcfg_dnsdomain(tctx->lp_ctx);
	r.in.partner_dns_name = dcerpc_server_name(p);

	torture_assert_ntstatus_ok(tctx,
		dcerpc_frsapi_ForceReplication_r(b, tctx, &r),
		"ForceReplication failed");

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

	return true;
}

static bool test_InfoW(struct torture_context *tctx,
		       struct dcerpc_pipe *p)
{
	struct dcerpc_binding_handle *b = p->binding_handle;
	int i;

	for (i=0; i<10; i++) {

		struct frsapi_InfoW r;
		struct frsapi_Info *info;
		int d;
		DATA_BLOB blob;

		ZERO_STRUCT(r);

		info = talloc_zero(tctx, struct frsapi_Info);

		r.in.length = 0x1000;
		r.in.info = r.out.info = info;

		info->length = r.in.length;
		info->length2 = r.in.length;
		info->level = i;
		info->offset = 0x2c;
		info->blob_len = 0x2c;

		torture_assert_ntstatus_ok(tctx,
			dcerpc_frsapi_InfoW_r(b, tctx, &r),
			"InfoW failed");

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

		/* display the formatted blob text */
		blob = r.out.info->blob;
		for (d = 0; d < blob.length; d++) {
			if (blob.data[d]) {
				printf("%c", blob.data[d]);
			}
		}
		printf("\n");
	}

	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");

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

	torture_rpc_tcase_add_test(tcase, "DsPollingIntervalW",
				   test_DsPollingIntervalW);

	torture_rpc_tcase_add_test(tcase, "IsPathReplicated",
				   test_IsPathReplicated);

	torture_rpc_tcase_add_test(tcase, "ForceReplication",
				   test_ForceReplication);

	torture_rpc_tcase_add_test(tcase, "InfoW",
				   test_InfoW);

	return suite;
}