s3-docs: Adapt version in man ldbrename.
[Samba.git] / source4 / torture / rpc / frsapi.c
blobc8e421a674980201bd45a6b8835fc9e0d5c77bf8
1 /*
2 Unix SMB/CIFS implementation.
3 test suite for rpc frsapi operations
5 Copyright (C) Guenther Deschner 2007
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "includes.h"
23 #include "torture/torture.h"
24 #include "torture/rpc/rpc.h"
25 #include "librpc/gen_ndr/ndr_frsapi_c.h"
26 #include "torture/util.h"
27 #include "param/param.h"
29 static bool test_GetDsPollingIntervalW(struct torture_context *tctx,
30 struct dcerpc_pipe *p,
31 uint32_t *CurrentInterval,
32 uint32_t *DsPollingLongInterval,
33 uint32_t *DsPollingShortInterval)
35 struct frsapi_GetDsPollingIntervalW r;
37 ZERO_STRUCT(r);
39 r.out.CurrentInterval = CurrentInterval;
40 r.out.DsPollingLongInterval = DsPollingLongInterval;
41 r.out.DsPollingShortInterval = DsPollingShortInterval;
43 torture_assert_ntstatus_ok(tctx,
44 dcerpc_frsapi_GetDsPollingIntervalW(p, tctx, &r),
45 "GetDsPollingIntervalW failed");
47 torture_assert_werr_ok(tctx, r.out.result,
48 "GetDsPollingIntervalW failed");
50 return true;
53 static bool test_SetDsPollingIntervalW(struct torture_context *tctx,
54 struct dcerpc_pipe *p,
55 uint32_t CurrentInterval,
56 uint32_t DsPollingLongInterval,
57 uint32_t DsPollingShortInterval)
59 struct frsapi_SetDsPollingIntervalW r;
61 ZERO_STRUCT(r);
63 r.in.CurrentInterval = CurrentInterval;
64 r.in.DsPollingLongInterval = DsPollingLongInterval;
65 r.in.DsPollingShortInterval = DsPollingShortInterval;
67 torture_assert_ntstatus_ok(tctx,
68 dcerpc_frsapi_SetDsPollingIntervalW(p, tctx, &r),
69 "SetDsPollingIntervalW failed");
71 torture_assert_werr_ok(tctx, r.out.result,
72 "SetDsPollingIntervalW failed");
74 return true;
77 static bool test_DsPollingIntervalW(struct torture_context *tctx,
78 struct dcerpc_pipe *p)
80 uint32_t i1, i2, i3;
81 uint32_t k1, k2, k3;
83 if (!test_GetDsPollingIntervalW(tctx, p, &i1, &i2, &i3)) {
84 return false;
87 if (!test_SetDsPollingIntervalW(tctx, p, i1, i2, i3)) {
88 return false;
91 k1 = i1;
92 k2 = k3 = 0;
94 if (!test_SetDsPollingIntervalW(tctx, p, k1, k2, k3)) {
95 return false;
98 if (!test_GetDsPollingIntervalW(tctx, p, &k1, &k2, &k3)) {
99 return false;
102 if ((i1 != k1) || (i2 != k2) || (i3 != k3)) {
103 return false;
106 return true;
109 static bool test_IsPathReplicated_err(struct torture_context *tctx,
110 struct dcerpc_pipe *p,
111 const char *path,
112 uint32_t type,
113 WERROR werr)
115 struct frsapi_IsPathReplicated r;
116 struct GUID guid;
117 uint32_t unknown1, unknown2, unknown3 = 0;
119 ZERO_STRUCT(r);
121 r.in.path = path;
122 r.in.replica_set_type = type;
123 r.out.unknown1 = &unknown1;
124 r.out.unknown2 = &unknown2;
125 r.out.unknown3 = &unknown3;
126 r.out.replica_set_guid = &guid;
128 torture_assert_ntstatus_ok(tctx,
129 dcerpc_frsapi_IsPathReplicated(p, tctx, &r),
130 "IsPathReplicated failed");
132 torture_assert_werr_equal(tctx, r.out.result, werr,
133 "GetDsPollingIntervalW failed");
135 return true;
138 static bool _test_IsPathReplicated(struct torture_context *tctx,
139 struct dcerpc_pipe *p,
140 const char *path,
141 uint32_t type)
143 return test_IsPathReplicated_err(tctx, p, path, type, WERR_OK);
146 static bool test_IsPathReplicated(struct torture_context *tctx,
147 struct dcerpc_pipe *p)
149 const uint32_t lvls[] = {
150 FRSAPI_REPLICA_SET_TYPE_0,
151 FRSAPI_REPLICA_SET_TYPE_DOMAIN,
152 FRSAPI_REPLICA_SET_TYPE_DFS };
153 int i;
154 bool ret = true;
156 if (!test_IsPathReplicated_err(tctx, p, NULL, 0,
157 WERR_FRS_INVALID_SERVICE_PARAMETER)) {
158 ret = false;
161 for (i=0; i<ARRAY_SIZE(lvls); i++) {
162 if (!_test_IsPathReplicated(tctx, p, dcerpc_server_name(p),
163 lvls[i])) {
164 ret = false;
168 for (i=0; i<ARRAY_SIZE(lvls); i++) {
169 const char *path = talloc_asprintf(tctx, "\\\\%s\\SYSVOL",
170 dcerpc_server_name(p));
171 if (!_test_IsPathReplicated(tctx, p, path, lvls[i])) {
172 ret = false;
176 for (i=0; i<ARRAY_SIZE(lvls); i++) {
177 if (!_test_IsPathReplicated(tctx, p,
178 "C:\\windows\\sysvol\\domain",
179 lvls[i])) {
180 ret = false;
184 return ret;
187 static bool test_ForceReplication(struct torture_context *tctx,
188 struct dcerpc_pipe *p)
190 struct frsapi_ForceReplication r;
192 ZERO_STRUCT(r);
194 r.in.guid1 = NULL;
195 r.in.guid2 = NULL;
196 r.in.replica_set = talloc_asprintf(tctx, "%s",
197 lp_realm(tctx->lp_ctx));
198 r.in.partner_name = dcerpc_server_name(p);
200 torture_assert_ntstatus_ok(tctx,
201 dcerpc_frsapi_ForceReplication(p, tctx, &r),
202 "ForceReplication failed");
204 torture_assert_werr_ok(tctx, r.out.result,
205 "ForceReplication failed");
207 return true;
210 static bool test_InfoW(struct torture_context *tctx,
211 struct dcerpc_pipe *p)
213 int i;
215 for (i=0; i<10; i++) {
217 struct frsapi_InfoW r;
218 struct frsapi_Info *info;
219 int d;
220 DATA_BLOB blob;
222 ZERO_STRUCT(r);
224 info = talloc_zero(tctx, struct frsapi_Info);
226 r.in.length = 0x1000;
227 r.in.info = r.out.info = info;
229 info->length = r.in.length;
230 info->length2 = r.in.length;
231 info->level = i;
232 info->offset = 0x2c;
233 info->blob_len = 0x2c;
235 torture_assert_ntstatus_ok(tctx,
236 dcerpc_frsapi_InfoW(p, tctx, &r),
237 "InfoW failed");
239 torture_assert_werr_ok(tctx, r.out.result, "InfoW failed");
241 /* display the formatted blob text */
242 blob = r.out.info->blob;
243 for (d = 0; d < blob.length; d++) {
244 if (blob.data[d]) {
245 printf("%c", blob.data[d]);
248 printf("\n");
251 return true;
254 struct torture_suite *torture_rpc_frsapi(TALLOC_CTX *mem_ctx)
256 struct torture_rpc_tcase *tcase;
257 struct torture_suite *suite = torture_suite_create(mem_ctx, "FRSAPI");
258 struct torture_test *test;
260 tcase = torture_suite_add_rpc_iface_tcase(suite, "frsapi",
261 &ndr_table_frsapi);
263 test = torture_rpc_tcase_add_test(tcase, "DsPollingIntervalW",
264 test_DsPollingIntervalW);
266 test = torture_rpc_tcase_add_test(tcase, "IsPathReplicated",
267 test_IsPathReplicated);
269 test = torture_rpc_tcase_add_test(tcase, "ForceReplication",
270 test_ForceReplication);
272 test = torture_rpc_tcase_add_test(tcase, "InfoW",
273 test_InfoW);
274 return suite;