r5941: Commit this patch much earlier than I would normally prefer, but metze needs...
authorAndrew Bartlett <abartlet@samba.org>
Tue, 22 Mar 2005 08:00:45 +0000 (08:00 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:11:11 +0000 (13:11 -0500)
The main volume of this patch was what I started working on today:
 - Cleans up memory handling around DCE/RPC pipes, to have a parent talloc context.
 - Uses sepereate inner loops for some of the DCE/RPC tests

The other and more important part of this patch fixes issues
surrounding the new credentials framwork:

This makes the struct cli_credentials always a talloc() structure,
rather than on the stack.  Parts of the cli_credentials code already
assumed this.

There were other issues, particularly in the DCERPC over SMB handling,
as well as little things that had to be tidied up before test_w2k3.sh
would start to pass.

Andrew Bartlett
(This used to be commit 0453f9d05d2e336fba1f85dbf2718d01fa2bf778)

53 files changed:
source4/client/client.c
source4/gtk/common/gtk-smb.c
source4/gtk/tools/gepdump.c
source4/gtk/tools/gwcrontab.c
source4/gtk/tools/gwsam.c
source4/lib/cmdline/popt_common.c
source4/lib/com/dcom/main.c
source4/lib/credentials.c
source4/lib/registry/reg_backend_rpc.c
source4/libcli/cliconnect.c
source4/libcli/raw/clitree.c
source4/libnet/libnet_join.c
source4/libnet/libnet_passwd.c
source4/libnet/libnet_rpc.c
source4/libnet/libnet_time.c
source4/librpc/rpc/dcerpc.c
source4/librpc/rpc/dcerpc_schannel.c
source4/librpc/rpc/dcerpc_util.c
source4/rpc_server/remote/dcesrv_remote.c
source4/torture/com/simple.c
source4/torture/libnet/userinfo.c
source4/torture/masktest.c
source4/torture/rpc/alter_context.c
source4/torture/rpc/atsvc.c
source4/torture/rpc/autoidl.c
source4/torture/rpc/bind.c
source4/torture/rpc/countcalls.c
source4/torture/rpc/dcom.c
source4/torture/rpc/dfs.c
source4/torture/rpc/drsuapi.c
source4/torture/rpc/dssetup.c
source4/torture/rpc/echo.c
source4/torture/rpc/epmapper.c
source4/torture/rpc/eventlog.c
source4/torture/rpc/initshutdown.c
source4/torture/rpc/lsa.c
source4/torture/rpc/mgmt.c
source4/torture/rpc/netlogon.c
source4/torture/rpc/oxidresolve.c
source4/torture/rpc/remact.c
source4/torture/rpc/rot.c
source4/torture/rpc/samlogon.c
source4/torture/rpc/samr.c
source4/torture/rpc/samsync.c
source4/torture/rpc/scanner.c
source4/torture/rpc/schannel.c
source4/torture/rpc/spoolss.c
source4/torture/rpc/srvsvc.c
source4/torture/rpc/svcctl.c
source4/torture/rpc/testjoin.c
source4/torture/rpc/winreg.c
source4/torture/rpc/wkssvc.c
source4/torture/torture.c

index a1a055c9beca981ec1fe54b252336533c2af3e7e..4ce686cdcfd6586c0976d6386837e8dfaa55bdbd 100644 (file)
@@ -2552,7 +2552,7 @@ static BOOL browse_host(const char *query_host)
 
        binding = talloc_asprintf(mem_ctx, "ncacn_np:%s", query_host);
 
-       status = dcerpc_pipe_connect(&p, binding, 
+       status = dcerpc_pipe_connect(mem_ctx, &p, binding, 
                                     DCERPC_SRVSVC_UUID, 
                                     DCERPC_SRVSVC_VERSION,
                                     cmdline_credentials);
@@ -2562,7 +2562,6 @@ static BOOL browse_host(const char *query_host)
                talloc_free(mem_ctx);
                return False;
        }
-       talloc_steal(mem_ctx, p);
 
        r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
        r.in.level = 1;
index e03c4096f002fb7027f7eb5e3a4fa8a03cf196c7..a84f9f639d3803de825340a446f61852cc948c0e 100644 (file)
@@ -95,7 +95,7 @@ static void gtk_rpc_binding_dialog_init (GtkRpcBindingDialog *gtk_rpc_binding_di
 
        gtk_rpc_binding_dialog->mem_ctx = talloc_init("gtk_rcp_binding_dialog");
 
-       gtk_rpc_binding_dialog->credentials = talloc(gtk_rpc_binding_dialog->mem_ctx, struct cli_credentials);
+       gtk_rpc_binding_dialog->credentials = cli_credentials_init(gtk_rpc_binding_dialog->mem_ctx);
 
        cli_credentials_guess(gtk_rpc_binding_dialog->credentials);
        
index 28234c006e0e9baf4dc88c16adfbc78812905654..1bf938feb2fc08fd422bf8cf2b0e8b61989331e2 100644 (file)
@@ -188,7 +188,7 @@ static void on_connect_clicked(GtkButton *btn, gpointer         user_data)
        mem_ctx = talloc_init("connect");
        bs = gtk_rpc_binding_dialog_get_binding_string (d, mem_ctx);
 
-       status = dcerpc_pipe_connect(&epmapper_pipe, bs, 
+       status = dcerpc_pipe_connect(talloc_autofree_context(), &epmapper_pipe, bs, 
                                     DCERPC_EPMAPPER_UUID, DCERPC_EPMAPPER_VERSION, 
                                     cmdline_credentials);
 
index 47a7d68dc96977cc20849bb8750d71fcec9fe249..a1b57225db05810c3e9a8959ac689fd0cf2af81b 100644 (file)
@@ -103,7 +103,7 @@ on_connect_activate                    (GtkMenuItem     *menuitem,
        mem_ctx = talloc_init("gwcrontab_connect");
        /* If connected, get list of jobs */
        
-       status = dcerpc_pipe_connect_b(&at_pipe,
+       status = dcerpc_pipe_connect_b(mem_ctx, &at_pipe,
                                       gtk_rpc_binding_dialog_get_binding(d, mem_ctx),
                                       DCERPC_ATSVC_UUID,
                                       DCERPC_ATSVC_VERSION,
@@ -118,6 +118,7 @@ on_connect_activate                    (GtkMenuItem     *menuitem,
        }
        gtk_widget_destroy(GTK_WIDGET(d));
 
+       at_pipe = talloc_reference(talloc_autofree_context(), at_pipe);
        talloc_free(mem_ctx);
        update_joblist();
 }
@@ -126,7 +127,7 @@ void
 on_quit_activate                      (GtkMenuItem     *menuitem,
                                                                           gpointer         user_data)
 {
-       if(at_pipe)dcerpc_pipe_close(at_pipe);
+       talloc_free(at_pipe);
        gtk_main_quit();
 }
 
index 75a4b532f2b2c9084eda865dbb276c05af36b9c0..71765424d7934482d9d8df351ce2c6af9f9d197f 100644 (file)
@@ -128,7 +128,7 @@ static void connect_sam(void)
 
        mem_ctx = talloc_init("gwsam_connect");
        /* If connected, get list of jobs */
-       status = dcerpc_pipe_connect_b(&sam_pipe,
+       status = dcerpc_pipe_connect_b(mem_ctx, &sam_pipe,
                                       gtk_rpc_binding_dialog_get_binding(d, mem_ctx),
                                       DCERPC_SAMR_UUID, DCERPC_SAMR_VERSION,
                                       gtk_rpc_binding_dialog_get_credentials(d)
@@ -159,6 +159,8 @@ static void connect_sam(void)
        gtk_widget_set_sensitive (mnu_disconnect, TRUE);
        gtk_window_set_title (GTK_WINDOW (mainwin), talloc_asprintf(mem_ctx, "User Manager - Connected to %s", gtk_rpc_binding_dialog_get_host(d)));
        gtk_widget_destroy(GTK_WIDGET(d));
+
+       sam_pipe = talloc_reference(talloc_autofree_context(), sam_pipe);
        talloc_free(mem_ctx);
 
 }
@@ -176,7 +178,8 @@ static void on_disconnect_activate (GtkMenuItem *menuitem, gpointer user_data)
 
 static void on_quit_activate (GtkMenuItem *menuitem, gpointer user_data)
 {
-       if(sam_pipe)dcerpc_pipe_close(sam_pipe);
+       talloc_free(sam_pipe);
+
        gtk_main_quit();
 }
 
index c65c311af15af172026fe5190110dd236341e7b6..d364f4d3bf6c5a438f254b5792d754c4bef19424 100644 (file)
@@ -177,13 +177,13 @@ static void popt_common_credentials_callback(poptContext con,
                                                const char *arg, const void *data)
 {
        if (reason == POPT_CALLBACK_REASON_PRE) {
-               cmdline_credentials = talloc_zero(talloc_autofree_context(), struct cli_credentials);
-               cli_credentials_guess(cmdline_credentials);
-
+               cmdline_credentials = cli_credentials_init(talloc_autofree_context());
                return;
        }
        
        if (reason == POPT_CALLBACK_REASON_POST) {
+               cli_credentials_guess(cmdline_credentials);
+
                if (!dont_ask) {
                        cli_credentials_set_cmdline_callbacks(cmdline_credentials);
                }
@@ -232,8 +232,7 @@ static void popt_common_credentials_callback(poptContext con,
                        cmdline_credentials->username_obtained = CRED_SPECIFIED;
                        cli_credentials_set_password(cmdline_credentials, opt_password, CRED_SPECIFIED);
                        free(opt_password);
-
-                       cli_credentials_set_domain(cmdline_credentials, lp_workgroup(), CRED_SPECIFIED);
+                       
                }
                /* machine accounts only work with kerberos */
 
index be350c32f56707169e33a4a07274be534f93db98..08a928cda6b83da67b45194aee144c071a07db12 100644 (file)
@@ -81,7 +81,7 @@ static NTSTATUS dcom_connect_host(struct com_context *ctx, struct dcerpc_pipe **
        TALLOC_CTX *mem_ctx = talloc_init("dcom_connect");
 
        if (server == NULL) { 
-               return dcerpc_pipe_connect(p, "ncalrpc", 
+               return dcerpc_pipe_connect(ctx, p, "ncalrpc", 
                                           DCERPC_IREMOTEACTIVATION_UUID, 
                                           DCERPC_IREMOTEACTIVATION_VERSION,
                                           ctx->dcom->credentials);
@@ -89,7 +89,7 @@ static NTSTATUS dcom_connect_host(struct com_context *ctx, struct dcerpc_pipe **
 
        /* Allow server name to contain a binding string */
        if (NT_STATUS_IS_OK(dcerpc_parse_binding(mem_ctx, server, &bd))) {
-               status = dcerpc_pipe_connect_b(p, bd, 
+               status = dcerpc_pipe_connect_b(ctx, p, bd, 
                                               DCERPC_IREMOTEACTIVATION_UUID, 
                                               DCERPC_IREMOTEACTIVATION_VERSION, 
                                                   ctx->dcom->credentials);
@@ -106,7 +106,7 @@ static NTSTATUS dcom_connect_host(struct com_context *ctx, struct dcerpc_pipe **
                        return NT_STATUS_NO_MEMORY;
                }
                
-               status = dcerpc_pipe_connect(p, binding, 
+               status = dcerpc_pipe_connect(ctx, p, binding, 
                                             DCERPC_IREMOTEACTIVATION_UUID, 
                                             DCERPC_IREMOTEACTIVATION_VERSION, 
                                                 ctx->dcom->credentials);
@@ -301,9 +301,9 @@ NTSTATUS dcom_get_pipe (struct IUnknown *iface, struct dcerpc_pipe **pp)
                if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(1, ("Error parsing string binding"));
                } else {
-                       status = dcerpc_pipe_connect_b(&p, binding, 
+                       status = dcerpc_pipe_connect_b(NULL, &p, binding, 
                                                       uuid, 0.0, 
-                                                          iface->ctx->dcom->credentials);
+                                                      iface->ctx->dcom->credentials);
                }
                talloc_free(binding);
                i++;
index 2601028e7ec0eb1c02b8305c8ea4b922e0d90872..92f389e228ddfbe8e2dbb685dd146a6091cfdd1d 100644 (file)
@@ -3,6 +3,7 @@
 
    Copyright (C) Jelmer Vernooij 2005
    Copyright (C) Tim Potter 2001
+   Copyright (C) Andrew Bartlett <abartlet@samba.org> 2005
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 #include "includes.h"
 #include "system/filesys.h"
 
-const char *cli_credentials_get_username(struct cli_credentials *cred)
+/* Create a new credentials structure, on the specified TALLOC_CTX */
+struct cli_credentials *cli_credentials_init(TALLOC_CTX *mem_ctx) 
 {
-       if (cred == NULL) {
-               return NULL;
-       }
+       return talloc_zero(mem_ctx, struct cli_credentials);
+}
 
+const char *cli_credentials_get_username(struct cli_credentials *cred)
+{
        if (cred->username_obtained == CRED_CALLBACK) {
                cred->username = cred->username_cb(cred);
                cred->username_obtained = CRED_SPECIFIED;
@@ -49,10 +52,6 @@ BOOL cli_credentials_set_username(struct cli_credentials *cred, const char *val,
 
 const char *cli_credentials_get_password(struct cli_credentials *cred)
 {
-       if (cred == NULL) {
-               return NULL;
-       }
-       
        if (cred->password_obtained == CRED_CALLBACK) {
                cred->password = cred->password_cb(cred);
                cred->password_obtained = CRED_SPECIFIED;
@@ -74,10 +73,6 @@ BOOL cli_credentials_set_password(struct cli_credentials *cred, const char *val,
 
 const char *cli_credentials_get_domain(struct cli_credentials *cred)
 {
-       if (cred == NULL) {
-               return NULL;
-       }
-
        if (cred->domain_obtained == CRED_CALLBACK) {
                cred->domain = cred->domain_cb(cred);
                cred->domain_obtained = CRED_SPECIFIED;
@@ -264,23 +259,20 @@ void cli_credentials_parse_string(struct cli_credentials *credentials, const cha
        char *uname, *p;
 
        uname = talloc_strdup(credentials, data); 
-       cli_credentials_set_username(credentials, uname, obtained);
-
-       if ((p = strchr_m(uname,'\\')) || (p = strchr_m(uname, '/'))) {
+       if ((p = strchr_m(uname,'%'))) {
                *p = 0;
-               cli_credentials_set_domain(credentials, uname, obtained);
-               credentials->username = uname = p+1;
+               cli_credentials_set_password(credentials, p+1, obtained);
        }
 
        if ((p = strchr_m(uname,'@'))) {
                *p = 0;
                cli_credentials_set_realm(credentials, p+1, obtained);
-       }
-
-       if ((p = strchr_m(uname,'%'))) {
+       } else if ((p = strchr_m(uname,'\\')) || (p = strchr_m(uname, '/'))) {
                *p = 0;
-               cli_credentials_set_password(credentials, p+1, obtained);
+               cli_credentials_set_domain(credentials, uname, obtained);
+               uname = p+1;
        }
+       cli_credentials_set_username(credentials, uname, obtained);
 }
 
 void cli_credentials_guess(struct cli_credentials *cred)
@@ -319,11 +311,18 @@ void cli_credentials_guess(struct cli_credentials *cred)
        }
 }
 
+/* Fill in a credentails structure as anonymous */
+void cli_credentials_set_anonymous(struct cli_credentials *cred) 
+{
+       cli_credentials_set_username(cred, "", CRED_SPECIFIED);
+       cli_credentials_set_domain(cred, "", CRED_SPECIFIED);
+}
+
 BOOL cli_credentials_is_anonymous(struct cli_credentials *credentials)
 {
        const char *username = cli_credentials_get_username(credentials);
 
-       if (!username || !username[0]) 
+       if (!username[0]) 
                return True;
 
        return False;
index a72d104521086a08dbeaa549dd20eb175fd59f8f..5240cf5696364721ff8b955d873eace089c45ffa 100644 (file)
@@ -122,13 +122,6 @@ static WERROR rpc_get_predefined_key (struct registry_context *ctx, uint32_t hke
        return known_hives[n].open((struct dcerpc_pipe *)ctx->backend_data, *k, &(mykeydata->pol));
 }
 
-static int rpc_close (void *_h)
-{
-       struct registry_context *h = _h;
-       dcerpc_pipe_close(h->backend_data);
-       return 0;
-}
-
 #if 0
 static WERROR rpc_key_put_rpc_data(TALLOC_CTX *mem_ctx, struct registry_key *k)
 {
@@ -381,7 +374,8 @@ WERROR reg_open_remote (struct registry_context **ctx, struct cli_credentials *c
                location = talloc_strdup(ctx, "ncalrpc:");
        }
 
-       status = dcerpc_pipe_connect(&p, location, 
+       status = dcerpc_pipe_connect(*ctx /* TALLOC_CTX */, 
+                                    &p, location, 
                                     DCERPC_WINREG_UUID,
                                     DCERPC_WINREG_VERSION,
                                     credentials);
@@ -389,13 +383,13 @@ WERROR reg_open_remote (struct registry_context **ctx, struct cli_credentials *c
 
        if(NT_STATUS_IS_ERR(status)) {
                DEBUG(1, ("Unable to open '%s': %s\n", location, nt_errstr(status)));
+               talloc_free(*ctx);
+               *ctx = NULL;
                return ntstatus_to_werror(status);
        }
 
        (*ctx)->get_predefined_key = rpc_get_predefined_key;
 
-       talloc_set_destructor(*ctx, rpc_close);
-
        return WERR_OK;
 }
 
index 3834d49e49d0db10a1a08e5f2c06578f18aed89e..7459460137af8c894f2121df805114a2fa4188ea 100644 (file)
@@ -78,11 +78,6 @@ NTSTATUS smbcli_session_setup(struct smbcli_state *cli,
        setup.in.sesskey = cli->transport->negotiate.sesskey;
        setup.in.capabilities = cli->transport->negotiate.capabilities;
        if (cli_credentials_is_anonymous(credentials)) {
-               setup.in.password = NULL;
-               setup.in.user = "";
-               setup.in.domain = "";
-               setup.in.capabilities &= ~CAP_EXTENDED_SECURITY;
-       } else {
                if (cli->transport->negotiate.sec_mode & NEGOTIATE_SECURITY_USER_LEVEL) {
                        setup.in.password = cli_credentials_get_password(credentials);
                } else {
index 0559c64dc1394e2ec9dc3450efa04284cc57de2a..f333cf7a98d3a46236ed33ffef586a86d963cfb7 100644 (file)
@@ -167,7 +167,7 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx,
                                     const char *my_name, 
                                     const char *dest_host, int port,
                                     const char *service, const char *service_type,
-                                        struct cli_credentials *credentials)
+                                    struct cli_credentials *credentials)
 {
        struct smb_composite_connect io;
        NTSTATUS status;
@@ -180,11 +180,7 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx,
        io.in.service_type = service_type;
        io.in.domain = cli_credentials_get_domain(credentials);
        io.in.user = cli_credentials_get_username(credentials);
-       if (!cli_credentials_is_anonymous(credentials)) {
-               io.in.password = cli_credentials_get_password(credentials);
-       } else {
-               io.in.password = NULL;
-       }
+       io.in.password = cli_credentials_get_password(credentials);
        
        status = smb_composite_connect(&io, parent_ctx);
        if (NT_STATUS_IS_OK(status)) {
index f8acac8fb2a15a5f419c1ea1f8c4213b33aba758..2dcffd93e148d79e90f2e2f4565343be33b9ecd9 100644 (file)
@@ -287,7 +287,7 @@ static NTSTATUS libnet_JoinDomain_samr(struct libnet_context *ctx,
 
 disconnect:
        /* close connection */
-       dcerpc_pipe_close(c.pdc.out.dcerpc_pipe);
+       talloc_free(c.pdc.out.dcerpc_pipe);
 
        return status;
 }
index 41d70d8208c8c03a709c8443dc930f6a8b398f30..9613df75f39e154b6214b5220254e0dd2d0082da 100644 (file)
@@ -247,7 +247,7 @@ ChangePasswordUser:
 #endif
 disconnect:
        /* close connection */
-       dcerpc_pipe_close(c.pdc.out.dcerpc_pipe);
+       talloc_free(c.pdc.out.dcerpc_pipe);
 
        return status;
 }
@@ -631,7 +631,7 @@ static NTSTATUS libnet_SetPassword_samr(struct libnet_context *ctx, TALLOC_CTX *
 
 disconnect:
        /* close connection */
-       dcerpc_pipe_close(c.pdc.out.dcerpc_pipe);
+       talloc_free(c.pdc.out.dcerpc_pipe);
 
        return status;
 }
index 7e941aac76d6d2af357f51e1308fea1a3ec40df6..1f1812e261b67bcf7f77840abdc74a424d1d10af 100644 (file)
@@ -97,7 +97,8 @@ static NTSTATUS libnet_rpc_connect_standard(struct libnet_context *ctx, TALLOC_C
        binding = talloc_asprintf(mem_ctx, "ncacn_np:%s",
                                        r->standard.in.server_name);
 
-       status = dcerpc_pipe_connect(&r->standard.out.dcerpc_pipe,
+       status = dcerpc_pipe_connect(mem_ctx, 
+                                    &r->standard.out.dcerpc_pipe,
                                     binding,
                                     r->standard.in.dcerpc_iface_uuid,
                                     r->standard.in.dcerpc_iface_version,
index ddf26876b9ea91bd41c0e69b78156b49b2160e83..b8f4cb7a8661f4571b3a239dc65e8673106743d9 100644 (file)
@@ -88,7 +88,7 @@ static NTSTATUS libnet_RemoteTOD_srvsvc(struct libnet_context *ctx, TALLOC_CTX *
 
 disconnect:
        /* close connection */
-       dcerpc_pipe_close(c.standard.out.dcerpc_pipe);
+       talloc_free(c.standard.out.dcerpc_pipe);
 
        return status;
 }
index f2f78519f087f132d7ab0dc8ad18e0a9d759acb8..2a7ca8eb17672205e8fc95880f25dda6a589d58d 100644 (file)
@@ -130,12 +130,6 @@ static uint32_t next_call_id(struct dcerpc_connection *c)
        return c->call_id;
 }
 
-/* close down a dcerpc over SMB pipe */
-void dcerpc_pipe_close(struct dcerpc_pipe *p)
-{
-       talloc_free(p);
-}
-
 /* we need to be able to get/set the fragment length without doing a full
    decode */
 void dcerpc_set_frag_length(DATA_BLOB *blob, uint16_t v)
index bcdd1a923c7b3bfe375580058d21840f94c9ddb5..77453cf4768887041a8861d2acfe7aa55de53b1f 100644 (file)
@@ -294,8 +294,9 @@ static NTSTATUS dcerpc_schannel_client_start(struct gensec_security *gensec_secu
 /*
   get a schannel key using a netlogon challenge on a secondary pipe
 */
-static NTSTATUS dcerpc_schannel_key(struct dcerpc_pipe *p,
-                                                                       struct cli_credentials *credentials,
+static NTSTATUS dcerpc_schannel_key(TALLOC_CTX *tmp_ctx, 
+                                   struct dcerpc_pipe *p,
+                                   struct cli_credentials *credentials,
                                    int chan_type,
                                    struct creds_CredentialState *creds)
 {
@@ -308,7 +309,6 @@ static NTSTATUS dcerpc_schannel_key(struct dcerpc_pipe *p,
        struct samr_Password mach_pwd;
        const char *workgroup;
        uint32_t negotiate_flags;
-       TALLOC_CTX *tmp_ctx;
 
        if (p->conn->flags & DCERPC_SCHANNEL_128) {
                negotiate_flags = NETLOGON_NEG_AUTH2_ADS_FLAGS;
@@ -318,8 +318,6 @@ static NTSTATUS dcerpc_schannel_key(struct dcerpc_pipe *p,
 
        workgroup = cli_credentials_get_domain(credentials);
 
-       tmp_ctx = talloc_new(NULL);
-
        /*
          step 1 - establish a netlogon connection, with no authentication
        */
@@ -328,7 +326,6 @@ static NTSTATUS dcerpc_schannel_key(struct dcerpc_pipe *p,
        status = dcerpc_parse_binding(tmp_ctx, p->conn->binding_string, &b);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("Failed to parse dcerpc binding '%s'\n", p->conn->binding_string));
-               talloc_free(tmp_ctx);
                return status;
        }
 
@@ -337,18 +334,14 @@ static NTSTATUS dcerpc_schannel_key(struct dcerpc_pipe *p,
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("Failed to map DCERPC/TCP NCACN_NP pipe for '%s' - %s\n", 
                         DCERPC_NETLOGON_UUID, nt_errstr(status)));
-               talloc_free(p);
                return status;
        }
 
        status = dcerpc_secondary_connection(p, &p2, b);
        if (!NT_STATUS_IS_OK(status)) {
-               talloc_free(tmp_ctx);
                return status;
        }
 
-       talloc_free(tmp_ctx);
-
        status = dcerpc_bind_auth_none(p2, DCERPC_NETLOGON_UUID, 
                                       DCERPC_NETLOGON_VERSION);
        if (!NT_STATUS_IS_OK(status)) {
@@ -359,14 +352,14 @@ static NTSTATUS dcerpc_schannel_key(struct dcerpc_pipe *p,
        /*
          step 2 - request a netlogon challenge
        */
-       r.in.server_name = talloc_asprintf(p, "\\\\%s", dcerpc_server_name(p));
+       r.in.server_name = talloc_asprintf(tmp_ctx, "\\\\%s", dcerpc_server_name(p));
        r.in.computer_name = cli_credentials_get_workstation(credentials);
        r.in.credentials = &credentials1;
        r.out.credentials = &credentials2;
 
        generate_random_buffer(credentials1.data, sizeof(credentials1.data));
 
-       status = dcerpc_netr_ServerReqChallenge(p2, p, &r);
+       status = dcerpc_netr_ServerReqChallenge(p2, tmp_ctx, &r);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
@@ -391,7 +384,7 @@ static NTSTATUS dcerpc_schannel_key(struct dcerpc_pipe *p,
        a.in.credentials = &credentials3;
        a.out.credentials = &credentials3;
 
-       status = dcerpc_netr_ServerAuthenticate2(p2, p, &a);
+       status = dcerpc_netr_ServerAuthenticate2(p2, tmp_ctx, &a);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
@@ -405,7 +398,7 @@ static NTSTATUS dcerpc_schannel_key(struct dcerpc_pipe *p,
 
          we no longer need the netlogon pipe open
        */
-       dcerpc_pipe_close(p2);
+       talloc_free(p2);
 
        return NT_STATUS_OK;
 }
@@ -480,14 +473,15 @@ NTSTATUS dcerpc_bind_auth_schannel_withkey(struct dcerpc_pipe *p,
        return NT_STATUS_OK;
 }
 
-NTSTATUS dcerpc_bind_auth_schannel(struct dcerpc_pipe *p,
+NTSTATUS dcerpc_bind_auth_schannel(TALLOC_CTX *tmp_ctx, 
+                                  struct dcerpc_pipe *p,
                                   const char *uuid, uint_t version,
                                   struct cli_credentials *credentials)
 {
        NTSTATUS status;
        int chan_type = 0;
        struct creds_CredentialState *creds;
-       creds = talloc(p, struct creds_CredentialState);
+       creds = talloc(tmp_ctx, struct creds_CredentialState);
        if (!creds) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -500,7 +494,8 @@ NTSTATUS dcerpc_bind_auth_schannel(struct dcerpc_pipe *p,
                chan_type = SEC_CHAN_DOMAIN;
        }
 
-       status = dcerpc_schannel_key(p, credentials,
+       status = dcerpc_schannel_key(tmp_ctx, 
+                                    p, credentials,
                                     chan_type,
                                     creds);
 
@@ -514,7 +509,7 @@ NTSTATUS dcerpc_bind_auth_schannel(struct dcerpc_pipe *p,
 }
 
 static BOOL dcerpc_schannel_have_feature(struct gensec_security *gensec_security,
-                                         uint32_t feature)
+                                        uint32_t feature)
 {
        if (feature & (GENSEC_FEATURE_SESSION_KEY | 
                       GENSEC_FEATURE_SIGN | 
index d539f9f74e875a94f815ea20279f843c5d7f3b72..3ee3445ede05379d56958eccc1f66cea94c62018 100644 (file)
@@ -800,6 +800,11 @@ NTSTATUS dcerpc_epm_map_binding(TALLOC_CTX *mem_ctx, struct dcerpc_binding *bind
        const struct dcerpc_interface_table *table = idl_iface_by_uuid(uuid);
        int i;
 
+       struct cli_credentials *anon_creds
+               = cli_credentials_init(mem_ctx);
+       cli_credentials_set_anonymous(anon_creds);
+       cli_credentials_guess(anon_creds);
+
        /* First, check if there is a default endpoint specified in the IDL */
 
        if (table) {
@@ -836,11 +841,12 @@ NTSTATUS dcerpc_epm_map_binding(TALLOC_CTX *mem_ctx, struct dcerpc_binding *bind
        epmapper_binding->endpoint = NULL;
        epmapper_binding->authservice = NULL;
        
-       status = dcerpc_pipe_connect_b(&p,
+       status = dcerpc_pipe_connect_b(mem_ctx, 
+                                      &p,
                                       epmapper_binding,
                                       DCERPC_EPMAPPER_UUID,
                                       DCERPC_EPMAPPER_VERSION,
-                                      NULL);
+                                      anon_creds);
 
        if (!NT_STATUS_IS_OK(status)) {
                return status;
@@ -870,29 +876,29 @@ NTSTATUS dcerpc_epm_map_binding(TALLOC_CTX *mem_ctx, struct dcerpc_binding *bind
 
        status = dcerpc_epm_Map(p, p, &r);
        if (!NT_STATUS_IS_OK(status)) {
-               dcerpc_pipe_close(p);
+               talloc_free(p);
                return status;
        }
        if (r.out.result != 0 || r.out.num_towers != 1) {
-               dcerpc_pipe_close(p);
+               talloc_free(p);
                return NT_STATUS_PORT_UNREACHABLE;
        }
 
        twr_r = r.out.towers[0].twr;
        if (!twr_r) {
-               dcerpc_pipe_close(p);
+               talloc_free(p);
                return NT_STATUS_PORT_UNREACHABLE;
        }
 
        if (twr_r->tower.num_floors != twr.tower.num_floors ||
            twr_r->tower.floors[3].lhs.protocol != twr.tower.floors[3].lhs.protocol) {
-               dcerpc_pipe_close(p);
+               talloc_free(p);
                return NT_STATUS_PORT_UNREACHABLE;
        }
 
        binding->endpoint = talloc_reference(binding, dcerpc_floor_get_rhs_data(mem_ctx, &twr_r->tower.floors[3]));
 
-       dcerpc_pipe_close(p);
+       talloc_free(p);
 
        return NT_STATUS_OK;
 }
@@ -908,6 +914,9 @@ NTSTATUS dcerpc_pipe_auth(struct dcerpc_pipe *p,
                          struct cli_credentials *credentials)
 {
        NTSTATUS status;
+       TALLOC_CTX *tmp_ctx;
+       tmp_ctx = talloc_new(p);
+
        p->conn->flags = binding->flags;
 
        /* remember the binding string for possible secondary connections */
@@ -915,7 +924,8 @@ NTSTATUS dcerpc_pipe_auth(struct dcerpc_pipe *p,
 
        if (!cli_credentials_is_anonymous(credentials) &&
                (binding->flags & DCERPC_SCHANNEL_ANY)) {
-               status = dcerpc_bind_auth_schannel(p, pipe_uuid, pipe_version, 
+               status = dcerpc_bind_auth_schannel(tmp_ctx, 
+                                                  p, pipe_uuid, pipe_version, 
                                                   credentials);
        } else if (!cli_credentials_is_anonymous(credentials)) {
                uint8_t auth_type;
@@ -928,8 +938,8 @@ NTSTATUS dcerpc_pipe_auth(struct dcerpc_pipe *p,
                }
 
                status = dcerpc_bind_auth_password(p, pipe_uuid, pipe_version, 
-                                                                                  credentials, auth_type,
-                                                                                  binding->authservice);
+                                                  credentials, auth_type,
+                                                  binding->authservice);
        } else {
                status = dcerpc_bind_auth_none(p, pipe_uuid, pipe_version);
        }
@@ -937,97 +947,77 @@ NTSTATUS dcerpc_pipe_auth(struct dcerpc_pipe *p,
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("Failed to bind to uuid %s - %s\n", pipe_uuid, nt_errstr(status)));
        }
+       talloc_free(tmp_ctx);
        return status;
 }
 
 
 /* open a rpc connection to a rpc pipe on SMB using the binding
    structure to determine the endpoint and options */
-static NTSTATUS dcerpc_pipe_connect_ncacn_np(struct dcerpc_pipe **pp, 
+static NTSTATUS dcerpc_pipe_connect_ncacn_np(TALLOC_CTX *tmp_ctx, 
+                                            struct dcerpc_pipe *p, 
                                             struct dcerpc_binding *binding,
                                             const char *pipe_uuid, 
                                             uint32_t pipe_version,
-                                                struct cli_credentials *credentials)
+                                            struct cli_credentials *credentials)
 {
-       struct dcerpc_pipe *p;
        NTSTATUS status;
        struct smbcli_state *cli;
        const char *pipe_name = NULL;
-       TALLOC_CTX *tmp_ctx;
-
-       *pp = NULL;
 
-       p = dcerpc_pipe_init(NULL);
-       if (p == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
-       tmp_ctx = talloc_new(p);
-       
-       /* Look up identifier using the epmapper */
-       if (!binding->endpoint) {
-               status = dcerpc_epm_map_binding(tmp_ctx, binding, pipe_uuid, pipe_version);
-               if (!NT_STATUS_IS_OK(status)) {
-                       DEBUG(0,("Failed to map DCERPC/TCP NCACN_NP pipe for '%s' - %s\n", 
-                                pipe_uuid, nt_errstr(status)));
-                       talloc_free(p);
-                       return status;
-               }
-               DEBUG(1,("Mapped to DCERPC/NP pipe %s\n", binding->endpoint));
-       }
-
-       pipe_name = binding->endpoint;
-
-       if (cli_credentials_is_anonymous(credentials) || 
-           (binding->flags & DCERPC_SCHANNEL_ANY)) {
+       if (binding->flags & DCERPC_SCHANNEL_ANY) {
+               struct cli_credentials *anon_creds
+                       = cli_credentials_init(tmp_ctx);
+               cli_credentials_set_anonymous(anon_creds);
+               cli_credentials_guess(anon_creds);
                status = smbcli_full_connection(p->conn, &cli, 
                                                cli_credentials_get_workstation(credentials),
                                                binding->host, 
-                                               "ipc$", NULL, 
-                                               NULL);
+                                               "IPC$", NULL, 
+                                               anon_creds);
        } else {
                status = smbcli_full_connection(p->conn, &cli, 
                                                cli_credentials_get_workstation(credentials),
                                                binding->host, 
-                                               "ipc$", NULL,
+                                               "IPC$", NULL,
                                                credentials);
        }
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("Failed to connect to %s - %s\n", binding->host, nt_errstr(status)));
-               talloc_free(p);
                return status;
        }
 
+       /* Look up identifier using the epmapper */
+       if (!binding->endpoint) {
+               status = dcerpc_epm_map_binding(tmp_ctx, binding, pipe_uuid, pipe_version);
+               if (!NT_STATUS_IS_OK(status)) {
+                       DEBUG(0,("Failed to map DCERPC/TCP NCACN_NP pipe for '%s' - %s\n", 
+                                pipe_uuid, nt_errstr(status)));
+                       return status;
+               }
+               DEBUG(1,("Mapped to DCERPC/NP pipe %s\n", binding->endpoint));
+       }
+
+       pipe_name = binding->endpoint;
+
        status = dcerpc_pipe_open_smb(p->conn, cli->tree, pipe_name);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("Failed to open pipe %s - %s\n", pipe_name, nt_errstr(status)));
-               talloc_free(p);
                return status;
        }
 
-       (*pp) = p;
-       talloc_free(tmp_ctx);
-
        return NT_STATUS_OK;
 }
 
 /* open a rpc connection to a rpc pipe on SMP using the binding
    structure to determine the endpoint and options */
-static NTSTATUS dcerpc_pipe_connect_ncalrpc(struct dcerpc_pipe **pp, 
+static NTSTATUS dcerpc_pipe_connect_ncalrpc(TALLOC_CTX *tmp_ctx, 
+                                           struct dcerpc_pipe *p, 
                                            struct dcerpc_binding *binding,
                                            const char *pipe_uuid, 
                                            uint32_t pipe_version)
 {
        NTSTATUS status;
-       struct dcerpc_pipe *p;
-       TALLOC_CTX *tmp_ctx;
-
-       (*pp) = NULL;
-
-       p = dcerpc_pipe_init(NULL);
-       if (p == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
-       tmp_ctx = talloc_new(p);
 
        /* Look up identifier using the epmapper */
        if (!binding->endpoint) {
@@ -1035,7 +1025,6 @@ static NTSTATUS dcerpc_pipe_connect_ncalrpc(struct dcerpc_pipe **pp,
                if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(0,("Failed to map DCERPC/TCP NCALRPC identifier for '%s' - %s\n", 
                                 pipe_uuid, nt_errstr(status)));
-                       talloc_free(p);
                        return status;
                }
                DEBUG(1,("Mapped to DCERPC/LRPC identifier %s\n", binding->endpoint));
@@ -1045,13 +1034,9 @@ static NTSTATUS dcerpc_pipe_connect_ncalrpc(struct dcerpc_pipe **pp,
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("Failed to open ncalrpc pipe '%s' - %s\n", 
                         binding->endpoint, nt_errstr(status)));
-               talloc_free(p);
                return status;
        }
 
-       (*pp) = p;
-       talloc_free(tmp_ctx);
-
        return status;
 }
 
@@ -1059,26 +1044,19 @@ static NTSTATUS dcerpc_pipe_connect_ncalrpc(struct dcerpc_pipe **pp,
 
 /* open a rpc connection to a rpc pipe on SMP using the binding
    structure to determine the endpoint and options */
-static NTSTATUS dcerpc_pipe_connect_ncacn_unix_stream(struct dcerpc_pipe **pp, 
+static NTSTATUS dcerpc_pipe_connect_ncacn_unix_stream(TALLOC_CTX *tmp_ctx, 
+                                                     struct dcerpc_pipe *p, 
                                                      struct dcerpc_binding *binding,
                                                      const char *pipe_uuid, 
                                                      uint32_t pipe_version)
 {
        NTSTATUS status;
-       struct dcerpc_pipe *p;
-
-       (*pp) = NULL;
 
        if (!binding->endpoint) {
                DEBUG(0, ("Path to unix socket not specified\n"));
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       p = dcerpc_pipe_init(NULL);
-       if (p == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
-
        status = dcerpc_pipe_open_unix_stream(p->conn, binding->endpoint);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("Failed to open unix socket %s - %s\n", 
@@ -1087,30 +1065,19 @@ static NTSTATUS dcerpc_pipe_connect_ncacn_unix_stream(struct dcerpc_pipe **pp,
                 return status;
        }
 
-       (*pp) = p;
        return status;
 }
 
-/* open a rpc connection to a rpc pipe on SMP using the binding
+/* open a rpc connection to a rpc pipe on TCP/IP sockets using the binding
    structure to determine the endpoint and options */
-static NTSTATUS dcerpc_pipe_connect_ncacn_ip_tcp(struct dcerpc_pipe **pp, 
+static NTSTATUS dcerpc_pipe_connect_ncacn_ip_tcp(TALLOC_CTX *tmp_ctx, 
+                                                struct dcerpc_pipe *p, 
                                                 struct dcerpc_binding *binding,
                                                 const char *pipe_uuid, 
                                                 uint32_t pipe_version)
 {
        NTSTATUS status;
        uint32_t port = 0;
-       struct dcerpc_pipe *p;
-       TALLOC_CTX *tmp_ctx;
-
-       (*pp) = NULL;
-
-       p = dcerpc_pipe_init(NULL);
-       if (p == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
-       tmp_ctx = talloc_new(p);
 
        if (!binding->endpoint) {
                status = dcerpc_epm_map_binding(tmp_ctx, binding, 
@@ -1118,7 +1085,6 @@ static NTSTATUS dcerpc_pipe_connect_ncacn_ip_tcp(struct dcerpc_pipe **pp,
                if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(0,("Failed to map DCERPC/TCP port for '%s' - %s\n", 
                                 pipe_uuid, nt_errstr(status)));
-                       talloc_free(p);
                        return status;
                }
                DEBUG(1,("Mapped to DCERPC/TCP port %s\n", binding->endpoint));
@@ -1130,54 +1096,68 @@ static NTSTATUS dcerpc_pipe_connect_ncacn_ip_tcp(struct dcerpc_pipe **pp,
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("Failed to connect to %s:%d - %s\n", 
                         binding->host, port, nt_errstr(status)));
-               talloc_free(p);
                 return status;
         }
 
-       (*pp) = p;
-       talloc_free(tmp_ctx);
         return status;
 }
 
 
 /* open a rpc connection to a rpc pipe, using the specified 
    binding structure to determine the endpoint and options */
-NTSTATUS dcerpc_pipe_connect_b(struct dcerpc_pipe **pp, 
+NTSTATUS dcerpc_pipe_connect_b(TALLOC_CTX *parent_ctx, 
+                              struct dcerpc_pipe **pp, 
                               struct dcerpc_binding *binding,
                               const char *pipe_uuid, 
                               uint32_t pipe_version,
-                                  struct cli_credentials *credentials)
+                              struct cli_credentials *credentials)
 {
        NTSTATUS status = NT_STATUS_INVALID_PARAMETER;
+       struct dcerpc_pipe *p; 
        
+       TALLOC_CTX *tmp_ctx;
+
+       (*pp) = NULL;
+
+       p = dcerpc_pipe_init(parent_ctx);
+       if (p == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+       tmp_ctx = talloc_named(p, 0, "dcerpc_pipe_connect_b tmp_ctx");
+
        switch (binding->transport) {
        case NCACN_NP:
-               status = dcerpc_pipe_connect_ncacn_np(pp, binding, pipe_uuid, pipe_version, credentials);
+               status = dcerpc_pipe_connect_ncacn_np(tmp_ctx, 
+                                                     p, binding, pipe_uuid, pipe_version, credentials);
                break;
        case NCACN_IP_TCP:
-               status = dcerpc_pipe_connect_ncacn_ip_tcp(pp, binding, pipe_uuid, pipe_version);
+               status = dcerpc_pipe_connect_ncacn_ip_tcp(tmp_ctx, 
+                                                         p, binding, pipe_uuid, pipe_version);
                break;
        case NCACN_UNIX_STREAM:
-               status = dcerpc_pipe_connect_ncacn_unix_stream(pp, binding, pipe_uuid, pipe_version);
+               status = dcerpc_pipe_connect_ncacn_unix_stream(tmp_ctx, 
+                                                              p, binding, pipe_uuid, pipe_version);
                break;
        case NCALRPC:
-               status = dcerpc_pipe_connect_ncalrpc(pp, binding, pipe_uuid, pipe_version);
+               status = dcerpc_pipe_connect_ncalrpc(tmp_ctx, 
+                                                    p, binding, pipe_uuid, pipe_version);
                break;
        default:
                return NT_STATUS_NOT_SUPPORTED;
        }
 
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(p);
                return status;
        }
 
-       status = dcerpc_pipe_auth(*pp, binding, pipe_uuid, pipe_version, credentials);
+       status = dcerpc_pipe_auth(p, binding, pipe_uuid, pipe_version, credentials);
        if (!NT_STATUS_IS_OK(status)) {
-               talloc_free(*pp);
-               *pp = NULL;
+               talloc_free(p);
                return status;
        }
+       *pp = p;
+       talloc_free(tmp_ctx);
 
        return status;
 }
@@ -1185,17 +1165,18 @@ NTSTATUS dcerpc_pipe_connect_b(struct dcerpc_pipe **pp,
 
 /* open a rpc connection to a rpc pipe, using the specified string
    binding to determine the endpoint and options */
-NTSTATUS dcerpc_pipe_connect(struct dcerpc_pipe **pp, 
+NTSTATUS dcerpc_pipe_connect(TALLOC_CTX *parent_ctx, 
+                            struct dcerpc_pipe **pp, 
                             const char *binding,
                             const char *pipe_uuid, 
                             uint32_t pipe_version,
-                                struct cli_credentials *credentials)
+                            struct cli_credentials *credentials)
 {
        struct dcerpc_binding *b;
        NTSTATUS status;
        TALLOC_CTX *tmp_ctx;
 
-       tmp_ctx = talloc_new(NULL);
+       tmp_ctx = talloc_named(parent_ctx, 0, "dcerpc_pipe_connect tmp_ctx");
        if (!tmp_ctx) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -1209,8 +1190,12 @@ NTSTATUS dcerpc_pipe_connect(struct dcerpc_pipe **pp,
 
        DEBUG(3,("Using binding %s\n", dcerpc_binding_string(tmp_ctx, b)));
 
-       status = dcerpc_pipe_connect_b(pp, b, pipe_uuid, pipe_version, credentials);
+       status = dcerpc_pipe_connect_b(tmp_ctx,
+                                      pp, b, pipe_uuid, pipe_version, credentials);
 
+       if (NT_STATUS_IS_OK(status)) {
+               *pp = talloc_reference(parent_ctx, *pp);
+       }
        talloc_free(tmp_ctx);
 
        return status;
index 4c25ace71efe6e2df0af73cf238ee238cd84a542..825adddfee2f09f75aa3d207639dde9bc89bc5e9 100644 (file)
@@ -31,7 +31,7 @@ static NTSTATUS remote_op_bind(struct dcesrv_call_state *dce_call, const struct
         NTSTATUS status;
         struct dcesrv_remote_private *private;
        const char *binding = lp_parm_string(-1, "dcerpc_remote", "binding");
-       struct cli_credentials credentials;
+       struct cli_credentials *credentials;
 
        if (!binding) {
                DEBUG(0,("You must specify a ncacn binding string\n"));
@@ -42,13 +42,20 @@ static NTSTATUS remote_op_bind(struct dcesrv_call_state *dce_call, const struct
        if (!private) {
                return NT_STATUS_NO_MEMORY;     
        }
+       
+       credentials = cli_credentials_init(private);
+
+       cli_credentials_set_username(credentials, lp_parm_string(-1, "dcerpc_remote", "username"), CRED_SPECIFIED);
+       cli_credentials_set_workstation(credentials, lp_netbios_name(), CRED_SPECIFIED);
+       cli_credentials_set_domain(credentials, lp_workgroup(), CRED_SPECIFIED);
+       cli_credentials_set_password(credentials, lp_parm_string(-1, "dcerpc_remote", "password"), CRED_SPECIFIED);
 
-       cli_credentials_set_username(&credentials, lp_parm_string(-1, "dcerpc_remote", "username"), CRED_SPECIFIED);
-       cli_credentials_set_workstation(&credentials, lp_netbios_name(), CRED_SPECIFIED);
-       cli_credentials_set_domain(&credentials, lp_workgroup(), CRED_SPECIFIED);
-       cli_credentials_set_password(&credentials, lp_parm_string(-1, "dcerpc_remote", "password"), CRED_SPECIFIED);
+       status = dcerpc_pipe_connect(private, 
+                                    &(private->c_pipe), binding, 
+                                    iface->uuid, iface->if_version, 
+                                    credentials);
 
-       status = dcerpc_pipe_connect(&(private->c_pipe), binding, iface->uuid, iface->if_version, &credentials);
+       talloc_free(credentials);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
@@ -62,7 +69,7 @@ static void remote_op_unbind(struct dcesrv_connection_context *context, const st
 {
        struct dcesrv_remote_private *private = context->private;
 
-       dcerpc_pipe_close(private->c_pipe);
+       talloc_free(private->c_pipe);
 
        return; 
 }
index 128d84d1c7afe31e6bd7a55038ccdaed7a3b695d..25800896dbf0ecff08f6f1cd01d2c257aa73cc34 100644 (file)
@@ -28,7 +28,6 @@
 
 static BOOL test_readwrite(TALLOC_CTX *mem_ctx, const char *host)
 {
-       struct dcerpc_pipe *p = NULL;
        BOOL ret = True;
        struct GUID IID[2];
        struct GUID clsid;
@@ -48,9 +47,9 @@ static BOOL test_readwrite(TALLOC_CTX *mem_ctx, const char *host)
 
        if (host) {
                error = dcom_create_object(ctx, &clsid, 
-                                                         host, 2, IID,
-                                                         &interfaces, 
-                                                         results);
+                                          host, 2, IID,
+                                          &interfaces, 
+                                          results);
        } else {
                error = com_create_object(ctx, &clsid, 2, IID, interfaces, results);
        }
@@ -78,8 +77,6 @@ static BOOL test_readwrite(TALLOC_CTX *mem_ctx, const char *host)
 
        IUnknown_Release((struct IUnknown *)interfaces[1], mem_ctx);
 
-       torture_rpc_close(p);
-
        return True;
 }
 
index 9a775277cb8aa547a201a41ba84aaaa9765445a9..911aa086d4cd54a951db808d14c1b34da2003050 100644 (file)
@@ -220,7 +220,8 @@ BOOL torture_userinfo(void)
        mem_ctx = talloc_init("test_userinfo");
        binding = lp_parm_string(-1, "torture", "binding");
 
-       status = torture_rpc_connection(&p,
+       status = torture_rpc_connection(mem_ctx, 
+                                       &p,
                                        DCERPC_SAMR_NAME,
                                        DCERPC_SAMR_UUID,
                                        DCERPC_SAMR_VERSION);
@@ -259,7 +260,6 @@ BOOL torture_userinfo(void)
        }
 done:
        talloc_free(mem_ctx);
-       torture_rpc_close(p);
 
        return ret;
 }
index 00a0c2688d81f0888c850956540382318053d1a9..d760934334bf24f272273afd8f59ea81f3732477 100644 (file)
@@ -25,7 +25,7 @@
 #include "libcli/raw/libcliraw.h"
 #include "system/time.h"
 
-static struct cli_credentials credentials;
+static struct cli_credentials *credentials;
 static BOOL showall = False;
 static BOOL old_list = False;
 static const char *maskchars = "<>\"?*abc.";
@@ -80,7 +80,7 @@ static struct smbcli_state *connect_one(char *share)
        status = smbcli_full_connection(NULL, &c, "masktest",
                                        server, 
                                        share, NULL,
-                                       &credentials);
+                                       credentials);
 
        if (!NT_STATUS_IS_OK(status)) {
                return NULL;
@@ -297,8 +297,8 @@ static void usage(void)
        lp_load(dyn_CONFIGFILE,True,False,False);
        load_interfaces();
 
-       ZERO_STRUCT(credentials);
-       cli_credentials_guess(&credentials);
+       credentials = cli_credentials_init(talloc_autofree_context());
+       cli_credentials_guess(credentials);
 
        seed = time(NULL);
 
@@ -322,7 +322,7 @@ static void usage(void)
                        lp_set_cmdline("max protocol", optarg);
                        break;
                case 'U':
-                       cli_credentials_parse_string(&credentials, optarg, CRED_SPECIFIED);
+                       cli_credentials_parse_string(credentials, optarg, CRED_SPECIFIED);
                        break;
                case 's':
                        seed = atoi(optarg);
index 79135ba01837d021e9372af99111cae3172a7f40..ad00a349137841aed95b8c359bdab1b8860874ca 100644 (file)
@@ -38,11 +38,12 @@ BOOL torture_rpc_alter_context(void)
        mem_ctx = talloc_init("torture_rpc_alter_context");
 
        printf("opening LSA connection\n");
-       status = torture_rpc_connection(&p, 
+       status = torture_rpc_connection(mem_ctx, &p, 
                                        DCERPC_LSARPC_NAME, 
                                        DCERPC_LSARPC_UUID, 
                                        DCERPC_LSARPC_VERSION);
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
                return False;
        }
 
@@ -53,6 +54,7 @@ BOOL torture_rpc_alter_context(void)
        printf("Opening secondary DSSETUP context\n");
        status = dcerpc_secondary_context(p, &p2, DCERPC_DSSETUP_UUID, DCERPC_DSSETUP_VERSION);
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
                printf("dcerpc_alter_context failed - %s\n", nt_errstr(status));
                return False;
        }
@@ -60,6 +62,7 @@ BOOL torture_rpc_alter_context(void)
        printf("Opening bad secondary connection\n");
        status = dcerpc_secondary_context(p, &p2, DCERPC_DSSETUP_UUID, DCERPC_DSSETUP_VERSION+100);
        if (NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
                printf("dcerpc_alter_context with wrong version should fail\n");
                return False;
        }
@@ -77,6 +80,7 @@ BOOL torture_rpc_alter_context(void)
        printf("Testing change of primary context\n");
        status = dcerpc_alter_context(p, mem_ctx, &p2->syntax, &p2->transfer_syntax);
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
                printf("dcerpc_alter_context failed - %s\n", nt_errstr(status));
                return False;
        }
@@ -99,7 +103,5 @@ BOOL torture_rpc_alter_context(void)
 
        talloc_free(mem_ctx);
 
-        torture_rpc_close(p);
-
        return ret;
 }
index fd29a9228b23e89b7e460f7b891d493c23f5612a..0be4e3ca584c9de0c59d4e334c05a0840c8fa2d8 100644 (file)
@@ -142,25 +142,27 @@ BOOL torture_rpc_atsvc(void)
 
        mem_ctx = talloc_init("torture_rpc_atsvc");
 
-       status = torture_rpc_connection(&p, 
+       status = torture_rpc_connection(mem_ctx, 
+                                       &p, 
                                        DCERPC_ATSVC_NAME, 
                                        DCERPC_ATSVC_UUID, 
                                        DCERPC_ATSVC_VERSION);
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
                return False;
        }
 
        if (!test_JobEnum(p, mem_ctx)) {
+               talloc_free(mem_ctx);
                return False;
        }
 
        if (!test_JobAdd(p, mem_ctx)) {
+               talloc_free(mem_ctx);
                return False;
        }
 
        talloc_free(mem_ctx);
 
-        torture_rpc_close(p);
-
        return ret;
 }
index 0df88d2bf6a6b06cbf2163f553824b64af20f5ca..3bf8f0e2c803608f1b30bb91c4f42dea59b079df 100644 (file)
@@ -84,15 +84,17 @@ static void fill_blob_handle(DATA_BLOB *blob, TALLOC_CTX *mem_ctx,
        memcpy(blob->data, b2.data, 20);
 }
 
-static void reopen(struct dcerpc_pipe **p, const struct dcerpc_interface_table *iface)
+static void reopen(TALLOC_CTX *mem_ctx, 
+                  struct dcerpc_pipe **p, 
+                  const struct dcerpc_interface_table *iface)
 {
        NTSTATUS status;
 
-       if (*p) {
-               dcerpc_pipe_close(*p);
-       }
+       talloc_free(*p);
 
-       status = torture_rpc_connection(p, iface->endpoints->names[0], iface->uuid, iface->if_version);
+       status = torture_rpc_connection(mem_ctx, 
+                                       p, iface->endpoints->names[0], 
+                                       iface->uuid, iface->if_version);
        if (!NT_STATUS_IS_OK(status)) {
                printf("Failed to reopen '%s' - %s\n", iface->name, nt_errstr(status));
                exit(1);
@@ -118,7 +120,7 @@ static void try_expand(TALLOC_CTX *mem_ctx, const struct dcerpc_interface_table
        NTSTATUS status;
        struct dcerpc_pipe *p = NULL;
 
-       reopen(&p, iface);
+       reopen(mem_ctx, &p, iface);
 
        /* work out how much to expand to get a non fault */
        for (n=0;n<2000;n++) {
@@ -144,11 +146,11 @@ static void try_expand(TALLOC_CTX *mem_ctx, const struct dcerpc_interface_table
 #endif
                }
                if (p->last_fault_code == 5) {
-                       reopen(&p, iface);
+                       reopen(mem_ctx, &p, iface);
                }
        }
 
-       dcerpc_pipe_close(p);   
+       talloc_free(p); 
 }
 
 
@@ -160,7 +162,7 @@ static void test_ptr_scan(TALLOC_CTX *mem_ctx, const struct dcerpc_interface_tab
        NTSTATUS status;
        struct dcerpc_pipe *p = NULL;
 
-       reopen(&p, iface);
+       reopen(mem_ctx, &p, iface);
 
        stub_in = data_blob(NULL, base_in->length);
        memcpy(stub_in.data, base_in->data, base_in->length);
@@ -175,7 +177,7 @@ static void test_ptr_scan(TALLOC_CTX *mem_ctx, const struct dcerpc_interface_tab
                        printf("possible ptr at ofs %d - fault %s\n", 
                               ofs-min_ofs, dcerpc_errstr(mem_ctx, p->last_fault_code));
                        if (p->last_fault_code == 5) {
-                               reopen(&p, iface);
+                               reopen(mem_ctx, &p, iface);
                        }
                        if (depth == 0) {
                                try_expand(mem_ctx, iface, opnum, &stub_in, ofs+4, depth+1);
@@ -188,7 +190,7 @@ static void test_ptr_scan(TALLOC_CTX *mem_ctx, const struct dcerpc_interface_tab
                SIVAL(stub_in.data, ofs, 0);
        }
 
-       dcerpc_pipe_close(p);   
+       talloc_free(p); 
 }
        
 
@@ -200,7 +202,7 @@ static void test_scan_call(TALLOC_CTX *mem_ctx, const struct dcerpc_interface_ta
        struct dcerpc_pipe *p = NULL;
        struct policy_handle handle;
 
-       reopen(&p, iface);
+       reopen(mem_ctx, &p, iface);
 
        get_policy_handle(p, mem_ctx, &handle);
 
@@ -216,7 +218,7 @@ static void test_scan_call(TALLOC_CTX *mem_ctx, const struct dcerpc_interface_ta
                        printf("opnum %d   min_input %d - output %d\n", 
                               opnum, stub_in.length, stub_out.length);
                        dump_data(0, stub_out.data, stub_out.length);
-                       dcerpc_pipe_close(p);
+                       talloc_free(p);
                        test_ptr_scan(mem_ctx, iface, opnum, &stub_in, 0, stub_in.length, 0);
                        return;
                }
@@ -229,7 +231,7 @@ static void test_scan_call(TALLOC_CTX *mem_ctx, const struct dcerpc_interface_ta
                        printf("opnum %d   min_input %d - output %d (with handle)\n", 
                               opnum, stub_in.length, stub_out.length);
                        dump_data(0, stub_out.data, stub_out.length);
-                       dcerpc_pipe_close(p);
+                       talloc_free(p);
                        test_ptr_scan(mem_ctx, iface, opnum, &stub_in, 0, stub_in.length, 0);
                        return;
                }
@@ -237,7 +239,7 @@ static void test_scan_call(TALLOC_CTX *mem_ctx, const struct dcerpc_interface_ta
                if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
                        printf("opnum %d  size %d fault %s\n", opnum, i, dcerpc_errstr(mem_ctx, p->last_fault_code));
                        if (p->last_fault_code == 5) {
-                               reopen(&p, iface);
+                               reopen(mem_ctx, &p, iface);
                        }
                        continue;
                }
@@ -246,7 +248,7 @@ static void test_scan_call(TALLOC_CTX *mem_ctx, const struct dcerpc_interface_ta
        }
 
        printf("opnum %d minimum not found!?\n", opnum);
-       dcerpc_pipe_close(p);
+       talloc_free(p);
 }
 
 
@@ -272,5 +274,6 @@ BOOL torture_rpc_autoidl(void)
 
        test_auto_scan(mem_ctx, iface);
 
+       talloc_free(mem_ctx);
        return True;
 }
index 71eaec4f925faabf3ff0e370fddc2f26782f8bcc..6ab36cf510decddaa34e4f306e02c70c0266e8a1 100644 (file)
@@ -55,12 +55,14 @@ BOOL torture_multi_bind(void)
                return False;
        }
 
-       status = torture_rpc_connection(&p, 
+       status = torture_rpc_connection(mem_ctx, 
+                                       &p, 
                                        NULL,
                                        pipe_uuid,
                                        pipe_version);
        
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
                return False;
        }
 
@@ -77,7 +79,6 @@ BOOL torture_multi_bind(void)
        }
 
        talloc_free(mem_ctx);
-       torture_rpc_close(p);
 
        return ret;
 }
index d42729769aea45b42d0bde34ca51485f2f98819a..ac4788f349b657cdf042528ac4a5e89da2a81457 100644 (file)
@@ -44,7 +44,7 @@ BOOL torture_rpc_countcalls(void)
                return False;
        }
 
-       status = torture_rpc_connection(&p, iface->endpoints->names[0], 
+       status = torture_rpc_connection(NULL, &p, iface->endpoints->names[0], 
                                        iface->uuid, iface->if_version);
        if (!NT_STATUS_IS_OK(status)) {
                printf("Failed to open '%s' - %s\n", iface->name, nt_errstr(status));
@@ -65,13 +65,14 @@ BOOL torture_rpc_countcalls(void)
        }
        
        if (i==5000) {
+               talloc_free(p);
                printf("no limit on calls!?\n");
                return False;
        }
 
        printf("Found %d calls\n", i);
 
-       torture_rpc_close(p);
+       talloc_free(p);
 
        return True;
 }
index f8bcf4096575e539f458006b24507a3c7fa8ea2d..318e9c88eaaea372e9003899486c7f8be58ea7bd 100644 (file)
@@ -32,18 +32,16 @@ BOOL torture_rpc_dcom(void)
 
        mem_ctx = talloc_init("torture_rpc_dcom");
 
-       status = torture_rpc_connection(&p, 
-                                                                       DCERPC_IOXIDRESOLVER_NAME,
-                                                                       DCERPC_IOXIDRESOLVER_UUID,
-                                                                       DCERPC_IOXIDRESOLVER_VERSION);
+       status = torture_rpc_connection(mem_ctx, &p, 
+                                       DCERPC_IOXIDRESOLVER_NAME,
+                                       DCERPC_IOXIDRESOLVER_UUID,
+                                       DCERPC_IOXIDRESOLVER_VERSION);
        if (!NT_STATUS_IS_OK(status)) {
-               return False;
+               ret = False;
        }
 
        printf("\n");
 
        talloc_free(mem_ctx);
-
-       torture_rpc_close(p);
        return ret;
 }
index 358b94fa721ccd55b334553192578b9aeb1af03f..4e33f921facb80841a110e2fbe3acaf54d0b5ef7 100644 (file)
@@ -173,7 +173,8 @@ BOOL torture_rpc_dfs(void)
 
        mem_ctx = talloc_init("torture_rpc_dfs");
 
-       status = torture_rpc_connection(&p, 
+       status = torture_rpc_connection(mem_ctx, 
+                                       &p, 
                                        DCERPC_NETDFS_NAME,
                                        DCERPC_NETDFS_UUID,
                                        DCERPC_NETDFS_VERSION);
@@ -197,7 +198,5 @@ BOOL torture_rpc_dfs(void)
 
        talloc_free(mem_ctx);
 
-        torture_rpc_close(p);
-
        return ret;
 }
index c4dbe00958d7d542bc04b7f67f5a68a4fa8c4372..88ff85d8da72d9771f62bcac6f70af18395e569f 100644 (file)
@@ -1008,18 +1008,20 @@ BOOL torture_rpc_drsuapi(void)
        BOOL ret = True;
        struct DsPrivate priv;
 
-       status = torture_rpc_connection(&p, 
+       mem_ctx = talloc_init("torture_rpc_drsuapi");
+
+       status = torture_rpc_connection(mem_ctx, 
+                                       &p, 
                                        DCERPC_DRSUAPI_NAME,
                                        DCERPC_DRSUAPI_UUID,
                                        DCERPC_DRSUAPI_VERSION);
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
                return False;
        }
 
        printf("Connected to DRAUAPI pipe\n");
 
-       mem_ctx = talloc_init("torture_rpc_drsuapi");
-
        ZERO_STRUCT(priv);
 
        ret &= test_DsBind(p, mem_ctx, &priv);
@@ -1042,7 +1044,5 @@ BOOL torture_rpc_drsuapi(void)
 
        talloc_free(mem_ctx);
 
-        torture_rpc_close(p);
-
        return ret;
 }
index bd20a695e2878e6461b70a1a975b3f0118089e8e..d4f76fea90b60e2a8d6742c0b0c8c8017268aa98 100644 (file)
@@ -64,11 +64,13 @@ BOOL torture_rpc_dssetup(void)
 
        mem_ctx = talloc_init("torture_rpc_dssetup");
 
-       status = torture_rpc_connection(&p, 
+       status = torture_rpc_connection(mem_ctx, &p, 
                                        DCERPC_DSSETUP_NAME, 
                                        DCERPC_DSSETUP_UUID, 
                                        DCERPC_DSSETUP_VERSION);
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
+
                return False;
        }
 
@@ -76,7 +78,5 @@ BOOL torture_rpc_dssetup(void)
 
        talloc_free(mem_ctx);
 
-        torture_rpc_close(p);
-
        return ret;
 }
index 8ef0b00eb252ed80784aa35ec46177eac2d0e7f6..34a509a1d4d3b8a2d4791d2b4e9b1be6df28a0dd 100644 (file)
@@ -398,13 +398,14 @@ static BOOL test_doublepointer(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
 BOOL torture_rpc_echo(void)
 {
        NTSTATUS status;
-    struct dcerpc_pipe *p;
+       struct dcerpc_pipe *p;
        TALLOC_CTX *mem_ctx;
        BOOL ret = True;
 
        mem_ctx = talloc_init("torture_rpc_echo");
 
-       status = torture_rpc_connection(&p, 
+       status = torture_rpc_connection(mem_ctx, 
+                                       &p, 
                                        DCERPC_RPCECHO_NAME,
                                        DCERPC_RPCECHO_UUID,
                                        DCERPC_RPCECHO_VERSION);
@@ -427,6 +428,5 @@ BOOL torture_rpc_echo(void)
        
        talloc_free(mem_ctx);
 
-    torture_rpc_close(p);
        return ret;
 }
index debcd987566193d93a3fb4ec8bf1fdfbadbe58d6..28877fa1a45c733ecfebef1ef270c5d37984f8a2 100644 (file)
@@ -281,11 +281,13 @@ BOOL torture_rpc_epmapper(void)
 
        mem_ctx = talloc_init("torture_rpc_epmapper");
 
-       status = torture_rpc_connection(&p, 
+       status = torture_rpc_connection(mem_ctx, 
+                                       &p, 
                                        DCERPC_EPMAPPER_NAME,
                                        DCERPC_EPMAPPER_UUID,
                                        DCERPC_EPMAPPER_VERSION);
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
                return False;
        }
 
@@ -303,7 +305,5 @@ BOOL torture_rpc_epmapper(void)
 
        talloc_free(mem_ctx);
 
-       torture_rpc_close(p);
-
        return ret;
 }
index 7e320200f0619e007d68897ef09febb9756b3176..7d3a3bfea9943127f014463a2dc2230a87b9b1cf 100644 (file)
@@ -155,15 +155,18 @@ BOOL torture_rpc_eventlog(void)
 
        mem_ctx = talloc_init("torture_rpc_atsvc");
 
-       status = torture_rpc_connection(&p, 
+       status = torture_rpc_connection(mem_ctx, 
+                                       &p, 
                                        DCERPC_EVENTLOG_NAME, 
                                        DCERPC_EVENTLOG_UUID, 
                                        DCERPC_EVENTLOG_VERSION);
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
                return False;
        }
 
        if (!test_OpenEventLog(p, mem_ctx, &handle)) {
+               talloc_free(mem_ctx);
                return False;
        }
 
@@ -175,7 +178,5 @@ BOOL torture_rpc_eventlog(void)
 
        talloc_free(mem_ctx);
 
-    torture_rpc_close(p);
-
        return ret;
 }
index 0aa64e3eb274b65fa8c6238b194a95c33f74b988..ff1496aea415ec1ff6fda06de6f57f842d983fb1 100644 (file)
@@ -120,12 +120,14 @@ BOOL torture_rpc_initshutdown(void)
 
        mem_ctx = talloc_init("torture_rpc_initshutdown");
 
-       status = torture_rpc_connection(&p, 
+       status = torture_rpc_connection(mem_ctx, 
+                                       &p, 
                                        DCERPC_INITSHUTDOWN_NAME, 
                                        DCERPC_INITSHUTDOWN_UUID, 
                                        DCERPC_INITSHUTDOWN_VERSION);
 
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
                return False;
        }
 
@@ -140,7 +142,5 @@ BOOL torture_rpc_initshutdown(void)
 
        talloc_free(mem_ctx);
 
-    torture_rpc_close(p);
-
        return ret;
 }
index 277a5fc793bc19e6a07e09e02cd564d0d7c10072..f723f68a0226e087f0063aba53065863f7e9996d 100644 (file)
@@ -1612,11 +1612,13 @@ BOOL torture_rpc_lsa(void)
 
        mem_ctx = talloc_init("torture_rpc_lsa");
 
-       status = torture_rpc_connection(&p, 
+       status = torture_rpc_connection(mem_ctx, 
+                                       &p, 
                                        DCERPC_LSARPC_NAME, 
                                        DCERPC_LSARPC_UUID, 
                                        DCERPC_LSARPC_VERSION);
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
                return False;
        }
 
@@ -1676,7 +1678,5 @@ BOOL torture_rpc_lsa(void)
 
        talloc_free(mem_ctx);
 
-        torture_rpc_close(p);
-
        return ret;
 }
index cb2023b64c6c2ec0d2d49633837ddad4ecf42e05..be9cf649d3af3ef0fdb58bd112eb1e8ad00ecbea 100644 (file)
@@ -177,7 +177,7 @@ BOOL torture_rpc_mgmt(void)
 {
         NTSTATUS status;
         struct dcerpc_pipe *p;
-       TALLOC_CTX *mem_ctx;
+       TALLOC_CTX *mem_ctx, *loop_ctx;
        BOOL ret = True;
        const char *binding = lp_parm_string(-1, "torture", "binding");
        const struct dcerpc_interface_list *l;
@@ -192,24 +192,29 @@ BOOL torture_rpc_mgmt(void)
        
        status = dcerpc_parse_binding(mem_ctx, binding, &b);
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
                printf("Failed to parse binding '%s'\n", binding);
                return False;
        }
 
        for (l=librpc_dcerpc_pipes();l;l=l->next) {             
+               loop_ctx = talloc_named(mem_ctx, 0, "torture_rpc_mgmt loop context");
+               
                /* some interfaces are not mappable */
                if (l->table->num_calls == 0 ||
                    strcmp(l->table->name, "mgmt") == 0) {
+                       talloc_free(loop_ctx);
                        continue;
                }
 
                printf("\nTesting pipe '%s'\n", l->table->name);
 
                if (b->transport == NCACN_IP_TCP) {
-                       status = dcerpc_epm_map_binding(mem_ctx, b, 
-                                                        l->table->uuid,
-                                                        l->table->if_version);
+                       status = dcerpc_epm_map_binding(loop_ctx, b, 
+                                                       l->table->uuid,
+                                                       l->table->if_version);
                        if (!NT_STATUS_IS_OK(status)) {
+                               talloc_free(loop_ctx);
                                printf("Failed to map port for uuid %s\n", l->table->uuid);
                                continue;
                        }
@@ -217,38 +222,39 @@ BOOL torture_rpc_mgmt(void)
                        b->endpoint = talloc_strdup(b, l->table->name);
                }
 
-               lp_set_cmdline("torture:binding", dcerpc_binding_string(mem_ctx, b));
+               lp_set_cmdline("torture:binding", dcerpc_binding_string(loop_ctx, b));
 
-               status = torture_rpc_connection(&p, 
+               status = torture_rpc_connection(loop_ctx, 
+                                               &p, 
                                                l->table->name,
                                                DCERPC_MGMT_UUID,
                                                DCERPC_MGMT_VERSION);
                if (!NT_STATUS_IS_OK(status)) {
+                       talloc_free(loop_ctx);
                        ret = False;
                        continue;
                }
        
-               if (!test_is_server_listening(p, mem_ctx)) {
+               if (!test_is_server_listening(p, loop_ctx)) {
                        ret = False;
                }
 
-               if (!test_stop_server_listening(p, mem_ctx)) {
+               if (!test_stop_server_listening(p, loop_ctx)) {
                        ret = False;
                }
 
-               if (!test_inq_stats(p, mem_ctx)) {
+               if (!test_inq_stats(p, loop_ctx)) {
                        ret = False;
                }
 
-               if (!test_inq_princ_name(p, mem_ctx)) {
+               if (!test_inq_princ_name(p, loop_ctx)) {
                        ret = False;
                }
 
-               if (!test_inq_if_ids(p, mem_ctx)) {
+               if (!test_inq_if_ids(p, loop_ctx)) {
                        ret = False;
                }
 
-               torture_rpc_close(p);
        }
 
        return ret;
index 2266659c3795e5cc940ad66de67e3bbefab3af8e..d9ce350428ba0c5a91b26115381c1b739c69d13f 100644 (file)
@@ -26,6 +26,7 @@
 #include "lib/events/events.h"
 #include "librpc/gen_ndr/ndr_netlogon.h"
 #include "auth/auth.h"
+#include "lib/cmdline/popt_common.h"
 
 static const char *machine_password;
 
@@ -37,7 +38,7 @@ static BOOL test_LogonUasLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
        struct netr_LogonUasLogon r;
 
        r.in.server_name = NULL;
-       r.in.account_name = lp_parm_string(-1, "torture", "username");
+       r.in.account_name = cli_credentials_get_username(cmdline_credentials),
        r.in.workstation = TEST_MACHINE_NAME;
 
        printf("Testing LogonUasLogon\n");
@@ -58,7 +59,7 @@ static BOOL test_LogonUasLogoff(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
        struct netr_LogonUasLogoff r;
 
        r.in.server_name = NULL;
-       r.in.account_name = lp_parm_string(-1, "torture", "username");
+       r.in.account_name = cli_credentials_get_username(cmdline_credentials),
        r.in.workstation = TEST_MACHINE_NAME;
 
        printf("Testing LogonUasLogoff\n");
@@ -491,8 +492,8 @@ static BOOL test_SamLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
        struct netr_LogonSamLogon r;
        struct netr_Authenticator auth, auth2;
        struct netr_NetworkInfo ninfo;
-       const char *username = lp_parm_string(-1, "torture", "username");
-       const char *password = lp_parm_string(-1, "torture", "password");
+       const char *username = cli_credentials_get_username(cmdline_credentials);
+       const char *password = cli_credentials_get_password(cmdline_credentials);
        struct creds_CredentialState *creds;
 
        int i;
@@ -503,7 +504,7 @@ static BOOL test_SamLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
                return False;
        }
 
-       ninfo.identity_info.domain_name.string = lp_workgroup();
+       ninfo.identity_info.domain_name.string = cli_credentials_get_domain(cmdline_credentials);
        ninfo.identity_info.parameter_control = 0;
        ninfo.identity_info.logon_id_low = 0;
        ninfo.identity_info.logon_id_high = 0;
@@ -1330,7 +1331,7 @@ static BOOL test_ManyGetDCName(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
                return False;
        }
 
-       dcerpc_pipe_close(p2);
+       talloc_free(p2);
 
        d.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s",
                                            dcerpc_server_name(p));
@@ -1368,15 +1369,17 @@ BOOL torture_rpc_netlogon(void)
        join_ctx = torture_join_domain(TEST_MACHINE_NAME, lp_workgroup(), ACB_SVRTRUST, 
                                       &machine_password);
        if (!join_ctx) {
+               talloc_free(mem_ctx);
                printf("Failed to join as BDC\n");
                return False;
        }
 
-       status = torture_rpc_connection(&p, 
+       status = torture_rpc_connection(mem_ctx, &p, 
                                        DCERPC_NETLOGON_NAME,
                                        DCERPC_NETLOGON_UUID,
                                        DCERPC_NETLOGON_VERSION);
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
                return False;
        }
 
@@ -1403,8 +1406,6 @@ BOOL torture_rpc_netlogon(void)
 
        talloc_free(mem_ctx);
 
-       torture_rpc_close(p);
-
        torture_leave_domain(join_ctx);
 
        return ret;
index 2caf3512d5525f46f6d42f8cb9b6eb6ff5027f74..3b0269891cbf5362a3f1983e2906b49c3b9747fc 100644 (file)
@@ -223,21 +223,25 @@ BOOL torture_rpc_oxidresolve(void)
 
        mem_ctx = talloc_init("torture_rpc_oxidresolve");
 
-       status = torture_rpc_connection(&premact, 
+       status = torture_rpc_connection(mem_ctx, 
+                                       &premact, 
                                        DCERPC_IREMOTEACTIVATION_NAME, 
                                        DCERPC_IREMOTEACTIVATION_UUID, 
                                        DCERPC_IREMOTEACTIVATION_VERSION);                                                              
                        
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
                return False;
        }
 
-       status = torture_rpc_connection(&p, 
+       status = torture_rpc_connection(mem_ctx, 
+                                       &p, 
                                        DCERPC_IOXIDRESOLVER_NAME, 
                                        DCERPC_IOXIDRESOLVER_UUID, 
                                        DCERPC_IOXIDRESOLVER_VERSION);
 
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
                return False;
        }
 
@@ -264,7 +268,5 @@ BOOL torture_rpc_oxidresolve(void)
 
        talloc_free(mem_ctx);
 
-    torture_rpc_close(p);
-
        return ret;
 }
index a8dff5f50b0e2dfc7b841945390422221e4a7700..1d145dd1cb2fc2f458821bd934272c419eeaec97 100644 (file)
@@ -95,19 +95,21 @@ static int test_RemoteActivation(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
 
 BOOL torture_rpc_remact(void)
 {
-     NTSTATUS status;
-     struct dcerpc_pipe *p;
+       NTSTATUS status;
+       struct dcerpc_pipe *p;
        TALLOC_CTX *mem_ctx;
        BOOL ret = True;
 
        mem_ctx = talloc_init("torture_rpc_remact");
 
-       status = torture_rpc_connection(&p, 
+       status = torture_rpc_connection(mem_ctx,
+                                       &p, 
                                        DCERPC_IREMOTEACTIVATION_NAME,
                                        DCERPC_IREMOTEACTIVATION_UUID, 
                                        DCERPC_IREMOTEACTIVATION_VERSION);
 
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
                return False;
        }
 
@@ -116,7 +118,5 @@ BOOL torture_rpc_remact(void)
 
        talloc_free(mem_ctx);
 
-    torture_rpc_close(p);
-
        return ret;
 }
index d2e3742cf07563c051b0d4532b7f9914d2144548..ee47fe350e9fb474480348c0b9e1346ff9329e0b 100644 (file)
 
 BOOL torture_rpc_rot(void)
 {
-    NTSTATUS status;
-    struct dcerpc_pipe *p;
+       NTSTATUS status;
+       struct dcerpc_pipe *p;
        TALLOC_CTX *mem_ctx;
        BOOL ret = True;
 
        mem_ctx = talloc_init("torture_rpc_rot");
 
-       status = torture_rpc_connection(&p, 
+       status = torture_rpc_connection(mem_ctx, 
+                                       &p, 
                                        DCERPC_ROT_NAME, 
                                        DCERPC_ROT_UUID, 
                                        DCERPC_ROT_VERSION);
 
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
                return False;
        }
 
-    torture_rpc_close(p);
+       talloc_free(mem_ctx);
 
        return ret;
 }
index 1ee8f36b8ed565506713f99135cdd789538a53f7..86bfe48a7585248255fbffeb3e2251d47b9be886 100644 (file)
@@ -1072,6 +1072,7 @@ static BOOL test_SamLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                          const char *plain_pass,
                          int n_subtests)
 {
+       TALLOC_CTX *fn_ctx = talloc_named(mem_ctx, 0, "test_SamLogon function-level context");
        int i, v, l, f;
        BOOL ret = True;
        int validation_levels[] = {2,3,6};
@@ -1084,27 +1085,26 @@ static BOOL test_SamLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
        
        printf("testing netr_LogonSamLogon and netr_LogonSamLogonWithFlags\n");
        
-       samlogon_state.mem_ctx = mem_ctx;
        samlogon_state.account_name = account_name;
        samlogon_state.account_domain = account_domain;
        samlogon_state.password = plain_pass;
        samlogon_state.p = p;
        samlogon_state.creds = creds;
 
-       samlogon_state.chall = data_blob_talloc(mem_ctx, NULL, 8);
+       samlogon_state.chall = data_blob_talloc(fn_ctx, NULL, 8);
 
        generate_random_buffer(samlogon_state.chall.data, 8);
-       samlogon_state.r_flags.in.server_name = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
+       samlogon_state.r_flags.in.server_name = talloc_asprintf(fn_ctx, "\\\\%s", dcerpc_server_name(p));
        samlogon_state.r_flags.in.workstation = TEST_MACHINE_NAME;
        samlogon_state.r_flags.in.credential = &samlogon_state.auth;
        samlogon_state.r_flags.in.return_authenticator = &samlogon_state.auth2;
        samlogon_state.r_flags.in.flags = 0;
 
-       samlogon_state.r_ex.in.server_name = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
+       samlogon_state.r_ex.in.server_name = talloc_asprintf(fn_ctx, "\\\\%s", dcerpc_server_name(p));
        samlogon_state.r_ex.in.workstation = TEST_MACHINE_NAME;
        samlogon_state.r_ex.in.flags = 0;
 
-       samlogon_state.r.in.server_name = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
+       samlogon_state.r.in.server_name = talloc_asprintf(fn_ctx, "\\\\%s", dcerpc_server_name(p));
        samlogon_state.r.in.workstation = TEST_MACHINE_NAME;
        samlogon_state.r.in.credential = &samlogon_state.auth;
        samlogon_state.r.in.return_authenticator = &samlogon_state.auth2;
@@ -1117,6 +1117,8 @@ static BOOL test_SamLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                        for (v=0;v<ARRAY_SIZE(validation_levels);v++) {
                                for (l=0;l<ARRAY_SIZE(logon_levels);l++) {
                                        char *error_string = NULL;
+                                       TALLOC_CTX *tmp_ctx = talloc_named(fn_ctx, 0, "test_SamLogon inner loop");
+                                       samlogon_state.mem_ctx = tmp_ctx;
                                        samlogon_state.function_level = function_levels[f];
                                        samlogon_state.r.in.validation_level = validation_levels[v];
                                        samlogon_state.r.in.logon_level = logon_levels[l];
@@ -1139,11 +1141,12 @@ static BOOL test_SamLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                                                }
                                                SAFE_FREE(error_string);
                                        }
+                                       talloc_free(tmp_ctx);
                                }
                        }
                }
        }
-
+       talloc_free(fn_ctx);
        return ret;
 }
 
@@ -1156,6 +1159,7 @@ static BOOL test_InteractiveLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                                  const char *plain_pass)
 {
        NTSTATUS status;
+       TALLOC_CTX *fn_ctx = talloc_named(mem_ctx, 0, "test_InteractiveLogon function-level context");
        struct netr_LogonSamLogonWithFlags r;
        struct netr_Authenticator a, ra;
        struct netr_PasswordInfo pinfo;
@@ -1166,7 +1170,7 @@ static BOOL test_InteractiveLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
 
        creds_client_authenticator(creds, &a);
 
-       r.in.server_name = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
+       r.in.server_name = talloc_asprintf(fn_ctx, "\\\\%s", dcerpc_server_name(p));
        r.in.workstation = TEST_MACHINE_NAME;
        r.in.credential = &a;
        r.in.return_authenticator = &ra;
@@ -1195,14 +1199,17 @@ static BOOL test_InteractiveLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
 
        printf("Testing netr_LogonSamLogonWithFlags (Interactive Logon)\n");
 
-       status = dcerpc_netr_LogonSamLogonWithFlags(p, mem_ctx, &r);
+       status = dcerpc_netr_LogonSamLogonWithFlags(p, fn_ctx, &r);
        if (!r.out.return_authenticator || !creds_client_check(creds, &r.out.return_authenticator->cred)) {
                printf("Credential chaining failed\n");
+               talloc_free(fn_ctx);
                return False;
        }
 
+       talloc_free(fn_ctx);
+
        if (!NT_STATUS_IS_OK(status)) {
-               printf("netr_LogonSamLogonWithFlags - %s\n", nt_errstr(status));
+               printf("[%s]\\[%s] netr_LogonSamLogonWithFlags - %s\n", account_name, account_domain, nt_errstr(status));
                return False;
        }
 
@@ -1216,7 +1223,7 @@ BOOL torture_rpc_samlogon(void)
         NTSTATUS status;
         struct dcerpc_pipe *p;
        struct dcerpc_binding *b;
-       struct cli_credentials credentials;
+       struct cli_credentials *credentials;
        TALLOC_CTX *mem_ctx = talloc_init("torture_rpc_netlogon");
        BOOL ret = True;
        struct test_join *join_ctx;
@@ -1256,9 +1263,9 @@ BOOL torture_rpc_samlogon(void)
                        NULL,
                        talloc_asprintf(mem_ctx, 
                                        "%s@%s", 
-                       cli_credentials_get_domain(cmdline_credentials),
-                       cli_credentials_get_username(cmdline_credentials)
-                                       ),
+                                       cli_credentials_get_username(cmdline_credentials),
+                                       cli_credentials_get_domain(cmdline_credentials)
+                               ),
                        cli_credentials_get_password(cmdline_credentials),
                        False
                },
@@ -1268,7 +1275,7 @@ BOOL torture_rpc_samlogon(void)
                                        "%s@%s", 
                                        cli_credentials_get_username(cmdline_credentials),
                                        cli_credentials_get_realm(cmdline_credentials)
-                                       ),
+                               ),
                        cli_credentials_get_password(cmdline_credentials),
                        True
                },
@@ -1300,6 +1307,8 @@ BOOL torture_rpc_samlogon(void)
 #endif
        };
                
+       credentials = cli_credentials_init(mem_ctx);
+
        test_machine_account = talloc_asprintf(mem_ctx, "%s$", TEST_MACHINE_NAME);
        /* We only need to join as a workstation here, and in future,
         * if we wish to test against trusted domains, we must be a
@@ -1338,17 +1347,18 @@ BOOL torture_rpc_samlogon(void)
        b->flags &= ~DCERPC_AUTH_OPTIONS;
        b->flags |= DCERPC_SCHANNEL_WORKSTATION | DCERPC_SIGN | DCERPC_SCHANNEL_128;
 
-       cli_credentials_set_workstation(&credentials, TEST_MACHINE_NAME, CRED_SPECIFIED);
-       cli_credentials_set_domain(&credentials, lp_workgroup(), CRED_SPECIFIED);
-       cli_credentials_set_username(&credentials, test_machine_account, CRED_SPECIFIED);
-       cli_credentials_set_password(&credentials, machine_password, CRED_SPECIFIED);
+       cli_credentials_set_workstation(credentials, TEST_MACHINE_NAME, CRED_SPECIFIED);
+       cli_credentials_set_domain(credentials, lp_workgroup(), CRED_SPECIFIED);
+       cli_credentials_set_username(credentials, test_machine_account, CRED_SPECIFIED);
+       cli_credentials_set_password(credentials, machine_password, CRED_SPECIFIED);
 
-       status = dcerpc_pipe_connect_b(&p, b, 
+       status = dcerpc_pipe_connect_b(mem_ctx, &p, b, 
                                       DCERPC_NETLOGON_UUID,
                                       DCERPC_NETLOGON_VERSION,
-                                          &credentials);
+                                      credentials);
 
        if (!NT_STATUS_IS_OK(status)) {
+               printf("RPC pipe connect as domain member failed: %s\n", nt_errstr(status));
                ret = False;
                goto failed;
        }
@@ -1405,8 +1415,6 @@ BOOL torture_rpc_samlogon(void)
 failed:
        talloc_free(mem_ctx);
 
-       torture_rpc_close(p);
-
        torture_leave_domain(join_ctx);
 #if 0
        torture_leave_domain(user_ctx);
index 6b663acdf59250f3a91e5a8ddde37d22e4c64a6d..969711858c83e673a04806a76e72158aa0add3ca 100644 (file)
@@ -1573,12 +1573,15 @@ static BOOL test_CreateUser(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                SAMR_FIELD_PASSWORD | SAMR_FIELD_PASSWORD2,
                0
        };
+       
+       TALLOC_CTX *user_ctx;
 
        /* This call creates a 'normal' account - check that it really does */
        const uint32_t acct_flags = ACB_NORMAL;
        struct samr_String name;
        BOOL ret = True;
 
+       user_ctx = talloc_named(mem_ctx, 0, "test_CreateUser2 per-user context");
        init_samr_String(&name, TEST_ACCOUNT_NAME);
 
        r.in.domain_handle = domain_handle;
@@ -1589,21 +1592,24 @@ static BOOL test_CreateUser(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
 
        printf("Testing CreateUser(%s)\n", r.in.account_name->string);
 
-       status = dcerpc_samr_CreateUser(p, mem_ctx, &r);
+       status = dcerpc_samr_CreateUser(p, user_ctx, &r);
 
        if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
                printf("Server refused create of '%s'\n", r.in.account_name->string);
                ZERO_STRUCTP(user_handle);
+               talloc_free(user_ctx);
                return True;
        }
 
        if (NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) {
-               if (!test_DeleteUser_byname(p, mem_ctx, domain_handle, r.in.account_name->string)) {
+               if (!test_DeleteUser_byname(p, user_ctx, domain_handle, r.in.account_name->string)) {
+                       talloc_free(user_ctx);
                        return False;
                }
-               status = dcerpc_samr_CreateUser(p, mem_ctx, &r);
+               status = dcerpc_samr_CreateUser(p, user_ctx, &r);
        }
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(user_ctx);
                printf("CreateUser failed - %s\n", nt_errstr(status));
                return False;
        }
@@ -1611,7 +1617,7 @@ static BOOL test_CreateUser(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
        q.in.user_handle = user_handle;
        q.in.level = 16;
 
-       status = dcerpc_samr_QueryUserInfo(p, mem_ctx, &q);
+       status = dcerpc_samr_QueryUserInfo(p, user_ctx, &q);
        if (!NT_STATUS_IS_OK(status)) {
                printf("QueryUserInfo level %u failed - %s\n", 
                       q.in.level, nt_errstr(status));
@@ -1625,44 +1631,46 @@ static BOOL test_CreateUser(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                }
        }
 
-       if (!test_user_ops(p, mem_ctx, user_handle, acct_flags, name.string)) {
+       if (!test_user_ops(p, user_ctx, user_handle, acct_flags, name.string)) {
                ret = False;
        }
 
-       if (!test_SetUserPass(p, mem_ctx, user_handle, &password)) {
+       if (!test_SetUserPass(p, user_ctx, user_handle, &password)) {
                ret = False;
        }       
 
        for (i = 0; password_fields[i]; i++) {
-               if (!test_SetUserPass_23(p, mem_ctx, user_handle, password_fields[i], &password)) {
+               if (!test_SetUserPass_23(p, user_ctx, user_handle, password_fields[i], &password)) {
                        ret = False;
                }       
                
                /* check it was set right */
-               if (!test_ChangePasswordUser3(p, mem_ctx, domain_handle, 0, &password)) {
+               if (!test_ChangePasswordUser3(p, user_ctx, domain_handle, 0, &password)) {
                        ret = False;
                }
        }               
 
        for (i = 0; password_fields[i]; i++) {
-               if (!test_SetUserPass_25(p, mem_ctx, user_handle, password_fields[i], &password)) {
+               if (!test_SetUserPass_25(p, user_ctx, user_handle, password_fields[i], &password)) {
                        ret = False;
                }       
                
                /* check it was set right */
-               if (!test_ChangePasswordUser3(p, mem_ctx, domain_handle, 0, &password)) {
+               if (!test_ChangePasswordUser3(p, user_ctx, domain_handle, 0, &password)) {
                        ret = False;
                }
        }               
 
-       if (!test_SetUserPassEx(p, mem_ctx, user_handle, &password)) {
+       if (!test_SetUserPassEx(p, user_ctx, user_handle, &password)) {
                ret = False;
        }       
 
-       if (!test_ChangePassword(p, mem_ctx, domain_handle, &password)) {
+       if (!test_ChangePassword(p, user_ctx, domain_handle, &password)) {
                ret = False;
        }       
 
+       talloc_free(user_ctx);
+       
        return ret;
 }
 
@@ -1724,9 +1732,10 @@ static BOOL test_CreateUser2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
        };
 
        for (i = 0; account_types[i].account_name; i++) {
+               TALLOC_CTX *user_ctx;
                uint32_t acct_flags = account_types[i].acct_flags;
                uint32_t access_granted;
-
+               user_ctx = talloc_named(mem_ctx, 0, "test_CreateUser2 per-user context");
                init_samr_String(&name, account_types[i].account_name);
 
                r.in.domain_handle = handle;
@@ -1739,17 +1748,20 @@ static BOOL test_CreateUser2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                
                printf("Testing CreateUser2(%s, 0x%x)\n", r.in.account_name->string, acct_flags);
                
-               status = dcerpc_samr_CreateUser2(p, mem_ctx, &r);
+               status = dcerpc_samr_CreateUser2(p, user_ctx, &r);
                
                if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
+                       talloc_free(user_ctx);
                        printf("Server refused create of '%s'\n", r.in.account_name->string);
                        continue;
 
                } else if (NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) {
-                       if (!test_DeleteUser_byname(p, mem_ctx, handle, r.in.account_name->string)) {
-                               return False;
+                       if (!test_DeleteUser_byname(p, user_ctx, handle, r.in.account_name->string)) {
+                               talloc_free(user_ctx);
+                               ret = False;
+                               continue;
                        }
-                       status = dcerpc_samr_CreateUser2(p, mem_ctx, &r);
+                       status = dcerpc_samr_CreateUser2(p, user_ctx, &r);
 
                }
                if (!NT_STATUS_EQUAL(status, account_types[i].nt_status)) {
@@ -1762,7 +1774,7 @@ static BOOL test_CreateUser2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                        q.in.user_handle = &user_handle;
                        q.in.level = 16;
                        
-                       status = dcerpc_samr_QueryUserInfo(p, mem_ctx, &q);
+                       status = dcerpc_samr_QueryUserInfo(p, user_ctx, &q);
                        if (!NT_STATUS_IS_OK(status)) {
                                printf("QueryUserInfo level %u failed - %s\n", 
                                       q.in.level, nt_errstr(status));
@@ -1776,7 +1788,7 @@ static BOOL test_CreateUser2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                                }
                        }
                
-                       if (!test_user_ops(p, mem_ctx, &user_handle, acct_flags, name.string)) {
+                       if (!test_user_ops(p, user_ctx, &user_handle, acct_flags, name.string)) {
                                ret = False;
                        }
 
@@ -1785,12 +1797,13 @@ static BOOL test_CreateUser2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                        d.in.user_handle = &user_handle;
                        d.out.user_handle = &user_handle;
                        
-                       status = dcerpc_samr_DeleteUser(p, mem_ctx, &d);
+                       status = dcerpc_samr_DeleteUser(p, user_ctx, &d);
                        if (!NT_STATUS_IS_OK(status)) {
                                printf("DeleteUser failed - %s\n", nt_errstr(status));
                                ret = False;
                        }
                }
+               talloc_free(user_ctx);
        }
 
        return ret;
@@ -3188,11 +3201,13 @@ BOOL torture_rpc_samr(void)
 
        mem_ctx = talloc_init("torture_rpc_samr");
 
-       status = torture_rpc_connection(&p, 
+       status = torture_rpc_connection(mem_ctx, 
+                                       &p, 
                                        DCERPC_SAMR_NAME,
                                        DCERPC_SAMR_UUID,
                                        DCERPC_SAMR_VERSION);
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
                return False;
        }
 
@@ -3222,8 +3237,6 @@ BOOL torture_rpc_samr(void)
 
        talloc_free(mem_ctx);
 
-        torture_rpc_close(p);
-
        return ret;
 }
 
index b92752227cab7d6bd8948e61c04d4531ba1d0c6d..b8214859cd2f43a98b532e2353c86d42187a6b7c 100644 (file)
@@ -309,11 +309,13 @@ static BOOL samsync_handle_domain(TALLOC_CTX *mem_ctx, struct samsync_state *sam
 
        if (!samsync_state->domain_handle[database_id]) {
                samsync_state->domain_handle[database_id]
-                       = samsync_open_domain(mem_ctx, samsync_state, samsync_state->domain_name[database_id], 
-                                             &dom_sid);
+                       = talloc_reference(samsync_state, 
+                                          samsync_open_domain(mem_ctx, samsync_state, samsync_state->domain_name[database_id], 
+                                                              &dom_sid));
        }
        if (samsync_state->domain_handle[database_id]) {
                samsync_state->sid[database_id] = talloc_reference(samsync_state, dom_sid);
+               talloc_reference(dom_sid, dom_sid->sub_auths);
        }
 
        printf("\tsequence_nums[%d/%s]=%llu\n",
@@ -730,6 +732,7 @@ static BOOL samsync_handle_secret(TALLOC_CTX *mem_ctx, struct samsync_state *sam
        new->secret = data_blob_talloc(new, secret->current_cipher.cipher_data, secret->current_cipher.maxlen);
        new->mtime = secret->current_cipher_set_time;
 
+       new = talloc_reference(samsync_state, new);
        DLIST_ADD(samsync_state->secrets, new);
 
        old->name = talloc_reference(old, name);
@@ -918,6 +921,7 @@ static BOOL samsync_handle_trusted_domain(TALLOC_CTX *mem_ctx, struct samsync_st
   We would like to do this, but it is NOT_SUPPORTED on win2k3
        TEST_SEC_DESC_EQUAL(trusted_domain->sdbuf, lsa, &trustdom_handle);
 */
+       new = talloc_reference(samsync_state, new);
        DLIST_ADD(samsync_state->trusted_domains, new);
 
        return ret;
@@ -1015,6 +1019,7 @@ static BOOL test_DatabaseSync(struct samsync_state *samsync_state,
                              TALLOC_CTX *mem_ctx)
 {
        NTSTATUS status;
+       TALLOC_CTX *loop_ctx, *delta_ctx, *trustdom_ctx;
        struct netr_DatabaseSync r;
        const uint32_t database_ids[] = {SAM_DATABASE_DOMAIN, SAM_DATABASE_BUILTIN, SAM_DATABASE_PRIVS}; 
        int i, d;
@@ -1036,9 +1041,10 @@ static BOOL test_DatabaseSync(struct samsync_state *samsync_state,
                printf("Testing DatabaseSync of id %d\n", r.in.database_id);
 
                do {
+                       loop_ctx = talloc_named(mem_ctx, 0, "DatabaseSync loop context");
                        creds_client_authenticator(samsync_state->creds, &r.in.credential);
 
-                       status = dcerpc_netr_DatabaseSync(samsync_state->p, mem_ctx, &r);
+                       status = dcerpc_netr_DatabaseSync(samsync_state->p, loop_ctx, &r);
                        if (!NT_STATUS_IS_OK(status) &&
                            !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
                                printf("DatabaseSync - %s\n", nt_errstr(status));
@@ -1053,65 +1059,68 @@ static BOOL test_DatabaseSync(struct samsync_state *samsync_state,
                        r.in.sync_context = r.out.sync_context;
 
                        for (d=0; d < r.out.delta_enum_array->num_deltas; d++) {
+                               delta_ctx = talloc_named(loop_ctx, 0, "DatabaseSync delta context");
                                switch (r.out.delta_enum_array->delta_enum[d].delta_type) {
                                case NETR_DELTA_DOMAIN:
-                                       if (!samsync_handle_domain(mem_ctx, samsync_state, 
+                                       if (!samsync_handle_domain(delta_ctx, samsync_state, 
                                                                   r.in.database_id, &r.out.delta_enum_array->delta_enum[d])) {
                                                printf("Failed to handle DELTA_DOMAIN\n");
                                                ret = False;
                                        }
                                        break;
                                case NETR_DELTA_GROUP:
-                                       if (!samsync_handle_group(mem_ctx, samsync_state, 
+                                       if (!samsync_handle_group(delta_ctx, samsync_state, 
                                                                  r.in.database_id, &r.out.delta_enum_array->delta_enum[d])) {
                                                printf("Failed to handle DELTA_USER\n");
                                                ret = False;
                                        }
                                        break;
                                case NETR_DELTA_USER:
-                                       if (!samsync_handle_user(mem_ctx, samsync_state, 
+                                       if (!samsync_handle_user(delta_ctx, samsync_state, 
                                                                 r.in.database_id, &r.out.delta_enum_array->delta_enum[d])) {
                                                printf("Failed to handle DELTA_USER\n");
                                                ret = False;
                                        }
                                        break;
                                case NETR_DELTA_ALIAS:
-                                       if (!samsync_handle_alias(mem_ctx, samsync_state, 
+                                       if (!samsync_handle_alias(delta_ctx, samsync_state, 
                                                                  r.in.database_id, &r.out.delta_enum_array->delta_enum[d])) {
                                                printf("Failed to handle DELTA_ALIAS\n");
                                                ret = False;
                                        }
                                        break;
                                case NETR_DELTA_POLICY:
-                                       if (!samsync_handle_policy(mem_ctx, samsync_state, 
+                                       if (!samsync_handle_policy(delta_ctx, samsync_state, 
                                                                   r.in.database_id, &r.out.delta_enum_array->delta_enum[d])) {
                                                printf("Failed to handle DELTA_POLICY\n");
                                                ret = False;
                                        }
                                        break;
                                case NETR_DELTA_TRUSTED_DOMAIN:
-                                       if (!samsync_handle_trusted_domain(mem_ctx, samsync_state, 
+                                       if (!samsync_handle_trusted_domain(delta_ctx, samsync_state, 
                                                                           r.in.database_id, &r.out.delta_enum_array->delta_enum[d])) {
                                                printf("Failed to handle DELTA_TRUSTED_DOMAIN\n");
                                                ret = False;
                                        }
                                        break;
                                case NETR_DELTA_ACCOUNT:
-                                       if (!samsync_handle_account(mem_ctx, samsync_state, 
+                                       if (!samsync_handle_account(delta_ctx, samsync_state, 
                                                                    r.in.database_id, &r.out.delta_enum_array->delta_enum[d])) {
                                                printf("Failed to handle DELTA_ACCOUNT\n");
                                                ret = False;
                                        }
                                        break;
                                case NETR_DELTA_SECRET:
-                                       if (!samsync_handle_secret(mem_ctx, samsync_state, 
+                                       if (!samsync_handle_secret(delta_ctx, samsync_state, 
                                                                   r.in.database_id, &r.out.delta_enum_array->delta_enum[d])) {
                                                printf("Failed to handle DELTA_SECRET\n");
                                                ret = False;
                                        }
                                        break;
                                }
+                               talloc_free(delta_ctx);
                        }
+                       talloc_free(loop_ctx);
                } while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES));
                
        }
@@ -1121,10 +1130,12 @@ static BOOL test_DatabaseSync(struct samsync_state *samsync_state,
                printf("Never got a DOMAIN object in samsync!\n");
                return False;
        }
+
+       trustdom_ctx = talloc_named(mem_ctx, 0, "test_DatabaseSync Trusted domains context");
        
-       username = talloc_asprintf(mem_ctx, "%s$", domain);
+       username = talloc_asprintf(trustdom_ctx, "%s$", domain);
        for (t=samsync_state->trusted_domains; t; t=t->next) {
-               char *secret_name = talloc_asprintf(mem_ctx, "G$$%s", t->name);
+               char *secret_name = talloc_asprintf(trustdom_ctx, "G$$%s", t->name);
                for (s=samsync_state->secrets; s; s=s->next) {
                        if (StrCaseCmp(s->name, secret_name) == 0) {
                                NTSTATUS nt_status;
@@ -1132,7 +1143,7 @@ static BOOL test_DatabaseSync(struct samsync_state *samsync_state,
                                mdfour(nt_hash.hash, s->secret.data, s->secret.length);
                                
                                printf("Checking password for %s\\%s\n", t->name, username);
-                               nt_status = test_SamLogon(samsync_state->p_netlogon_wksta, mem_ctx, samsync_state->creds_netlogon_wksta, 
+                               nt_status = test_SamLogon(samsync_state->p_netlogon_wksta, trustdom_ctx, samsync_state->creds_netlogon_wksta, 
                                                          t->name,
                                                          username, 
                                                          TEST_WKSTA_MACHINE_NAME,
@@ -1153,7 +1164,7 @@ static BOOL test_DatabaseSync(struct samsync_state *samsync_state,
                                
                                /* break it */
                                nt_hash.hash[0]++;
-                               nt_status = test_SamLogon(samsync_state->p_netlogon_wksta, mem_ctx, samsync_state->creds_netlogon_wksta, 
+                               nt_status = test_SamLogon(samsync_state->p_netlogon_wksta, trustdom_ctx, samsync_state->creds_netlogon_wksta, 
                                                          t->name,
                                                          username, 
                                                          TEST_WKSTA_MACHINE_NAME,
@@ -1171,6 +1182,7 @@ static BOOL test_DatabaseSync(struct samsync_state *samsync_state,
                        }
                }
        }
+       talloc_free(trustdom_ctx);
        return ret;
 }
 
@@ -1181,6 +1193,7 @@ static BOOL test_DatabaseSync(struct samsync_state *samsync_state,
 static BOOL test_DatabaseDeltas(struct samsync_state *samsync_state, TALLOC_CTX *mem_ctx)
 {
        NTSTATUS status;
+       TALLOC_CTX *loop_ctx;
        struct netr_DatabaseDeltas r;
        const uint32_t database_ids[] = {0, 1, 2}; 
        int i;
@@ -1204,15 +1217,15 @@ static BOOL test_DatabaseDeltas(struct samsync_state *samsync_state, TALLOC_CTX
                       r.in.database_id, r.in.sequence_num);
 
                do {
+                       loop_ctx = talloc_named(mem_ctx, 0, "test_DatabaseDeltas loop context");
                        creds_client_authenticator(samsync_state->creds, &r.in.credential);
 
-                       status = dcerpc_netr_DatabaseDeltas(samsync_state->p, mem_ctx, &r);
+                       status = dcerpc_netr_DatabaseDeltas(samsync_state->p, loop_ctx, &r);
                        if (!NT_STATUS_IS_OK(status) &&
                            !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES) &&
                            !NT_STATUS_EQUAL(status, NT_STATUS_SYNCHRONIZATION_REQUIRED)) {
                                printf("DatabaseDeltas - %s\n", nt_errstr(status));
                                ret = False;
-                               break;
                        }
 
                        if (!creds_client_check(samsync_state->creds, &r.out.return_authenticator.cred)) {
@@ -1220,6 +1233,7 @@ static BOOL test_DatabaseDeltas(struct samsync_state *samsync_state, TALLOC_CTX
                        }
 
                        r.in.sequence_num++;
+                       talloc_free(loop_ctx);
                } while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES));
        }
 
@@ -1234,6 +1248,7 @@ static BOOL test_DatabaseSync2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                               struct creds_CredentialState *creds)
 {
        NTSTATUS status;
+       TALLOC_CTX *loop_ctx;
        struct netr_DatabaseSync2 r;
        const uint32_t database_ids[] = {0, 1, 2}; 
        int i;
@@ -1252,14 +1267,14 @@ static BOOL test_DatabaseSync2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                printf("Testing DatabaseSync2 of id %d\n", r.in.database_id);
 
                do {
+                       loop_ctx = talloc_named(mem_ctx, 0, "test_DatabaseSync2 loop context");
                        creds_client_authenticator(creds, &r.in.credential);
 
-                       status = dcerpc_netr_DatabaseSync2(p, mem_ctx, &r);
+                       status = dcerpc_netr_DatabaseSync2(p, loop_ctx, &r);
                        if (!NT_STATUS_IS_OK(status) &&
                            !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
                                printf("DatabaseSync2 - %s\n", nt_errstr(status));
                                ret = False;
-                               break;
                        }
 
                        if (!creds_client_check(creds, &r.out.return_authenticator.cred)) {
@@ -1267,6 +1282,7 @@ static BOOL test_DatabaseSync2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                        }
 
                        r.in.sync_context = r.out.sync_context;
+                       talloc_free(loop_ctx);
                } while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES));
        }
 
@@ -1295,7 +1311,8 @@ BOOL torture_rpc_samsync(void)
        struct lsa_ObjectAttribute attr;
        struct lsa_QosInfo qos;
        struct lsa_OpenPolicy2 r;
-       struct cli_credentials credentials;
+       struct cli_credentials *credentials;
+       struct cli_credentials *credentials_wksta;
 
        struct samsync_state *samsync_state;
 
@@ -1304,11 +1321,12 @@ BOOL torture_rpc_samsync(void)
        char *test_wksta_machine_account;
 
        mem_ctx = talloc_init("torture_rpc_netlogon");
-
+       
        test_machine_account = talloc_asprintf(mem_ctx, "%s$", TEST_MACHINE_NAME);
        join_ctx = torture_create_testuser(test_machine_account, lp_workgroup(), ACB_SVRTRUST, 
                                           &machine_password);
        if (!join_ctx) {
+               talloc_free(mem_ctx);
                printf("Failed to join as BDC\n");
                return False;
        }
@@ -1317,6 +1335,7 @@ BOOL torture_rpc_samsync(void)
        join_ctx2 = torture_create_testuser(test_wksta_machine_account, lp_workgroup(), ACB_WSTRUST, 
                                            &wksta_machine_password);
        if (!join_ctx2) {
+               talloc_free(mem_ctx);
                printf("Failed to join as member\n");
                return False;
        }
@@ -1325,6 +1344,7 @@ BOOL torture_rpc_samsync(void)
                                           lp_workgroup(),
                                           ACB_NORMAL, NULL);
        if (!user_ctx) {
+               talloc_free(mem_ctx);
                printf("Failed to create test account\n");
                return False;
        }
@@ -1375,7 +1395,8 @@ BOOL torture_rpc_samsync(void)
        }
        
 
-       status = torture_rpc_connection(&samsync_state->p_lsa, 
+       status = torture_rpc_connection(samsync_state,
+                                       &samsync_state->p_lsa, 
                                        DCERPC_LSARPC_NAME,
                                        DCERPC_LSARPC_UUID,
                                        DCERPC_LSARPC_VERSION);
@@ -1419,23 +1440,27 @@ BOOL torture_rpc_samsync(void)
        b->flags &= ~DCERPC_AUTH_OPTIONS;
        b->flags |= DCERPC_SCHANNEL_BDC | DCERPC_SIGN;
 
-       cli_credentials_set_workstation(&credentials, TEST_MACHINE_NAME, CRED_SPECIFIED);
-       cli_credentials_set_domain(&credentials, lp_workgroup(), CRED_SPECIFIED);
-       cli_credentials_set_username(&credentials, test_machine_account, CRED_SPECIFIED);
-       cli_credentials_set_password(&credentials, machine_password, CRED_SPECIFIED);
+       credentials = cli_credentials_init(mem_ctx);
 
-       status = dcerpc_pipe_connect_b(&samsync_state->p, b, 
+       cli_credentials_set_workstation(credentials, TEST_MACHINE_NAME, CRED_SPECIFIED);
+       cli_credentials_set_domain(credentials, lp_workgroup(), CRED_SPECIFIED);
+       cli_credentials_set_username(credentials, test_machine_account, CRED_SPECIFIED);
+       cli_credentials_set_password(credentials, machine_password, CRED_SPECIFIED);
+
+       status = dcerpc_pipe_connect_b(samsync_state,
+                                      &samsync_state->p, b, 
                                       DCERPC_NETLOGON_UUID,
                                       DCERPC_NETLOGON_VERSION,
-                                          &credentials);
-
+                                      credentials);
+       
        if (!NT_STATUS_IS_OK(status)) {
                printf("Failed to connect to server as a BDC: %s\n", nt_errstr(status));
                ret = False;
                goto failed;
        }
 
-       status = dcerpc_schannel_creds(samsync_state->p->conn->security_state.generic_state, mem_ctx, &samsync_state->creds);
+       status = dcerpc_schannel_creds(samsync_state->p->conn->security_state.generic_state, 
+                                      samsync_state, &samsync_state->creds);
        if (!NT_STATUS_IS_OK(status)) {
                ret = False;
        }
@@ -1452,15 +1477,19 @@ BOOL torture_rpc_samsync(void)
        b_netlogon_wksta->flags &= ~DCERPC_AUTH_OPTIONS;
        b_netlogon_wksta->flags |= DCERPC_SCHANNEL_WORKSTATION | DCERPC_SIGN;
 
-       cli_credentials_set_workstation(&credentials, TEST_WKSTA_MACHINE_NAME, CRED_SPECIFIED);
-       cli_credentials_set_username(&credentials, test_wksta_machine_account, CRED_SPECIFIED);
-       cli_credentials_set_password(&credentials, wksta_machine_password, CRED_SPECIFIED);
+       credentials_wksta = cli_credentials_init(mem_ctx);
+
+       cli_credentials_set_workstation(credentials_wksta, TEST_WKSTA_MACHINE_NAME, CRED_SPECIFIED);
+       cli_credentials_set_domain(credentials_wksta, lp_workgroup(), CRED_SPECIFIED);
+       cli_credentials_set_username(credentials_wksta, test_wksta_machine_account, CRED_SPECIFIED);
+       cli_credentials_set_password(credentials_wksta, wksta_machine_password, CRED_SPECIFIED);
 
-       status = dcerpc_pipe_connect_b(&samsync_state->p_netlogon_wksta, 
+       status = dcerpc_pipe_connect_b(samsync_state, 
+                                      &samsync_state->p_netlogon_wksta, 
                                       b_netlogon_wksta, 
                                       DCERPC_NETLOGON_UUID,
                                       DCERPC_NETLOGON_VERSION,
-                                          &credentials);
+                                      credentials_wksta);
 
        if (!NT_STATUS_IS_OK(status)) {
                printf("Failed to connect to server as a Workstation: %s\n", nt_errstr(status));
@@ -1469,7 +1498,7 @@ BOOL torture_rpc_samsync(void)
        }
 
        status = dcerpc_schannel_creds(samsync_state->p_netlogon_wksta->conn->security_state.generic_state, 
-                                      mem_ctx, &samsync_state->creds_netlogon_wksta);
+                                      samsync_state, &samsync_state->creds_netlogon_wksta);
        if (!NT_STATUS_IS_OK(status)) {
                printf("Failed to obtail schanel creds!\n");
                ret = False;
@@ -1490,7 +1519,6 @@ BOOL torture_rpc_samsync(void)
                ret = False;
        }
 failed:
-       torture_rpc_close(samsync_state->p);
 
        torture_leave_domain(join_ctx);
        torture_leave_domain(join_ctx2);
index 3d78d7a888247252fab463546433bf860668ce68..d7a5d03271e1cde453076a96a98b04780f5ae658 100644 (file)
@@ -39,7 +39,8 @@ static BOOL test_num_calls(const struct dcerpc_interface_table *iface,
 
        uuid = GUID_string(mem_ctx, &id->uuid);
 
-       status = torture_rpc_connection(&p, iface->name,
+       status = torture_rpc_connection(mem_ctx, 
+                                       &p, iface->name,
                                        uuid, id->if_version);
        if (!NT_STATUS_IS_OK(status)) {
                printf("Failed to connect to '%s' on '%s' - %s\n", 
@@ -80,7 +81,7 @@ static BOOL test_num_calls(const struct dcerpc_interface_table *iface,
        }
 
 done:
-       torture_rpc_close(p);
+       talloc_free(p);
        return True;
 }
 
@@ -132,7 +133,7 @@ BOOL torture_rpc_scanner(void)
 {
         NTSTATUS status;
         struct dcerpc_pipe *p;
-       TALLOC_CTX *mem_ctx;
+       TALLOC_CTX *mem_ctx, *loop_ctx;
        BOOL ret = True;
        const struct dcerpc_interface_list *l;
        const char *binding = lp_parm_string(-1, "torture", "binding");
@@ -141,20 +142,24 @@ BOOL torture_rpc_scanner(void)
        mem_ctx = talloc_init("torture_rpc_scanner");
 
        if (!binding) {
+               talloc_free(mem_ctx);
                printf("You must supply a ncacn binding string\n");
                return False;
        }
        
        status = dcerpc_parse_binding(mem_ctx, binding, &b);
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
                printf("Failed to parse binding '%s'\n", binding);
                return False;
        }
 
        for (l=librpc_dcerpc_pipes();l;l=l->next) {             
+               loop_ctx = talloc_named(mem_ctx, 0, "torture_rpc_scanner loop context");
                /* some interfaces are not mappable */
                if (l->table->num_calls == 0 ||
                    strcmp(l->table->name, "mgmt") == 0) {
+                       talloc_free(loop_ctx);
                        continue;
                }
 
@@ -165,6 +170,7 @@ BOOL torture_rpc_scanner(void)
                                                         l->table->uuid,
                                                         l->table->if_version);
                        if (!NT_STATUS_IS_OK(status)) {
+                               talloc_free(loop_ctx);
                                printf("Failed to map port for uuid %s\n", l->table->uuid);
                                continue;
                        }
@@ -174,11 +180,13 @@ BOOL torture_rpc_scanner(void)
 
                lp_set_cmdline("torture:binding", dcerpc_binding_string(mem_ctx, b));
 
-               status = torture_rpc_connection(&p, 
+               status = torture_rpc_connection(loop_ctx, 
+                                               &p, 
                                                l->table->name,
                                                DCERPC_MGMT_UUID,
                                                DCERPC_MGMT_VERSION);
                if (!NT_STATUS_IS_OK(status)) {
+                       talloc_free(loop_ctx);
                        ret = False;
                        continue;
                }
@@ -186,8 +194,6 @@ BOOL torture_rpc_scanner(void)
                if (!test_inq_if_ids(p, mem_ctx, l->table)) {
                        ret = False;
                }
-
-               torture_rpc_close(p);
        }
 
        return ret;
index f572933bf55a913394084eeb11b52f3bff9eb067..d27285a9cc2d66e4a7c7403acf140d8c19b5cbf5 100644 (file)
@@ -127,17 +127,22 @@ static BOOL test_schannel(TALLOC_CTX *mem_ctx,
        struct dcerpc_pipe *p = NULL;
        struct dcerpc_pipe *p_netlogon = NULL;
        struct creds_CredentialState *creds;
-       struct cli_credentials credentials;
+       struct cli_credentials *credentials;
+
+       TALLOC_CTX *test_ctx = talloc_named(mem_ctx, 0, "test_schannel context");
        char *test_machine_account = talloc_asprintf(NULL, "%s$", TEST_MACHINE_NAME);
 
+       credentials = cli_credentials_init(mem_ctx);
+
        join_ctx = torture_create_testuser(test_machine_account, lp_workgroup(), 
                                           acct_flags, &machine_password);
        if (!join_ctx) {
                printf("Failed to join domain with acct_flags=0x%x\n", acct_flags);
+               talloc_free(test_ctx);
                return False;
        }
 
-       status = dcerpc_parse_binding(mem_ctx, binding, &b);
+       status = dcerpc_parse_binding(test_ctx, binding, &b);
        if (!NT_STATUS_IS_OK(status)) {
                printf("Bad binding string %s\n", binding);
                goto failed;
@@ -146,25 +151,27 @@ static BOOL test_schannel(TALLOC_CTX *mem_ctx,
        b->flags &= ~DCERPC_AUTH_OPTIONS;
        b->flags |= dcerpc_flags;
 
-       cli_credentials_set_domain(&credentials, lp_workgroup(), CRED_SPECIFIED);
-       cli_credentials_set_workstation(&credentials, TEST_MACHINE_NAME, CRED_SPECIFIED);
-       cli_credentials_set_username(&credentials, test_machine_account, CRED_SPECIFIED);
-       cli_credentials_set_password(&credentials, machine_password, CRED_SPECIFIED);
-       status = dcerpc_pipe_connect_b(&p, b, 
+       cli_credentials_set_domain(credentials, lp_workgroup(), CRED_SPECIFIED);
+       cli_credentials_set_workstation(credentials, TEST_MACHINE_NAME, CRED_SPECIFIED);
+       cli_credentials_set_username(credentials, test_machine_account, CRED_SPECIFIED);
+       cli_credentials_set_password(credentials, machine_password, CRED_SPECIFIED);
+
+       status = dcerpc_pipe_connect_b(test_ctx, 
+                                      &p, b, 
                                       DCERPC_SAMR_UUID,
                                       DCERPC_SAMR_VERSION,
-                                          &credentials);
+                                      credentials);
        if (!NT_STATUS_IS_OK(status)) {
                printf("Failed to connect with schannel: %s\n", nt_errstr(status));
                goto failed;
        }
 
-       if (!test_samr_ops(p, mem_ctx)) {
+       if (!test_samr_ops(p, test_ctx)) {
                printf("Failed to process schannel secured ops\n");
                goto failed;
        }
 
-       status = dcerpc_schannel_creds(p->conn->security_state.generic_state, mem_ctx, &creds);
+       status = dcerpc_schannel_creds(p->conn->security_state.generic_state, test_ctx, &creds);
        if (!NT_STATUS_IS_OK(status)) {
                goto failed;
        }
@@ -174,7 +181,7 @@ static BOOL test_schannel(TALLOC_CTX *mem_ctx,
         * the second */
 
        /* Swap the binding details from SAMR to NETLOGON */
-       status = dcerpc_epm_map_binding(mem_ctx, b, DCERPC_NETLOGON_UUID,
+       status = dcerpc_epm_map_binding(test_ctx, b, DCERPC_NETLOGON_UUID,
                                        DCERPC_NETLOGON_VERSION);
        if (!NT_STATUS_IS_OK(status)) {
                goto failed;
@@ -196,26 +203,24 @@ static BOOL test_schannel(TALLOC_CTX *mem_ctx,
                goto failed;
        }
 
-       status = dcerpc_schannel_creds(p_netlogon->conn->security_state.generic_state, mem_ctx, &creds);
+       status = dcerpc_schannel_creds(p_netlogon->conn->security_state.generic_state, test_ctx, &creds);
        if (!NT_STATUS_IS_OK(status)) {
                goto failed;
        }
 
        /* do a couple of logins */
-       if (!test_netlogon_ops(p_netlogon, mem_ctx, creds)) {
+       if (!test_netlogon_ops(p_netlogon, test_ctx, creds)) {
                printf("Failed to process schannel secured ops\n");
                goto failed;
        }
 
        torture_leave_domain(join_ctx);
-       dcerpc_pipe_close(p_netlogon);
-       dcerpc_pipe_close(p);
+       talloc_free(test_ctx);
        return True;
 
 failed:
        torture_leave_domain(join_ctx);
-       dcerpc_pipe_close(p_netlogon);
-       dcerpc_pipe_close(p);
+       talloc_free(test_ctx);
        return False;   
 }
 
index e5c827afaab238722da0500532b04241fa4749ec..acaa5828dc9cb6a3836401a8bcb63859d13f4725 100644 (file)
@@ -732,7 +732,7 @@ static BOOL test_SecondaryClosePrinter(struct dcerpc_pipe *p, TALLOC_CTX *mem_ct
                                       DCERPC_SPOOLSS_VERSION);
        if (!NT_STATUS_IS_OK(status)) {
                printf("Failed to create bind on secondary connection\n");
-               dcerpc_pipe_close(p2);
+               talloc_free(p2);
 
                 return False;
         }
@@ -748,7 +748,7 @@ static BOOL test_SecondaryClosePrinter(struct dcerpc_pipe *p, TALLOC_CTX *mem_ct
                ret = False;
        }
 
-       dcerpc_pipe_close(p2);
+       talloc_free(p2);
 
        return ret;
 }
@@ -1165,16 +1165,18 @@ BOOL torture_rpc_spoolss(void)
        TALLOC_CTX *mem_ctx;
        BOOL ret = True;
 
-       status = torture_rpc_connection(&p, 
+       mem_ctx = talloc_init("torture_rpc_spoolss");
+
+       status = torture_rpc_connection(mem_ctx, 
+                                       &p, 
                                        DCERPC_SPOOLSS_NAME,
                                        DCERPC_SPOOLSS_UUID,
                                        DCERPC_SPOOLSS_VERSION);
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
                return False;
        }
 
-       mem_ctx = talloc_init("torture_rpc_spoolss");
-
        ret &= test_OpenPrinter_badnames(p, mem_ctx);
 
        ret &= test_AddPort(p, mem_ctx);
@@ -1187,7 +1189,5 @@ BOOL torture_rpc_spoolss(void)
 
        talloc_free(mem_ctx);
 
-        torture_rpc_close(p);
-
        return ret;
 }
index 697ae4afe7865b7f2ce8eb3bb44507d9ac56bfec..c12504e646947298b559104f050ab4b8c7846359 100644 (file)
@@ -720,11 +720,13 @@ BOOL torture_rpc_srvsvc(void)
 
        mem_ctx = talloc_init("torture_rpc_srvsvc");
 
-       status = torture_rpc_connection(&p,
+       status = torture_rpc_connection(mem_ctx, 
+                                       &p,
                                        DCERPC_SRVSVC_NAME,
                                        DCERPC_SRVSVC_UUID,
                                        DCERPC_SRVSVC_VERSION);
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
                return False;
        }
 
@@ -774,7 +776,5 @@ BOOL torture_rpc_srvsvc(void)
 
        talloc_free(mem_ctx);
 
-        torture_rpc_close(p);
-
        return ret;
 }
index 092329ab68f8ce595c6ba7c994ee14d34d0a3193..44b79058a95fa1aca80942564d09e105b014619e 100644 (file)
@@ -117,11 +117,13 @@ BOOL torture_rpc_svcctl(void)
 
        mem_ctx = talloc_init("torture_rpc_svcctl");
 
-       status = torture_rpc_connection(&p,
+       status = torture_rpc_connection(mem_ctx, 
+                                       &p,
                                        DCERPC_SVCCTL_NAME,
                                        DCERPC_SVCCTL_UUID,
                                        DCERPC_SVCCTL_VERSION);
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
                return False;
        }
 
@@ -139,7 +141,5 @@ BOOL torture_rpc_svcctl(void)
 
        talloc_free(mem_ctx);
 
-    torture_rpc_close(p);
-
        return ret;
 }
index 2d96116c0da08e4d646544a7287ace84e03b75ef..5e4c5a32f31fa5bd24967430e145e518bed81e15 100644 (file)
@@ -121,7 +121,8 @@ struct test_join *torture_create_testuser(const char *username,
 
        printf("Connecting to SAMR\n");
 
-       status = torture_rpc_connection(&join->p, 
+       status = torture_rpc_connection(join, 
+                                       &join->p, 
                                        DCERPC_SAMR_NAME,
                                        DCERPC_SAMR_UUID,
                                        DCERPC_SAMR_VERSION);
@@ -305,10 +306,6 @@ void torture_leave_domain(struct test_join *join)
                }
        }
 
-       if (join->p) {
-               torture_rpc_close(join->p);
-       }
-
        talloc_free(join);
 }
 
index df0114b669540ae939f0adcf46f37f531d7a4659..c6eada4d793e6f40766e26cd38393ca9df73453f 100644 (file)
@@ -760,7 +760,7 @@ static BOOL test_Open(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, void *fn)
 BOOL torture_rpc_winreg(void)
 {
         NTSTATUS status;
-       struct dcerpc_pipe *p;
+       struct dcerpc_pipe *p;
        TALLOC_CTX *mem_ctx;
        BOOL ret = True;
        winreg_open_fn *open_fns[] = { test_OpenHKLM, test_OpenHKU,
@@ -769,12 +769,14 @@ BOOL torture_rpc_winreg(void)
 
        mem_ctx = talloc_init("torture_rpc_winreg");
 
-       status = torture_rpc_connection(&p, 
+       status = torture_rpc_connection(mem_ctx, 
+                                       &p, 
                                        DCERPC_WINREG_NAME, 
                                        DCERPC_WINREG_UUID, 
                                        DCERPC_WINREG_VERSION);
 
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
                return False;
        }
 
@@ -794,7 +796,5 @@ BOOL torture_rpc_winreg(void)
 
        talloc_free(mem_ctx);
 
-        torture_rpc_close(p);
-
        return ret;
 }
index f3a3ec233c2da93c3d8fc6bb179279d7ee70bb9c..47e893ae2e854f78d926216fc51658ecf39732c8 100644 (file)
@@ -93,11 +93,13 @@ BOOL torture_rpc_wkssvc(void)
 
        mem_ctx = talloc_init("torture_rpc_wkssvc");
 
-       status = torture_rpc_connection(&p, 
+       status = torture_rpc_connection(mem_ctx, 
+                                       &p, 
                                        DCERPC_WKSSVC_NAME,
                                        DCERPC_WKSSVC_UUID,
                                        DCERPC_WKSSVC_VERSION);
        if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
                return False;
        }
 
@@ -111,7 +113,5 @@ BOOL torture_rpc_wkssvc(void)
 
        talloc_free(mem_ctx);
 
-        torture_rpc_close(p);
-
        return ret;
 }
index cdc9efbf7c6ccbcc4262597fac55d4a5213575fa..4fca36a9aee58c9d31bd44d30fedfb3b115cf520 100644 (file)
@@ -120,7 +120,8 @@ BOOL torture_close_connection(struct smbcli_state *c)
 }
 
 /* open a rpc connection to the chosen binding string */
-NTSTATUS torture_rpc_connection(struct dcerpc_pipe **p, 
+NTSTATUS torture_rpc_connection(TALLOC_CTX *parent_ctx, 
+                               struct dcerpc_pipe **p, 
                                const char *pipe_name,
                                const char *pipe_uuid, 
                                uint32_t pipe_version)
@@ -133,14 +134,16 @@ NTSTATUS torture_rpc_connection(struct dcerpc_pipe **p,
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       status = dcerpc_pipe_connect(p, binding, pipe_uuid, pipe_version,
-                                        cmdline_credentials);
+       status = dcerpc_pipe_connect(parent_ctx, 
+                                    p, binding, pipe_uuid, pipe_version,
+                                    cmdline_credentials);
  
         return status;
 }
 
 /* open a rpc connection to a specific transport */
-NTSTATUS torture_rpc_connection_transport(struct dcerpc_pipe **p, 
+NTSTATUS torture_rpc_connection_transport(TALLOC_CTX *parent_ctx, 
+                                         struct dcerpc_pipe **p, 
                                          const char *pipe_name,
                                          const char *pipe_uuid, 
                                          uint32_t pipe_version,
@@ -149,10 +152,11 @@ NTSTATUS torture_rpc_connection_transport(struct dcerpc_pipe **p,
         NTSTATUS status;
        const char *binding = lp_parm_string(-1, "torture", "binding");
        struct dcerpc_binding *b;
-       TALLOC_CTX *mem_ctx = talloc_init("torture_rpc_connection_smb");
+       TALLOC_CTX *mem_ctx = talloc_named(parent_ctx, 0, "torture_rpc_connection_smb");
 
        if (!binding) {
                printf("You must specify a ncacn binding string\n");
+               talloc_free(mem_ctx);
                return NT_STATUS_INVALID_PARAMETER;
        }
 
@@ -165,21 +169,18 @@ NTSTATUS torture_rpc_connection_transport(struct dcerpc_pipe **p,
 
        b->transport = transport;
 
-       status = dcerpc_pipe_connect_b(p, b, pipe_uuid, pipe_version,
+       status = dcerpc_pipe_connect_b(mem_ctx, p, b, pipe_uuid, pipe_version,
                                                                   cmdline_credentials);
                                           
+       if (NT_STATUS_IS_OK(status)) {
+               *p = talloc_reference(parent_ctx, *p);
+       } else {
+               *p = NULL;
+       }
+       talloc_free(mem_ctx);
         return status;
 }
 
-/* close a rpc connection to a named pipe */
-NTSTATUS torture_rpc_close(struct dcerpc_pipe *p)
-{
-       dcerpc_pipe_close(p);
-       return NT_STATUS_OK;
-}
-
-
 /* check if the server produced the expected error code */
 BOOL check_error(const char *location, struct smbcli_state *c, 
                 uint8_t eclass, uint32_t ecode, NTSTATUS nterr)
@@ -2636,7 +2637,7 @@ static BOOL is_binding_string(const char *binding_string)
 #endif
 
        pc = poptGetContext("smbtorture", argc, (const char **) argv, long_options, 
-                               POPT_CONTEXT_KEEP_FIRST);
+                           POPT_CONTEXT_KEEP_FIRST);
 
        poptSetOtherOptionHelp(pc, "<binding>|<unc> TEST1 TEST2 ...");