r23779: Change from v2 or later to v3 or later.
[nivanova/samba-autobuild/.git] / source3 / torture / locktest.c
index c8336ebaf66daf90ab0098be033515e22f71260f..97242541d48a628edab02643bb45460727febc7e 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,
@@ -36,6 +36,9 @@ static unsigned min_length = 0;
 static BOOL exact_error_codes;
 static BOOL zero_zero;
 
+extern char *optarg;
+extern int optind;
+
 #define FILENAME "\\locktest.dat"
 
 #define READ_PCT 50
@@ -51,6 +54,20 @@ static BOOL zero_zero;
 
 enum lock_op {OP_LOCK, OP_UNLOCK, OP_REOPEN};
 
+static const char *lock_op_type(int op)
+{
+       if (op == WRITE_LOCK) return "write";
+       else if (op == READ_LOCK) return "read";
+       else return "other";
+}
+
+static const char *lock_op_name(enum lock_op op)
+{
+       if (op == OP_LOCK) return "lock";
+       else if (op == OP_UNLOCK) return "unlock";
+       else return "reopen";
+}
+
 struct record {
        enum lock_op lock_op;
        enum brl_type lock_type;
@@ -99,9 +116,13 @@ static struct record preset[] = {
 
 static struct record *recorded;
 
-static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, struct process_id pid, 
-                     enum brl_type lock_type,
-                     br_off start, br_off size)
+static void print_brl(struct file_id id,
+                       struct server_id pid, 
+                       enum brl_type lock_type,
+                       enum brl_flavour lock_flav,
+                       br_off start,
+                       br_off size,
+                       void *private_data)
 {
 #if NASTY_POSIX_LOCK_HACK
        {
@@ -117,8 +138,8 @@ static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, struct process_id pid,
        }
 #endif
 
-       printf("%s   %05x:%05x    %s  %.0f:%.0f(%.0f)\n", 
-              procid_str_static(&pid), (int)dev, (int)ino, 
+       printf("%s   %s    %s  %.0f:%.0f(%.0f)\n", 
+              procid_str_static(&pid), file_id_static_string(&id),
               lock_type==READ_LOCK?"R":"W",
               (double)start, (double)start+size-1,(double)size);
 
@@ -127,7 +148,7 @@ static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, struct process_id pid,
 
 static void show_locks(void)
 {
-       brl_forall(print_brl);
+       brl_forall(print_brl, NULL);
        /* system("cat /proc/locks"); */
 }
 
@@ -144,6 +165,7 @@ static struct cli_state *connect_one(char *share, int snum)
        struct in_addr ip;
        fstring myname;
        static int count;
+       NTSTATUS status;
 
        fstrcpy(server,share+2);
        share = strchr_m(server,'\\');
@@ -164,11 +186,17 @@ static struct cli_state *connect_one(char *share, int snum)
         zero_ip(&ip);
 
        /* have to open a new connection */
-       if (!(c=cli_initialise(NULL)) || !cli_connect(c, server_n, &ip)) {
+       if (!(c=cli_initialise())) {
                DEBUG(0,("Connection to %s failed\n", server_n));
                return NULL;
        }
 
+       status = cli_connect(c, server_n, &ip);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0,("Connection to %s failed. Error %s\n", server_n, nt_errstr(status) ));
+               return NULL;
+       }
+
        c->use_kerberos = use_kerberos;
 
        if (!cli_session_request(c, &calling, &called)) {
@@ -202,10 +230,12 @@ static struct cli_state *connect_one(char *share, int snum)
                fstrcpy(username[1], username[0]);
        }
 
-       if (!cli_session_setup(c, username[snum], 
-                              password[snum], strlen(password[snum]),
-                              password[snum], strlen(password[snum]),
-                              lp_workgroup())) {
+       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)));
                return NULL;
        }
@@ -520,9 +550,9 @@ static void test_locks(char *share[NSERVERS])
        close_files(cli, fnum);
 
        for (i=0;i<n;i++) {
-               printf("{%d, %d, %u, %u, %.0f, %.0f, %u},\n",
-                      recorded[i].lock_op,
-                      recorded[i].lock_type,
+               printf("{%s, %s, conn = %u, file = %u, start = %.0f, len = %.0f, %u},\n",
+                      lock_op_name(recorded[i].lock_op),
+                      lock_op_type(recorded[i].lock_type),
                       recorded[i].conn,
                       recorded[i].f,
                       (double)recorded[i].start,
@@ -561,14 +591,14 @@ static void usage(void)
  int main(int argc,char *argv[])
 {
        char *share[NSERVERS];
-       extern char *optarg;
-       extern int optind;
        int opt;
        char *p;
        int seed, server;
 
        setlinebuf(stdout);
 
+       load_case_tables();
+
        dbf = x_stderr;
 
        if (argc < 3 || argv[1][0] == '-') {
@@ -586,7 +616,7 @@ static void usage(void)
        argc -= NSERVERS;
        argv += NSERVERS;
 
-       lp_load(dyn_CONFIGFILE,True,False,False);
+       lp_load(dyn_CONFIGFILE,True,False,False,True);
        load_interfaces();
 
        if (getenv("USER")) {