summaryrefslogtreecommitdiff
path: root/source4/libcli
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2005-10-10 19:57:55 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:39:39 -0500
commitd617556ef50863d6a03c81a04f0f6b05848a250e (patch)
treec5963dd3778e2cb2f6e3b4942649f1d9e3195677 /source4/libcli
parent3dfe8c22b835c34453b23b654cd5649d698da3cb (diff)
downloadsamba-d617556ef50863d6a03c81a04f0f6b05848a250e.tar.gz
samba-d617556ef50863d6a03c81a04f0f6b05848a250e.tar.bz2
samba-d617556ef50863d6a03c81a04f0f6b05848a250e.zip
r10878: Reply to some comments by tridge and metze:
* rename the composite helper functions from comp_* to composite_* * Move the lsa initialization to wb_connect_lsa.c * Equip smb_composite_connect with a fallback_to_anonymous The latter two simplify wb_init_domain.c quite a bit. Volker (This used to be commit deb127e04ea01ae93394da5ebffb39d81caeb6d9)
Diffstat (limited to 'source4/libcli')
-rw-r--r--source4/libcli/composite/composite.c42
-rw-r--r--source4/libcli/raw/clitree.c1
-rw-r--r--source4/libcli/smb_composite/connect.c83
-rw-r--r--source4/libcli/smb_composite/fetchfile.c1
-rw-r--r--source4/libcli/smb_composite/fsinfo.c1
-rw-r--r--source4/libcli/smb_composite/smb_composite.h2
6 files changed, 107 insertions, 23 deletions
diff --git a/source4/libcli/composite/composite.c b/source4/libcli/composite/composite.c
index 6458a971b4..f5eed77300 100644
--- a/source4/libcli/composite/composite.c
+++ b/source4/libcli/composite/composite.c
@@ -75,7 +75,7 @@ void composite_trigger_done(struct composite_context *c)
* functions.
*/
-BOOL comp_is_ok(struct composite_context *ctx)
+BOOL composite_is_ok(struct composite_context *ctx)
{
if (NT_STATUS_IS_OK(ctx->status)) {
return True;
@@ -87,22 +87,22 @@ BOOL comp_is_ok(struct composite_context *ctx)
return False;
}
-void comp_error(struct composite_context *ctx, NTSTATUS status)
+void composite_error(struct composite_context *ctx, NTSTATUS status)
{
ctx->status = status;
- SMB_ASSERT(!comp_is_ok(ctx));
+ SMB_ASSERT(!composite_is_ok(ctx));
}
-BOOL comp_nomem(const void *p, struct composite_context *ctx)
+BOOL composite_nomem(const void *p, struct composite_context *ctx)
{
if (p != NULL) {
return False;
}
- comp_error(ctx, NT_STATUS_NO_MEMORY);
+ composite_error(ctx, NT_STATUS_NO_MEMORY);
return True;
}
-void comp_done(struct composite_context *ctx)
+void composite_done(struct composite_context *ctx)
{
ctx->state = COMPOSITE_STATE_DONE;
if (ctx->async.fn != NULL) {
@@ -110,32 +110,32 @@ void comp_done(struct composite_context *ctx)
}
}
-void comp_cont(struct composite_context *ctx,
- struct composite_context *new_ctx,
- void (*continuation)(struct composite_context *),
- void *private_data)
+void composite_continue(struct composite_context *ctx,
+ struct composite_context *new_ctx,
+ void (*continuation)(struct composite_context *),
+ void *private_data)
{
- if (comp_nomem(new_ctx, ctx)) return;
+ if (composite_nomem(new_ctx, ctx)) return;
new_ctx->async.fn = continuation;
new_ctx->async.private_data = private_data;
}
-void rpc_cont(struct composite_context *ctx,
- struct rpc_request *new_req,
- void (*continuation)(struct rpc_request *),
- void *private_data)
+void composite_continue_rpc(struct composite_context *ctx,
+ struct rpc_request *new_req,
+ void (*continuation)(struct rpc_request *),
+ void *private_data)
{
- if (comp_nomem(new_req, ctx)) return;
+ if (composite_nomem(new_req, ctx)) return;
new_req->async.callback = continuation;
new_req->async.private = private_data;
}
-void irpc_cont(struct composite_context *ctx,
- struct irpc_request *new_req,
- void (*continuation)(struct irpc_request *),
- void *private_data)
+void composite_continue_irpc(struct composite_context *ctx,
+ struct irpc_request *new_req,
+ void (*continuation)(struct irpc_request *),
+ void *private_data)
{
- if (comp_nomem(new_req, ctx)) return;
+ if (composite_nomem(new_req, ctx)) return;
new_req->async.fn = continuation;
new_req->async.private = private_data;
}
diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c
index cae93bdbe2..990552d64f 100644
--- a/source4/libcli/raw/clitree.c
+++ b/source4/libcli/raw/clitree.c
@@ -179,6 +179,7 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx,
io.in.service = service;
io.in.service_type = service_type;
io.in.credentials = credentials;
+ io.in.fallback_to_anonymous = False;
io.in.workgroup = lp_workgroup();
status = smb_composite_connect(&io, parent_ctx, ev);
diff --git a/source4/libcli/smb_composite/connect.c b/source4/libcli/smb_composite/connect.c
index 53cc8a9ac0..925d5ddb38 100644
--- a/source4/libcli/smb_composite/connect.c
+++ b/source4/libcli/smb_composite/connect.c
@@ -30,9 +30,10 @@
/* the stages of this call */
enum connect_stage {CONNECT_RESOLVE,
CONNECT_SOCKET,
- CONNECT_SESSION_REQUEST,
+ CONNECT_SESSION_REQUEST,
CONNECT_NEGPROT,
CONNECT_SESSION_SETUP,
+ CONNECT_SESSION_SETUP_ANON,
CONNECT_TCON};
struct connect_state {
@@ -101,7 +102,59 @@ static NTSTATUS connect_tcon(struct composite_context *c,
/*
- a session setup request has competed
+ a session setup request with anonymous fallback has completed
+*/
+static NTSTATUS connect_session_setup_anon(struct composite_context *c,
+ struct smb_composite_connect *io)
+{
+ struct connect_state *state = talloc_get_type(c->private_data, struct connect_state);
+ NTSTATUS status;
+
+ status = smb_composite_sesssetup_recv(state->creq);
+ NT_STATUS_NOT_OK_RETURN(status);
+
+ io->out.anonymous_fallback_done = True;
+
+ state->session->vuid = state->io_setup->out.vuid;
+
+ /* setup for a tconx */
+ io->out.tree = smbcli_tree_init(state->session, state, True);
+ NT_STATUS_HAVE_NO_MEMORY(io->out.tree);
+
+ state->io_tcon = talloc(c, union smb_tcon);
+ NT_STATUS_HAVE_NO_MEMORY(state->io_tcon);
+
+ /* connect to a share using a tree connect */
+ state->io_tcon->generic.level = RAW_TCON_TCONX;
+ state->io_tcon->tconx.in.flags = 0;
+ state->io_tcon->tconx.in.password = data_blob(NULL, 0);
+
+ state->io_tcon->tconx.in.path = talloc_asprintf(state->io_tcon,
+ "\\\\%s\\%s",
+ io->in.called_name,
+ io->in.service);
+ NT_STATUS_HAVE_NO_MEMORY(state->io_tcon->tconx.in.path);
+ if (!io->in.service_type) {
+ state->io_tcon->tconx.in.device = "?????";
+ } else {
+ state->io_tcon->tconx.in.device = io->in.service_type;
+ }
+
+ state->req = smb_raw_tcon_send(io->out.tree, state->io_tcon);
+ NT_STATUS_HAVE_NO_MEMORY(state->req);
+ if (state->req->state == SMBCLI_REQUEST_ERROR) {
+ return state->req->status;
+ }
+
+ state->req->async.fn = request_handler;
+ state->req->async.private = c;
+ state->stage = CONNECT_TCON;
+
+ return NT_STATUS_OK;
+}
+
+/*
+ a session setup request has completed
*/
static NTSTATUS connect_session_setup(struct composite_context *c,
struct smb_composite_connect *io)
@@ -110,6 +163,29 @@ static NTSTATUS connect_session_setup(struct composite_context *c,
NTSTATUS status;
status = smb_composite_sesssetup_recv(state->creq);
+
+ if (!NT_STATUS_IS_OK(status) &&
+ !cli_credentials_is_anonymous(state->io->in.credentials) &&
+ io->in.fallback_to_anonymous) {
+
+ state->io_setup->in.credentials = cli_credentials_init(state);
+ NT_STATUS_HAVE_NO_MEMORY(state->io_setup->in.credentials);
+ cli_credentials_set_conf(state->io_setup->in.credentials);
+ cli_credentials_set_anonymous(state->io_setup->in.credentials);
+
+ state->creq = smb_composite_sesssetup_send(state->session,
+ state->io_setup);
+ NT_STATUS_HAVE_NO_MEMORY(state->creq);
+ if (state->creq->state == COMPOSITE_STATE_ERROR) {
+ return state->creq->status;
+ }
+ state->creq->async.fn = composite_handler;
+ state->creq->async.private_data = c;
+ state->stage = CONNECT_SESSION_SETUP_ANON;
+
+ return NT_STATUS_OK;
+ }
+
NT_STATUS_NOT_OK_RETURN(status);
state->session->vuid = state->io_setup->out.vuid;
@@ -318,6 +394,9 @@ static void state_handler(struct composite_context *c)
case CONNECT_SESSION_SETUP:
c->status = connect_session_setup(c, state->io);
break;
+ case CONNECT_SESSION_SETUP_ANON:
+ c->status = connect_session_setup_anon(c, state->io);
+ break;
case CONNECT_TCON:
c->status = connect_tcon(c, state->io);
break;
diff --git a/source4/libcli/smb_composite/fetchfile.c b/source4/libcli/smb_composite/fetchfile.c
index 8aa91bf3a9..1891ee956c 100644
--- a/source4/libcli/smb_composite/fetchfile.c
+++ b/source4/libcli/smb_composite/fetchfile.c
@@ -144,6 +144,7 @@ struct composite_context *smb_composite_fetchfile_send(struct smb_composite_fetc
state->connect->in.service = io->in.service;
state->connect->in.service_type = io->in.service_type;
state->connect->in.credentials = io->in.credentials;
+ state->connect->in.fallback_to_anonymous = False;
state->connect->in.workgroup = io->in.workgroup;
state->creq = smb_composite_connect_send(state->connect, state, event_ctx);
diff --git a/source4/libcli/smb_composite/fsinfo.c b/source4/libcli/smb_composite/fsinfo.c
index fa9f18d132..1d3860e5c6 100644
--- a/source4/libcli/smb_composite/fsinfo.c
+++ b/source4/libcli/smb_composite/fsinfo.c
@@ -149,6 +149,7 @@ struct composite_context *smb_composite_fsinfo_send(struct smbcli_tree *tree,
state->connect->in.service = io->in.service;
state->connect->in.service_type = io->in.service_type;
state->connect->in.credentials = io->in.credentials;
+ state->connect->in.fallback_to_anonymous = False;
state->connect->in.workgroup = io->in.workgroup;
c->state = COMPOSITE_STATE_IN_PROGRESS;
diff --git a/source4/libcli/smb_composite/smb_composite.h b/source4/libcli/smb_composite/smb_composite.h
index ec3a7af22d..7ab0127440 100644
--- a/source4/libcli/smb_composite/smb_composite.h
+++ b/source4/libcli/smb_composite/smb_composite.h
@@ -90,10 +90,12 @@ struct smb_composite_connect {
const char *service;
const char *service_type;
struct cli_credentials *credentials;
+ BOOL fallback_to_anonymous;
const char *workgroup;
} in;
struct {
struct smbcli_tree *tree;
+ BOOL anonymous_fallback_done;
} out;
};