Replace cli_rpc_pipe_close by a talloc destructor on rpc_pipe_struct
authorVolker Lendecke <vl@samba.org>
Sun, 20 Apr 2008 11:51:46 +0000 (13:51 +0200)
committerVolker Lendecke <vl@samba.org>
Sun, 20 Apr 2008 12:08:16 +0000 (14:08 +0200)
(This used to be commit 99fc3283c4ecc791f5a242bd1983b4352ce3e6cf)

15 files changed:
source3/client/client.c
source3/libnet/libnet_join.c
source3/libsmb/clientgen.c
source3/libsmb/libsmb_dir.c
source3/libsmb/passchange.c
source3/rpc_client/cli_pipe.c
source3/rpcclient/cmd_test.c
source3/rpcclient/rpcclient.c
source3/utils/net_rpc.c
source3/utils/net_rpc_join.c
source3/utils/net_rpc_shell.c
source3/utils/net_util.c
source3/utils/smbcacls.c
source3/utils/smbtree.c
source3/winbindd/winbindd_cm.c

index 1c9c21e979f442a8b6fee829e81a42f9b670d92b..b4e1985a837b3a14eb1fed04106ff8469c4102d0 100644 (file)
@@ -3658,7 +3658,7 @@ static bool browse_host_rpc(bool sort)
                                              &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;
        }
@@ -3668,7 +3668,7 @@ static bool browse_host_rpc(bool sort)
                browse_fn(info.name, info.type, info.comment, NULL);
        }
 
-       cli_rpc_pipe_close(pipe_hnd);
+       TALLOC_FREE(pipe_hnd);
        TALLOC_FREE(frame);
        return true;
 }
index 207a3acfa85798686408c21bf9739b266e1a3a4a..d22fbc21b939cbb960389085c9e58baf26d86aaf 100644 (file)
@@ -706,7 +706,7 @@ static NTSTATUS libnet_join_lookup_dc_rpc(TALLOC_CTX *mem_ctx,
        }
 
        rpccli_lsa_Close(pipe_hnd, mem_ctx, &lsa_pol);
-       cli_rpc_pipe_close(pipe_hnd);
+       TALLOC_FREE(pipe_hnd);
 
  done:
        return status;
@@ -951,7 +951,7 @@ static NTSTATUS libnet_join_joindomain_rpc(TALLOC_CTX *mem_ctx,
        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;
 }
@@ -1217,7 +1217,7 @@ done:
        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) {
index ef2c2639cd531db778ed8e43290f424e7bbcfc00..e64b6fa278a233f08ac24102c5ff23e33e90ff9b 100644 (file)
@@ -616,55 +616,17 @@ struct cli_state *cli_initialise(void)
         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);
        }
 }
 
index 612a8772c0efdb6a93882bb4c890a1450b1cbb2d..aea4f103b6f314c2aa8375c4e8aef1de3c7f1778 100644 (file)
@@ -319,7 +319,7 @@ net_share_enum_rpc(struct cli_state *cli,
 
 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;
index 2f9a87dee4a70aa10a8c0fe19531b5bccc0cc181..8f7cbf265e96fd89578f26d5f8366a2df0c03ce3 100644 (file)
@@ -196,7 +196,7 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
        }
 
        /* OK, that failed, so try again... */
-       cli_rpc_pipe_close(pipe_hnd);
+       TALLOC_FREE(pipe_hnd);
        
        /* Try anonymous NTLMSSP... */
        cli_init_creds(cli, "", "", NULL);
