static bool parse_target(struct loadparm_context *lp_ctx, const char *target) { char *host = NULL, *share = NULL; struct dcerpc_binding *binding_struct; NTSTATUS status; /* see if its a RPC transport specifier */ if (!smbcli_parse_unc(target, NULL, &host, &share)) { status = dcerpc_parse_binding(talloc_autofree_context(), target, &binding_struct); if (NT_STATUS_IS_ERR(status)) { d_printf("Invalid option: %s is not a valid torture target (share or binding string)\n\n", target); return false; } lp_set_cmdline(lp_ctx, "torture:host", binding_struct->host); if (lp_parm_string(lp_ctx, NULL, "torture", "share") == NULL) lp_set_cmdline(lp_ctx, "torture:share", "IPC$"); lp_set_cmdline(lp_ctx, "torture:binding", target); } else { lp_set_cmdline(lp_ctx, "torture:host", host); lp_set_cmdline(lp_ctx, "torture:share", share); lp_set_cmdline(lp_ctx, "torture:binding", host); } return true; }
static int ejs_tree_connect(MprVarHandle eid, int argc, char **argv) { struct cli_credentials *creds; struct smb_composite_connect io; struct smbcli_tree *tree; char *hostname, *sharename; NTSTATUS result; TALLOC_CTX *mem_ctx; if (argc != 2) { ejsSetErrorMsg(eid, "tree_connect(): invalid number of args"); return -1; } /* Set up host, share destination */ mem_ctx = talloc_new(mprMemCtx()); smbcli_parse_unc(argv[0], mem_ctx, &hostname, &sharename); /* Set up credentials */ creds = cli_credentials_init(NULL); cli_credentials_set_conf(creds); cli_credentials_parse_string(creds, argv[1], CRED_SPECIFIED); /* Do connect */ io.in.dest_host = hostname; io.in.port = 0; io.in.called_name = strupper_talloc(mem_ctx, hostname); io.in.service = sharename; io.in.service_type = "?????"; io.in.credentials = creds; io.in.fallback_to_anonymous = False; io.in.workgroup = lp_workgroup(); result = smb_composite_connect(&io, mem_ctx, NULL); tree = io.out.tree; talloc_free(mem_ctx); if (!NT_STATUS_IS_OK(result)) { mpr_Return(eid, mprNTSTATUS(result)); return 0; } mpr_Return(eid, mprCreatePtrVar(tree)); return 0; }
/***************************************************** return a connection to a server *******************************************************/ static struct smbcli_state *connect_one(struct tevent_context *ev, struct loadparm_context *lp_ctx, TALLOC_CTX *mem_ctx, char *share, int snum, int conn) { struct smbcli_state *c; char *server, *myname; NTSTATUS status; int retries = 10; struct smbcli_options options; struct smbcli_session_options session_options; lp_smbcli_options(lp_ctx, &options); lp_smbcli_session_options(lp_ctx, &session_options); printf("connect_one(%s, %d, %d)\n", share, snum, conn); server = talloc_strdup(mem_ctx, share+2); share = strchr_m(server,'\\'); if (!share) return NULL; *share = 0; share++; if (snum == 0) { char **unc_list = NULL; int num_unc_names; const char *p; p = lp_parm_string(lp_ctx, NULL, "torture", "unclist"); if (p) { char *h, *s; unc_list = file_lines_load(p, &num_unc_names, 0, NULL); if (!unc_list || num_unc_names <= 0) { printf("Failed to load unc names list from '%s'\n", p); exit(1); } if (!smbcli_parse_unc(unc_list[conn % num_unc_names], NULL, &h, &s)) { printf("Failed to parse UNC name %s\n", unc_list[conn % num_unc_names]); exit(1); } server = talloc_strdup(mem_ctx, h); share = talloc_strdup(mem_ctx, s); } } myname = talloc_asprintf(mem_ctx, "lock-%u-%u", getpid(), snum); cli_credentials_set_workstation(servers[snum], myname, CRED_SPECIFIED); do { printf("\\\\%s\\%s\n", server, share); status = smbcli_full_connection(NULL, &c, server, lp_smb_ports(lp_ctx), share, NULL, lp_socket_options(lp_ctx), servers[snum], lp_resolve_context(lp_ctx), ev, &options, &session_options, lp_iconv_convenience(lp_ctx), lp_gensec_settings(mem_ctx, lp_ctx)); if (!NT_STATUS_IS_OK(status)) { sleep(2); } } while (!NT_STATUS_IS_OK(status) && retries--); if (!NT_STATUS_IS_OK(status)) { return NULL; } return c; }