r2709: finally solved the talloc reference problem.
[bbaumbach/samba-autobuild/.git] / source4 / torture / locktest.c
index 10238c75a544ec588bf4516d53adbda8d413fd8a..494688dfb5d612ff9a3df8be98180654c8fc1099 100644 (file)
 
 #include "includes.h"
 
-static fstring password[2];
-static fstring username[2];
-static int got_user;
-static int got_pass;
-static BOOL use_kerberos;
 static int numops = 1000;
 static BOOL showall;
 static BOOL analyze;
@@ -49,6 +44,11 @@ static BOOL zero_zero;
 
 #define NASTY_POSIX_LOCK_HACK 0
 
+static struct {
+       char *username;
+       char *password;
+} servers[NSERVERS];
+
 enum lock_op {OP_LOCK, OP_UNLOCK, OP_REOPEN};
 
 struct record {
@@ -102,12 +102,13 @@ static struct record *recorded;
 /***************************************************** 
 return a connection to a server
 *******************************************************/
-static struct cli_state *connect_one(char *share, int snum)
+static struct smbcli_state *connect_one(char *share, int snum)
 {
-       struct cli_state *c;
+       struct smbcli_state *c;
        fstring server, myname;
        uint_t flags = 0;
        NTSTATUS status;
+       int retries = 10;
 
        fstrcpy(server,share+2);
        share = strchr_m(server,'\\');
@@ -117,14 +118,16 @@ static struct cli_state *connect_one(char *share, int snum)
 
        slprintf(myname,sizeof(myname), "lock-%u-%u", getpid(), snum);
 
-       if (use_kerberos)
-               flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
-       
-       status = cli_full_connection(&c, myname,
-                                    server, NULL,  
-                                    share, "?????", 
-                                    username[snum], lp_workgroup(), 
-                                    password[snum], flags, NULL);
+       do {
+               status = smbcli_full_connection(&c, myname,
+                                            server, NULL,  
+                                            share, "?????", 
+                                            servers[snum].username, lp_workgroup(), 
+                                            servers[snum].password, flags, NULL);
+               if (!NT_STATUS_IS_OK(status)) {
+                       sleep(2);
+               }
+       } while (!NT_STATUS_IS_OK(status) && retries--);
 
        if (!NT_STATUS_IS_OK(status)) {
                return NULL;
@@ -134,7 +137,7 @@ static struct cli_state *connect_one(char *share, int snum)
 }
 
 
-static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS], int fnum[NSERVERS][NCONNECTIONS][NFILES],
+static void reconnect(struct smbcli_state *cli[NSERVERS][NCONNECTIONS], int fnum[NSERVERS][NCONNECTIONS][NFILES],
                      char *share[NSERVERS])
 {
        int server, conn, f;
@@ -144,11 +147,11 @@ static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS], int fnum[NS
                if (cli[server][conn]) {
                        for (f=0;f<NFILES;f++) {
                                if (fnum[server][conn][f] != -1) {
-                                       cli_close(cli[server][conn]->tree, fnum[server][conn][f]);
+                                       smbcli_close(cli[server][conn]->tree, fnum[server][conn][f]);
                                        fnum[server][conn][f] = -1;
                                }
                        }
-                       cli_shutdown(cli[server][conn]);
+                       smbcli_shutdown(cli[server][conn]);
                }
                cli[server][conn] = connect_one(share[server], server);
                if (!cli[server][conn]) {
@@ -160,7 +163,7 @@ static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS], int fnum[NS
 
 
 
-static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS], 
+static BOOL test_one(struct smbcli_state *cli[NSERVERS][NCONNECTIONS], 
                     int fnum[NSERVERS][NCONNECTIONS][NFILES],
                     struct record *rec)
 {
@@ -177,10 +180,10 @@ static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS],
        case OP_LOCK:
                /* set a lock */
                for (server=0;server<NSERVERS;server++) {
-                       ret[server] = NT_STATUS_IS_OK(cli_lock64(cli[server][conn]->tree, 
+                       ret[server] = NT_STATUS_IS_OK(smbcli_lock64(cli[server][conn]->tree, 
                                                 fnum[server][conn][f],
                                                 start, len, LOCK_TIMEOUT, op));
-                       status[server] = cli_nt_error(cli[server][conn]->tree);
+                       status[server] = smbcli_nt_error(cli[server][conn]->tree);
                        if (!exact_error_codes && 
                            NT_STATUS_EQUAL(status[server], 
                                            NT_STATUS_FILE_LOCK_CONFLICT)) {
@@ -200,10 +203,10 @@ static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS],
        case OP_UNLOCK:
                /* unset a lock */
                for (server=0;server<NSERVERS;server++) {
-                       ret[server] = NT_STATUS_IS_OK(cli_unlock64(cli[server][conn]->tree, 
+                       ret[server] = NT_STATUS_IS_OK(smbcli_unlock64(cli[server][conn]->tree, 
                                                   fnum[server][conn][f],
                                                   start, len));
-                       status[server] = cli_nt_error(cli[server][conn]->tree);
+                       status[server] = smbcli_nt_error(cli[server][conn]->tree);
                }
                if (showall || 
                    (!hide_unlock_fails && !NT_STATUS_EQUAL(status[0],status[1]))) {
@@ -219,11 +222,11 @@ static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS],
        case OP_REOPEN:
                /* reopen the file */
                for (server=0;server<NSERVERS;server++) {
-                       cli_close(cli[server][conn]->tree, fnum[server][conn][f]);
+                       smbcli_close(cli[server][conn]->tree, fnum[server][conn][f]);
                        fnum[server][conn][f] = -1;
                }
                for (server=0;server<NSERVERS;server++) {
-                       fnum[server][conn][f] = cli_open(cli[server][conn]->tree, FILENAME,
+                       fnum[server][conn][f] = smbcli_open(cli[server][conn]->tree, FILENAME,
                                                         O_RDWR|O_CREAT,
                                                         DENY_NONE);
                        if (fnum[server][conn][f] == -1) {
@@ -241,7 +244,7 @@ static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS],
        return True;
 }
 
-static void close_files(struct cli_state *cli[NSERVERS][NCONNECTIONS], 
+static void close_files(struct smbcli_state *cli[NSERVERS][NCONNECTIONS], 
                        int fnum[NSERVERS][NCONNECTIONS][NFILES])
 {
        int server, conn, f; 
@@ -250,16 +253,16 @@ static void close_files(struct cli_state *cli[NSERVERS][NCONNECTIONS],
        for (conn=0;conn<NCONNECTIONS;conn++)
        for (f=0;f<NFILES;f++) {
                if (fnum[server][conn][f] != -1) {
-                       cli_close(cli[server][conn]->tree, fnum[server][conn][f]);
+                       smbcli_close(cli[server][conn]->tree, fnum[server][conn][f]);
                        fnum[server][conn][f] = -1;
                }
        }
        for (server=0;server<NSERVERS;server++) {
-               cli_unlink(cli[server][0]->tree, FILENAME);
+               smbcli_unlink(cli[server][0]->tree, FILENAME);
        }
 }
 
-static void open_files(struct cli_state *cli[NSERVERS][NCONNECTIONS], 
+static void open_files(struct smbcli_state *cli[NSERVERS][NCONNECTIONS], 
                       int fnum[NSERVERS][NCONNECTIONS][NFILES])
 {
        int server, conn, f; 
@@ -267,7 +270,7 @@ static void open_files(struct cli_state *cli[NSERVERS][NCONNECTIONS],
        for (server=0;server<NSERVERS;server++)
        for (conn=0;conn<NCONNECTIONS;conn++)
        for (f=0;f<NFILES;f++) {
-               fnum[server][conn][f] = cli_open(cli[server][conn]->tree, FILENAME,
+               fnum[server][conn][f] = smbcli_open(cli[server][conn]->tree, FILENAME,
                                                 O_RDWR|O_CREAT,
                                                 DENY_NONE);
                if (fnum[server][conn][f] == -1) {
@@ -279,7 +282,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], 
                   int fnum[NSERVERS][NCONNECTIONS][NFILES],
                   int n)
 {
@@ -305,7 +308,7 @@ static int retest(struct cli_state *cli[NSERVERS][NCONNECTIONS],
  */
 static void test_locks(char *share[NSERVERS])
 {
-       struct cli_state *cli[NSERVERS][NCONNECTIONS];
+       struct smbcli_state *cli[NSERVERS][NCONNECTIONS];
        int fnum[NSERVERS][NCONNECTIONS][NFILES];
        int n, i, n1, skip, r1, r2; 
 
@@ -431,7 +434,6 @@ static void usage(void)
   locktest //server1/share1 //server2/share2 [options..]\n\
   options:\n\
         -U user%%pass        (may be specified twice)\n\
-        -k               use kerberos\n\
         -s seed\n\
         -o numops\n\
         -u          hide unlock fails\n\
@@ -453,8 +455,7 @@ static void usage(void)
 {
        char *share[NSERVERS];
        int opt;
-       char *p;
-       int seed, server;
+       int seed, server, i;
 
        setlinebuf(stdout);
 
@@ -478,35 +479,17 @@ static void usage(void)
        lp_load(dyn_CONFIGFILE,True,False,False);
        load_interfaces();
 
-       if (getenv("USER")) {
-               fstrcpy(username[0],getenv("USER"));
-               fstrcpy(username[1],getenv("USER"));
-       }
-
        seed = time(NULL);
 
-       while ((opt = getopt(argc, argv, "U:s:ho:aAW:OkR:B:M:EZ")) != EOF) {
+       while ((opt = getopt(argc, argv, "U:s:ho:aAW:OR:B:M:EZW:")) != EOF) {
                switch (opt) {
-               case 'k':
-#ifdef HAVE_KRB5
-                       use_kerberos = True;
-#else
-                       d_printf("No kerberos support compiled in\n");
-                       exit(1);
-#endif
-                       break;
                case 'U':
-                       got_user = 1;
-                       if (got_pass == 2) {
-                               d_printf("Max of 2 usernames\n");
-                               exit(1);
-                       }
-                       fstrcpy(username[got_pass],optarg);
-                       p = strchr_m(username[got_pass],'%');
-                       if (p) {
-                               *p = 0;
-                               fstrcpy(password[got_pass], p+1);
-                               got_pass++;
+                       i = servers[0].username?1:0;
+                       if (!split_username(optarg, 
+                                           &servers[i].username, 
+                                           &servers[i].password)) {
+                               printf("Must supply USER%%PASS\n");
+                               return -1;
                        }
                        break;
                case 'R':
@@ -542,6 +525,9 @@ static void usage(void)
                case 'E':
                        exact_error_codes = True;
                        break;
+               case 'W':
+                       lp_set_cmdline("workgroup", optarg);
+                       break;
                case 'h':
                        usage();
                        exit(1);
@@ -551,7 +537,14 @@ static void usage(void)
                }
        }
 
-       if(use_kerberos && !got_user) got_pass = True;
+       if (!servers[0].username) {
+               usage();
+               return -1;
+       }
+       if (!servers[1].username) {
+               servers[1].username = servers[0].username;
+               servers[1].password = servers[0].password;
+       }
 
        argc -= optind;
        argv += optind;