s4-loadparm: 2nd half of lp_ to lpcfg_ conversion
[sfrench/samba-autobuild/.git] / source4 / torture / rpc / frsapi.c
1 /*
2    Unix SMB/CIFS implementation.
3    test suite for rpc frsapi operations
4
5    Copyright (C) Guenther Deschner 2007
6
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.
11
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.
16
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.
20 */
21
22 #include "includes.h"
23 #include "torture/rpc/torture_rpc.h"
24 #include "librpc/gen_ndr/ndr_frsapi_c.h"
25 #include "param/param.h"
26
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)
32 {
33         struct frsapi_GetDsPollingIntervalW r;
34
35         ZERO_STRUCT(r);
36
37         r.out.CurrentInterval = CurrentInterval;
38         r.out.DsPollingLongInterval = DsPollingLongInterval;
39         r.out.DsPollingShortInterval = DsPollingShortInterval;
40
41         torture_assert_ntstatus_ok(tctx,
42                 dcerpc_frsapi_GetDsPollingIntervalW_r(b, tctx, &r),
43                 "GetDsPollingIntervalW failed");
44
45         torture_assert_werr_ok(tctx, r.out.result,
46                                "GetDsPollingIntervalW failed");
47
48         return true;
49 }
50
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)
56 {
57         struct frsapi_SetDsPollingIntervalW r;
58
59         ZERO_STRUCT(r);
60
61         r.in.CurrentInterval = CurrentInterval;
62         r.in.DsPollingLongInterval = DsPollingLongInterval;
63         r.in.DsPollingShortInterval = DsPollingShortInterval;
64
65         torture_assert_ntstatus_ok(tctx,
66                 dcerpc_frsapi_SetDsPollingIntervalW_r(b, tctx, &r),
67                 "SetDsPollingIntervalW failed");
68
69         torture_assert_werr_ok(tctx, r.out.result,
70                                "SetDsPollingIntervalW failed");
71
72         return true;
73 }
74
75 static bool test_DsPollingIntervalW(struct torture_context *tctx,
76                                     struct dcerpc_pipe *p)
77 {
78         struct dcerpc_binding_handle *b = p->binding_handle;
79         uint32_t i1, i2, i3;
80         uint32_t k1, k2, k3;
81
82         if (!test_GetDsPollingIntervalW(tctx, b, &i1, &i2, &i3)) {
83                 return false;
84         }
85
86         if (!test_SetDsPollingIntervalW(tctx, b, i1, i2, i3)) {
87                 return false;
88         }
89
90         k1 = i1;
91         k2 = k3 = 0;
92
93         if (!test_SetDsPollingIntervalW(tctx, b, k1, k2, k3)) {
94                 return false;
95         }
96
97         if (!test_GetDsPollingIntervalW(tctx, b, &k1, &k2, &k3)) {
98                 return false;
99         }
100
101         if ((i1 != k1) || (i2 != k2) || (i3 != k3)) {
102                 return false;
103         }
104
105         return true;
106 }
107
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)
113 {
114         struct frsapi_IsPathReplicated r;
115         struct GUID guid;
116         uint32_t replicated, primary, root;
117
118         ZERO_STRUCT(r);
119
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;
126
127         torture_assert_ntstatus_ok(tctx,
128                 dcerpc_frsapi_IsPathReplicated_r(b, tctx, &r),
129                 "IsPathReplicated failed");
130
131         torture_assert_werr_equal(tctx, r.out.result, werr,
132                                   "GetDsPollingIntervalW failed");
133
134         return true;
135 }
136
137 static bool _test_IsPathReplicated(struct torture_context *tctx,
138                                   struct dcerpc_binding_handle *b,
139                                   const char *path,
140                                   uint32_t type)
141 {
142         return test_IsPathReplicated_err(tctx, b, path, type, WERR_OK);
143 }
144
145 static bool test_IsPathReplicated(struct torture_context *tctx,
146                                   struct dcerpc_pipe *p)
147 {
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;
155
156         if (!test_IsPathReplicated_err(tctx, b, NULL, 0,
157                                        WERR_FRS_INVALID_SERVICE_PARAMETER)) {
158                 ret = false;
159         }
160
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;
165                 }
166         }
167
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;
173                 }
174         }
175
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;
181                 }
182         }
183
184         return ret;
185 }
186
187 static bool test_ForceReplication(struct torture_context *tctx,
188                                   struct dcerpc_pipe *p)
189 {
190         struct dcerpc_binding_handle *b = p->binding_handle;
191         struct frsapi_ForceReplication r;
192
193         ZERO_STRUCT(r);
194
195         r.in.replica_set_guid = NULL;
196         r.in.connection_guid = NULL;
197         r.in.replica_set_name = lpcfg_dnsdomain(tctx->lp_ctx);
198         r.in.partner_dns_name = dcerpc_server_name(p);
199
200         torture_assert_ntstatus_ok(tctx,
201                 dcerpc_frsapi_ForceReplication_r(b, tctx, &r),
202                 "ForceReplication failed");
203
204         torture_assert_werr_ok(tctx, r.out.result,
205                                "ForceReplication failed");
206
207         return true;
208 }
209
210 static bool test_InfoW(struct torture_context *tctx,
211                        struct dcerpc_pipe *p)
212 {
213         struct dcerpc_binding_handle *b = p->binding_handle;
214         int i;
215
216         for (i=0; i<10; i++) {
217
218                 struct frsapi_InfoW r;
219                 struct frsapi_Info *info;
220                 int d;
221                 DATA_BLOB blob;
222
223                 ZERO_STRUCT(r);
224
225                 info = talloc_zero(tctx, struct frsapi_Info);
226
227                 r.in.length = 0x1000;
228                 r.in.info = r.out.info = info;
229
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;
235
236                 torture_assert_ntstatus_ok(tctx,
237                         dcerpc_frsapi_InfoW_r(b, tctx, &r),
238                         "InfoW failed");
239
240                 torture_assert_werr_ok(tctx, r.out.result, "InfoW failed");
241
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]);
247                         }
248                 }
249                 printf("\n");
250         }
251
252         return true;
253 }
254
255 struct torture_suite *torture_rpc_frsapi(TALLOC_CTX *mem_ctx)
256 {
257         struct torture_rpc_tcase *tcase;
258         struct torture_suite *suite = torture_suite_create(mem_ctx, "FRSAPI");
259         struct torture_test *test;
260
261         tcase = torture_suite_add_rpc_iface_tcase(suite, "frsapi",
262                                                   &ndr_table_frsapi);
263
264         test = torture_rpc_tcase_add_test(tcase, "DsPollingIntervalW",
265                                           test_DsPollingIntervalW);
266
267         test = torture_rpc_tcase_add_test(tcase, "IsPathReplicated",
268                                           test_IsPathReplicated);
269
270         test = torture_rpc_tcase_add_test(tcase, "ForceReplication",
271                                           test_ForceReplication);
272
273         test = torture_rpc_tcase_add_test(tcase, "InfoW",
274                                           test_InfoW);
275         return suite;
276 }