LCOV - code coverage report
Current view: top level - source4/torture/basic - charset.c (source / functions) Hit Total Coverage
Test: coverage report for master 6248eab5 Lines: 73 82 89.0 %
Date: 2021-08-25 13:27:56 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    SMB torture tester - charset test routines
       5             : 
       6             :    Copyright (C) Andrew Tridgell 2001
       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 "libcli/libcli.h"
      24             : #include "torture/util.h"
      25             : #include "param/param.h"
      26             : #include "torture/basic/proto.h"
      27             : 
      28             : #define BASEDIR "\\chartest\\"
      29             : 
      30             : /* 
      31             :    open a file using a set of unicode code points for the name
      32             : 
      33             :    the prefix BASEDIR is added before the name
      34             : */
      35           8 : static NTSTATUS unicode_open(struct torture_context *tctx,
      36             :                              struct smbcli_tree *tree,
      37             :                              TALLOC_CTX *mem_ctx,
      38             :                              uint32_t open_disposition, 
      39             :                              const uint32_t *u_name, 
      40             :                              size_t u_name_len)
      41             : {
      42             :         union smb_open io;
      43           8 :         char *fname, *fname2=NULL, *ucs_name;
      44             :         size_t i;
      45             :         NTSTATUS status;
      46             : 
      47           8 :         ucs_name = talloc_size(mem_ctx, (1+u_name_len)*2);
      48           8 :         if (!ucs_name) {
      49           0 :                 printf("Failed to create UCS2 Name - talloc() failure\n");
      50           0 :                 return NT_STATUS_NO_MEMORY;
      51             :         }
      52             : 
      53          18 :         for (i=0;i<u_name_len;i++) {
      54          10 :                 SSVAL(ucs_name, i*2, u_name[i]);
      55             :         }
      56           8 :         SSVAL(ucs_name, i*2, 0);
      57             : 
      58           8 :         if (!convert_string_talloc_handle(ucs_name, lpcfg_iconv_handle(tctx->lp_ctx), CH_UTF16, CH_UNIX, ucs_name, (1+u_name_len)*2, (void **)&fname, &i)) {
      59           1 :                 torture_comment(tctx, "Failed to convert UCS2 Name into unix - convert_string_talloc() failure\n");
      60           1 :                 talloc_free(ucs_name);
      61           1 :                 return NT_STATUS_NO_MEMORY;
      62             :         }
      63             : 
      64           7 :         fname2 = talloc_asprintf(ucs_name, "%s%s", BASEDIR, fname);
      65           7 :         if (!fname2) {
      66           0 :                 talloc_free(ucs_name);
      67           0 :                 return NT_STATUS_NO_MEMORY;
      68             :         }
      69             : 
      70           7 :         io.generic.level = RAW_OPEN_NTCREATEX;
      71           7 :         io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
      72           7 :         io.ntcreatex.in.root_fid.fnum = 0;
      73           7 :         io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
      74           7 :         io.ntcreatex.in.alloc_size = 0;
      75           7 :         io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
      76           7 :         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
      77           7 :         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
      78           7 :         io.ntcreatex.in.create_options = 0;
      79           7 :         io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
      80           7 :         io.ntcreatex.in.security_flags = 0;
      81           7 :         io.ntcreatex.in.fname = fname2;
      82           7 :         io.ntcreatex.in.open_disposition = open_disposition;
      83             : 
      84           7 :         status = smb_raw_open(tree, tctx, &io);
      85             : 
      86           7 :         talloc_free(ucs_name);
      87             : 
      88           7 :         return status;
      89             : }
      90             : 
      91             : 
      92             : /*
      93             :   see if the server recognises composed characters
      94             : */
      95           1 : static bool test_composed(struct torture_context *tctx, 
      96             :                           struct smbcli_state *cli)
      97             : {
      98           1 :         const uint32_t name1[] = {0x61, 0x308};
      99           1 :         const uint32_t name2[] = {0xe4};
     100             :         NTSTATUS status1, status2;
     101             : 
     102           1 :         torture_assert(tctx, torture_setup_dir(cli, BASEDIR), 
     103             :                        "setting up basedir");
     104             : 
     105           1 :         status1 = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name1, 2);
     106           1 :         torture_assert_ntstatus_ok(tctx, status1, "Failed to create composed name");
     107             : 
     108           1 :         status2 = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name2, 1);
     109             : 
     110           1 :         torture_assert_ntstatus_ok(tctx, status2, "Failed to create accented character");
     111             : 
     112           1 :         return true;
     113             : }
     114             : 
     115             : /*
     116             :   see if the server recognises a naked diacritical
     117             : */
     118           1 : static bool test_diacritical(struct torture_context *tctx, 
     119             :                              struct smbcli_state *cli)
     120             : {
     121           1 :         const uint32_t name1[] = {0x308};
     122           1 :         const uint32_t name2[] = {0x308, 0x308};
     123             :         NTSTATUS status1, status2;
     124             : 
     125           1 :         torture_assert(tctx, torture_setup_dir(cli, BASEDIR), 
     126             :                        "setting up basedir");
     127             : 
     128           1 :         status1 = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name1, 1);
     129             : 
     130           1 :         torture_assert_ntstatus_ok(tctx, status1, "Failed to create naked diacritical");
     131             : 
     132             :         /* try a double diacritical */
     133           1 :         status2 = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name2, 2);
     134             : 
     135           1 :         torture_assert_ntstatus_ok(tctx, status2, "Failed to create double naked diacritical");
     136             : 
     137           1 :         return true;
     138             : }
     139             : 
     140             : /*
     141             :   see if the server recognises a partial surrogate pair
     142             : */
     143           1 : static bool test_surrogate(struct torture_context *tctx, 
     144             :                            struct smbcli_state *cli)
     145             : {
     146           1 :         const uint32_t name1[] = {0xd800};
     147           1 :         const uint32_t name2[] = {0xdc00};
     148           1 :         const uint32_t name3[] = {0xd800, 0xdc00};
     149             :         NTSTATUS status;
     150             : 
     151           1 :         torture_assert(tctx, torture_setup_dir(cli, BASEDIR), 
     152             :                        "setting up basedir");
     153             : 
     154           1 :         status = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name1, 1);
     155             : 
     156           1 :         torture_assert_ntstatus_ok(tctx, status, "Failed to create partial surrogate 1");
     157             : 
     158           0 :         status = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name2, 1);
     159             : 
     160           0 :         torture_assert_ntstatus_ok(tctx, status, "Failed to create partial surrogate 2");
     161             : 
     162           0 :         status = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name3, 2);
     163             : 
     164           0 :         torture_assert_ntstatus_ok(tctx, status, "Failed to create full surrogate");
     165             : 
     166           0 :         return true;
     167             : }
     168             : 
     169             : /*
     170             :   see if the server recognises wide-a characters
     171             : */
     172           1 : static bool test_widea(struct torture_context *tctx, 
     173             :                        struct smbcli_state *cli)
     174             : {
     175           1 :         const uint32_t name1[] = {'a'};
     176           1 :         const uint32_t name2[] = {0xff41};
     177           1 :         const uint32_t name3[] = {0xff21};
     178             :         NTSTATUS status;
     179             : 
     180           1 :         torture_assert(tctx, torture_setup_dir(cli, BASEDIR), 
     181             :                        "setting up basedir");
     182             : 
     183           1 :         status = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name1, 1);
     184             : 
     185           1 :         torture_assert_ntstatus_ok(tctx, status, "Failed to create 'a'");
     186             : 
     187           1 :         status = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name2, 1);
     188             : 
     189           1 :         torture_assert_ntstatus_ok(tctx, status, "Failed to create wide-a");
     190             : 
     191           1 :         status = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name3, 1);
     192             : 
     193           1 :         torture_assert_ntstatus_equal(tctx, status, NT_STATUS_OBJECT_NAME_COLLISION, 
     194             :                 "Failed to create wide-A");
     195             : 
     196           1 :         return true;
     197             : }
     198             : 
     199        2353 : struct torture_suite *torture_charset(TALLOC_CTX *mem_ctx)
     200             : {
     201        2353 :         struct torture_suite *suite = torture_suite_create(mem_ctx, "charset");
     202             : 
     203        2353 :         torture_suite_add_1smb_test(suite, "Testing composite character (a umlaut)", test_composed); 
     204        2353 :         torture_suite_add_1smb_test(suite, "Testing naked diacritical (umlaut)", test_diacritical);
     205        2353 :         torture_suite_add_1smb_test(suite, "Testing partial surrogate", test_surrogate);
     206        2353 :         torture_suite_add_1smb_test(suite, "Testing wide-a", test_widea);
     207             : 
     208        2353 :         return suite;
     209             : }

Generated by: LCOV version 1.13