summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2005-03-22 08:00:45 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:11:11 -0500
commit645711c602313940dcf80ec786557920ecfbf884 (patch)
tree77c5f5c5f1285677eaaf7a3fa62bf0b2540e153f /source4/lib
parent376b03ebd895b221b70058ee18bea50587388182 (diff)
downloadsamba-645711c602313940dcf80ec786557920ecfbf884.tar.gz
samba-645711c602313940dcf80ec786557920ecfbf884.tar.bz2
samba-645711c602313940dcf80ec786557920ecfbf884.zip
r5941: Commit this patch much earlier than I would normally prefer, but metze needs a working tree...
The main volume of this patch was what I started working on today: - Cleans up memory handling around DCE/RPC pipes, to have a parent talloc context. - Uses sepereate inner loops for some of the DCE/RPC tests The other and more important part of this patch fixes issues surrounding the new credentials framwork: This makes the struct cli_credentials always a talloc() structure, rather than on the stack. Parts of the cli_credentials code already assumed this. There were other issues, particularly in the DCERPC over SMB handling, as well as little things that had to be tidied up before test_w2k3.sh would start to pass. Andrew Bartlett (This used to be commit 0453f9d05d2e336fba1f85dbf2718d01fa2bf778)
Diffstat (limited to 'source4/lib')
-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
4 files changed, 34 insertions, 42 deletions
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;
}