summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source4/client/client.c3
-rw-r--r--source4/gtk/common/gtk-smb.c2
-rw-r--r--source4/gtk/tools/gepdump.c2
-rw-r--r--source4/gtk/tools/gwcrontab.c5
-rw-r--r--source4/gtk/tools/gwsam.c7
-rw-r--r--source4/lib/cmdline/popt_common.c9
-rw-r--r--source4/lib/com/dcom/main.c10
-rw-r--r--source4/lib/credentials.c43
-rw-r--r--source4/lib/registry/reg_backend_rpc.c14
-rw-r--r--source4/libcli/cliconnect.c5
-rw-r--r--source4/libcli/raw/clitree.c8
-rw-r--r--source4/libnet/libnet_join.c2
-rw-r--r--source4/libnet/libnet_passwd.c4
-rw-r--r--source4/libnet/libnet_rpc.c3
-rw-r--r--source4/libnet/libnet_time.c2
-rw-r--r--source4/librpc/rpc/dcerpc.c6
-rw-r--r--source4/librpc/rpc/dcerpc_schannel.c31
-rw-r--r--source4/librpc/rpc/dcerpc_util.c191
-rw-r--r--source4/rpc_server/remote/dcesrv_remote.c21
-rw-r--r--source4/torture/com/simple.c9
-rw-r--r--source4/torture/libnet/userinfo.c4
-rw-r--r--source4/torture/masktest.c10
-rw-r--r--source4/torture/rpc/alter_context.c8
-rw-r--r--source4/torture/rpc/atsvc.c8
-rw-r--r--source4/torture/rpc/autoidl.c35
-rw-r--r--source4/torture/rpc/bind.c5
-rw-r--r--source4/torture/rpc/countcalls.c5
-rw-r--r--source4/torture/rpc/dcom.c12
-rw-r--r--source4/torture/rpc/dfs.c5
-rw-r--r--source4/torture/rpc/drsuapi.c10
-rw-r--r--source4/torture/rpc/dssetup.c6
-rw-r--r--source4/torture/rpc/echo.c6
-rw-r--r--source4/torture/rpc/epmapper.c6
-rw-r--r--source4/torture/rpc/eventlog.c7
-rw-r--r--source4/torture/rpc/initshutdown.c6
-rw-r--r--source4/torture/rpc/lsa.c6
-rw-r--r--source4/torture/rpc/mgmt.c30
-rw-r--r--source4/torture/rpc/netlogon.c19
-rw-r--r--source4/torture/rpc/oxidresolve.c10
-rw-r--r--source4/torture/rpc/remact.c10
-rw-r--r--source4/torture/rpc/rot.c10
-rw-r--r--source4/torture/rpc/samlogon.c52
-rw-r--r--source4/torture/rpc/samr.c59
-rw-r--r--source4/torture/rpc/samsync.c102
-rw-r--r--source4/torture/rpc/scanner.c18
-rw-r--r--source4/torture/rpc/schannel.c39
-rw-r--r--source4/torture/rpc/spoolss.c14
-rw-r--r--source4/torture/rpc/srvsvc.c6
-rw-r--r--source4/torture/rpc/svcctl.c6
-rw-r--r--source4/torture/rpc/testjoin.c7
-rw-r--r--source4/torture/rpc/winreg.c8
-rw-r--r--source4/torture/rpc/wkssvc.c6
-rw-r--r--source4/torture/torture.c33
53 files changed, 493 insertions, 452 deletions
diff --git a/source4/client/client.c b/source4/client/client.c
index a1a055c9be..4ce686cdcf 100644
--- a/source4/client/client.c
+++ b/source4/client/client.c
@@ -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;
diff --git a/source4/gtk/common/gtk-smb.c b/source4/gtk/common/gtk-smb.c
index e03c4096f0..a84f9f639d 100644
--- a/source4/gtk/common/gtk-smb.c
+++ b/source4/gtk/common/gtk-smb.c
@@ -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);
diff --git a/source4/gtk/tools/gepdump.c b/source4/gtk/tools/gepdump.c
index 28234c006e..1bf938feb2 100644
--- a/source4/gtk/tools/gepdump.c
+++ b/source4/gtk/tools/gepdump.c
@@ -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);
diff --git a/source4/gtk/tools/gwcrontab.c b/source4/gtk/tools/gwcrontab.c
index 47a7d68dc9..a1b57225db 100644
--- a/source4/gtk/tools/gwcrontab.c
+++ b/source4/gtk/tools/gwcrontab.c
@@ -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();
}
diff --git a/source4/gtk/tools/gwsam.c b/source4/gtk/tools/gwsam.c
index 75a4b532f2..71765424d7 100644
--- a/source4/gtk/tools/gwsam.c
+++ b/source4/gtk/tools/gwsam.c
@@ -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();
}
diff --git a/source4/lib/cmdline/popt_common.c b/source4/lib/cmdline/popt_common.c
index c65c311af1..d364f4d3bf 100644
--- a/source4/lib/cmdline/popt_common.c
+++ b/source4/lib/cmdline/popt_common.c
@@ -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 */
diff --git a/source4/lib/com/dcom/main.c b/source4/lib/com/dcom/main.c
index be350c32f5..08a928cda6 100644
--- a/source4/lib/com/dcom/main.c
+++ b/source4/lib/com/dcom/main.c
@@ -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++;
diff --git a/source4/lib/credentials.c b/source4/lib/credentials.c
index 2601028e7e..92f389e228 100644
--- a/source4/lib/credentials.c
+++ b/source4/lib/credentials.c
@@ -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
@@ -22,12 +23,14 @@
#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;
diff --git a/source4/lib/registry/reg_backend_rpc.c b/source4/lib/registry/reg_backend_rpc.c
index a72d104521..5240cf5696 100644
--- a/source4/lib/registry/reg_backend_rpc.c
+++ b/source4/lib/registry/reg_backend_rpc.c
@@ -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;
}
diff --git a/source4/libcli/cliconnect.c b/source4/libcli/cliconnect.c
index 3834d49e49..7459460137 100644
--- a/source4/libcli/cliconnect.c
+++ b/source4/libcli/cliconnect.c
@@ -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 {
diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c
index 0559c64dc1..f333cf7a98 100644
--- a/source4/libcli/raw/clitree.c
+++ b/source4/libcli/raw/clitree.c
@@ -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)) {
diff --git a/source4/libnet/libnet_join.c b/source4/libnet/libnet_join.c
index f8acac8fb2..2dcffd93e1 100644
--- a/source4/libnet/libnet_join.c
+++ b/source4/libnet/libnet_join.c
@@ -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;
}
diff --git a/source4/libnet/libnet_passwd.c b/source4/libnet/libnet_passwd.c
index 41d70d8208..9613df75f3 100644
--- a/source4/libnet/libnet_passwd.c
+++ b/source4/libnet/libnet_passwd.c
@@ -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;
}
diff --git a/source4/libnet/libnet_rpc.c b/source4/libnet/libnet_rpc.c
index 7e941aac76..1f1812e261 100644
--- a/source4/libnet/libnet_rpc.c
+++ b/source4/libnet/libnet_rpc.c
@@ -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,
diff --git a/source4/libnet/libnet_time.c b/source4/libnet/libnet_time.c
index ddf26876b9..b8f4cb7a86 100644
--- a/source4/libnet/libnet_time.c
+++ b/source4/libnet/libnet_time.c
@@ -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;
}
diff --git a/source4/librpc/rpc/dcerpc.c b/source4/librpc/rpc/dcerpc.c
index f2f78519f0..2a7ca8eb17 100644
--- a/source4/librpc/rpc/dcerpc.c
+++ b/source4/librpc/rpc/dcerpc.c
@@ -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)
diff --git a/source4/librpc/rpc/dcerpc_schannel.c b/source4/librpc/rpc/dcerpc_schannel.c
index bcdd1a923c..77453cf476 100644
--- a/source4/librpc/rpc/dcerpc_schannel.c
+++ b/source4/librpc/rpc/dcerpc_schannel.c
@@ -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 |
diff --git a/source4/librpc/rpc/dcerpc_util.c b/source4/librpc/rpc/dcerpc_util.c
index d539f9f74e..3ee3445ede 100644
--- a/source4/librpc/rpc/dcerpc_util.c
+++ b/source4/librpc/rpc/dcerpc_util.c
@@ -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;
diff --git a/source4/rpc_server/remote/dcesrv_remote.c b/source4/rpc_server/remote/dcesrv_remote.c
index 4c25ace71e..825adddfee 100644
--- a/source4/rpc_server/remote/dcesrv_remote.c
+++ b/source4/rpc_server/remote/dcesrv_remote.c
@@ -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;
}
diff --git a/source4/torture/com/simple.c b/source4/torture/com/simple.c
index 128d84d1c7..25800896db 100644
--- a/source4/torture/com/simple.c
+++ b/source4/torture/com/simple.c
@@ -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;
}
diff --git a/source4/torture/libnet/userinfo.c b/source4/torture/libnet/userinfo.c
index 9a775277cb..911aa086d4 100644
--- a/source4/torture/libnet/userinfo.c
+++ b/source4/torture/libnet/userinfo.c
@@ -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;
}
diff --git a/source4/torture/masktest.c b/source4/torture/masktest.c
index 00a0c2688d..d760934334 100644
--- a/source4/torture/masktest.c
+++ b/source4/torture/masktest.c
@@ -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);
diff --git a/source4/torture/rpc/alter_context.c b/source4/torture/rpc/alter_context.c
index 79135ba018..ad00a34913 100644
--- a/source4/torture/rpc/alter_context.c
+++ b/source4/torture/rpc/alter_context.c
@@ -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;
}
diff --git a/source4/torture/rpc/atsvc.c b/source4/torture/rpc/atsvc.c
index fd29a9228b..0be4e3ca58 100644
--- a/source4/torture/rpc/atsvc.c
+++ b/source4/torture/rpc/atsvc.c
@@ -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;
}
diff --git a/source4/torture/rpc/autoidl.c b/source4/torture/rpc/autoidl.c
index 0df88d2bf6..3bf8f0e2c8 100644
--- a/source4/torture/rpc/autoidl.c
+++ b/source4/torture/rpc/autoidl.c
@@ -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;
}
diff --git a/source4/torture/rpc/bind.c b/source4/torture/rpc/bind.c
index 71eaec4f92..6ab36cf510 100644
--- a/source4/torture/rpc/bind.c
+++ b/source4/torture/rpc/bind.c
@@ -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;
}
diff --git a/source4/torture/rpc/countcalls.c b/source4/torture/rpc/countcalls.c
index d42729769a..ac4788f349 100644
--- a/source4/torture/rpc/countcalls.c
+++ b/source4/torture/rpc/countcalls.c
@@ -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;
}
diff --git a/source4/torture/rpc/dcom.c b/source4/torture/rpc/dcom.c
index f8bcf40965..318e9c88ea 100644
--- a/source4/torture/rpc/dcom.c
+++ b/source4/torture/rpc/dcom.c
@@ -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;
}
diff --git a/source4/torture/rpc/dfs.c b/source4/torture/rpc/dfs.c
index 358b94fa72..4e33f921fa 100644
--- a/source4/torture/rpc/dfs.c
+++ b/source4/torture/rpc/dfs.c
@@ -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;
}
diff --git a/source4/torture/rpc/drsuapi.c b/source4/torture/rpc/drsuapi.c
index c4dbe00958..88ff85d8da 100644
--- a/source4/torture/rpc/drsuapi.c
+++ b/source4/torture/rpc/drsuapi.c
@@ -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;
}
diff --git a/source4/torture/rpc/dssetup.c b/source4/torture/rpc/dssetup.c
index bd20a695e2..d4f76fea90 100644
--- a/source4/torture/rpc/dssetup.c
+++ b/source4/torture/rpc/dssetup.c
@@ -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;
}
diff --git a/source4/torture/rpc/echo.c b/source4/torture/rpc/echo.c
index 8ef0b00eb2..34a509a1d4 100644
--- a/source4/torture/rpc/echo.c
+++ b/source4/torture/rpc/echo.c
@@ -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;
}
diff --git a/source4/torture/rpc/epmapper.c b/source4/torture/rpc/epmapper.c
index debcd98756..28877fa1a4 100644
--- a/source4/torture/rpc/epmapper.c
+++ b/source4/torture/rpc/epmapper.c
@@ -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;
}
diff --git a/source4/torture/rpc/eventlog.c b/source4/torture/rpc/eventlog.c
index 7e320200f0..7d3a3bfea9 100644
--- a/source4/torture/rpc/eventlog.c
+++ b/source4/torture/rpc/eventlog.c
@@ -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;
}
diff --git a/source4/torture/rpc/initshutdown.c b/source4/torture/rpc/initshutdown.c
index 0aa64e3eb2..ff1496aea4 100644
--- a/source4/torture/rpc/initshutdown.c
+++ b/source4/torture/rpc/initshutdown.c
@@ -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;
}
diff --git a/source4/torture/rpc/lsa.c b/source4/torture/rpc/lsa.c
index 277a5fc793..f723f68a02 100644
--- a/source4/torture/rpc/lsa.c
+++ b/source4/torture/rpc/lsa.c
@@ -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;
}
diff --git a/source4/torture/rpc/mgmt.c b/source4/torture/rpc/mgmt.c
index cb2023b64c..be9cf649d3 100644
--- a/source4/torture/rpc/mgmt.c
+++ b/source4/torture/rpc/mgmt.c
@@ -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;
diff --git a/source4/torture/rpc/netlogon.c b/source4/torture/rpc/netlogon.c
index 2266659c37..d9ce350428 100644
--- a/source4/torture/rpc/netlogon.c
+++ b/source4/torture/rpc/netlogon.c
@@ -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;
diff --git a/source4/torture/rpc/oxidresolve.c b/source4/torture/rpc/oxidresolve.c
index 2caf3512d5..3b0269891c 100644
--- a/source4/torture/rpc/oxidresolve.c
+++ b/source4/torture/rpc/oxidresolve.c
@@ -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;
}
diff --git a/source4/torture/rpc/remact.c b/source4/torture/rpc/remact.c
index a8dff5f50b..1d145dd1cb 100644
--- a/source4/torture/rpc/remact.c
+++ b/source4/torture/rpc/remact.c
@@ -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;
}
diff --git a/source4/torture/rpc/rot.c b/source4/torture/rpc/rot.c
index d2e3742cf0..ee47fe350e 100644
--- a/source4/torture/rpc/rot.c
+++ b/source4/torture/rpc/rot.c
@@ -24,23 +24,25 @@
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;
}
diff --git a/source4/torture/rpc/samlogon.c b/source4/torture/rpc/samlogon.c
index 1ee8f36b8e..86bfe48a75 100644
--- a/source4/torture/rpc/samlogon.c
+++ b/source4/torture/rpc/samlogon.c
@@ -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);
diff --git a/source4/torture/rpc/samr.c b/source4/torture/rpc/samr.c
index 6b663acdf5..969711858c 100644
--- a/source4/torture/rpc/samr.c
+++ b/source4/torture/rpc/samr.c
@@ -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;
}
diff --git a/source4/torture/rpc/samsync.c b/source4/torture/rpc/samsync.c
index b92752227c..b8214859cd 100644
--- a/source4/torture/rpc/samsync.c
+++ b/source4/torture/rpc/samsync.c
@@ -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);
diff --git a/source4/torture/rpc/scanner.c b/source4/torture/rpc/scanner.c
index 3d78d7a888..d7a5d03271 100644
--- a/source4/torture/rpc/scanner.c
+++ b/source4/torture/rpc/scanner.c
@@ -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;
diff --git a/source4/torture/rpc/schannel.c b/source4/torture/rpc/schannel.c
index f572933bf5..d27285a9cc 100644
--- a/source4/torture/rpc/schannel.c
+++ b/source4/torture/rpc/schannel.c
@@ -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;
}
diff --git a/source4/torture/rpc/spoolss.c b/source4/torture/rpc/spoolss.c
index e5c827afaa..acaa5828dc 100644
--- a/source4/torture/rpc/spoolss.c
+++ b/source4/torture/rpc/spoolss.c
@@ -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;
}
diff --git a/source4/torture/rpc/srvsvc.c b/source4/torture/rpc/srvsvc.c
index 697ae4afe7..c12504e646 100644
--- a/source4/torture/rpc/srvsvc.c
+++ b/source4/torture/rpc/srvsvc.c
@@ -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;
}
diff --git a/source4/torture/rpc/svcctl.c b/source4/torture/rpc/svcctl.c
index 092329ab68..44b79058a9 100644
--- a/source4/torture/rpc/svcctl.c
+++ b/source4/torture/rpc/svcctl.c
@@ -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;
}
diff --git a/source4/torture/rpc/testjoin.c b/source4/torture/rpc/testjoin.c
index 2d96116c0d..5e4c5a32f3 100644
--- a/source4/torture/rpc/testjoin.c
+++ b/source4/torture/rpc/testjoin.c
@@ -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);
}
diff --git a/source4/torture/rpc/winreg.c b/source4/torture/rpc/winreg.c
index df0114b669..c6eada4d79 100644
--- a/source4/torture/rpc/winreg.c
+++ b/source4/torture/rpc/winreg.c
@@ -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;
}
diff --git a/source4/torture/rpc/wkssvc.c b/source4/torture/rpc/wkssvc.c
index f3a3ec233c..47e893ae2e 100644
--- a/source4/torture/rpc/wkssvc.c
+++ b/source4/torture/rpc/wkssvc.c
@@ -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;
}
diff --git a/source4/torture/torture.c b/source4/torture/torture.c
index cdc9efbf7c..4fca36a9ae 100644
--- a/source4/torture/torture.c
+++ b/source4/torture/torture.c
@@ -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 ...");