X-Git-Url: http://git.samba.org/?a=blobdiff_plain;f=source3%2Ftorture%2Flocktest2.c;h=5c8a2d8019ed953a7b1ca87419dfe85d54d66a06;hb=8e306b51b79d3dacd68be9f13aa8455e2eb4c03f;hp=899310933fc4453697ce62992182ad40d3708b1d;hpb=b30e75692d68233448b3ad3d7ddd4b4ac423d3ab;p=amitay%2Fsamba.git
diff --git a/source3/torture/locktest2.c b/source3/torture/locktest2.c
index 899310933fc..5c8a2d8019e 100644
--- a/source3/torture/locktest2.c
+++ b/source3/torture/locktest2.c
@@ -1,12 +1,11 @@
/*
- Unix SMB/Netbios implementation.
- Version 2.0
+ Unix SMB/CIFS implementation.
byte range lock tester - with local filesystem support
Copyright (C) Andrew Tridgell 1999
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,
@@ -15,22 +14,22 @@
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 .
*/
-#define NO_SYSLOG
-
#include "includes.h"
static fstring password;
static fstring username;
static int got_pass;
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;
+
+extern char *optarg;
+extern int optind;
#define FILENAME "\\locktest.dat"
#define LOCKRANGE 100
@@ -63,28 +62,39 @@ 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;
+ char *path;
switch (fstype) {
case FSTYPE_SMB:
- return cli_open(c, fname, flags, DENY_NONE);
+ {
+ uint16_t fd;
+ if (!NT_STATUS_IS_OK(cli_open(c, fname, flags, DENY_NONE, &fd))) {
+ return -1;
+ }
+ return fd;
+ }
case FSTYPE_NFS:
- slprintf(path, sizeof(path), "%s%s", nfs, fname);
- pstring_sub(path,"\\", "/");
- return open(path, flags, 0666);
+ if (asprintf(&path, "%s%s", nfs, fname) > 0) {
+ int ret;
+ string_replace(path,'\\', '/');
+ ret = open(path, flags, 0666);
+ SAFE_FREE(path);
+ return ret;
+ }
+ break;
}
return -1;
}
-static BOOL try_close(struct cli_state *c, int fstype, int fd)
+static bool try_close(struct cli_state *c, int fstype, int fd)
{
switch (fstype) {
case FSTYPE_SMB:
- return cli_close(c, fd);
+ return NT_STATUS_IS_OK(cli_close(c, fd));
case FSTYPE_NFS:
return close(fd) == 0;
@@ -93,9 +103,9 @@ static BOOL try_close(struct cli_state *c, int fstype, int fd)
return False;
}
-static BOOL try_lock(struct cli_state *c, int fstype,
+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;
@@ -115,14 +125,14 @@ static BOOL try_lock(struct cli_state *c, int fstype,
return False;
}
-static BOOL try_unlock(struct cli_state *c, int fstype,
+static bool try_unlock(struct cli_state *c, int fstype,
int fd, unsigned start, unsigned len)
{
struct flock lock;
switch (fstype) {
case FSTYPE_SMB:
- return cli_unlock(c, fd, start, len);
+ return NT_STATUS_IS_OK(cli_unlock(c, fd, start, len));
case FSTYPE_NFS:
lock.l_type = F_UNLCK;
@@ -136,12 +146,14 @@ static BOOL try_unlock(struct cli_state *c, int fstype,
return False;
}
-static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, int pid,
+static void print_brl(struct file_id id, struct server_id pid,
enum brl_type lock_type,
- br_off start, br_off size)
+ enum brl_flavour lock_flav,
+ br_off start, br_off size,
+ void *private_data)
{
- printf("%6d %05x:%05x %s %.0f:%.0f(%.0f)\n",
- (int)pid, (int)dev, (int)ino,
+ printf("%6d %s %s %.0f:%.0f(%.0f)\n",
+ (int)procid_to_pid(&pid), file_id_string_tos(&id),
lock_type==READ_LOCK?"R":"W",
(double)start, (double)start+size-1,(double)size);
@@ -150,16 +162,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 +179,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-%lu-%u", (unsigned long)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,
+ Undefined, 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 +223,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]) {
@@ -280,7 +234,7 @@ static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS],
-static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS],
+static bool test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS],
char *nfs[NSERVERS],
int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES],
struct record *rec)
@@ -292,9 +246,9 @@ 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];
+ bool ret[NSERVERS];
if (r1 < READ_PCT) {
op = READ_LOCK;
@@ -316,7 +270,7 @@ static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS],
op==READ_LOCK?"READ_LOCK":"WRITE_LOCK",
ret[0], ret[1]);
}
- if (showall) brl_forall(print_brl);
+ if (showall) brl_forall(print_brl, NULL);
if (ret[0] != ret[1]) return False;
} else if (r2 < LOCK_PCT+UNLOCK_PCT) {
/* unset a lock */
@@ -331,7 +285,7 @@ static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS],
start, start+len-1, len,
ret[0], ret[1]);
}
- if (showall) brl_forall(print_brl);
+ if (showall) brl_forall(print_brl, NULL);
if (!hide_unlock_fails && ret[0] != ret[1]) return False;
} else {
/* reopen the file */
@@ -347,7 +301,7 @@ static BOOL test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS],
if (showall) {
printf("reopen conn=%u fstype=%u f=%u\n",
conn, fstype, f);
- brl_forall(print_brl);
+ brl_forall(print_brl, NULL);
}
}
return True;
@@ -369,7 +323,7 @@ static void close_files(struct cli_state *cli[NSERVERS][NCONNECTIONS],
}
}
for (server=0;server