LCOV - code coverage report
Current view: top level - source4/torture/rpc - wkssvc.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 361 776 46.5 %
Date: 2024-04-21 15:09:00 Functions: 26 35 74.3 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    test suite for wkssvc rpc operations
       4             : 
       5             :    Copyright (C) Andrew Tridgell 2003
       6             :    Copyright (C) Günther Deschner 2007
       7             : 
       8             :    This program is free software; you can redistribute it and/or modify
       9             :    it under the terms of the GNU General Public License as published by
      10             :    the Free Software Foundation; either version 3 of the License, or
      11             :    (at your option) any later version.
      12             : 
      13             :    This program is distributed in the hope that it will be useful,
      14             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :    GNU General Public License for more details.
      17             : 
      18             :    You should have received a copy of the GNU General Public License
      19             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      20             : */
      21             : 
      22             : #include "includes.h"
      23             : #include "torture/torture.h"
      24             : #include "librpc/gen_ndr/ndr_wkssvc_c.h"
      25             : #include "torture/rpc/torture_rpc.h"
      26             : #include "lib/cmdline/cmdline.h"
      27             : #include "param/param.h"
      28             : #include "libcli/auth/libcli_auth.h"
      29             : 
      30             : #define SMBTORTURE_MACHINE_NAME "smbtrt_name"
      31             : #define SMBTORTURE_ALTERNATE_NAME "smbtrt_altname"
      32             : #define SMBTORTURE_TRANSPORT_NAME "\\Device\\smbtrt_transport_name"
      33             : #define SMBTORTURE_USE_NAME "S:"
      34             : #define SMBTORTURE_MESSAGE "You are currently tortured by Samba"
      35             : 
      36           5 : static bool test_NetWkstaGetInfo(struct torture_context *tctx,
      37             :                                  struct dcerpc_pipe *p)
      38             : {
      39           0 :         NTSTATUS status;
      40           0 :         struct wkssvc_NetWkstaGetInfo r;
      41           0 :         union wkssvc_NetWkstaInfo info;
      42           5 :         uint16_t levels[] = {100, 101, 102, 502};
      43           0 :         int i;
      44           5 :         struct dcerpc_binding_handle *b = p->binding_handle;
      45             : 
      46           5 :         r.in.server_name = dcerpc_server_name(p);
      47           5 :         r.out.info = &info;
      48             : 
      49          17 :         for (i=0;i<ARRAY_SIZE(levels);i++) {
      50          17 :                 r.in.level = levels[i];
      51          17 :                 torture_comment(tctx, "Testing NetWkstaGetInfo level %u\n",
      52             :                                 r.in.level);
      53          17 :                 status = dcerpc_wkssvc_NetWkstaGetInfo_r(b, tctx, &r);
      54          17 :                 torture_assert_ntstatus_ok(tctx, status,
      55             :                         talloc_asprintf(tctx, "NetWkstaGetInfo level %u failed",
      56             :                                         r.in.level));
      57          17 :                 torture_assert_werr_ok(tctx, r.out.result,
      58             :                         talloc_asprintf(tctx, "NetWkstaGetInfo level %u failed",
      59             :                                         r.in.level));
      60             :         }
      61             : 
      62           0 :         return true;
      63             : }
      64             : 
      65           5 : static bool test_NetWkstaTransportEnum(struct torture_context *tctx,
      66             :                                        struct dcerpc_pipe *p)
      67             : {
      68           0 :         NTSTATUS status;
      69           0 :         struct wkssvc_NetWkstaTransportEnum r;
      70           5 :         uint32_t resume_handle = 0;
      71           0 :         struct wkssvc_NetWkstaTransportInfo info;
      72           0 :         union wkssvc_NetWkstaTransportCtr ctr;
      73           0 :         struct wkssvc_NetWkstaTransportCtr0 ctr0;
      74           5 :         uint32_t total_entries = 0;
      75           5 :         struct dcerpc_binding_handle *b = p->binding_handle;
      76             : 
      77           5 :         ZERO_STRUCT(ctr0);
      78           5 :         ctr.ctr0 = &ctr0;
      79             : 
      80           5 :         info.level = 0;
      81           5 :         info.ctr = ctr;
      82             : 
      83           5 :         r.in.server_name = dcerpc_server_name(p);
      84           5 :         r.in.info = &info;
      85           5 :         r.in.max_buffer = (uint32_t)-1;
      86           5 :         r.in.resume_handle = &resume_handle;
      87           5 :         r.out.total_entries = &total_entries;
      88           5 :         r.out.info = &info;
      89           5 :         r.out.resume_handle = &resume_handle;
      90             : 
      91           5 :         torture_comment(tctx, "Testing NetWkstaTransportEnum level 0\n");
      92             : 
      93           5 :         status = dcerpc_wkssvc_NetWkstaTransportEnum_r(b, tctx, &r);
      94           5 :         torture_assert_ntstatus_ok(tctx, status,
      95             :                                    "NetWkstaTransportEnum failed");
      96           3 :         torture_assert_werr_ok(tctx, r.out.result, talloc_asprintf(tctx,
      97             :                                "NetWkstaTransportEnum level %u failed",
      98             :                                info.level));
      99             : 
     100           0 :         return true;
     101             : }
     102             : 
     103           5 : static bool test_NetrWkstaTransportAdd(struct torture_context *tctx,
     104             :                                        struct dcerpc_pipe *p)
     105             : {
     106           0 :         NTSTATUS status;
     107           0 :         struct wkssvc_NetrWkstaTransportAdd r;
     108           0 :         struct wkssvc_NetWkstaTransportInfo0 info0;
     109           5 :         uint32_t parm_err = 0;
     110           5 :         struct dcerpc_binding_handle *b = p->binding_handle;
     111             : 
     112           5 :         ZERO_STRUCT(info0);
     113             : 
     114           5 :         info0.quality_of_service = 0xffff;
     115           5 :         info0.vc_count = 0;
     116           5 :         info0.name = SMBTORTURE_TRANSPORT_NAME;
     117           5 :         info0.address = "000000000000";
     118           5 :         info0.wan_link = 0x400;
     119             : 
     120           5 :         r.in.server_name = dcerpc_server_name(p);
     121           5 :         r.in.level = 0;
     122           5 :         r.in.info0 = &info0;
     123           5 :         r.in.parm_err = r.out.parm_err = &parm_err;
     124             : 
     125           5 :         torture_comment(tctx, "Testing NetrWkstaTransportAdd level 0\n");
     126             : 
     127           5 :         status = dcerpc_wkssvc_NetrWkstaTransportAdd_r(b, tctx, &r);
     128           5 :         torture_assert_ntstatus_ok(tctx, status,
     129             :                                    "NetrWkstaTransportAdd failed");
     130           0 :         torture_assert_werr_equal(tctx, r.out.result,
     131             :                                   WERR_INVALID_PARAMETER,
     132             :                                   "NetrWkstaTransportAdd level 0 failed");
     133             : 
     134           0 :         return true;
     135             : }
     136             : 
     137           5 : static bool test_NetrWkstaTransportDel(struct torture_context *tctx,
     138             :                                        struct dcerpc_pipe *p)
     139             : {
     140           0 :         NTSTATUS status;
     141           0 :         struct wkssvc_NetrWkstaTransportDel r;
     142           5 :         struct dcerpc_binding_handle *b = p->binding_handle;
     143             : 
     144           5 :         r.in.server_name = dcerpc_server_name(p);
     145           5 :         r.in.transport_name = SMBTORTURE_TRANSPORT_NAME;
     146           5 :         r.in.unknown3 = 0;
     147             : 
     148           5 :         torture_comment(tctx, "Testing NetrWkstaTransportDel\n");
     149             : 
     150           5 :         status = dcerpc_wkssvc_NetrWkstaTransportDel_r(b, tctx, &r);
     151           5 :         torture_assert_ntstatus_ok(tctx, status,
     152             :                                    "NetrWkstaTransportDel failed");
     153           0 :         torture_assert_werr_ok(tctx, r.out.result,
     154             :                                "NetrWkstaTransportDel");
     155             : 
     156           0 :         return true;
     157             : }
     158             : 
     159           5 : static bool test_NetWkstaEnumUsers(struct torture_context *tctx,
     160             :                                    struct dcerpc_pipe *p)
     161             : {
     162           0 :         NTSTATUS status;
     163           0 :         struct wkssvc_NetWkstaEnumUsers r;
     164           5 :         uint32_t handle = 0;
     165           5 :         uint32_t entries_read = 0;
     166           0 :         struct wkssvc_NetWkstaEnumUsersInfo info;
     167           0 :         struct wkssvc_NetWkstaEnumUsersCtr0 *user0;
     168           0 :         struct wkssvc_NetWkstaEnumUsersCtr1 *user1;
     169           5 :         uint32_t levels[] = { 0, 1 };
     170           0 :         int i;
     171           5 :         struct dcerpc_binding_handle *b = p->binding_handle;
     172             : 
     173           9 :         for (i=0; i<ARRAY_SIZE(levels); i++) {
     174             : 
     175           7 :                 ZERO_STRUCT(info);
     176             : 
     177           7 :                 info.level = levels[i];
     178           7 :                 switch (info.level) {
     179           5 :                 case 0:
     180           5 :                         user0 = talloc_zero(tctx,
     181             :                                             struct wkssvc_NetWkstaEnumUsersCtr0);
     182           5 :                         info.ctr.user0 = user0;
     183           5 :                         break;
     184           2 :                 case 1:
     185           2 :                         user1 = talloc_zero(tctx,
     186             :                                             struct wkssvc_NetWkstaEnumUsersCtr1);
     187           2 :                         info.ctr.user1 = user1;
     188           2 :                         break;
     189           0 :                 default:
     190           0 :                         break;
     191             :                 }
     192             : 
     193           7 :                 r.in.server_name = dcerpc_server_name(p);
     194           7 :                 r.in.prefmaxlen = (uint32_t)-1;
     195           7 :                 r.in.info = r.out.info = &info;
     196           7 :                 r.in.resume_handle = r.out.resume_handle = &handle;
     197             : 
     198           7 :                 r.out.entries_read = &entries_read;
     199             : 
     200           7 :                 torture_comment(tctx, "Testing NetWkstaEnumUsers level %u\n",
     201             :                                 levels[i]);
     202             : 
     203           7 :                 status = dcerpc_wkssvc_NetWkstaEnumUsers_r(b, tctx, &r);
     204           7 :                 torture_assert_ntstatus_ok(tctx, status,
     205             :                                            "NetWkstaEnumUsers failed");
     206           4 :                 torture_assert_werr_ok(tctx, r.out.result,
     207             :                                        "NetWkstaEnumUsers failed");
     208             :         }
     209             : 
     210           2 :         return true;
     211             : }
     212             : 
     213           5 : static bool test_NetrWkstaUserGetInfo(struct torture_context *tctx,
     214             :                                       struct dcerpc_pipe *p)
     215             : {
     216           0 :         NTSTATUS status;
     217           0 :         struct wkssvc_NetrWkstaUserGetInfo r;
     218           0 :         union wkssvc_NetrWkstaUserInfo info;
     219           5 :         const char *dom = lpcfg_workgroup(tctx->lp_ctx);
     220           5 :         struct cli_credentials *creds = samba_cmdline_get_creds();
     221           5 :         const char *user = cli_credentials_get_username(creds);
     222           0 :         int i;
     223           5 :         struct dcerpc_binding_handle *b = p->binding_handle;
     224             : 
     225           0 :         const struct {
     226             :                 const char *unknown;
     227             :                 uint32_t level;
     228             :                 WERROR result;
     229           5 :         } tests[] = {
     230             :                 { NULL, 0, WERR_NO_SUCH_LOGON_SESSION },
     231             :                 { NULL, 1, WERR_NO_SUCH_LOGON_SESSION },
     232             :                 { NULL, 1101, WERR_OK },
     233             :                 { dom, 0, WERR_INVALID_PARAMETER },
     234             :                 { dom, 1, WERR_INVALID_PARAMETER },
     235             :                 { dom, 1101, WERR_INVALID_PARAMETER },
     236             :                 { user, 0, WERR_INVALID_PARAMETER },
     237             :                 { user, 1, WERR_INVALID_PARAMETER },
     238             :                 { user, 1101, WERR_INVALID_PARAMETER },
     239             :         };
     240             : 
     241           5 :         for (i=0; i<ARRAY_SIZE(tests); i++) {
     242           5 :                 r.in.unknown = tests[i].unknown;
     243           5 :                 r.in.level = tests[i].level;
     244           5 :                 r.out.info = &info;
     245             : 
     246           5 :                 torture_comment(tctx, "Testing NetrWkstaUserGetInfo level %u\n",
     247             :                                 r.in.level);
     248             : 
     249           5 :                 status = dcerpc_wkssvc_NetrWkstaUserGetInfo_r(b, tctx, &r);
     250           5 :                 torture_assert_ntstatus_ok(tctx, status,
     251             :                                            "NetrWkstaUserGetInfo failed");
     252           0 :                 torture_assert_werr_equal(tctx, r.out.result,
     253             :                                           tests[i].result,
     254             :                                           "NetrWkstaUserGetInfo failed");
     255             :         }
     256             : 
     257           0 :         return true;
     258             : }
     259             : 
     260           5 : static bool test_NetrUseEnum(struct torture_context *tctx,
     261             :                              struct dcerpc_pipe *p)
     262             : {
     263           0 :         NTSTATUS status;
     264           0 :         struct wkssvc_NetrUseEnum r;
     265           5 :         uint32_t handle = 0;
     266           5 :         uint32_t entries_read = 0;
     267           0 :         struct wkssvc_NetrUseEnumInfo info;
     268           0 :         struct wkssvc_NetrUseEnumCtr0 *use0;
     269           0 :         struct wkssvc_NetrUseEnumCtr1 *use1;
     270           0 :         struct wkssvc_NetrUseEnumCtr2 *use2;
     271           5 :         uint32_t levels[] = { 0, 1, 2 };
     272           0 :         int i;
     273           5 :         struct dcerpc_binding_handle *b = p->binding_handle;
     274             : 
     275           5 :         for (i=0; i<ARRAY_SIZE(levels); i++) {
     276             : 
     277           5 :                 ZERO_STRUCT(info);
     278             : 
     279           5 :                 info.level = levels[i];
     280           5 :                 switch (info.level) {
     281           5 :                 case 0:
     282           5 :                         use0 = talloc_zero(tctx, struct wkssvc_NetrUseEnumCtr0);
     283           5 :                         info.ctr.ctr0 = use0;
     284           5 :                         break;
     285           0 :                 case 1:
     286           0 :                         use1 = talloc_zero(tctx, struct wkssvc_NetrUseEnumCtr1);
     287           0 :                         info.ctr.ctr1 = use1;
     288           0 :                         break;
     289           0 :                 case 2:
     290           0 :                         use2 = talloc_zero(tctx, struct wkssvc_NetrUseEnumCtr2);
     291           0 :                         info.ctr.ctr2 = use2;
     292           0 :                         break;
     293           0 :                 default:
     294           0 :                         break;
     295             :                 }
     296             : 
     297           5 :                 r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
     298           5 :                 r.in.prefmaxlen = (uint32_t)-1;
     299           5 :                 r.in.info = r.out.info = &info;
     300           5 :                 r.in.resume_handle = r.out.resume_handle = &handle;
     301             : 
     302           5 :                 r.out.entries_read = &entries_read;
     303             : 
     304           5 :                 torture_comment(tctx, "Testing NetrUseEnum level %u\n",
     305             :                                 levels[i]);
     306             : 
     307           5 :                 status = dcerpc_wkssvc_NetrUseEnum_r(b, tctx, &r);
     308           5 :                 torture_assert_ntstatus_ok(tctx, status,
     309             :                                            "NetrUseEnum failed");
     310           0 :                 torture_assert_werr_ok(tctx, r.out.result,
     311             :                                        "NetrUseEnum failed");
     312             :         }
     313             : 
     314           0 :         return true;
     315             : }
     316             : 
     317           5 : static bool test_NetrUseAdd(struct torture_context *tctx,
     318             :                             struct dcerpc_pipe *p)
     319             : {
     320           0 :         NTSTATUS status;
     321           0 :         struct wkssvc_NetrUseAdd r;
     322           0 :         struct wkssvc_NetrUseInfo0 info0;
     323           0 :         struct wkssvc_NetrUseInfo1 info1;
     324           0 :         union wkssvc_NetrUseGetInfoCtr *ctr;
     325           5 :         uint32_t parm_err = 0;
     326           5 :         struct dcerpc_binding_handle *b = p->binding_handle;
     327             : 
     328           5 :         ctr = talloc(tctx, union wkssvc_NetrUseGetInfoCtr);
     329             : 
     330           5 :         ZERO_STRUCT(info0);
     331             : 
     332           5 :         info0.local = SMBTORTURE_USE_NAME;
     333           5 :         info0.remote = "\\\\localhost\\c$";
     334             : 
     335           5 :         ctr->info0 = &info0;
     336             : 
     337           5 :         r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
     338           5 :         r.in.level = 0;
     339           5 :         r.in.ctr = ctr;
     340           5 :         r.in.parm_err = r.out.parm_err = &parm_err;
     341             : 
     342           5 :         torture_comment(tctx, "Testing NetrUseAdd level %u\n",
     343             :                         r.in.level);
     344             : 
     345           5 :         status = dcerpc_wkssvc_NetrUseAdd_r(b, tctx, &r);
     346           5 :         torture_assert_ntstatus_ok(tctx, status,
     347             :                                    "NetrUseAdd failed");
     348           0 :         torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_LEVEL,
     349             :                                "NetrUseAdd failed");
     350             : 
     351           0 :         ZERO_STRUCT(r);
     352           0 :         ZERO_STRUCT(info1);
     353             : 
     354           0 :         info1.local = SMBTORTURE_USE_NAME;
     355           0 :         info1.remote = "\\\\localhost\\sysvol";
     356           0 :         info1.password = NULL;
     357             : 
     358           0 :         ctr->info1 = &info1;
     359             : 
     360           0 :         r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
     361           0 :         r.in.level = 1;
     362           0 :         r.in.ctr = ctr;
     363           0 :         r.in.parm_err = r.out.parm_err = &parm_err;
     364             : 
     365           0 :         torture_comment(tctx, "Testing NetrUseAdd level %u\n",
     366             :                         r.in.level);
     367             : 
     368           0 :         status = dcerpc_wkssvc_NetrUseAdd_r(b, tctx, &r);
     369           0 :         torture_assert_ntstatus_ok(tctx, status,
     370             :                                    "NetrUseAdd failed");
     371           0 :         torture_assert_werr_ok(tctx, r.out.result,
     372             :                                "NetrUseAdd failed");
     373             : 
     374           0 :         return true;
     375             : }
     376             : 
     377           5 : static bool test_NetrUseDel(struct torture_context *tctx,
     378             :                             struct dcerpc_pipe *p)
     379             : {
     380           0 :         NTSTATUS status;
     381           0 :         struct wkssvc_NetrUseDel r;
     382           5 :         struct dcerpc_binding_handle *b = p->binding_handle;
     383             : 
     384           5 :         r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
     385           5 :         r.in.use_name = SMBTORTURE_USE_NAME;
     386           5 :         r.in.force_cond = 0;
     387             : 
     388           5 :         torture_comment(tctx, "Testing NetrUseDel\n");
     389             : 
     390           5 :         status = dcerpc_wkssvc_NetrUseDel_r(b, tctx, &r);
     391           5 :         torture_assert_ntstatus_ok(tctx, status,
     392             :                                    "NetrUseDel failed");
     393           0 :         torture_assert_werr_ok(tctx, r.out.result,
     394             :                                "NetrUseDel failed");
     395           0 :         return true;
     396             : }
     397             : 
     398           0 : static bool test_NetrUseGetInfo_level(struct torture_context *tctx,
     399             :                                       struct dcerpc_pipe *p,
     400             :                                       const char *use_name,
     401             :                                       uint32_t level,
     402             :                                       WERROR werr)
     403             : {
     404           0 :         NTSTATUS status;
     405           0 :         struct wkssvc_NetrUseGetInfo r;
     406           0 :         union wkssvc_NetrUseGetInfoCtr ctr;
     407           0 :         struct dcerpc_binding_handle *b = p->binding_handle;
     408             : 
     409           0 :         ZERO_STRUCT(ctr);
     410             : 
     411           0 :         r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
     412           0 :         r.in.use_name = use_name;
     413           0 :         r.in.level = level;
     414           0 :         r.out.ctr = &ctr;
     415           0 :         status = dcerpc_wkssvc_NetrUseGetInfo_r(b, tctx, &r);
     416             : 
     417           0 :         torture_assert_ntstatus_ok(tctx, status,
     418             :                                    "NetrUseGetInfo failed");
     419           0 :         torture_assert_werr_equal(tctx, r.out.result, werr,
     420             :                                   "NetrUseGetInfo failed");
     421           0 :         return true;
     422             : }
     423             : 
     424           5 : static bool test_NetrUseGetInfo(struct torture_context *tctx,
     425             :                                 struct dcerpc_pipe *p)
     426             : {
     427           0 :         NTSTATUS status;
     428           0 :         struct wkssvc_NetrUseEnum r;
     429           5 :         uint32_t handle = 0;
     430           5 :         uint32_t entries_read = 0;
     431           0 :         struct wkssvc_NetrUseEnumInfo info;
     432           0 :         struct wkssvc_NetrUseEnumCtr0 *use0;
     433           5 :         uint32_t levels[] = { 0, 1, 2 };
     434           5 :         const char *use_name = NULL;
     435           0 :         int i, k;
     436           5 :         struct dcerpc_binding_handle *b = p->binding_handle;
     437             : 
     438           5 :         ZERO_STRUCT(info);
     439             : 
     440           5 :         info.level = 0;
     441           5 :         use0 = talloc_zero(tctx, struct wkssvc_NetrUseEnumCtr0);
     442           5 :         info.ctr.ctr0 = use0;
     443             : 
     444           5 :         r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
     445           5 :         r.in.prefmaxlen = (uint32_t)-1;
     446           5 :         r.in.info = r.out.info = &info;
     447           5 :         r.in.resume_handle = r.out.resume_handle = &handle;
     448           5 :         r.out.entries_read = &entries_read;
     449             : 
     450           5 :         status = dcerpc_wkssvc_NetrUseEnum_r(b, tctx, &r);
     451           5 :         torture_assert_ntstatus_ok(tctx, status,
     452             :                                    "NetrUseEnum failed");
     453           0 :         torture_assert_werr_ok(tctx, r.out.result,
     454             :                                "NetrUseEnum failed");
     455             : 
     456           0 :         for (k=0; k < r.out.info->ctr.ctr0->count; k++) {
     457             : 
     458           0 :                 use_name = r.out.info->ctr.ctr0->array[k].local;
     459             : 
     460           0 :                 for (i=0; i<ARRAY_SIZE(levels); i++) {
     461             : 
     462           0 :                         if (!test_NetrUseGetInfo_level(tctx, p, use_name,
     463             :                                                        levels[i],
     464           0 :                                                        WERR_OK))
     465             :                         {
     466           0 :                                 if (levels[i] != 0) {
     467           0 :                                         return false;
     468             :                                 }
     469             :                         }
     470             :                 }
     471             : 
     472           0 :                 use_name = r.out.info->ctr.ctr0->array[k].remote;
     473             : 
     474           0 :                 for (i=0; i<ARRAY_SIZE(levels); i++) {
     475             : 
     476           0 :                         if (!test_NetrUseGetInfo_level(tctx, p, use_name,
     477             :                                                        levels[i],
     478           0 :                                                        WERR_NERR_USENOTFOUND))
     479             :                         {
     480           0 :                                 if (levels[i] != 0) {
     481           0 :                                         return false;
     482             :                                 }
     483             :                         }
     484             :                 }
     485             :         }
     486             : 
     487           0 :         return true;
     488             : }
     489             : 
     490           5 : static bool test_NetrLogonDomainNameAdd(struct torture_context *tctx,
     491             :                                         struct dcerpc_pipe *p)
     492             : {
     493           0 :         NTSTATUS status;
     494           0 :         struct wkssvc_NetrLogonDomainNameAdd r;
     495           5 :         struct dcerpc_binding_handle *b = p->binding_handle;
     496             : 
     497           5 :         r.in.domain_name = lpcfg_workgroup(tctx->lp_ctx);
     498             : 
     499           5 :         torture_comment(tctx, "Testing NetrLogonDomainNameAdd\n");
     500             : 
     501           5 :         status = dcerpc_wkssvc_NetrLogonDomainNameAdd_r(b, tctx, &r);
     502           5 :         torture_assert_ntstatus_ok(tctx, status,
     503             :                                    "NetrLogonDomainNameAdd failed");
     504           0 :         torture_assert_werr_equal(tctx, r.out.result, WERR_NOT_SUPPORTED,
     505             :                                   "NetrLogonDomainNameAdd failed");
     506           0 :         return true;
     507             : }
     508             : 
     509           5 : static bool test_NetrLogonDomainNameDel(struct torture_context *tctx,
     510             :                                         struct dcerpc_pipe *p)
     511             : {
     512           0 :         NTSTATUS status;
     513           0 :         struct wkssvc_NetrLogonDomainNameDel r;
     514           5 :         struct dcerpc_binding_handle *b = p->binding_handle;
     515             : 
     516           5 :         r.in.domain_name = lpcfg_workgroup(tctx->lp_ctx);
     517             : 
     518           5 :         torture_comment(tctx, "Testing NetrLogonDomainNameDel\n");
     519             : 
     520           5 :         status = dcerpc_wkssvc_NetrLogonDomainNameDel_r(b, tctx, &r);
     521           5 :         torture_assert_ntstatus_ok(tctx, status,
     522             :                                    "NetrLogonDomainNameDel failed");
     523           0 :         torture_assert_werr_equal(tctx, r.out.result, WERR_NOT_SUPPORTED,
     524             :                                   "NetrLogonDomainNameDel failed");
     525           0 :         return true;
     526             : }
     527             : 
     528           5 : static bool test_NetrEnumerateComputerNames_level(struct torture_context *tctx,
     529             :                                                   struct dcerpc_pipe *p,
     530             :                                                   uint16_t level,
     531             :                                                   const char ***names,
     532             :                                                   size_t *num_names)
     533             : {
     534           0 :         NTSTATUS status;
     535           0 :         struct wkssvc_NetrEnumerateComputerNames r;
     536           0 :         struct wkssvc_ComputerNamesCtr *ctr;
     537           0 :         int i;
     538           5 :         struct dcerpc_binding_handle *b = p->binding_handle;
     539             : 
     540           5 :         ctr = talloc_zero(tctx, struct wkssvc_ComputerNamesCtr);
     541             : 
     542           5 :         r.in.server_name = dcerpc_server_name(p);
     543           5 :         r.in.name_type = level;
     544           5 :         r.in.Reserved = 0;
     545           5 :         r.out.ctr = &ctr;
     546             : 
     547           5 :         torture_comment(tctx, "Testing NetrEnumerateComputerNames level %u\n",
     548           5 :                         r.in.name_type);
     549             : 
     550           5 :         status = dcerpc_wkssvc_NetrEnumerateComputerNames_r(b, tctx, &r);
     551           5 :         torture_assert_ntstatus_ok(tctx, status,
     552             :                                    "NetrEnumerateComputerNames failed");
     553           0 :         torture_assert_werr_ok(tctx, r.out.result,
     554             :                                "NetrEnumerateComputerNames failed");
     555             : 
     556           0 :         if ((level == NetPrimaryComputerName) && ctr->count != 1) {
     557           0 :                 torture_comment(tctx,
     558             :                                 "NetrEnumerateComputerNames did not return one "
     559           0 :                                 "name but %u\n", ctr->count);
     560           0 :                 return false;
     561             :         }
     562             : 
     563           0 :         if (names && num_names) {
     564           0 :                 *num_names = 0;
     565           0 :                 *names = NULL;
     566           0 :                 for (i=0; i<ctr->count; i++) {
     567           0 :                         if (!add_string_to_array(tctx,
     568           0 :                                                  ctr->computer_name[i].string,
     569             :                                                  names,
     570             :                                                  num_names))
     571             :                         {
     572           0 :                                 return false;
     573             :                         }
     574             :                 }
     575             :         }
     576             : 
     577           0 :         return true;
     578             : }
     579             : 
     580           5 : static bool test_NetrEnumerateComputerNames(struct torture_context *tctx,
     581             :                                             struct dcerpc_pipe *p)
     582             : {
     583           5 :         uint16_t levels[] = {0,1,2};
     584           0 :         int i;
     585             : 
     586           5 :         for (i=0; i<ARRAY_SIZE(levels); i++) {
     587             : 
     588           5 :                 if (!test_NetrEnumerateComputerNames_level(tctx,
     589             :                                                            p,
     590           5 :                                                            levels[i],
     591             :                                                            NULL, NULL))
     592             :                 {
     593           5 :                         return false;
     594             :                 }
     595             :         }
     596             : 
     597           0 :         return true;
     598             : }
     599             : 
     600           5 : static bool test_NetrValidateName(struct torture_context *tctx,
     601             :                                   struct dcerpc_pipe *p)
     602             : {
     603           0 :         NTSTATUS status;
     604           0 :         struct wkssvc_NetrValidateName r;
     605           5 :         uint16_t levels[] = {0,1,2,3,4,5};
     606           0 :         int i;
     607           5 :         struct dcerpc_binding_handle *b = p->binding_handle;
     608             : 
     609           5 :         for (i=0; i<ARRAY_SIZE(levels); i++) {
     610             : 
     611           5 :                 r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
     612           5 :                 r.in.name = lpcfg_workgroup(tctx->lp_ctx);
     613           5 :                 r.in.Account = NULL;
     614           5 :                 r.in.Password = NULL;
     615           5 :                 r.in.name_type = levels[i];
     616             : 
     617           5 :                 torture_comment(tctx, "Testing NetrValidateName level %u\n",
     618           5 :                                 r.in.name_type);
     619             : 
     620           5 :                 status = dcerpc_wkssvc_NetrValidateName_r(b, tctx, &r);
     621           5 :                 torture_assert_ntstatus_ok(tctx, status,
     622             :                                            "NetrValidateName failed");
     623           0 :                 torture_assert_werr_equal(tctx, r.out.result,
     624             :                                           WERR_NOT_SUPPORTED,
     625             :                                           "NetrValidateName failed");
     626             :         }
     627             : 
     628           0 :         return true;
     629             : }
     630             : 
     631           5 : static bool test_NetrValidateName2(struct torture_context *tctx,
     632             :                                    struct dcerpc_pipe *p)
     633             : {
     634           0 :         NTSTATUS status;
     635           0 :         struct wkssvc_NetrValidateName2 r;
     636           5 :         uint16_t levels[] = {0,1,2,3,4,5};
     637           0 :         int i;
     638           5 :         struct dcerpc_binding_handle *b = p->binding_handle;
     639             : 
     640           5 :         for (i=0; i<ARRAY_SIZE(levels); i++) {
     641             : 
     642           5 :                 r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
     643           5 :                 r.in.name = lpcfg_workgroup(tctx->lp_ctx);
     644           5 :                 r.in.Account = NULL;
     645           5 :                 r.in.EncryptedPassword = NULL;
     646           5 :                 r.in.name_type = levels[i];
     647             : 
     648           5 :                 torture_comment(tctx, "Testing NetrValidateName2 level %u\n",
     649           5 :                                 r.in.name_type);
     650             : 
     651           5 :                 status = dcerpc_wkssvc_NetrValidateName2_r(b, tctx, &r);
     652           5 :                 torture_assert_ntstatus_ok(tctx, status,
     653             :                                            "NetrValidateName2 failed");
     654           0 :                 torture_assert_werr_equal(tctx, r.out.result,
     655             :                                           W_ERROR(HRES_ERROR_V(HRES_RPC_E_REMOTE_DISABLED)),
     656             :                                           "NetrValidateName2 failed");
     657             :         }
     658             : 
     659           0 :         return true;
     660             : }
     661             : 
     662           5 : static bool test_NetrAddAlternateComputerName(struct torture_context *tctx,
     663             :                                               struct dcerpc_pipe *p)
     664             : {
     665           0 :         NTSTATUS status;
     666           0 :         struct wkssvc_NetrAddAlternateComputerName r;
     667           5 :         const char **names = NULL;
     668           5 :         size_t num_names = 0;
     669           0 :         int i;
     670           5 :         struct dcerpc_binding_handle *b = p->binding_handle;
     671             : 
     672           5 :         r.in.server_name = dcerpc_server_name(p);
     673           5 :         r.in.NewAlternateMachineName = SMBTORTURE_ALTERNATE_NAME;
     674           5 :         r.in.Account = NULL;
     675           5 :         r.in.EncryptedPassword = NULL;
     676           5 :         r.in.Reserved = 0;
     677             : 
     678           5 :         torture_comment(tctx, "Testing NetrAddAlternateComputerName\n");
     679             : 
     680           5 :         status = dcerpc_wkssvc_NetrAddAlternateComputerName_r(b, tctx, &r);
     681           5 :         torture_assert_ntstatus_ok(tctx, status,
     682             :                                    "NetrAddAlternateComputerName failed");
     683           0 :         torture_assert_werr_ok(tctx, r.out.result,
     684             :                                "NetrAddAlternateComputerName failed");
     685             : 
     686           0 :         if (!test_NetrEnumerateComputerNames_level(tctx, p,
     687             :                                                    NetAlternateComputerNames,
     688             :                                                    &names, &num_names))
     689             :         {
     690           0 :                 return false;
     691             :         }
     692             : 
     693           0 :         for (i=0; i<num_names; i++) {
     694           0 :                 if (strequal(names[i], SMBTORTURE_ALTERNATE_NAME)) {
     695           0 :                         return true;
     696             :                 }
     697             :         }
     698             : 
     699           0 :         torture_comment(tctx, "new alternate name not set\n");
     700             : 
     701           0 :         return false;
     702             : }
     703             : 
     704           5 : static bool test_NetrRemoveAlternateComputerName(struct torture_context *tctx,
     705             :                                                  struct dcerpc_pipe *p)
     706             : {
     707           0 :         NTSTATUS status;
     708           0 :         struct wkssvc_NetrRemoveAlternateComputerName r;
     709           5 :         const char **names = NULL;
     710           5 :         size_t num_names = 0;
     711           0 :         int i;
     712           5 :         struct dcerpc_binding_handle *b = p->binding_handle;
     713             : 
     714           5 :         r.in.server_name = dcerpc_server_name(p);
     715           5 :         r.in.AlternateMachineNameToRemove = SMBTORTURE_ALTERNATE_NAME;
     716           5 :         r.in.Account = NULL;
     717           5 :         r.in.EncryptedPassword = NULL;
     718           5 :         r.in.Reserved = 0;
     719             : 
     720           5 :         torture_comment(tctx, "Testing NetrRemoveAlternateComputerName\n");
     721             : 
     722           5 :         status = dcerpc_wkssvc_NetrRemoveAlternateComputerName_r(b, tctx, &r);
     723           5 :         torture_assert_ntstatus_ok(tctx, status,
     724             :                                    "NetrRemoveAlternateComputerName failed");
     725           0 :         torture_assert_werr_ok(tctx, r.out.result,
     726             :                                "NetrRemoveAlternateComputerName failed");
     727             : 
     728           0 :         if (!test_NetrEnumerateComputerNames_level(tctx, p,
     729             :                                                    NetAlternateComputerNames,
     730             :                                                    &names, &num_names))
     731             :         {
     732           0 :                 return false;
     733             :         }
     734             : 
     735           0 :         for (i=0; i<num_names; i++) {
     736           0 :                 if (strequal(names[i], SMBTORTURE_ALTERNATE_NAME)) {
     737           0 :                         return false;
     738             :                 }
     739             :         }
     740             : 
     741           0 :         return true;
     742             : }
     743             : 
     744           0 : static bool test_NetrSetPrimaryComputername_name(struct torture_context *tctx,
     745             :                                                  struct dcerpc_pipe *p,
     746             :                                                  const char *name)
     747             : {
     748           0 :         NTSTATUS status;
     749           0 :         struct wkssvc_NetrSetPrimaryComputername r;
     750           0 :         struct dcerpc_binding_handle *b = p->binding_handle;
     751             : 
     752           0 :         r.in.server_name = dcerpc_server_name(p);
     753           0 :         r.in.primary_name = name;
     754           0 :         r.in.Account = NULL;
     755           0 :         r.in.EncryptedPassword = NULL;
     756           0 :         r.in.Reserved = 0;
     757             : 
     758           0 :         status = dcerpc_wkssvc_NetrSetPrimaryComputername_r(b, tctx, &r);
     759           0 :         torture_assert_ntstatus_ok(tctx, status,
     760             :                                    "NetrSetPrimaryComputername failed");
     761           0 :         torture_assert_werr_ok(tctx, r.out.result,
     762             :                                "NetrSetPrimaryComputername failed");
     763           0 :         return true;
     764             : }
     765             : 
     766             : 
     767           0 : static bool test_NetrSetPrimaryComputername(struct torture_context *tctx,
     768             :                                             struct dcerpc_pipe *p)
     769             : {
     770             :         /*
     771             :           add alternate,
     772             :           check if there
     773             :           store old primary
     774             :           set new primary (alternate)
     775             :           check if there
     776             :           later: check if del is possible
     777             :           set primary back to origin
     778             :           check if there
     779             :           del alternate
     780             :         */
     781             : 
     782           0 :         const char **names_o = NULL, **names = NULL;
     783           0 :         size_t num_names_o = 0, num_names = 0;
     784             : 
     785           0 :         torture_comment(tctx, "Testing NetrSetPrimaryComputername\n");
     786             : 
     787           0 :         if (!test_NetrAddAlternateComputerName(tctx, p)) {
     788           0 :                 return false;
     789             :         }
     790             : 
     791           0 :         if (!test_NetrEnumerateComputerNames_level(tctx, p,
     792             :                                                    NetPrimaryComputerName,
     793             :                                                    &names_o, &num_names_o))
     794             :         {
     795           0 :                 return false;
     796             :         }
     797             : 
     798           0 :         if (num_names_o != 1) {
     799           0 :                 return false;
     800             :         }
     801             : 
     802           0 :         if (!test_NetrSetPrimaryComputername_name(tctx, p,
     803             :                                                   SMBTORTURE_ALTERNATE_NAME))
     804             :         {
     805           0 :                 return false;
     806             :         }
     807             : 
     808           0 :         if (!test_NetrEnumerateComputerNames_level(tctx, p,
     809             :                                                    NetPrimaryComputerName,
     810             :                                                    &names, &num_names))
     811             :         {
     812           0 :                 return false;
     813             :         }
     814             : 
     815           0 :         if (num_names != 1) {
     816           0 :                 return false;
     817             :         }
     818             : 
     819           0 :         if (!strequal(names[0], SMBTORTURE_ALTERNATE_NAME)) {
     820           0 :                 torture_comment(tctx,
     821             :                                 "name mismatch (%s != %s) after NetrSetPrimaryComputername!\n",
     822             :                                 names[0], SMBTORTURE_ALTERNATE_NAME);
     823           0 :                 /*return false */;
     824             :         }
     825             : 
     826           0 :         if (!test_NetrSetPrimaryComputername_name(tctx, p,
     827             :                                                   names_o[0]))
     828             :         {
     829           0 :                 return false;
     830             :         }
     831             : 
     832           0 :         if (!test_NetrRemoveAlternateComputerName(tctx, p)) {
     833           0 :                 return false;
     834             :         }
     835             : 
     836             : 
     837           0 :         return true;
     838             : }
     839             : 
     840           0 : static bool test_NetrRenameMachineInDomain(struct torture_context *tctx,
     841             :                                            struct dcerpc_pipe *p)
     842             : {
     843           0 :         NTSTATUS status;
     844           0 :         struct wkssvc_NetrRenameMachineInDomain r;
     845           0 :         struct dcerpc_binding_handle *b = p->binding_handle;
     846             : 
     847           0 :         r.in.server_name = dcerpc_server_name(p);
     848           0 :         r.in.NewMachineName = SMBTORTURE_MACHINE_NAME;
     849           0 :         r.in.Account = NULL;
     850           0 :         r.in.password = NULL;
     851           0 :         r.in.RenameOptions = 0;
     852             : 
     853           0 :         torture_comment(tctx, "Testing NetrRenameMachineInDomain\n");
     854             : 
     855           0 :         status = dcerpc_wkssvc_NetrRenameMachineInDomain_r(b, tctx, &r);
     856           0 :         torture_assert_ntstatus_ok(tctx, status,
     857             :                                    "NetrRenameMachineInDomain failed");
     858           0 :         torture_assert_werr_equal(tctx, r.out.result, WERR_NOT_SUPPORTED,
     859             :                                   "NetrRenameMachineInDomain failed");
     860           0 :         return true;
     861             : }
     862             : 
     863           0 : static bool test_NetrRenameMachineInDomain2_name(struct torture_context *tctx,
     864             :                                                  struct dcerpc_pipe *p,
     865             :                                                  const char *new_name)
     866             : {
     867           0 :         NTSTATUS status;
     868           0 :         struct wkssvc_NetrRenameMachineInDomain2 r;
     869           0 :         struct dcerpc_binding_handle *b = p->binding_handle;
     870             : 
     871           0 :         r.in.server_name = dcerpc_server_name(p);
     872           0 :         r.in.NewMachineName = new_name;
     873           0 :         r.in.Account = NULL;
     874           0 :         r.in.EncryptedPassword = NULL;
     875           0 :         r.in.RenameOptions = 0;
     876             : 
     877           0 :         status = dcerpc_wkssvc_NetrRenameMachineInDomain2_r(b, tctx, &r);
     878           0 :         torture_assert_ntstatus_ok(tctx, status,
     879             :                                    "NetrRenameMachineInDomain2 failed");
     880           0 :         torture_assert_werr_ok(tctx, r.out.result,
     881             :                                "NetrRenameMachineInDomain2 failed");
     882           0 :         return true;
     883             : }
     884             : 
     885           0 : static bool test_NetrRenameMachineInDomain2(struct torture_context *tctx,
     886             :                                             struct dcerpc_pipe *p)
     887             : {
     888           0 :         const char **names_o = NULL, **names = NULL;
     889           0 :         size_t num_names_o = 0, num_names = 0;
     890             : 
     891           0 :         torture_comment(tctx, "Testing NetrRenameMachineInDomain2\n");
     892             : 
     893           0 :         if (!test_NetrEnumerateComputerNames_level(tctx, p,
     894             :                                                    NetPrimaryComputerName,
     895             :                                                    &names_o, &num_names_o))
     896             :         {
     897           0 :                 return false;
     898             :         }
     899             : 
     900           0 :         if (num_names_o != 1) {
     901           0 :                 return false;
     902             :         }
     903             : 
     904           0 :         if (!test_NetrRenameMachineInDomain2_name(tctx, p,
     905             :                                                   SMBTORTURE_MACHINE_NAME))
     906             :         {
     907           0 :                 return false;
     908             :         }
     909             : 
     910           0 :         if (!test_NetrEnumerateComputerNames_level(tctx, p,
     911             :                                                    NetPrimaryComputerName,
     912             :                                                    &names, &num_names))
     913             :         {
     914           0 :                 return false;
     915             :         }
     916             : 
     917           0 :         if (num_names != 1) {
     918           0 :                 return false;
     919             :         }
     920             : 
     921           0 :         if (strequal(names[0], names_o[0])) {
     922           0 :                 test_NetrRenameMachineInDomain2_name(tctx, p, names_o[0]);
     923           0 :                 return false;
     924             :         }
     925             : 
     926           0 :         if (!strequal(names[0], SMBTORTURE_MACHINE_NAME)) {
     927           0 :                 test_NetrRenameMachineInDomain2_name(tctx, p, names_o[0]);
     928           0 :                 return false;
     929             :         }
     930             : 
     931           0 :         if (!test_NetrRenameMachineInDomain2_name(tctx, p, names_o[0]))
     932             :         {
     933           0 :                 return false;
     934             :         }
     935             : 
     936           0 :         if (!test_NetrEnumerateComputerNames_level(tctx, p,
     937             :                                                    NetPrimaryComputerName,
     938             :                                                    &names, &num_names))
     939             :         {
     940           0 :                 return false;
     941             :         }
     942             : 
     943           0 :         if (num_names != 1) {
     944           0 :                 return false;
     945             :         }
     946             : 
     947           0 :         if (!strequal(names[0], names_o[0])) {
     948           0 :                 return false;
     949             :         }
     950             : 
     951           0 :         return true;
     952             : }
     953             : 
     954           5 : static bool test_NetrWorkstationStatisticsGet(struct torture_context *tctx,
     955             :                                               struct dcerpc_pipe *p)
     956             : {
     957           0 :         NTSTATUS status;
     958           0 :         struct wkssvc_NetrWorkstationStatisticsGet r;
     959           0 :         struct wkssvc_NetrWorkstationStatistics *info;
     960           5 :         struct dcerpc_binding_handle *b = p->binding_handle;
     961             : 
     962           5 :         ZERO_STRUCT(r);
     963             : 
     964           5 :         info = talloc_zero(tctx, struct wkssvc_NetrWorkstationStatistics);
     965             : 
     966           5 :         r.in.server_name = dcerpc_server_name(p);
     967           5 :         r.out.info = &info;
     968             : 
     969           5 :         torture_comment(tctx, "Testing NetrWorkstationStatisticsGet\n");
     970             : 
     971           5 :         status = dcerpc_wkssvc_NetrWorkstationStatisticsGet_r(b, tctx, &r);
     972           5 :         torture_assert_ntstatus_ok(tctx, status,
     973             :                                    "NetrWorkstationStatisticsGet failed");
     974           0 :         torture_assert_werr_ok(tctx, r.out.result,
     975             :                                "NetrWorkstationStatisticsGet failed");
     976           0 :         return true;
     977             : }
     978             : 
     979             : /* only succeeds as long as the local messenger service is running - Guenther */
     980             : 
     981           5 : static bool test_NetrMessageBufferSend(struct torture_context *tctx,
     982             :                                        struct dcerpc_pipe *p)
     983             : {
     984           0 :         NTSTATUS status;
     985           0 :         struct wkssvc_NetrMessageBufferSend r;
     986           5 :         const char *message = SMBTORTURE_MESSAGE;
     987           0 :         size_t size;
     988           0 :         uint16_t *msg;
     989           5 :         struct dcerpc_binding_handle *b = p->binding_handle;
     990             : 
     991           5 :         if (!push_ucs2_talloc(tctx, &msg, message, &size)) {
     992           0 :                 return false;
     993             :         }
     994             : 
     995           5 :         r.in.server_name = dcerpc_server_name(p);
     996           5 :         r.in.message_name = dcerpc_server_name(p);
     997           5 :         r.in.message_sender_name = dcerpc_server_name(p);
     998           5 :         r.in.message_buffer = (uint8_t *)msg;
     999           5 :         r.in.message_size = size;
    1000             : 
    1001           5 :         torture_comment(tctx, "Testing NetrMessageBufferSend\n");
    1002             : 
    1003           5 :         status = dcerpc_wkssvc_NetrMessageBufferSend_r(b, tctx, &r);
    1004           5 :         torture_assert_ntstatus_ok(tctx, status,
    1005             :                                    "NetrMessageBufferSend failed");
    1006           0 :         torture_assert_werr_ok(tctx, r.out.result,
    1007             :                                "NetrMessageBufferSend failed");
    1008           0 :         return true;
    1009             : }
    1010             : 
    1011           5 : static bool test_NetrGetJoinInformation(struct torture_context *tctx,
    1012             :                                         struct dcerpc_pipe *p)
    1013             : {
    1014           0 :         NTSTATUS status;
    1015           0 :         struct wkssvc_NetrGetJoinInformation r;
    1016           0 :         enum wkssvc_NetJoinStatus join_status;
    1017           5 :         const char *name_buffer = "";
    1018           5 :         struct dcerpc_binding_handle *b = p->binding_handle;
    1019             : 
    1020           5 :         r.in.server_name = dcerpc_server_name(p);
    1021           5 :         r.in.name_buffer = r.out.name_buffer = &name_buffer;
    1022           5 :         r.out.name_type = &join_status;
    1023             : 
    1024           5 :         torture_comment(tctx, "Testing NetrGetJoinInformation\n");
    1025             : 
    1026           5 :         status = dcerpc_wkssvc_NetrGetJoinInformation_r(b, tctx, &r);
    1027           5 :         torture_assert_ntstatus_ok(tctx, status,
    1028             :                                    "NetrGetJoinInformation failed");
    1029           0 :         torture_assert_werr_ok(tctx, r.out.result,
    1030             :                                "NetrGetJoinInformation failed");
    1031           0 :         return true;
    1032             : }
    1033             : 
    1034           0 : static bool test_GetJoinInformation(struct torture_context *tctx,
    1035             :                                     struct dcerpc_pipe *p,
    1036             :                                     enum wkssvc_NetJoinStatus *join_status_p,
    1037             :                                     const char **name)
    1038             : {
    1039           0 :         NTSTATUS status;
    1040           0 :         struct wkssvc_NetrGetJoinInformation r;
    1041           0 :         enum wkssvc_NetJoinStatus join_status;
    1042           0 :         const char *name_buffer = "";
    1043           0 :         struct dcerpc_binding_handle *b = p->binding_handle;
    1044             : 
    1045           0 :         r.in.server_name = dcerpc_server_name(p);
    1046           0 :         r.in.name_buffer = r.out.name_buffer = &name_buffer;
    1047           0 :         r.out.name_type = &join_status;
    1048             : 
    1049           0 :         status = dcerpc_wkssvc_NetrGetJoinInformation_r(b, tctx, &r);
    1050           0 :         torture_assert_ntstatus_ok(tctx, status,
    1051             :                                    "NetrGetJoinInformation failed");
    1052           0 :         torture_assert_werr_ok(tctx, r.out.result,
    1053             :                                "NetrGetJoinInformation failed");
    1054             : 
    1055           0 :         if (join_status_p) {
    1056           0 :                 *join_status_p = join_status;
    1057             :         }
    1058             : 
    1059           0 :         if (*name) {
    1060           0 :                 *name = talloc_strdup(tctx, name_buffer);
    1061             :         }
    1062             : 
    1063           0 :         return true;
    1064             : 
    1065             : }
    1066             : 
    1067           5 : static bool test_NetrGetJoinableOus(struct torture_context *tctx,
    1068             :                                     struct dcerpc_pipe *p)
    1069             : {
    1070           0 :         NTSTATUS status;
    1071           0 :         struct wkssvc_NetrGetJoinableOus r;
    1072           5 :         uint32_t num_ous = 0;
    1073           5 :         const char **ous = NULL;
    1074           5 :         struct dcerpc_binding_handle *b = p->binding_handle;
    1075             : 
    1076           5 :         r.in.server_name = dcerpc_server_name(p);
    1077           5 :         r.in.domain_name = lpcfg_workgroup(tctx->lp_ctx);
    1078           5 :         r.in.Account = NULL;
    1079           5 :         r.in.unknown = NULL;
    1080           5 :         r.in.num_ous = r.out.num_ous = &num_ous;
    1081           5 :         r.out.ous = &ous;
    1082             : 
    1083           5 :         torture_comment(tctx, "Testing NetrGetJoinableOus\n");
    1084             : 
    1085           5 :         status = dcerpc_wkssvc_NetrGetJoinableOus_r(b, tctx, &r);
    1086           5 :         torture_assert_ntstatus_ok(tctx, status, "NetrGetJoinableOus failed");
    1087           0 :         torture_assert_werr_equal(tctx, r.out.result,
    1088             :                                   WERR_NOT_SUPPORTED,
    1089             :                                   "NetrGetJoinableOus failed");
    1090             : 
    1091           0 :         return true;
    1092             : }
    1093             : 
    1094           5 : static bool test_NetrGetJoinableOus2(struct torture_context *tctx,
    1095             :                                      struct dcerpc_pipe *p)
    1096             : {
    1097           0 :         NTSTATUS status;
    1098           0 :         struct wkssvc_NetrGetJoinableOus2 r;
    1099           5 :         uint32_t num_ous = 0;
    1100           5 :         const char **ous = NULL;
    1101           5 :         struct dcerpc_binding_handle *b = p->binding_handle;
    1102             : 
    1103           5 :         r.in.server_name = dcerpc_server_name(p);
    1104           5 :         r.in.domain_name = lpcfg_workgroup(tctx->lp_ctx);
    1105           5 :         r.in.Account = NULL;
    1106           5 :         r.in.EncryptedPassword = NULL;
    1107           5 :         r.in.num_ous = r.out.num_ous = &num_ous;
    1108           5 :         r.out.ous = &ous;
    1109             : 
    1110           5 :         torture_comment(tctx, "Testing NetrGetJoinableOus2\n");
    1111             : 
    1112           5 :         status = dcerpc_wkssvc_NetrGetJoinableOus2_r(b, tctx, &r);
    1113           5 :         torture_assert_ntstatus_ok(tctx, status, "NetrGetJoinableOus2 failed");
    1114           0 :         torture_assert_werr_equal(tctx, r.out.result,
    1115             :                                   W_ERROR(HRES_ERROR_V(HRES_RPC_E_REMOTE_DISABLED)),
    1116             :                                   "NetrGetJoinableOus2 failed");
    1117             : 
    1118           0 :         return true;
    1119             : }
    1120             : 
    1121           5 : static bool test_NetrUnjoinDomain(struct torture_context *tctx,
    1122             :                                   struct dcerpc_pipe *p)
    1123             : {
    1124           0 :         NTSTATUS status;
    1125           0 :         struct wkssvc_NetrUnjoinDomain r;
    1126           5 :         struct cli_credentials *creds = samba_cmdline_get_creds();
    1127           5 :         const char *user = cli_credentials_get_username(creds);
    1128           5 :         const char *admin_account = NULL;
    1129           5 :         struct dcerpc_binding_handle *b = p->binding_handle;
    1130             : 
    1131           5 :         admin_account = talloc_asprintf(tctx, "%s\\%s",
    1132             :                                         lpcfg_workgroup(tctx->lp_ctx),
    1133             :                                         user);
    1134             : 
    1135           5 :         r.in.server_name = dcerpc_server_name(p);
    1136           5 :         r.in.Account = admin_account;
    1137           5 :         r.in.password = NULL;
    1138           5 :         r.in.unjoin_flags = 0;
    1139             : 
    1140           5 :         torture_comment(tctx, "Testing NetrUnjoinDomain\n");
    1141             : 
    1142           5 :         status = dcerpc_wkssvc_NetrUnjoinDomain_r(b, tctx, &r);
    1143           5 :         torture_assert_ntstatus_ok(tctx, status,
    1144             :                                    "NetrUnjoinDomain failed");
    1145           0 :         torture_assert_werr_equal(tctx, r.out.result, WERR_NOT_SUPPORTED,
    1146             :                                   "NetrUnjoinDomain failed");
    1147           0 :         return true;
    1148             : }
    1149             : 
    1150           5 : static bool test_NetrJoinDomain(struct torture_context *tctx,
    1151             :                                 struct dcerpc_pipe *p)
    1152             : {
    1153           0 :         NTSTATUS status;
    1154           0 :         struct wkssvc_NetrJoinDomain r;
    1155           5 :         struct cli_credentials *creds = samba_cmdline_get_creds();
    1156           5 :         const char *user = cli_credentials_get_username(creds);
    1157           5 :         const char *admin_account = NULL;
    1158           5 :         struct dcerpc_binding_handle *b = p->binding_handle;
    1159             : 
    1160           5 :         admin_account = talloc_asprintf(tctx, "%s\\%s",
    1161             :                                         lpcfg_workgroup(tctx->lp_ctx),
    1162             :                                         user);
    1163             : 
    1164           5 :         r.in.server_name = dcerpc_server_name(p);
    1165           5 :         r.in.domain_name = lpcfg_dnsdomain(tctx->lp_ctx);
    1166           5 :         r.in.account_ou = NULL;
    1167           5 :         r.in.Account = admin_account;
    1168           5 :         r.in.password = NULL;
    1169           5 :         r.in.join_flags = 0;
    1170             : 
    1171           5 :         torture_comment(tctx, "Testing NetrJoinDomain\n");
    1172             : 
    1173           5 :         status = dcerpc_wkssvc_NetrJoinDomain_r(b, tctx, &r);
    1174           5 :         torture_assert_ntstatus_ok(tctx, status,
    1175             :                                    "NetrJoinDomain failed");
    1176           0 :         torture_assert_werr_equal(tctx, r.out.result, WERR_NOT_SUPPORTED,
    1177             :                                   "NetrJoinDomain failed");
    1178           0 :         return true;
    1179             : }
    1180             : 
    1181             : /*
    1182             :  * prerequisites for remotely joining an unjoined XP SP2 workstation:
    1183             :  * - firewall needs to be disabled (or open for ncacn_np access)
    1184             :  * - HKLM\System\CurrentControlSet\Control\Lsa\forceguest needs to 0
    1185             :  * see also:
    1186             :  * http://support.microsoft.com/kb/294355/EN-US/ and
    1187             :  * http://support.microsoft.com/kb/290403/EN-US/
    1188             :  */
    1189             : 
    1190           0 : static bool test_NetrJoinDomain2(struct torture_context *tctx,
    1191             :                                  struct dcerpc_pipe *p)
    1192             : {
    1193           0 :         NTSTATUS status;
    1194           0 :         struct wkssvc_NetrJoinDomain2 r;
    1195           0 :         const char *domain_admin_account = NULL;
    1196           0 :         const char *domain_admin_password = NULL;
    1197           0 :         const char *domain_name = NULL;
    1198           0 :         struct wkssvc_PasswordBuffer *pwd_buf;
    1199           0 :         enum wkssvc_NetJoinStatus join_status;
    1200           0 :         const char *join_name = NULL;
    1201           0 :         WERROR expected_err;
    1202           0 :         WERROR werr;
    1203           0 :         DATA_BLOB session_key;
    1204           0 :         struct dcerpc_binding_handle *b = p->binding_handle;
    1205             : 
    1206             :         /* FIXME: this test assumes to join workstations / servers and does not
    1207             :          * handle DCs (WERR_NERR_SETUPDOMAINCONTROLLER) */
    1208             : 
    1209           0 :         if (!test_GetJoinInformation(tctx, p, &join_status, &join_name))
    1210             :         {
    1211           0 :                 return false;
    1212             :         }
    1213             : 
    1214           0 :         switch (join_status) {
    1215           0 :                 case NET_SETUP_DOMAIN_NAME:
    1216           0 :                         expected_err = WERR_NERR_SETUPALREADYJOINED;
    1217           0 :                         break;
    1218           0 :                 case NET_SETUP_UNKNOWN_STATUS:
    1219             :                 case NET_SETUP_UNJOINED:
    1220             :                 case NET_SETUP_WORKGROUP_NAME:
    1221             :                 default:
    1222           0 :                         expected_err = WERR_OK;
    1223           0 :                         break;
    1224             :         }
    1225             : 
    1226           0 :         domain_admin_account = torture_setting_string(tctx, "domain_admin_account", NULL);
    1227             : 
    1228           0 :         domain_admin_password = torture_setting_string(tctx, "domain_admin_password", NULL);
    1229             : 
    1230           0 :         domain_name = torture_setting_string(tctx, "domain_name", NULL);
    1231             : 
    1232           0 :         if ((domain_admin_account == NULL) ||
    1233           0 :             (domain_admin_password == NULL) ||
    1234             :             (domain_name == NULL)) {
    1235           0 :                 torture_comment(tctx, "not enough input parameter\n");
    1236           0 :                 return false;
    1237             :         }
    1238             : 
    1239           0 :         status = dcerpc_fetch_session_key(p, &session_key);
    1240           0 :         if (!NT_STATUS_IS_OK(status)) {
    1241           0 :                 return false;
    1242             :         }
    1243             : 
    1244           0 :         werr = encode_wkssvc_join_password_buffer(tctx,
    1245             :                                                   domain_admin_password,
    1246             :                                                   &session_key,
    1247             :                                                   &pwd_buf);
    1248           0 :         if (!W_ERROR_IS_OK(werr)) {
    1249           0 :                 return false;
    1250             :         }
    1251             : 
    1252           0 :         r.in.server_name = dcerpc_server_name(p);
    1253           0 :         r.in.domain_name = domain_name;
    1254           0 :         r.in.account_ou = NULL;
    1255           0 :         r.in.admin_account = domain_admin_account;
    1256           0 :         r.in.encrypted_password = pwd_buf;
    1257           0 :         r.in.join_flags = WKSSVC_JOIN_FLAGS_JOIN_TYPE |
    1258             :                           WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE;
    1259             : 
    1260           0 :         torture_comment(tctx, "Testing NetrJoinDomain2 (assuming non-DC)\n");
    1261             : 
    1262           0 :         status = dcerpc_wkssvc_NetrJoinDomain2_r(b, tctx, &r);
    1263           0 :         torture_assert_ntstatus_ok(tctx, status,
    1264             :                                    "NetrJoinDomain2 failed");
    1265           0 :         torture_assert_werr_equal(tctx, r.out.result, expected_err,
    1266             :                                   "NetrJoinDomain2 failed");
    1267             : 
    1268           0 :         if (!test_GetJoinInformation(tctx, p, &join_status, &join_name))
    1269             :         {
    1270           0 :                 return false;
    1271             :         }
    1272             : 
    1273           0 :         if (join_status != NET_SETUP_DOMAIN_NAME) {
    1274           0 :                 torture_comment(tctx,
    1275             :                                 "Join verify failed: got %d\n", join_status);
    1276           0 :                 return false;
    1277             :         }
    1278             : 
    1279           0 :         return true;
    1280             : }
    1281             : 
    1282           0 : static bool test_NetrUnjoinDomain2(struct torture_context *tctx,
    1283             :                                    struct dcerpc_pipe *p)
    1284             : {
    1285           0 :         NTSTATUS status;
    1286           0 :         struct wkssvc_NetrUnjoinDomain2 r;
    1287           0 :         const char *domain_admin_account = NULL;
    1288           0 :         const char *domain_admin_password = NULL;
    1289           0 :         struct wkssvc_PasswordBuffer *pwd_buf;
    1290           0 :         enum wkssvc_NetJoinStatus join_status;
    1291           0 :         const char *join_name = NULL;
    1292           0 :         WERROR expected_err;
    1293           0 :         WERROR werr;
    1294           0 :         DATA_BLOB session_key;
    1295           0 :         struct dcerpc_binding_handle *b = p->binding_handle;
    1296             : 
    1297             :         /* FIXME: this test assumes to join workstations / servers and does not
    1298             :          * handle DCs (WERR_NERR_SETUPDOMAINCONTROLLER) */
    1299             : 
    1300           0 :         if (!test_GetJoinInformation(tctx, p, &join_status, &join_name))
    1301             :         {
    1302           0 :                 return false;
    1303             :         }
    1304             : 
    1305           0 :         switch (join_status) {
    1306           0 :                 case NET_SETUP_UNJOINED:
    1307           0 :                         expected_err = WERR_NERR_SETUPNOTJOINED;
    1308           0 :                         break;
    1309           0 :                 case NET_SETUP_DOMAIN_NAME:
    1310             :                 case NET_SETUP_UNKNOWN_STATUS:
    1311             :                 case NET_SETUP_WORKGROUP_NAME:
    1312             :                 default:
    1313           0 :                         expected_err = WERR_OK;
    1314           0 :                         break;
    1315             :         }
    1316             : 
    1317           0 :         domain_admin_account = torture_setting_string(tctx, "domain_admin_account", NULL);
    1318             : 
    1319           0 :         domain_admin_password = torture_setting_string(tctx, "domain_admin_password", NULL);
    1320             : 
    1321           0 :         if ((domain_admin_account == NULL) ||
    1322           0 :             (domain_admin_password == NULL)) {
    1323           0 :                 torture_comment(tctx, "not enough input parameter\n");
    1324           0 :                 return false;
    1325             :         }
    1326             : 
    1327           0 :         status = dcerpc_fetch_session_key(p, &session_key);
    1328           0 :         if (!NT_STATUS_IS_OK(status)) {
    1329           0 :                 return false;
    1330             :         }
    1331             : 
    1332           0 :         werr = encode_wkssvc_join_password_buffer(tctx,
    1333             :                                                   domain_admin_password,
    1334             :                                                   &session_key,
    1335             :                                                   &pwd_buf);
    1336           0 :         if (!W_ERROR_IS_OK(werr)) {
    1337           0 :                 return false;
    1338             :         }
    1339             : 
    1340           0 :         r.in.server_name = dcerpc_server_name(p);
    1341           0 :         r.in.account = domain_admin_account;
    1342           0 :         r.in.encrypted_password = pwd_buf;
    1343           0 :         r.in.unjoin_flags = 0;
    1344             : 
    1345           0 :         torture_comment(tctx, "Testing NetrUnjoinDomain2 (assuming non-DC)\n");
    1346             : 
    1347           0 :         status = dcerpc_wkssvc_NetrUnjoinDomain2_r(b, tctx, &r);
    1348           0 :         torture_assert_ntstatus_ok(tctx, status,
    1349             :                                    "NetrUnjoinDomain2 failed");
    1350           0 :         torture_assert_werr_equal(tctx, r.out.result, expected_err,
    1351             :                                   "NetrUnjoinDomain2 failed");
    1352             : 
    1353           0 :         if (!test_GetJoinInformation(tctx, p, &join_status, &join_name))
    1354             :         {
    1355           0 :                 return false;
    1356             :         }
    1357             : 
    1358           0 :         switch (join_status) {
    1359           0 :                 case NET_SETUP_UNJOINED:
    1360             :                 case NET_SETUP_WORKGROUP_NAME:
    1361           0 :                         break;
    1362           0 :                 case NET_SETUP_UNKNOWN_STATUS:
    1363             :                 case NET_SETUP_DOMAIN_NAME:
    1364             :                 default:
    1365           0 :                         torture_comment(tctx,
    1366             :                                 "Unjoin verify failed: got %d\n", join_status);
    1367           0 :                         return false;
    1368             :         }
    1369             : 
    1370           0 :         return true;
    1371             : }
    1372             : 
    1373             : 
    1374        2354 : struct torture_suite *torture_rpc_wkssvc(TALLOC_CTX *mem_ctx)
    1375             : {
    1376         125 :         struct torture_suite *suite;
    1377         125 :         struct torture_rpc_tcase *tcase;
    1378         125 :         struct torture_test *test;
    1379             : 
    1380        2354 :         suite = torture_suite_create(mem_ctx, "wkssvc");
    1381        2354 :         tcase = torture_suite_add_rpc_iface_tcase(suite, "wkssvc",
    1382             :                                                   &ndr_table_wkssvc);
    1383             : 
    1384        2354 :         torture_rpc_tcase_add_test(tcase, "NetWkstaGetInfo",
    1385             :                                    test_NetWkstaGetInfo);
    1386             : 
    1387        2354 :         torture_rpc_tcase_add_test(tcase, "NetWkstaTransportEnum",
    1388             :                                    test_NetWkstaTransportEnum);
    1389        2354 :         torture_rpc_tcase_add_test(tcase, "NetrWkstaTransportDel",
    1390             :                                    test_NetrWkstaTransportDel);
    1391        2354 :         torture_rpc_tcase_add_test(tcase, "NetrWkstaTransportAdd",
    1392             :                                    test_NetrWkstaTransportAdd);
    1393             : 
    1394        2354 :         torture_rpc_tcase_add_test(tcase, "NetWkstaEnumUsers",
    1395             :                                    test_NetWkstaEnumUsers);
    1396        2354 :         torture_rpc_tcase_add_test(tcase, "NetrWkstaUserGetInfo",
    1397             :                                    test_NetrWkstaUserGetInfo);
    1398             : 
    1399        2354 :         torture_rpc_tcase_add_test(tcase, "NetrUseDel",
    1400             :                                    test_NetrUseDel);
    1401        2354 :         torture_rpc_tcase_add_test(tcase, "NetrUseGetInfo",
    1402             :                                    test_NetrUseGetInfo);
    1403        2354 :         torture_rpc_tcase_add_test(tcase, "NetrUseEnum",
    1404             :                                    test_NetrUseEnum);
    1405        2354 :         torture_rpc_tcase_add_test(tcase, "NetrUseAdd",
    1406             :                                    test_NetrUseAdd);
    1407             : 
    1408        2354 :         torture_rpc_tcase_add_test(tcase, "NetrValidateName",
    1409             :                                    test_NetrValidateName);
    1410        2354 :         torture_rpc_tcase_add_test(tcase, "NetrValidateName2",
    1411             :                                    test_NetrValidateName2);
    1412        2354 :         torture_rpc_tcase_add_test(tcase, "NetrLogonDomainNameDel",
    1413             :                                    test_NetrLogonDomainNameDel);
    1414        2354 :         torture_rpc_tcase_add_test(tcase, "NetrLogonDomainNameAdd",
    1415             :                                    test_NetrLogonDomainNameAdd);
    1416        2354 :         torture_rpc_tcase_add_test(tcase, "NetrRemoveAlternateComputerName",
    1417             :                                    test_NetrRemoveAlternateComputerName);
    1418        2354 :         torture_rpc_tcase_add_test(tcase, "NetrAddAlternateComputerName",
    1419             :                                    test_NetrAddAlternateComputerName);
    1420        2354 :         test = torture_rpc_tcase_add_test(tcase, "NetrSetPrimaryComputername",
    1421             :                                           test_NetrSetPrimaryComputername);
    1422        2354 :         test->dangerous = true;
    1423        2354 :         test = torture_rpc_tcase_add_test(tcase, "NetrRenameMachineInDomain",
    1424             :                                           test_NetrRenameMachineInDomain);
    1425        2354 :         test->dangerous = true;
    1426        2354 :         test = torture_rpc_tcase_add_test(tcase, "NetrRenameMachineInDomain2",
    1427             :                                           test_NetrRenameMachineInDomain2);
    1428        2354 :         test->dangerous = true;
    1429        2354 :         torture_rpc_tcase_add_test(tcase, "NetrEnumerateComputerNames",
    1430             :                                    test_NetrEnumerateComputerNames);
    1431             : 
    1432        2354 :         test = torture_rpc_tcase_add_test(tcase, "NetrJoinDomain2",
    1433             :                                           test_NetrJoinDomain2);
    1434        2354 :         test->dangerous = true;
    1435        2354 :         test = torture_rpc_tcase_add_test(tcase, "NetrUnjoinDomain2",
    1436             :                                           test_NetrUnjoinDomain2);
    1437        2354 :         test->dangerous = true;
    1438             : 
    1439        2354 :         torture_rpc_tcase_add_test(tcase, "NetrJoinDomain",
    1440             :                                    test_NetrJoinDomain);
    1441        2354 :         test->dangerous = true;
    1442        2354 :         torture_rpc_tcase_add_test(tcase, "NetrUnjoinDomain",
    1443             :                                    test_NetrUnjoinDomain);
    1444        2354 :         test->dangerous = true;
    1445        2354 :         torture_rpc_tcase_add_test(tcase, "NetrGetJoinInformation",
    1446             :                                    test_NetrGetJoinInformation);
    1447        2354 :         torture_rpc_tcase_add_test(tcase, "NetrGetJoinableOus",
    1448             :                                    test_NetrGetJoinableOus);
    1449        2354 :         torture_rpc_tcase_add_test(tcase, "NetrGetJoinableOus2",
    1450             :                                    test_NetrGetJoinableOus2);
    1451             : 
    1452        2354 :         torture_rpc_tcase_add_test(tcase, "NetrWorkstationStatisticsGet",
    1453             :                                    test_NetrWorkstationStatisticsGet);
    1454        2354 :         torture_rpc_tcase_add_test(tcase, "NetrMessageBufferSend",
    1455             :                                    test_NetrMessageBufferSend);
    1456             : 
    1457        2354 :         return suite;
    1458             : }

Generated by: LCOV version 1.14