&werr);
if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) {
- cli_rpc_pipe_close(pipe_hnd);
+ TALLOC_FREE(pipe_hnd);
TALLOC_FREE(frame);
return false;
}
browse_fn(info.name, info.type, info.comment, NULL);
}
- cli_rpc_pipe_close(pipe_hnd);
+ TALLOC_FREE(pipe_hnd);
TALLOC_FREE(frame);
return true;
}
}
rpccli_lsa_Close(pipe_hnd, mem_ctx, &lsa_pol);
- cli_rpc_pipe_close(pipe_hnd);
+ TALLOC_FREE(pipe_hnd);
done:
return status;
if (is_valid_policy_hnd(&user_pol)) {
rpccli_samr_Close(pipe_hnd, mem_ctx, &user_pol);
}
- cli_rpc_pipe_close(pipe_hnd);
+ TALLOC_FREE(pipe_hnd);
return status;
}
if (pipe_hnd) {
rpccli_samr_Close(pipe_hnd, mem_ctx, &domain_pol);
rpccli_samr_Close(pipe_hnd, mem_ctx, &sam_pol);
- cli_rpc_pipe_close(pipe_hnd);
+ TALLOC_FREE(pipe_hnd);
}
if (cli) {
return NULL;
}
-/****************************************************************************
- External interface.
- Close an open named pipe over SMB. Free any authentication data.
- Returns false if the cli_close call failed.
- ****************************************************************************/
-
-bool cli_rpc_pipe_close(struct rpc_pipe_client *cli)
-{
- bool ret;
-
- if (!cli) {
- return false;
- }
-
- ret = cli_close(cli->cli, cli->fnum);
-
- if (!ret) {
- DEBUG(1,("cli_rpc_pipe_close: cli_close failed on pipe %s, "
- "fnum 0x%x "
- "to machine %s. Error was %s\n",
- cli->pipe_name,
- (int) cli->fnum,
- cli->desthost,
- cli_errstr(cli->cli)));
- }
-
- if (cli->auth.cli_auth_data_free_func) {
- (*cli->auth.cli_auth_data_free_func)(&cli->auth);
- }
-
- DEBUG(10,("cli_rpc_pipe_close: closed pipe %s to machine %s\n",
- cli->pipe_name, cli->desthost ));
-
- DLIST_REMOVE(cli->cli->pipe_list, cli);
- talloc_destroy(cli);
- return ret;
-}
-
/****************************************************************************
Close all pipes open on this session.
****************************************************************************/
void cli_nt_pipes_close(struct cli_state *cli)
{
- struct rpc_pipe_client *cp, *next;
-
- for (cp = cli->pipe_list; cp; cp = next) {
- next = cp->next;
- cli_rpc_pipe_close(cp);
+ while (cli->pipe_list != NULL) {
+ /*
+ * No TALLOC_FREE here!
+ */
+ talloc_free(cli->pipe_list);
}
}
done:
/* Close the server service pipe */
- cli_rpc_pipe_close(pipe_hnd);
+ TALLOC_FREE(pipe_hnd);
/* Tell 'em if it worked */
return W_ERROR_IS_OK(result) ? 0 : -1;
}
/* OK, that failed, so try again... */
- cli_rpc_pipe_close(pipe_hnd);
+ TALLOC_FREE(pipe_hnd);
/* Try anonymous NTLMSSP... */
cli_init_creds(cli, "", "", NULL);
/* Use lp_workgroup() if domain not specified */
if (!cli->domain || !cli->domain[0]) {
- cli->domain = lp_workgroup();
+ cli->domain = talloc_strdup(cli, lp_workgroup());
+ if (cli->domain == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
}
init_rpc_auth_schannel_neg(&schannel_neg, cli->domain, global_myname());
return (cli->abstract_syntax == pipe_names[pipe_idx].abstr_syntax);
}
+static int rpc_pipe_destructor(struct rpc_pipe_client *p)
+{
+ bool ret;
+
+ ret = cli_close(p->cli, p->fnum);
+ if (!ret) {
+ DEBUG(1, ("rpc_pipe_destructor: cli_close failed on pipe %s, "
+ "fnum 0x%x to machine %s. Error was %s\n",
+ p->pipe_name, (int) p->fnum,
+ p->desthost, cli_errstr(p->cli)));
+ }
+
+ if (p->auth.cli_auth_data_free_func) {
+ (*p->auth.cli_auth_data_free_func)(&p->auth);
+ }
+
+ DEBUG(10, ("rpc_pipe_destructor: closed pipe %s to machine %s\n",
+ p->pipe_name, p->desthost ));
+
+ DLIST_REMOVE(p->cli->pipe_list, p);
+
+ return ret ? -1 : 0;
+}
+
/****************************************************************************
Open a named pipe over SMB to a remote server.
*
result->fnum = fnum;
DLIST_ADD(cli->pipe_list, result);
+ talloc_set_destructor(result, rpc_pipe_destructor);
+
*perr = NT_STATUS_OK;
return result;
}
DEBUG(lvl, ("cli_rpc_pipe_open_noauth: rpc_pipe_bind for pipe %s failed with error %s\n",
cli_get_pipe_name(pipe_idx), nt_errstr(*perr) ));
- cli_rpc_pipe_close(result);
+ TALLOC_FREE(result);
return NULL;
}
err:
- cli_rpc_pipe_close(result);
+ TALLOC_FREE(result);
return NULL;
}
if (!get_schannel_session_key_common(netlogon_pipe, cli, domain,
pneg_flags, perr))
{
- cli_rpc_pipe_close(netlogon_pipe);
+ TALLOC_FREE(netlogon_pipe);
return NULL;
}
result->auth.a_u.schannel_auth = TALLOC_ZERO_P(
result, struct schannel_auth_struct);
if (!result->auth.a_u.schannel_auth) {
- cli_rpc_pipe_close(result);
+ TALLOC_FREE(result);
*perr = NT_STATUS_NO_MEMORY;
return NULL;
}
TALLOC_FREE(result->domain);
result->domain = talloc_strdup(result, domain);
if (result->domain == NULL) {
- cli_rpc_pipe_close(result);
+ TALLOC_FREE(result);
*perr = NT_STATUS_NO_MEMORY;
return NULL;
}
if (!NT_STATUS_IS_OK(*perr)) {
DEBUG(0, ("cli_rpc_pipe_open_schannel_with_key: cli_rpc_pipe_bind failed with error %s\n",
nt_errstr(*perr) ));
- cli_rpc_pipe_close(result);
+ TALLOC_FREE(result);
return NULL;
}
if (!get_schannel_session_key_common(netlogon_pipe, cli, domain,
pneg_flags, perr))
{
- cli_rpc_pipe_close(netlogon_pipe);
+ TALLOC_FREE(netlogon_pipe);
return NULL;
}
domain, netlogon_pipe->dc, perr);
/* Now we've bound using the session key we can close the netlog pipe. */
- cli_rpc_pipe_close(netlogon_pipe);
+ TALLOC_FREE(netlogon_pipe);
return result;
}
domain, netlogon_pipe->dc, perr);
/* Now we've bound using the session key we can close the netlog pipe. */
- cli_rpc_pipe_close(netlogon_pipe);
+ TALLOC_FREE(netlogon_pipe);
return result;
}
service_princ = talloc_asprintf(result, "%s$@%s",
cli->desthost, lp_realm() );
if (!service_princ) {
- cli_rpc_pipe_close(result);
+ TALLOC_FREE(result);
return NULL;
}
}
if (username && password) {
int ret = kerberos_kinit_password(username, password, 0, NULL);
if (ret) {
- cli_rpc_pipe_close(result);
+ TALLOC_FREE(result);
return NULL;
}
}
result->auth.a_u.kerberos_auth = TALLOC_ZERO_P(
result, struct kerberos_auth_struct);
if (!result->auth.a_u.kerberos_auth) {
- cli_rpc_pipe_close(result);
+ TALLOC_FREE(result);
*perr = NT_STATUS_NO_MEMORY;
return NULL;
}
if (!NT_STATUS_IS_OK(*perr)) {
DEBUG(0, ("cli_rpc_pipe_open_krb5: cli_rpc_pipe_bind failed with error %s\n",
nt_errstr(*perr) ));
- cli_rpc_pipe_close(result);
+ TALLOC_FREE(result);
return NULL;
}
goto done;
done:
- if (lsa_pipe != NULL) cli_rpc_pipe_close(lsa_pipe);
- if (samr_pipe != NULL) cli_rpc_pipe_close(samr_pipe);
+ TALLOC_FREE(lsa_pipe);
+ TALLOC_FREE(samr_pipe);
return status;
}
sid_copy(&domain_sid, info->account_domain.sid);
rpccli_lsa_Close(lsapipe, mem_ctx, &pol);
- cli_rpc_pipe_close(lsapipe);
+ TALLOC_FREE(lsapipe);
talloc_destroy(mem_ctx);
return;
error:
if (lsapipe) {
- cli_rpc_pipe_close(lsapipe);
+ TALLOC_FREE(lsapipe);
}
fprintf(stderr, "could not obtain sid for domain %s\n", cli->domain);
if (tmp_set->rpc_pipe->auth.auth_type != pipe_default_auth_type ||
tmp_set->rpc_pipe->auth.auth_level != pipe_default_auth_level) {
- cli_rpc_pipe_close(tmp_set->rpc_pipe);
+ TALLOC_FREE(tmp_set->rpc_pipe);
tmp_set->rpc_pipe = NULL;
}
}
*domain_sid = info->account_domain.sid;
rpccli_lsa_Close(lsa_pipe, mem_ctx, &pol);
- cli_rpc_pipe_close(lsa_pipe);
+ TALLOC_FREE(lsa_pipe);
return NT_STATUS_OK;
}
if (!(conn_flags & NET_FLAGS_NO_PIPE)) {
if (pipe_hnd) {
- cli_rpc_pipe_close(pipe_hnd);
+ TALLOC_FREE(pipe_hnd);
}
}
done:
if (pipe_hnd) {
- cli_rpc_pipe_close(pipe_hnd);
+ TALLOC_FREE(pipe_hnd);
}
if (!NT_STATUS_IS_OK(result) && (StrnCaseCmp(name, "S-", 2) == 0)) {
if (!NT_STATUS_IS_OK(result)) {
d_fprintf(stderr, "Couldn't open LSA policy handle\n");
- cli_rpc_pipe_close(lsa_pipe);
+ TALLOC_FREE(lsa_pipe);
return result;
}
alias_sids = TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID, num_members);
if (!alias_sids) {
d_fprintf(stderr, "Out of memory\n");
- cli_rpc_pipe_close(lsa_pipe);
+ TALLOC_FREE(lsa_pipe);
return NT_STATUS_NO_MEMORY;
}
if (!NT_STATUS_IS_OK(result) &&
!NT_STATUS_EQUAL(result, STATUS_SOME_UNMAPPED)) {
d_fprintf(stderr, "Couldn't lookup SIDs\n");
- cli_rpc_pipe_close(lsa_pipe);
+ TALLOC_FREE(lsa_pipe);
return result;
}
}
}
- cli_rpc_pipe_close(lsa_pipe);
+ TALLOC_FREE(lsa_pipe);
return NT_STATUS_OK;
}
domain_name,
&buffer,
NULL);
- cli_rpc_pipe_close(netr);
+ TALLOC_FREE(netr);
if (NT_STATUS_IS_OK(status)) {
return status;
return -1;
};
- cli_rpc_pipe_close(pipe_hnd);
+ TALLOC_FREE(pipe_hnd);
/*
* Listing trusting domains (stored in passdb backend, if local)
domain_sid = info->account_domain.sid;
rpccli_lsa_Close(pipe_hnd, mem_ctx, &lsa_pol);
- cli_rpc_pipe_close(pipe_hnd); /* Done with this pipe */
+ TALLOC_FREE(pipe_hnd); /* Done with this pipe */
/* Bail out if domain didn't get set. */
if (!domain) {
&set_info);
rpccli_samr_Close(pipe_hnd, mem_ctx, &user_pol);
- cli_rpc_pipe_close(pipe_hnd); /* Done with this pipe */
+ TALLOC_FREE(pipe_hnd); /* Done with this pipe */
/* Now check the whole process from top-to-bottom */
goto done;
}
- cli_rpc_pipe_close(netlogon_schannel_pipe);
+ TALLOC_FREE(netlogon_schannel_pipe);
}
- cli_rpc_pipe_close(pipe_hnd);
+ TALLOC_FREE(pipe_hnd);
/* Now store the secret in the secrets database */
status = cmd->fn(mem_ctx, ctx, pipe_hnd, argc, argv);
- cli_rpc_pipe_close(pipe_hnd);
+ TALLOC_FREE(pipe_hnd);
talloc_destroy(mem_ctx);
if (is_valid_policy_hnd(&pol)) {
rpccli_lsa_Close(lsa_pipe, mem_ctx, &pol);
}
- cli_rpc_pipe_close(lsa_pipe);
+ TALLOC_FREE(lsa_pipe);
return result;
}
status = NT_STATUS_OK;
fail:
- if (p != NULL) {
- cli_rpc_pipe_close(p);
- }
+ TALLOC_FREE(p);
cli_tdis(cli);
cli->cnum = orig_cnum;
TALLOC_FREE(frame);
status = NT_STATUS_OK;
fail:
- if (p != NULL) {
- cli_rpc_pipe_close(p);
- }
+ TALLOC_FREE(p);
cli_tdis(cli);
cli->cnum = orig_cnum;
TALLOC_FREE(frame);
if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) {
TALLOC_FREE(mem_ctx);
- cli_rpc_pipe_close(pipe_hnd);
+ TALLOC_FREE(pipe_hnd);
return False;
}
}
TALLOC_FREE(mem_ctx);
- cli_rpc_pipe_close(pipe_hnd);
+ TALLOC_FREE(pipe_hnd);
return True;
}
}
if (conn->samr_pipe != NULL) {
- if (!cli_rpc_pipe_close(conn->samr_pipe)) {
- /* Ok, it must be dead. Drop timeout to 0.5 sec. */
- if (conn->cli) {
- cli_set_timeout(conn->cli, 500);
- }
+ TALLOC_FREE(conn->samr_pipe);
+ /* Ok, it must be dead. Drop timeout to 0.5 sec. */
+ if (conn->cli) {
+ cli_set_timeout(conn->cli, 500);
}
- conn->samr_pipe = NULL;
}
if (conn->lsa_pipe != NULL) {
- if (!cli_rpc_pipe_close(conn->lsa_pipe)) {
- /* Ok, it must be dead. Drop timeout to 0.5 sec. */
- if (conn->cli) {
- cli_set_timeout(conn->cli, 500);
- }
+ TALLOC_FREE(conn->lsa_pipe);
+ /* Ok, it must be dead. Drop timeout to 0.5 sec. */
+ if (conn->cli) {
+ cli_set_timeout(conn->cli, 500);
}
- conn->lsa_pipe = NULL;
}
if (conn->netlogon_pipe != NULL) {
- if (!cli_rpc_pipe_close(conn->netlogon_pipe)) {
- /* Ok, it must be dead. Drop timeout to 0.5 sec. */
- if (conn->cli) {
- cli_set_timeout(conn->cli, 500);
- }
+ TALLOC_FREE(conn->netlogon_pipe);
+ /* Ok, it must be dead. Drop timeout to 0.5 sec. */
+ if (conn->cli) {
+ cli_set_timeout(conn->cli, 500);
}
- conn->netlogon_pipe = NULL;
}
if (conn->cli) {
DS_ROLE_BASIC_INFORMATION,
&info,
&werr);
- cli_rpc_pipe_close(cli);
+ TALLOC_FREE(cli);
if (!NT_STATUS_IS_OK(result)) {
DEBUG(5, ("set_dc_type_and_flags_connect: rpccli_ds_getprimarydominfo "
DEBUG(5, ("set_dc_type_and_flags_connect: Could not bind to "
"PI_LSARPC on domain %s: (%s)\n",
domain->name, nt_errstr(result)));
- cli_rpc_pipe_close(cli);
+ TALLOC_FREE(cli);
TALLOC_FREE(mem_ctx);
return;
}
DEBUG(5,("set_dc_type_and_flags_connect: domain %s is %srunning active directory.\n",
domain->name, domain->active_directory ? "" : "NOT "));
- cli_rpc_pipe_close(cli);
+ TALLOC_FREE(cli);
TALLOC_FREE(mem_ctx);
DEBUG(10,("cm_connect_sam: ntlmssp-sealed rpccli_samr_Connect2 "
"failed for domain %s, error was %s. Trying schannel\n",
domain->name, nt_errstr(result) ));
- cli_rpc_pipe_close(conn->samr_pipe);
+ TALLOC_FREE(conn->samr_pipe);
schannel:
DEBUG(10,("cm_connect_sam: schannel-sealed rpccli_samr_Connect2 failed "
"for domain %s, error was %s. Trying anonymous\n",
domain->name, nt_errstr(result) ));
- cli_rpc_pipe_close(conn->samr_pipe);
+ TALLOC_FREE(conn->samr_pipe);
anonymous:
DEBUG(10,("cm_connect_lsa: rpccli_lsa_open_policy failed, trying "
"schannel\n"));
- cli_rpc_pipe_close(conn->lsa_pipe);
+ TALLOC_FREE(conn->lsa_pipe);
schannel:
DEBUG(10,("cm_connect_lsa: rpccli_lsa_open_policy failed, trying "
"anonymous\n"));
- cli_rpc_pipe_close(conn->lsa_pipe);
+ TALLOC_FREE(conn->lsa_pipe);
anonymous:
if (!get_trust_pw_hash(domain->name, mach_pwd, &account_name,
&sec_chan_type))
{
- cli_rpc_pipe_close(netlogon_pipe);
+ TALLOC_FREE(netlogon_pipe);
return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
}
&neg_flags);
if (!NT_STATUS_IS_OK(result)) {
- cli_rpc_pipe_close(netlogon_pipe);
+ TALLOC_FREE(netlogon_pipe);
return result;
}
if ((lp_client_schannel() == True) &&
((neg_flags & NETLOGON_NEG_SCHANNEL) == 0)) {
DEBUG(3, ("Server did not offer schannel\n"));
- cli_rpc_pipe_close(netlogon_pipe);
+ TALLOC_FREE(netlogon_pipe);
return NT_STATUS_ACCESS_DENIED;
}
&result);
/* We can now close the initial netlogon pipe. */
- cli_rpc_pipe_close(netlogon_pipe);
+ TALLOC_FREE(netlogon_pipe);
if (conn->netlogon_pipe == NULL) {
DEBUG(3, ("Could not open schannel'ed NETLOGON pipe. Error "