return 1;
}
- status = cli_connect_nb(desthost, have_ip ? &dest_ss : NULL,
+ status = cli_connect_nb(talloc_tos(),
+ desthost, have_ip ? &dest_ss : NULL,
port ? port : NBT_SMB_PORT, name_type,
lp_netbios_name(),
SMB_SIGNING_OFF,
return NT_STATUS_OK;
}
-NTSTATUS cli_connect_nb(const char *host, const struct sockaddr_storage *dest_ss,
- uint16_t port, int name_type, const char *myname,
- enum smb_signing_setting signing_state, int flags, struct cli_state **pcli)
+NTSTATUS cli_connect_nb(TALLOC_CTX *mem_ctx,
+ const char *host,
+ const struct sockaddr_storage *dest_ss,
+ uint16_t port,
+ int name_type,
+ const char *myname,
+ enum smb_signing_setting signing_state,
+ int flags,
+ struct cli_state **pcli)
{
struct tevent_context *ev;
struct tevent_req *req;
NTSTATUS status = NT_STATUS_NO_MEMORY;
- ev = samba_tevent_context_init(talloc_tos());
+ ev = samba_tevent_context_init(mem_ctx);
if (ev == NULL) {
goto fail;
}
if (!tevent_req_poll_ntstatus(req, ev, &status)) {
goto fail;
}
- status = cli_connect_nb_recv(req, NULL, pcli);
+ status = cli_connect_nb_recv(req, mem_ctx, pcli);
fail:
TALLOC_FREE(ev);
return status;
return NT_STATUS_INVALID_PARAMETER;
}
- status = cli_connect_nb(
- server, dest_ss, port, name_type, NULL,
- signing_state,
- flags, &c);
+ /*
+ * The functions cli_resolve_path() and cli_cm_open() might not create a
+ * new cli context, but might return an already existing one. This
+ * forces us to have a long lived cli allocated on the NULL context.
+ */
+ status = cli_connect_nb(NULL,
+ server,
+ dest_ss,
+ port,
+ name_type,
+ NULL,
+ signing_state,
+ flags,
+ &c);
if (!NT_STATUS_IS_OK(status)) {
if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
/*
* Try 139 first for IPC$
*/
- status = cli_connect_nb(server_n, NULL, NBT_SMB_PORT, 0x20,
- smbc_getNetbiosName(context),
- signing_state, flags, &c);
+ status = cli_connect_nb(NULL,
+ server_n,
+ NULL,
+ NBT_SMB_PORT,
+ 0x20,
+ smbc_getNetbiosName(context),
+ signing_state,
+ flags,
+ &c);
}
}
/*
* No IPC$ or 139 did not work
*/
- status = cli_connect_nb(server_n, NULL, port, 0x20,
+ status = cli_connect_nb(NULL,
+ server_n,
+ NULL,
+ port,
+ 0x20,
smbc_getNetbiosName(context),
- signing_state, flags, &c);
+ signing_state,
+ flags,
+ &c);
}
if (!NT_STATUS_IS_OK(status)) {
*err_str = NULL;
- result = cli_connect_nb(remote_machine, NULL, 0, 0x20, NULL,
- SMB_SIGNING_IPC_DEFAULT, 0, &cli);
+ result = cli_connect_nb(talloc_tos(),
+ remote_machine,
+ NULL,
+ 0,
+ 0x20,
+ NULL,
+ SMB_SIGNING_IPC_DEFAULT,
+ 0,
+ &cli);
if (!NT_STATUS_IS_OK(result)) {
if (NT_STATUS_EQUAL(result, NT_STATUS_NOT_SUPPORTED)) {
if (asprintf(err_str, "Unable to connect to SMB server on "
NTSTATUS cli_tree_connect(struct cli_state *cli, const char *share,
const char *dev, const char *pass);
NTSTATUS cli_tdis(struct cli_state *cli);
-NTSTATUS cli_connect_nb(const char *host, const struct sockaddr_storage *dest_ss,
- uint16_t port, int name_type, const char *myname,
- enum smb_signing_setting signing_state, int flags, struct cli_state **pcli);
+NTSTATUS cli_connect_nb(TALLOC_CTX *mem_ctx,
+ const char *host,
+ const struct sockaddr_storage *dest_ss,
+ uint16_t port,
+ int name_type,
+ const char *myname,
+ enum smb_signing_setting signing_state,
+ int flags,
+ struct cli_state **pcli);
NTSTATUS cli_start_connection(struct cli_state **output_cli,
const char *my_name,
const char *dest_host,
in_addr_to_sockaddr_storage(&ss, ip);
- status = cli_connect_nb(name, &ss, NBT_SMB_PORT, nm_type,
- get_local_machine_name(), SMB_SIGNING_DEFAULT,
- 0, &cli);
+ status = cli_connect_nb(talloc_tos(),
+ name,
+ &ss,
+ NBT_SMB_PORT,
+ nm_type,
+ get_local_machine_name(),
+ SMB_SIGNING_DEFAULT,
+ 0,
+ &cli);
if (!NT_STATUS_IS_OK(status)) {
return;
}
flags |= CLI_FULL_CONNECTION_FORCE_DOS_ERRORS;
}
- status = cli_connect_nb(host, NULL, port_to_use, 0x20, myname,
- signing_state, flags, &c);
+ status = cli_connect_nb(NULL,
+ host,
+ NULL,
+ port_to_use,
+ 0x20,
+ myname,
+ signing_state,
+ flags,
+ &c);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
return NULL;
if (!net_find_server(c, NULL, flags, &server_ss, &server_name))
return false;
- status = cli_connect_nb(server_name, &server_ss, 0, 0x20,
- lp_netbios_name(), SMB_SIGNING_IPC_DEFAULT,
- 0, &cli);
+ status = cli_connect_nb(c,
+ server_name,
+ &server_ss,
+ 0,
+ 0x20,
+ lp_netbios_name(),
+ SMB_SIGNING_IPC_DEFAULT,
+ 0,
+ &cli);
if (!NT_STATUS_IS_OK(status)) {
if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
DBG_ERR("NetBIOS support disabled, unable to connect\n");
struct cli_state *cli = NULL;
NTSTATUS status;
- status = cli_connect_nb(host, dest_ss, 0, 0x20, lp_netbios_name(),
- SMB_SIGNING_DEFAULT, 0, &cli);
+ status = cli_connect_nb(talloc_tos(),
+ host,
+ dest_ss,
+ 0,
+ 0x20,
+ lp_netbios_name(),
+ SMB_SIGNING_DEFAULT,
+ 0,
+ &cli);
if (!NT_STATUS_IS_OK(status)) {
if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
fprintf(stderr, "Can't contact server %s. NetBIOS support disabled,"