4627164bef89dca607d24f52c511a2edafa1abb2
[ira/wip.git] / source / torture / torture.c
1 /* 
2    Unix SMB/CIFS implementation.
3    SMB torture tester
4    Copyright (C) Andrew Tridgell 1997-2003
5    Copyright (C) Jelmer Vernooij 2006
6    
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.
11    
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.
16    
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.
20 */
21
22 #include "includes.h"
23 #include "lib/cmdline/popt_common.h"
24 #include "libcli/raw/libcliraw.h"
25 #include "system/time.h"
26 #include "system/wait.h"
27 #include "system/filesys.h"
28 #include "libcli/raw/ioctl.h"
29 #include "libcli/libcli.h"
30 #include "lib/ldb/include/ldb.h"
31 #include "lib/events/events.h"
32 #include "libcli/resolve/resolve.h"
33 #include "auth/credentials/credentials.h"
34 #include "libcli/ldap/ldap_client.h"
35 #include "librpc/gen_ndr/ndr_nbt.h"
36
37 #include "torture/raw/proto.h"
38 #include "torture/smb2/proto.h"
39 #include "torture/rap/proto.h"
40 #include "torture/auth/proto.h"
41 #include "torture/local/proto.h"
42 #include "torture/nbench/proto.h"
43 #include "torture/ldap/proto.h"
44 #include "torture/com/proto.h"
45 #include "torture/nbt/proto.h"
46 #include "torture/libnet/proto.h"
47 #include "torture/torture.h"
48 #include "torture/util.h"
49 #include "build.h"
50 #include "dlinklist.h"
51
52 _PUBLIC_ int torture_nprocs=4;
53 _PUBLIC_ int torture_numops=10;
54 _PUBLIC_ int torture_entries=1000;
55 _PUBLIC_ int torture_failures=1;
56 _PUBLIC_ int torture_seed=0;
57 _PUBLIC_ BOOL use_oplocks;
58 static int procnum; /* records process count number when forking */
59 static struct smbcli_state *current_cli;
60 _PUBLIC_ BOOL use_level_II_oplocks;
61 _PUBLIC_ BOOL torture_showall = False;
62
63
64 BOOL torture_open_connection_share(TALLOC_CTX *mem_ctx,
65                                    struct smbcli_state **c, 
66                                    const char *hostname, 
67                                    const char *sharename,
68                                    struct event_context *ev)
69 {
70         NTSTATUS status;
71
72         status = smbcli_full_connection(mem_ctx, c, hostname, 
73                                         sharename, NULL,
74                                         cmdline_credentials, ev);
75         if (!NT_STATUS_IS_OK(status)) {
76                 printf("Failed to open connection - %s\n", nt_errstr(status));
77                 return False;
78         }
79
80         (*c)->transport->options.use_oplocks = use_oplocks;
81         (*c)->transport->options.use_level2_oplocks = use_level_II_oplocks;
82
83         return True;
84 }
85
86 _PUBLIC_ BOOL torture_open_connection(struct smbcli_state **c)
87 {
88         const char *host = lp_parm_string(-1, "torture", "host");
89         const char *share = lp_parm_string(-1, "torture", "share");
90
91         return torture_open_connection_share(NULL, c, host, share, NULL);
92 }
93
94
95
96 _PUBLIC_ BOOL torture_close_connection(struct smbcli_state *c)
97 {
98         BOOL ret = True;
99         if (!c) return True;
100         if (NT_STATUS_IS_ERR(smbcli_tdis(c))) {
101                 printf("tdis failed (%s)\n", smbcli_errstr(c->tree));
102                 ret = False;
103         }
104         talloc_free(c);
105         return ret;
106 }
107
108
109 /* check if the server produced the expected error code */
110 _PUBLIC_ BOOL check_error(const char *location, struct smbcli_state *c, 
111                  uint8_t eclass, uint32_t ecode, NTSTATUS nterr)
112 {
113         NTSTATUS status;
114         
115         status = smbcli_nt_error(c->tree);
116         if (NT_STATUS_IS_DOS(status)) {
117                 int class, num;
118                 class = NT_STATUS_DOS_CLASS(status);
119                 num = NT_STATUS_DOS_CODE(status);
120                 if (eclass != class || ecode != num) {
121                         printf("unexpected error code %s\n", nt_errstr(status));
122                         printf(" expected %s or %s (at %s)\n", 
123                                nt_errstr(NT_STATUS_DOS(eclass, ecode)), 
124                                nt_errstr(nterr), location);
125                         return False;
126                 }
127         } else {
128                 if (!NT_STATUS_EQUAL(nterr, status)) {
129                         printf("unexpected error code %s\n", nt_errstr(status));
130                         printf(" expected %s (at %s)\n", nt_errstr(nterr), location);
131                         return False;
132                 }
133         }
134
135         return True;
136 }
137
138
139
140 static BOOL wait_lock(struct smbcli_state *c, int fnum, uint32_t offset, uint32_t len)
141 {
142         while (NT_STATUS_IS_ERR(smbcli_lock(c->tree, fnum, offset, len, -1, WRITE_LOCK))) {
143                 if (!check_error(__location__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
144         }
145         return True;
146 }
147
148
149 static BOOL rw_torture(struct smbcli_state *c)
150 {
151         const char *lockfname = "\\torture.lck";
152         char *fname;
153         int fnum;
154         int fnum2;
155         pid_t pid2, pid = getpid();
156         int i, j;
157         uint8_t buf[1024];
158         BOOL correct = True;
159
160         fnum2 = smbcli_open(c->tree, lockfname, O_RDWR | O_CREAT | O_EXCL, 
161                          DENY_NONE);
162         if (fnum2 == -1)
163                 fnum2 = smbcli_open(c->tree, lockfname, O_RDWR, DENY_NONE);
164         if (fnum2 == -1) {
165                 printf("open of %s failed (%s)\n", lockfname, smbcli_errstr(c->tree));
166                 return False;
167         }
168
169
170         for (i=0;i<torture_numops;i++) {
171                 uint_t n = (uint_t)random()%10;
172                 if (i % 10 == 0) {
173                         printf("%d\r", i); fflush(stdout);
174                 }
175                 asprintf(&fname, "\\torture.%u", n);
176
177                 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
178                         return False;
179                 }
180
181                 fnum = smbcli_open(c->tree, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
182                 if (fnum == -1) {
183                         printf("open failed (%s)\n", smbcli_errstr(c->tree));
184                         correct = False;
185                         break;
186                 }
187
188                 if (smbcli_write(c->tree, fnum, 0, &pid, 0, sizeof(pid)) != sizeof(pid)) {
189                         printf("write failed (%s)\n", smbcli_errstr(c->tree));
190                         correct = False;
191                 }
192
193                 for (j=0;j<50;j++) {
194                         if (smbcli_write(c->tree, fnum, 0, buf, 
195                                       sizeof(pid)+(j*sizeof(buf)), 
196                                       sizeof(buf)) != sizeof(buf)) {
197                                 printf("write failed (%s)\n", smbcli_errstr(c->tree));
198                                 correct = False;
199                         }
200                 }
201
202                 pid2 = 0;
203
204                 if (smbcli_read(c->tree, fnum, &pid2, 0, sizeof(pid)) != sizeof(pid)) {
205                         printf("read failed (%s)\n", smbcli_errstr(c->tree));
206                         correct = False;
207                 }
208
209                 if (pid2 != pid) {
210                         printf("data corruption!\n");
211                         correct = False;
212                 }
213
214                 if (NT_STATUS_IS_ERR(smbcli_close(c->tree, fnum))) {
215                         printf("close failed (%s)\n", smbcli_errstr(c->tree));
216                         correct = False;
217                 }
218
219                 if (NT_STATUS_IS_ERR(smbcli_unlink(c->tree, fname))) {
220                         printf("unlink failed (%s)\n", smbcli_errstr(c->tree));
221                         correct = False;
222                 }
223
224                 if (NT_STATUS_IS_ERR(smbcli_unlock(c->tree, fnum2, n*sizeof(int), sizeof(int)))) {
225                         printf("unlock failed (%s)\n", smbcli_errstr(c->tree));
226                         correct = False;
227                 }
228                 free(fname);
229         }
230
231         smbcli_close(c->tree, fnum2);
232         smbcli_unlink(c->tree, lockfname);
233
234         printf("%d\n", i);
235
236         return correct;
237 }
238
239 static BOOL run_torture(struct smbcli_state *cli, int dummy)
240 {
241         BOOL ret;
242
243         ret = rw_torture(cli);
244         
245         if (!torture_close_connection(cli)) {
246                 ret = False;
247         }
248
249         return ret;
250 }
251
252
253 /*
254   see how many RPC pipes we can open at once
255 */
256 static BOOL run_pipe_number(void)
257 {
258         struct smbcli_state *cli1;
259         const char *pipe_name = "\\WKSSVC";
260         int fnum;
261         int num_pipes = 0;
262
263         printf("starting pipenumber test\n");
264         if (!torture_open_connection(&cli1)) {
265                 return False;
266         }
267
268         while(1) {
269                 fnum = smbcli_nt_create_full(cli1->tree, pipe_name, 0, SEC_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
270                                    NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OPEN_IF, 0, 0);
271
272                 if (fnum == -1) {
273                         printf("Open of pipe %s failed with error (%s)\n", pipe_name, smbcli_errstr(cli1->tree));
274                         break;
275                 }
276                 num_pipes++;
277                 printf("%d\r", num_pipes);
278                 fflush(stdout);
279         }
280
281         printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
282         torture_close_connection(cli1);
283         return True;
284 }
285
286
287
288
289 /*
290   open N connections to the server and just hold them open
291   used for testing performance when there are N idle users
292   already connected
293  */
294  static BOOL torture_holdcon(void)
295 {
296         int i;
297         struct smbcli_state **cli;
298         int num_dead = 0;
299
300         printf("Opening %d connections\n", torture_numops);
301         
302         cli = malloc_array_p(struct smbcli_state *, torture_numops);
303
304         for (i=0;i<torture_numops;i++) {
305                 if (!torture_open_connection(&cli[i])) {
306                         return False;
307                 }
308                 printf("opened %d connections\r", i);
309                 fflush(stdout);
310         }
311
312         printf("\nStarting pings\n");
313
314         while (1) {
315                 for (i=0;i<torture_numops;i++) {
316                         NTSTATUS status;
317                         if (cli[i]) {
318                                 status = smbcli_chkpath(cli[i]->tree, "\\");
319                                 if (!NT_STATUS_IS_OK(status)) {
320                                         printf("Connection %d is dead\n", i);
321                                         cli[i] = NULL;
322                                         num_dead++;
323                                 }
324                                 usleep(100);
325                         }
326                 }
327
328                 if (num_dead == torture_numops) {
329                         printf("All connections dead - finishing\n");
330                         break;
331                 }
332
333                 printf(".");
334                 fflush(stdout);
335         }
336
337         return True;
338 }
339
340 /*
341 test how many open files this server supports on the one socket
342 */
343 static BOOL run_maxfidtest(struct smbcli_state *cli, int dummy)
344 {
345 #define MAXFID_TEMPLATE "\\maxfid\\fid%d\\maxfid.%d.%d"
346         char *fname;
347         int fnums[0x11000], i;
348         int retries=4, maxfid;
349         BOOL correct = True;
350
351         if (retries <= 0) {
352                 printf("failed to connect\n");
353                 return False;
354         }
355
356         if (smbcli_deltree(cli->tree, "\\maxfid") == -1) {
357                 printf("Failed to deltree \\maxfid - %s\n",
358                        smbcli_errstr(cli->tree));
359                 return False;
360         }
361         if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\maxfid"))) {
362                 printf("Failed to mkdir \\maxfid, error=%s\n", 
363                        smbcli_errstr(cli->tree));
364                 return False;
365         }
366
367         printf("Testing maximum number of open files\n");
368
369         for (i=0; i<0x11000; i++) {
370                 if (i % 1000 == 0) {
371                         asprintf(&fname, "\\maxfid\\fid%d", i/1000);
372                         if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, fname))) {
373                                 printf("Failed to mkdir %s, error=%s\n", 
374                                        fname, smbcli_errstr(cli->tree));
375                                 return False;
376                         }
377                         free(fname);
378                 }
379                 asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
380                 if ((fnums[i] = smbcli_open(cli->tree, fname, 
381                                         O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
382                     -1) {
383                         printf("open of %s failed (%s)\n", 
384                                fname, smbcli_errstr(cli->tree));
385                         printf("maximum fnum is %d\n", i);
386                         break;
387                 }
388                 free(fname);
389                 printf("%6d\r", i);
390         }
391         printf("%6d\n", i);
392         i--;
393
394         maxfid = i;
395
396         printf("cleaning up\n");
397         for (i=0;i<maxfid/2;i++) {
398                 asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
399                 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[i]))) {
400                         printf("Close of fnum %d failed - %s\n", fnums[i], smbcli_errstr(cli->tree));
401                 }
402                 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
403                         printf("unlink of %s failed (%s)\n", 
404                                fname, smbcli_errstr(cli->tree));
405                         correct = False;
406                 }
407                 free(fname);
408
409                 asprintf(&fname, MAXFID_TEMPLATE, (maxfid-i)/1000, maxfid-i,(int)getpid());
410                 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[maxfid-i]))) {
411                         printf("Close of fnum %d failed - %s\n", fnums[maxfid-i], smbcli_errstr(cli->tree));
412                 }
413                 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
414                         printf("unlink of %s failed (%s)\n", 
415                                fname, smbcli_errstr(cli->tree));
416                         correct = False;
417                 }
418                 free(fname);
419
420                 printf("%6d %6d\r", i, maxfid-i);
421         }
422         printf("%6d\n", 0);
423
424         if (smbcli_deltree(cli->tree, "\\maxfid") == -1) {
425                 printf("Failed to deltree \\maxfid - %s\n",
426                        smbcli_errstr(cli->tree));
427                 return False;
428         }
429
430         printf("maxfid test finished\n");
431         if (!torture_close_connection(cli)) {
432                 correct = False;
433         }
434         return correct;
435 #undef MAXFID_TEMPLATE
436 }
437
438
439
440 /*
441   sees what IOCTLs are supported
442  */
443 static BOOL torture_ioctl_test(void)
444 {
445         struct smbcli_state *cli;
446         uint16_t device, function;
447         int fnum;
448         const char *fname = "\\ioctl.dat";
449         NTSTATUS status;
450         union smb_ioctl parms;
451         TALLOC_CTX *mem_ctx;
452
453         if (!torture_open_connection(&cli)) {
454                 return False;
455         }
456
457         mem_ctx = talloc_init("ioctl_test");
458
459         printf("starting ioctl test\n");
460
461         smbcli_unlink(cli->tree, fname);
462
463         fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
464         if (fnum == -1) {
465                 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
466                 return False;
467         }
468
469         parms.ioctl.level = RAW_IOCTL_IOCTL;
470         parms.ioctl.in.file.fnum = fnum;
471         parms.ioctl.in.request = IOCTL_QUERY_JOB_INFO;
472         status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
473         printf("ioctl job info: %s\n", smbcli_errstr(cli->tree));
474
475         for (device=0;device<0x100;device++) {
476                 printf("testing device=0x%x\n", device);
477                 for (function=0;function<0x100;function++) {
478                         parms.ioctl.in.request = (device << 16) | function;
479                         status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
480
481                         if (NT_STATUS_IS_OK(status)) {
482                                 printf("ioctl device=0x%x function=0x%x OK : %d bytes\n", 
483                                         device, function, (int)parms.ioctl.out.blob.length);
484                         }
485                 }
486         }
487
488         if (!torture_close_connection(cli)) {
489                 return False;
490         }
491
492         return True;
493 }
494
495
496 static void sigcont(int sig)
497 {
498 }
499
500 double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result)
501 {
502         int i, status;
503         volatile pid_t *child_status;
504         volatile BOOL *child_status_out;
505         int synccount;
506         int tries = 8;
507         double start_time_limit = 10 + (torture_nprocs * 1.5);
508         char **unc_list = NULL;
509         const char *p;
510         int num_unc_names = 0;
511         struct timeval tv;
512
513         *result = True;
514
515         synccount = 0;
516
517         signal(SIGCONT, sigcont);
518
519         child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*torture_nprocs);
520         if (!child_status) {
521                 printf("Failed to setup shared memory\n");
522                 return -1;
523         }
524
525         child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*torture_nprocs);
526         if (!child_status_out) {
527                 printf("Failed to setup result status shared memory\n");
528                 return -1;
529         }
530
531         p = lp_parm_string(-1, "torture", "unclist");
532         if (p) {
533                 unc_list = file_lines_load(p, &num_unc_names, NULL);
534                 if (!unc_list || num_unc_names <= 0) {
535                         printf("Failed to load unc names list from '%s'\n", p);
536                         exit(1);
537                 }
538         }
539
540         for (i = 0; i < torture_nprocs; i++) {
541                 child_status[i] = 0;
542                 child_status_out[i] = True;
543         }
544
545         tv = timeval_current();
546
547         for (i=0;i<torture_nprocs;i++) {
548                 procnum = i;
549                 if (fork() == 0) {
550                         char *myname;
551                         char *hostname=NULL, *sharename;
552
553                         pid_t mypid = getpid();
554                         srandom(((int)mypid) ^ ((int)time(NULL)));
555
556                         asprintf(&myname, "CLIENT%d", i);
557                         lp_set_cmdline("netbios name", myname);
558                         free(myname);
559
560
561                         if (unc_list) {
562                                 if (!smbcli_parse_unc(unc_list[i % num_unc_names],
563                                                       NULL, &hostname, &sharename)) {
564                                         printf("Failed to parse UNC name %s\n",
565                                                unc_list[i % num_unc_names]);
566                                         exit(1);
567                                 }
568                         }
569
570                         while (1) {
571                                 if (hostname) {
572                                         if (torture_open_connection_share(NULL,
573                                                                           &current_cli,
574                                                                           hostname, 
575                                                                           sharename,
576                                                                           NULL)) {
577                                                 break;
578                                         }
579                                 } else if (torture_open_connection(&current_cli)) {
580                                                 break;
581                                 }
582                                 if (tries-- == 0) {
583                                         printf("pid %d failed to start\n", (int)getpid());
584                                         _exit(1);
585                                 }
586                                 msleep(100);    
587                         }
588
589                         child_status[i] = getpid();
590
591                         pause();
592
593                         if (child_status[i]) {
594                                 printf("Child %d failed to start!\n", i);
595                                 child_status_out[i] = 1;
596                                 _exit(1);
597                         }
598
599                         child_status_out[i] = fn(current_cli, i);
600                         _exit(0);
601                 }
602         }
603
604         do {
605                 synccount = 0;
606                 for (i=0;i<torture_nprocs;i++) {
607                         if (child_status[i]) synccount++;
608                 }
609                 if (synccount == torture_nprocs) break;
610                 msleep(100);
611         } while (timeval_elapsed(&tv) < start_time_limit);
612
613         if (synccount != torture_nprocs) {
614                 printf("FAILED TO START %d CLIENTS (started %d)\n", torture_nprocs, synccount);
615                 *result = False;
616                 return timeval_elapsed(&tv);
617         }
618
619         printf("Starting %d clients\n", torture_nprocs);
620
621         /* start the client load */
622         tv = timeval_current();
623         for (i=0;i<torture_nprocs;i++) {
624                 child_status[i] = 0;
625         }
626
627         printf("%d clients started\n", torture_nprocs);
628
629         kill(0, SIGCONT);
630
631         for (i=0;i<torture_nprocs;i++) {
632                 int ret;
633                 while ((ret=waitpid(0, &status, 0)) == -1 && errno == EINTR) /* noop */ ;
634                 if (ret == -1 || WEXITSTATUS(status) != 0) {
635                         *result = False;
636                 }
637         }
638
639         printf("\n");
640         
641         for (i=0;i<torture_nprocs;i++) {
642                 if (!child_status_out[i]) {
643                         *result = False;
644                 }
645         }
646         return timeval_elapsed(&tv);
647 }
648
649 #define FLAG_MULTIPROC 1
650
651 static struct {
652         const char *name;
653         BOOL (*fn)(void);
654         BOOL (*multi_fn)(struct smbcli_state *, int );
655 } builtin_torture_ops[] = {
656         /* benchmarking tests */
657         {"BENCH-HOLDCON",  torture_holdcon, 0},
658         {"BENCH-NBENCH",  torture_nbench, 0},
659         {"BENCH-TORTURE", NULL, run_torture},
660         {"BENCH-NBT",     torture_bench_nbt, 0},
661         {"BENCH-WINS",    torture_bench_wins, 0},
662         {"BENCH-CLDAP",   torture_bench_cldap, 0},
663
664         /* RAW smb tests */
665         {"RAW-QFSINFO", torture_raw_qfsinfo, 0},
666         {"RAW-QFILEINFO", torture_raw_qfileinfo, 0},
667         {"RAW-SFILEINFO", torture_raw_sfileinfo, 0},
668         {"RAW-SFILEINFO-BUG", torture_raw_sfileinfo_bug, 0},
669         {"RAW-SEARCH", torture_raw_search, 0},
670         {"RAW-CLOSE", torture_raw_close, 0},
671         {"RAW-OPEN", torture_raw_open, 0},
672         {"RAW-MKDIR", torture_raw_mkdir, 0},
673         {"RAW-OPLOCK", torture_raw_oplock, 0},
674         {"RAW-NOTIFY", torture_raw_notify, 0},
675         {"RAW-MUX", torture_raw_mux, 0},
676         {"RAW-IOCTL", torture_raw_ioctl, 0},
677         {"RAW-CHKPATH", torture_raw_chkpath, 0},
678         {"RAW-UNLINK", torture_raw_unlink, 0},
679         {"RAW-READ", torture_raw_read, 0},
680         {"RAW-WRITE", torture_raw_write, 0},
681         {"RAW-LOCK", torture_raw_lock, 0},
682         {"RAW-CONTEXT", torture_raw_context, 0},
683         {"RAW-RENAME", torture_raw_rename, 0},
684         {"RAW-SEEK", torture_raw_seek, 0},
685         {"RAW-EAS", torture_raw_eas, 0},
686         {"RAW-EAMAX", torture_max_eas, 0},
687         {"RAW-STREAMS", torture_raw_streams, 0},
688         {"RAW-ACLS", torture_raw_acls, 0},
689         {"RAW-RAP", torture_raw_rap, 0},
690         {"RAW-COMPOSITE", torture_raw_composite, 0},
691
692         /* SMB2 tests */
693         {"SMB2-CONNECT", torture_smb2_connect, 0},
694         {"SMB2-SCAN", torture_smb2_scan, 0},
695         {"SMB2-SCANGETINFO", torture_smb2_getinfo_scan, 0},
696         {"SMB2-SCANSETINFO", torture_smb2_setinfo_scan, 0},
697         {"SMB2-SCANFIND", torture_smb2_find_scan, 0},
698         {"SMB2-GETINFO", torture_smb2_getinfo, 0},
699         {"SMB2-SETINFO", torture_smb2_setinfo, 0},
700         {"SMB2-FIND", torture_smb2_find, 0},
701
702         /* protocol scanners */
703         {"SCAN-MAXFID", NULL, run_maxfidtest},
704         {"SCAN-PIPE_NUMBER", run_pipe_number, 0},
705         {"SCAN-IOCTL",  torture_ioctl_test, 0},
706         {"SCAN-RAP",  torture_rap_scan, 0},
707
708         /* local (no server) testers */
709         {"LOCAL-NTLMSSP", torture_ntlmssp_self_check, 0},
710         {"LOCAL-ICONV", torture_local_iconv, 0},
711         {"LOCAL-TALLOC", torture_local_talloc, 0},
712         {"LOCAL-MESSAGING", torture_local_messaging, 0},
713         {"LOCAL-IRPC",  torture_local_irpc, 0},
714         {"LOCAL-BINDING", torture_local_binding_string, 0},
715         {"LOCAL-STRLIST", torture_local_util_strlist, 0},
716         {"LOCAL-FILE", torture_local_util_file, 0},
717         {"LOCAL-IDTREE", torture_local_idtree, 0},
718         {"LOCAL-SOCKET", torture_local_socket, 0},
719         {"LOCAL-PAC", torture_pac, 0},
720         {"LOCAL-REGISTRY", torture_registry, 0},
721         {"LOCAL-RESOLVE", torture_local_resolve, 0},
722         {"LOCAL-SDDL", torture_local_sddl, 0},
723         {"LOCAL-NDR", torture_local_ndr, 0},
724
725         /* ldap testers */
726         {"LDAP-BASIC", torture_ldap_basic, 0},
727         {"LDAP-CLDAP", torture_cldap, 0},
728
729         /* nbt tests */
730         {"NBT-REGISTER", torture_nbt_register, 0},
731         {"NBT-WINS", torture_nbt_wins, 0},
732         {"NBT-DGRAM", torture_nbt_dgram, 0},
733         {"NBT-BROWSE", torture_nbt_browse, 0},
734         {"NBT-WINSREPLICATION-SIMPLE", torture_nbt_winsreplication_simple, 0},
735         {"NBT-WINSREPLICATION-REPLICA", torture_nbt_winsreplication_replica, 0},
736         {"NBT-WINSREPLICATION-OWNED", torture_nbt_winsreplication_owned, 0},
737         
738         {NULL, NULL, 0}};
739
740 static void register_builtin_ops(void)
741 {
742         int i;
743         for (i = 0; builtin_torture_ops[i].name; i++) {
744                 register_torture_op(builtin_torture_ops[i].name, 
745                                                         builtin_torture_ops[i].fn, 
746                                                         builtin_torture_ops[i].multi_fn);
747         }
748 }
749
750
751 struct torture_op *torture_ops = NULL;
752
753 static struct torture_op *find_torture_op(const char *name)
754 {
755         struct torture_op *o;
756         for (o = torture_ops; o; o = o->next) {
757                 if (strcmp(name, o->name) == 0)
758                         return o;
759         }
760
761         return NULL;
762 }
763
764 _PUBLIC_ NTSTATUS register_torture_op(const char *name, BOOL (*fn)(void), BOOL (*multi_fn)(struct smbcli_state *, int ))
765 {
766         struct torture_op *op;
767         
768         /* Check for duplicates */
769         if (find_torture_op(name) != NULL) {
770                 DEBUG(0,("There already is a torture op registered with the name %s!\n", name));
771                 return NT_STATUS_OBJECT_NAME_COLLISION;
772         }
773
774         op = talloc(talloc_autofree_context(), struct torture_op);
775
776         op->name = talloc_strdup(op, name);
777         op->fn = fn;
778         op->multi_fn = multi_fn;
779
780         DLIST_ADD(torture_ops, op);
781         
782         return NT_STATUS_OK;
783 }
784
785 int torture_init(void)
786 {
787         init_module_fn static_init[] = STATIC_torture_MODULES;
788         init_module_fn *shared_init = load_samba_modules(NULL, "torture");
789         
790         register_builtin_ops();
791
792         run_init_functions(static_init);
793         run_init_functions(shared_init);
794
795         talloc_free(shared_init);
796
797         return 0;
798 }