Convert all uses of uint32/16/8 to _t in source3/torture.
[bbaumbach/samba-autobuild/.git] / source3 / torture / mangle_test.c
index e4ccfc1b834361d5746d8df6ee5b004c93284474..9886e38b5325c04b40ff25fb7b991ba32ef04937 100644 (file)
@@ -5,7 +5,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
+#include "system/filesys.h"
+#include "torture/proto.h"
+#include "libsmb/libsmb.h"
+#include "libsmb/clirap.h"
+#include "util_tdb.h"
+
+extern int torture_numops;
 
 static TDB_CONTEXT *tdb;
 
@@ -26,9 +32,9 @@ static TDB_CONTEXT *tdb;
 
 static unsigned total, collisions, failures;
 
-static BOOL test_one(struct cli_state *cli, const char *name)
+static bool test_one(struct cli_state *cli, const char *name)
 {
-       int fnum;
+       uint16_t fnum;
        fstring shortname;
        fstring name2;
        NTSTATUS status;
@@ -36,56 +42,61 @@ static BOOL test_one(struct cli_state *cli, const char *name)
 
        total++;
 
-       fnum = cli_open(cli, name, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
-       if (fnum == -1) {
-               printf("open of %s failed (%s)\n", name, cli_errstr(cli));
+       status = cli_openx(cli, name, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open of %s failed (%s)\n", name, nt_errstr(status));
                return False;
        }
 
-       if (!cli_close(cli, fnum)) {
-               printf("close of %s failed (%s)\n", name, cli_errstr(cli));
+       status = cli_close(cli, fnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close of %s failed (%s)\n", name, nt_errstr(status));
                return False;
        }
 
        /* get the short name */
        status = cli_qpathinfo_alt_name(cli, name, shortname);
        if (!NT_STATUS_IS_OK(status)) {
-               printf("query altname of %s failed (%s)\n", name, cli_errstr(cli));
+               printf("query altname of %s failed (%s)\n", name, nt_errstr(status));
                return False;
        }
 
-       snprintf(name2, sizeof(name2), "\\mangle_test\\%s", shortname);
-       if (!cli_unlink(cli, name2)) {
+       fstr_sprintf(name2, "\\mangle_test\\%s", shortname);
+       status = cli_unlink(cli, name2, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       if (!NT_STATUS_IS_OK(status)) {
                printf("unlink of %s  (%s) failed (%s)\n", 
-                      name2, name, cli_errstr(cli));
+                      name2, name, nt_errstr(status));
                return False;
        }
 
        /* recreate by short name */
-       fnum = cli_open(cli, name2, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
-       if (fnum == -1) {
-               printf("open2 of %s failed (%s)\n", name2, cli_errstr(cli));
+       status = cli_openx(cli, name2, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open2 of %s failed (%s)\n", name2, nt_errstr(status));
                return False;
        }
-       if (!cli_close(cli, fnum)) {
-               printf("close of %s failed (%s)\n", name, cli_errstr(cli));
+
+       status = cli_close(cli, fnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close of %s failed (%s)\n", name, nt_errstr(status));
                return False;
        }
 
        /* and unlink by long name */
-       if (!cli_unlink(cli, name)) {
+       status = cli_unlink(cli, name, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       if (!NT_STATUS_IS_OK(status)) {
                printf("unlink2 of %s  (%s) failed (%s)\n", 
-                      name, name2, cli_errstr(cli));
+                      name, name2, nt_errstr(status));
                failures++;
-               cli_unlink(cli, name2);
+               cli_unlink(cli, name2, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
                return True;
        }
 
        /* see if the short name is already in the tdb */
-       data = tdb_fetch_by_string(tdb, shortname);
+       data = tdb_fetch_bystring(tdb, shortname);
        if (data.dptr) {
                /* maybe its a duplicate long name? */
-               if (strcasecmp(name, data.dptr) != 0) {
+               if (!strequal(name, (const char *)data.dptr)) {
                        /* we have a collision */
                        collisions++;
                        printf("Collision between %s and %s   ->  %s "
@@ -96,9 +107,9 @@ static BOOL test_one(struct cli_state *cli, const char *name)
        } else {
                TDB_DATA namedata;
                /* store it for later */
-               namedata.dptr = name;
+               namedata.dptr = discard_const_p(uint8_t, name);
                namedata.dsize = strlen(name)+1;
-               tdb_store_by_string(tdb, shortname, namedata, TDB_REPLACE);
+               tdb_store_bystring(tdb, shortname, namedata, TDB_REPLACE);
        }
 
        return True;
@@ -150,19 +161,22 @@ static void gen_name(char *name)
                        s[4] = 0;
                }
        }
+
+       /* ..... and a 100% proability of a file not ending in "." */
+       if (p[strlen(p)-1] == '.')
+               p[strlen(p)-1] = '_';
 }
 
 
-BOOL torture_mangle(int dummy)
+bool torture_mangle(int dummy)
 {
-       extern int torture_numops;
        static struct cli_state *cli;
        int i;
-       BOOL ret = True;
+       bool ret = True;
 
        printf("starting mangle test\n");
 
-       if (!torture_open_connection(&cli)) {
+       if (!torture_open_connection(&cli, 0)) {
                return False;
        }
 
@@ -173,10 +187,10 @@ BOOL torture_mangle(int dummy)
                return False;
        }
 
-       cli_unlink(cli, "\\mangle_test\\*");
+       cli_unlink(cli, "\\mangle_test\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
        cli_rmdir(cli, "\\mangle_test");
 
-       if (!cli_mkdir(cli, "\\mangle_test")) {
+       if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\mangle_test"))) {
                printf("ERROR: Failed to make directory\n");
                return False;
        }
@@ -197,8 +211,8 @@ BOOL torture_mangle(int dummy)
                }
        }
 
-       cli_unlink(cli, "\\mangle_test\\*");
-       if (!cli_rmdir(cli, "\\mangle_test")) {
+       cli_unlink(cli, "\\mangle_test\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       if (!NT_STATUS_IS_OK(cli_rmdir(cli, "\\mangle_test"))) {
                printf("ERROR: Failed to remove directory\n");
                return False;
        }