From 3db52feb1f3b2c07ce0b06ad4a7099fa6efe3fc7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 13 Dec 1999 13:27:58 +0000 Subject: first pass at updating head branch to be to be the same as the SAMBA_2_0 branch (This used to be commit 453a822a76780063dff23526c35408866d0c0154) --- source3/utils/debug2html.c | 182 +++----- source3/utils/make_printerdef.c | 7 + source3/utils/make_smbcodepage.c | 10 +- source3/utils/nmblookup.c | 151 +++--- source3/utils/rpctorture.c | 515 +++------------------ source3/utils/smbfilter.c | 6 +- source3/utils/smbpasswd.c | 521 +++++++-------------- source3/utils/smbrun.c | 28 +- source3/utils/status.c | 132 +++--- source3/utils/testparm.c | 247 +++++++--- source3/utils/torture.c | 959 ++++++++++++++++++++++++--------------- 11 files changed, 1224 insertions(+), 1534 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/debug2html.c b/source3/utils/debug2html.c index ef7201168f..f9a1f43f46 100644 --- a/source3/utils/debug2html.c +++ b/source3/utils/debug2html.c @@ -28,19 +28,36 @@ * does a decent job of converting Samba logs into HTML. * -------------------------------------------------------------------------- ** * - * $Revision: 1.9 $ + * Revision 1.4 1998/11/13 03:37:01 tridge + * fixes for OSF1 compilation + * + * Revision 1.3 1998/10/28 20:33:35 crh + * I've moved the debugparse module files into the ubiqx directory because I + * know that 'make proto' will ignore them there. The debugparse.h header + * file is included in includes.h, and includes.h is included in debugparse.c, + * so all of the pieces "see" each other. I've compiled and tested this, + * and it does seem to work. It's the same compromise model I used when + * adding the ubiqx modules into the system, which is why I put it all into + * the same directory. + * + * Chris -)----- + * + * Revision 1.1 1998/10/26 23:21:37 crh + * Here is the simple debug parser and the debug2html converter. Still to do: + * + * * Debug message filtering. + * * I need to add all this to Makefile.in + * (If it looks at all strange I'll ask for help.) + * + * If you want to compile debug2html, you'll need to do it by hand until I + * make the changes to Makefile.in. Sorry. + * + * Chris -)----- * * ========================================================================== ** */ -#include "includes.h" - -/* -------------------------------------------------------------------------- ** - * Global values. - */ - -FILE *infile; -FILE *outfile; +#include "debugparse.h" /* -------------------------------------------------------------------------- ** * The size of the read buffer. @@ -81,7 +98,7 @@ static dbg_Token modechange( dbg_Token new, dbg_Token mode ) if( dbg_message != mode ) { /* Switching to message mode. */ - (void)fprintf( outfile, "
\n" );
+        (void)printf( "
\n" );
         return( dbg_message );
         }
       break;
