/**************************************************************************** log in as an nt user, log out again. ****************************************************************************/ void run_ntlogin_test(int num_ops, struct client_info *cli_info, struct cli_state *cli) { pstring cmd; int i; /* establish connections. nothing to stop these being re-established. */ rpcclient_connect(cli_info); DEBUG(5,("rpcclient_connect: cli->fd:%d\n", cli->fd)); if (cli->fd <= 0) { fprintf(out_hnd, "warning: connection could not be established to %s<%02x>\n", cli_info->dest_host, cli_info->name_type); return; } for (i = 0; i < num_ops; i++) { slprintf(cmd, sizeof(cmd)-1, "%s %s", cli->user_name, password); set_first_token(cmd); cmd_netlogon_login_test(cli_info); } rpcclient_stop(); }
/**************************************************************************** log in as an nt user, log out again. ****************************************************************************/ void run_enums_test(int num_ops, struct client_info *cli_info, struct cli_state *cli) { pstring cmd; int i; /* establish connections. nothing to stop these being re-established. */ rpcclient_connect(cli_info); DEBUG(5,("rpcclient_connect: cli->fd:%d\n", cli->fd)); if (cli->fd <= 0) { fprintf(out_hnd, "warning: connection could not be established to %s<%02x>\n", cli_info->dest_host, cli_info->name_type); return; } for (i = 0; i < num_ops; i++) { set_first_token(""); cmd_srv_enum_sess(cli_info); set_first_token(""); cmd_srv_enum_shares(cli_info); set_first_token(""); cmd_srv_enum_files(cli_info); if (password[0] != 0) { slprintf(cmd, sizeof(cmd)-1, "1"); set_first_token(cmd); } else { set_first_token(""); } cmd_srv_enum_conn(cli_info); } rpcclient_stop(); }
/**************************************************************************** main program ****************************************************************************/ int main(int argc,char *argv[]) { BOOL interactive = True; int opt; extern FILE *dbf; extern char *optarg; extern int optind; static pstring servicesf = CONFIGFILE; pstring term_code; char *p; BOOL got_pass = False; char *cmd_str=""; mode_t myumask = 0755; enum client_action cli_action = CLIENT_NONE; struct client_info cli_info; pstring password; /* local copy only, if one is entered */ out_hnd = stdout; fstrcpy(debugf, argv[0]); rpcclient_init(); #ifdef KANJI pstrcpy(term_code, KANJI); #else /* KANJI */ *term_code = 0; #endif /* KANJI */ DEBUGLEVEL = 2; cli_info.put_total_size = 0; cli_info.put_total_time_ms = 0; cli_info.get_total_size = 0; cli_info.get_total_time_ms = 0; cli_info.dir_total = 0; cli_info.newer_than = 0; cli_info.archive_level = 0; cli_info.print_mode = 1; cli_info.translation = False; cli_info.recurse_dir = False; cli_info.lowercase = False; cli_info.prompt = True; cli_info.abort_mget = True; cli_info.dest_ip.s_addr = 0; cli_info.name_type = 0x20; pstrcpy(cli_info.cur_dir , "\\"); pstrcpy(cli_info.file_sel, ""); pstrcpy(cli_info.base_dir, ""); pstrcpy(smb_cli->domain, ""); pstrcpy(smb_cli->user_name, ""); pstrcpy(cli_info.myhostname, ""); pstrcpy(cli_info.dest_host, ""); pstrcpy(cli_info.svc_type, "A:"); pstrcpy(cli_info.share, ""); pstrcpy(cli_info.service, ""); ZERO_STRUCT(cli_info.dom.level3_sid); ZERO_STRUCT(cli_info.dom.level5_sid); fstrcpy(cli_info.dom.level3_dom, ""); fstrcpy(cli_info.dom.level5_dom, ""); smb_cli->nt_pipe_fnum = 0xffff; TimeInit(); charset_initialise(); myumask = umask(0); umask(myumask); if (!get_myname(global_myname)) { fprintf(stderr, "Failed to get my hostname.\n"); } if (getenv("USER")) { pstrcpy(smb_cli->user_name,getenv("USER")); /* modification to support userid%passwd syntax in the USER var 25.Aug.97, [email protected] */ if ((p=strchr(smb_cli->user_name,'%'))) { *p = 0; pstrcpy(password,p+1); got_pass = True; memset(strchr(getenv("USER"),'%')+1,'X',strlen(password)); } strupper(smb_cli->user_name); } password[0] = 0; /* modification to support PASSWD environmental var 25.Aug.97, [email protected] */ if (getenv("PASSWD")) { pstrcpy(password,getenv("PASSWD")); } if (*smb_cli->user_name == 0 && getenv("LOGNAME")) { pstrcpy(smb_cli->user_name,getenv("LOGNAME")); strupper(smb_cli->user_name); } if (argc < 2) { usage(argv[0]); exit(1); } if (*argv[1] != '-') { pstrcpy(cli_info.service, argv[1]); /* Convert any '/' characters in the service name to '\' characters */ string_replace( cli_info.service, '/','\\'); argc--; argv++; fprintf(out_hnd, "service: %s\n", cli_info.service); if (count_chars(cli_info.service,'\\') < 3) { usage(argv[0]); printf("\n%s: Not enough '\\' characters in service\n", cli_info.service); exit(1); } /* if (count_chars(cli_info.service,'\\') > 3) { usage(pname); printf("\n%s: Too many '\\' characters in service\n", cli_info.service); exit(1); } */ if (argc > 1 && (*argv[1] != '-')) { got_pass = True; pstrcpy(password,argv[1]); memset(argv[1],'X',strlen(argv[1])); argc--; argv++; } cli_action = CLIENT_SVC; } while ((opt = getopt(argc, argv,"s:O:M:S:i:N:n:d:l:hI:EB:U:L:t:m:W:T:D:c:")) != EOF) { switch (opt) { case 'm': { /* FIXME ... max_protocol seems to be funny here */ int max_protocol = 0; max_protocol = interpret_protocol(optarg,max_protocol); fprintf(stderr, "max protocol not currently supported\n"); break; } case 'O': { pstrcpy(user_socket_options,optarg); break; } case 'S': { pstrcpy(cli_info.dest_host,optarg); strupper(cli_info.dest_host); cli_action = CLIENT_IPC; break; } case 'i': { extern pstring global_scope; pstrcpy(global_scope, optarg); strupper(global_scope); break; } case 'U': { char *lp; pstrcpy(smb_cli->user_name,optarg); if ((lp=strchr(smb_cli->user_name,'%'))) { *lp = 0; pstrcpy(password,lp+1); got_pass = True; memset(strchr(optarg,'%')+1,'X',strlen(password)); } break; } case 'W': { pstrcpy(smb_cli->domain,optarg); break; } case 'E': { dbf = stderr; break; } case 'I': { cli_info.dest_ip = *interpret_addr2(optarg); if (zero_ip(cli_info.dest_ip)) { exit(1); } break; } case 'n': { fstrcpy(global_myname, optarg); break; } case 'N': { got_pass = True; break; } case 'd': { if (*optarg == 'A') DEBUGLEVEL = 10000; else DEBUGLEVEL = atoi(optarg); break; } case 'l': { slprintf(debugf, sizeof(debugf)-1, "%s.client", optarg); interactive = False; break; } case 'c': { cmd_str = optarg; got_pass = True; break; } case 'h': { usage(argv[0]); exit(0); break; } case 's': { pstrcpy(servicesf, optarg); break; } case 't': { pstrcpy(term_code, optarg); break; } default: { usage(argv[0]); exit(1); break; } } } setup_logging(debugf, interactive); if (cli_action == CLIENT_NONE) { usage(argv[0]); exit(1); } strupper(global_myname); fstrcpy(cli_info.myhostname, global_myname); DEBUG(3,("%s client started (version %s)\n",timestring(False),VERSION)); if (!lp_load(servicesf,True, False, False)) { fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); } codepage_initialise(lp_client_code_page()); if (*smb_cli->domain == 0) pstrcpy(smb_cli->domain,lp_workgroup()); load_interfaces(); if (cli_action == CLIENT_IPC) { pstrcpy(cli_info.share, "IPC$"); pstrcpy(cli_info.svc_type, "IPC"); } fstrcpy(cli_info.mach_acct, cli_info.myhostname); strupper(cli_info.mach_acct); fstrcat(cli_info.mach_acct, "$"); /* set the password cache info */ if (got_pass) { if (password[0] == 0) { pwd_set_nullpwd(&(smb_cli->pwd)); } else { pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */ } } else { pwd_read(&(smb_cli->pwd), "Enter Password:"******"rpcclient_connect: smb_cli->fd:%d\n", smb_cli->fd)); if (smb_cli->fd <= 0) { fprintf(stderr, "warning: connection could not be established to %s<%02x>\n", cli_info.dest_host, cli_info.name_type); fprintf(stderr, "this version of smbclient may crash if you proceed\n"); exit(-1); } switch (cli_action) { case CLIENT_IPC: { process(&cli_info, cmd_str); break; } default: { fprintf(stderr, "unknown client action requested\n"); break; } } rpcclient_stop(); return(0); }