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/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" 28 29static bool test_GetDsPollingIntervalW(struct torture_context *tctx, 30 struct dcerpc_pipe *p, 31 uint32_t *CurrentInterval, 32 uint32_t *DsPollingLongInterval, 33 uint32_t *DsPollingShortInterval) 34{ 35 struct frsapi_GetDsPollingIntervalW r; 36 37 ZERO_STRUCT(r); 38 39 r.out.CurrentInterval = CurrentInterval; 40 r.out.DsPollingLongInterval = DsPollingLongInterval; 41 r.out.DsPollingShortInterval = DsPollingShortInterval; 42 43 torture_assert_ntstatus_ok(tctx, 44 dcerpc_frsapi_GetDsPollingIntervalW(p, tctx, &r), 45 "GetDsPollingIntervalW failed"); 46 47 torture_assert_werr_ok(tctx, r.out.result, 48 "GetDsPollingIntervalW failed"); 49 50 return true; 51} 52 53static bool test_SetDsPollingIntervalW(struct torture_context *tctx, 54 struct dcerpc_pipe *p, 55 uint32_t CurrentInterval, 56 uint32_t DsPollingLongInterval, 57 uint32_t DsPollingShortInterval) 58{ 59 struct frsapi_SetDsPollingIntervalW r; 60 61 ZERO_STRUCT(r); 62 63 r.in.CurrentInterval = CurrentInterval; 64 r.in.DsPollingLongInterval = DsPollingLongInterval; 65 r.in.DsPollingShortInterval = DsPollingShortInterval; 66 67 torture_assert_ntstatus_ok(tctx, 68 dcerpc_frsapi_SetDsPollingIntervalW(p, tctx, &r), 69 "SetDsPollingIntervalW failed"); 70 71 torture_assert_werr_ok(tctx, r.out.result, 72 "SetDsPollingIntervalW failed"); 73 74 return true; 75} 76 77static bool test_DsPollingIntervalW(struct torture_context *tctx, 78 struct dcerpc_pipe *p) 79{ 80 uint32_t i1, i2, i3; 81 uint32_t k1, k2, k3; 82 83 if (!test_GetDsPollingIntervalW(tctx, p, &i1, &i2, &i3)) { 84 return false; 85 } 86 87 if (!test_SetDsPollingIntervalW(tctx, p, i1, i2, i3)) { 88 return false; 89 } 90 91 k1 = i1; 92 k2 = k3 = 0; 93 94 if (!test_SetDsPollingIntervalW(tctx, p, k1, k2, k3)) { 95 return false; 96 } 97 98 if (!test_GetDsPollingIntervalW(tctx, p, &k1, &k2, &k3)) { 99 return false; 100 } 101 102 if ((i1 != k1) || (i2 != k2) || (i3 != k3)) { 103 return false; 104 } 105 106 return true; 107} 108 109static bool test_IsPathReplicated_err(struct torture_context *tctx, 110 struct dcerpc_pipe *p, 111 const char *path, 112 uint32_t type, 113 WERROR werr) 114{ 115 struct frsapi_IsPathReplicated r; 116 struct GUID guid; 117 uint32_t replicated, primary, root; 118 119 ZERO_STRUCT(r); 120 121 r.in.path = path; 122 r.in.replica_set_type = type; 123 r.out.replicated = &replicated; 124 r.out.primary = &primary; 125 r.out.root = &root; 126 r.out.replica_set_guid = &guid; 127 128 torture_assert_ntstatus_ok(tctx, 129 dcerpc_frsapi_IsPathReplicated(p, tctx, &r), 130 "IsPathReplicated failed"); 131 132 torture_assert_werr_equal(tctx, r.out.result, werr, 133 "GetDsPollingIntervalW failed"); 134 135 return true; 136} 137 138static bool _test_IsPathReplicated(struct torture_context *tctx, 139 struct dcerpc_pipe *p, 140 const char *path, 141 uint32_t type) 142{ 143 return test_IsPathReplicated_err(tctx, p, path, type, WERR_OK); 144} 145 146static bool test_IsPathReplicated(struct torture_context *tctx, 147 struct dcerpc_pipe *p) 148{ 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, p, 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, p, 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, p, path, lvls[i])) { 172 ret = false; 173 } 174 } 175 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; 181 } 182 } 183 184 return ret; 185} 186 187static bool test_ForceReplication(struct torture_context *tctx, 188 struct dcerpc_pipe *p) 189{ 190 struct frsapi_ForceReplication r; 191 192 ZERO_STRUCT(r); 193 194 r.in.replica_set_guid = NULL; 195 r.in.connection_guid = NULL; 196 r.in.replica_set_name = talloc_asprintf(tctx, "%s", 197 lp_realm(tctx->lp_ctx)); 198 r.in.partner_dns_name = dcerpc_server_name(p); 199 200 torture_assert_ntstatus_ok(tctx, 201 dcerpc_frsapi_ForceReplication(p, tctx, &r), 202 "ForceReplication failed"); 203 204 torture_assert_werr_ok(tctx, r.out.result, 205 "ForceReplication failed"); 206 207 return true; 208} 209 210static bool test_InfoW(struct torture_context *tctx, 211 struct dcerpc_pipe *p) 212{ 213 int i; 214 215 for (i=0; i<10; i++) { 216 217 struct frsapi_InfoW r; 218 struct frsapi_Info *info; 219 int d; 220 DATA_BLOB blob; 221 222 ZERO_STRUCT(r); 223 224 info = talloc_zero(tctx, struct frsapi_Info); 225 226 r.in.length = 0x1000; 227 r.in.info = r.out.info = info; 228 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; 234 235 torture_assert_ntstatus_ok(tctx, 236 dcerpc_frsapi_InfoW(p, tctx, &r), 237 "InfoW failed"); 238 239 torture_assert_werr_ok(tctx, r.out.result, "InfoW failed"); 240 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]); 246 } 247 } 248 printf("\n"); 249 } 250 251 return true; 252} 253 254struct torture_suite *torture_rpc_frsapi(TALLOC_CTX *mem_ctx) 255{ 256 struct torture_rpc_tcase *tcase; 257 struct torture_suite *suite = torture_suite_create(mem_ctx, "FRSAPI"); 258 struct torture_test *test; 259 260 tcase = torture_suite_add_rpc_iface_tcase(suite, "frsapi", 261 &ndr_table_frsapi); 262 263 test = torture_rpc_tcase_add_test(tcase, "DsPollingIntervalW", 264 test_DsPollingIntervalW); 265 266 test = torture_rpc_tcase_add_test(tcase, "IsPathReplicated", 267 test_IsPathReplicated); 268 269 test = torture_rpc_tcase_add_test(tcase, "ForceReplication", 270 test_ForceReplication); 271 272 test = torture_rpc_tcase_add_test(tcase, "InfoW", 273 test_InfoW); 274 return suite; 275} 276