s3-rpc_server: run minimal_includes.pl.
[samba.git] / source3 / torture / locktest.c
index 34068cf0d70e676ff9f42d73474b382040e0958c..242099092b6ab90735212893cdfd199702af47e9 100644 (file)
 */
 
 #include "includes.h"
+#include "system/filesys.h"
+#include "locking/proto.h"
+#include "libsmb/nmblib.h"
 
 static fstring password[2];
 static fstring username[2];
 static int got_user;
 static int got_pass;
-static BOOL use_kerberos;
+static bool use_kerberos;
 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;
 static unsigned lock_range = 100;
 static unsigned lock_base = 0;
 static unsigned min_length = 0;
-static BOOL exact_error_codes;
-static BOOL zero_zero;
+static bool exact_error_codes;
+static bool zero_zero;
 
 extern char *optarg;
 extern int optind;
@@ -71,7 +74,7 @@ struct record {
        enum lock_op lock_op;
        enum brl_type lock_type;
        char conn, f;
-       SMB_BIG_UINT start, len;
+       uint64_t start, len;
        char needed;
 };
 
@@ -125,20 +128,22 @@ static void print_brl(struct file_id id,
 {
 #if NASTY_POSIX_LOCK_HACK
        {
-               pstring cmd;
                static SMB_INO_T lastino;
 
                if (lastino != ino) {
-                       slprintf(cmd, sizeof(cmd), 
-                                "egrep POSIX.*%u /proc/locks", (int)ino);
-                       system(cmd);
+                       char *cmd;
+                       if (asprintf(&cmd,
+                                "egrep POSIX.*%u /proc/locks", (int)ino) > 0) {
+                               system(cmd);
+                               SAFE_FREE(cmd);
+                       }
                }
                lastino = ino;
        }
 #endif
 
        printf("%s   %s    %s  %.0f:%.0f(%.0f)\n", 
-              procid_str_static(&pid), file_id_static_string(&id),
+              procid_str_static(&pid), file_id_string_tos(&id),
               lock_type==READ_LOCK?"R":"W",
               (double)start, (double)start+size-1,(double)size);
 
@@ -161,7 +166,7 @@ static struct cli_state *connect_one(char *share, int snum)
        struct nmb_name called, calling;
        char *server_n;
        fstring server;
-       struct in_addr ip;
+       struct sockaddr_storage ss;
        fstring myname;
        static int count;
        NTSTATUS status;
@@ -173,8 +178,8 @@ static struct cli_state *connect_one(char *share, int snum)
        share++;
 
        server_n = server;
-       
-        zero_ip(&ip);
+
+       zero_sockaddr(&ss);
 
        slprintf(myname,sizeof(myname), "lock-%lu-%u", (unsigned long)getpid(), count++);
 
@@ -182,7 +187,7 @@ static struct cli_state *connect_one(char *share, int snum)
        make_nmb_name(&called , server, 0x20);
 
  again:
-        zero_ip(&ip);
+        zero_sockaddr(&ss);
 
        /* have to open a new connection */
        if (!(c=cli_initialise())) {
@@ -190,7 +195,7 @@ static struct cli_state *connect_one(char *share, int snum)
                return NULL;
        }
 
-       status = cli_connect(c, server_n, &ip);
+       status = cli_connect(c, server_n, &ss);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("Connection to %s failed. Error %s\n", server_n, nt_errstr(status) ));
                return NULL;
@@ -210,8 +215,10 @@ static struct cli_state *connect_one(char *share, int snum)
 
        DEBUG(4,(" session request ok\n"));
 
-       if (!cli_negprot(c)) {
-               DEBUG(0,("protocol negotiation failed\n"));
+       status = cli_negprot(c);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0, ("protocol negotiation failed: %s\n",
+                         nt_errstr(status)));
                cli_shutdown(c);
                return NULL;
        }
@@ -225,17 +232,16 @@ static struct cli_state *connect_one(char *share, int snum)
        }
 
        if (got_pass == 1) {
-               fstrcpy(password[1], password[0]);
-               fstrcpy(username[1], username[0]);
+               strlcpy(password[1], password[0],sizeof(password[1]));
+               strlcpy(username[1], username[0],sizeof(username[1]));
        }
 
