LCOV - code coverage report
Current view: top level - source4/torture/rpc - frsapi.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 9 117 7.7 %
Date: 2024-04-21 15:09:00 Functions: 1 9 11.1 %

          Line data    Source code
       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           0 : 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           0 :         struct frsapi_GetDsPollingIntervalW r;
      34             : 
      35           0 :         ZERO_STRUCT(r);
      36             : 
      37           0 :         r.out.CurrentInterval = CurrentInterval;
      38           0 :         r.out.DsPollingLongInterval = DsPollingLongInterval;
      39           0 :         r.out.DsPollingShortInterval = DsPollingShortInterval;
      40             : 
      41           0 :         torture_assert_ntstatus_ok(tctx,
      42             :                 dcerpc_frsapi_GetDsPollingIntervalW_r(b, tctx, &r),
      43             :                 "GetDsPollingIntervalW failed");
      44             : 
      45           0 :         torture_assert_werr_ok(tctx, r.out.result,
      46             :                                "GetDsPollingIntervalW failed");
      47             : 
      48           0 :         return true;
      49             : }
      50             : 
      51           0 : 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           0 :         struct frsapi_SetDsPollingIntervalW r;
      58             : 
      59           0 :         ZERO_STRUCT(r);
      60             : 
      61           0 :         r.in.CurrentInterval = CurrentInterval;
      62           0 :         r.in.DsPollingLongInterval = DsPollingLongInterval;
      63           0 :         r.in.DsPollingShortInterval = DsPollingShortInterval;
      64             : 
      65           0 :         torture_assert_ntstatus_ok(tctx,
      66             :                 dcerpc_frsapi_SetDsPollingIntervalW_r(b, tctx, &r),
      67             :                 "SetDsPollingIntervalW failed");
      68             : 
      69           0 :         torture_assert_werr_ok(tctx, r.out.result,
      70             :                                "SetDsPollingIntervalW failed");
      71             : 
      72           0 :         return true;
      73             : }
      74             : 
      75           0 : static bool test_DsPollingIntervalW(struct torture_context *tctx,
      76             :                                     struct dcerpc_pipe *p)
      77             : {
      78           0 :         struct dcerpc_binding_handle *b = p->binding_handle;
      79           0 :         uint32_t i1, i2, i3;
      80           0 :         uint32_t k1, k2, k3;
      81             : 
      82           0 :         if (!test_GetDsPollingIntervalW(tctx, b, &i1, &i2, &i3)) {
      83           0 :                 return false;
      84             :         }
      85             : 
      86           0 :         if (!test_SetDsPollingIntervalW(tctx, b, i1, i2, i3)) {
      87           0 :                 return false;
      88             :         }
      89             : 
      90           0 :         k1 = i1;
      91           0 :         k2 = k3 = 0;
      92             : 
      93           0 :         if (!test_SetDsPollingIntervalW(tctx, b, k1, k2, k3)) {
      94           0 :                 return false;
      95             :         }
      96             : 
      97           0 :         if (!test_GetDsPollingIntervalW(tctx, b, &k1, &k2, &k3)) {
      98           0 :                 return false;
      99             :         }
     100             : 
     101           0 :         if ((i1 != k1) || (i2 != k2) || (i3 != k3)) {
     102           0 :                 return false;
     103             :         }
     104             : 
     105           0 :         return true;
     106             : }
     107             : 
     108           0 : 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           0 :         struct frsapi_IsPathReplicated r;
     115           0 :         struct GUID guid;
     116           0 :         uint32_t replicated, primary, root;
     117             : 
     118           0 :         ZERO_STRUCT(r);
     119             : 
     120           0 :         r.in.path = path;
     121           0 :         r.in.replica_set_type = type;
     122           0 :         r.out.replicated = &replicated;
     123           0 :         r.out.primary = &primary;
     124           0 :         r.out.root = &root;
     125           0 :         r.out.replica_set_guid = &guid;
     126             : 
     127           0 :         torture_assert_ntstatus_ok(tctx,
     128             :                 dcerpc_frsapi_IsPathReplicated_r(b, tctx, &r),
     129             :                 "IsPathReplicated failed");
     130             : 
     131           0 :         torture_assert_werr_equal(tctx, r.out.result, werr,
     132             :                                   "GetDsPollingIntervalW failed");
     133             : 
     134           0 :         return true;
     135             : }
     136             : 
     137           0 : static bool _test_IsPathReplicated(struct torture_context *tctx,
     138             :                                   struct dcerpc_binding_handle *b,
     139             :                                   const char *path,
     140             :                                   uint32_t type)
     141             : {
     142           0 :         return test_IsPathReplicated_err(tctx, b, path, type, WERR_OK);
     143             : }
     144             : 
     145           0 : static bool test_IsPathReplicated(struct torture_context *tctx,
     146             :                                   struct dcerpc_pipe *p)
     147             : {
     148           0 :         struct dcerpc_binding_handle *b = p->binding_handle;
     149           0 :         const uint32_t lvls[] = {
     150             :                 FRSAPI_REPLICA_SET_TYPE_0,
     151             :                 FRSAPI_REPLICA_SET_TYPE_DOMAIN,
     152             :                 FRSAPI_REPLICA_SET_TYPE_DFS };
     153           0 :         int i;
     154           0 :         bool ret = true;
     155             : 
     156           0 :         if (!test_IsPathReplicated_err(tctx, b, NULL, 0,
     157           0 :                                        WERR_FRS_ERR_INVALID_SERVICE_PARAMETER)) {
     158           0 :                 ret = false;
     159             :         }
     160             : 
     161           0 :         for (i=0; i<ARRAY_SIZE(lvls); i++) {
     162           0 :                 if (!_test_IsPathReplicated(tctx, b, dcerpc_server_name(p),
     163           0 :                                             lvls[i])) {
     164           0 :                         ret = false;
     165             :                 }
     166             :         }
     167             : 
     168           0 :         for (i=0; i<ARRAY_SIZE(lvls); i++) {
     169           0 :                 const char *path = talloc_asprintf(tctx, "\\\\%s\\SYSVOL",
     170             :                                                    dcerpc_server_name(p));
     171           0 :                 if (!_test_IsPathReplicated(tctx, b, path, lvls[i])) {
     172           0 :                         ret = false;
     173             :                 }
     174             :         }
     175             : 
     176           0 :         for (i=0; i<ARRAY_SIZE(lvls); i++) {
     177           0 :                 if (!_test_IsPathReplicated(tctx, b,
     178             :                                             "C:\\windows\\sysvol\\domain",
     179           0 :                                             lvls[i])) {
     180           0 :                         ret = false;
     181             :                 }
     182             :         }
     183             : 
     184           0 :         return ret;
     185             : }
     186             : 
     187           0 : static bool test_ForceReplication(struct torture_context *tctx,
     188             :                                   struct dcerpc_pipe *p)
     189             : {
     190           0 :         struct dcerpc_binding_handle *b = p->binding_handle;
     191           0 :         struct frsapi_ForceReplication r;
     192             : 
     193           0 :         ZERO_STRUCT(r);
     194             : 
     195           0 :         r.in.replica_set_guid = NULL;
     196           0 :         r.in.connection_guid = NULL;
     197           0 :         r.in.replica_set_name = lpcfg_dnsdomain(tctx->lp_ctx);
     198           0 :         r.in.partner_dns_name = dcerpc_server_name(p);
     199             : 
     200           0 :         torture_assert_ntstatus_ok(tctx,
     201             :                 dcerpc_frsapi_ForceReplication_r(b, tctx, &r),
     202             :                 "ForceReplication failed");
     203             : 
     204           0 :         torture_assert_werr_ok(tctx, r.out.result,
     205             :                                "ForceReplication failed");
     206             : 
     207           0 :         return true;
     208             : }
     209             : 
     210           0 : static bool test_InfoW(struct torture_context *tctx,
     211             :                        struct dcerpc_pipe *p)
     212             : {
     213           0 :         struct dcerpc_binding_handle *b = p->binding_handle;
     214           0 :         int i;
     215             : 
     216           0 :         for (i=0; i<10; i++) {
     217             : 
     218           0 :                 struct frsapi_InfoW r;
     219           0 :                 struct frsapi_Info *info;
     220           0 :                 int d;
     221           0 :                 DATA_BLOB blob;
     222             : 
     223           0 :                 ZERO_STRUCT(r);
     224             : 
     225           0 :                 info = talloc_zero(tctx, struct frsapi_Info);
     226             : 
     227           0 :                 r.in.length = 0x1000;
     228           0 :                 r.in.info = r.out.info = info;
     229             : 
     230           0 :                 info->length = r.in.length;
     231           0 :                 info->length2 = r.in.length;
     232           0 :                 info->level = i;
     233           0 :                 info->offset = 0x2c;
     234           0 :                 info->blob_len = 0x2c;
     235             : 
     236           0 :                 torture_assert_ntstatus_ok(tctx,
     237             :                         dcerpc_frsapi_InfoW_r(b, tctx, &r),
     238             :                         "InfoW failed");
     239             : 
     240           0 :                 torture_assert_werr_ok(tctx, r.out.result, "InfoW failed");
     241             : 
     242             :                 /* display the formatted blob text */
     243           0 :                 blob = r.out.info->blob;
     244           0 :                 for (d = 0; d < blob.length; d++) {
     245           0 :                         if (blob.data[d]) {
     246           0 :                                 printf("%c", blob.data[d]);
     247             :                         }
     248             :                 }
     249           0 :                 printf("\n");
     250             :         }
     251             : 
     252           0 :         return true;
     253             : }
     254             : 
     255        2354 : struct torture_suite *torture_rpc_frsapi(TALLOC_CTX *mem_ctx)
     256             : {
     257         125 :         struct torture_rpc_tcase *tcase;
     258        2354 :         struct torture_suite *suite = torture_suite_create(mem_ctx, "frsapi");
     259             : 
     260        2354 :         tcase = torture_suite_add_rpc_iface_tcase(suite, "frsapi",
     261             :                                                   &ndr_table_frsapi);
     262             : 
     263        2354 :         torture_rpc_tcase_add_test(tcase, "DsPollingIntervalW",
     264             :                                    test_DsPollingIntervalW);
     265             : 
     266        2354 :         torture_rpc_tcase_add_test(tcase, "IsPathReplicated",
     267             :                                    test_IsPathReplicated);
     268             : 
     269        2354 :         torture_rpc_tcase_add_test(tcase, "ForceReplication",
     270             :                                    test_ForceReplication);
     271             : 
     272        2354 :         torture_rpc_tcase_add_test(tcase, "InfoW",
     273             :                                    test_InfoW);
     274             : 
     275        2354 :         return suite;
     276             : }

Generated by: LCOV version 1.14