s3:lib: Add FALL_THROUGH statements in util_sd.c
[sfrench/samba-autobuild/.git] / source3 / torture / locktest2.c
index 44ef250154a1577a3ef1fa543ecda0555501c28d..6ab1ed4fa19e1f444e99c885139949000015f9f7 100644 (file)
 */
 
 #include "includes.h"
+#include "libsmb/libsmb.h"
+#include "system/filesys.h"
+#include "locking/proto.h"
 
 static fstring password;
 static fstring username;
 static int got_pass;
 static int numops = 1000;
-static BOOL showall;
-static BOOL analyze;
-static BOOL hide_unlock_fails;
-static BOOL use_oplocks;
+static bool showall;
+static bool analyze;
+static bool hide_unlock_fails;
+static bool use_oplocks;
 
 extern char *optarg;
 extern int optind;
@@ -64,26 +67,37 @@ static struct record *recorded;
 
 static int try_open(struct cli_state *c, char *nfs, int fstype, const char *fname, int flags)
 {
-       pstring path;
+       char *path;
 
        switch (fstype) {
        case FSTYPE_SMB:
-               return cli_open(c, fname, flags, DENY_NONE);
+               {
+                       uint16_t fd;
+                       if (!NT_STATUS_IS_OK(cli_openx(c, fname, flags, DENY_NONE, &fd))) {
+                               return -1;
+                       }
+                       return fd;
+               }
 
        case FSTYPE_NFS:
-               slprintf(path, sizeof(path), "%s%s", nfs, fname);
-               pstring_sub(path,"\\", "/");
-               return open(path, flags, 0666);
+               if (asprintf(&path, "%s%s", nfs, fname) > 0) {
+                       int ret;
+                       string_replace(path,'\\', '/');
+                       ret = open(path, flags, 0666);
+                       SAFE_FREE(path);
+                       return ret;
+               }
+               break;
        }
 
        return -1;
 }
 
-static BOOL try_close(struct cli_state *c, int fstype, int fd)
+static bool try_close(struct cli_state *c, int fstype, int fd)
 {
        switch (fstype) {
        case FSTYPE_SMB:
-               return cli_close(c, fd);
+               return NT_STATUS_IS_OK(cli_close(c, fd));
 
        case FSTYPE_NFS:
                return close(fd) == 0;
@@ -92,7 +106,7 @@ static BOOL try_close(struct cli_state *c, int fstype, int fd)
        return False;
 }
 
-static BOOL try_lock(struct cli_state *c, int fstype, 
+static bool try_lock(struct cli_state *c, int fstype, 
                     int fd, unsigned start, unsigned len,
                     enum brl_type op)
 {
@@ -100,7 +114,8 @@ static BOOL try_lock(struct cli_state *c, int fstype,
 
        switch (fstype) {
        case FSTYPE_SMB:
-               return cli_lock(c, fd, start, len, LOCK_TIMEOUT, op);
+               return NT_STATUS_IS_OK(cli_lock32(c, fd, start, len,
+                                      LOCK_TIMEOUT, op));
 
        case FSTYPE_NFS:
                lock.l_type = (op==READ_LOCK) ? F_RDLCK:F_WRLCK;
@@ -114,14 +129,14 @@ static BOOL try_lock(struct cli_state *c, int fstype,
        return False;
 }
 
-static BOOL try_unlock(struct cli_state *c, int fstype, 
+static bool try_unlock(struct cli_state *c, int fstype, 
                       int fd, unsigned start, unsigned len)
 {
        struct flock lock;
 
        switch (fstype) {
        case FSTYPE_SMB:
-               return cli_unlock(c, fd, start, len);
+               return NT_STATUS_IS_OK(cli_unlock(c, fd, start, len));
 
        case FSTYPE_NFS:
                lock.l_type = F_UNLCK;
@@ -169,9 +184,12 @@ static struct cli_state *connect_one(char *share)
        server_n = server;
        
        if (!got_pass) {
-               char *pass = getpass("Password: ");
-               if (pass) {
-                       fstrcpy(password, pass);
+               char pwd[256] = {0};
+               int rc;
+
+               rc = samba_getpass("Password: ", pwd, sizeof(pwd), false, false);
+               if (rc == 0) {
+                       fstrcpy(password, pwd);
                }
        }
 
@@ -179,7 +197,7 @@ static struct cli_state *connect_one(char *share)
 
        nt_status = cli_full_connection(&c, myname, server_n, NULL, 0, share, "?????", 
                                        username, lp_workgroup(), password, 0,
-                                       Undefined, NULL);
+                                       SMB_SIGNING_DEFAULT);
 
        if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(0, ("cli_full_connection failed with error %s\n", nt_errstr(nt_status)));
@@ -223,7 +241,7 @@ static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS],
 
 
 
-static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS], 
+static bool test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS], 
                     char *nfs[NSERVERS],
                     int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES],
                     struct record *rec)
@@ -237,7 +255,7 @@ static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS],
        unsigned r2 = rec->r2;
        enum brl_type op;
        int server;
-       BOOL ret[NSERVERS];
+       bool ret[NSERVERS];
 
        if (r1 < READ_PCT) {
                op = READ_LOCK; 
@@ -312,7 +330,7 @@ static void close_files(struct cli_state *cli[NSERVERS][NCONNECTIONS],
                }
        }
        for (server=0;server<NSERVERS;server++) {
-               cli_unlink(cli[server][0], FILENAME);
+               cli_unlink(cli[server][0], FILENAME, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
        }
 }
 
@@ -480,13 +498,13 @@ static void usage(void)
 
        setlinebuf(stdout);
 
-       dbf = x_stderr;
-
        if (argc < 5 || argv[1][0] == '-') {
                usage();
                exit(1);
        }
 
+       setup_logging(argv[0], DEBUG_STDOUT);
+
        share1 = argv[1];
        share2 = argv[2];
        nfspath1 = argv[3];
@@ -495,12 +513,10 @@ static void usage(void)
        all_string_sub(share1,"/","\\",0);
        all_string_sub(share2,"/","\\",0);
 
-       setup_logging(argv[0],True);
-
        argc -= 4;
        argv += 4;
 
-       lp_load(dyn_CONFIGFILE,True,False,False,True);
+       lp_load_global(get_dyn_CONFIGFILE());
        load_interfaces();
 
        if (getenv("USER")) {
@@ -553,7 +569,7 @@ static void usage(void)
        DEBUG(0,("seed=%u\n", seed));
        srandom(seed);
 
-       locking_init(1);
+       locking_init_readonly();
        test_locks(share1, share2, nfspath1, nfspath2);
 
        return(0);