-       if (!NT_STATUS_IS_OK(cli_session_setup(c, username[snum], 
-                                              password[snum],
-                                              strlen(password[snum]),
-                                              password[snum],
-                                              strlen(password[snum]),
-                                              lp_workgroup()))) {
-               DEBUG(0,("session setup failed: %s\n", cli_errstr(c)));
+       status = cli_session_setup(c, username[snum],
+                                  password[snum], strlen(password[snum]),
+                                  password[snum], strlen(password[snum]),
+                                  lp_workgroup());
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0,("session setup failed: %s\n", nt_errstr(status)));
                return NULL;
        }
 
@@ -253,9 +259,10 @@ static struct cli_state *connect_one(char *share, int snum)
        
        DEBUG(4,(" session setup ok\n"));
 
-       if (!cli_send_tconX(c, share, "?????",
-                           password[snum], strlen(password[snum])+1)) {
-               DEBUG(0,("tree connect failed: %s\n", cli_errstr(c)));
+       status = cli_tcon_andx(c, share, "?????", password[snum],
+                              strlen(password[snum])+1);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0,("tree connect failed: %s\n", nt_errstr(status)));
                cli_shutdown(c);
                return NULL;
        }
@@ -268,7 +275,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 cli_state *cli[NSERVERS][NCONNECTIONS], uint16_t fnum[NSERVERS][NCONNECTIONS][NFILES],
                      char *share[NSERVERS])
 {
        int server, conn, f;
@@ -277,9 +284,9 @@ static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS], int fnum[NS
        for (conn=0;conn<NCONNECTIONS;conn++) {
                if (cli[server][conn]) {
                        for (f=0;f<NFILES;f++) {
-                               if (fnum[server][conn][f] != -1) {
+                               if (fnum[server][conn][f] != (uint16_t)-1) {
                                        cli_close(cli[server][conn], fnum[server][conn][f]);
-                                       fnum[server][conn][f] = -1;
+                                       fnum[server][conn][f] = (uint16_t)-1;
                                }
                        }
                        cli_ulogoff(cli[server][conn]);
@@ -295,17 +302,17 @@ static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS], int fnum[NS
 
 
 
-static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS], 
-                    int fnum[NSERVERS][NCONNECTIONS][NFILES],
+static bool test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS], 
+                    uint16_t fnum[NSERVERS][NCONNECTIONS][NFILES],
                     struct record *rec)
 {
        unsigned conn = rec->conn;
        unsigned f = rec->f;
-       SMB_BIG_UINT start = rec->start;
-       SMB_BIG_UINT len = rec->len;
+       uint64_t start = rec->start;
+       uint64_t len = rec->len;
        enum brl_type op = rec->lock_type;
        int server;
-       BOOL ret[NSERVERS];
+       bool ret[NSERVERS];
        NTSTATUS status[NSERVERS];
 
        switch (rec->lock_op) {
@@ -336,9 +343,9 @@ static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS],
        case OP_UNLOCK:
                /* unset a lock */
                for (server=0;server<NSERVERS;server++) {
-                       ret[server] = cli_unlock64(cli[server][conn], 
+                       ret[server] = NT_STATUS_IS_OK(cli_unlock64(cli[server][conn], 
                                                   fnum[server][conn][f],
-                                                  start, len);
+                                                  start, len));
                        status[server] = cli_nt_error(cli[server][conn]);
                }
                if (showall || 
@@ -357,13 +364,13 @@ static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS],
                /* reopen the file */
                for (server=0;server<NSERVERS;server++) {
                        cli_close(cli[server][conn], fnum[server][conn][f]);
-                       fnum[server][conn][f] = -1;
+                       fnum[server][conn][f] = (uint16_t)-1;
                }
                for (server=0;server<NSERVERS;server++) {
-                       fnum[server][conn][f] = cli_open(cli[server][conn], FILENAME,
+                       fnum[server][conn][f] = (uint16_t)-1;
+                       if (!NT_STATUS_IS_OK(cli_open(cli[server][conn], FILENAME,
                                                         O_RDWR|O_CREAT,
-                                                        DENY_NONE);
-                       if (fnum[server][conn][f] == -1) {
+                                                        DENY_NONE, &fnum[server][conn][f]))) {
                                printf("failed to reopen on share%d\n", server);
                                return False;
                        }
@@ -380,35 +387,36 @@ static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS],
 }
 
 static void close_files(struct cli_state *cli[NSERVERS][NCONNECTIONS], 
-                       int fnum[NSERVERS][NCONNECTIONS][NFILES])
+                       uint16_t fnum[NSERVERS][NCONNECTIONS][NFILES])
 {
        int server, conn, f; 
 
        for (server=0;server<NSERVERS;server++)
        for (conn=0;conn<NCONNECTIONS;conn++)
        for (f=0;f<NFILES;f++) {
-               if (fnum[server][conn][f] != -1) {
+               if (fnum[server][conn][f] != (uint16_t)-1) {
                        cli_close(cli[server][conn], fnum[server][conn][f]);
-                       fnum[server][conn][f] = -1;
+                       fnum[server][conn][f] = (uint16_t)-1;
                }
        }
        for (server=0;server<NSERVERS;server++) {
-               cli_unlink(cli[server][0], FILENAME);
+               cli_unlink(cli[server][0], FILENAME, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
        }
 }
 
 static void open_files(struct cli_state *cli[NSERVERS][NCONNECTIONS], 
-                      int fnum[NSERVERS][NCONNECTIONS][NFILES])
+                      uint16_t fnum[NSERVERS][NCONNECTIONS][NFILES])
 {
        int server, conn, f; 
 
        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], FILENAME,
+               fnum[server][conn][f] = (uint16_t)-1;
+               if (!NT_STATUS_IS_OK(cli_open(cli[server][conn], FILENAME,
                                                 O_RDWR|O_CREAT,
-                                                DENY_NONE);
-               if (fnum[server][conn][f] == -1) {
+                                                DENY_NONE,
+                                                &fnum[server][conn][f]))) {
                        fprintf(stderr,"Failed to open fnum[%u][%u][%u]\n",
                                server, conn, f);
                        exit(1);
@@ -418,7 +426,7 @@ static void open_files(struct cli_state *cli[NSERVERS][NCONNECTIONS],
 
 
 static int retest(struct cli_state *cli[NSERVERS][NCONNECTIONS], 
-                  int fnum[NSERVERS][NCONNECTIONS][NFILES],
+                  uint16_t fnum[NSERVERS][NCONNECTIONS][NFILES],
                   int n)
 {
        int i;
@@ -444,7 +452,7 @@ static int retest(struct cli_state *cli[NSERVERS][NCONNECTIONS],
 static void test_locks(char *share[NSERVERS])
 {
        struct cli_state *cli[NSERVERS][NCONNECTIONS];
-       int fnum[NSERVERS][NCONNECTIONS][NFILES];
+       uint16_t fnum[NSERVERS][NCONNECTIONS][NFILES];
        int n, i, n1, skip, r1, r2; 
 
        ZERO_STRUCT(fnum);
@@ -598,14 +606,12 @@ static void usage(void)
 
        load_case_tables();
 
-       dbf = x_stderr;
-
        if (argc < 3 || argv[1][0] == '-') {
                usage();
                exit(1);
        }
 
-       setup_logging(argv[0],True);
+       setup_logging(argv[0], DEBUG_STDOUT);
 
        for (server=0;server<NSERVERS;server++) {
                share[server] = argv[1+server];
@@ -615,7 +621,7 @@ static void usage(void)
        argc -= NSERVERS;
        argv += NSERVERS;
 
-       lp_load(dyn_CONFIGFILE,True,False,False,True);
+       lp_load(get_dyn_CONFIGFILE(),True,False,False,True);
        load_interfaces();
 
        if (getenv("USER")) {