Merge from HEAD:
[bbaumbach/samba-autobuild/.git] / source3 / torture / locktest2.c
index 899310933fc4453697ce62992182ad40d3708b1d..97844b5609ecfbea1ad374ab0862d453079592f4 100644 (file)
@@ -1,6 +1,5 @@
 /* 
-   Unix SMB/Netbios implementation.
-   Version 2.0
+   Unix SMB/CIFS implementation.
    byte range lock tester - with local filesystem support
    Copyright (C) Andrew Tridgell 1999
    
@@ -63,7 +62,7 @@ struct record {
 
 static struct record *recorded;
 
-static int try_open(struct cli_state *c, char *nfs, int fstype, char *fname, int flags)
+static int try_open(struct cli_state *c, char *nfs, int fstype, const char *fname, int flags)
 {
        pstring path;
 
@@ -95,7 +94,7 @@ static BOOL try_close(struct cli_state *c, int fstype, int fd)
 
 static BOOL try_lock(struct cli_state *c, int fstype, 
                     int fd, unsigned start, unsigned len,
-                    int op)
+                    enum brl_type op)
 {
        struct flock lock;
 
@@ -150,16 +149,14 @@ static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, int pid,
 /***************************************************** 
 return a connection to a server
 *******************************************************/
-struct cli_state *connect_one(char *share)
+static struct cli_state *connect_one(char *share)
 {
        struct cli_state *c;
-       struct nmb_name called, calling;
        char *server_n;
        fstring server;
-       struct in_addr ip;
-       extern struct in_addr ipzero;
        fstring myname;
        static int count;
+       NTSTATUS nt_status;
 
        fstrcpy(server,share+2);
        share = strchr_m(server,'\\');
@@ -169,78 +166,24 @@ struct cli_state *connect_one(char *share)
 
        server_n = server;
        
-       ip = ipzero;
-
-       slprintf(myname,sizeof(myname), "lock-%u-%u", getpid(), count++);
-
-       make_nmb_name(&calling, myname, 0x0);
-       make_nmb_name(&called , server, 0x20);
-
- again:
-       ip = ipzero;
-
-       /* have to open a new connection */
-       if (!(c=cli_initialise(NULL)) || !cli_connect(c, server_n, &ip)) {
-               DEBUG(0,("Connection to %s failed\n", server_n));
-               return NULL;
-       }
-
-       if (!cli_session_request(c, &calling, &called)) {
-               DEBUG(0,("session request to %s failed\n", called.name));
-               cli_shutdown(c);
-               if (strcmp(called.name, "*SMBSERVER")) {
-                       make_nmb_name(&called , "*SMBSERVER", 0x20);
-                       goto again;
-               }
-               return NULL;
-       }
-
-       DEBUG(4,(" session request ok\n"));
-
-       if (!cli_negprot(c)) {
-               DEBUG(0,("protocol negotiation failed\n"));
-               cli_shutdown(c);
-               return NULL;
-       }
-
        if (!got_pass) {
                char *pass = getpass("Password: ");
                if (pass) {
-                       pstrcpy(password, pass);
+                       fstrcpy(password, pass);
                }
        }
 
-       if (!cli_session_setup(c, username, 
-                              password, strlen(password),
-                              password, strlen(password),
-                              lp_workgroup())) {
-               DEBUG(0,("session setup failed: %s\n", cli_errstr(c)));
-               return NULL;
-       }
+       slprintf(myname,sizeof(myname), "lock-%u-%u", getpid(), count++);
 
-       /*
-        * These next two lines are needed to emulate
-        * old client behaviour for people who have
-        * scripts based on client output.
-        * QUESTION ? Do we want to have a 'client compatibility
-        * mode to turn these on/off ? JRA.
-        */
-
-       if (*c->server_domain || *c->server_os || *c->server_type)
-               DEBUG(1,("Domain=[%s] OS=[%s] Server=[%s]\n",
-                       c->server_domain,c->server_os,c->server_type));
-       
-       DEBUG(4,(" session setup ok\n"));
+       nt_status = cli_full_connection(&c, myname, server_n, NULL, 0, share, "?????", 
+                                       username, lp_workgroup(), password, 0,
+                                       NULL);
 
-       if (!cli_send_tconX(c, share, "?????",
-                           password, strlen(password)+1)) {
-               DEBUG(0,("tree connect failed: %s\n", cli_errstr(c)));
-               cli_shutdown(c);
+       if (!NT_STATUS_IS_OK(nt_status)) {
+               DEBUG(0, ("cli_full_connection failed with error %s\n", nt_errstr(nt_status)));
                return NULL;
        }
 
-       DEBUG(4,(" tconx ok\n"));
-
        c->use_oplocks = use_oplocks;
 
        return c;
@@ -267,8 +210,6 @@ static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS],
                        }
                        cli_ulogoff(cli[server][conn]);
                        cli_shutdown(cli[server][conn]);
-                       free(cli[server][conn]);
-                       cli[server][conn] = NULL;
                }
                cli[server][conn] = connect_one(share[server]);
                if (!cli[server][conn]) {
@@ -292,7 +233,7 @@ static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS],
        unsigned len = rec->len;
        unsigned r1 = rec->r1;
        unsigned r2 = rec->r2;
-       unsigned op;
+       enum brl_type op;
        int server;
        BOOL ret[NSERVERS];
 
@@ -533,11 +474,9 @@ static void usage(void)
        char *share1, *share2, *nfspath1, *nfspath2;
        extern char *optarg;
        extern int optind;
-       extern XFILE *dbf;
        int opt;
        char *p;
        int seed;
-       static pstring servicesf = CONFIGFILE;
 
        setlinebuf(stdout);
 
@@ -561,13 +500,11 @@ static void usage(void)
        argc -= 4;
        argv += 4;
 
-       TimeInit();
-
-       lp_load(servicesf,True,False,False);
+       lp_load(dyn_CONFIGFILE,True,False,False);
        load_interfaces();
 
        if (getenv("USER")) {
-               pstrcpy(username,getenv("USER"));
+               fstrcpy(username,getenv("USER"));
        }
 
        seed = time(NULL);
@@ -575,11 +512,11 @@ static void usage(void)
        while ((opt = getopt(argc, argv, "U:s:ho:aAW:O")) != EOF) {
                switch (opt) {
                case 'U':
-                       pstrcpy(username,optarg);
+                       fstrcpy(username,optarg);
                        p = strchr_m(username,'%');
                        if (p) {
                                *p = 0;
-                               pstrcpy(password, p+1);
+                               fstrcpy(password, p+1);
                                got_pass = 1;
                        }
                        break;