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);
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;
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);
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);
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,
}
gtk_widget_destroy(GTK_WIDGET(d));
+ at_pipe = talloc_reference(talloc_autofree_context(), at_pipe);
talloc_free(mem_ctx);
update_joblist();
}
on_quit_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
- if(at_pipe)dcerpc_pipe_close(at_pipe);
+ talloc_free(at_pipe);
gtk_main_quit();
}
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)
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);
}
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();
}
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);
}
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 */
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);
/* 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);
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);
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++;
Copyright (C) Jelmer Vernooij 2005
Copyright (C) Tim Potter 2001
+ Copyright (C) Andrew Bartlett <abartlet@samba.org> 2005
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include "includes.h"
#include "system/filesys.h"
-const char *cli_credentials_get_username(struct cli_credentials *cred)
+/* Create a new credentials structure, on the specified TALLOC_CTX */
+struct cli_credentials *cli_credentials_init(TALLOC_CTX *mem_ctx)
{
- if (cred == NULL) {
- return NULL;
- }
+ return talloc_zero(mem_ctx, struct cli_credentials);
+}
+const char *cli_credentials_get_username(struct cli_credentials *cred)
+{
if (cred->username_obtained == CRED_CALLBACK) {
cred->username = cred->username_cb(cred);
cred->username_obtained = CRED_SPECIFIED;
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;
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;
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)
}
}
+/* 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;
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)
{
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);
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;
}
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 {
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;
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)) {
disconnect:
/* close connection */
- dcerpc_pipe_close(c.pdc.out.dcerpc_pipe);
+ talloc_free(c.pdc.out.dcerpc_pipe);
return status;
}
#endif
disconnect:
/* close connection */
- dcerpc_pipe_close(c.pdc.out.dcerpc_pipe);
+ talloc_free(c.pdc.out.dcerpc_pipe);
return status;
}
disconnect:
/* close connection */
- dcerpc_pipe_close(c.pdc.out.dcerpc_pipe);
+ talloc_free(c.pdc.out.dcerpc_pipe);
return status;
}
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,
disconnect:
/* close connection */
- dcerpc_pipe_close(c.standard.out.dcerpc_pipe);
+ talloc_free(c.standard.out.dcerpc_pipe);
return status;
}
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)
/*
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)
{
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;
workgroup = cli_credentials_get_domain(credentials);
- tmp_ctx = talloc_new(NULL);
-
/*
step 1 - establish a netlogon connection, with no authentication
*/
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;
}
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)) {
/*
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;
}
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;
}
we no longer need the netlogon pipe open
*/
- dcerpc_pipe_close(p2);
+ talloc_free(p2);
return NT_STATUS_OK;
}
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;
}
chan_type = SEC_CHAN_DOMAIN;
}
- status = dcerpc_schannel_key(p, credentials,
+ status = dcerpc_schannel_key(tmp_ctx,
+ p, credentials,
chan_type,
creds);
}
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 |
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) {
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;
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;
}
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 */
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;
}
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);
}
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) {
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));
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;
}
/* 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",
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,
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));
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;
}
/* 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;
}
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;
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"));
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;
}
{
struct dcesrv_remote_private *private = context->private;
- dcerpc_pipe_close(private->c_pipe);
+ talloc_free(private->c_pipe);
return;
}
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;
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);
}
IUnknown_Release((struct IUnknown *)interfaces[1], mem_ctx);
- torture_rpc_close(p);
-
return True;
}
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);
}
done:
talloc_free(mem_ctx);
- torture_rpc_close(p);
return ret;
}
#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.";
status = smbcli_full_connection(NULL, &c, "masktest",
server,
share, NULL,
- &credentials);
+ credentials);
if (!NT_STATUS_IS_OK(status)) {
return NULL;
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);
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);
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;
}
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;
}
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;
}
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;
}
talloc_free(mem_ctx);
- torture_rpc_close(p);
-
return ret;
}
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;
}
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);
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++) {
#endif
}
if (p->last_fault_code == 5) {
- reopen(&p, iface);
+ reopen(mem_ctx, &p, iface);
}
}
- dcerpc_pipe_close(p);
+ talloc_free(p);
}
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);
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);
SIVAL(stub_in.data, ofs, 0);
}
- dcerpc_pipe_close(p);
+ talloc_free(p);
}
struct dcerpc_pipe *p = NULL;
struct policy_handle handle;
- reopen(&p, iface);
+ reopen(mem_ctx, &p, iface);
get_policy_handle(p, mem_ctx, &handle);
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;
}
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;
}
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;
}
}
printf("opnum %d minimum not found!?\n", opnum);
- dcerpc_pipe_close(p);
+ talloc_free(p);
}
test_auto_scan(mem_ctx, iface);
+ talloc_free(mem_ctx);
return True;
}
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;
}
}
talloc_free(mem_ctx);
- torture_rpc_close(p);
return ret;
}
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));
}
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;
}
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;
}
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);
talloc_free(mem_ctx);
- torture_rpc_close(p);
-
return ret;
}
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);
talloc_free(mem_ctx);
- torture_rpc_close(p);
-
return ret;
}
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;
}
talloc_free(mem_ctx);
- torture_rpc_close(p);
-
return ret;
}
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);
talloc_free(mem_ctx);
- torture_rpc_close(p);
return ret;
}
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;
}
talloc_free(mem_ctx);
- torture_rpc_close(p);
-
return ret;
}
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;
}
talloc_free(mem_ctx);
- torture_rpc_close(p);
-
return ret;
}
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;
}
talloc_free(mem_ctx);
- torture_rpc_close(p);
-
return ret;
}
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;
}
talloc_free(mem_ctx);
- torture_rpc_close(p);
-
return ret;
}
{
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;
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;
}
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;
#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;
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");
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");
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;
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;
return False;
}
- dcerpc_pipe_close(p2);
+ talloc_free(p2);
d.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s",
dcerpc_server_name(p));
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;
}
talloc_free(mem_ctx);
- torture_rpc_close(p);
-
torture_leave_domain(join_ctx);
return ret;
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;
}
talloc_free(mem_ctx);
- torture_rpc_close(p);
-
return ret;
}
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;
}
talloc_free(mem_ctx);
- torture_rpc_close(p);
-
return ret;
}
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;
}
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};
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;
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];
}
SAFE_FREE(error_string);
}
+ talloc_free(tmp_ctx);
}
}
}
}
-
+ talloc_free(fn_ctx);
return ret;
}
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;
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;
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;
}
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;
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
},
"%s@%s",
cli_credentials_get_username(cmdline_credentials),
cli_credentials_get_realm(cmdline_credentials)
- ),
+ ),
cli_credentials_get_password(cmdline_credentials),
True
},
#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
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;
}
failed:
talloc_free(mem_ctx);
- torture_rpc_close(p);
-
torture_leave_domain(join_ctx);
#if 0
torture_leave_domain(user_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;
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;
}
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));
}
}
- 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;
}
};
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;
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)) {
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));
}
}
- 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;
}
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;
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;
}
talloc_free(mem_ctx);
- torture_rpc_close(p);
-
return ret;
}
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",
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);
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;
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;
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));
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));
}
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;
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,
/* 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,
}
}
}
+ talloc_free(trustdom_ctx);
return ret;
}
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;
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)) {
}
r.in.sequence_num++;
+ talloc_free(loop_ctx);
} while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES));
}
struct creds_CredentialState *creds)
{
NTSTATUS status;
+ TALLOC_CTX *loop_ctx;
struct netr_DatabaseSync2 r;
const uint32_t database_ids[] = {0, 1, 2};
int i;
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)) {
}
r.in.sync_context = r.out.sync_context;
+ talloc_free(loop_ctx);
} while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES));
}
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;
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;
}
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;
}
lp_workgroup(),
ACB_NORMAL, NULL);
if (!user_ctx) {
+ talloc_free(mem_ctx);
printf("Failed to create test account\n");
return False;
}
}
- 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);
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;
}
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));
}
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;
ret = False;
}
failed:
- torture_rpc_close(samsync_state->p);
torture_leave_domain(join_ctx);
torture_leave_domain(join_ctx2);
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",
}
done:
- torture_rpc_close(p);
+ talloc_free(p);
return True;
}
{
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");
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;
}
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;
}
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;
}
if (!test_inq_if_ids(p, mem_ctx, l->table)) {
ret = False;
}
-
- torture_rpc_close(p);
}
return ret;
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;
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;
}
* 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;
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;
}
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;
}
ret = False;
}
- dcerpc_pipe_close(p2);
+ talloc_free(p2);
return ret;
}
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);
talloc_free(mem_ctx);
- torture_rpc_close(p);
-
return ret;
}
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;
}
talloc_free(mem_ctx);
- torture_rpc_close(p);
-
return ret;
}
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;
}
talloc_free(mem_ctx);
- torture_rpc_close(p);
-
return ret;
}
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);
}
}
- if (join->p) {
- torture_rpc_close(join->p);
- }
-
talloc_free(join);
}
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,
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;
}
talloc_free(mem_ctx);
- torture_rpc_close(p);
-
return ret;
}
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;
}
talloc_free(mem_ctx);
- torture_rpc_close(p);
-
return ret;
}
}
/* 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)
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,
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;
}
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)
#endif
pc = poptGetContext("smbtorture", argc, (const char **) argv, long_options,
- POPT_CONTEXT_KEEP_FIRST);
+ POPT_CONTEXT_KEEP_FIRST);
poptSetOtherOptionHelp(pc, "<binding>|<unc> TEST1 TEST2 ...");