710aa8007a9adac84488bc1eef6370ea3ba844f0
[gd/samba-autobuild/.git] / source4 / torture / locktest.c
1 /* 
2    Unix SMB/CIFS implementation.
3    randomised byte range lock tester
4    Copyright (C) Andrew Tridgell 1999
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "includes.h"
21 #include "lib/cmdline/popt_common.h"
22 #include "lib/events/events.h"
23 #include "system/filesys.h"
24 #include "system/time.h"
25 #include "auth/credentials/credentials.h"
26 #include "auth/gensec/gensec.h"
27 #include "libcli/libcli.h"
28 #include "param/param.h"
29 #include "dynconfig/dynconfig.h"
30 #include "libcli/resolve/resolve.h"
31
32 static int numops = 1000;
33 static int showall;
34 static int analyze;
35 static int hide_unlock_fails;
36 static int use_oplocks;
37 static uint_t lock_range = 100;
38 static uint_t lock_base = 0;
39 static uint_t min_length = 0;
40 static int exact_error_codes;
41 static int zero_zero;
42
43 #define FILENAME "\\locktest.dat"
44
45 #define READ_PCT 50
46 #define LOCK_PCT 45
47 #define UNLOCK_PCT 70
48 #define RANGE_MULTIPLE 1
49 #define NSERVERS 2
50 #define NCONNECTIONS 2
51 #define NFILES 2
52 #define LOCK_TIMEOUT 0
53
54 static struct cli_credentials *servers[NSERVERS];
55
56 enum lock_op {OP_LOCK, OP_UNLOCK, OP_REOPEN};
57
58 struct record {
59         enum lock_op lock_op;
60         enum brl_type lock_type;
61         char conn, f;
62         uint64_t start, len;
63         char needed;
64         uint16_t pid;
65 };
66
67 #define PRESETS 0
68
69 #if PRESETS
70 static struct record preset[] = {
71 {OP_LOCK, WRITE_LOCK, 0, 0, 2, 0, 1},
72 {OP_LOCK, WRITE_LOCK, 0, 0, 0, 0, 1},
73 {OP_LOCK, WRITE_LOCK, 0, 0, 3, 0, 1},
74 {OP_UNLOCK, 0       , 0, 0, 2, 0, 1},
75 {OP_REOPEN, 0, 0, 0, 0, 0, 1},
76
77 {OP_LOCK, READ_LOCK, 0, 0, 2, 0, 1},
78 {OP_LOCK, READ_LOCK, 0, 0, 1, 1, 1},
79 {OP_LOCK, WRITE_LOCK, 0, 0, 0, 0, 1},
80 {OP_REOPEN, 0, 0, 0, 0, 0, 1},
81
82 {OP_LOCK, READ_LOCK, 0, 0, 2, 0, 1},
83 {OP_LOCK, WRITE_LOCK, 0, 0, 3, 1, 1},
84 {OP_LOCK, WRITE_LOCK, 0, 0, 0, 0, 1},
85 {OP_REOPEN, 0, 0, 0, 0, 0, 1},
86
87 {OP_LOCK, READ_LOCK, 0, 0, 2, 0, 1},
88 {OP_LOCK, WRITE_LOCK, 0, 0, 1, 1, 1},
89 {OP_LOCK, WRITE_LOCK, 0, 0, 0, 0, 1},
90 {OP_REOPEN, 0, 0, 0, 0, 0, 1},
91
92 {OP_LOCK, WRITE_LOCK, 0, 0, 2, 0, 1},
93 {OP_LOCK, READ_LOCK, 0, 0, 1, 1, 1},
94 {OP_LOCK, WRITE_LOCK, 0, 0, 0, 0, 1},
95 {OP_REOPEN, 0, 0, 0, 0, 0, 1},
96
97 {OP_LOCK, WRITE_LOCK, 0, 0, 2, 0, 1},
98 {OP_LOCK, READ_LOCK, 0, 0, 3, 1, 1},
99 {OP_LOCK, WRITE_LOCK, 0, 0, 0, 0, 1},
100 {OP_REOPEN, 0, 0, 0, 0, 0, 1},
101
102 };
103 #endif
104
105 static struct record *recorded;
106
107 /***************************************************** 
108 return a connection to a server
109 *******************************************************/
110 static struct smbcli_state *connect_one(struct event_context *ev,
111                                         struct loadparm_context *lp_ctx,
112                                         TALLOC_CTX *mem_ctx,
113                                         char *share, int snum, int conn)
114 {
115         struct smbcli_state *c;
116         char *server, *myname;
117         NTSTATUS status;
118         int retries = 10;
119         struct smbcli_options options;
120         struct smbcli_session_options session_options;
121
122         lp_smbcli_options(lp_ctx, &options);
123         lp_smbcli_session_options(lp_ctx, &session_options);
124
125         printf("connect_one(%s, %d, %d)\n", share, snum, conn);
126
127         server = talloc_strdup(mem_ctx, share+2);
128         share = strchr_m(server,'\\');
129         if (!share) return NULL;
130         *share = 0;
131         share++;
132
133         if (snum == 0) {
134                 char **unc_list = NULL;
135                 int num_unc_names;
136                 const char *p;
137                 p = lp_parm_string(lp_ctx, NULL, "torture", "unclist");
138                 if (p) {
139                         char *h, *s;
140                         unc_list = file_lines_load(p, &num_unc_names, 0, NULL);
141                         if (!unc_list || num_unc_names <= 0) {
142                                 printf("Failed to load unc names list from '%s'\n", p);
143                                 exit(1);
144                         }
145
146                         if (!smbcli_parse_unc(unc_list[conn % num_unc_names],
147                                               NULL, &h, &s)) {
148                                 printf("Failed to parse UNC name %s\n",
149                                        unc_list[conn % num_unc_names]);
150                                 exit(1);
151                         }
152                         server = talloc_strdup(mem_ctx, h);
153                         share = talloc_strdup(mem_ctx, s);
154                 }
155         }
156
157
158         myname = talloc_asprintf(mem_ctx, "lock-%u-%u", getpid(), snum);
159         cli_credentials_set_workstation(servers[snum], myname, CRED_SPECIFIED);
160
161         do {
162                 printf("\\\\%s\\%s\n", server, share);
163                 status = smbcli_full_connection(NULL, &c, 
164                                                 server, 
165                                                 lp_smb_ports(lp_ctx),
166                                                 share, NULL,
167                                                 servers[snum], 
168                                                 lp_resolve_context(lp_ctx),
169                                                 ev, &options, &session_options);
170                 if (!NT_STATUS_IS_OK(status)) {
171                         sleep(2);
172                 }
173         } while (!NT_STATUS_IS_OK(status) && retries--);
174
175         if (!NT_STATUS_IS_OK(status)) {
176                 return NULL;
177         }
178
179         return c;
180 }
181
182
183 static void reconnect(struct event_context *ev,
184                       struct loadparm_context *lp_ctx,
185                           TALLOC_CTX *mem_ctx,
186                       struct smbcli_state *cli[NSERVERS][NCONNECTIONS], int fnum[NSERVERS][NCONNECTIONS][NFILES],
187                       char *share[NSERVERS])
188 {
189         int server, conn, f;
190
191         for (server=0;server<NSERVERS;server++)
192         for (conn=0;conn<NCONNECTIONS;conn++) {
193                 if (cli[server][conn]) {
194                         for (f=0;f<NFILES;f++) {
195                                 if (fnum[server][conn][f] != -1) {
196                                         smbcli_close(cli[server][conn]->tree, fnum[server][conn][f]);
197                                         fnum[server][conn][f] = -1;
198                                 }
199                         }
200                         talloc_free(cli[server][conn]);
201                 }
202                 cli[server][conn] = connect_one(ev, lp_ctx, mem_ctx, share[server], 
203                                                 server, conn);
204                 if (!cli[server][conn]) {
205                         DEBUG(0,("Failed to connect to %s\n", share[server]));
206                         exit(1);
207                 }
208         }
209 }
210
211
212
213 static bool test_one(struct smbcli_state *cli[NSERVERS][NCONNECTIONS], 
214                      int fnum[NSERVERS][NCONNECTIONS][NFILES],
215                      struct record *rec)
216 {
217         uint_t conn = rec->conn;
218         uint_t f = rec->f;
219         uint64_t start = rec->start;
220         uint64_t len = rec->len;
221         enum brl_type op = rec->lock_type;
222         int server;
223         bool ret[NSERVERS];
224         NTSTATUS status[NSERVERS];
225
226         switch (rec->lock_op) {
227         case OP_LOCK:
228                 /* set a lock */
229                 for (server=0;server<NSERVERS;server++) {
230                         NTSTATUS res;
231                         struct smbcli_tree *tree=cli[server][conn]->tree;
232                         int fn=fnum[server][conn][f];
233
234                         if (!(tree->session->transport->negotiate.capabilities & CAP_LARGE_FILES)) {
235                                 res=smbcli_lock(tree, fn, start, len, LOCK_TIMEOUT, rec->lock_op);
236                         } else {
237                                 union smb_lock parms;
238                                 int ltype;
239                                 struct smb_lock_entry lock[1];
240
241                                 parms.lockx.level = RAW_LOCK_LOCKX;
242                                 parms.lockx.in.file.fnum = fn;
243         
244                                 ltype = (rec->lock_op == READ_LOCK? 1 : 0);
245                                 ltype |= LOCKING_ANDX_LARGE_FILES;
246                                 parms.lockx.in.mode = ltype;
247                                 parms.lockx.in.timeout = LOCK_TIMEOUT;
248                                 parms.lockx.in.ulock_cnt = 0;
249                                 parms.lockx.in.lock_cnt = 1;
250                                 lock[0].pid = rec->pid;
251                                 lock[0].offset = start;
252                                 lock[0].count = len;
253                                 parms.lockx.in.locks = &lock[0];
254
255                                 res = smb_raw_lock(tree, &parms);
256                         }
257
258                         ret[server] = NT_STATUS_IS_OK(res); 
259                         status[server] = smbcli_nt_error(cli[server][conn]->tree);
260                         if (!exact_error_codes && 
261                             NT_STATUS_EQUAL(status[server], 
262                                             NT_STATUS_FILE_LOCK_CONFLICT)) {
263                                 status[server] = NT_STATUS_LOCK_NOT_GRANTED;
264                         }
265                 }
266                 if (showall || !NT_STATUS_EQUAL(status[0],status[1])) {
267                         printf("lock   conn=%u f=%u range=%.0f(%.0f) op=%s -> %s:%s\n",
268                                conn, f, 
269                                (double)start, (double)len,
270                                op==READ_LOCK?"READ_LOCK":"WRITE_LOCK",
271                                nt_errstr(status[0]), nt_errstr(status[1]));
272                 }
273                 if (!NT_STATUS_EQUAL(status[0],status[1])) return false;
274                 break;
275                 
276         case OP_UNLOCK:
277                 /* unset a lock */
278                 for (server=0;server<NSERVERS;server++) {
279                         NTSTATUS res;
280                         struct smbcli_tree *tree=cli[server][conn]->tree;
281                         int fn=fnum[server][conn][f];
282
283
284                         if (!(tree->session->transport->negotiate.capabilities & CAP_LARGE_FILES)) {
285                                 res=smbcli_unlock(tree, fn, start, len);
286                         } else {
287                                 union smb_lock parms;
288                                 struct smb_lock_entry lock[1];
289
290                                 parms.lockx.level = RAW_LOCK_LOCKX;
291                                 parms.lockx.in.file.fnum = fn;
292                                 parms.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
293                                 parms.lockx.in.timeout = 0;
294                                 parms.lockx.in.ulock_cnt = 1;
295                                 parms.lockx.in.lock_cnt = 0;
296                                 lock[0].pid = rec->pid;
297                                 lock[0].count = len;
298                                 lock[0].offset = start;
299                                 parms.lockx.in.locks = &lock[0];
300
301                                 res = smb_raw_lock(tree, &parms);
302                         }
303
304                         ret[server] = NT_STATUS_IS_OK(res);
305                         status[server] = smbcli_nt_error(cli[server][conn]->tree);
306                 }
307                 if (showall || 
308                     (!hide_unlock_fails && !NT_STATUS_EQUAL(status[0],status[1]))) {
309                         printf("unlock conn=%u f=%u range=%.0f(%.0f)       -> %s:%s\n",
310                                conn, f, 
311                                (double)start, (double)len,
312                                nt_errstr(status[0]), nt_errstr(status[1]));
313                 }
314                 if (!hide_unlock_fails && !NT_STATUS_EQUAL(status[0],status[1])) 
315                         return false;
316                 break;
317
318         case OP_REOPEN:
319                 /* reopen the file */
320                 for (server=0;server<NSERVERS;server++) {
321                         smbcli_close(cli[server][conn]->tree, fnum[server][conn][f]);
322                         fnum[server][conn][f] = -1;
323                 }
324                 for (server=0;server<NSERVERS;server++) {
325                         fnum[server][conn][f] = smbcli_open(cli[server][conn]->tree, FILENAME,
326                                                          O_RDWR|O_CREAT,
327                                                          DENY_NONE);
328                         if (fnum[server][conn][f] == -1) {
329                                 printf("failed to reopen on share%d\n", server);
330                                 return false;
331                         }
332                 }
333                 if (showall) {
334                         printf("reopen conn=%u f=%u\n",
335                                conn, f);
336                 }
337                 break;
338         }
339
340         return true;
341 }
342
343 static void close_files(struct smbcli_state *cli[NSERVERS][NCONNECTIONS], 
344                         int fnum[NSERVERS][NCONNECTIONS][NFILES])
345 {
346         int server, conn, f; 
347
348         for (server=0;server<NSERVERS;server++)
349         for (conn=0;conn<NCONNECTIONS;conn++)
350         for (f=0;f<NFILES;f++) {
351                 if (fnum[server][conn][f] != -1) {
352                         smbcli_close(cli[server][conn]->tree, fnum[server][conn][f]);
353                         fnum[server][conn][f] = -1;
354                 }
355         }
356         for (server=0;server<NSERVERS;server++) {
357                 smbcli_unlink(cli[server][0]->tree, FILENAME);
358         }
359 }
360
361 static void open_files(struct smbcli_state *cli[NSERVERS][NCONNECTIONS], 
362                        int fnum[NSERVERS][NCONNECTIONS][NFILES])
363 {
364         int server, conn, f; 
365
366         for (server=0;server<NSERVERS;server++)
367         for (conn=0;conn<NCONNECTIONS;conn++)
368         for (f=0;f<NFILES;f++) {
369                 fnum[server][conn][f] = smbcli_open(cli[server][conn]->tree, FILENAME,
370                                                  O_RDWR|O_CREAT,
371                                                  DENY_NONE);
372                 if (fnum[server][conn][f] == -1) {
373                         fprintf(stderr,"Failed to open fnum[%u][%u][%u]\n",
374                                 server, conn, f);
375                         exit(1);
376                 }
377         }
378 }
379
380
381 static int retest(struct smbcli_state *cli[NSERVERS][NCONNECTIONS], 
382                    int fnum[NSERVERS][NCONNECTIONS][NFILES],
383                    int n)
384 {
385         int i;
386         printf("testing %u ...\n", n);
387         for (i=0; i<n; i++) {
388                 if (i && i % 100 == 0) {
389                         printf("%u\n", i);
390                 }
391
392                 if (recorded[i].needed &&
393                     !test_one(cli, fnum, &recorded[i])) return i;
394         }
395         return n;
396 }
397
398
399 /* each server has two connections open to it. Each connection has two file
400    descriptors open on the file - 8 file descriptors in total 
401
402    we then do random locking ops in tamdem on the 4 fnums from each
403    server and ensure that the results match
404  */
405 static int test_locks(struct event_context *ev,
406                       struct loadparm_context *lp_ctx,
407                           TALLOC_CTX *mem_ctx,
408                       char *share[NSERVERS])
409 {
410         struct smbcli_state *cli[NSERVERS][NCONNECTIONS];
411         int fnum[NSERVERS][NCONNECTIONS][NFILES];
412         int n, i, n1, skip, r1, r2; 
413
414         ZERO_STRUCT(fnum);
415         ZERO_STRUCT(cli);
416
417         recorded = malloc_array_p(struct record, numops);
418
419         for (n=0; n<numops; n++) {
420 #if PRESETS
421                 if (n < sizeof(preset) / sizeof(preset[0])) {
422                         recorded[n] = preset[n];
423                 } else {
424 #endif
425                         recorded[n].conn = random() % NCONNECTIONS;
426                         recorded[n].f = random() % NFILES;
427                         recorded[n].start = lock_base + ((uint_t)random() % (lock_range-1));
428                         recorded[n].len =  min_length +
429                                 random() % (lock_range-(recorded[n].start-lock_base));
430                         recorded[n].start *= RANGE_MULTIPLE;
431                         recorded[n].len *= RANGE_MULTIPLE;
432                         recorded[n].pid = random()%3;
433                         if (recorded[n].pid == 2) {
434                                 recorded[n].pid = 0xFFFF; /* see if its magic */
435                         }
436                         r1 = random() % 100;
437                         r2 = random() % 100;
438                         if (r1 < READ_PCT) {
439                                 recorded[n].lock_type = READ_LOCK;
440                         } else {
441                                 recorded[n].lock_type = WRITE_LOCK;
442                         }
443                         if (r2 < LOCK_PCT) {
444                                 recorded[n].lock_op = OP_LOCK;
445                         } else if (r2 < UNLOCK_PCT) {
446                                 recorded[n].lock_op = OP_UNLOCK;
447                         } else {
448                                 recorded[n].lock_op = OP_REOPEN;
449                         }
450                         recorded[n].needed = true;
451                         if (!zero_zero && recorded[n].start==0 && recorded[n].len==0) {
452                                 recorded[n].len = 1;
453                         }
454 #if PRESETS
455                 }
456 #endif
457         }
458
459         reconnect(ev, lp_ctx, mem_ctx, cli, fnum, share);
460         open_files(cli, fnum);
461         n = retest(cli, fnum, numops);
462
463         if (n == numops || !analyze) {
464                 if (n != numops) {
465                         return 1;
466                 }
467                 return 0;
468         }
469         n++;
470
471         skip = n/2;
472
473         while (1) {
474                 n1 = n;
475
476                 close_files(cli, fnum);
477                 reconnect(ev, lp_ctx, mem_ctx, cli, fnum, share);
478                 open_files(cli, fnum);
479
480                 for (i=0;i<n-skip;i+=skip) {
481                         int m, j;
482                         printf("excluding %d-%d\n", i, i+skip-1);
483                         for (j=i;j<i+skip;j++) {
484                                 recorded[j].needed = false;
485                         }
486
487                         close_files(cli, fnum);
488                         open_files(cli, fnum);
489
490                         m = retest(cli, fnum, n);
491                         if (m == n) {
492                                 for (j=i;j<i+skip;j++) {
493                                         recorded[j].needed = true;
494                                 }
495                         } else {
496                                 if (i+(skip-1) < m) {
497                                         memmove(&recorded[i], &recorded[i+skip],
498                                                 (m-(i+skip-1))*sizeof(recorded[0]));
499                                 }
500                                 n = m-(skip-1);
501                                 i--;
502                         }
503                 }
504
505                 if (skip > 1) {
506                         skip = skip/2;
507                         printf("skip=%d\n", skip);
508                         continue;
509                 }
510
511                 if (n1 == n) break;
512         }
513
514         close_files(cli, fnum);
515         reconnect(ev, lp_ctx, mem_ctx, cli, fnum, share);
516         open_files(cli, fnum);
517         showall = true;
518         n1 = retest(cli, fnum, n);
519         if (n1 != n-1) {
520                 printf("ERROR - inconsistent result (%u %u)\n", n1, n);
521         }
522         close_files(cli, fnum);
523
524         for (i=0;i<n;i++) {
525                 printf("{%d, %d, %u, %u, %.0f, %.0f, %u},\n",
526                        recorded[i].lock_op,
527                        recorded[i].lock_type,
528                        recorded[i].conn,
529                        recorded[i].f,
530                        (double)recorded[i].start,
531                        (double)recorded[i].len,
532                        recorded[i].needed);
533         }       
534
535         return 1;
536 }
537
538
539
540 static void usage(poptContext pc)
541 {
542         printf("Usage:\n\tlocktest //server1/share1 //server2/share2 [options..]\n");
543         poptPrintUsage(pc, stdout, 0);
544 }
545
546 /****************************************************************************
547   main program
548 ****************************************************************************/
549  int main(int argc,char *argv[])
550 {
551         char *share[NSERVERS];
552         int opt;
553         int seed, server;
554         int username_count=0;
555         struct event_context *ev;
556         struct loadparm_context *lp_ctx;
557         poptContext pc;
558         int argc_new, i;
559         char **argv_new;
560         enum {OPT_UNCLIST=1000};
561         struct poptOption long_options[] = {
562                 POPT_AUTOHELP
563                 {"seed",          0, POPT_ARG_INT,  &seed,      0,      "Seed to use for randomizer",   NULL},
564                 {"num-ops",       0, POPT_ARG_INT,  &numops,    0,      "num ops",      NULL},
565                 {"lockrange",     0, POPT_ARG_INT,  &lock_range,0,      "locking range", NULL},
566                 {"lockbase",      0, POPT_ARG_INT,  &lock_base, 0,      "locking base", NULL},
567                 {"minlength",     0, POPT_ARG_INT,  &min_length,0,      "min lock length", NULL},
568                 {"hidefails",     0, POPT_ARG_NONE, &hide_unlock_fails,0,"hide unlock fails", NULL},
569                 {"oplocks",       0, POPT_ARG_NONE, &use_oplocks,0,      "use oplocks", NULL},
570                 {"showall",       0, POPT_ARG_NONE, &showall,    0,      "display all operations", NULL},
571                 {"analyse",       0, POPT_ARG_NONE, &analyze,    0,      "do backtrack analysis", NULL},
572                 {"zerozero",      0, POPT_ARG_NONE, &zero_zero,    0,      "do zero/zero lock", NULL},
573                 {"exacterrors",   0, POPT_ARG_NONE, &exact_error_codes,0,"use exact error codes", NULL},
574                 {"unclist",       0, POPT_ARG_STRING,   NULL,   OPT_UNCLIST,    "unclist",      NULL},
575                 { "user", 'U',       POPT_ARG_STRING, NULL, 'U', "Set the network username", "[DOMAIN/]USERNAME[%PASSWORD]" },
576                 POPT_COMMON_SAMBA
577                 POPT_COMMON_CONNECTION
578                 POPT_COMMON_CREDENTIALS
579                 POPT_COMMON_VERSION
580                 { NULL }
581         };
582
583         setlinebuf(stdout);
584         seed = time(NULL);
585
586         pc = poptGetContext("locktest", argc, (const char **) argv, long_options, 
587                             POPT_CONTEXT_KEEP_FIRST);
588
589         poptSetOtherOptionHelp(pc, "<unc1> <unc2>");
590
591         lp_ctx = cmdline_lp_ctx;
592         servers[0] = cli_credentials_init(talloc_autofree_context());
593         servers[1] = cli_credentials_init(talloc_autofree_context());
594         cli_credentials_guess(servers[0], lp_ctx);
595         cli_credentials_guess(servers[1], lp_ctx);
596
597         while((opt = poptGetNextOpt(pc)) != -1) {
598                 switch (opt) {
599                 case OPT_UNCLIST:
600                         lp_set_cmdline(cmdline_lp_ctx, "torture:unclist", poptGetOptArg(pc));
601                         break;
602                 case 'U':
603                         if (username_count == 2) {
604                                 usage(pc);
605                                 exit(1);
606                         }
607                         cli_credentials_parse_string(servers[username_count], poptGetOptArg(pc), CRED_SPECIFIED);
608                         username_count++;
609                         break;
610                 }
611         }
612
613         argv_new = discard_const_p(char *, poptGetArgs(pc));
614         argc_new = argc;
615         for (i=0; i<argc; i++) {
616                 if (argv_new[i] == NULL) {
617                         argc_new = i;
618                         break;
619                 }
620         }
621
622         if (!(argc_new >= 3)) {
623                 usage(pc);
624                 exit(1);
625         }
626
627         setup_logging("locktest", DEBUG_STDOUT);
628
629         for (server=0;server<NSERVERS;server++) {
630                 share[server] = argv_new[1+server];
631                 all_string_sub(share[server],"/","\\",0);
632         }
633
634         lp_ctx = cmdline_lp_ctx;
635
636         if (username_count == 0) {
637                 usage(pc);
638                 return -1;
639         }
640         if (username_count == 1) {
641                 servers[1] = servers[0];
642         }
643
644         ev = s4_event_context_init(talloc_autofree_context());
645
646         gensec_init(lp_ctx);
647
648         DEBUG(0,("seed=%u base=%d range=%d min_length=%d\n", 
649                  seed, lock_base, lock_range, min_length));
650         srandom(seed);
651
652         return test_locks(ev, lp_ctx, NULL, share);
653 }
654