/* Unix SMB/Netbios implementation. Version 2.0 randomised byte range lock tester 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 (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 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. */ #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; #define FILENAME "\\locktest.dat" #define LOCKRANGE 1000 #define LOCKBASE 0; /* #define LOCKBASE (0x40000000 - 50) */ #define READ_PCT 50 #define LOCK_PCT 35 #define UNLOCK_PCT 55 #define RANGE_MULTIPLE 1 #define NSERVERS 2 #define NCONNECTIONS 2 #define NFILES 2 #define LOCK_TIMEOUT 0 #define NASTY_POSIX_LOCK_HACK 0 struct record { char r1, r2; char conn, f; SMB_BIG_UINT start, len; char needed; }; static struct record preset[] = { #if 0 {36, 5, 0, 0, 0, 8, 1}, { 2, 6, 0, 1, 0, 1, 1}, {53, 92, 0, 0, 0, 0, 1}, {99, 11, 0, 0, 7, 1, 1}, #endif }; 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) { #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); } lastino = ino; } #endif printf("%6d %05x:%05x %s %.0f:%.0f(%.0f)\n", (int)pid, (int)dev, (int)ino, lock_type==READ_LOCK?"R":"W", (double)start, (double)start+size-1,(double)size); } static void show_locks(void) { brl_forall(print_brl); /* system("cat /proc/locks"); */ } /***************************************************** return a connection to a server *******************************************************/ 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; fstrcpy(server,share+2); share = strchr(server,'\\'); if (!share) return NULL; *share = 0; 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_set_port(c, 139) == 0) || !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); } } 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; } /* * 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")); if (!cli_send_tconX(c, share, "?????", password, strlen(password)+1)) { DEBUG(0,("tree connect failed: %s\n", cli_errstr(c))); cli_shutdown(c); return NULL; } DEBUG(4,(" tconx ok\n")); c->use_oplocks = use_oplocks; return c; } static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS], int fnum[NSERVERS][NCONNECTIONS][NFILES], char *share[NSERVERS]) { int server, conn, f; for (server=0;serverconn; unsigned f = rec->f; SMB_BIG_UINT start = rec->start; SMB_BIG_UINT len = rec->len; unsigned r1 = rec->r1; unsigned r2 = rec->r2; unsigned op; int server; BOOL ret[NSERVERS]; if (r1 < READ_PCT) { op = READ_LOCK; } else { op = WRITE_LOCK; } if (r2 < LOCK_PCT) { /* set a lock */ for (server=0;server %u:%u\n", conn, f, (double)start, (double)start+len-1, (double)len, op==READ_LOCK?"READ_LOCK":"WRITE_LOCK", ret[0], ret[1]); } if (showall || ret[0] != ret[1]) show_locks(); if (ret[0] != ret[1]) return False; } else if (r2 < LOCK_PCT+UNLOCK_PCT) { /* unset a lock */ for (server=0;server %u:%u\n", conn, f, (double)start, (double)start+len-1, (double)len, ret[0], ret[1]); } if (showall || ret[0] != ret[1]) show_locks(); if (!hide_unlock_fails && ret[0] != ret[1]) return False; } else { /* reopen the file */ for (server=0;server