@@ -89,7 +106,7 @@ static dbg_Token modechange( dbg_Token new, dbg_Token mode )
       if( dbg_message == mode )
         {
         /* Switching out of message mode. */
-        (void)fprintf( outfile, "
\n\n" ); + (void)printf( "
\n\n" ); return( dbg_null ); } } @@ -117,33 +134,29 @@ static void newblock( dbg_Token old, dbg_Token new ) switch( old ) { case dbg_timestamp: - (void)fprintf( outfile, "," ); + (void)printf( "," ); break; case dbg_level: - (void)fprintf( outfile, "]\n " ); + (void)printf( "]\n " ); break; case dbg_sourcefile: - (void)fprintf( outfile, ":" ); + (void)printf( ":" ); break; case dbg_lineno: - (void)fprintf( outfile, ")" ); - break; - default: + (void)printf( ")" ); break; } switch( new ) { case dbg_timestamp: - (void)fprintf( outfile, "[" ); + (void)printf( "[" ); break; case dbg_level: - (void)fprintf( outfile, " " ); + (void)printf( " " ); break; case dbg_lineno: - (void)fprintf( outfile, "(" ); - break; - default: + (void)printf( "(" ); break; } } /* newblock */ @@ -167,38 +180,41 @@ static void charprint( dbg_Token tok, int c ) break; case dbg_null: case dbg_eof: - (void)putc( '\n', outfile ); + (void)putchar( '\n' ); break; default: switch( c ) { case '<': - (void)fprintf( outfile, "<" ); + (void)printf( "<" ); break; case '>': - (void)fprintf( outfile, ">" ); + (void)printf( ">" ); break; case '&': - (void)fprintf( outfile, "&" ); + (void)printf( "&" ); break; case '\"': - (void)fprintf( outfile, """ ); + (void)printf( """ ); break; default: - (void)putc( c, outfile ); + (void)putchar( c ); break; } } } /* charprint */ -static void convert( void ) +int main( int argc, char *argv[] ) /* ------------------------------------------------------------------------ ** - * Read the input logfile, converting the entries to HTML. + * This simple program scans and parses Samba debug logs, and produces HTML + * output. + * + * Input: argc - Currently ignored. + * argv - Currently ignored. + * + * Output: Always zero. * - * Input: none. - * output: none. - * Notes: Reads from the global infile, writes to the global outfile. - * These default to stdin and stdout, respectively. + * Notes: The HTML output is sent to stdout. * * ------------------------------------------------------------------------ ** */ @@ -211,8 +227,12 @@ static void convert( void ) state = dbg_null, mode = dbg_null; - while( (!feof( infile )) - && ((len = fread( bufr, 1, DBG_BSIZE, infile )) > 0) ) + (void)printf( "\n" ); + (void)printf( "\n\n" ); + (void)printf( " Samba Debug Output\n\n\n\n" ); + + while( (!feof( stdin )) + && ((len = fread( bufr, 1, DBG_BSIZE, stdin )) > 0) ) { for( i = 0; i < len; i++ ) { @@ -228,94 +248,6 @@ static void convert( void ) } (void)modechange( dbg_eof, mode ); - } /* convert */ - -static void usage( void ) - /* ------------------------------------------------------------------------ ** - * Prints a usage message on stderr, then gently exits. - * - * Input: none. - * Output: none. Exits with return code of 0. - * - * ------------------------------------------------------------------------ ** - */ - { - fprintf( stderr, "This utility converts Samba log files " ); - fprintf( stderr, "into HTML documents.\n" ); - fprintf( stderr, "Usage:\n" ); - fprintf( stderr, " debug2html \n" ); - exit( 0 ); - } /* usage */ - -static FILE *carefull_fopen( const char *path, const char *type ) - /* ------------------------------------------------------------------------ ** - * Checks for leading '-' characters, which are generically regarded as - * flags. Also exits the program gracefully should the file fail to open. - * - * Input: path - pathname of the file to open. - * type - open mode. See fopen(3S). - * - * Output: Pointer to open file. - * - * ------------------------------------------------------------------------ ** - */ - { - FILE *tmp; - - if( '-' == path[0] || '\0' == path[0] ) - usage(); - - tmp = sys_fopen( path, type ); - if( NULL == tmp ) - { - fprintf( stderr, "Error opening file %s: %s\n", path, strerror(errno) ); - exit( 1 ); - } - return( tmp ); - } /* carefull_fopen */ - -int main( int argc, char *argv[] ) - /* ------------------------------------------------------------------------ ** - * This simple program scans and parses Samba debug logs, and produces HTML - * output. - * - * Input: argc - Argument count. - * argv[1] - Input file name. - * argv[2] - Output file name. - * A '-' character by itself means use defaults (i.e., - * or depending upon the argument. - * A string beginning with '-' and containing more than - * that one character will generate a usage message. - * - * Output: An exit value of 1 is returned if an error was encountered - * while opening a file, else 0. - * - * Notes: The HTML output is sent to stdout. - * - * ------------------------------------------------------------------------ ** - */ - { - if( argc > 3 ) - usage(); - - infile = stdin; - outfile = stdout; - - if( argc > 1 && 0 != strcmp( argv[1], "-" ) ) - infile = carefull_fopen( argv[1], "r" ); - - if( argc > 2 && 0 != strcmp( argv[2], "-" ) ) - infile = carefull_fopen( argv[2], "w" ); - - (void)fprintf( outfile, - "\n" ); - (void)fprintf( outfile, "\n\n" ); - (void)fprintf( outfile, - " Samba Log\n\n\n\n" ); - - convert(); - - (void)fprintf( outfile, "\n\n" ); - + (void)printf( "\n\n" ); return( 0 ); } /* main */ diff --git a/source3/utils/make_printerdef.c b/source3/utils/make_printerdef.c index 68b603bf1f..fc1f8ad781 100644 --- a/source3/utils/make_printerdef.c +++ b/source3/utils/make_printerdef.c @@ -176,6 +176,13 @@ static void lookup_strings(FILE *fichier) pointeur++; } } + + /* CCMRCF Mod, seg fault or worse if not found */ + if (pointeur == 0) { + fprintf(stderr,"Printer not found\tNo [Strings] block in inf file\n"); + exit(2); + } + #ifdef DEBUGIT fprintf(stderr,"\t\tFound %d entries\n",pointeur-1); #endif diff --git a/source3/utils/make_smbcodepage.c b/source3/utils/make_smbcodepage.c index a57af2fc44..f0b68a7bae 100644 --- a/source3/utils/make_smbcodepage.c +++ b/source3/utils/make_smbcodepage.c @@ -3,7 +3,7 @@ Version 1.9. Create codepage files from codepage_def.XXX files. - Copyright (C) Jeremy Allison 1997-1998. + Copyright (C) Jeremy Allison 1997-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 @@ -62,7 +62,7 @@ static void read_line( char **buf, char *line_buf, int size) * Returns the number of lines copied. */ -static int clean_data( char **buf, uint32 *size) +static int clean_data( char **buf, size_t *size) { pstring linebuf; char *p = *buf; @@ -165,7 +165,7 @@ static void parse_error(char *buf, char *msg) static int do_compile(int codepage, char *input_file, char *output_file) { FILE *fp = NULL; - uint32 size = 0; + size_t size = 0; char *buf = NULL; char output_buf[CODEPAGE_HEADER_SIZE + 4 * MAXCODEPAGELINES]; int num_lines = 0; @@ -309,7 +309,7 @@ definition file. File %s has %d.\n", prog_name, MAXCODEPAGELINES, input_file, nu static int do_decompile( int codepage, char *input_file, char *output_file) { - uint32 size = 0; + size_t size = 0; SMB_STRUCT_STAT st; char header_buf[CODEPAGE_HEADER_SIZE]; char *buf = NULL; @@ -325,7 +325,7 @@ static int do_decompile( int codepage, char *input_file, char *output_file) exit(1); } - size = (uint32)st.st_size; + size = (size_t)st.st_size; if( size < CODEPAGE_HEADER_SIZE || size > (CODEPAGE_HEADER_SIZE + 256)) { diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index f920106f75..2f9bbc6c53 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -28,48 +28,37 @@ extern int DEBUGLEVEL; extern pstring scope; -extern pstring myhostname; extern struct in_addr ipzero; -int ServerFD= -1; - -BOOL RootPort = False; +static BOOL use_bcast = True; +static BOOL got_bcast = False; +static struct in_addr bcast_addr; +static BOOL recursion_desired = False; +static BOOL translate_addresses = False; +static int ServerFD= -1; +static int RootPort = 0; +static BOOL find_status=False; /**************************************************************************** open the socket communication **************************************************************************/ static BOOL open_sockets(void) { - if (RootPort) - { - ServerFD = open_socket_in( SOCK_DGRAM, - 137, - 3, - interpret_addr(lp_socket_address()) ); - - if (ServerFD == -1) - { - return(False); - } + ServerFD = open_socket_in( SOCK_DGRAM, + (RootPort ? 137 :0), + 3, + interpret_addr(lp_socket_address()), True ); - set_socket_options(ServerFD,"SO_BROADCAST"); - DEBUG(3, ("Socket opened.\n")); - } - return True; -} - - -/**************************************************************************** - initialise connect, service and file structs -****************************************************************************/ -static BOOL init_structs(void ) -{ - if (!get_myname(myhostname,NULL)) + if (ServerFD == -1) return(False); + set_socket_options(ServerFD,"SO_BROADCAST"); + + DEBUG(3, ("Socket opened.\n")); return True; } + /**************************************************************************** usage on the program ****************************************************************************/ @@ -83,15 +72,70 @@ static void usage(void) printf("\t-M searches for a master browser\n"); printf("\t-R set recursion desired in packet\n"); printf("\t-S lookup node status as well\n"); + printf("\t-T translate IP addresses into names\n"); printf("\t-r Use root port 137 (Win95 only replies to this)\n"); printf("\t-A Do a node status on as an IP Address\n"); printf("\t-i NetBIOS scope Use the given NetBIOS scope for name queries\n"); printf("\t-s smb.conf file Use the given path to the smb.conf file\n"); printf("\t-h Print this help message.\n"); + printf("\n If you specify -M and name is \"-\", nmblookup looks up __MSBROWSE__<01>\n"); printf("\n"); } +/**************************************************************************** +send out one query +****************************************************************************/ +static BOOL query_one(char *lookup, unsigned int lookup_type) +{ + int j, count; + struct in_addr *ip_list=NULL; + + if (got_bcast) { + printf("querying %s on %s\n", lookup, inet_ntoa(bcast_addr)); + ip_list = name_query(ServerFD,lookup,lookup_type,use_bcast, + use_bcast?True:recursion_desired, + bcast_addr,&count,NULL); + } else { + struct in_addr *bcast; + for (j=iface_count() - 1; + !ip_list && j >= 0; + j--) { + bcast = iface_n_bcast(j); + printf("querying %s on %s\n", + lookup, inet_ntoa(*bcast)); + ip_list = name_query(ServerFD,lookup,lookup_type, + use_bcast, + use_bcast?True:recursion_desired, + *bcast,&count,NULL); + } + } + + if (!ip_list) return False; + + for (j=0;j h_name); + } + } + printf("%s %s<%02x>\n",inet_ntoa(ip_list[j]),lookup, lookup_type); + } + + /* We can only do find_status if the ip address returned + was valid - ie. name_query returned true. + */ + if (find_status) { + printf("Looking up status of %s\n",inet_ntoa(ip_list[0])); + name_status(ServerFD,lookup,lookup_type,True,ip_list[0],NULL,NULL,NULL); + printf("\n"); + } + + return (ip_list != NULL); +} + + /**************************************************************************** main program ****************************************************************************/ @@ -103,14 +147,10 @@ int main(int argc,char *argv[]) extern int optind; extern char *optarg; BOOL find_master=False; - BOOL find_status=False; int i; static pstring servicesf = CONFIGFILE; - struct in_addr bcast_addr; - BOOL use_bcast = True; - BOOL got_bcast = False; BOOL lookup_by_ip = False; - BOOL recursion_desired = False; + int commandline_debuglevel = -2; DEBUGLEVEL = 1; *lookup = 0; @@ -121,21 +161,22 @@ int main(int argc,char *argv[]) charset_initialise(); - while ((opt = getopt(argc, argv, "d:B:U:i:s:SMrhAR")) != EOF) + while ((opt = getopt(argc, argv, "d:B:U:i:s:SMrhART")) != EOF) switch (opt) { case 'B': - iface_set_default(NULL,optarg,NULL); bcast_addr = *interpret_addr2(optarg); got_bcast = True; use_bcast = True; break; case 'U': - iface_set_default(NULL,optarg,NULL); bcast_addr = *interpret_addr2(optarg); got_bcast = True; use_bcast = False; break; + case 'T': + translate_addresses = !translate_addresses; + break; case 'i': fstrcpy(scope,optarg); strupper(scope); @@ -150,13 +191,13 @@ int main(int argc,char *argv[]) recursion_desired = True; break; case 'd': - DEBUGLEVEL = atoi(optarg); + commandline_debuglevel = DEBUGLEVEL = atoi(optarg); break; case 's': pstrcpy(servicesf, optarg); break; case 'r': - RootPort = True; + RootPort = -1; break; case 'h': usage(); @@ -175,27 +216,25 @@ int main(int argc,char *argv[]) exit(1); } - init_structs(); - if (!lp_load(servicesf,True,False,False)) { fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); } - load_interfaces(); - if (!open_sockets()) return(1); - - if (!got_bcast) - bcast_addr = *iface_bcast(ipzero); + /* + * Ensure we reset DEBUGLEVEL if someone specified it + * on the command line. + */ - DEBUG(1,("Sending queries to %s\n",inet_ntoa(bcast_addr))); + if(commandline_debuglevel != -2) + DEBUGLEVEL = commandline_debuglevel; + load_interfaces(); + if (!open_sockets()) return(1); for (i=optind;i\n",inet_ntoa(ip_list[j]),lookup, lookup_type); - - /* We can only do find_status if the ip address returned - was valid - ie. name_query returned true. - */ - if (find_status) { - printf("Looking up status of %s\n",inet_ntoa(ip_list[0])); - name_status(ServerFD,lookup,lookup_type,True,ip_list[0],NULL,NULL,NULL); - printf("\n"); - } - } else { + if (!query_one(lookup, lookup_type)) { printf("name_query failed to find name %s\n", lookup); } } diff --git a/source3/utils/rpctorture.c b/source3/utils/rpctorture.c index 0933cf38c1..fb08d70011 100644 --- a/source3/utils/rpctorture.c +++ b/source3/utils/rpctorture.c @@ -49,61 +49,16 @@ struct cli_state *smb_cli = &smbcli; FILE *out_hnd; -static pstring user_name; /* local copy only, if one is entered */ static pstring password; /* local copy only, if one is entered */ -static pstring domain; /* local copy only, if one is entered */ -BOOL got_pass = False; - -static struct nmb_name calling; -static struct nmb_name called; - -static void get_passwd(void) -{ - /* 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 */ - got_pass = True; - } -} /**************************************************************************** initialise smb client structure ****************************************************************************/ void rpcclient_init(void) { - bzero(smb_cli, sizeof(smb_cli)); + memset((char *)smb_cli, '\0', sizeof(smb_cli)); cli_initialise(smb_cli); smb_cli->capabilities |= CAP_NT_SMBS; - smb_cli->capabilities |= CAP_STATUS32; - - pstrcpy(smb_cli->user_name, user_name); - - get_passwd(); - - if (*domain == 0) - { - pstrcpy(smb_cli->domain,lp_workgroup()); - } - else - { - pstrcpy(smb_cli->domain, domain); - } - - strupper(smb_cli->domain); } /**************************************************************************** @@ -111,9 +66,11 @@ make smb client connection ****************************************************************************/ static BOOL rpcclient_connect(struct client_info *info) { - rpcclient_init(); + struct nmb_name calling; + struct nmb_name called; - smb_cli->use_ntlmv2 = lp_client_ntlmv2(); + make_nmb_name(&called , dns_to_netbios_name(info->dest_host ), info->name_type, scope); + make_nmb_name(&calling, dns_to_netbios_name(info->myhostname), 0x0 , scope); if (!cli_establish_connection(smb_cli, info->dest_host, &info->dest_ip, @@ -140,7 +97,7 @@ static void rpcclient_stop(void) /**************************************************************************** log in as an nt user, log out again. ****************************************************************************/ -void run_enums_test(int num_ops, struct client_info *cli_info) +void run_enums_test(int num_ops, struct client_info *cli_info, struct cli_state *cli) { pstring cmd; int i; @@ -148,8 +105,8 @@ void run_enums_test(int num_ops, struct client_info *cli_info) /* establish connections. nothing to stop these being re-established. */ rpcclient_connect(cli_info); - DEBUG(5,("rpcclient_connect: smb_cli->fd:%d\n", smb_cli->fd)); - if (smb_cli->fd <= 0) + 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); @@ -184,7 +141,7 @@ void run_enums_test(int num_ops, struct client_info *cli_info) /**************************************************************************** log in as an nt user, log out again. ****************************************************************************/ -void run_ntlogin_test(int num_ops, struct client_info *cli_info) +void run_ntlogin_test(int num_ops, struct client_info *cli_info, struct cli_state *cli) { pstring cmd; int i; @@ -192,8 +149,8 @@ void run_ntlogin_test(int num_ops, struct client_info *cli_info) /* establish connections. nothing to stop these being re-established. */ rpcclient_connect(cli_info); - DEBUG(5,("rpcclient_connect: smb_cli->fd:%d\n", smb_cli->fd)); - if (smb_cli->fd <= 0) + 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); @@ -202,7 +159,7 @@ void run_ntlogin_test(int num_ops, struct client_info *cli_info) for (i = 0; i < num_ops; i++) { - slprintf(cmd, sizeof(cmd)-1, "%s %s", smb_cli->user_name, password); + slprintf(cmd, sizeof(cmd)-1, "%s %s", cli->user_name, password); set_first_token(cmd); cmd_netlogon_login_test(cli_info); @@ -212,382 +169,12 @@ void run_ntlogin_test(int num_ops, struct client_info *cli_info) } -/* generate a random buffer */ -static void rand_buf(char *buf, int len) -{ - while (len--) { - *buf = sys_random(); - buf++; - } -} - -/**************************************************************************** -do a random rpc command -****************************************************************************/ -BOOL do_random_rpc(struct cli_state *cli, uint16 nt_pipe_fnum, int max_len) -{ - prs_struct rbuf; - prs_struct buf; - uint8 opcode; - int param_len; - BOOL response = False; - - if ((sys_random() % 20) == 0) - { - param_len = (sys_random() % 256) + 4; - } - else - { - param_len = (sys_random() % max_len) + 4; - } - - prs_init(&buf , param_len, 4, SAFETY_MARGIN, False); - prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True ); - - opcode = sys_random() % 256; - - /* turn parameters into data stream */ - rand_buf(mem_data(&buf.data, 0), param_len); - buf.offset = param_len; - - /* send the data on \PIPE\ */ - if (rpc_api_pipe_req(cli, nt_pipe_fnum, opcode, &buf, &rbuf)) - { - response = rbuf.offset != 0; - - if (response) - { - DEBUG(0,("response! opcode: 0x%x\n", opcode)); - DEBUG(0,("request: length %d\n", param_len)); - dump_data(0, mem_data(&buf.data , 0), MIN(param_len, 128)); - DEBUG(0,("response: length %d\n", rbuf.data->offset.end)); - dump_data(0, mem_data(&rbuf.data, 0), rbuf.data->offset.end); - } - } - - prs_mem_free(&rbuf); - prs_mem_free(&buf ); - - return response; -} - - -/* send random IPC commands */ -static void random_rpc_pipe_enc(char *pipe_name, struct client_info *cli_info, - int numops) -{ - uint16 nt_pipe_fnum; - int i; - - DEBUG(0,("starting random rpc test on %s (encryped)\n", pipe_name)); - - /* establish connections. nothing to stop these being re-established. */ - if (!rpcclient_connect(cli_info)) - { - DEBUG(0,("random rpc test: connection failed\n")); - return; - } - - cli_nt_set_ntlmssp_flgs(smb_cli, - NTLMSSP_NEGOTIATE_UNICODE | - NTLMSSP_NEGOTIATE_OEM | - NTLMSSP_NEGOTIATE_SIGN | - NTLMSSP_NEGOTIATE_SEAL | - NTLMSSP_NEGOTIATE_LM_KEY | - NTLMSSP_NEGOTIATE_NTLM | - NTLMSSP_NEGOTIATE_ALWAYS_SIGN | - NTLMSSP_NEGOTIATE_00001000 | - NTLMSSP_NEGOTIATE_00002000); - - for (i = 1; i <= numops * 100; i++) - { - /* open session. */ - cli_nt_session_open(smb_cli, pipe_name, &nt_pipe_fnum); - - do_random_rpc(smb_cli, nt_pipe_fnum, 1024); - if (i % 500 == 0) - { - DEBUG(0,("calls: %i\n", i)); - } - - /* close the session */ - cli_nt_session_close(smb_cli, nt_pipe_fnum); - } - - /* close the rpc pipe */ - rpcclient_stop(); - - DEBUG(0,("finished random rpc test on %s\n", pipe_name)); -} - -/* send random IPC commands */ -static void random_rpc_pipe(char *pipe_name, struct client_info *cli_info, - int numops) -{ - uint16 nt_pipe_fnum; - int i; - - DEBUG(0,("starting random rpc test on %s\n", pipe_name)); - - /* establish connections. nothing to stop these being re-established. */ - if (!rpcclient_connect(cli_info)) - { - DEBUG(0,("random rpc test: connection failed\n")); - return; - } - - /* open session. */ - if (!cli_nt_session_open(smb_cli, pipe_name, &nt_pipe_fnum)) - { - DEBUG(0,("random rpc test: session open failed\n")); - return; - } - - for (i = 1; i <= numops * 100; i++) - { - do_random_rpc(smb_cli, nt_pipe_fnum, 8192); - if (i % 500 == 0) - { - DEBUG(0,("calls: %i\n", i)); - } - } - - /* close the session */ - cli_nt_session_close(smb_cli, nt_pipe_fnum); - - /* close the rpc pipe */ - rpcclient_stop(); - - DEBUG(0,("finished random rpc test on %s\n", pipe_name)); -} - -static void run_randomrpc(int numops, struct client_info *cli_info) -{ - char *pipes[] = - { - PIPE_SAMR , - PIPE_WINREG , - PIPE_SRVSVC , - PIPE_WKSSVC , - PIPE_NETLOGON , - PIPE_NTSVCS , - PIPE_LSARPC , - NULL - }; - - int i = 0; - - while (pipes[i] != NULL) - { - random_rpc_pipe(pipes[i], cli_info, numops); -#if 0 - random_rpc_pipe_enc(pipes[i], cli_info, numops); -#endif - - i++; - } -} - - -static void run_samhandles(int numops, struct client_info *cli_info) -{ - uint16 nt_pipe_fnum; - int i; - int count = 0; - int failed = 0; - int retry = 500; - fstring srv_name; - fstrcpy(srv_name, "\\\\"); - fstrcat(srv_name, cli_info->dest_host); - strupper(srv_name); - - DEBUG(0,("starting sam handle test\n")); - - /* establish connections. nothing to stop these being re-established. */ - while (retry > 0 && !rpcclient_connect(cli_info)) - { - retry--; - } - - if (retry == 0) - { - DEBUG(0,("samhandle test: connection failed\n")); - return; - } - - /* open session. */ - if (!cli_nt_session_open(smb_cli, PIPE_SAMR, &nt_pipe_fnum)) - { - DEBUG(0,("samhandle test: session open failed\n")); - return; - } - - for (i = 1; i <= numops * 100; i++) - { - POLICY_HND pol; - POLICY_HND dom; - if (!samr_connect(smb_cli, nt_pipe_fnum, srv_name, 0x20, &pol)) - { - failed++; - } -/* - if (!samr_open_domain(smb_cli, nt_pipe_fnum, srv_name, 0x00000020, &pol)) - { - DEBUG(0,("samhandle domain open test (%i): failed\n", i)); - } - */ - if (i % 500 == 0) - { - DEBUG(0,("calls: %i\n", i)); - } - count++; - } - - /* close the session */ - cli_nt_session_close(smb_cli, nt_pipe_fnum); - - /* close the rpc pipe */ - rpcclient_stop(); - - DEBUG(0,("finished samhandle test. count: %d failed: %d\n", count, failed)); -} - - -static void run_lsahandles(int numops, struct client_info *cli_info) -{ - uint16 nt_pipe_fnum; - int i; - int count = 0; - int failed = 0; - int retry = 500; - fstring srv_name; - fstrcpy(srv_name, "\\\\"); - fstrcat(srv_name, cli_info->myhostname); - strupper(srv_name); - - DEBUG(0,("starting lsa handle test\n")); - - /* establish connections. nothing to stop these being re-established. */ - while (retry > 0 && !rpcclient_connect(cli_info)) - { - retry--; - } - - if (retry == 0) - { - DEBUG(0,("lsahandle test: connection failed\n")); - return; - } - for (i = 1; i <= numops * 100; i++) - { - extern struct cli_state *rpc_smb_cli; - rpc_smb_cli = smb_cli; - POLICY_HND pol; - if (!lsa_open_policy(srv_name, &pol, False)) - { - failed++; - } - if (i % 500 == 0) - { - DEBUG(0,("calls: %i\n", i)); - } - count++; - } - - /* close the rpc pipe */ - rpcclient_stop(); - - DEBUG(0,("finished lsahandle test. count: %d failed: %d\n", count, failed)); -} - - -static void run_pipegobble(int numops, struct client_info *cli_info, char *pipe_name) -{ - uint16 nt_pipe_fnum; - int i; - int count = 0; - int failed = 0; - int retry = 500; - fstring srv_name; - fstrcpy(srv_name, "\\\\"); - fstrcat(srv_name, cli_info->myhostname); - strupper(srv_name); - - DEBUG(0,("starting pipe gobble test (%s)\n", pipe_name)); - - /* establish connections. nothing to stop these being re-established. */ - while (retry > 0 && !rpcclient_connect(cli_info)) - { - retry--; - } - - if (retry == 0) - { - DEBUG(0,("pipe gobble test: connection failed\n")); - return; - } - for (i = 1; i <= numops * 100; i++) - { - /* open session. */ - if (!cli_nt_session_open(smb_cli, pipe_name, &nt_pipe_fnum)) - { - DEBUG(0,("pipe gobble test: session open failed\n")); - } - - if (i % 500 == 0) - { - DEBUG(0,("calls: %i\n", i)); - } - count++; - } - - rpcclient_stop(); - - DEBUG(0,("finished pipe gobble test (%s). count: %d failed: %d\n", - pipe_name, count, failed)); -} - - -static void run_handles(int numops, struct client_info *cli_info) -{ - run_lsahandles(numops, cli_info); - run_samhandles(numops, cli_info); -} - -static void run_pipegobbler(int numops, struct client_info *cli_info) -{ - run_pipegobble(numops, cli_info, PIPE_SAMR); - run_pipegobble(numops, cli_info, PIPE_LSARPC); -} - -/**************************************************************************** -make tcp connection -****************************************************************************/ -static void run_tcpconnect(int numops, struct client_info *info) -{ - int i; - int failed = 0; - - for (i = 0; i < numops; i++) - { - rpcclient_init(); - - if (!cli_connect(smb_cli, info->dest_host, &info->dest_ip)) - { - failed++; - } - cli_shutdown(smb_cli); - } - - DEBUG(0,("tcp connections: count: %d failed: %d\n", numops, failed)); -} - /**************************************************************************** runs n simultaneous functions. ****************************************************************************/ static void create_procs(int nprocs, int numops, - struct client_info *cli_info, - void (*fn)(int, struct client_info *)) + struct client_info *cli_info, struct cli_state *cli, + void (*fn)(int, struct client_info *, struct cli_state *)) { int i, status; @@ -595,10 +182,10 @@ static void create_procs(int nprocs, int numops, { if (fork() == 0) { - int mypid = getpid(); + pid_t mypid = getpid(); sys_srandom(mypid ^ time(NULL)); - fn(numops, cli_info); - dbgflush(); + fn(numops, cli_info, cli); + fflush(out_hnd); _exit(0); } } @@ -608,8 +195,6 @@ static void create_procs(int nprocs, int numops, waitpid(0, &status, 0); } } - - /**************************************************************************** usage on the program - OUT OF DATE! ****************************************************************************/ @@ -628,8 +213,6 @@ static void usage(char *pname) 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, "\t-N processes number of processes\n"); - fprintf(out_hnd, "\t-o operations number of operations\n"); fprintf(out_hnd, "\n"); } @@ -652,6 +235,7 @@ enum client_action 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; @@ -662,6 +246,8 @@ enum client_action out_hnd = stdout; + rpcclient_init(); + #ifdef KANJI pstrcpy(term_code, KANJI); #else /* KANJI */ @@ -699,6 +285,8 @@ enum client_action 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, ""); @@ -711,6 +299,7 @@ enum client_action ZERO_STRUCT(cli_info.dom.level5_sid); pstrcpy(cli_info.dom.level5_dom, ""); + smb_cli->nt_pipe_fnum = 0xffff; setup_logging(pname, True); @@ -720,7 +309,7 @@ enum client_action myumask = umask(0); umask(myumask); - if (!get_myname(global_myname, NULL)) + if (!get_myname(global_myname)) { fprintf(stderr, "Failed to get my hostname.\n"); } @@ -771,7 +360,7 @@ enum client_action cli_action = CLIENT_SVC; } - while ((opt = getopt(argc, argv,"s:B:O:M:S:i:N:o:n:d:l:hI:EB:U:L:t:m:W:T:D:c:")) != EOF) + 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) { @@ -799,12 +388,6 @@ enum client_action break; } - case 'B': - { - iface_set_default(NULL,optarg,NULL); - break; - } - case 'i': { pstrcpy(scope, optarg); @@ -814,8 +397,8 @@ enum client_action case 'U': { char *lp; - pstrcpy(user_name,optarg); - if ((lp=strchr(user_name,'%'))) + pstrcpy(smb_cli->user_name,optarg); + if ((lp=strchr(smb_cli->user_name,'%'))) { *lp = 0; pstrcpy(password,lp+1); @@ -827,7 +410,7 @@ enum client_action case 'W': { - pstrcpy(domain,optarg); + pstrcpy(smb_cli->domain,optarg); break; } @@ -925,7 +508,13 @@ enum client_action strupper(global_myname); fstrcpy(cli_info.myhostname, global_myname); - DEBUG(3,("%s client started (version %s)\n",timestring(),VERSION)); + 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(); @@ -939,25 +528,31 @@ enum client_action strupper(cli_info.mach_acct); fstrcat(cli_info.mach_acct, "$"); - make_nmb_name(&called , dns_to_netbios_name(cli_info.dest_host ), cli_info.name_type, scope); - make_nmb_name(&calling, dns_to_netbios_name(cli_info.myhostname), 0x0 , scope); + /* 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 */ + } - get_passwd(); -/* - create_procs(nprocs, numops, &cli_info, run_enums_test); + create_procs(nprocs, numops, &cli_info, smb_cli, run_enums_test); if (password[0] != 0) { - create_procs(nprocs, numops, &cli_info, run_ntlogin_test); + create_procs(nprocs, numops, &cli_info, smb_cli, run_ntlogin_test); } -*/ - -/* - create_procs(nprocs, numops, &cli_info, run_randomrpc); - create_procs(nprocs, numops, &cli_info, run_pipegobbler); - create_procs(nprocs, numops, &cli_info, run_tcpconnect); -*/ - create_procs(nprocs, numops, &cli_info, run_handles); fflush(out_hnd); diff --git a/source3/utils/smbfilter.c b/source3/utils/smbfilter.c index 643a3ed2ce..81b10e4519 100644 --- a/source3/utils/smbfilter.c +++ b/source3/utils/smbfilter.c @@ -120,7 +120,7 @@ static void filter_child(int c, struct in_addr dest_ip) if (s != -1) FD_SET(s, &fds); if (c != -1) FD_SET(c, &fds); - num = sys_select(MAX(s+1, c+1),&fds,NULL, NULL); + num = sys_select(MAX(s+1, c+1),&fds,NULL); if (num <= 0) continue; if (c != -1 && FD_ISSET(c, &fds)) { @@ -159,7 +159,7 @@ static void start_filter(char *desthost) CatchChild(); /* start listening on port 139 locally */ - s = open_socket_in(SOCK_STREAM, 139, 0, 0); + s = open_socket_in(SOCK_STREAM, 139, 0, 0, True); if (s == -1) { DEBUG(0,("bind failed\n")); @@ -184,7 +184,7 @@ static void start_filter(char *desthost) FD_ZERO(&fds); FD_SET(s, &fds); - num = sys_select(s+1,&fds,NULL, NULL); + num = sys_select(s+1,&fds,NULL); if (num > 0) { c = accept(s, &addr, &in_addrlen); if (c != -1) { diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 3b87687c26..ec6ce15f07 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -1,7 +1,6 @@ /* - * Unix SMB/Netbios implementation. Version 1.9. smbpasswd module. - * Copyright (C) Jeremy Allison 1995-1999 - * Copyright (C) Luke Kenneth Casson Leighton 1996-1999 + * Unix SMB/Netbios implementation. Version 1.9. smbpasswd module. Copyright + * (C) Jeremy Allison 1995-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 @@ -20,9 +19,7 @@ #include "includes.h" -extern pstring myhostname; extern pstring global_myname; -extern pstring global_myworkgroup; extern int DEBUGLEVEL; /* @@ -65,135 +62,85 @@ static void usage(void) if (getuid() == 0) { printf(" -R ORDER name resolve order\n"); printf(" -j DOMAIN join domain name\n"); - printf(" -S synchronise with PDC (if we are BDC)\n"); printf(" -a add user\n"); printf(" -d disable user\n"); printf(" -e enable user\n"); printf(" -n set no password\n"); - printf(" -m workstation trust account\n"); - printf(" -b backup domain controller account\n"); - printf(" -i inter-domain trust account\n"); - printf(" -p user cannot change password\n"); - printf(" -x user can change password\n"); + printf(" -m machine trust account\n"); } - exit(1); } /********************************************************* Join a domain. **********************************************************/ -static int create_interdomain_trust_acct(char *domain, char *name) +static int join_domain(char *domain, char *remote) { + pstring remote_machine; fstring trust_passwd; - unsigned char hash[16]; - uint16 sec_chan; - - switch (lp_server_role()) - { - case ROLE_DOMAIN_PDC: - { - DEBUG(0, ("Joining domain - we are PDC\n")); - sec_chan = SEC_CHAN_DOMAIN; - break; - } - case ROLE_DOMAIN_BDC: - { - DEBUG(0, ("Cannot set up inter-domain trust as BDC!\n")); - return 1; - } - default: - { - DEBUG(0, ("Cannot set up inter-domain trust as workstation!\n")); - return 1; - } - } + unsigned char orig_trust_passwd_hash[16]; + BOOL ret; + + pstrcpy(remote_machine, remote ? remote : ""); + fstrcpy(trust_passwd, global_myname); + strlower(trust_passwd); + E_md4hash( (uchar *)trust_passwd, orig_trust_passwd_hash); -#if 0 - pstrcpy(remote_machine, remote ? remote : lp_passwordserver()); + /* Ensure that we are not trying to join a + domain if we are locally set up as a domain + controller. */ - if (!remote_machine[0]) - { - fprintf(stderr, "You must specify the PDC via 'password server' or -r."); + if(strequal(remote, global_myname)) { + fprintf(stderr, "Cannot join domain %s as the domain controller name is our own. We cannot be a domain controller for a domain and also be a domain member.\n", domain); return 1; } -#endif - fstrcpy(trust_passwd, name); - strlower(trust_passwd); - E_md4hash( (uchar *)trust_passwd, hash); - - if (!create_trust_account_file(domain, name, hash)) - { + /* + * Create the machine account password file. + */ + if(!trust_password_lock( domain, global_myname, True)) { + fprintf(stderr, "Unable to open the machine account password file for \ +machine %s in domain %s.\n", global_myname, domain); return 1; } + + /* + * Write the old machine account password. + */ -#if 0 - if(!change_trust_account_password(domain, remote_machine, sec_chan)) - { - fprintf(stderr,"Unable to join domain %s.\n",domain); + if(!set_trust_account_password( orig_trust_passwd_hash)) { + fprintf(stderr, "Unable to write the machine account password for \ +machine %s in domain %s.\n", global_myname, domain); + trust_password_unlock(); return 1; } -#endif - printf("Created Inter-Domain Trust Account for %s.\n",domain); - return 0; -} - -/********************************************************* -Join a domain. -**********************************************************/ -static int join_domain(char *domain, char *remote) -{ - pstring remote_machine; - fstring trust_passwd; - unsigned char orig_trust_passwd_hash[16]; - uint16 sec_chan; - - switch (lp_server_role()) - { - case ROLE_DOMAIN_PDC: - { - DEBUG(0, ("Cannot join domain - we are PDC!\n")); - return 1; - } - case ROLE_DOMAIN_BDC: - { - DEBUG(0, ("Joining Domain as BDC\n")); - sec_chan = SEC_CHAN_BDC; - break; - } - default: - { - DEBUG(0, ("Joining Domain as Workstation\n")); - sec_chan = SEC_CHAN_WKSTA; - } + + /* + * If we are given a remote machine assume this is the PDC. + */ + + if(remote == NULL) { + pstrcpy(remote_machine, lp_passwordserver()); } - pstrcpy(remote_machine, remote ? remote : lp_passwordserver()); - - if (!remote_machine[0]) - { - fprintf(stderr, "You must specify the PDC via 'password server' or -r."); + if(!*remote_machine) { + fprintf(stderr, "No password server list given in smb.conf - \ +unable to join domain.\n"); + trust_password_unlock(); return 1; } - fstrcpy(trust_passwd, global_myname); - strlower(trust_passwd); - E_md4hash( (uchar *)trust_passwd, orig_trust_passwd_hash); - - if (!create_trust_account_file(domain, global_myname, trust_passwd)) - { - return 1; - } + ret = change_trust_account_password( domain, remote_machine); + trust_password_unlock(); - if(!change_trust_account_password(domain, remote_machine, sec_chan)) - { + if(!ret) { + trust_password_delete( domain, global_myname); fprintf(stderr,"Unable to join domain %s.\n",domain); - return 1; + } else { + printf("Joined domain %s.\n",domain); } - - printf("Joined domain %s.\n",domain); - return 0; + + return (int)ret; } @@ -262,6 +209,7 @@ static char *prompt_for_new_password(BOOL stdin_get) if (strcmp(p, new_passwd)) { fprintf(stderr, "Mismatch - password unchanged.\n"); + ZERO_ARRAY(new_passwd); return NULL; } @@ -273,47 +221,35 @@ static char *prompt_for_new_password(BOOL stdin_get) change a password either locally or remotely *************************************************************/ static BOOL password_change(const char *remote_machine, char *user_name, - char *old_passwd, char *new_passwd, - BOOL add_user, - uint16 acb_info, uint16 acb_mask) + char *old_passwd, char *new_passwd, + BOOL add_user, BOOL enable_user, + BOOL disable_user, BOOL set_no_password, + BOOL trust_account) { BOOL ret; pstring err_str; pstring msg_str; - if (remote_machine != NULL) - { - if (add_user || - IS_BITS_SET_SOME(acb_info, ACB_PWNOTREQ | ACB_WSTRUST | ACB_DOMTRUST | ACB_SVRTRUST) || - (IS_BITS_SET_SOME(acb_mask, ACB_DISABLED) && - IS_BITS_CLR_ALL(acb_info, ACB_DISABLED))) - { + if (remote_machine != NULL) { + if (add_user || enable_user || disable_user || set_no_password || trust_account) { /* these things can't be done remotely yet */ return False; } ret = remote_password_change(remote_machine, user_name, - old_passwd, new_passwd, - err_str, sizeof(err_str)); - if (*err_str != 0) - { + old_passwd, new_passwd, err_str, sizeof(err_str)); + if(*err_str) fprintf(stderr, err_str); - } return ret; } - ret = local_password_change(user_name, add_user, acb_info, acb_mask, - new_passwd, - err_str, sizeof(err_str), - msg_str, sizeof(msg_str)); + ret = local_password_change(user_name, trust_account, add_user, enable_user, + disable_user, set_no_password, new_passwd, + err_str, sizeof(err_str), msg_str, sizeof(msg_str)); - if (*msg_str != 0) - { + if(*msg_str) printf(msg_str); - } - if (*err_str != 0) - { + if(*err_str) fprintf(stderr, err_str); - } return ret; } @@ -326,156 +262,80 @@ static int process_root(int argc, char *argv[]) { struct passwd *pwd; int ch; - uint16 acb_info = 0; - uint16 acb_mask = 0; BOOL joining_domain = False; - BOOL sam_sync = False; - BOOL wks_trust_account = False; - BOOL srv_trust_account = False; - BOOL dom_trust_account = False; + BOOL trust_account = False; BOOL add_user = False; BOOL disable_user = False; BOOL enable_user = False; BOOL set_no_password = False; BOOL stdin_passwd_get = False; - BOOL lock_password = False; - BOOL unlock_password = False; char *user_name = NULL; char *new_domain = NULL; char *new_passwd = NULL; char *old_passwd = NULL; char *remote_machine = NULL; - int ret; - - while ((ch = getopt(argc, argv, "abdehimnpxj:Sr:sR:D:U:")) != EOF) - { - switch(ch) - { - case 'a': - { - add_user = True; - break; - } - case 'd': - { - disable_user = True; - new_passwd = "XXXXXX"; - break; - } - case 'e': - { - enable_user = True; - break; - } - case 'D': - { - DEBUGLEVEL = atoi(optarg); - break; - } - case 'n': - { - set_no_password = True; - new_passwd = "NO PASSWORD"; - } - case 'r': - { - remote_machine = optarg; - break; - } - case 's': - { - set_line_buffering(stdin); - set_line_buffering(stdout); - set_line_buffering(stderr); - stdin_passwd_get = True; - break; - } - case 'R': - { - lp_set_name_resolve_order(optarg); - break; - } - case 'i': - { - dom_trust_account = True; - break; - } - case 'b': - { - srv_trust_account = True; - break; - } - case 'm': - { - wks_trust_account = True; - break; - } - case 'j': - { - new_domain = optarg; - strupper(new_domain); - joining_domain = True; - break; - } - case 'S': - { - sam_sync = True; - break; - } - case 'U': - { - user_name = optarg; - break; - } - case 'p': - { - lock_password = True; - break; - } - case 'x': - { - unlock_password = True; - break; - } - default: - { - usage(); - } + + while ((ch = getopt(argc, argv, "adehmnj:r:sR:D:U:")) != EOF) { + switch(ch) { + case 'a': + add_user = True; + break; + case 'd': + disable_user = True; + new_passwd = "XXXXXX"; + break; + case 'e': + enable_user = True; + break; + case 'D': + DEBUGLEVEL = atoi(optarg); + break; + case 'n': + set_no_password = True; + new_passwd = "NO PASSWORD"; + case 'r': + remote_machine = optarg; + break; + case 's': + set_line_buffering(stdin); + set_line_buffering(stdout); + set_line_buffering(stderr); + stdin_passwd_get = True; + break; + case 'R': + lp_set_name_resolve_order(optarg); + break; + case 'm': + trust_account = True; + break; + case 'j': + new_domain = optarg; + strupper(new_domain); + joining_domain = True; + break; + case 'U': + user_name = optarg; + break; + default: + usage(); } } argc -= optind; argv += optind; + /* * Ensure add_user and either remote machine or join domain are * not both set. */ - if (add_user && ((remote_machine != NULL) || joining_domain)) - { + if(add_user && ((remote_machine != NULL) || joining_domain)) { usage(); } - - if (sam_sync && lp_server_role() != ROLE_DOMAIN_BDC) { - fprintf(stderr, "The -S option can only be used on a Backup Domain Controller.\n"); - return 1; - } - if (joining_domain) - { - if (!dom_trust_account) - { - if (argc != 0) usage(); - ret = join_domain(new_domain, remote_machine); - - if ((ret != 0) || (!sam_sync)) - return ret; - } - } - - if (sam_sync) - { - return synchronise_passdb(); + if(joining_domain) { + if (argc != 0) usage(); + return join_domain(new_domain, remote_machine); } /* @@ -496,7 +356,7 @@ static int process_root(int argc, char *argv[]) usage(); } - if (!user_name && (pwd = getpwuid(0))) { + if (!user_name && (pwd = sys_getpwuid(0))) { user_name = xstrdup(pwd->pw_name); } @@ -505,8 +365,7 @@ static int process_root(int argc, char *argv[]) exit(1); } - if (wks_trust_account || srv_trust_account || dom_trust_account) - { + if (trust_account) { /* add the $ automatically */ static fstring buf; @@ -539,24 +398,12 @@ static int process_root(int argc, char *argv[]) exit(1); } - if (joining_domain) - { - if (dom_trust_account) - { - ret = create_interdomain_trust_acct(new_domain, - global_myworkgroup); - - if ((ret != 0) || (!sam_sync)) - return ret; - } - } - if (remote_machine != NULL) { old_passwd = get_pass("Old SMB password:",stdin_passwd_get); } - if (!new_passwd) - { + if (!new_passwd) { + /* * If we are trying to enable a user, first we need to find out * if they are using a modern version of the smbpasswd file that @@ -566,94 +413,43 @@ static int process_root(int argc, char *argv[]) * smbpasswd file) then we need to prompt for a new password. */ - if (enable_user) - { + if(enable_user) { struct smb_passwd *smb_pass = getsmbpwnam(user_name); - if((smb_pass != NULL) && (smb_pass->smb_passwd != NULL)) - { + if((smb_pass != NULL) && (smb_pass->smb_passwd != NULL)) { new_passwd = "XXXX"; /* Don't care. */ } } if(!new_passwd) - { new_passwd = prompt_for_new_password(stdin_passwd_get); - } - } - - if (enable_user) - { - acb_mask |= ACB_DISABLED; - acb_info &= ~ACB_DISABLED; - } - - if (disable_user) - { - acb_mask |= ACB_DISABLED; - acb_info |= ACB_DISABLED; - } - if (set_no_password) - { - acb_mask |= ACB_PWNOTREQ; - acb_info |= ACB_PWNOTREQ; - } - - if (lock_password) - { - acb_mask |= ACB_PWLOCK; - acb_info |= ACB_PWLOCK; - } - - if (unlock_password) - { - acb_mask |= ACB_PWLOCK; - acb_info &= ~ACB_PWLOCK; + if(!new_passwd) { + fprintf(stderr, "Unable to get new password.\n"); + exit(1); + } } - if (wks_trust_account) - { - acb_mask |= ACB_WSTRUST; - acb_info |= ACB_WSTRUST; - } - else if (srv_trust_account) - { - acb_mask |= ACB_SVRTRUST; - acb_info |= ACB_SVRTRUST; - } - else if (dom_trust_account) - { - acb_mask |= ACB_DOMTRUST; - acb_info |= ACB_DOMTRUST; - } - else - { - acb_mask |= ACB_NORMAL; - acb_info |= ACB_NORMAL; - } - if (!password_change(remote_machine, user_name, old_passwd, new_passwd, - add_user, acb_info, acb_mask)) - { + add_user, enable_user, disable_user, set_no_password, + trust_account)) { fprintf(stderr,"Failed to change password entry for %s\n", user_name); return 1; } - if (disable_user) - { + if(disable_user) { printf("User %s disabled.\n", user_name); - } - if (enable_user) - { + } else if(enable_user) { printf("User %s enabled.\n", user_name); - } - if (set_no_password) - { + } else if (set_no_password) { printf("User %s - set to no password.\n", user_name); - } - if (!disable_user && !enable_user && !set_no_password) - { - printf("Password changed for user %s\n", user_name); + } else { + struct smb_passwd *smb_pass = getsmbpwnam(user_name); + printf("Password changed for user %s.", user_name ); + if((smb_pass != NULL) && (smb_pass->acct_ctrl & ACB_DISABLED )) + printf(" User has disabled flag set."); + if((smb_pass != NULL) && (smb_pass->acct_ctrl & ACB_PWNOTREQ)) + printf(" User has no password flag set."); + printf("\n"); } return 0; } @@ -671,11 +467,9 @@ static int process_nonroot(int argc, char *argv[]) char *remote_machine = NULL; char *user_name = NULL; char *new_passwd = NULL; - - while ((ch = getopt(argc, argv, "hD:r:sU:")) != EOF) - { - switch(ch) - { + + while ((ch = getopt(argc, argv, "hD:r:sU:")) != EOF) { + switch(ch) { case 'D': DEBUGLEVEL = atoi(optarg); break; @@ -708,7 +502,7 @@ static int process_nonroot(int argc, char *argv[]) } if (!user_name) { - pwd = getpwuid(getuid()); + pwd = sys_getpwuid(getuid()); if (pwd) { user_name = xstrdup(pwd->pw_name); } else { @@ -726,6 +520,7 @@ static int process_nonroot(int argc, char *argv[]) remote_machine = "127.0.0.1"; } + if (remote_machine != NULL) { old_passwd = get_pass("Old SMB password:",stdin_passwd_get); } @@ -735,14 +530,12 @@ static int process_nonroot(int argc, char *argv[]) } if (!new_passwd) { - printf("unable to get new password\n"); - exit(0); + fprintf(stderr, "Unable to get new password.\n"); + exit(1); } - if (!password_change(remote_machine, user_name, - old_passwd, new_passwd, - False, 0x0, 0x0)) - { + if (!password_change(remote_machine, user_name, old_passwd, new_passwd, + False, False, False, False, False)) { fprintf(stderr,"Failed to change password for %s\n", user_name); return 1; } @@ -760,20 +553,24 @@ int main(int argc, char **argv) { static pstring servicesf = CONFIGFILE; +#if defined(HAVE_SET_AUTH_PARAMETERS) + set_auth_parameters(argc, argv); +#endif /* HAVE_SET_AUTH_PARAMETERS */ + TimeInit(); setup_logging("smbpasswd", True); charset_initialise(); - if (!lp_load(servicesf,True,False,False)) { - fprintf(stderr, "Can't load %s - run testparm to debug it\n", - servicesf); + if(!initialize_password_db()) { + fprintf(stderr, "Can't setup password database vectors.\n"); exit(1); } - if(!get_myname(myhostname,NULL)) { - fprintf(stderr, "unable to get my hostname.\n"); + if (!lp_load(servicesf,True,False,False)) { + fprintf(stderr, "Can't load %s - run testparm to debug it\n", + servicesf); exit(1); } @@ -784,7 +581,7 @@ int main(int argc, char **argv) if (!*global_myname) { char *p; - fstrcpy(global_myname, myhostname); + fstrcpy(global_myname, myhostname()); p = strchr(global_myname, '.' ); if (p) *p = 0; } @@ -794,12 +591,6 @@ int main(int argc, char **argv) load_interfaces(); - if(!pwdb_initialise(False)) - { - fprintf(stderr, "Can't setup password database vectors.\n"); - exit(1); - } - /* Check the effective uid - make sure we are not setuid */ if ((geteuid() == (uid_t)0) && (getuid() != (uid_t)0)) { fprintf(stderr, "smbpasswd must *NOT* be setuid root.\n"); diff --git a/source3/utils/smbrun.c b/source3/utils/smbrun.c index 2a94ac3235..b7c678411c 100644 --- a/source3/utils/smbrun.c +++ b/source3/utils/smbrun.c @@ -48,35 +48,17 @@ It takes 3 arguments as uid,gid,command and runs command after becoming a non-root user */ int main(int argc,char *argv[]) { - int uid,gid; + uid_t uid; + gid_t gid; close_fds(); if (argc != 4) exit(2); - uid = atoi(argv[1]); - gid = atoi(argv[2]); - - /* first become root - we may need to do this in order to lose - our privilages! */ -#ifdef HAVE_SETRESUID - setresgid(0,0,0); - setresuid(0,0,0); -#else - setuid(0); - seteuid(0); -#endif - -#ifdef HAVE_SETRESUID - setresgid(gid,gid,gid); - setresuid(uid,uid,uid); -#else - setgid(gid); - setegid(gid); - setuid(uid); - seteuid(uid); -#endif + uid = (uid_t)atoi(argv[1]); + gid = (gid_t)atoi(argv[2]); + become_user_permanently( uid, gid); /* paranoia :-) */ if (getuid() != uid) diff --git a/source3/utils/status.c b/source3/utils/status.c index 320a54cc7d..2cbfbfdaf5 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -36,9 +36,11 @@ #include "includes.h" +struct connect_record crec; + struct session_record{ - int pid; - int uid; + pid_t pid; + uid_t uid; char machine[31]; time_t start; struct session_record *next; @@ -46,10 +48,9 @@ struct session_record{ extern int DEBUGLEVEL; extern FILE *dbf; -extern pstring myhostname; static pstring Ucrit_username = ""; /* added by OH */ -int Ucrit_pid[100]; /* Ugly !!! */ /* added by OH */ +pid_t Ucrit_pid[100]; /* Ugly !!! */ /* added by OH */ int Ucrit_MaxPid=0; /* added by OH */ unsigned int Ucrit_IsActive = 0; /* added by OH */ @@ -76,7 +77,7 @@ static unsigned int Ucrit_checkUsername(char *username) return 0; } -static void Ucrit_addPid(int pid) +static void Ucrit_addPid(pid_t pid) { int i; if ( !Ucrit_IsActive) return; @@ -85,7 +86,7 @@ static void Ucrit_addPid(int pid) Ucrit_pid[Ucrit_MaxPid++] = pid; } -static unsigned int Ucrit_checkPid(int pid) +static unsigned int Ucrit_checkPid(pid_t pid) { int i; if ( !Ucrit_IsActive) return 1; @@ -106,7 +107,7 @@ static void print_share_mode(share_mode_entry *e, char *fname) count++; if (Ucrit_checkPid(e->pid)) { - printf("%-5d ",e->pid); + printf("%-5d ",(int)e->pid); switch ((e->share_mode>>4)&0xF) { case DENY_NONE: printf("DENY_NONE "); break; case DENY_ALL: printf("DENY_ALL "); break; @@ -128,10 +129,13 @@ static void print_share_mode(share_mode_entry *e, char *fname) printf("EXCLUSIVE "); else if (e->op_type & BATCH_OPLOCK) printf("BATCH "); + else if (e->op_type & LEVEL_II_OPLOCK) + printf("LEVEL_II "); else printf("NONE "); - printf(" %s %s",fname,asctime(LocalTime((time_t *)&e->time.tv_sec))); + printf(" %s %s",dos_to_unix(fname,False), + asctime(LocalTime((time_t *)&e->time.tv_sec))); } } @@ -167,12 +171,9 @@ static int profile_dump(void) extern char *optarg; int verbose = 0, brief =0; BOOL processes_only=False; - int last_pid=0; + pid_t last_pid=(pid_t)0; struct session_record *ptr; int profile_only = 0; - struct connect_record *crec = NULL; - uint32 connection_count; - uint32 conn; TimeInit(); setup_logging(argv[0],True); @@ -214,13 +215,11 @@ static int profile_dump(void) Ucrit_addUsername(optarg); /* added by OH */ break; default: - fprintf(stderr, "Usage: %s [-P] [-d] [-L] [-p] [-S] [-s configfile] [-u username]\n", *argv); + fprintf(stderr, "Usage: %s [-P] [-d] [-L] [-p] [-S] [-s configfile] [-u username]\n", *argv); /* changed by OH */ return (-1); } } - get_myname(myhostname, NULL); - if (!lp_load(servicesf,False,False,False)) { fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); return (-1); @@ -232,7 +231,7 @@ static int profile_dump(void) } if (profile_only) { - return profile_dump(); + return profile_dump(); } pstrcpy(fname,lp_lockdir()); @@ -267,59 +266,60 @@ static int profile_dump(void) printf("----------------------------------------------\n"); } } - - if (get_connection_status(&crec, &connection_count)) - { - for (conn=0;connpid==crec.pid)&&(strncmp(ptr->machine,crec.machine,30)==0)) { - ptr=srecs; - while (ptr!=NULL) - { - if ((ptr->pid==crec[conn].pid)&&(strncmp(ptr->machine,crec[conn].machine,30)==0)) - { - if (ptr->start > crec[conn].start) - ptr->start=crec[conn].start; - break; - } - ptr=ptr->next; - } - if (ptr==NULL) - { - ptr=(struct session_record *) malloc(sizeof(struct session_record)); - ptr->uid=crec[conn].uid; - ptr->pid=crec[conn].pid; - ptr->start=crec[conn].start; - strncpy(ptr->machine,crec[conn].machine,30); - ptr->machine[30]='\0'; - ptr->next=srecs; - srecs=ptr; - } + if (ptr->start > crec.start) + ptr->start=crec.start; + break; } - else - { - Ucrit_addPid(crec[conn].pid); /* added by OH */ - if (processes_only) { - if (last_pid != crec[conn].pid) - printf("%d\n",crec[conn].pid); - last_pid = crec[conn].pid; /* XXXX we can still get repeats, have to - add a sort at some time */ - } - else - printf("%-10.10s %-8s %-8s %5d %-8s (%s) %s", - crec[conn].name,uidtoname(crec[conn].uid),gidtoname(crec[conn].gid),crec[conn].pid, - crec[conn].machine,crec[conn].addr, - asctime(LocalTime(&crec[conn].start))); - } - } - } - free(crec); - } + ptr=ptr->next; + } + if (ptr==NULL) + { + ptr=(struct session_record *) malloc(sizeof(struct session_record)); + ptr->uid=crec.uid; + ptr->pid=crec.pid; + ptr->start=crec.start; + strncpy(ptr->machine,crec.machine,30); + ptr->machine[30]='\0'; + ptr->next=srecs; + srecs=ptr; + } + } + else + { + Ucrit_addPid(crec.pid); /* added by OH */ + if (processes_only) { + if (last_pid != crec.pid) + printf("%d\n",(int)crec.pid); + last_pid = crec.pid; /* XXXX we can still get repeats, have to + add a sort at some time */ + } + else + printf("%-10.10s %-8s %-8s %5d %-8s (%s) %s", + crec.name,uidtoname(crec.uid),gidtoname(crec.gid),(int)crec.pid, + crec.machine,crec.addr, + asctime(LocalTime(&crec.start))); + } + } + } + fclose(f); } - if (processes_only) exit(0); if (brief) @@ -327,7 +327,7 @@ static int profile_dump(void) ptr=srecs; while (ptr!=NULL) { - printf("%-8d%-10.10s%-30.30s%s",ptr->pid,uidtoname(ptr->uid),ptr->machine,asctime(LocalTime(&(ptr->start)))); + printf("%-8d%-10.10s%-30.30s%s",(int)ptr->pid,uidtoname(ptr->uid),ptr->machine,asctime(LocalTime(&(ptr->start)))); ptr=ptr->next; } printf("\n"); diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index 9bf741e24f..e4f603e0ce 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -38,46 +38,153 @@ /* these live in util.c */ extern FILE *dbf; extern int DEBUGLEVEL; -extern pstring myhostname; /*********************************************** Here we do a set of 'hard coded' checks for bad configuration settings. ************************************************/ -static void do_global_checks(void) + +static int do_global_checks(void) { + int ret = 0; SMB_STRUCT_STAT st; + if (lp_security() > SEC_SHARE && lp_revalidate(-1)) { printf("WARNING: the 'revalidate' parameter is ignored in all but \ 'security=share' mode.\n"); } - if (lp_security() == SEC_DOMAIN && !lp_encrypted_passwords()) { + if (lp_security() == SEC_DOMAIN && !lp_encrypted_passwords()) { printf("ERROR: in 'security=domain' mode the 'encrypt passwords' parameter must also be set to 'true'.\n"); + ret = 1; } if (lp_wins_support() && *lp_wins_server()) { printf("ERROR: both 'wins support = true' and 'wins server = ' \ cannot be set in the smb.conf file. nmbd will abort with this setting.\n"); + ret = 1; } if (!directory_exist(lp_lockdir(), &st)) { printf("ERROR: lock directory %s does not exist\n", lp_lockdir()); + ret = 1; } else if ((st.st_mode & 0777) != 0755) { printf("WARNING: lock directory %s should have permissions 0755 for browsing to work\n", lp_lockdir()); + ret = 1; + } + + /* + * Password server sanity checks. + */ + + if((lp_security() == SEC_SERVER || lp_security() == SEC_DOMAIN) && !lp_passwordserver()) { + pstring sec_setting; + if(lp_security() == SEC_SERVER) + pstrcpy(sec_setting, "server"); + else if(lp_security() == SEC_DOMAIN) + pstrcpy(sec_setting, "domain"); + + printf("ERROR: The setting 'security=%s' requires the 'password server' parameter be set \ +to a valid password server.\n", sec_setting ); + ret = 1; + } + + /* + * Password chat sanity checks. + */ + + if(lp_security() == SEC_USER && lp_unix_password_sync()) { + + /* + * Check that we have a valid lp_passwd_program(). + */ + + if(lp_passwd_program() == NULL) { + printf("ERROR: the 'unix password sync' parameter is set and there is no valid 'passwd program' \ +parameter.\n" ); + ret = 1; + } else { + pstring passwd_prog; + pstring truncated_prog; + char *p; + + pstrcpy( passwd_prog, lp_passwd_program()); + p = passwd_prog; + *truncated_prog = '\0'; + next_token(&p, truncated_prog, NULL, sizeof(pstring)); + + if(access(truncated_prog, F_OK) == -1) { + printf("ERROR: the 'unix password sync' parameter is set and the 'passwd program' (%s) \ +cannot be executed (error was %s).\n", truncated_prog, strerror(errno) ); + ret = 1; + } + } + + if(lp_passwd_chat() == NULL) { + printf("ERROR: the 'unix password sync' parameter is set and there is no valid 'passwd chat' \ +parameter.\n"); + ret = 1; + } + + /* + * Check that we have a valid script and that it hasn't + * been written to expect the old password. + */ + + if(lp_encrypted_passwords()) { + if(strstr( lp_passwd_chat(), "%o")!=NULL) { + printf("ERROR: the 'passwd chat' script [%s] expects to use the old plaintext password \ +via the %%o substitution. With encrypted passwords this is not possible.\n", lp_passwd_chat() ); + ret = 1; + } + } + } + + /* + * WINS server line sanity checks. + */ + + if(*lp_wins_server()) { + fstring server; + int count = 0; + char *p = lp_wins_server(); + + while(next_token(&p,server,LIST_SEP,sizeof(server))) + count++; + if(count > 1) { + printf("ERROR: the 'wins server' parameter must only contain one WINS server.\n"); + ret = -1; + } } + + return ret; } - int main(int argc, char *argv[]) +static void usage(char *pname) +{ + printf("Usage: %s [-sh] [-L servername] [configfilename] [hostname hostIP]\n", pname); + printf("\t-s Suppress prompt for enter\n"); + printf("\t-h Print usage\n"); + printf("\t-L servername Set %%L macro to servername\n"); + printf("\tconfigfilename Configuration file to test\n"); + printf("\thostname hostIP. Hostname and Host IP address to test\n"); + printf("\t against \"host allow\" and \"host deny\"\n"); + printf("\n"); +} + + +int main(int argc, char *argv[]) { extern char *optarg; extern int optind; + extern fstring local_machine; pstring configfile; int opt; int s; BOOL silent_mode = False; + int ret = 0; TimeInit(); @@ -85,11 +192,23 @@ cannot be set in the smb.conf file. nmbd will abort with this setting.\n"); charset_initialise(); - while ((opt = getopt(argc, argv,"s")) != EOF) { + while ((opt = getopt(argc, argv,"shL:")) != EOF) { switch (opt) { case 's': silent_mode = True; break; + case 'L': + fstrcpy(local_machine,optarg); + break; + case 'h': + usage(argv[0]); + exit(0); + break; + default: + printf("Incorrect program usage\n"); + usage(argv[0]); + exit(1); + break; } } @@ -105,71 +224,87 @@ cannot be set in the smb.conf file. nmbd will abort with this setting.\n"); printf("Load smb config files from %s\n",configfile); - if(!get_myname(myhostname,NULL)) - { - printf("Failed to get my hostname.\n"); - return(1); - } - - if (!lp_load(configfile,False,True,False)) - { + if (!lp_load(configfile,False,True,False)) { printf("Error loading services.\n"); return(1); - } - + } printf("Loaded services file OK.\n"); - do_global_checks(); + ret = do_global_checks(); - for (s=0;s<1000;s++) + for (s=0;s<1000;s++) { if (VALID_SNUM(s)) if (strlen(lp_servicename(s)) > 8) { - printf("WARNING: You have some share names that are longer than 8 chars\n"); - printf("These may give errors while browsing or may not be accessible\nto some older clients\n"); - break; + printf("WARNING: You have some share names that are longer than 8 chars\n"); + printf("These may give errors while browsing or may not be accessible\nto some older clients\n"); + break; + } + } + + for (s=0;s<1000;s++) { + if (VALID_SNUM(s)) { + char *deny_list = lp_hostsdeny(s); + char *allow_list = lp_hostsallow(s); + if(deny_list) { + char *hasstar = strchr(deny_list, '*'); + char *hasquery = strchr(deny_list, '?'); + if(hasstar || hasquery) { + printf("Invalid character %c in hosts deny list %s for service %s.\n", + hasstar ? *hasstar : *hasquery, deny_list, lp_servicename(s) ); + } } - if (argc < 3) - { - if (!silent_mode) { - printf("Press enter to see a dump of your service definitions\n"); - fflush(stdout); - getc(stdin); + if(allow_list) { + char *hasstar = strchr(allow_list, '*'); + char *hasquery = strchr(allow_list, '?'); + if(hasstar || hasquery) { + printf("Invalid character %c in hosts allow list %s for service %s.\n", + hasstar ? *hasstar : *hasquery, allow_list, lp_servicename(s) ); + } } - lp_dump(stdout,True); + + if(lp_level2_oplocks(s) && !lp_oplocks(s)) { + printf("Invalid combination of parameters for service %s. \ +Level II oplocks can only be set if oplocks are also set.\n", + lp_servicename(s) ); + } + } + } + + if (argc < 3) { + if (!silent_mode) { + printf("Press enter to see a dump of your service definitions\n"); + fflush(stdout); + getc(stdin); } + lp_dump(stdout,True, lp_numservices()); + } - if (argc >= 3) - { - char *cname; - char *caddr; + if (argc >= 3) { + char *cname; + char *caddr; - if (argc == 3) { - cname = argv[optind]; - caddr = argv[optind+1]; - } else if (argc == 4) { - cname = argv[optind+1]; - caddr = argv[optind+2]; - } + if (argc == 3) { + cname = argv[optind]; + caddr = argv[optind+1]; + } else { + cname = argv[optind+1]; + caddr = argv[optind+2]; + } - /* this is totally ugly, a real `quick' hack */ - for (s=0;s<1000;s++) - if (VALID_SNUM(s)) - { - if (allow_access(lp_hostsdeny(s),lp_hostsallow(s),cname,caddr)) - { - printf("Allow connection from %s (%s) to %s\n", - cname,caddr,lp_servicename(s)); - } - else - { - printf("Deny connection from %s (%s) to %s\n", - cname,caddr,lp_servicename(s)); - } - } + /* this is totally ugly, a real `quick' hack */ + for (s=0;s<1000;s++) { + if (VALID_SNUM(s)) { + if (allow_access(lp_hostsdeny(s),lp_hostsallow(s),cname,caddr)) { + printf("Allow connection from %s (%s) to %s\n", + cname,caddr,lp_servicename(s)); + } else { + printf("Deny connection from %s (%s) to %s\n", + cname,caddr,lp_servicename(s)); + } + } } - return(0); + } + return(ret); } - - diff --git a/source3/utils/torture.c b/source3/utils/torture.c index 6dea2f2d22..9dc9d664b2 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -23,12 +23,13 @@ #include "includes.h" -extern int DEBUGLEVEL; -extern pstring debugf; - static fstring host, workgroup, share, password, username, myname; static int max_protocol = PROTOCOL_NT1; -static char *sockops=""; +static char *sockops="TCP_NODELAY"; +static int nprocs=1, numops=100; +static struct cli_state current_cli; + +static double create_procs(void (*fn)(int)); static struct timeval tp1,tp2; @@ -45,82 +46,101 @@ static double end_timer(void) (tp2.tv_usec - tp1.tv_usec)*1.0e-6); } -#define FAILED_NO_ERROR 0 -#define FAILED_TCP_CONNECT 1 -#define FAILED_SESSION_REQ 2 -#define FAILED_SMB_SESS_SETUP 3 -#define FAILED_SMB_TCON 4 -#define FAILED_SMB_NEGPROT 5 -#define FAILED_CLI_STATE_INIT 6 -#define NUM_ERR_STATES 7 -static char *smb_messages[] = +/* return a pointer to a anonymous shared memory segment of size "size" + which will persist across fork() but will disappear when all processes + exit + + The memory is not zeroed + + This function uses system5 shared memory. It takes advantage of a property + that the memory is not destroyed if it is attached when the id is removed + */ +static void *shm_setup(int size) { - "No errors in connection", - "TCP connection ", - "NetBIOS Session Request", - "SMB Session Setup ", - "SMB Tcon ", - "SMB Negprot ", - "Client initialisation " -}; - -static int open_connection(struct cli_state *c) + int shmid; + void *ret; + + shmid = shmget(IPC_PRIVATE, size, SHM_R | SHM_W); + if (shmid == -1) { + printf("can't get shared memory\n"); + exit(1); + } + ret = (void *)shmat(shmid, 0, 0); + if (!ret || ret == (void *)-1) { + printf("can't attach to shared memory\n"); + return NULL; + } + /* the following releases the ipc, but note that this process + and all its children will still have access to the memory, its + just that the shmid is no longer valid for other shm calls. This + means we don't leave behind lots of shm segments after we exit + + See Stevens "advanced programming in unix env" for details + */ + shmctl(shmid, IPC_RMID, 0); + + return ret; +} + + +static BOOL open_connection(struct cli_state *c) { struct nmb_name called, calling; + struct in_addr ip; + extern struct in_addr ipzero; ZERO_STRUCTP(c); make_nmb_name(&calling, myname, 0x0, ""); make_nmb_name(&called , host, 0x20, ""); - if (!cli_initialise(c)) - { - DEBUG(0,("Failed to connect with %s\n", host)); - return FAILED_CLI_STATE_INIT; - } + ip = ipzero; - if (!cli_connect(c, host, NULL)) { - DEBUG(0,("Failed to connect with %s\n", host)); - return FAILED_TCP_CONNECT; + if (!cli_initialise(c) || !cli_connect(c, host, &ip)) { + printf("Failed to connect with %s\n", host); + return False; } + c->timeout = 120000; /* set a really long timeout (2 minutes) */ + if (!cli_session_request(c, &calling, &called)) { + printf("%s rejected the session\n",host); cli_shutdown(c); - DEBUG(0,("%s rejected the session\n",host)); - return FAILED_SESSION_REQ; + return False; } if (!cli_negprot(c)) { - DEBUG(0,("%s rejected the negprot (%s)\n",host, cli_errstr(c))); + printf("%s rejected the negprot (%s)\n",host, cli_errstr(c)); cli_shutdown(c); - return FAILED_SMB_NEGPROT; + return False; } if (!cli_session_setup(c, username, password, strlen(password), password, strlen(password), workgroup)) { - DEBUG(0,("%s rejected the sessionsetup (%s)\n", host, cli_errstr(c))); + printf("%s rejected the sessionsetup (%s)\n", host, cli_errstr(c)); cli_shutdown(c); - return FAILED_SMB_SESS_SETUP; + return False; } if (!cli_send_tconX(c, share, "?????", password, strlen(password)+1)) { - DEBUG(0,("%s refused tree connect (%s)\n", host, cli_errstr(c))); + printf("%s refused tree connect (%s)\n", host, cli_errstr(c)); cli_shutdown(c); - return FAILED_SMB_TCON; + return False; } - return FAILED_NO_ERROR; + return True; } + static void close_connection(struct cli_state *c) { if (!cli_tdis(c)) { - DEBUG(0,("tdis failed (%s)\n", cli_errstr(c))); + printf("tdis failed (%s)\n", cli_errstr(c)); } cli_shutdown(c); @@ -133,14 +153,13 @@ static BOOL check_error(struct cli_state *c, { uint8 class; uint32 num; - int eno; - eno = cli_error(c, &class, &num); + (void)cli_error(c, &class, &num, NULL); if ((eclass != class || ecode != num) && num != (nterr&0xFFFFFF)) { - DEBUG(0,("unexpected error code class=%d code=%d\n", - (int)class, (int)num)); - DEBUG(0,(" expected %d/%d %d\n", - (int)eclass, (int)ecode, (int)nterr)); + printf("unexpected error code class=%d code=%d\n", + (int)class, (int)num); + printf(" expected %d/%d %d\n", + (int)eclass, (int)ecode, (int)nterr); return False; } return True; @@ -156,13 +175,13 @@ static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len) } -static BOOL rw_torture(struct cli_state *c, int numops) +static BOOL rw_torture(struct cli_state *c) { char *lockfname = "\\torture.lck"; fstring fname; int fnum; int fnum2; - int pid2, pid = getpid(); + pid_t pid2, pid = getpid(); int i, j; char buf[1024]; @@ -171,7 +190,7 @@ static BOOL rw_torture(struct cli_state *c, int numops) if (fnum2 == -1) fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE); if (fnum2 == -1) { - DEBUG(0,("open of %s failed (%s)\n", lockfname, cli_errstr(c))); + printf("open of %s failed (%s)\n", lockfname, cli_errstr(c)); return False; } @@ -179,7 +198,7 @@ static BOOL rw_torture(struct cli_state *c, int numops) for (i=0;i\n"); + struct cli_state cli; - printf("\t-U user%%pass\n"); - printf("\t-N numprocs\n"); - printf("\t-n my_netbios_name\n"); - printf("\t-W workgroup\n"); - printf("\t-o num_operations\n"); - printf("\t-O socket_options\n"); - printf("\t-m maximum protocol\n"); - printf("\n"); + cli = current_cli; - exit(1); -} + cli_sockopt(&cli, sockops); + rw_torture(&cli); + + close_connection(&cli); +} +int line_count = 0; -static void run_torture(int numops) +/* run a test that simulates an approximate netbench client load */ +static void run_netbench(int client) { - static struct cli_state cli; + struct cli_state cli; + int i; + fstring fname; + pstring line; + char cname[20]; + FILE *f; + char *params[20]; + + cli = current_cli; + + cli_sockopt(&cli, sockops); - if (open_connection(&cli) == 0) - { - cli_sockopt(&cli, sockops); + nb_setup(&cli); - DEBUG(0,("pid %d OK\n", getpid())); + slprintf(cname,sizeof(fname), "CLIENT%d", client); - rw_torture(&cli, numops); + f = fopen("client.txt", "r"); - close_connection(&cli); + if (!f) { + perror("client.txt"); + return; } - else - { - DEBUG(0,("pid %d failed\n", getpid())); + + while (fgets(line, sizeof(line)-1, f)) { + line_count++; + + line[strlen(line)-1] = 0; + + /* printf("[%d] %s\n", line_count, line); */ + + all_string_sub(line,"CLIENT1", cname, sizeof(line)); + + for (i=0;i<20;i++) params[i] = ""; + + /* parse the command parameters */ + params[0] = strtok(line," "); + i = 0; + while (params[i]) params[++i] = strtok(NULL," "); + + params[i] = ""; + + if (i < 2) continue; + + if (strcmp(params[1],"REQUEST") == 0) { + if (!strcmp(params[0],"SMBopenX")) { + fstrcpy(fname, params[5]); + } else if (!strcmp(params[0],"SMBclose")) { + nb_close(atoi(params[3])); + } else if (!strcmp(params[0],"SMBmkdir")) { + nb_mkdir(params[3]); + } else if (!strcmp(params[0],"CREATE")) { + nb_create(params[3], atoi(params[5])); + } else if (!strcmp(params[0],"SMBrmdir")) { + nb_rmdir(params[3]); + } else if (!strcmp(params[0],"SMBunlink")) { + fstrcpy(fname, params[3]); + } else if (!strcmp(params[0],"SMBmv")) { + nb_rename(params[3], params[5]); + } else if (!strcmp(params[0],"SMBgetatr")) { + fstrcpy(fname, params[3]); + } else if (!strcmp(params[0],"SMBwrite")) { + nb_write(atoi(params[3]), + atoi(params[5]), atoi(params[7])); + } else if (!strcmp(params[0],"SMBwritebraw")) { + nb_write(atoi(params[3]), + atoi(params[7]), atoi(params[5])); + } else if (!strcmp(params[0],"SMBreadbraw")) { + nb_read(atoi(params[3]), + atoi(params[7]), atoi(params[5])); + } else if (!strcmp(params[0],"SMBread")) { + nb_read(atoi(params[3]), + atoi(params[5]), atoi(params[7])); + } + } else { + if (!strcmp(params[0],"SMBopenX")) { + if (!strncmp(params[2], "ERR", 3)) continue; + nb_open(fname, atoi(params[3]), atoi(params[5])); + } else if (!strcmp(params[0],"SMBgetatr")) { + if (!strncmp(params[2], "ERR", 3)) continue; + nb_stat(fname, atoi(params[3])); + } else if (!strcmp(params[0],"SMBunlink")) { + if (!strncmp(params[2], "ERR", 3)) continue; + nb_unlink(fname); + } + } } + fclose(f); + + slprintf(fname,sizeof(fname), "CLIENTS/CLIENT%d", client); + rmdir(fname); + rmdir("CLIENTS"); + printf("+"); + + close_connection(&cli); } + +/* run a test that simulates an approximate netbench w9X client load */ +static void run_nbw95(int dummy) +{ + double t; + t = create_procs(run_netbench); + /* to produce a netbench result we scale accoding to the + netbench measured throughput for the run that produced the + sniff that was used to produce client.txt. That run used 2 + clients and ran for 660 seconds to produce a result of + 4MBit/sec. */ + printf("Throughput %g MB/sec (NB=%g MB/sec %g MBit/sec)\n", + 132*nprocs/t, 0.5*0.5*nprocs*660/t, 2*nprocs*660/t); +} + +/* run a test that simulates an approximate netbench wNT client load */ +static void run_nbwnt(int dummy) +{ + double t; + t = create_procs(run_netbench); + printf("Throughput %g MB/sec (NB=%g MB/sec %g MBit/sec)\n", + 132*nprocs/t, 0.5*0.5*nprocs*660/t, 2*nprocs*660/t); +} + + + /* This test checks for two things: @@ -282,57 +403,57 @@ static void run_torture(int numops) must not use posix semantics) 2) support for lock timeouts */ -static void run_locktest1(void) +static void run_locktest1(int dummy) { static struct cli_state cli1, cli2; char *fname = "\\lockt1.lck"; int fnum1, fnum2, fnum3; time_t t1, t2; - if (open_connection(&cli1) != 0 || open_connection(&cli2) != 0) { + if (!open_connection(&cli1) || !open_connection(&cli2)) { return; } cli_sockopt(&cli1, sockops); cli_sockopt(&cli2, sockops); - DEBUG(0,("starting locktest1\n")); + printf("starting locktest1\n"); cli_unlink(&cli1, fname); fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); if (fnum1 == -1) { - DEBUG(0,("open of %s failed (%s)\n", fname, cli_errstr(&cli1))); + printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1)); return; } fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_NONE); if (fnum2 == -1) { - DEBUG(0,("open2 of %s failed (%s)\n", fname, cli_errstr(&cli1))); + printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli1)); return; } fnum3 = cli_open(&cli2, fname, O_RDWR, DENY_NONE); if (fnum3 == -1) { - DEBUG(0,("open3 of %s failed (%s)\n", fname, cli_errstr(&cli2))); + printf("open3 of %s failed (%s)\n", fname, cli_errstr(&cli2)); return; } if (!cli_lock(&cli1, fnum1, 0, 4, 0)) { - DEBUG(0,("lock1 failed (%s)\n", cli_errstr(&cli1))); + printf("lock1 failed (%s)\n", cli_errstr(&cli1)); return; } if (cli_lock(&cli2, fnum3, 0, 4, 0)) { - DEBUG(0,("lock2 succeeded! This is a locking bug\n")); + printf("lock2 succeeded! This is a locking bug\n"); return; } else { if (!check_error(&cli2, ERRDOS, ERRlock, 0)) return; } - DEBUG(0,("Testing lock timeouts\n")); + printf("Testing lock timeouts\n"); t1 = time(NULL); if (cli_lock(&cli2, fnum3, 0, 4, 10*1000)) { - DEBUG(0,("lock3 succeeded! This is a locking bug\n")); + printf("lock3 succeeded! This is a locking bug\n"); return; } else { if (!check_error(&cli2, ERRDOS, ERRlock, 0)) return; @@ -340,33 +461,33 @@ static void run_locktest1(void) t2 = time(NULL); if (t2 - t1 < 5) { - DEBUG(0,("error: This server appears not to support timed lock requests\n")); + printf("error: This server appears not to support timed lock requests\n"); } if (!cli_close(&cli1, fnum2)) { - DEBUG(0,("close1 failed (%s)\n", cli_errstr(&cli1))); + printf("close1 failed (%s)\n", cli_errstr(&cli1)); return; } if (cli_lock(&cli2, fnum3, 0, 4, 0)) { - DEBUG(0,("lock4 succeeded! This is a locking bug\n")); + printf("lock4 succeeded! This is a locking bug\n"); return; } else { if (!check_error(&cli2, ERRDOS, ERRlock, 0)) return; } if (!cli_close(&cli1, fnum1)) { - DEBUG(0,("close2 failed (%s)\n", cli_errstr(&cli1))); + printf("close2 failed (%s)\n", cli_errstr(&cli1)); return; } if (!cli_close(&cli2, fnum3)) { - DEBUG(0,("close3 failed (%s)\n", cli_errstr(&cli2))); + printf("close3 failed (%s)\n", cli_errstr(&cli2)); return; } if (!cli_unlink(&cli1, fname)) { - DEBUG(0,("unlink failed (%s)\n", cli_errstr(&cli1))); + printf("unlink failed (%s)\n", cli_errstr(&cli1)); return; } @@ -374,7 +495,7 @@ static void run_locktest1(void) close_connection(&cli1); close_connection(&cli2); - DEBUG(0,("Passed locktest1\n")); + printf("Passed locktest1\n"); } @@ -389,19 +510,19 @@ static void run_locktest1(void) 3) the server denies unlock requests by an incorrect client PID */ -static void run_locktest2(void) +static void run_locktest2(int dummy) { static struct cli_state cli; char *fname = "\\lockt2.lck"; int fnum1, fnum2, fnum3; - if (open_connection(&cli) != 0) { + if (!open_connection(&cli)) { return; } cli_sockopt(&cli, sockops); - DEBUG(0,("starting locktest2\n")); + printf("starting locktest2\n"); cli_unlink(&cli, fname); @@ -409,13 +530,13 @@ static void run_locktest2(void) fnum1 = cli_open(&cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); if (fnum1 == -1) { - DEBUG(0,("open of %s failed (%s)\n", fname, cli_errstr(&cli))); + printf("open of %s failed (%s)\n", fname, cli_errstr(&cli)); return; } fnum2 = cli_open(&cli, fname, O_RDWR, DENY_NONE); if (fnum2 == -1) { - DEBUG(0,("open2 of %s failed (%s)\n", fname, cli_errstr(&cli))); + printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli)); return; } @@ -423,19 +544,19 @@ static void run_locktest2(void) fnum3 = cli_open(&cli, fname, O_RDWR, DENY_NONE); if (fnum3 == -1) { - DEBUG(0,("open3 of %s failed (%s)\n", fname, cli_errstr(&cli))); + printf("open3 of %s failed (%s)\n", fname, cli_errstr(&cli)); return; } cli_setpid(&cli, 1); if (!cli_lock(&cli, fnum1, 0, 4, 0)) { - DEBUG(0,("lock1 failed (%s)\n", cli_errstr(&cli))); + printf("lock1 failed (%s)\n", cli_errstr(&cli)); return; } if (cli_lock(&cli, fnum2, 0, 4, 0)) { - DEBUG(0,("lock2 succeeded! This is a locking bug\n")); + printf("lock2 succeeded! This is a locking bug\n"); } else { if (!check_error(&cli, ERRDOS, ERRlock, 0)) return; } @@ -443,11 +564,11 @@ static void run_locktest2(void) cli_setpid(&cli, 2); if (cli_unlock(&cli, fnum1, 0, 4, 0)) { - DEBUG(0,("unlock1 succeeded! This is a locking bug\n")); + printf("unlock1 succeeded! This is a locking bug\n"); } if (cli_lock(&cli, fnum3, 0, 4, 0)) { - DEBUG(0,("lock3 succeeded! This is a locking bug\n")); + printf("lock3 succeeded! This is a locking bug\n"); } else { if (!check_error(&cli, ERRDOS, ERRlock, 0)) return; } @@ -455,23 +576,23 @@ static void run_locktest2(void) cli_setpid(&cli, 1); if (!cli_close(&cli, fnum1)) { - DEBUG(0,("close1 failed (%s)\n", cli_errstr(&cli))); + printf("close1 failed (%s)\n", cli_errstr(&cli)); return; } if (!cli_close(&cli, fnum2)) { - DEBUG(0,("close2 failed (%s)\n", cli_errstr(&cli))); + printf("close2 failed (%s)\n", cli_errstr(&cli)); return; } if (!cli_close(&cli, fnum3)) { - DEBUG(0,("close3 failed (%s)\n", cli_errstr(&cli))); + printf("close3 failed (%s)\n", cli_errstr(&cli)); return; } close_connection(&cli); - DEBUG(0,("locktest2 finished\n")); + printf("locktest2 finished\n"); } @@ -480,7 +601,7 @@ static void run_locktest2(void) 1) the server supports the full offset range in lock requests */ -static void run_locktest3(int numops) +static void run_locktest3(int dummy) { static struct cli_state cli1, cli2; char *fname = "\\lockt3.lck"; @@ -489,40 +610,40 @@ static void run_locktest3(int numops) #define NEXT_OFFSET offset += (~(uint32)0) / numops - if (open_connection(&cli1) != 0 || open_connection(&cli2) != 0) { + if (!open_connection(&cli1) || !open_connection(&cli2)) { return; } cli_sockopt(&cli1, sockops); cli_sockopt(&cli2, sockops); - DEBUG(0,("starting locktest3\n")); + printf("starting locktest3\n"); cli_unlink(&cli1, fname); fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); if (fnum1 == -1) { - DEBUG(0,("open of %s failed (%s)\n", fname, cli_errstr(&cli1))); + printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1)); return; } fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE); if (fnum2 == -1) { - DEBUG(0,("open2 of %s failed (%s)\n", fname, cli_errstr(&cli2))); + printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli2)); return; } for (offset=i=0;i n) { fnum--; - slprintf(fname,sizeof(fname)-1,template, fnum,getpid()); + slprintf(fname,sizeof(fname)-1,template, fnum,(int)getpid()); if (cli_unlink(&cli, fname)) { - DEBUG(0,("unlink of %s failed (%s)\n", - fname, cli_errstr(&cli))); + printf("unlink of %s failed (%s)\n", + fname, cli_errstr(&cli)); } } - DEBUG(0,("maxfid test finished\n")); + printf("maxfid test finished\n"); close_connection(&cli); } @@ -740,116 +858,45 @@ static void run_maxfidtest(int n) static void rand_buf(char *buf, int len) { while (len--) { - *buf = sys_random(); + *buf = (char)sys_random(); buf++; } } -#define TORT_BUFFER_SIZE 1024 - /* send random IPC commands */ -static void run_randomipc(int numops) +static void run_randomipc(int dummy) { char *rparam = NULL; char *rdata = NULL; int rdrcnt,rprcnt; - char param[TORT_BUFFER_SIZE]; + pstring param; int api, param_len, i; - int reconnect_count = 500; static struct cli_state cli; - DEBUG(0,("starting random ipc test\n")); - - while (reconnect_count > 0 && open_connection(&cli) != 0) - { - DEBUG(0,("connection failed: retrying %d\n", reconnect_count)); - msleep(sys_random() % 5000); - reconnect_count--; - } + printf("starting random ipc test\n"); - if (reconnect_count == 0) - { + if (!open_connection(&cli)) { return; } - for (i=0;i 0 && open_connection(&cli) != 0) - { - DEBUG(0,("connection failed: retrying %d\n", reconnect_count)); - msleep(sys_random() % 5000); - reconnect_count--; - } - - if (reconnect_count == 0) - { - return; - } - - for (i=0;i 2) { - DEBUG(0,("ERROR: SMBgetatr bug. time is %s", - ctime(&t))); + printf("ERROR: SMBgetatr bug. time is %s", + ctime(&t)); t = time(NULL); } t2 = t-60*60*24; /* 1 day ago */ if (!cli_setatr(&cli, fname, 0, t2)) { - DEBUG(0,("setatr failed (%s)\n", cli_errstr(&cli))); + printf("setatr failed (%s)\n", cli_errstr(&cli)); } if (!cli_getatr(&cli, fname, NULL, NULL, &t)) { - DEBUG(0,("getatr failed (%s)\n", cli_errstr(&cli))); + printf("getatr failed (%s)\n", cli_errstr(&cli)); } if (t != t2) { - DEBUG(0,("ERROR: getatr/setatr bug. times are\n%s", - ctime(&t))); - DEBUG(0,("%s", ctime(&t2))); + printf("ERROR: getatr/setatr bug. times are\n%s", + ctime(&t)); + printf("%s", ctime(&t2)); } cli_unlink(&cli, fname); close_connection(&cli); - DEBUG(0,("attrib test finished\n")); + printf("attrib test finished\n"); } /* This checks a couple of trans2 calls */ -static void run_trans2test(void) +static void run_trans2test(int dummy) { static struct cli_state cli; int fnum; @@ -959,9 +1006,9 @@ static void run_trans2test(void) char *dname = "\\trans2"; char *fname2 = "\\trans2\\trans2.tst"; - DEBUG(0,("starting trans2 test\n")); + printf("starting trans2 test\n"); - if (open_connection(&cli) != 0) { + if (!open_connection(&cli)) { return; } @@ -970,7 +1017,7 @@ static void run_trans2test(void) O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); if (!cli_qfileinfo(&cli, fnum, NULL, &size, &c_time, &a_time, &m_time, NULL, NULL)) { - DEBUG(0,("ERROR: qfileinfo failed (%s)\n", cli_errstr(&cli))); + printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(&cli)); } cli_close(&cli, fnum); @@ -982,20 +1029,20 @@ static void run_trans2test(void) cli_close(&cli, fnum); if (!cli_qpathinfo(&cli, fname, &c_time, &a_time, &m_time, &size, NULL)) { - DEBUG(0,("ERROR: qpathinfo failed (%s)\n", cli_errstr(&cli))); + printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(&cli)); } else { if (c_time != m_time) { - DEBUG(0,("create time=%s", ctime(&c_time))); - DEBUG(0,("modify time=%s", ctime(&m_time))); - DEBUG(0,("This system appears to have sticky create times\n")); + printf("create time=%s", ctime(&c_time)); + printf("modify time=%s", ctime(&m_time)); + printf("This system appears to have sticky create times\n"); } if (a_time % (60*60) == 0) { - DEBUG(0,("access time=%s", ctime(&a_time))); - DEBUG(0,("This system appears to set a midnight access time\n")); + printf("access time=%s", ctime(&a_time)); + printf("This system appears to set a midnight access time\n"); } if (abs(m_time - time(NULL)) > 60*60*24*7) { - DEBUG(0,("ERROR: totally incorrect times - maybe word reversed?\n")); + printf("ERROR: totally incorrect times - maybe word reversed?\n"); } } @@ -1006,11 +1053,11 @@ static void run_trans2test(void) cli_close(&cli, fnum); if (!cli_qpathinfo2(&cli, fname, &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL)) { - DEBUG(0,("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli))); + printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); } else { if (w_time < 60*60*24*2) { - DEBUG(0,("write time=%s", ctime(&w_time))); - DEBUG(0,("This system appears to set a initial 0 write time\n")); + printf("write time=%s", ctime(&w_time)); + printf("This system appears to set a initial 0 write time\n"); } } @@ -1020,12 +1067,12 @@ static void run_trans2test(void) /* check if the server updates the directory modification time when creating a new file */ if (!cli_mkdir(&cli, dname)) { - DEBUG(0,("ERROR: mkdir failed (%s)\n", cli_errstr(&cli))); + printf("ERROR: mkdir failed (%s)\n", cli_errstr(&cli)); } sleep(3); if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL)) { - DEBUG(0,("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli))); + printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); } fnum = cli_open(&cli, fname2, @@ -1034,10 +1081,10 @@ static void run_trans2test(void) cli_close(&cli, fnum); if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time2, &w_time, &size, NULL, NULL)) { - DEBUG(0,("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli))); + printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); } else { if (m_time2 == m_time) - DEBUG(0,("This system does not update directory modification times\n")); + printf("This system does not update directory modification times\n"); } cli_unlink(&cli, fname2); cli_rmdir(&cli, dname); @@ -1045,105 +1092,298 @@ static void run_trans2test(void) close_connection(&cli); - DEBUG(0,("trans2 test finished\n")); + printf("trans2 test finished\n"); } -static void run_connection(int numops) +/* + this is a harness for some oplock tests + */ +static void run_oplock(int dummy) { - struct cli_state c; - int count = 0; - int failed[NUM_ERR_STATES]; - int i; + static struct cli_state cli1, cli2; + char *fname = "\\lockt1.lck"; + char *fname2 = "\\lockt2.lck"; + int fnum1, fnum2; - DEBUG(0,("Connection test starts:\n")); + printf("starting oplock test\n"); - for (i = 0; i < NUM_ERR_STATES; i++) - { - failed[i] = 0; + if (!open_connection(&cli1)) { + return; } - for (i = 0; i < numops; i++) - { - int err; - DEBUG(0,("Connection test %d %d\n", i, numops)); - if ((err = open_connection(&c))) - { - failed[err]++; - } - count++; + cli_unlink(&cli1, fname); + + cli_sockopt(&cli1, sockops); + + cli1.use_oplocks = True; + + fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum1 == -1) { + printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1)); + return; + } + + cli1.use_oplocks = False; + + cli_unlink(&cli1, fname); + cli_unlink(&cli1, fname); + + if (!cli_close(&cli1, fnum1)) { + printf("close2 failed (%s)\n", cli_errstr(&cli1)); + return; } - { - int failtotal = 0; + if (!cli_unlink(&cli1, fname)) { + printf("unlink failed (%s)\n", cli_errstr(&cli1)); + return; + } + + + close_connection(&cli1); + + printf("finished oplock test\n"); +} + + +static void list_fn(file_info *finfo, const char *name) +{ + +} + +/* + test directory listing speed + */ +static void run_dirtest(int dummy) +{ + int i; + static struct cli_state cli; + int fnum; + double t1; + + printf("starting directory test\n"); + + if (!open_connection(&cli)) { + return; + } + + cli_sockopt(&cli, sockops); - for (i = 0, failtotal = 0; i < NUM_ERR_STATES; i++) - { - failtotal += failed[i]; + srandom(0); + for (i=0;i TEST1 TEST2 ...\n"); + + printf("\t-U user%%pass\n"); + printf("\t-N numprocs\n"); + printf("\t-n my_netbios_name\n"); + printf("\t-W workgroup\n"); + printf("\t-o num_operations\n"); + printf("\t-O socket_options\n"); + printf("\t-m maximum protocol\n"); + printf("\n\n"); + + printf("tests are:"); + for (i=0;torture_ops[i].name;i++) { + printf(" %s", torture_ops[i].name); + } + printf("\n"); + + printf("default test is ALL\n"); + + exit(1); +} + + + -#define DEBUG_INTERACTIVE True /**************************************************************************** main program ****************************************************************************/ int main(int argc,char *argv[]) { - int nprocs=1, numops=100; - int opt; + int opt, i; char *p; int gotpass = 0; extern char *optarg; extern int optind; - extern BOOL append_log; - extern BOOL timestamp_log; + extern FILE *dbf; + static pstring servicesf = CONFIGFILE; + + dbf = stdout; - DEBUGLEVEL = 0; - pstrcpy(debugf,"./log.torture"); - setup_logging(argv[0], DEBUG_INTERACTIVE); - append_log = True; - timestamp_log = False; + setbuffer(stdout, NULL, 0); charset_initialise(); + lp_load(servicesf,True,False,False); + load_interfaces(); + if (argc < 2) { usage(); } @@ -1164,7 +1404,7 @@ static void create_procs(int nprocs, int numops, void (*fn)(int )) *p = 0; fstrcpy(share, p+1); - get_myname(myname,NULL); + get_myname(myname); if (*username == 0 && getenv("LOGNAME")) { pstrcpy(username,getenv("LOGNAME")); @@ -1174,6 +1414,8 @@ static void create_procs(int nprocs, int numops, void (*fn)(int )) argv++; + fstrcpy(workgroup, lp_workgroup()); + while ((opt = getopt(argc, argv, "hW:U:n:N:O:o:m:")) != EOF) { switch (opt) { case 'W': @@ -1218,35 +1460,16 @@ static void create_procs(int nprocs, int numops, void (*fn)(int )) } } - printf("host=%s share=%s user=%s myname=%s procs=%d ops=%d\n", - host, share, username, myname, nprocs, numops); + printf("host=%s share=%s user=%s myname=%s\n", + host, share, username, myname); - create_procs(nprocs, numops, run_randomipc); -/* - create_procs(nprocs, numops, run_randomipc_nowait); - - create_procs(nprocs, numops, run_connection); - - run_fdpasstest(); - run_locktest1(); - run_locktest2(); - run_locktest3(numops); - run_unlinktest(); - run_browsetest(); - run_attrtest(); - run_trans2test(); - - create_procs(nprocs, numops, run_maxfidtest); - - - - start_timer(); - create_procs(nprocs, numops, run_torture); - printf("rw_torture: %g secs\n", end_timer()); -*/ - dbgflush(); + if (argc == 1) { + run_test("ALL"); + } else { + for (i=1;i