⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 locktest.c

📁 samba-3.0.22.tar.gz 编译smb服务器的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*    Unix SMB/CIFS implementation.   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.*/#include "includes.h"static fstring password[2];static fstring username[2];static int got_user;static int got_pass;static BOOL use_kerberos;static int numops = 1000;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;#define FILENAME "\\locktest.dat"#define READ_PCT 50#define LOCK_PCT 45#define UNLOCK_PCT 70#define RANGE_MULTIPLE 1#define NSERVERS 2#define NCONNECTIONS 2#define NFILES 2#define LOCK_TIMEOUT 0#define NASTY_POSIX_LOCK_HACK 0enum lock_op {OP_LOCK, OP_UNLOCK, OP_REOPEN};struct record {	enum lock_op lock_op;	enum brl_type lock_type;	char conn, f;	SMB_BIG_UINT start, len;	char needed;};#define PRESETS 0#if PRESETSstatic struct record preset[] = {{OP_LOCK, WRITE_LOCK, 0, 0, 2, 0, 1},{OP_LOCK, WRITE_LOCK, 0, 0, 0, 0, 1},{OP_LOCK, WRITE_LOCK, 0, 0, 3, 0, 1},{OP_UNLOCK, 0       , 0, 0, 2, 0, 1},{OP_REOPEN, 0, 0, 0, 0, 0, 1},{OP_LOCK, READ_LOCK, 0, 0, 2, 0, 1},{OP_LOCK, READ_LOCK, 0, 0, 1, 1, 1},{OP_LOCK, WRITE_LOCK, 0, 0, 0, 0, 1},{OP_REOPEN, 0, 0, 0, 0, 0, 1},{OP_LOCK, READ_LOCK, 0, 0, 2, 0, 1},{OP_LOCK, WRITE_LOCK, 0, 0, 3, 1, 1},{OP_LOCK, WRITE_LOCK, 0, 0, 0, 0, 1},{OP_REOPEN, 0, 0, 0, 0, 0, 1},{OP_LOCK, READ_LOCK, 0, 0, 2, 0, 1},{OP_LOCK, WRITE_LOCK, 0, 0, 1, 1, 1},{OP_LOCK, WRITE_LOCK, 0, 0, 0, 0, 1},{OP_REOPEN, 0, 0, 0, 0, 0, 1},{OP_LOCK, WRITE_LOCK, 0, 0, 2, 0, 1},{OP_LOCK, READ_LOCK, 0, 0, 1, 1, 1},{OP_LOCK, WRITE_LOCK, 0, 0, 0, 0, 1},{OP_REOPEN, 0, 0, 0, 0, 0, 1},{OP_LOCK, WRITE_LOCK, 0, 0, 2, 0, 1},{OP_LOCK, READ_LOCK, 0, 0, 3, 1, 1},{OP_LOCK, WRITE_LOCK, 0, 0, 0, 0, 1},{OP_REOPEN, 0, 0, 0, 0, 0, 1},};#endifstatic 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){#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("%s   %05x:%05x    %s  %.0f:%.0f(%.0f)\n", 	       procid_str_static(&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*******************************************************/static struct cli_state *connect_one(char *share, int snum){	struct cli_state *c;	struct nmb_name called, calling;	char *server_n;	fstring server;	struct in_addr ip;	fstring myname;	static int count;	fstrcpy(server,share+2);	share = strchr_m(server,'\\');	if (!share) return NULL;	*share = 0;	share++;	server_n = server;	        zero_ip(&ip);	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);	/* 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;	}	c->use_kerberos = use_kerberos;	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) {			fstrcpy(password[0], pass);			fstrcpy(password[1], pass);		}	}	if (got_pass == 1) {		fstrcpy(password[1], password[0]);		fstrcpy(username[1], username[0]);	}	if (!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;	}	/*	 * 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[snum], strlen(password[snum])+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;server<NSERVERS;server++)	for (conn=0;conn<NCONNECTIONS;conn++) {		if (cli[server][conn]) {			for (f=0;f<NFILES;f++) {				if (fnum[server][conn][f] != -1) {					cli_close(cli[server][conn], fnum[server][conn][f]);					fnum[server][conn][f] = -1;				}			}			cli_ulogoff(cli[server][conn]);			cli_shutdown(cli[server][conn]);		}		cli[server][conn] = connect_one(share[server], server);		if (!cli[server][conn]) {			DEBUG(0,("Failed to connect to %s\n", share[server]));			exit(1);		}	}}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;	enum brl_type op = rec->lock_type;	int server;	BOOL ret[NSERVERS];	NTSTATUS status[NSERVERS];	switch (rec->lock_op) {	case OP_LOCK:		/* set a lock */		for (server=0;server<NSERVERS;server++) {			ret[server] = cli_lock64(cli[server][conn], 						 fnum[server][conn][f],						 start, len, LOCK_TIMEOUT, op);			status[server] = cli_nt_error(cli[server][conn]);			if (!exact_error_codes && 			    NT_STATUS_EQUAL(status[server], 					    NT_STATUS_FILE_LOCK_CONFLICT)) {				status[server] = NT_STATUS_LOCK_NOT_GRANTED;			}		}		if (showall || !NT_STATUS_EQUAL(status[0],status[1])) {			printf("lock   conn=%u f=%u range=%.0f(%.0f) op=%s -> %s:%s\n",			       conn, f, 			       (double)start, (double)len,			       op==READ_LOCK?"READ_LOCK":"WRITE_LOCK",			       nt_errstr(status[0]), nt_errstr(status[1]));		}		if (showall || !NT_STATUS_EQUAL(status[0],status[1])) show_locks();		if (!NT_STATUS_EQUAL(status[0],status[1])) return False;		break;			case OP_UNLOCK:		/* unset a lock */		for (server=0;server<NSERVERS;server++) {			ret[server] = cli_unlock64(cli[server][conn], 						   fnum[server][conn][f],						   start, len);			status[server] = cli_nt_error(cli[server][conn]);		}		if (showall || 		    (!hide_unlock_fails && !NT_STATUS_EQUAL(status[0],status[1]))) {			printf("unlock conn=%u f=%u range=%.0f(%.0f)       -> %s:%s\n",			       conn, f, 			       (double)start, (double)len,			       nt_errstr(status[0]), nt_errstr(status[1]));		}		if (showall || !NT_STATUS_EQUAL(status[0],status[1])) show_locks();		if (!hide_unlock_fails && !NT_STATUS_EQUAL(status[0],status[1])) 			return False;		break;	case OP_REOPEN:		/* reopen the file */		for (server=0;server<NSERVERS;server++) {			cli_close(cli[server][conn], fnum[server][conn][f]);			fnum[server][conn][f] = -1;		}		for (server=0;server<NSERVERS;server++) {			fnum[server][conn][f] = cli_open(cli[server][conn], FILENAME,							 O_RDWR|O_CREAT,							 DENY_NONE);			if (fnum[server][conn][f] == -1) {				printf("failed to reopen on share%d\n", server);				return False;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -