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;
32 #define FILENAME "locktest.dat"
39 /* each server has two connections open to it. Each connection has two file
40 descriptors open on the file - 8 file descriptors in total
42 we then do random locking ops in tamdem on the 4 fnums from each
43 server and ensure that the results match
45 static void test_locks(struct cli_state *cli[2][2])
50 cli_unlink(cli[0][0], FILENAME);
51 cli_unlink(cli[1][0], FILENAME);
53 for (server=0;server<2;server++)
54 for (conn=0;conn<2;conn++)
56 fnum[server][conn][f] = cli_open(cli[server][conn], FILENAME,
59 if (fnum[server][conn][f] == -1) {
60 fprintf(stderr,"Failed to open fnum[%d][%d][%d]\n",
67 int start, len, op, r;
72 start = random() % (LOCKRANGE-1);
73 len = 1 + random() % (LOCKRANGE-start);
87 ret1 = cli_lock(cli[0][conn],
90 ret2 = cli_lock(cli[1][conn],
94 printf("lock(%d): server1 gave %d server2 gave %d\n",
95 numops, (int)ret1, (int)ret2);
98 } else if (r < LOCK_PCT+UNLOCK_PCT) {
101 ret1 = cli_unlock(cli[0][conn],
104 ret2 = cli_unlock(cli[1][conn],
108 printf("unlock(%d): server1 gave %d server2 gave %d\n",
109 numops, (int)ret1, (int)ret2);
113 /* reopen the file */
114 cli_close(cli[0][conn], fnum[0][conn][f]);
115 cli_close(cli[1][conn], fnum[1][conn][f]);
116 fnum[0][conn][f] = cli_open(cli[0][conn], FILENAME,
119 fnum[1][conn][f] = cli_open(cli[1][conn], FILENAME,
122 if (fnum[0][conn][f] == -1) {
123 printf("failed to reopen on share1\n");
126 if (fnum[1][conn][f] == -1) {
127 printf("failed to reopen on share2\n");
131 if (numops % 100 == 0) {
132 printf("%d\n", numops);
138 /*****************************************************
139 return a connection to a server
140 *******************************************************/
141 struct cli_state *connect_one(char *share)
144 struct nmb_name called, calling;
148 extern struct in_addr ipzero;
150 fstrcpy(server,share+2);
151 share = strchr(server,'\\');
152 if (!share) return NULL;
160 make_nmb_name(&calling, "locktest", 0x0);
161 make_nmb_name(&called , server, 0x20);
166 /* have to open a new connection */
167 if (!(c=cli_initialise(NULL)) || (cli_set_port(c, 139) == 0) ||
168 !cli_connect(c, server_n, &ip)) {
169 DEBUG(0,("Connection to %s failed\n", server_n));
173 if (!cli_session_request(c, &calling, &called)) {
174 DEBUG(0,("session request to %s failed\n", called.name));
176 if (strcmp(called.name, "*SMBSERVER")) {
177 make_nmb_name(&called , "*SMBSERVER", 0x20);
183 DEBUG(4,(" session request ok\n"));
185 if (!cli_negprot(c)) {
186 DEBUG(0,("protocol negotiation failed\n"));
192 char *pass = getpass("Password: ");
194 pstrcpy(password, pass);
198 if (!cli_session_setup(c, username,
199 password, strlen(password),
200 password, strlen(password),
202 DEBUG(0,("session setup failed: %s\n", cli_errstr(c)));
207 * These next two lines are needed to emulate
208 * old client behaviour for people who have
209 * scripts based on client output.
210 * QUESTION ? Do we want to have a 'client compatibility
211 * mode to turn these on/off ? JRA.
214 if (*c->server_domain || *c->server_os || *c->server_type)
215 DEBUG(1,("Domain=[%s] OS=[%s] Server=[%s]\n",
216 c->server_domain,c->server_os,c->server_type));
218 DEBUG(4,(" session setup ok\n"));
220 if (!cli_send_tconX(c, share, "?????",
221 password, strlen(password)+1)) {
222 DEBUG(0,("tree connect failed: %s\n", cli_errstr(c)));
227 DEBUG(4,(" tconx ok\n"));
233 static void usage(void)
237 locktest //server1/share1 //server2/share2 [options..]\n\
244 /****************************************************************************
246 ****************************************************************************/
247 int main(int argc,char *argv[])
249 char *share1, *share2;
250 struct cli_state *cli[2][2];
257 static pstring servicesf = CONFIGFILE;
263 if (argv[1][0] == '-' || argc < 3) {
271 all_string_sub(share1,"/","\\",0);
272 all_string_sub(share2,"/","\\",0);
274 setup_logging(argv[0],True);
280 charset_initialise();
282 lp_load(servicesf,True,False,False);
285 if (getenv("USER")) {
286 pstrcpy(username,getenv("USER"));
291 while ((opt = getopt(argc, argv, "U:s:ho:")) != EOF) {
294 pstrcpy(username,optarg);
295 p = strchr(username,'%');
298 pstrcpy(password, p+1);
306 numops = atoi(optarg);
312 printf("Unknown option %c (%d)\n", (char)opt, opt);
320 DEBUG(0,("seed=%d\n", seed));
323 cli[0][0] = connect_one(share1);
324 cli[0][1] = connect_one(share1);
325 if (!cli[0][0] || !cli[0][1]) {
326 DEBUG(0,("Failed to connect to %s\n", share1));
330 cli[1][0] = connect_one(share2);
331 cli[1][1] = connect_one(share2);
332 if (!cli[1][0] || !cli[1][1]) {
333 DEBUG(0,("Failed to connect to %s\n", share2));