LCOV - code coverage report
Current view: top level - source4/torture/rap - rap.c (source / functions) Hit Total Coverage
Test: coverage report for v4-17-test 1498b464 Lines: 17 110 15.5 %
Date: 2024-06-13 04:01:37 Functions: 1 9 11.1 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             :    test suite for various RAP operations
       4             :    Copyright (C) Volker Lendecke 2004
       5             :    Copyright (C) Tim Potter 2005
       6             :    Copyright (C) Jelmer Vernooij 2007
       7             :    Copyright (C) Guenther Deschner 2010
       8             :    
       9             :    This program is free software; you can redistribute it and/or modify
      10             :    it under the terms of the GNU General Public License as published by
      11             :    the Free Software Foundation; either version 3 of the License, or
      12             :    (at your option) any later version.
      13             :    
      14             :    This program is distributed in the hope that it will be useful,
      15             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17             :    GNU General Public License for more details.
      18             :    
      19             :    You should have received a copy of the GNU General Public License
      20             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      21             : */
      22             : 
      23             : #include "includes.h"
      24             : #include "libcli/libcli.h"
      25             : #include "torture/smbtorture.h"
      26             : #include "torture/util.h"
      27             : #include "param/param.h"
      28             : #include "libcli/rap/rap.h"
      29             : #include "torture/rap/proto.h"
      30             : 
      31           0 : static bool test_netshareenum(struct torture_context *tctx, 
      32             :                               struct smbcli_state *cli)
      33             : {
      34             :         struct rap_NetShareEnum r;
      35             :         int i;
      36             : 
      37           0 :         r.in.level = 1;
      38           0 :         r.in.bufsize = 8192;
      39             : 
      40           0 :         torture_assert_ntstatus_ok(tctx, 
      41             :                 smbcli_rap_netshareenum(cli->tree, tctx, &r), "");
      42             : 
      43           0 :         for (i=0; i<r.out.count; i++) {
      44           0 :                 printf("%s %d %s\n", r.out.info[i].info1.share_name,
      45           0 :                        r.out.info[i].info1.share_type,
      46           0 :                        r.out.info[i].info1.comment);
      47             :         }
      48             : 
      49           0 :         return true;
      50             : }
      51             : 
      52           0 : static bool test_netserverenum(struct torture_context *tctx, 
      53             :                                struct smbcli_state *cli)
      54             : {
      55             :         struct rap_NetServerEnum2 r;
      56             :         int i;
      57             : 
      58           0 :         r.in.level = 0;
      59           0 :         r.in.bufsize = 8192;
      60           0 :         r.in.servertype = 0xffffffff;
      61           0 :         r.in.servertype = 0x80000000;
      62           0 :         r.in.domain = NULL;
      63             : 
      64           0 :         torture_assert_ntstatus_ok(tctx, 
      65             :                    smbcli_rap_netserverenum2(cli->tree, tctx, &r), "");
      66             : 
      67           0 :         for (i=0; i<r.out.count; i++) {
      68           0 :                 switch (r.in.level) {
      69           0 :                 case 0:
      70           0 :                         printf("%s\n", r.out.info[i].info0.name);
      71           0 :                         break;
      72           0 :                 case 1:
      73           0 :                         printf("%s %x %s\n", r.out.info[i].info1.name,
      74           0 :                                r.out.info[i].info1.servertype,
      75           0 :                                r.out.info[i].info1.comment);
      76           0 :                         break;
      77             :                 }
      78             :         }
      79             : 
      80           0 :         return true;
      81             : }
      82             : 
      83           0 : static bool test_netservergetinfo(struct torture_context *tctx, 
      84             :                                   struct smbcli_state *cli)
      85             : {
      86             :         struct rap_WserverGetInfo r;
      87           0 :         bool res = true;
      88             : 
      89           0 :         r.in.bufsize = 0xffff;
      90             : 
      91           0 :         r.in.level = 0;
      92           0 :         torture_assert_ntstatus_ok(tctx,
      93             :                 smbcli_rap_netservergetinfo(cli->tree, tctx, &r),
      94             :                 "rap_netservergetinfo level 0 failed");
      95           0 :         torture_assert_werr_ok(tctx, W_ERROR(r.out.status),
      96             :                 "rap_netservergetinfo level 0 failed");
      97             : 
      98           0 :         r.in.level = 1;
      99           0 :         torture_assert_ntstatus_ok(tctx,
     100             :                 smbcli_rap_netservergetinfo(cli->tree, tctx, &r),
     101             :                 "rap_netservergetinfo level 1 failed");
     102           0 :         torture_assert_werr_ok(tctx, W_ERROR(r.out.status),
     103             :                 "rap_netservergetinfo level 1 failed");
     104             : 
     105           0 :         return res;
     106             : }
     107             : 
     108           0 : static bool test_netsessionenum(struct torture_context *tctx,
     109             :                                 struct smbcli_state *cli)
     110             : {
     111             :         struct rap_NetSessionEnum r;
     112             :         int i,n;
     113           0 :         uint16_t levels[] = { 2 };
     114             : 
     115           0 :         for (i=0; i < ARRAY_SIZE(levels); i++) {
     116             : 
     117           0 :                 r.in.level = levels[i];
     118           0 :                 r.in.bufsize = 8192;
     119             : 
     120           0 :                 torture_comment(tctx,
     121           0 :                         "Testing rap_NetSessionEnum level %d\n", r.in.level);
     122             : 
     123           0 :                 torture_assert_ntstatus_ok(tctx,
     124             :                         smbcli_rap_netsessionenum(cli->tree, tctx, &r),
     125             :                         "smbcli_rap_netsessionenum failed");
     126           0 :                 torture_assert_werr_ok(tctx, W_ERROR(r.out.status),
     127             :                         "smbcli_rap_netsessionenum failed");
     128             : 
     129           0 :                 for (n=0; n < r.out.count; n++) {
     130           0 :                         switch (r.in.level) {
     131           0 :                         case 2:
     132           0 :                                 torture_comment(tctx, "ComputerName: %s\n",
     133           0 :                                         r.out.info[n].info2.ComputerName);
     134             : 
     135           0 :                                 torture_comment(tctx, "UserName: %s\n",
     136           0 :                                         r.out.info[n].info2.UserName);
     137             : 
     138           0 :                                 torture_assert(tctx, r.out.info[n].info2.ComputerName,
     139             :                                         "ComputerName empty");
     140           0 :                                 torture_assert(tctx, r.out.info[n].info2.UserName,
     141             :                                         "UserName empty");
     142           0 :                                 break;
     143           0 :                         default:
     144           0 :                                 break;
     145             :                         }
     146             :                 }
     147             :         }
     148             : 
     149           0 :         return true;
     150             : }
     151             : 
     152           0 : static bool test_netsessiongetinfo_bysession(struct torture_context *tctx,
     153             :                                              struct smbcli_state *cli,
     154             :                                              const char *session)
     155             : {
     156             :         struct rap_NetSessionGetInfo r;
     157             :         int i;
     158           0 :         uint16_t levels[] = { 2 };
     159             : 
     160           0 :         if (session && session[0] == '\\' && session[1] == '\\') {
     161           0 :                 r.in.SessionName = session;
     162             :         } else {
     163           0 :                 r.in.SessionName = talloc_asprintf(tctx, "\\\\%s", session);
     164             :         }
     165           0 :         r.in.bufsize = 0xffff;
     166             : 
     167           0 :         for (i=0; i < ARRAY_SIZE(levels); i++) {
     168             : 
     169           0 :                 r.in.level = levels[i];
     170             : 
     171           0 :                 torture_assert_ntstatus_ok(tctx,
     172             :                         smbcli_rap_netsessiongetinfo(cli->tree, tctx, &r),
     173             :                         "rap_netsessiongetinfo failed");
     174           0 :                 torture_assert_werr_ok(tctx, W_ERROR(r.out.status),
     175             :                         "rap_netsessiongetinfo failed");
     176             :         }
     177             : 
     178           0 :         return true;
     179             : }
     180             : 
     181           0 : static bool test_netsessiongetinfo(struct torture_context *tctx,
     182             :                                    struct smbcli_state *cli)
     183             : {
     184             :         struct rap_NetSessionEnum r;
     185             :         int i,n;
     186           0 :         uint16_t levels[] = { 2 };
     187             : 
     188           0 :         for (i=0; i < ARRAY_SIZE(levels); i++) {
     189             : 
     190           0 :                 r.in.level = levels[i];
     191           0 :                 r.in.bufsize = 8192;
     192             : 
     193           0 :                 torture_assert_ntstatus_ok(tctx,
     194             :                         smbcli_rap_netsessionenum(cli->tree, tctx, &r),
     195             :                         "smbcli_rap_netsessionenum failed");
     196           0 :                 torture_assert_werr_ok(tctx, W_ERROR(r.out.status),
     197             :                         "smbcli_rap_netsessionenum failed");
     198             : 
     199           0 :                 for (n=0; n < r.out.count; n++) {
     200           0 :                         torture_assert(tctx,
     201             :                                 test_netsessiongetinfo_bysession(tctx, cli, r.out.info[n].info2.ComputerName),
     202             :                                 "failed to query sessioninfo");
     203             :                 }
     204             :         }
     205             : 
     206           0 :         return true;
     207             : }
     208             : 
     209           0 : static bool test_netremotetod(struct torture_context *tctx,
     210             :                               struct smbcli_state *cli)
     211             : {
     212             :         struct rap_NetRemoteTOD r;
     213             : 
     214           0 :         r.in.bufsize = 8192;
     215             : 
     216           0 :         torture_assert_ntstatus_ok(tctx,
     217             :                 smbcli_rap_netremotetod(cli->tree, tctx, &r),
     218             :                 "smbcli_rap_netremotetod failed");
     219           0 :         torture_assert_werr_ok(tctx, W_ERROR(r.out.status),
     220             :                 "smbcli_rap_netremotetod failed");
     221             : 
     222           0 :         return true;
     223             : }
     224             : 
     225           0 : bool torture_rap_scan(struct torture_context *torture, struct smbcli_state *cli)
     226             : {
     227             :         int callno;
     228             : 
     229           0 :         for (callno = 0; callno < 0xffff; callno++) {
     230           0 :                 struct rap_call *call = new_rap_cli_call(torture, callno);
     231             :                 NTSTATUS result;
     232             : 
     233           0 :                 result = rap_cli_do_call(cli->tree, call);
     234             : 
     235           0 :                 if (!NT_STATUS_EQUAL(result, NT_STATUS_INVALID_PARAMETER))
     236           0 :                         continue;
     237             : 
     238           0 :                 printf("callno %d is RAP call\n", callno);
     239             :         }
     240             : 
     241           0 :         return true;
     242             : }
     243             : 
     244         964 : NTSTATUS torture_rap_init(TALLOC_CTX *ctx)
     245             : {
     246         964 :         struct torture_suite *suite = torture_suite_create(ctx, "rap");
     247         964 :         struct torture_suite *suite_basic = torture_suite_create(suite, "basic");
     248             : 
     249         964 :         torture_suite_add_suite(suite, suite_basic);
     250         964 :         torture_suite_add_suite(suite, torture_rap_rpc(suite));
     251         964 :         torture_suite_add_suite(suite, torture_rap_printing(suite));
     252         964 :         torture_suite_add_suite(suite, torture_rap_sam(suite));
     253             : 
     254         964 :         torture_suite_add_1smb_test(suite_basic, "netserverenum", 
     255             :                                     test_netserverenum);
     256         964 :         torture_suite_add_1smb_test(suite_basic, "netshareenum",
     257             :                                     test_netshareenum);
     258         964 :         torture_suite_add_1smb_test(suite_basic, "netservergetinfo",
     259             :                                     test_netservergetinfo);
     260         964 :         torture_suite_add_1smb_test(suite_basic, "netsessionenum",
     261             :                                     test_netsessionenum);
     262         964 :         torture_suite_add_1smb_test(suite_basic, "netsessiongetinfo",
     263             :                                     test_netsessiongetinfo);
     264         964 :         torture_suite_add_1smb_test(suite_basic, "netremotetod",
     265             :                                     test_netremotetod);
     266             : 
     267         964 :         torture_suite_add_1smb_test(suite, "scan", torture_rap_scan);
     268             : 
     269         964 :         suite->description = talloc_strdup(suite, 
     270             :                                                 "Remote Administration Protocol tests");
     271             : 
     272         964 :         torture_register_suite(ctx, suite);
     273             : 
     274         964 :         return NT_STATUS_OK;
     275             : }

Generated by: LCOV version 1.13