r6799: Remove a rudundent variable from the context structure - we can figure
[samba.git] / source / torture / locktest2.c
index 17435afb4cfb74c52b022bef34f745e7b6cef10d..3eb3398bd17920feb671f9f1d92bd19fcff47cf8 100644 (file)
@@ -19,6 +19,7 @@
 */
 
 #include "includes.h"
+#include "system/passwd.h"
 
 static fstring password;
 static fstring username;
@@ -54,19 +55,19 @@ static BOOL use_oplocks;
 struct record {
        char r1, r2;
        char conn, f, fstype;
-       unsigned start, len;
+       uint_t start, len;
        char needed;
 };
 
 static struct record *recorded;
 
-static int try_open(struct cli_state *c, char *nfs, int fstype, const char *fname, int flags)
+static int try_open(struct smbcli_state *c, char *nfs, int fstype, const char *fname, int flags)
 {
        pstring path;
 
        switch (fstype) {
        case FSTYPE_SMB:
-               return cli_open(c, fname, flags, DENY_NONE);
+               return smbcli_open(c, fname, flags, DENY_NONE);
 
        case FSTYPE_NFS:
                slprintf(path, sizeof(path), "%s%s", nfs, fname);
@@ -77,11 +78,11 @@ static int try_open(struct cli_state *c, char *nfs, int fstype, const char *fnam
        return -1;
 }
 
-static BOOL try_close(struct cli_state *c, int fstype, int fd)
+static BOOL try_close(struct smbcli_state *c, int fstype, int fd)
 {
        switch (fstype) {
        case FSTYPE_SMB:
-               return cli_close(c, fd);
+               return smbcli_close(c, fd);
 
        case FSTYPE_NFS:
                return close(fd) == 0;
@@ -90,15 +91,15 @@ static BOOL try_close(struct cli_state *c, int fstype, int fd)
        return False;
 }
 
-static BOOL try_lock(struct cli_state *c, int fstype, 
-                    int fd, unsigned start, unsigned len,
+static BOOL try_lock(struct smbcli_state *c, int fstype, 
+                    int fd, uint_t start, uint_t len,
                     enum brl_type op)
 {
        struct flock lock;
 
        switch (fstype) {
        case FSTYPE_SMB:
-               return cli_lock(c, fd, start, len, LOCK_TIMEOUT, op);
+               return smbcli_lock(c, fd, start, len, LOCK_TIMEOUT, op);
 
        case FSTYPE_NFS:
                lock.l_type = (op==READ_LOCK) ? F_RDLCK:F_WRLCK;
@@ -112,14 +113,14 @@ static BOOL try_lock(struct cli_state *c, int fstype,
        return False;
 }
 
-static BOOL try_unlock(struct cli_state *c, int fstype, 
-                      int fd, unsigned start, unsigned len)
+static BOOL try_unlock(struct smbcli_state *c, int fstype, 
+                      int fd, uint_t start, uint_t len)
 {
        struct flock lock;
 
        switch (fstype) {
        case FSTYPE_SMB:
-               return cli_unlock(c, fd, start, len);
+               return smbcli_unlock(c, fd, start, len);
 
        case FSTYPE_NFS:
                lock.l_type = F_UNLCK;
@@ -133,23 +134,12 @@ static BOOL try_unlock(struct cli_state *c, int fstype,
        return False;
 }      
 
-static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, int pid, 
-                     enum brl_type lock_type,
-                     br_off start, br_off size)
-{
-       printf("%6d   %05x:%05x    %s  %.0f:%.0f(%.0f)\n", 
-              (int)pid, (int)dev, (int)ino, 
-              lock_type==READ_LOCK?"R":"W",
-              (double)start, (double)start+size-1,(double)size);
-
-}
-
 /***************************************************** 
 return a connection to a server
 *******************************************************/
-static struct cli_state *connect_one(char *share)
+static struct smbcli_state *connect_one(char *share)
 {
-       struct cli_state *c;
+       struct smbcli_state *c;
        char *server_n;
        fstring server;
        fstring myname;
@@ -173,12 +163,11 @@ static struct cli_state *connect_one(char *share)
 
        slprintf(myname,sizeof(myname), "lock-%u-%u", getpid(), count++);
 
-       nt_status = cli_full_connection(&c, myname, server_n, NULL, 0, share, "?????", 
-                                       username, lp_workgroup(), password, 0,
-                                       NULL);
-
+       nt_status = smbcli_full_connection(NULL, 
+                                          &c, myname, server_n, 0, share, NULL,
+                                          username, lp_workgroup(), password);
        if (!NT_STATUS_IS_OK(nt_status)) {
-               DEBUG(0, ("cli_full_connection failed with error %s\n", nt_errstr(nt_status)));
+               DEBUG(0, ("smbcli_full_connection failed with error %s\n", nt_errstr(nt_status)));
                return NULL;
        }
 
@@ -188,7 +177,7 @@ static struct cli_state *connect_one(char *share)
 }
 
 
-static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS], 
+static void reconnect(struct smbcli_state *cli[NSERVERS][NCONNECTIONS], 
                      char *nfs[NSERVERS], 
                      int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES],
                      char *share1, char *share2)
@@ -204,10 +193,10 @@ static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS],
        for (conn=0;conn<NCONNECTIONS;conn++) {
                if (cli[server][conn]) {
                        for (f=0;f<NFILES;f++) {
-                               cli_close(cli[server][conn], fnum[server][fstype][conn][f]);
+                               smbcli_close(cli[server][conn], fnum[server][fstype][conn][f]);
                        }
-                       cli_ulogoff(cli[server][conn]);
-                       cli_shutdown(cli[server][conn]);
+                       smbcli_ulogoff(cli[server][conn]);
+                       smbcli_shutdown(cli[server][conn]);
                }
                cli[server][conn] = connect_one(share[server]);
                if (!cli[server][conn]) {
@@ -219,18 +208,18 @@ static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS],
 
 
 
-static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS], 
+static BOOL test_one(struct smbcli_state *cli[NSERVERS][NCONNECTIONS], 
                     char *nfs[NSERVERS],
                     int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES],
                     struct record *rec)
 {
-       unsigned conn = rec->conn;
-       unsigned f = rec->f;
-       unsigned fstype = rec->fstype;
-       unsigned start = rec->start;
-       unsigned len = rec->len;
-       unsigned r1 = rec->r1;
-       unsigned r2 = rec->r2;
+       uint_t conn = rec->conn;
+       uint_t f = rec->f;
+       uint_t fstype = rec->fstype;
+       uint_t start = rec->start;
+       uint_t len = rec->len;
+       uint_t r1 = rec->r1;
+       uint_t r2 = rec->r2;
        enum brl_type op;
        int server;
        BOOL ret[NSERVERS];
@@ -255,7 +244,6 @@ static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS],
                               op==READ_LOCK?"READ_LOCK":"WRITE_LOCK",
                               ret[0], ret[1]);
                }
-               if (showall) brl_forall(print_brl);
                if (ret[0] != ret[1]) return False;
        } else if (r2 < LOCK_PCT+UNLOCK_PCT) {
                /* unset a lock */
@@ -270,7 +258,6 @@ static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS],
                               start, start+len-1, len,
                               ret[0], ret[1]);
                }