index 3e03887bfdb00c842aa2f461dbab7bac2271e392..b0d6f8eafd6c5f6fe05bd9db264b29d1be440c39 100644 (file)
@@ -1066,7 +1066,10 @@ static NTSTATUS create_schannel_auth_rpc_bind_req( struct rpc_pipe_client *cli,
        /* 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());
@@ -2137,6 +2140,30 @@ bool rpccli_is_pipe_idx(struct rpc_pipe_client *cli, int pipe_idx)
        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.
  *
@@ -2220,6 +2247,8 @@ static struct rpc_pipe_client *cli_rpc_pipe_open(struct cli_state *cli, int pipe
        result->fnum = fnum;
 
        DLIST_ADD(cli->pipe_list, result);
+       talloc_set_destructor(result, rpc_pipe_destructor);
+
        *perr = NT_STATUS_OK;
 
        return result;
@@ -2248,7 +2277,7 @@ struct rpc_pipe_client *cli_rpc_pipe_open_noauth(struct cli_state *cli, int pipe
                }
                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;
        }
 
@@ -2360,7 +2389,7 @@ static struct rpc_pipe_client *cli_rpc_pipe_open_ntlmssp_internal(struct cli_sta
 
   err:
 
-       cli_rpc_pipe_close(result);
+       TALLOC_FREE(result);
        return NULL;
 }
 
@@ -2481,7 +2510,7 @@ struct rpc_pipe_client *get_schannel_session_key(struct cli_state *cli,
        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;
        }
 
@@ -2511,7 +2540,7 @@ struct rpc_pipe_client *cli_rpc_pipe_open_schannel_with_key(struct cli_state *cl
        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;
        }
@@ -2519,7 +2548,7 @@ struct rpc_pipe_client *cli_rpc_pipe_open_schannel_with_key(struct cli_state *cl
        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;
        }
@@ -2530,7 +2559,7 @@ struct rpc_pipe_client *cli_rpc_pipe_open_schannel_with_key(struct cli_state *cl
        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;
        }
 
@@ -2570,7 +2599,7 @@ static struct rpc_pipe_client *get_schannel_session_key_auth_ntlmssp(struct cli_
        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;
        }
 
@@ -2609,7 +2638,7 @@ struct rpc_pipe_client *cli_rpc_pipe_open_ntlmssp_auth_schannel(struct cli_state
                                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;
 }
@@ -2642,7 +2671,7 @@ struct rpc_pipe_client *cli_rpc_pipe_open_schannel(struct cli_state *cli,
                                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;
 }
@@ -2687,7 +2716,7 @@ struct rpc_pipe_client *cli_rpc_pipe_open_krb5(struct cli_state *cli,
                service_princ = talloc_asprintf(result, "%s$@%s",
                                                cli->desthost, lp_realm() );
                if (!service_princ) {
-                       cli_rpc_pipe_close(result);
+                       TALLOC_FREE(result);
                        return NULL;
                }
        }
@@ -2696,7 +2725,7 @@ struct rpc_pipe_client *cli_rpc_pipe_open_krb5(struct cli_state *cli,
        if (username && password) {
                int ret = kerberos_kinit_password(username, password, 0, NULL);
                if (ret) {
-                       cli_rpc_pipe_close(result);
+                       TALLOC_FREE(result);
                        return NULL;
                }
        }
@@ -2704,7 +2733,7 @@ struct rpc_pipe_client *cli_rpc_pipe_open_krb5(struct cli_state *cli,
        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;
        }
@@ -2716,7 +2745,7 @@ struct rpc_pipe_client *cli_rpc_pipe_open_krb5(struct cli_state *cli,
        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;
        }
 
index 089d7bcaa3f8a2fc511b64eb4218b4e550c7d692..f9ea5c0fc2d6167947f3cdb84ad4ebe123a709a8 100644 (file)
@@ -48,8 +48,8 @@ static NTSTATUS cmd_testme(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
                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;
 }
index 8592e0a3b60ce6479db8a44df9c0d21badbfe79d..ebd38044b84636e2c2b20118ce01c33138f810f0 100644 (file)
@@ -169,7 +169,7 @@ static void fetch_machine_sid(struct cli_state *cli)
        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;
@@ -177,7 +177,7 @@ static void fetch_machine_sid(struct cli_state *cli)
  error:
 
        if (lsapipe) {
-               cli_rpc_pipe_close(lsapipe);
+               TALLOC_FREE(lsapipe);
        }
 
        fprintf(stderr, "could not obtain sid for domain %s\n", cli->domain);
@@ -336,7 +336,7 @@ static NTSTATUS cmd_set_ss_level(void)
 
                        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;
                        }
                }
index 330317b0fd5e4f9236b34f3bb7dc934aa9f1a505..f6f0c4054caf63a32732802a03dbde923339e97d 100644 (file)
@@ -88,7 +88,7 @@ NTSTATUS net_get_remote_domain_sid(struct cli_state *cli, TALLOC_CTX *mem_ctx,
        *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;
 }
@@ -185,7 +185,7 @@ int run_rpc_command(struct cli_state *cli_arg,
                
        if (!(conn_flags & NET_FLAGS_NO_PIPE)) {
                if (pipe_hnd) {
-                       cli_rpc_pipe_close(pipe_hnd);
+                       TALLOC_FREE(pipe_hnd);
                }
        }
 
@@ -1973,7 +1973,7 @@ static NTSTATUS get_sid_from_name(struct cli_state *cli,
 
  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)) {
@@ -2748,14 +2748,14 @@ static NTSTATUS rpc_list_alias_members(struct rpc_pipe_client *pipe_hnd,
 
        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;
        }
 
@@ -2770,7 +2770,7 @@ static NTSTATUS rpc_list_alias_members(struct rpc_pipe_client *pipe_hnd,
        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;
        }
 
@@ -2790,7 +2790,7 @@ static NTSTATUS rpc_list_alias_members(struct rpc_pipe_client *pipe_hnd,
                }
        }
 
-       cli_rpc_pipe_close(lsa_pipe);
+       TALLOC_FREE(lsa_pipe);
        return NT_STATUS_OK;
 }
  
@@ -5652,7 +5652,7 @@ static NTSTATUS rpc_trustdom_get_pdc(struct cli_state *cli,
                                       domain_name,
                                       &buffer,
                                       NULL);
-       cli_rpc_pipe_close(netr);
+       TALLOC_FREE(netr);
 
        if (NT_STATUS_IS_OK(status)) {
                return status;
@@ -6248,7 +6248,7 @@ static int rpc_trustdom_list(int argc, const char **argv)
                return -1;
        };
        
-       cli_rpc_pipe_close(pipe_hnd);
+       TALLOC_FREE(pipe_hnd);
 
        /*
         * Listing trusting domains (stored in passdb backend, if local)
index b868ea824fb6745167b679238fcf3332f53ccd59..c94e9d1a4089c2f0755bc988fc65f44bc9cddb4f 100644 (file)
@@ -221,7 +221,7 @@ int net_rpc_join_newstyle(int argc, const char **argv)
        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) {
@@ -368,7 +368,7 @@ int net_rpc_join_newstyle(int argc, const char **argv)
                                         &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 */
 
@@ -429,10 +429,10 @@ int net_rpc_join_newstyle(int argc, const char **argv)
 
                        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 */
 
index e6302b652edaccead48d98be41962533f336d061..7bd726e614f6fbc9e0097970dae26d7b1a73e189 100644 (file)
@@ -85,7 +85,7 @@ static NTSTATUS net_sh_run(struct rpc_sh_ctx *ctx, struct rpc_sh_cmd *cmd,
 
        status = cmd->fn(mem_ctx, ctx, pipe_hnd, argc, argv);
 
-       cli_rpc_pipe_close(pipe_hnd);
+       TALLOC_FREE(pipe_hnd);
 
        talloc_destroy(mem_ctx);
 
index f844992d5622071a1723c7cd54a3e39318850227..576c2191b31763f16972b83599f7bde68103dfde 100644 (file)
@@ -75,7 +75,7 @@ NTSTATUS net_rpc_lookup_name(TALLOC_CTX *mem_ctx, struct cli_state *cli,
        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;
 }
index 134f5617603ffc44f35ac81af6c24ad08e9c69d7..af14c622dc9616e685945eded431f88b97c84a58 100644 (file)
@@ -103,9 +103,7 @@ static NTSTATUS cli_lsa_lookup_sid(struct cli_state *cli,
 
        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);
@@ -151,9 +149,7 @@ static NTSTATUS cli_lsa_lookup_name(struct cli_state *cli,
 
        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);
index d2dd1b49d32ac6d192d4a043c8c31bb4e85479ee..c2b364d1e9ac80250dbb3d60ab97bbf36f361933 100644 (file)
@@ -188,7 +188,7 @@ static bool get_rpc_shares(struct cli_state *cli,
 
        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;
        }
 
@@ -198,7 +198,7 @@ static bool get_rpc_shares(struct cli_state *cli,
        }
 
        TALLOC_FREE(mem_ctx);
-       cli_rpc_pipe_close(pipe_hnd);
+       TALLOC_FREE(pipe_hnd);
        return True;
 }
 
index 8fcbae77ff75ca2c75be33b5cd2049d9cbf0a0f9..73f74ca8ec04b0864c4014d75d3bf53670ff7f0e 100644 (file)
@@ -1432,33 +1432,27 @@ void invalidate_cm_connection(struct winbindd_cm_conn *conn)
        }
 
        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) {
@@ -1711,7 +1705,7 @@ static void set_dc_type_and_flags_connect( struct winbindd_domain *domain )
                                                                  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 "
@@ -1745,7 +1739,7 @@ no_dssetup:
                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;
        }
@@ -1825,7 +1819,7 @@ done:
        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);
 
@@ -1971,7 +1965,7 @@ NTSTATUS cm_connect_sam(struct winbindd_domain *domain, TALLOC_CTX *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:
 
@@ -2006,7 +2000,7 @@ NTSTATUS cm_connect_sam(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx,
        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:
 
@@ -2108,7 +2102,7 @@ NTSTATUS cm_connect_lsa(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx,
        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:
 
@@ -2143,7 +2137,7 @@ NTSTATUS cm_connect_lsa(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx,
        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:
 
@@ -2218,7 +2212,7 @@ NTSTATUS cm_connect_netlogon(struct winbindd_domain *domain,
        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;
        }
 
@@ -2233,14 +2227,14 @@ NTSTATUS cm_connect_netlogon(struct winbindd_domain *domain,
                 &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;
        }
 
@@ -2273,7 +2267,7 @@ NTSTATUS cm_connect_netlogon(struct winbindd_domain *domain,
                                                    &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 "