s4:tortore/rpc/spoolss: some compilers don't like .foo.bar = 5
[Samba/gebeck_regimport.git] / source4 / torture / rpc / frsapi.c
blob74b5f063477f8abbdf59b8e6e42ec1ab4f2f80dd
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/rpc/rpc.h"
24 #include "librpc/gen_ndr/ndr_frsapi_c.h"
25 #include "param/param.h"
27 static bool test_GetDsPollingIntervalW(struct torture_context *tctx,
28 struct dcerpc_binding_handle *b,
29 uint32_t *CurrentInterval,
30 uint32_t *DsPollingLongInterval,
31 uint32_t *DsPollingShortInterval)
33 struct frsapi_GetDsPollingIntervalW r;
35 ZERO_STRUCT(r);
37 r.out.CurrentInterval = CurrentInterval;
38 r.out.DsPollingLongInterval = DsPollingLongInterval;
39 r.out.DsPollingShortInterval = DsPollingShortInterval;
41 torture_assert_ntstatus_ok(tctx,
42 dcerpc_frsapi_GetDsPollingIntervalW_r(b, tctx, &r),
43 "GetDsPollingIntervalW failed");
45 torture_assert_werr_ok(tctx, r.out.result,
46 "GetDsPollingIntervalW failed");
48 return true;
51 static bool test_SetDsPollingIntervalW(struct torture_context *tctx,
52 struct dcerpc_binding_handle *b,
53 uint32_t CurrentInterval,
54 uint32_t DsPollingLongInterval,
55 uint32_t DsPollingShortInterval)
57 struct frsapi_SetDsPollingIntervalW r;
59 ZERO_STRUCT(r);
61 r.in.CurrentInterval = CurrentInterval;
62 r.in.DsPollingLongInterval = DsPollingLongInterval;
63 r.in.DsPollingShortInterval = DsPollingShortInterval;
65 torture_assert_ntstatus_ok(tctx,
66 dcerpc_frsapi_SetDsPollingIntervalW_r(b, tctx, &r),
67 "SetDsPollingIntervalW failed");
69 torture_assert_werr_ok(tctx, r.out.result,
70 "SetDsPollingIntervalW failed");
72 return true;
75 static bool test_DsPollingIntervalW(struct torture_context *tctx,
76 struct dcerpc_pipe *p)
78 struct dcerpc_binding_handle *b = p->binding_handle;
79 uint32_t i1, i2, i3;
80 uint32_t k1, k2, k3;
82 if (!test_GetDsPollingIntervalW(tctx, b, &i1, &i2, &i3)) {
83 return false;
86 if (!test_SetDsPollingIntervalW(tctx, b, i1, i2, i3)) {
87 return false;
90 k1 = i1;
91 k2 = k3 = 0;
93 if (!test_SetDsPollingIntervalW(tctx, b, k1, k2, k3)) {
94 return false;
97 if (!test_GetDsPollingIntervalW(tctx, b, &k1, &k2, &k3)) {
98 return false;
101 if ((i1 != k1) || (i2 != k2) || (i3 != k3)) {
102 return false;
105 return true;
108 static bool test_IsPathReplicated_err(struct torture_context *tctx,
109 struct dcerpc_binding_handle *b,
110 const char *path,
111 uint32_t type,
112 WERROR werr)
114 struct frsapi_IsPathReplicated r;
115 struct GUID guid;
116 uint32_t replicated, primary, root;
118 ZERO_STRUCT(r);
120 r.in.path = path;
121 r.in.replica_set_type = type;
122 r.out.replicated = &replicated;
123 r.out.primary = &primary;
124 r.out.root = &root;
125 r.out.replica_set_guid = &guid;
127 torture_assert_ntstatus_ok(tctx,
128 dcerpc_frsapi_IsPathReplicated_r(b, tctx, &r),
129 "IsPathReplicated failed");
131 torture_assert_werr_equal(tctx, r.out.result, werr,
132 "GetDsPollingIntervalW failed");
134 return true;
137 static bool _test_IsPathReplicated(struct torture_context *tctx,
138 struct dcerpc_binding_handle *b,
139 const char *path,
140 uint32_t type)
142 return test_IsPathReplicated_err(tctx, b, path, type, WERR_OK);
145 static bool test_IsPathReplicated(struct torture_context *tctx,
146 struct dcerpc_pipe *p)
148 struct dcerpc_binding_handle *b = p->binding_handle;
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, b, 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, b, 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, b, path, lvls[i])) {
172 ret = false;
176 for (i=0; i<ARRAY_SIZE(lvls); i++) {
177 if (!_test_IsPathReplicated(tctx, b,
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 dcerpc_binding_handle *b = p->binding_handle;
191 struct frsapi_ForceReplication r;
193 ZERO_STRUCT(r);
195 r.in.replica_set_guid = NULL;
196 r.in.connection_guid = NULL;
197 r.in.replica_set_name = lp_dnsdomain(tctx->lp_ctx);
198 r.in.partner_dns_name = dcerpc_server_name(p);
200 torture_assert_ntstatus_ok(tctx,
201 dcerpc_frsapi_ForceReplication_r(b, 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 struct dcerpc_binding_handle *b = p->binding_handle;
214 int i;
216 for (i=0; i<10; i++) {
218 struct frsapi_InfoW r;
219 struct frsapi_Info *info;
220 int d;
221 DATA_BLOB blob;
223 ZERO_STRUCT(r);
225 info = talloc_zero(tctx, struct frsapi_Info);
227 r.in.length = 0x1000;
228 r.in.info = r.out.info = info;
230 info->length = r.in.length;
231 info->length2 = r.in.length;
232 info->level = i;
233 info->offset = 0x2c;
234 info->blob_len = 0x2c;
236 torture_assert_ntstatus_ok(tctx,
237 dcerpc_frsapi_InfoW_r(b, tctx, &r),
238 "InfoW failed");
240 torture_assert_werr_ok(tctx, r.out.result, "InfoW failed");
242 /* display the formatted blob text */
243 blob = r.out.info->blob;
244 for (d = 0; d < blob.length; d++) {
245 if (blob.data[d]) {
246 printf("%c", blob.data[d]);
249 printf("\n");
252 return true;
255 struct torture_suite *torture_rpc_frsapi(TALLOC_CTX *mem_ctx)
257 struct torture_rpc_tcase *tcase;
258 struct torture_suite *suite = torture_suite_create(mem_ctx, "FRSAPI");
259 struct torture_test *test;
261 tcase = torture_suite_add_rpc_iface_tcase(suite, "frsapi",
262 &ndr_table_frsapi);
264 test = torture_rpc_tcase_add_test(tcase, "DsPollingIntervalW",
265 test_DsPollingIntervalW);
267 test = torture_rpc_tcase_add_test(tcase, "IsPathReplicated",
268 test_IsPathReplicated);
270 test = torture_rpc_tcase_add_test(tcase, "ForceReplication",
271 test_ForceReplication);
273 test = torture_rpc_tcase_add_test(tcase, "InfoW",
274 test_InfoW);
275 return suite;