LCOV - code coverage report
Current view: top level - source4/torture/basic - utable.c (source / functions) Hit Total Coverage
Test: coverage report for master 6248eab5 Lines: 0 81 0.0 %
Date: 2021-08-25 13:27:56 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             :    SMB torture tester - unicode table dumper
       4             :    Copyright (C) Andrew Tridgell 2001
       5             :    
       6             :    This program is free software; you can redistribute it and/or modify
       7             :    it under the terms of the GNU General Public License as published by
       8             :    the Free Software Foundation; either version 3 of the License, or
       9             :    (at your option) any later version.
      10             :    
      11             :    This program is distributed in the hope that it will be useful,
      12             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :    GNU General Public License for more details.
      15             :    
      16             :    You should have received a copy of the GNU General Public License
      17             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             : */
      19             : 
      20             : #include "includes.h"
      21             : #include "system/filesys.h"
      22             : #include "system/locale.h"
      23             : #include "libcli/libcli.h"
      24             : #include "torture/util.h"
      25             : #include "param/param.h"
      26             : #include "torture/basic/proto.h"
      27             : #include "lib/util/sys_rw.h"
      28             : 
      29           0 : bool torture_utable(struct torture_context *tctx, 
      30             :                                         struct smbcli_state *cli)
      31             : {
      32             :         char fname[256];
      33             :         const char *alt_name;
      34             :         int fnum;
      35             :         uint8_t c2[4];
      36             :         int c, fd;
      37             :         size_t len;
      38           0 :         int chars_allowed=0, alt_allowed=0;
      39             :         uint8_t valid[0x10000];
      40             : 
      41           0 :         torture_comment(tctx, "Generating valid character table\n");
      42             : 
      43           0 :         memset(valid, 0, sizeof(valid));
      44             : 
      45           0 :         torture_assert(tctx, torture_setup_dir(cli, "\\utable"),
      46             :                                    "Setting up dir \\utable failed");
      47             : 
      48           0 :         for (c=1; c < 0x10000; c++) {
      49             :                 char *p;
      50             : 
      51           0 :                 SSVAL(c2, 0, c);
      52           0 :                 strncpy(fname, "\\utable\\x", sizeof(fname)-1);
      53           0 :                 p = fname+strlen(fname);
      54           0 :                 len = 0;
      55           0 :                 if (!convert_string(CH_UTF16, CH_UNIX,
      56             :                                      c2, 2, 
      57           0 :                                      p, sizeof(fname)-strlen(fname), &len)) {
      58           0 :                         torture_comment(tctx, "convert_string failed [%s]\n",
      59             :                                 fname);
      60           0 :                         continue;
      61             :                 }
      62             : 
      63           0 :                 p[len] = 0;
      64           0 :                 strncat(fname,"_a_long_extension",sizeof(fname)-1);
      65             : 
      66           0 :                 fnum = smbcli_open(cli->tree, fname, O_RDWR | O_CREAT | O_TRUNC, 
      67             :                                 DENY_NONE);
      68           0 :                 if (fnum == -1) continue;
      69             : 
      70           0 :                 chars_allowed++;
      71             : 
      72           0 :                 smbcli_qpathinfo_alt_name(cli->tree, fname, &alt_name);
      73             : 
      74           0 :                 if (strncmp(alt_name, "X_A_L", 5) != 0) {
      75           0 :                         alt_allowed++;
      76           0 :                         valid[c] = 1;
      77           0 :                         torture_comment(tctx, "fname=[%s] alt_name=[%s]\n", fname, alt_name);
      78             :                 }
      79             : 
      80           0 :                 smbcli_close(cli->tree, fnum);
      81           0 :                 smbcli_unlink(cli->tree, fname);
      82             : 
      83           0 :                 if (c % 100 == 0) {
      84           0 :                         if (torture_setting_bool(tctx, "progress", true)) {
      85           0 :                                 torture_comment(tctx, "%d (%d/%d)\r", c, chars_allowed, alt_allowed);
      86           0 :                                 fflush(stdout);
      87             :                         }
      88             :                 }
      89             :         }
      90           0 :         torture_comment(tctx, "%d (%d/%d)\n", c, chars_allowed, alt_allowed);
      91             : 
      92           0 :         smbcli_rmdir(cli->tree, "\\utable");
      93             : 
      94           0 :         torture_comment(tctx, "%d chars allowed   %d alt chars allowed\n", chars_allowed, alt_allowed);
      95             : 
      96           0 :         fd = open("valid.dat", O_WRONLY|O_CREAT|O_TRUNC, 0644);
      97           0 :         torture_assert(tctx, fd != -1, 
      98             :                 talloc_asprintf(tctx, 
      99             :                 "Failed to create valid.dat - %s", strerror(errno)));
     100           0 :         sys_write_v(fd, valid, 0x10000);
     101           0 :         close(fd);
     102           0 :         torture_comment(tctx, "wrote valid.dat\n");
     103             : 
     104           0 :         return true;
     105             : }
     106             : 
     107             : 
     108           0 : static char *form_name(int c)
     109             : {
     110             :         static char fname[256];
     111             :         uint8_t c2[4];
     112             :         char *p;
     113           0 :         size_t len = 0;
     114             : 
     115           0 :         strncpy(fname, "\\utable\\", sizeof(fname)-1);
     116           0 :         p = fname+strlen(fname);
     117           0 :         SSVAL(c2, 0, c);
     118             : 
     119           0 :         if (!convert_string(CH_UTF16, CH_UNIX,
     120             :                              c2, 2, 
     121           0 :                              p, sizeof(fname)-strlen(fname), &len)) {
     122           0 :                 return NULL;
     123             :         }
     124           0 :         p[len] = 0;
     125           0 :         return fname;
     126             : }
     127             : 
     128           0 : bool torture_casetable(struct torture_context *tctx, 
     129             :                                            struct smbcli_state *cli)
     130             : {
     131             :         char *fname;
     132             :         int fnum;
     133             :         int c, i;
     134             : #define MAX_EQUIVALENCE 8
     135             :         codepoint_t equiv[0x10000][MAX_EQUIVALENCE];
     136             : 
     137           0 :         torture_comment(tctx, "Determining upper/lower case table\n");
     138             : 
     139           0 :         memset(equiv, 0, sizeof(equiv));
     140             : 
     141           0 :         torture_assert(tctx, torture_setup_dir(cli, "\\utable"),
     142             :                                    "Error setting up dir \\utable");
     143             : 
     144           0 :         for (c=1; c < 0x10000; c++) {
     145             :                 size_t size;
     146             : 
     147           0 :                 if (c == '.' || c == '\\') continue;
     148             : 
     149           0 :                 torture_comment(tctx, "%04x (%c)\n", c, isprint(c)?c:'.');
     150             : 
     151           0 :                 fname = form_name(c);
     152           0 :                 if (fname == NULL) continue;
     153           0 :                 fnum = smbcli_nt_create_full(cli->tree, fname, 0,
     154             : #if 0
     155             :                                              SEC_RIGHT_MAXIMUM_ALLOWED, 
     156             : #else
     157             :                                              SEC_RIGHTS_FILE_ALL,
     158             : #endif
     159             :                                              FILE_ATTRIBUTE_NORMAL,
     160             :                                              NTCREATEX_SHARE_ACCESS_NONE,
     161             :                                              NTCREATEX_DISP_OPEN_IF, 0, 0);
     162             : 
     163           0 :                 if (fnum == -1) {
     164           0 :                         torture_comment(tctx, "Failed to create file with char %04x\n", c);
     165           0 :                         continue;
     166             :                 }
     167             : 
     168           0 :                 size = 0;
     169             : 
     170           0 :                 if (NT_STATUS_IS_ERR(smbcli_qfileinfo(cli->tree, fnum, NULL, &size, 
     171             :                                                    NULL, NULL, NULL, NULL, NULL))) continue;
     172             : 
     173           0 :                 if (size > 0) {
     174             :                         /* found a character equivalence! */
     175             :                         int c2[MAX_EQUIVALENCE];
     176             : 
     177           0 :                         if (size/sizeof(int) >= MAX_EQUIVALENCE) {
     178           0 :                                 torture_comment(tctx, "too many chars match?? size=%d c=0x%04x\n",
     179             :                                        (int)size, c);
     180           0 :                                 smbcli_close(cli->tree, fnum);
     181           0 :                                 return false;
     182             :                         }
     183             : 
     184           0 :                         smbcli_read(cli->tree, fnum, c2, 0, size);
     185           0 :                         torture_comment(tctx, "%04x: ", c);
     186           0 :                         equiv[c][0] = c;
     187           0 :                         for (i=0; i<size/sizeof(int); i++) {
     188           0 :                                 torture_comment(tctx, "%04x ", c2[i]);
     189           0 :                                 equiv[c][i+1] = c2[i];
     190             :                         }
     191           0 :                         torture_comment(tctx, "\n");
     192             :                 }
     193             : 
     194           0 :                 smbcli_write(cli->tree, fnum, 0, &c, size, sizeof(c));
     195           0 :                 smbcli_close(cli->tree, fnum);
     196             :         }
     197             : 
     198           0 :         smbcli_unlink(cli->tree, "\\utable\\*");
     199           0 :         smbcli_rmdir(cli->tree, "\\utable");
     200             : 
     201           0 :         return true;
     202             : }

Generated by: LCOV version 1.13