-               if (showall) brl_forall(print_brl);
                if (!hide_unlock_fails && ret[0] != ret[1]) return False;
        } else {
                /* reopen the file */
@@ -286,13 +273,12 @@ static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS],
                if (showall) {
                        printf("reopen conn=%u fstype=%u f=%u\n",
                               conn, fstype, f);
-                       brl_forall(print_brl);
                }
        }
        return True;
 }
 
-static void close_files(struct cli_state *cli[NSERVERS][NCONNECTIONS], 
+static void close_files(struct smbcli_state *cli[NSERVERS][NCONNECTIONS], 
                        char *nfs[NSERVERS],
                        int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES])
 {
@@ -308,11 +294,11 @@ static void close_files(struct cli_state *cli[NSERVERS][NCONNECTIONS],
                }
        }
        for (server=0;server<NSERVERS;server++) {
-               cli_unlink(cli[server][0], FILENAME);
+               smbcli_unlink(cli[server][0], FILENAME);
        }
 }
 
-static void open_files(struct cli_state *cli[NSERVERS][NCONNECTIONS], 
+static void open_files(struct smbcli_state *cli[NSERVERS][NCONNECTIONS], 
                       char *nfs[NSERVERS],
                       int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES])
 {
@@ -333,7 +319,7 @@ static void open_files(struct cli_state *cli[NSERVERS][NCONNECTIONS],
 }
 
 
-static int retest(struct cli_state *cli[NSERVERS][NCONNECTIONS], 
+static int retest(struct smbcli_state *cli[NSERVERS][NCONNECTIONS], 
                  char *nfs[NSERVERS],
                  int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES],
                  int n)
@@ -360,7 +346,7 @@ static int retest(struct cli_state *cli[NSERVERS][NCONNECTIONS],
  */
 static void test_locks(char *share1, char *share2, char *nfspath1, char *nfspath2)
 {
-       struct cli_state *cli[NSERVERS][NCONNECTIONS];
+       struct smbcli_state *cli[NSERVERS][NCONNECTIONS];
        char *nfs[NSERVERS];
        int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES];
        int n, i, n1; 
@@ -371,13 +357,13 @@ static void test_locks(char *share1, char *share2, char *nfspath1, char *nfspath
        ZERO_STRUCT(fnum);
        ZERO_STRUCT(cli);
 
-       recorded = (struct record *)malloc(sizeof(*recorded) * numops);
+       recorded = malloc_array_p(struct record, numops);
 
        for (n=0; n<numops; n++) {
                recorded[n].conn = random() % NCONNECTIONS;
                recorded[n].fstype = random() % NUMFSTYPES;
                recorded[n].f = random() % NFILES;
-               recorded[n].start = LOCKBASE + ((unsigned)random() % (LOCKRANGE-1));
+               recorded[n].start = LOCKBASE + ((uint_t)random() % (LOCKRANGE-1));
                recorded[n].len = 1 + 
                        random() % (LOCKRANGE-(recorded[n].start-LOCKBASE));
                recorded[n].start *= RANGE_MULTIPLE;
@@ -493,7 +479,7 @@ static void usage(void)
        all_string_sub(share1,"/","\\",0);
        all_string_sub(share2,"/","\\",0);
 
-       setup_logging(argv[0],True);
+       setup_logging(argv[0], DEBUG_STDOUT);
 
        argc -= 4;
        argv += 4;