torture/rpctorture.c

説明を見る。
00001 /* 
00002    Unix SMB/CIFS implementation.
00003    SMB client
00004    Copyright (C) Andrew Tridgell 1994-1998
00005    
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015    
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software
00018    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 */
00020 
00021 #include "includes.h"
00022 
00023 #ifndef REGISTER
00024 #define REGISTER 0
00025 #endif
00026 
00027 extern pstring global_myname;
00028 
00029 extern pstring user_socket_options;
00030 
00031 
00032 extern file_info def_finfo;
00033 
00034 #define CNV_LANG(s) dos2unix_format(s,False)
00035 #define CNV_INPUT(s) unix2dos_format(s,True)
00036 
00037 static struct cli_state smbcli;
00038 struct cli_state *smb_cli = &smbcli;
00039 
00040 FILE *out_hnd;
00041 
00042 static pstring password; /* local copy only, if one is entered */
00043 
00044 /****************************************************************************
00045 initialise smb client structure
00046 ****************************************************************************/
00047 void rpcclient_init(void)
00048 {
00049         memset((char *)smb_cli, '\0', sizeof(smb_cli));
00050         cli_initialise(smb_cli);
00051         smb_cli->capabilities |= CAP_NT_SMBS;
00052 }
00053 
00054 /****************************************************************************
00055 make smb client connection
00056 ****************************************************************************/
00057 static BOOL rpcclient_connect(struct client_info *info)
00058 {
00059         struct nmb_name calling;
00060         struct nmb_name called;
00061 
00062         make_nmb_name(&called , dns_to_netbios_name(info->dest_host ), info->name_type);
00063         make_nmb_name(&calling, dns_to_netbios_name(info->myhostname), 0x0);
00064 
00065         if (!cli_establish_connection(smb_cli, 
00066                                   info->dest_host, &info->dest_ip, 
00067                                   &calling, &called,
00068                                   info->share, info->svc_type,
00069                                   False, True))
00070         {
00071                 DEBUG(0,("rpcclient_connect: connection failed\n"));
00072                 cli_shutdown(smb_cli);
00073                 return False;
00074         }
00075 
00076         return True;
00077 }
00078 
00079 /****************************************************************************
00080 stop the smb connection(s?)
00081 ****************************************************************************/
00082 static void rpcclient_stop(void)
00083 {
00084         cli_shutdown(smb_cli);
00085 }
00086 
00087 /****************************************************************************
00088   log in as an nt user, log out again. 
00089 ****************************************************************************/
00090 void run_enums_test(int num_ops, struct client_info *cli_info, struct cli_state *cli)
00091 {
00092         pstring cmd;
00093         int i;
00094 
00095         /* establish connections.  nothing to stop these being re-established. */
00096         rpcclient_connect(cli_info);
00097 
00098         DEBUG(5,("rpcclient_connect: cli->fd:%d\n", cli->fd));
00099         if (cli->fd <= 0)
00100         {
00101                 fprintf(out_hnd, "warning: connection could not be established to %s<%02x>\n",
00102                                  cli_info->dest_host, cli_info->name_type);
00103                 return;
00104         }
00105         
00106         for (i = 0; i < num_ops; i++)
00107         {
00108                 set_first_token("");
00109                 cmd_srv_enum_sess(cli_info);
00110                 set_first_token("");
00111                 cmd_srv_enum_shares(cli_info);
00112                 set_first_token("");
00113                 cmd_srv_enum_files(cli_info);
00114 
00115                 if (password[0] != 0)
00116                 {
00117                         slprintf(cmd, sizeof(cmd)-1, "1");
00118                         set_first_token(cmd);
00119                 }
00120                 else
00121                 {
00122                         set_first_token("");
00123                 }
00124                 cmd_srv_enum_conn(cli_info);
00125         }
00126 
00127         rpcclient_stop();
00128 
00129 }
00130 
00131 /****************************************************************************
00132   log in as an nt user, log out again. 
00133 ****************************************************************************/
00134 void run_ntlogin_test(int num_ops, struct client_info *cli_info, struct cli_state *cli)
00135 {
00136         pstring cmd;
00137         int i;
00138 
00139         /* establish connections.  nothing to stop these being re-established. */
00140         rpcclient_connect(cli_info);
00141 
00142         DEBUG(5,("rpcclient_connect: cli->fd:%d\n", cli->fd));
00143         if (cli->fd <= 0)
00144         {
00145                 fprintf(out_hnd, "warning: connection could not be established to %s<%02x>\n",
00146                                  cli_info->dest_host, cli_info->name_type);
00147                 return;
00148         }
00149         
00150         for (i = 0; i < num_ops; i++)
00151         {
00152                 slprintf(cmd, sizeof(cmd)-1, "%s %s", cli->user_name, password);
00153                 set_first_token(cmd);
00154 
00155                 cmd_netlogon_login_test(cli_info);
00156         }
00157 
00158         rpcclient_stop();
00159 
00160 }
00161 
00162 /****************************************************************************
00163   runs n simultaneous functions.
00164 ****************************************************************************/
00165 static void create_procs(int nprocs, int numops, 
00166                 struct client_info *cli_info, struct cli_state *cli,
00167                 void (*fn)(int, struct client_info *, struct cli_state *))
00168 {
00169         int i, status;
00170 
00171         for (i=0;i<nprocs;i++)
00172         {
00173                 if (fork() == 0)
00174                 {
00175                         pid_t mypid = getpid();
00176                         sys_srandom(mypid ^ time(NULL));
00177                         fn(numops, cli_info, cli);
00178                         fflush(out_hnd);
00179                         _exit(0);
00180                 }
00181         }
00182 
00183         for (i=0;i<nprocs;i++)
00184         {
00185                 waitpid(0, &status, 0);
00186         }
00187 }
00188 /****************************************************************************
00189 usage on the program - OUT OF DATE!
00190 ****************************************************************************/
00191 static void usage(char *pname)
00192 {
00193   fprintf(out_hnd, "Usage: %s service <password> [-d debuglevel] [-l log] ",
00194            pname);
00195 
00196   fprintf(out_hnd, "\nVersion %s\n",SAMBA_VERSION_STRING);
00197   fprintf(out_hnd, "\t-d debuglevel         set the debuglevel\n");
00198   fprintf(out_hnd, "\t-l log basename.      Basename for log/debug files\n");
00199   fprintf(out_hnd, "\t-n netbios name.      Use this name as my netbios name\n");
00200   fprintf(out_hnd, "\t-m max protocol       set the max protocol level\n");
00201   fprintf(out_hnd, "\t-I dest IP            use this IP to connect to\n");
00202   fprintf(out_hnd, "\t-E                    write messages to stderr instead of stdout\n");
00203   fprintf(out_hnd, "\t-U username           set the network username\n");
00204   fprintf(out_hnd, "\t-W workgroup          set the workgroup name\n");
00205   fprintf(out_hnd, "\t-t terminal code      terminal i/o code {sjis|euc|jis7|jis8|junet|hex}\n");
00206   fprintf(out_hnd, "\n");
00207 }
00208 
00209 enum client_action
00210 {
00211         CLIENT_NONE,
00212         CLIENT_IPC,
00213         CLIENT_SVC
00214 };
00215 
00216 /****************************************************************************
00217   main program
00218 ****************************************************************************/
00219  int main(int argc,char *argv[])
00220 {
00221         char *pname = argv[0];
00222         int opt;
00223         extern char *optarg;
00224         extern int optind;
00225         pstring term_code;
00226         BOOL got_pass = False;
00227         char *cmd_str="";
00228         enum client_action cli_action = CLIENT_NONE;
00229         int nprocs = 1;
00230         int numops = 100;
00231         pstring logfile;
00232 
00233         struct client_info cli_info;
00234 
00235         out_hnd = stdout;
00236 
00237         rpcclient_init();
00238 
00239 #ifdef KANJI
00240         pstrcpy(term_code, KANJI);
00241 #else /* KANJI */
00242         *term_code = 0;
00243 #endif /* KANJI */
00244 
00245         if (!lp_load(dyn_CONFIGFILE,True, False, False, True))
00246         {
00247                 fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE);
00248         }
00249 
00250         DEBUGLEVEL = 0;
00251 
00252         cli_info.put_total_size = 0;
00253         cli_info.put_total_time_ms = 0;
00254         cli_info.get_total_size = 0;
00255         cli_info.get_total_time_ms = 0;
00256 
00257         cli_info.dir_total = 0;
00258         cli_info.newer_than = 0;
00259         cli_info.archive_level = 0;
00260         cli_info.print_mode = 1;
00261 
00262         cli_info.translation = False;
00263         cli_info.recurse_dir = False;
00264         cli_info.lowercase = False;
00265         cli_info.prompt = True;
00266         cli_info.abort_mget = True;
00267 
00268         cli_info.dest_ip.s_addr = 0;
00269         cli_info.name_type = 0x20;
00270 
00271         pstrcpy(cli_info.cur_dir , "\\");
00272         pstrcpy(cli_info.file_sel, "");
00273         pstrcpy(cli_info.base_dir, "");
00274         pstrcpy(smb_cli->domain, "");
00275         pstrcpy(smb_cli->user_name, "");
00276         pstrcpy(cli_info.myhostname, "");
00277         pstrcpy(cli_info.dest_host, "");
00278 
00279         pstrcpy(cli_info.svc_type, "A:");
00280         pstrcpy(cli_info.share, "");
00281         pstrcpy(cli_info.service, "");
00282 
00283         ZERO_STRUCT(cli_info.dom.level3_sid);
00284         pstrcpy(cli_info.dom.level3_dom, "");
00285         ZERO_STRUCT(cli_info.dom.level5_sid);
00286         pstrcpy(cli_info.dom.level5_dom, "");
00287 
00288         {
00289                 int i;
00290                 for (i=0; i<PI_MAX_PIPES; i++)
00291                         smb_cli->pipes[i].fnum   = 0xffff;
00292         }
00293 
00294         setup_logging(pname, True);
00295 
00296         if (!get_myname(global_myname))
00297         {
00298                 fprintf(stderr, "Failed to get my hostname.\n");
00299         }
00300 
00301         password[0] = 0;
00302 
00303         if (argc < 2)
00304         {
00305                 usage(pname);
00306                 exit(1);
00307         }
00308 
00309         if (*argv[1] != '-')
00310         {
00311                 pstrcpy(cli_info.service, argv[1]);  
00312                 /* Convert any '/' characters in the service name to '\' characters */
00313                 string_replace( cli_info.service, '/','\\');
00314                 argc--;
00315                 argv++;
00316 
00317                 DEBUG(1,("service: %s\n", cli_info.service));
00318 
00319                 if (count_chars(cli_info.service,'\\') < 3)
00320                 {
00321                         usage(pname);
00322                         printf("\n%s: Not enough '\\' characters in service\n", cli_info.service);
00323                         exit(1);
00324                 }
00325 
00326                 /*
00327                 if (count_chars(cli_info.service,'\\') > 3)
00328                 {
00329                         usage(pname);
00330                         printf("\n%s: Too many '\\' characters in service\n", cli_info.service);
00331                         exit(1);
00332                 }
00333                 */
00334 
00335                 if (argc > 1 && (*argv[1] != '-'))
00336                 {
00337                         got_pass = True;
00338                         pstrcpy(password,argv[1]);  
00339                         memset(argv[1],'X',strlen(argv[1]));
00340                         argc--;
00341                         argv++;
00342                 }
00343 
00344                 cli_action = CLIENT_SVC;
00345         }
00346 
00347         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)
00348         {
00349                 switch (opt)
00350                 {
00351                         case 'm':
00352                         {
00353                                 /* FIXME ... max_protocol seems to be funny here */
00354 
00355                                 int max_protocol = 0;
00356                                 max_protocol = interpret_protocol(optarg,max_protocol);
00357                                 fprintf(stderr, "max protocol not currently supported\n");
00358                                 break;
00359                         }
00360 
00361                         case 'O':
00362                         {
00363                                 pstrcpy(user_socket_options,optarg);
00364                                 break;  
00365                         }
00366 
00367                         case 'S':
00368                         {
00369                                 pstrcpy(cli_info.dest_host,optarg);
00370                                 strupper_m(cli_info.dest_host);
00371                                 cli_action = CLIENT_IPC;
00372                                 break;
00373                         }
00374 
00375                         case 'i':
00376                         {
00377                                 pstrcpy(scope, optarg);
00378                                 break;
00379                         }
00380 
00381                         case 'U':
00382                         {
00383                                 char *lp;
00384                                 pstrcpy(smb_cli->user_name,optarg);
00385                                 if ((lp=strchr_m(smb_cli->user_name,'%')))
00386                                 {
00387                                         *lp = 0;
00388                                         pstrcpy(password,lp+1);
00389                                         got_pass = True;
00390                                         memset(strchr_m(optarg,'%')+1,'X',strlen(password));
00391                                 }
00392                                 break;
00393                         }
00394 
00395                         case 'W':
00396                         {
00397                                 pstrcpy(smb_cli->domain,optarg);
00398                                 break;
00399                         }
00400 
00401                         case 'E':
00402                         {
00403                                 dbf = x_stderr;
00404                                 break;
00405                         }
00406 
00407                         case 'I':
00408                         {
00409                                 cli_info.dest_ip = *interpret_addr2(optarg);
00410                                 if (is_zero_ip(cli_info.dest_ip))
00411                                 {
00412                                         exit(1);
00413                                 }
00414                                 break;
00415                         }
00416 
00417                         case 'N':
00418                         {
00419                                 nprocs = atoi(optarg);
00420                                 break;
00421                         }
00422 
00423                         case 'o':
00424                         {
00425                                 numops = atoi(optarg);
00426                                 break;
00427                         }
00428 
00429                         case 'n':
00430                         {
00431                                 fstrcpy(global_myname, optarg);
00432                                 break;
00433                         }
00434 
00435                         case 'd':
00436                         {
00437                                 if (*optarg == 'A')
00438                                         DEBUGLEVEL = 10000;
00439                                 else
00440                                         DEBUGLEVEL = atoi(optarg);
00441                                 break;
00442                         }
00443 
00444                         case 'l':
00445                         {
00446                                 slprintf(logfile, sizeof(logfile)-1,
00447                                          "%s.client",optarg);
00448                                 lp_set_logfile(logfile);
00449                                 break;
00450                         }
00451 
00452                         case 'c':
00453                         {
00454                                 cmd_str = optarg;
00455                                 got_pass = True;
00456                                 break;
00457                         }
00458 
00459                         case 'h':
00460                         {
00461                                 usage(pname);
00462                                 exit(0);
00463                                 break;
00464                         }
00465 
00466                         case 's':
00467                         {
00468                                 pstrcpy(dyn_CONFIGFILE, optarg);
00469                                 break;
00470                         }
00471 
00472                         case 't':
00473                         {
00474                                 pstrcpy(term_code, optarg);
00475                                 break;
00476                         }
00477 
00478                         default:
00479                         {
00480                                 usage(pname);
00481                                 exit(1);
00482                                 break;
00483                         }
00484                 }
00485         }
00486 
00487         if (cli_action == CLIENT_NONE)
00488         {
00489                 usage(pname);
00490                 exit(1);
00491         }
00492 
00493         strupper_m(global_myname);
00494         fstrcpy(cli_info.myhostname, global_myname);
00495 
00496         DEBUG(3,("%s client started (version %s)\n",current_timestring(False),SAMBA_VERSION_STRING));
00497 
00498         if (*smb_cli->domain == 0)
00499         {
00500                 pstrcpy(smb_cli->domain,lp_workgroup());
00501         }
00502         strupper_m(smb_cli->domain);
00503 
00504         load_interfaces();
00505 
00506         if (cli_action == CLIENT_IPC)
00507         {
00508                 pstrcpy(cli_info.share, "IPC$");
00509                 pstrcpy(cli_info.svc_type, "IPC");
00510         }
00511 
00512         fstrcpy(cli_info.mach_acct, cli_info.myhostname);
00513         strupper_m(cli_info.mach_acct);
00514         fstrcat(cli_info.mach_acct, "$");
00515 
00516         /* set the password cache info */
00517         if (got_pass)
00518         {
00519                 if (password[0] == 0)
00520                 {
00521                         pwd_set_nullpwd(&(smb_cli->pwd));
00522                 }
00523                 else
00524                 {
00525                         pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */
00526                 }
00527         }
00528         else 
00529         {
00530                 char *pwd = getpass("Enter Password:");
00531                 safe_strcpy(password, pwd, sizeof(password));
00532                 pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */
00533         }
00534 
00535         create_procs(nprocs, numops, &cli_info, smb_cli, run_enums_test);
00536 
00537         if (password[0] != 0)
00538         {
00539                 create_procs(nprocs, numops, &cli_info, smb_cli, run_ntlogin_test);
00540         }
00541 
00542         fflush(out_hnd);
00543 
00544         return(0);
00545 }

Sambaに対してSat Aug 29 21:23:27 2009に生成されました。  doxygen 1.4.7