2 Unix SMB/Netbios implementation.
5 Copyright (C) Andrew Tridgell 1999
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 static fstring password;
27 static fstring username;
28 static fstring workgroup;
30 static int numops = 1000;
33 #define FILENAME "locktest.dat"
40 /* each server has two connections open to it. Each connection has two file
41 descriptors open on the file - 8 file descriptors in total
43 we then do random locking ops in tamdem on the 4 fnums from each
44 server and ensure that the results match
46 static void test_locks(struct cli_state *cli[2][2])
49 int server, conn, f, n;
51 cli_unlink(cli[0][0], FILENAME);
52 cli_unlink(cli[1][0], FILENAME);
54 for (server=0;server<2;server++)
55 for (conn=0;conn<2;conn++)
57 fnum[server][conn][f] = cli_open(cli[server][conn], FILENAME,
60 if (fnum[server][conn][f] == -1) {
61 fprintf(stderr,"Failed to open fnum[%d][%d][%d]\n",
67 for (n=0; n<numops; n++) {
68 int start, len, op, r;
73 start = random() % (LOCKRANGE-1);
74 len = 1 + random() % (LOCKRANGE-start);
88 ret1 = cli_lock(cli[0][conn],
91 ret2 = cli_lock(cli[1][conn],
94 if (showall || ret1 != ret2) {
95 printf("%5d lock conn=%d f=%d %d:%d op=%s -> %d:%d\n",
96 n, conn, f, start, len, op==READ_LOCK?"READ_LOCK":"WRITE_LOCK",
99 if (ret1 != ret2) return;
100 } else if (r < LOCK_PCT+UNLOCK_PCT) {
103 ret1 = cli_unlock(cli[0][conn],
106 ret2 = cli_unlock(cli[1][conn],
109 if (showall || ret1 != ret2) {
110 printf("%5d unlock conn=%d f=%d %d:%d -> %d:%d\n",
111 n, conn, f, start, len,
115 /* reopen the file */
116 cli_close(cli[0][conn], fnum[0][conn][f]);
117 cli_close(cli[1][conn], fnum[1][conn][f]);
118 fnum[0][conn][f] = cli_open(cli[0][conn], FILENAME,
121 fnum[1][conn][f] = cli_open(cli[1][conn], FILENAME,
124 if (fnum[0][conn][f] == -1) {
125 printf("failed to reopen on share1\n");
128 if (fnum[1][conn][f] == -1) {
129 printf("failed to reopen on share2\n");
133 printf("%5d reopen conn=%d f=%d\n",
136 if (ret1 != ret2) return;
145 /*****************************************************
146 return a connection to a server
147 *******************************************************/
148 struct cli_state *connect_one(char *share)
151 struct nmb_name called, calling;
155 extern struct in_addr ipzero;
157 fstrcpy(server,share+2);
158 share = strchr(server,'\\');
159 if (!share) return NULL;
167 make_nmb_name(&calling, "locktest", 0x0);
168 make_nmb_name(&called , server, 0x20);
173 /* have to open a new connection */
174 if (!(c=cli_initialise(NULL)) || (cli_set_port(c, 139) == 0) ||
175 !cli_connect(c, server_n, &ip)) {
176 DEBUG(0,("Connection to %s failed\n", server_n));
180 if (!cli_session_request(c, &calling, &called)) {
181 DEBUG(0,("session request to %s failed\n", called.name));
183 if (strcmp(called.name, "*SMBSERVER")) {
184 make_nmb_name(&called , "*SMBSERVER", 0x20);
190 DEBUG(4,(" session request ok\n"));
192 if (!cli_negprot(c)) {
193 DEBUG(0,("protocol negotiation failed\n"));
199 char *pass = getpass("Password: ");
201 pstrcpy(password, pass);
205 if (!cli_session_setup(c, username,
206 password, strlen(password),
207 password, strlen(password),
209 DEBUG(0,("session setup failed: %s\n", cli_errstr(c)));
214 * These next two lines are needed to emulate
215 * old client behaviour for people who have
216 * scripts based on client output.
217 * QUESTION ? Do we want to have a 'client compatibility
218 * mode to turn these on/off ? JRA.
221 if (*c->server_domain || *c->server_os || *c->server_type)
222 DEBUG(1,("Domain=[%s] OS=[%s] Server=[%s]\n",
223 c->server_domain,c->server_os,c->server_type));
225 DEBUG(4,(" session setup ok\n"));
227 if (!cli_send_tconX(c, share, "?????",
228 password, strlen(password)+1)) {
229 DEBUG(0,("tree connect failed: %s\n", cli_errstr(c)));
234 DEBUG(4,(" tconx ok\n"));
240 static void usage(void)
244 locktest //server1/share1 //server2/share2 [options..]\n\
253 /****************************************************************************
255 ****************************************************************************/
256 int main(int argc,char *argv[])
258 char *share1, *share2;
259 struct cli_state *cli[2][2];
266 static pstring servicesf = CONFIGFILE;
272 if (argv[1][0] == '-' || argc < 3) {
280 all_string_sub(share1,"/","\\",0);
281 all_string_sub(share2,"/","\\",0);
283 setup_logging(argv[0],True);
289 charset_initialise();
291 lp_load(servicesf,True,False,False);
294 if (getenv("USER")) {
295 pstrcpy(username,getenv("USER"));
300 while ((opt = getopt(argc, argv, "U:s:ho:a")) != EOF) {
303 pstrcpy(username,optarg);
304 p = strchr(username,'%');
307 pstrcpy(password, p+1);
315 numops = atoi(optarg);
324 printf("Unknown option %c (%d)\n", (char)opt, opt);
332 DEBUG(0,("seed=%d\n", seed));
335 cli[0][0] = connect_one(share1);
336 cli[0][1] = connect_one(share1);
337 if (!cli[0][0] || !cli[0][1]) {
338 DEBUG(0,("Failed to connect to %s\n", share1));
342 cli[1][0] = connect_one(share2);
343 cli[1][1] = connect_one(share2);
344 if (!cli[1][0] || !cli[1][1]) {
345 DEBUG(0,("Failed to connect to %s\n", share2));