diff options
author | Andrew Tridgell <tridge@samba.org> | 2001-06-19 02:02:19 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2001-06-19 02:02:19 +0000 |
commit | ffb63e4f8ec2b7390cbb00bca74a9bedb8399a91 (patch) | |
tree | 13b20c7d32bfbe54784699b06865de9d4d38ac8c /source3/utils | |
parent | 90b757f6bf6c27c4bfc1fb745981c56a21da3488 (diff) | |
download | samba-ffb63e4f8ec2b7390cbb00bca74a9bedb8399a91.tar.gz samba-ffb63e4f8ec2b7390cbb00bca74a9bedb8399a91.tar.bz2 samba-ffb63e4f8ec2b7390cbb00bca74a9bedb8399a91.zip |
moved all our torture code to a separate directory
(This used to be commit dd12c47645e2d0e832bc555492a6a8725a4495ee)
Diffstat (limited to 'source3/utils')
-rw-r--r-- | source3/utils/locktest.c | 567 | ||||
-rw-r--r-- | source3/utils/locktest2.c | 626 | ||||
-rw-r--r-- | source3/utils/masktest.c | 521 | ||||
-rw-r--r-- | source3/utils/msgtest.c | 96 | ||||
-rw-r--r-- | source3/utils/nbio.c | 240 | ||||
-rw-r--r-- | source3/utils/rpctorture.c | 559 |
6 files changed, 0 insertions, 2609 deletions
diff --git a/source3/utils/locktest.c b/source3/utils/locktest.c deleted file mode 100644 index 80dbba1e37..0000000000 --- a/source3/utils/locktest.c +++ /dev/null @@ -1,567 +0,0 @@ -/* - Unix SMB/Netbios implementation. - Version 2.0 - 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. -*/ - -#define NO_SYSLOG - -#include "includes.h" - -static fstring password; -static fstring username; -static int got_pass; -static int numops = 1000; -static BOOL showall; -static BOOL analyze; -static BOOL hide_unlock_fails; -static BOOL use_oplocks; - -#define FILENAME "\\locktest.dat" -#define LOCKRANGE 1000 -#define LOCKBASE 0; - -/* -#define LOCKBASE (0x40000000 - 50) -*/ - -#define READ_PCT 50 -#define LOCK_PCT 35 -#define UNLOCK_PCT 55 -#define RANGE_MULTIPLE 1 -#define NSERVERS 2 -#define NCONNECTIONS 2 -#define NFILES 2 -#define LOCK_TIMEOUT 0 - -#define NASTY_POSIX_LOCK_HACK 0 - - -struct record { - char r1, r2; - char conn, f; - SMB_BIG_UINT start, len; - char needed; -}; - -static struct record preset[] = { -#if 0 -{36, 5, 0, 0, 0, 8, 1}, -{ 2, 6, 0, 1, 0, 1, 1}, -{53, 92, 0, 0, 0, 0, 1}, -{99, 11, 0, 0, 7, 1, 1}, -#endif -}; - -static struct record *recorded; - -static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, int 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("%6d %05x:%05x %s %.0f:%.0f(%.0f)\n", - (int)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 -*******************************************************/ -struct cli_state *connect_one(char *share) -{ - struct cli_state *c; - struct nmb_name called, calling; - char *server_n; - fstring server; - struct in_addr ip; - extern struct in_addr ipzero; - fstring myname; - static int count; - - fstrcpy(server,share+2); - share = strchr(server,'\\'); - if (!share) return NULL; - *share = 0; - share++; - - server_n = server; - - ip = ipzero; - - slprintf(myname,sizeof(myname), "lock-%u-%u", getpid(), count++); - - make_nmb_name(&calling, myname, 0x0); - make_nmb_name(&called , server, 0x20); - - again: - ip = ipzero; - - /* have to open a new connection */ - if (!(c=cli_initialise(NULL)) || (cli_set_port(c, 139) == 0) || - !cli_connect(c, server_n, &ip)) { - DEBUG(0,("Connection to %s failed\n", server_n)); - return NULL; - } - - 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) { - pstrcpy(password, pass); - } - } - - if (!cli_session_setup(c, username, - password, strlen(password), - password, strlen(password), - 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, strlen(password)+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++) { - cli_close(cli[server][conn], fnum[server][conn][f]); - } - cli_ulogoff(cli[server][conn]); - cli_shutdown(cli[server][conn]); - free(cli[server][conn]); - cli[server][conn] = NULL; - } - cli[server][conn] = connect_one(share[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; - unsigned r1 = rec->r1; - unsigned r2 = rec->r2; - unsigned op; - int server; - BOOL ret[NSERVERS]; - - if (r1 < READ_PCT) { - op = READ_LOCK; - } else { - op = WRITE_LOCK; - } - - if (r2 < LOCK_PCT) { - /* 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); - } - if (showall || ret[0] != ret[1]) { - printf("lock conn=%u f=%u range=%.0f:%.0f(%.0f) op=%s -> %u:%u\n", - conn, f, - (double)start, (double)start+len-1, (double)len, - op==READ_LOCK?"READ_LOCK":"WRITE_LOCK", - ret[0], ret[1]); - } - if (showall || ret[0] != ret[1]) show_locks(); - if (ret[0] != ret[1]) return False; - } else if (r2 < LOCK_PCT+UNLOCK_PCT) { - /* unset a lock */ - for (server=0;server<NSERVERS;server++) { - ret[server] = cli_unlock64(cli[server][conn], - fnum[server][conn][f], - start, len); - } - if (showall || (!hide_unlock_fails && (ret[0] != ret[1]))) { - printf("unlock conn=%u f=%u range=%.0f:%.0f(%.0f) -> %u:%u\n", - conn, f, - (double)start, (double)start+len-1, (double)len, - ret[0], ret[1]); - } - if (showall || ret[0] != ret[1]) show_locks(); - if (!hide_unlock_fails && ret[0] != ret[1]) return False; - } else { - /* reopen the file */ - for (server=0;server<NSERVERS;server++) { - cli_close(cli[server][conn], fnum[server][conn][f]); - } - 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; - } - } - if (showall) { - printf("reopen conn=%u f=%u\n", - conn, f); - show_locks(); - } - } - return True; -} - -static void close_files(struct cli_state *cli[NSERVERS][NCONNECTIONS], - int fnum[NSERVERS][NCONNECTIONS][NFILES]) -{ - int server, conn, f; - - for (server=0;server<NSERVERS;server++) - for (conn=0;conn<NCONNECTIONS;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; - } - } - for (server=0;server<NSERVERS;server++) { - cli_unlink(cli[server][0], FILENAME); - } -} - -static void open_files(struct cli_state *cli[NSERVERS][NCONNECTIONS], - int fnum[NSERVERS][NCONNECTIONS][NFILES]) -{ - int server, conn, f; - - for (server=0;server<NSERVERS;server++) - for (conn=0;conn<NCONNECTIONS;conn++) - for (f=0;f<NFILES;f++) { - fnum[server][conn][f] = cli_open(cli[server][conn], FILENAME, - O_RDWR|O_CREAT, - DENY_NONE); - if (fnum[server][conn][f] == -1) { - fprintf(stderr,"Failed to open fnum[%u][%u][%u]\n", - server, conn, f); - exit(1); - } - } -} - - -static int retest(struct cli_state *cli[NSERVERS][NCONNECTIONS], - int fnum[NSERVERS][NCONNECTIONS][NFILES], - int n) -{ - int i; - printf("testing %u ...\n", n); - for (i=0; i<n; i++) { - if (i && i % 100 == 0) { - printf("%u\n", i); - } - - if (recorded[i].needed && - !test_one(cli, fnum, &recorded[i])) return i; - } - return n; -} - - -/* each server has two connections open to it. Each connection has two file - descriptors open on the file - 8 file descriptors in total - - we then do random locking ops in tamdem on the 4 fnums from each - server and ensure that the results match - */ -static void test_locks(char *share[NSERVERS]) -{ - struct cli_state *cli[NSERVERS][NCONNECTIONS]; - int fnum[NSERVERS][NCONNECTIONS][NFILES]; - int n, i, n1; - - ZERO_STRUCT(fnum); - ZERO_STRUCT(cli); - - recorded = (struct record *)malloc(sizeof(*recorded) * numops); - - for (n=0; n<numops; n++) { - if (n < sizeof(preset) / sizeof(preset[0])) { - recorded[n] = preset[n]; - } else { - recorded[n].conn = random() % NCONNECTIONS; - recorded[n].f = random() % NFILES; - recorded[n].start = LOCKBASE + ((unsigned)random() % (LOCKRANGE-1)); - recorded[n].len = 1 + - random() % (LOCKRANGE-(recorded[n].start-LOCKBASE)); - recorded[n].start *= RANGE_MULTIPLE; - recorded[n].len *= RANGE_MULTIPLE; - recorded[n].r1 = random() % 100; - recorded[n].r2 = random() % 100; - recorded[n].needed = True; - } - } - - reconnect(cli, fnum, share); - open_files(cli, fnum); - n = retest(cli, fnum, numops); - - if (n == numops || !analyze) return; - n++; - - while (1) { - n1 = n; - - close_files(cli, fnum); - reconnect(cli, fnum, share); - open_files(cli, fnum); - - for (i=0;i<n-1;i++) { - int m; - recorded[i].needed = False; - - close_files(cli, fnum); - open_files(cli, fnum); - - m = retest(cli, fnum, n); - if (m == n) { - recorded[i].needed = True; - } else { - if (i < m) { - memmove(&recorded[i], &recorded[i+1], - (m-i)*sizeof(recorded[0])); - } - n = m; - i--; - } - } - - if (n1 == n) break; - } - - close_files(cli, fnum); - reconnect(cli, fnum, share); - open_files(cli, fnum); - showall = True; - n1 = retest(cli, fnum, n); - if (n1 != n-1) { - printf("ERROR - inconsistent result (%u %u)\n", n1, n); - } - close_files(cli, fnum); - - for (i=0;i<n;i++) { - printf("{%u, %u, %u, %u, %.0f, %.0f, %u},\n", - recorded[i].r1, - recorded[i].r2, - recorded[i].conn, - recorded[i].f, - (double)recorded[i].start, - (double)recorded[i].len, - recorded[i].needed); - } -} - - - -static void usage(void) -{ - printf( -"Usage:\n\ - locktest //server1/share1 //server2/share2 [options..]\n\ - options:\n\ - -U user%%pass\n\ - -s seed\n\ - -o numops\n\ - -u hide unlock fails\n\ - -a (show all ops)\n\ - -O use oplocks\n\ -"); -} - -/**************************************************************************** - main program -****************************************************************************/ - int main(int argc,char *argv[]) -{ - char *share[NSERVERS]; - extern char *optarg; - extern int optind; - extern FILE *dbf; - int opt; - char *p; - int seed, server; - static pstring servicesf = CONFIGFILE; - - setlinebuf(stdout); - - dbf = stderr; - - if (argc < 3 || argv[1][0] == '-') { - usage(); - exit(1); - } - - setup_logging(argv[0],True); - - for (server=0;server<NSERVERS;server++) { - share[server] = argv[1+server]; - all_string_sub(share[server],"/","\\",0); - } - - argc -= NSERVERS; - argv += NSERVERS; - - TimeInit(); - charset_initialise(); - codepage_initialise(lp_client_code_page()); - - lp_load(servicesf,True,False,False); - load_interfaces(); - - if (getenv("USER")) { - pstrcpy(username,getenv("USER")); - } - - seed = time(NULL); - - while ((opt = getopt(argc, argv, "U:s:ho:aAW:O")) != EOF) { - switch (opt) { - case 'U': - pstrcpy(username,optarg); - p = strchr(username,'%'); - if (p) { - *p = 0; - pstrcpy(password, p+1); - got_pass = 1; - } - break; - case 's': - seed = atoi(optarg); - break; - case 'u': - hide_unlock_fails = True; - break; - case 'o': - numops = atoi(optarg); - break; - case 'O': - use_oplocks = True; - break; - case 'a': - showall = True; - break; - case 'A': - analyze = True; - break; - case 'h': - usage(); - exit(1); - default: - printf("Unknown option %c (%d)\n", (char)opt, opt); - exit(1); - } - } - - argc -= optind; - argv += optind; - - DEBUG(0,("seed=%u\n", seed)); - srandom(seed); - - locking_init(1); - test_locks(share); - - return(0); -} diff --git a/source3/utils/locktest2.c b/source3/utils/locktest2.c deleted file mode 100644 index 0391aa2942..0000000000 --- a/source3/utils/locktest2.c +++ /dev/null @@ -1,626 +0,0 @@ -/* - Unix SMB/Netbios implementation. - Version 2.0 - byte range lock tester - with local filesystem support - 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. -*/ - -#define NO_SYSLOG - -#include "includes.h" - -static fstring password; -static fstring username; -static int got_pass; -static int numops = 1000; -static BOOL showall; -static BOOL analyze; -static BOOL hide_unlock_fails; -static BOOL use_oplocks; - -#define FILENAME "\\locktest.dat" -#define LOCKRANGE 100 -#define LOCKBASE 0 - -/* -#define LOCKBASE (0x40000000 - 50) -*/ - -#define READ_PCT 50 -#define LOCK_PCT 25 -#define UNLOCK_PCT 65 -#define RANGE_MULTIPLE 1 - -#define NSERVERS 2 -#define NCONNECTIONS 2 -#define NUMFSTYPES 2 -#define NFILES 2 -#define LOCK_TIMEOUT 0 - -#define FSTYPE_SMB 0 -#define FSTYPE_NFS 1 - -struct record { - char r1, r2; - char conn, f, fstype; - unsigned start, len; - char needed; -}; - -static struct record *recorded; - -static int try_open(struct cli_state *c, char *nfs, int fstype, char *fname, int flags) -{ - pstring path; - - switch (fstype) { - case FSTYPE_SMB: - return cli_open(c, fname, flags, DENY_NONE); - - case FSTYPE_NFS: - slprintf(path, sizeof(path), "%s%s", nfs, fname); - pstring_sub(path,"\\", "/"); - return open(path, flags, 0666); - } - - return -1; -} - -static BOOL try_close(struct cli_state *c, int fstype, int fd) -{ - switch (fstype) { - case FSTYPE_SMB: - return cli_close(c, fd); - - case FSTYPE_NFS: - return close(fd) == 0; - } - - return False; -} - -static BOOL try_lock(struct cli_state *c, int fstype, - int fd, unsigned start, unsigned len, - int op) -{ - struct flock lock; - - switch (fstype) { - case FSTYPE_SMB: - return cli_lock(c, fd, start, len, LOCK_TIMEOUT, op); - - case FSTYPE_NFS: - lock.l_type = (op==READ_LOCK) ? F_RDLCK:F_WRLCK; - lock.l_whence = SEEK_SET; - lock.l_start = start; - lock.l_len = len; - lock.l_pid = getpid(); - return fcntl(fd,F_SETLK,&lock) == 0; - } - - return False; -} - -static BOOL try_unlock(struct cli_state *c, int fstype, - int fd, unsigned start, unsigned len) -{ - struct flock lock; - - switch (fstype) { - case FSTYPE_SMB: - return cli_unlock(c, fd, start, len); - - case FSTYPE_NFS: - lock.l_type = F_UNLCK; - lock.l_whence = SEEK_SET; - lock.l_start = start; - lock.l_len = len; - lock.l_pid = getpid(); - return fcntl(fd,F_SETLK,&lock) == 0; - } - - return False; -} - -static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, int pid, - enum brl_type lock_type, - br_off start, br_off size) -{ - printf("%6d %05x:%05x %s %.0f:%.0f(%.0f)\n", - (int)pid, (int)dev, (int)ino, - lock_type==READ_LOCK?"R":"W", - (double)start, (double)start+size-1,(double)size); - -} - -/***************************************************** -return a connection to a server -*******************************************************/ -struct cli_state *connect_one(char *share) -{ - struct cli_state *c; - struct nmb_name called, calling; - char *server_n; - fstring server; - struct in_addr ip; - extern struct in_addr ipzero; - fstring myname; - static int count; - - fstrcpy(server,share+2); - share = strchr(server,'\\'); - if (!share) return NULL; - *share = 0; - share++; - - server_n = server; - - ip = ipzero; - - slprintf(myname,sizeof(myname), "lock-%u-%u", getpid(), count++); - - make_nmb_name(&calling, myname, 0x0); - make_nmb_name(&called , server, 0x20); - - again: - ip = ipzero; - - /* have to open a new connection */ - if (!(c=cli_initialise(NULL)) || (cli_set_port(c, 139) == 0) || - !cli_connect(c, server_n, &ip)) { - DEBUG(0,("Connection to %s failed\n", server_n)); - return NULL; - } - - 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) { - pstrcpy(password, pass); - } - } - - if (!cli_session_setup(c, username, - password, strlen(password), - password, strlen(password), - 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, strlen(password)+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], - char *nfs[NSERVERS], - int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES], - char *share1, char *share2) -{ - int server, conn, f, fstype; - char *share[2]; - share[0] = share1; - share[1] = share2; - - fstype = FSTYPE_SMB; - - for (server=0;server<NSERVERS;server++) - for (conn=0;conn<NCONNECTIONS;conn++) { - if (cli[server][conn]) { - for (f=0;f<NFILES;f++) { - cli_close(cli[server][conn], fnum[server][fstype][conn][f]); - } - cli_ulogoff(cli[server][conn]); - cli_shutdown(cli[server][conn]); - free(cli[server][conn]); - cli[server][conn] = NULL; - } - cli[server][conn] = connect_one(share[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], - char *nfs[NSERVERS], - int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES], - struct record *rec) -{ - unsigned conn = rec->conn; - unsigned f = rec->f; - unsigned fstype = rec->fstype; - unsigned start = rec->start; - unsigned len = rec->len; - unsigned r1 = rec->r1; - unsigned r2 = rec->r2; - unsigned op; - int server; - BOOL ret[NSERVERS]; - - if (r1 < READ_PCT) { - op = READ_LOCK; - } else { - op = WRITE_LOCK; - } - - if (r2 < LOCK_PCT) { - /* set a lock */ - for (server=0;server<NSERVERS;server++) { - ret[server] = try_lock(cli[server][conn], fstype, - fnum[server][fstype][conn][f], - start, len, op); - } - if (showall || ret[0] != ret[1]) { - printf("lock conn=%u fstype=%u f=%u range=%u:%u(%u) op=%s -> %u:%u\n", - conn, fstype, f, - start, start+len-1, len, - op==READ_LOCK?"READ_LOCK":"WRITE_LOCK", - ret[0], ret[1]); - } - if (showall) brl_forall(print_brl); - if (ret[0] != ret[1]) return False; - } else if (r2 < LOCK_PCT+UNLOCK_PCT) { - /* unset a lock */ - for (server=0;server<NSERVERS;server++) { - ret[server] = try_unlock(cli[server][conn], fstype, - fnum[server][fstype][conn][f], - start, len); - } - if (showall || (!hide_unlock_fails && (ret[0] != ret[1]))) { - printf("unlock conn=%u fstype=%u f=%u range=%u:%u(%u) -> %u:%u\n", - conn, fstype, f, - start, start+len-1, len, - ret[0], ret[1]); - } - if (showall) brl_forall(print_brl); - if (!hide_unlock_fails && ret[0] != ret[1]) return False; - } else { - /* reopen the file */ - for (server=0;server<NSERVERS;server++) { - try_close(cli[server][conn], fstype, fnum[server][fstype][conn][f]); - fnum[server][fstype][conn][f] = try_open(cli[server][conn], nfs[server], fstype, FILENAME, - O_RDWR|O_CREAT); - if (fnum[server][fstype][conn][f] == -1) { - printf("failed to reopen on share1\n"); - return False; - } - } - if (showall) { - printf("reopen conn=%u fstype=%u f=%u\n", - conn, fstype, f); - brl_forall(print_brl); - } - } - return True; -} - -static void close_files(struct cli_state *cli[NSERVERS][NCONNECTIONS], - char *nfs[NSERVERS], - int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES]) -{ - int server, conn, f, fstype; - - for (server=0;server<NSERVERS;server++) - for (fstype=0;fstype<NUMFSTYPES;fstype++) - for (conn=0;conn<NCONNECTIONS;conn++) - for (f=0;f<NFILES;f++) { - if (fnum[server][fstype][conn][f] != -1) { - try_close(cli[server][conn], fstype, fnum[server][fstype][conn][f]); - fnum[server][fstype][conn][f] = -1; - } - } - for (server=0;server<NSERVERS;server++) { - cli_unlink(cli[server][0], FILENAME); - } -} - -static void open_files(struct cli_state *cli[NSERVERS][NCONNECTIONS], - char *nfs[NSERVERS], - int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES]) -{ - int server, fstype, conn, f; - - for (server=0;server<NSERVERS;server++) - for (fstype=0;fstype<NUMFSTYPES;fstype++) - for (conn=0;conn<NCONNECTIONS;conn++) - for (f=0;f<NFILES;f++) { - fnum[server][fstype][conn][f] = try_open(cli[server][conn], nfs[server], fstype, FILENAME, - O_RDWR|O_CREAT); - if (fnum[server][fstype][conn][f] == -1) { - fprintf(stderr,"Failed to open fnum[%u][%u][%u][%u]\n", - server, fstype, conn, f); - exit(1); - } - } -} - - -static int retest(struct cli_state *cli[NSERVERS][NCONNECTIONS], - char *nfs[NSERVERS], - int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES], - int n) -{ - int i; - printf("testing %u ...\n", n); - for (i=0; i<n; i++) { - if (i && i % 100 == 0) { - printf("%u\n", i); - } - - if (recorded[i].needed && - !test_one(cli, nfs, fnum, &recorded[i])) return i; - } - return n; -} - - -/* each server has two connections open to it. Each connection has two file - descriptors open on the file - 8 file descriptors in total - - we then do random locking ops in tamdem on the 4 fnums from each - server and ensure that the results match - */ -static void test_locks(char *share1, char *share2, char *nfspath1, char *nfspath2) -{ - struct cli_state *cli[NSERVERS][NCONNECTIONS]; - char *nfs[NSERVERS]; - int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES]; - int n, i, n1; - - nfs[0] = nfspath1; - nfs[1] = nfspath2; - - ZERO_STRUCT(fnum); - ZERO_STRUCT(cli); - - recorded = (struct record *)malloc(sizeof(*recorded) * numops); - - for (n=0; n<numops; n++) { - recorded[n].conn = random() % NCONNECTIONS; - recorded[n].fstype = random() % NUMFSTYPES; - recorded[n].f = random() % NFILES; - recorded[n].start = LOCKBASE + ((unsigned)random() % (LOCKRANGE-1)); - recorded[n].len = 1 + - random() % (LOCKRANGE-(recorded[n].start-LOCKBASE)); - recorded[n].start *= RANGE_MULTIPLE; - recorded[n].len *= RANGE_MULTIPLE; - recorded[n].r1 = random() % 100; - recorded[n].r2 = random() % 100; - recorded[n].needed = True; - } - - reconnect(cli, nfs, fnum, share1, share2); - open_files(cli, nfs, fnum); - n = retest(cli, nfs, fnum, numops); - - if (n == numops || !analyze) return; - n++; - - while (1) { - n1 = n; - - close_files(cli, nfs, fnum); - reconnect(cli, nfs, fnum, share1, share2); - open_files(cli, nfs, fnum); - - for (i=0;i<n-1;i++) { - int m; - recorded[i].needed = False; - - close_files(cli, nfs, fnum); - open_files(cli, nfs, fnum); - - m = retest(cli, nfs, fnum, n); - if (m == n) { - recorded[i].needed = True; - } else { - if (i < m) { - memmove(&recorded[i], &recorded[i+1], - (m-i)*sizeof(recorded[0])); - } - n = m; - i--; - } - } - - if (n1 == n) break; - } - - close_files(cli, nfs, fnum); - reconnect(cli, nfs, fnum, share1, share2); - open_files(cli, nfs, fnum); - showall = True; - n1 = retest(cli, nfs, fnum, n); - if (n1 != n-1) { - printf("ERROR - inconsistent result (%u %u)\n", n1, n); - } - close_files(cli, nfs, fnum); - - for (i=0;i<n;i++) { - printf("{%u, %u, %u, %u, %u, %u, %u, %u},\n", - recorded[i].r1, - recorded[i].r2, - recorded[i].conn, - recorded[i].fstype, - recorded[i].f, - recorded[i].start, - recorded[i].len, - recorded[i].needed); - } -} - - - -static void usage(void) -{ - printf( -"Usage:\n\ - locktest //server1/share1 //server2/share2 /path1 /path2 [options..]\n\ - options:\n\ - -U user%%pass\n\ - -s seed\n\ - -o numops\n\ - -u hide unlock fails\n\ - -a (show all ops)\n\ - -O use oplocks\n\ -"); -} - -/**************************************************************************** - main program -****************************************************************************/ - int main(int argc,char *argv[]) -{ - char *share1, *share2, *nfspath1, *nfspath2; - extern char *optarg; - extern int optind; - extern FILE *dbf; - int opt; - char *p; - int seed; - static pstring servicesf = CONFIGFILE; - - setlinebuf(stdout); - - dbf = stderr; - - if (argc < 5 || argv[1][0] == '-') { - usage(); - exit(1); - } - - share1 = argv[1]; - share2 = argv[2]; - nfspath1 = argv[3]; - nfspath2 = argv[4]; - - all_string_sub(share1,"/","\\",0); - all_string_sub(share2,"/","\\",0); - - setup_logging(argv[0],True); - - argc -= 4; - argv += 4; - - TimeInit(); - charset_initialise(); - codepage_initialise(lp_client_code_page()); - - lp_load(servicesf,True,False,False); - load_interfaces(); - - if (getenv("USER")) { - pstrcpy(username,getenv("USER")); - } - - seed = time(NULL); - - while ((opt = getopt(argc, argv, "U:s:ho:aAW:O")) != EOF) { - switch (opt) { - case 'U': - pstrcpy(username,optarg); - p = strchr(username,'%'); - if (p) { - *p = 0; - pstrcpy(password, p+1); - got_pass = 1; - } - break; - case 's': - seed = atoi(optarg); - break; - case 'u': - hide_unlock_fails = True; - break; - case 'o': - numops = atoi(optarg); - break; - case 'O': - use_oplocks = True; - break; - case 'a': - showall = True; - break; - case 'A': - analyze = True; - break; - case 'h': - usage(); - exit(1); - default: - printf("Unknown option %c (%d)\n", (char)opt, opt); - exit(1); - } - } - - argc -= optind; - argv += optind; - - DEBUG(0,("seed=%u\n", seed)); - srandom(seed); - - locking_init(1); - test_locks(share1, share2, nfspath1, nfspath2); - - return(0); -} diff --git a/source3/utils/masktest.c b/source3/utils/masktest.c deleted file mode 100644 index a654b5bfd1..0000000000 --- a/source3/utils/masktest.c +++ /dev/null @@ -1,521 +0,0 @@ -/* - Unix SMB/Netbios implementation. - Version 2.0 - mask_match 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. -*/ - -#define NO_SYSLOG - -#include "includes.h" - -extern int DEBUGLEVEL; -static fstring password; -static fstring username; -static int got_pass; -static int max_protocol = PROTOCOL_NT1; -static BOOL showall = False; -static BOOL old_list = False; -static char *maskchars = "<>\"?*abc."; -static char *filechars = "abcdefghijklm."; -static int verbose; -static int die_on_error; - -/* a test fn for LANMAN mask support */ -int ms_fnmatch_lanman_core(char *pattern, char *string) -{ - char *p = pattern, *n = string; - char c; - - if (strcmp(p,"?")==0 && strcmp(n,".")==0) goto match; - - while ((c = *p++)) { - switch (c) { - case '.': - /* if (! *n && ! *p) goto match; */ - if (*n != '.') goto nomatch; - n++; - break; - - case '?': - if ((*n == '.' && n[1] != '.') || ! *n) goto next; - n++; - break; - - case '>': - if (n[0] == '.') { - if (! n[1] && ms_fnmatch_lanman_core(p, n+1) == 0) goto match; - if (ms_fnmatch_lanman_core(p, n) == 0) goto match; - goto nomatch; - } - if (! *n) goto next; - n++; - break; - - case '*': - if (! *p) goto match; - for (; *n; n++) { - if (ms_fnmatch_lanman_core(p, n) == 0) goto match; - } - break; - - case '<': - for (; *n; n++) { - if (ms_fnmatch_lanman_core(p, n) == 0) goto match; - if (*n == '.' && !strchr(n+1,'.')) { - n++; - break; - } - } - break; - - case '"': - if (*n == 0 && ms_fnmatch_lanman_core(p, n) == 0) goto match; - if (*n != '.') goto nomatch; - n++; - break; - - default: - if (c != *n) goto nomatch; - n++; - } - } - - if (! *n) goto match; - - nomatch: - if (verbose) printf("NOMATCH pattern=[%s] string=[%s]\n", pattern, string); - return -1; - -next: - if (ms_fnmatch_lanman_core(p, n) == 0) goto match; - goto nomatch; - - match: - if (verbose) printf("MATCH pattern=[%s] string=[%s]\n", pattern, string); - return 0; -} - -int ms_fnmatch_lanman(char *pattern, char *string) -{ - if (!strpbrk(pattern, "?*<>\"")) { - if (strcmp(string,"..") == 0) string = "."; - return strcmp(pattern, string); - } - - if (strcmp(string,"..") == 0 || strcmp(string,".") == 0) { - return ms_fnmatch_lanman_core(pattern, "..") && - ms_fnmatch_lanman_core(pattern, "."); - } - - return ms_fnmatch_lanman_core(pattern, string); -} - -static BOOL reg_match_one(char *pattern, char *file) -{ - /* oh what a weird world this is */ - if (old_list && strcmp(pattern, "*.*") == 0) return True; - - if (strcmp(pattern,".") == 0) return False; - - if (max_protocol <= PROTOCOL_LANMAN2) { - return ms_fnmatch_lanman(pattern, file)==0; - } - - if (strcmp(file,"..") == 0) file = "."; - - return ms_fnmatch(pattern, file)==0; -} - -static char *reg_test(char *pattern, char *long_name, char *short_name) -{ - static fstring ret; - fstrcpy(ret, "---"); - - pattern = 1+strrchr(pattern,'\\'); - - if (reg_match_one(pattern, ".")) ret[0] = '+'; - if (reg_match_one(pattern, "..")) ret[1] = '+'; - if (reg_match_one(pattern, long_name) || - (*short_name && reg_match_one(pattern, short_name))) ret[2] = '+'; - return ret; -} - - -/***************************************************** -return a connection to a server -*******************************************************/ -struct cli_state *connect_one(char *share) -{ - struct cli_state *c; - struct nmb_name called, calling; - char *server_n; - char *server; - struct in_addr ip; - extern struct in_addr ipzero; - - server = share+2; - share = strchr(server,'\\'); - if (!share) return NULL; - *share = 0; - share++; - - server_n = server; - - ip = ipzero; - - make_nmb_name(&calling, "masktest", 0x0); - make_nmb_name(&called , server, 0x20); - - again: - ip = ipzero; - - /* have to open a new connection */ - if (!(c=cli_initialise(NULL)) || (cli_set_port(c, 139) == 0) || - !cli_connect(c, server_n, &ip)) { - DEBUG(0,("Connection to %s failed\n", server_n)); - return NULL; - } - - c->protocol = max_protocol; - - 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) { - pstrcpy(password, pass); - } - } - - if (!cli_session_setup(c, username, - password, strlen(password), - password, strlen(password), - 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, strlen(password)+1)) { - DEBUG(0,("tree connect failed: %s\n", cli_errstr(c))); - cli_shutdown(c); - return NULL; - } - - DEBUG(4,(" tconx ok\n")); - - return c; -} - -static char *resultp; -static file_info *finfo; - -void listfn(file_info *f, const char *s, void *state) -{ - if (strcmp(f->name,".") == 0) { - resultp[0] = '+'; - } else if (strcmp(f->name,"..") == 0) { - resultp[1] = '+'; - } else { - resultp[2] = '+'; - } - finfo = f; -} - -static void get_real_name(struct cli_state *cli, - pstring long_name, fstring short_name) -{ - /* nasty hack to force level 260 listings - tridge */ - cli->capabilities |= CAP_NT_SMBS; - if (max_protocol <= PROTOCOL_LANMAN1) { - cli_list_new(cli, "\\masktest\\*.*", aHIDDEN | aDIR, listfn, NULL); - } else { - cli_list_new(cli, "\\masktest\\*", aHIDDEN | aDIR, listfn, NULL); - } - if (finfo) { - fstrcpy(short_name, finfo->short_name); - strlower(short_name); - pstrcpy(long_name, finfo->name); - strlower(long_name); - } - - if (*short_name == 0) { - fstrcpy(short_name, long_name); - } - -#if 0 - if (!strchr(short_name,'.')) { - fstrcat(short_name,"."); - } -#endif -} - -static void testpair(struct cli_state *cli, char *mask, char *file) -{ - int fnum; - fstring res1; - char *res2; - static int count; - fstring short_name; - pstring long_name; - - count++; - - fstrcpy(res1, "---"); - - fnum = cli_open(cli, file, O_CREAT|O_TRUNC|O_RDWR, 0); - if (fnum == -1) { - DEBUG(0,("Can't create %s\n", file)); - return; - } - cli_close(cli, fnum); - - resultp = res1; - fstrcpy(short_name, ""); - finfo = NULL; - get_real_name(cli, long_name, short_name); - finfo = NULL; - fstrcpy(res1, "---"); - cli_list(cli, mask, aHIDDEN | aDIR, listfn, NULL); - - res2 = reg_test(mask, long_name, short_name); - - if (showall || strcmp(res1, res2)) { - DEBUG(0,("%s %s %d mask=[%s] file=[%s] rfile=[%s/%s]\n", - res1, res2, count, mask, file, long_name, short_name)); - if (die_on_error) exit(1); - } - - cli_unlink(cli, file); - - if (count % 100 == 0) DEBUG(0,("%d\n", count)); -} - -static void test_mask(int argc, char *argv[], - struct cli_state *cli) -{ - pstring mask, file; - int l1, l2, i, l; - int mc_len = strlen(maskchars); - int fc_len = strlen(filechars); - - cli_mkdir(cli, "\\masktest"); - - cli_unlink(cli, "\\masktest\\*"); - - if (argc >= 2) { - while (argc >= 2) { - pstrcpy(mask,"\\masktest\\"); - pstrcpy(file,"\\masktest\\"); - pstrcat(mask, argv[0]); - pstrcat(file, argv[1]); - testpair(cli, mask, file); - argv += 2; - argc -= 2; - } - goto finished; - } - - while (1) { - l1 = 1 + random() % 20; - l2 = 1 + random() % 20; - pstrcpy(mask,"\\masktest\\"); - pstrcpy(file,"\\masktest\\"); - l = strlen(mask); - for (i=0;i<l1;i++) { - mask[i+l] = maskchars[random() % mc_len]; - } - mask[l+l1] = 0; - - for (i=0;i<l2;i++) { - file[i+l] = filechars[random() % fc_len]; - } - file[l+l2] = 0; - - if (strcmp(file+l,".") == 0 || - strcmp(file+l,"..") == 0 || - strcmp(mask+l,"..") == 0) continue; - - if (strspn(file+l, ".") == strlen(file+l)) continue; - - testpair(cli, mask, file); - } - - finished: - cli_rmdir(cli, "\\masktest"); -} - - -static void usage(void) -{ - printf( -"Usage:\n\ - masktest //server/share [options..]\n\ - options:\n\ - -W workgroup\n\ - -U user%%pass\n\ - -s seed\n\ - -f filechars (default %s)\n\ - -m maskchars (default %s)\n\ - -a show all tests\n\ -\n\ - This program tests wildcard matching between two servers. It generates\n\ - random pairs of filenames/masks and tests that they match in the same\n\ - way on the servers and internally\n\ -", - filechars, maskchars); -} - -/**************************************************************************** - main program -****************************************************************************/ - int main(int argc,char *argv[]) -{ - char *share; - struct cli_state *cli; - extern char *optarg; - extern int optind; - extern FILE *dbf; - int opt; - char *p; - int seed; - static pstring servicesf = CONFIGFILE; - - setlinebuf(stdout); - - dbf = stderr; - - if (argv[1][0] == '-' || argc < 2) { - usage(); - exit(1); - } - - share = argv[1]; - - all_string_sub(share,"/","\\",0); - - setup_logging(argv[0],True); - - argc -= 1; - argv += 1; - - TimeInit(); - charset_initialise(); - codepage_initialise(lp_client_code_page()); - - lp_load(servicesf,True,False,False); - load_interfaces(); - - if (getenv("USER")) { - pstrcpy(username,getenv("USER")); - } - - seed = time(NULL); - - while ((opt = getopt(argc, argv, "U:s:hm:f:aoW:M:vE")) != EOF) { - switch (opt) { - case 'E': - die_on_error = 1; - break; - case 'v': - verbose++; - break; - case 'M': - max_protocol = interpret_protocol(optarg, max_protocol); - break; - case 'U': - pstrcpy(username,optarg); - p = strchr(username,'%'); - if (p) { - *p = 0; - pstrcpy(password, p+1); - got_pass = 1; - } - break; - case 's': - seed = atoi(optarg); - break; - case 'h': - usage(); - exit(1); - case 'm': - maskchars = optarg; - break; - case 'f': - filechars = optarg; - break; - case 'a': - showall = 1; - break; - case 'o': - old_list = True; - break; - default: - printf("Unknown option %c (%d)\n", (char)opt, opt); - exit(1); - } - } - - argc -= optind; - argv += optind; - - - cli = connect_one(share); - if (!cli) { - DEBUG(0,("Failed to connect to %s\n", share)); - exit(1); - } - - /* need to init seed after connect as clientgen uses random numbers */ - DEBUG(0,("seed=%d\n", seed)); - srandom(seed); - - test_mask(argc, argv, cli); - - return(0); -} diff --git a/source3/utils/msgtest.c b/source3/utils/msgtest.c deleted file mode 100644 index 3fbf95af8f..0000000000 --- a/source3/utils/msgtest.c +++ /dev/null @@ -1,96 +0,0 @@ -/* - Unix SMB/Netbios implementation. - Version 3.0 - Copyright (C) Andrew Tridgell 2000 - - 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. -*/ - -/* - test code for internal messaging - */ - -#define NO_SYSLOG - -#include "includes.h" - -static int pong_count; - -/**************************************************************************** -a useful function for testing the message system -****************************************************************************/ -void pong_message(int msg_type, pid_t src, void *buf, size_t len) -{ - pong_count++; -} - - int main(int argc, char *argv[]) -{ - pid_t pid; - int i, n; - static pstring servicesf = CONFIGFILE; - char buf[12]; - - TimeInit(); - setup_logging(argv[0],True); - - charset_initialise(); - - lp_load(servicesf,False,False,False); - - message_init(); - - if (argc != 3) { - fprintf(stderr, "%s: Usage - %s pid count\n", argv[0], argv[0]); - exit(1); - } - - pid = atoi(argv[1]); - n = atoi(argv[2]); - - message_register(MSG_PONG, pong_message); - - for (i=0;i<n;i++) { - message_send_pid(pid, MSG_PING, NULL, 0, True); - } - - while (pong_count < i) { - message_dispatch(); - msleep(1); - } - - /* Now test that the duplicate filtering code works. */ - pong_count = 0; - - safe_strcpy(buf, "1234567890", sizeof(buf)-1); - - for (i=0;i<n;i++) { - message_send_pid(getpid(), MSG_PING, NULL, 0, False); - message_send_pid(getpid(), MSG_PING, buf, 11, False); - } - - for (i=0;i<n;i++) { - message_dispatch(); - msleep(1); - } - - if (pong_count != 2) { - fprintf(stderr, "Duplicate filter failed (%d).\n", pong_count); - exit(1); - } - - return (0); -} - diff --git a/source3/utils/nbio.c b/source3/utils/nbio.c deleted file mode 100644 index 4866e52d4e..0000000000 --- a/source3/utils/nbio.c +++ /dev/null @@ -1,240 +0,0 @@ -#define NBDEBUG 0 - -/* - Unix SMB/Netbios implementation. - Version 1.9. - SMB torture tester - Copyright (C) Andrew Tridgell 1997-1998 - - 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. -*/ - -#define NO_SYSLOG - -#include "includes.h" - -#define MAX_FILES 1000 - -static char buf[70000]; -extern int line_count; - -static struct { - int fd; - int handle; -} ftable[MAX_FILES]; - -static struct cli_state *c; - -static void sigsegv(int sig) -{ - char line[200]; - printf("segv at line %d\n", line_count); - slprintf(line, sizeof(line), "/usr/X11R6/bin/xterm -e gdb /proc/%d/exe %d", - (int)getpid(), (int)getpid()); - system(line); - exit(1); -} - -void nb_setup(struct cli_state *cli) -{ - signal(SIGSEGV, sigsegv); - c = cli; -} - - -void nb_unlink(char *fname) -{ - strupper(fname); - - if (!cli_unlink(c, fname)) { -#if NBDEBUG - printf("(%d) unlink %s failed (%s)\n", - line_count, fname, cli_errstr(c)); -#endif - } -} - -void nb_open(char *fname, int handle, int size) -{ - int fd, i; - int flags = O_RDWR|O_CREAT; - size_t st_size; - static int count; - - strupper(fname); - - if (size == 0) flags |= O_TRUNC; - - fd = cli_open(c, fname, flags, DENY_NONE); - if (fd == -1) { -#if NBDEBUG - printf("(%d) open %s failed for handle %d (%s)\n", - line_count, fname, handle, cli_errstr(c)); -#endif - return; - } - cli_getattrE(c, fd, NULL, &st_size, NULL, NULL, NULL); - if (size > st_size) { -#if NBDEBUG - printf("(%d) needs expanding %s to %d from %d\n", - line_count, fname, size, (int)st_size); -#endif - } else if (size < st_size) { -#if NBDEBUG - printf("(%d) needs truncating %s to %d from %d\n", - line_count, fname, size, (int)st_size); -#endif - } - for (i=0;i<MAX_FILES;i++) { - if (ftable[i].handle == 0) break; - } - if (i == MAX_FILES) { - printf("file table full for %s\n", fname); - exit(1); - } - ftable[i].handle = handle; - ftable[i].fd = fd; - if (count++ % 100 == 0) { - printf("."); - } -} - -void nb_write(int handle, int size, int offset) -{ - int i; - - if (buf[0] == 0) memset(buf, 1, sizeof(buf)); - - for (i=0;i<MAX_FILES;i++) { - if (ftable[i].handle == handle) break; - } - if (i == MAX_FILES) { -#if NBDEBUG - printf("(%d) nb_write: handle %d was not open size=%d ofs=%d\n", - line_count, handle, size, offset); -#endif - return; - } - if (cli_smbwrite(c, ftable[i].fd, buf, offset, size) != size) { - printf("(%d) write failed on handle %d, fd %d \ -errno %d (%s)\n", line_count, handle, ftable[i].fd, errno, strerror(errno)); - if (errno == ENOSPC) { - printf("Halting.\n"); - fflush(stdout); - fflush(stderr); - exit(3); - } - } -} - -void nb_read(int handle, int size, int offset) -{ - int i, ret; - - for (i=0;i<MAX_FILES;i++) { - if (ftable[i].handle == handle) break; - } - if (i == MAX_FILES) { - printf("(%d) nb_read: handle %d was not open size=%d ofs=%d\n", - line_count, handle, size, offset); - return; - } - if ((ret=cli_read(c, ftable[i].fd, buf, offset, size)) != size) { -#if NBDEBUG - printf("(%d) read failed on handle %d ofs=%d size=%d res=%d fd %d errno %d (%s)\n", - line_count, handle, offset, size, ret, ftable[i].fd, errno, strerror(errno)); -#endif - } -} - -void nb_close(int handle) -{ - int i; - for (i=0;i<MAX_FILES;i++) { - if (ftable[i].handle == handle) break; - } - if (i == MAX_FILES) { - printf("(%d) nb_close: handle %d was not open\n", - line_count, handle); - return; - } - cli_close(c, ftable[i].fd); - ftable[i].handle = 0; -} - -void nb_mkdir(char *fname) -{ - strupper(fname); - - if (!cli_mkdir(c, fname)) { -#if NBDEBUG - printf("mkdir %s failed (%s)\n", - fname, cli_errstr(c)); -#endif - } -} - -void nb_rmdir(char *fname) -{ - strupper(fname); - - if (!cli_rmdir(c, fname)) { -#if NBDEBUG - printf("rmdir %s failed (%s)\n", - fname, cli_errstr(c)); -#endif - } -} - -void nb_rename(char *old, char *new) -{ - strupper(old); - strupper(new); - - if (!cli_rename(c, old, new)) { -#if NBDEBUG - printf("rename %s %s failed (%s)\n", - old, new, cli_errstr(c)); -#endif - } -} - - -void nb_stat(char *fname, int size) -{ - size_t st_size; - - strupper(fname); - - if (!cli_getatr(c, fname, NULL, &st_size, NULL)) { -#if NBDEBUG - printf("(%d) nb_stat: %s size=%d %s\n", - line_count, fname, size, cli_errstr(c)); -#endif - return; - } - if (st_size != size) { -#if NBDEBUG - printf("(%d) nb_stat: %s wrong size %d %d\n", - line_count, fname, (int)st_size, size); -#endif - } -} - -void nb_create(char *fname, int size) -{ - nb_open(fname, 5000, size); - nb_close(5000); -} diff --git a/source3/utils/rpctorture.c b/source3/utils/rpctorture.c deleted file mode 100644 index c80cfe4ade..0000000000 --- a/source3/utils/rpctorture.c +++ /dev/null @@ -1,559 +0,0 @@ -/* - Unix SMB/Netbios implementation. - Version 1.9. - SMB client - Copyright (C) Andrew Tridgell 1994-1998 - - 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. -*/ - -#ifdef SYSLOG -#undef SYSLOG -#endif - -#include "includes.h" - -#ifndef REGISTER -#define REGISTER 0 -#endif - -extern pstring global_myname; - -extern pstring user_socket_options; - - -extern pstring debugf; -extern int DEBUGLEVEL; - - -extern file_info def_finfo; - -#define CNV_LANG(s) dos2unix_format(s,False) -#define CNV_INPUT(s) unix2dos_format(s,True) - -static struct cli_state smbcli; -struct cli_state *smb_cli = &smbcli; - -FILE *out_hnd; - -static pstring password; /* local copy only, if one is entered */ - -/**************************************************************************** -initialise smb client structure -****************************************************************************/ -void rpcclient_init(void) -{ - memset((char *)smb_cli, '\0', sizeof(smb_cli)); - cli_initialise(smb_cli); - smb_cli->capabilities |= CAP_NT_SMBS; -} - -/**************************************************************************** -make smb client connection -****************************************************************************/ -static BOOL rpcclient_connect(struct client_info *info) -{ - struct nmb_name calling; - struct nmb_name called; - - make_nmb_name(&called , dns_to_netbios_name(info->dest_host ), info->name_type); - make_nmb_name(&calling, dns_to_netbios_name(info->myhostname), 0x0); - - if (!cli_establish_connection(smb_cli, - info->dest_host, &info->dest_ip, - &calling, &called, - info->share, info->svc_type, - False, True)) - { - DEBUG(0,("rpcclient_connect: connection failed\n")); - cli_shutdown(smb_cli); - return False; - } - - return True; -} - -/**************************************************************************** -stop the smb connection(s?) -****************************************************************************/ -static void rpcclient_stop(void) -{ - cli_shutdown(smb_cli); -} - -/**************************************************************************** - log in as an nt user, log out again. -****************************************************************************/ -void run_enums_test(int num_ops, struct client_info *cli_info, struct cli_state *cli) -{ - pstring cmd; - int i; - - /* establish connections. nothing to stop these being re-established. */ - rpcclient_connect(cli_info); - - DEBUG(5,("rpcclient_connect: cli->fd:%d\n", cli->fd)); - if (cli->fd <= 0) - { - fprintf(out_hnd, "warning: connection could not be established to %s<%02x>\n", - cli_info->dest_host, cli_info->name_type); - return; - } - - for (i = 0; i < num_ops; i++) - { - set_first_token(""); - cmd_srv_enum_sess(cli_info); - set_first_token(""); - cmd_srv_enum_shares(cli_info); - set_first_token(""); - cmd_srv_enum_files(cli_info); - - if (password[0] != 0) - { - slprintf(cmd, sizeof(cmd)-1, "1"); - set_first_token(cmd); - } - else - { - set_first_token(""); - } - cmd_srv_enum_conn(cli_info); - } - - rpcclient_stop(); - -} - -/**************************************************************************** - log in as an nt user, log out again. -****************************************************************************/ -void run_ntlogin_test(int num_ops, struct client_info *cli_info, struct cli_state *cli) -{ - pstring cmd; - int i; - - /* establish connections. nothing to stop these being re-established. */ - rpcclient_connect(cli_info); - - DEBUG(5,("rpcclient_connect: cli->fd:%d\n", cli->fd)); - if (cli->fd <= 0) - { - fprintf(out_hnd, "warning: connection could not be established to %s<%02x>\n", - cli_info->dest_host, cli_info->name_type); - return; - } - - for (i = 0; i < num_ops; i++) - { - slprintf(cmd, sizeof(cmd)-1, "%s %s", cli->user_name, password); - set_first_token(cmd); - - cmd_netlogon_login_test(cli_info); - } - - rpcclient_stop(); - -} - -/**************************************************************************** - runs n simultaneous functions. -****************************************************************************/ -static void create_procs(int nprocs, int numops, - struct client_info *cli_info, struct cli_state *cli, - void (*fn)(int, struct client_info *, struct cli_state *)) -{ - int i, status; - - for (i=0;i<nprocs;i++) - { - if (fork() == 0) - { - pid_t mypid = getpid(); - sys_srandom(mypid ^ time(NULL)); - fn(numops, cli_info, cli); - fflush(out_hnd); - _exit(0); - } - } - - for (i=0;i<nprocs;i++) - { - waitpid(0, &status, 0); - } -} -/**************************************************************************** -usage on the program - OUT OF DATE! -****************************************************************************/ -static void usage(char *pname) -{ - fprintf(out_hnd, "Usage: %s service <password> [-d debuglevel] [-l log] ", - pname); - - fprintf(out_hnd, "\nVersion %s\n",VERSION); - fprintf(out_hnd, "\t-d debuglevel set the debuglevel\n"); - fprintf(out_hnd, "\t-l log basename. Basename for log/debug files\n"); - fprintf(out_hnd, "\t-n netbios name. Use this name as my netbios name\n"); - fprintf(out_hnd, "\t-m max protocol set the max protocol level\n"); - fprintf(out_hnd, "\t-I dest IP use this IP to connect to\n"); - fprintf(out_hnd, "\t-E write messages to stderr instead of stdout\n"); - fprintf(out_hnd, "\t-U username set the network username\n"); - fprintf(out_hnd, "\t-W workgroup set the workgroup name\n"); - fprintf(out_hnd, "\t-t terminal code terminal i/o code {sjis|euc|jis7|jis8|junet|hex}\n"); - fprintf(out_hnd, "\n"); -} - -enum client_action -{ - CLIENT_NONE, - CLIENT_IPC, - CLIENT_SVC -}; - -/**************************************************************************** - main program -****************************************************************************/ - int main(int argc,char *argv[]) -{ - char *pname = argv[0]; - int opt; - extern FILE *dbf; - extern char *optarg; - extern int optind; - static pstring servicesf = CONFIGFILE; - pstring term_code; - BOOL got_pass = False; - char *cmd_str=""; - mode_t myumask = 0755; - enum client_action cli_action = CLIENT_NONE; - int nprocs = 1; - int numops = 100; - - struct client_info cli_info; - - out_hnd = stdout; - - rpcclient_init(); - -#ifdef KANJI - pstrcpy(term_code, KANJI); -#else /* KANJI */ - *term_code = 0; -#endif /* KANJI */ - - if (!lp_load(servicesf,True, False, False)) - { - fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); - } - - codepage_initialise(lp_client_code_page()); - - DEBUGLEVEL = 0; - - cli_info.put_total_size = 0; - cli_info.put_total_time_ms = 0; - cli_info.get_total_size = 0; - cli_info.get_total_time_ms = 0; - - cli_info.dir_total = 0; - cli_info.newer_than = 0; - cli_info.archive_level = 0; - cli_info.print_mode = 1; - - cli_info.translation = False; - cli_info.recurse_dir = False; - cli_info.lowercase = False; - cli_info.prompt = True; - cli_info.abort_mget = True; - - cli_info.dest_ip.s_addr = 0; - cli_info.name_type = 0x20; - - pstrcpy(cli_info.cur_dir , "\\"); - pstrcpy(cli_info.file_sel, ""); - pstrcpy(cli_info.base_dir, ""); - pstrcpy(smb_cli->domain, ""); - pstrcpy(smb_cli->user_name, ""); - pstrcpy(cli_info.myhostname, ""); - pstrcpy(cli_info.dest_host, ""); - - pstrcpy(cli_info.svc_type, "A:"); - pstrcpy(cli_info.share, ""); - pstrcpy(cli_info.service, ""); - - ZERO_STRUCT(cli_info.dom.level3_sid); - pstrcpy(cli_info.dom.level3_dom, ""); - ZERO_STRUCT(cli_info.dom.level5_sid); - pstrcpy(cli_info.dom.level5_dom, ""); - - smb_cli->nt_pipe_fnum = 0xffff; - - setup_logging(pname, True); - - TimeInit(); - charset_initialise(); - - myumask = umask(0); - umask(myumask); - - if (!get_myname(global_myname)) - { - fprintf(stderr, "Failed to get my hostname.\n"); - } - - password[0] = 0; - - if (argc < 2) - { - usage(pname); - exit(1); - } - - if (*argv[1] != '-') - { - pstrcpy(cli_info.service, argv[1]); - /* Convert any '/' characters in the service name to '\' characters */ - string_replace( cli_info.service, '/','\\'); - argc--; - argv++; - - DEBUG(1,("service: %s\n", cli_info.service)); - - if (count_chars(cli_info.service,'\\') < 3) - { - usage(pname); - printf("\n%s: Not enough '\\' characters in service\n", cli_info.service); - exit(1); - } - - /* - if (count_chars(cli_info.service,'\\') > 3) - { - usage(pname); - printf("\n%s: Too many '\\' characters in service\n", cli_info.service); - exit(1); - } - */ - - if (argc > 1 && (*argv[1] != '-')) - { - got_pass = True; - pstrcpy(password,argv[1]); - memset(argv[1],'X',strlen(argv[1])); - argc--; - argv++; - } - - cli_action = CLIENT_SVC; - } - - while ((opt = getopt(argc, argv,"s:O:M:S:i:N:o:n:d:l:hI:EB:U:L:t:m:W:T:D:c:")) != EOF) - { - switch (opt) - { - case 'm': - { - /* FIXME ... max_protocol seems to be funny here */ - - int max_protocol = 0; - max_protocol = interpret_protocol(optarg,max_protocol); - fprintf(stderr, "max protocol not currently supported\n"); - break; - } - - case 'O': - { - pstrcpy(user_socket_options,optarg); - break; - } - - case 'S': - { - pstrcpy(cli_info.dest_host,optarg); - strupper(cli_info.dest_host); - cli_action = CLIENT_IPC; - break; - } - - case 'i': - { - pstrcpy(scope, optarg); - break; - } - - case 'U': - { - char *lp; - pstrcpy(smb_cli->user_name,optarg); - if ((lp=strchr(smb_cli->user_name,'%'))) - { - *lp = 0; - pstrcpy(password,lp+1); - got_pass = True; - memset(strchr(optarg,'%')+1,'X',strlen(password)); - } - break; - } - - case 'W': - { - pstrcpy(smb_cli->domain,optarg); - break; - } - - case 'E': - { - dbf = stderr; - break; - } - - case 'I': - { - cli_info.dest_ip = *interpret_addr2(optarg); - if (zero_ip(cli_info.dest_ip)) - { - exit(1); - } - break; - } - - case 'N': - { - nprocs = atoi(optarg); - break; - } - - case 'o': - { - numops = atoi(optarg); - break; - } - - case 'n': - { - fstrcpy(global_myname, optarg); - break; - } - - case 'd': - { - if (*optarg == 'A') - DEBUGLEVEL = 10000; - else - DEBUGLEVEL = atoi(optarg); - break; - } - - case 'l': - { - slprintf(debugf, sizeof(debugf)-1, - "%s.client",optarg); - break; - } - - case 'c': - { - cmd_str = optarg; - got_pass = True; - break; - } - - case 'h': - { - usage(pname); - exit(0); - break; - } - - case 's': - { - pstrcpy(servicesf, optarg); - break; - } - - case 't': - { - pstrcpy(term_code, optarg); - break; - } - - default: - { - usage(pname); - exit(1); - break; - } - } - } - - if (cli_action == CLIENT_NONE) - { - usage(pname); - exit(1); - } - - strupper(global_myname); - fstrcpy(cli_info.myhostname, global_myname); - - DEBUG(3,("%s client started (version %s)\n",timestring(False),VERSION)); - - if (*smb_cli->domain == 0) - { - pstrcpy(smb_cli->domain,lp_workgroup()); - } - strupper(smb_cli->domain); - - load_interfaces(); - - if (cli_action == CLIENT_IPC) - { - pstrcpy(cli_info.share, "IPC$"); - pstrcpy(cli_info.svc_type, "IPC"); - } - - fstrcpy(cli_info.mach_acct, cli_info.myhostname); - strupper(cli_info.mach_acct); - fstrcat(cli_info.mach_acct, "$"); - - /* set the password cache info */ - if (got_pass) - { - if (password[0] == 0) - { - pwd_set_nullpwd(&(smb_cli->pwd)); - } - else - { - pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */ - } - } - else - { - char *pwd = getpass("Enter Password:"); - safe_strcpy(password, pwd, sizeof(password)); - pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */ - } - - create_procs(nprocs, numops, &cli_info, smb_cli, run_enums_test); - - if (password[0] != 0) - { - create_procs(nprocs, numops, &cli_info, smb_cli, run_ntlogin_test); - } - - fflush(out_hnd); - - return(0); -} |