s3: Change sockaddr util function names for consistency
[samba.git] / source3 / torture / locktest.c
index 5f9a63802b31d351ed0b343c5ee87e6af0e4f9a0..247c9abcc18463fe0ea3623498bed35e24004b4d 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,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#define NO_SYSLOG
-
 #include "includes.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;
 
 #define FILENAME "\\locktest.dat"
 
@@ -52,11 +53,25 @@ 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;
        char conn, f;
-       SMB_BIG_UINT start, len;
+       uint64_t start, len;
        char needed;
 };
 
@@ -100,26 +115,32 @@ static struct record preset[] = {
 
 static struct record *recorded;
 
-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)
+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
        {
-               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("%6d   %05x:%05x    %s  %.0f:%.0f(%.0f)\n", 
-              (int)pid, (int)dev, (int)ino, 
+       printf("%s   %s    %s  %.0f:%.0f(%.0f)\n", 
+              procid_str_static(&pid), file_id_string_tos(&id),
               lock_type==READ_LOCK?"R":"W",
               (double)start, (double)start+size-1,(double)size);
 
@@ -128,7 +149,7 @@ static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, int pid,
 
 static void show_locks(void)
 {
-       brl_forall(print_brl);
+       brl_forall(print_brl, NULL);
        /* system("cat /proc/locks"); */
 }
 
@@ -142,9 +163,10 @@ 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;
 
        fstrcpy(server,share+2);
        share = strchr_m(server,'\\');
@@ -153,23 +175,29 @@ static struct cli_state *connect_one(char *share, int snum)
        share++;
 
        server_n = server;
-       
-        zero_ip(&ip);
 
-       slprintf(myname,sizeof(myname), "lock-%u-%u", getpid(), count++);
+       zero_sockaddr(&ss);
+
+       slprintf(myname,sizeof(myname), "lock-%lu-%u", (unsigned long)getpid(), count++);
 
        make_nmb_name(&calling, myname, 0x0);
        make_nmb_name(&called , server, 0x20);
 
  again:
-        zero_ip(&ip);
+        zero_sockaddr(&ss);
 
        /* 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, &ss);
+       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)) {
@@ -203,10 +231,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;
        }
@@ -267,17 +297,17 @@ 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 cli_state *cli[NSERVERS][NCONNECTIONS], 
                     int 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) {
@@ -422,7 +452,7 @@ static void test_locks(char *share[NSERVERS])
        ZERO_STRUCT(fnum);
        ZERO_STRUCT(cli);
 
-       recorded = (struct record *)malloc(sizeof(*recorded) * numops);
+       recorded = SMB_MALLOC_ARRAY(struct record, numops);
 
        for (n=0; n<numops; n++) {
 #if PRESETS
@@ -521,9 +551,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,
@@ -562,14 +592,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] == '-') {
@@ -587,7 +617,7 @@ static void usage(void)
        argc -= NSERVERS;
        argv += NSERVERS;
 
-       lp_load(dyn_CONFIGFILE,True,False,False);
+       lp_load(get_dyn_CONFIGFILE(),True,False,False,True);
        load_interfaces();
 
        if (getenv("USER")) {
@@ -602,13 +632,13 @@ static void usage(void)
                case 'k':
 #ifdef HAVE_KRB5
                        use_kerberos = True;
-                       got_pass = 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);
@@ -663,6 +693,8 @@ static void usage(void)
                }
        }
 
+       if(use_kerberos && !got_user) got_pass = True;
+
        argc -= optind;
        argv += optind;