summaryrefslogtreecommitdiff
path: root/source4/libcli
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-01-15 11:58:52 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:08:50 -0500
commit61a3d370b98ca4b75cd61e22f0d6b0f3fb7561b3 (patch)
tree64923e274b14c4b238e341b2c5a54b536c80e88e /source4/libcli
parente89fd49df7e63dcf37ee1aa7e2f50965851725c9 (diff)
downloadsamba-61a3d370b98ca4b75cd61e22f0d6b0f3fb7561b3.tar.gz
samba-61a3d370b98ca4b75cd61e22f0d6b0f3fb7561b3.tar.bz2
samba-61a3d370b98ca4b75cd61e22f0d6b0f3fb7561b3.zip
r4758: - added async support to the session request code
- added async support to the negprot client code - removed two unused parameters from smbcli_full_connection() code - converted smbclient to use smbcli_full_connection() rather than reinventing everything itself (This used to be commit 71cbe2873473e039b4511511302cb63f1c50bce8)
Diffstat (limited to 'source4/libcli')
-rw-r--r--source4/libcli/cliconnect.c35
-rw-r--r--source4/libcli/raw/clisession.c4
-rw-r--r--source4/libcli/raw/clitransport.c61
-rw-r--r--source4/libcli/raw/clitree.c14
-rw-r--r--source4/libcli/raw/rawnegotiate.c36
5 files changed, 105 insertions, 45 deletions
diff --git a/source4/libcli/cliconnect.c b/source4/libcli/cliconnect.c
index a0ba5ae0a1..4d46d1d23c 100644
--- a/source4/libcli/cliconnect.c
+++ b/source4/libcli/cliconnect.c
@@ -57,7 +57,7 @@ BOOL smbcli_transport_establish(struct smbcli_state *cli,
/* wrapper around smb_raw_negotiate() */
NTSTATUS smbcli_negprot(struct smbcli_state *cli)
{
- return smb_raw_negotiate(cli->transport);
+ return smb_raw_negotiate(cli->transport, lp_maxprotocol());
}
/* wrapper around smb_raw_session_setup() */
@@ -155,14 +155,11 @@ NTSTATUS smbcli_full_connection(TALLOC_CTX *parent_ctx,
struct smbcli_state **ret_cli,
const char *myname,
const char *host,
- struct ipv4_addr *ip,
const char *sharename,
const char *devtype,
const char *username,
const char *domain,
- const char *password,
- uint_t flags,
- BOOL *retry)
+ const char *password)
{
struct smbcli_tree *tree;
NTSTATUS status;
@@ -231,3 +228,31 @@ void smbcli_shutdown(struct smbcli_state *cli)
{
talloc_free(cli);
}
+
+/*
+ parse a //server/share type UNC name
+*/
+BOOL smbcli_parse_unc(const char *unc_name, TALLOC_CTX *mem_ctx,
+ const char **hostname, const char **sharename)
+{
+ char *p;
+
+ if (strncmp(unc_name, "\\\\", 2) &&
+ strncmp(unc_name, "//", 2)) {
+ return False;
+ }
+
+ *hostname = talloc_strdup(mem_ctx, &unc_name[2]);
+ p = strchr_m(&(*hostname)[2],'/');
+ if (!p) {
+ p = strchr_m(&(*hostname)[2],'\\');
+ if (!p) return False;
+ }
+ *p = 0;
+ *sharename = talloc_strdup(mem_ctx, p+1);
+
+ return True;
+}
+
+
+
diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c
index dcc0c8adbe..322d27688e 100644
--- a/source4/libcli/raw/clisession.c
+++ b/source4/libcli/raw/clisession.c
@@ -38,16 +38,14 @@ struct smbcli_session *smbcli_session_init(struct smbcli_transport *transport)
uint16_t flags2;
uint32_t capabilities;
- session = talloc_p(transport, struct smbcli_session);
+ session = talloc_zero(transport, struct smbcli_session);
if (!session) {
return NULL;
}
- ZERO_STRUCTP(session);
session->transport = talloc_reference(session, transport);
session->pid = (uint16_t)getpid();
session->vuid = UID_FIELD_INVALID;
-
capabilities = transport->negotiate.capabilities;
diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c
index 855543d670..fc9de577ee 100644
--- a/source4/libcli/raw/clitransport.c
+++ b/source4/libcli/raw/clitransport.c
@@ -140,12 +140,12 @@ static void smbcli_transport_write_disable(struct smbcli_transport *transport)
transport->socket->event.fde->flags &= ~EVENT_FD_WRITE;
}
-/****************************************************************************
-send a session request (if appropriate)
-****************************************************************************/
-BOOL smbcli_transport_connect(struct smbcli_transport *transport,
- struct nmb_name *calling,
- struct nmb_name *called)
+/*
+ send a session request
+*/
+struct smbcli_request *smbcli_transport_connect_send(struct smbcli_transport *transport,
+ struct nmb_name *calling,
+ struct nmb_name *called)
{
uint8_t *p;
int len = NBT_HDR_SIZE;
@@ -155,13 +155,10 @@ BOOL smbcli_transport_connect(struct smbcli_transport *transport,
transport->called = *called;
}
- /* 445 doesn't have session request */
- if (transport->socket->port == 445) {
- return True;
- }
-
/* allocate output buffer */
- req = smbcli_request_setup_nonsmb(transport, NBT_HDR_SIZE + 2*nbt_mangled_name_len());
+ req = smbcli_request_setup_nonsmb(transport,
+ NBT_HDR_SIZE + 2*nbt_mangled_name_len());
+ if (req == NULL) return NULL;
/* put in the destination name */
p = req->out.buffer + NBT_HDR_SIZE;
@@ -176,15 +173,27 @@ BOOL smbcli_transport_connect(struct smbcli_transport *transport,
_smb_setlen(req->out.buffer,len-4);
SCVAL(req->out.buffer,0,0x81);
- if (!smbcli_request_send(req) ||
- !smbcli_request_receive(req)) {
+ if (!smbcli_request_send(req)) {
+ smbcli_request_destroy(req);
+ return NULL;
+ }
+
+ return req;
+}
+
+/*
+ finish a smbcli_transport_connect()
+*/
+BOOL smbcli_transport_connect_recv(struct smbcli_request *req)
+{
+ if (!smbcli_request_receive(req)) {
smbcli_request_destroy(req);
return False;
}
-
+
if (CVAL(req->in.buffer,0) != 0x82) {
- transport->error.etype = ETYPE_NBT;
- transport->error.e.nbt_error = CVAL(req->in.buffer,4);
+ req->transport->error.etype = ETYPE_NBT;
+ req->transport->error.e.nbt_error = CVAL(req->in.buffer,4);
smbcli_request_destroy(req);
return False;
}
@@ -194,6 +203,24 @@ BOOL smbcli_transport_connect(struct smbcli_transport *transport,
}
+/*
+ send a session request (if needed)
+*/
+BOOL smbcli_transport_connect(struct smbcli_transport *transport,
+ struct nmb_name *calling,
+ struct nmb_name *called)
+{
+ struct smbcli_request *req;
+
+ if (transport->socket->port == 445) {
+ return True;
+ }
+
+ req = smbcli_transport_connect_send(transport,
+ calling, called);
+ return smbcli_transport_connect_recv(req);
+}
+
/****************************************************************************
get next mid in sequence
****************************************************************************/
diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c
index 0f56c0fe2e..cc7fefd084 100644
--- a/source4/libcli/raw/clitree.c
+++ b/source4/libcli/raw/clitree.c
@@ -34,12 +34,11 @@ struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session)
{
struct smbcli_tree *tree;
- tree = talloc_p(session, struct smbcli_tree);
+ tree = talloc_zero(session, struct smbcli_tree);
if (!tree) {
return NULL;
}
- ZERO_STRUCTP(tree);
tree->session = talloc_reference(tree, session);
return tree;
@@ -48,7 +47,8 @@ struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session)
/****************************************************************************
Send a tconX (async send)
****************************************************************************/
-struct smbcli_request *smb_tree_connect_send(struct smbcli_tree *tree, union smb_tcon *parms)
+struct smbcli_request *smb_tree_connect_send(struct smbcli_tree *tree,
+ union smb_tcon *parms)
{
struct smbcli_request *req = NULL;
@@ -83,7 +83,8 @@ struct smbcli_request *smb_tree_connect_send(struct smbcli_tree *tree, union smb
/****************************************************************************
Send a tconX (async recv)
****************************************************************************/
-NTSTATUS smb_tree_connect_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_tcon *parms)
+NTSTATUS smb_tree_connect_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx,
+ union smb_tcon *parms)
{
uint8_t *p;
@@ -124,7 +125,8 @@ failed:
/****************************************************************************
Send a tconX (sync interface)
****************************************************************************/
-NTSTATUS smb_tree_connect(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_tcon *parms)
+NTSTATUS smb_tree_connect(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx,
+ union smb_tcon *parms)
{
struct smbcli_request *req = smb_tree_connect_send(tree, parms);
return smb_tree_connect_recv(req, mem_ctx, parms);
@@ -203,7 +205,7 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx,
/* negotiate protocol options with the server */
- status = smb_raw_negotiate(transport);
+ status = smb_raw_negotiate(transport, lp_maxprotocol());
if (!NT_STATUS_IS_OK(status)) {
talloc_free(transport);
return status;
diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c
index a8cf603d46..d2d6b66d59 100644
--- a/source4/libcli/raw/rawnegotiate.c
+++ b/source4/libcli/raw/rawnegotiate.c
@@ -1,7 +1,9 @@
/*
Unix SMB/CIFS implementation.
+
SMB client negotiate context management functions
- Copyright (C) Andrew Tridgell 1994-1998
+
+ Copyright (C) Andrew Tridgell 1994-2005
Copyright (C) James Myers 2003 <myersjj@samba.org>
This program is free software; you can redistribute it and/or modify
@@ -40,10 +42,11 @@ static const struct {
{PROTOCOL_NT1,"NT LM 0.12"},
};
-/****************************************************************************
- Send a negprot command.
-****************************************************************************/
-struct smbcli_request *smb_negprot_send(struct smbcli_transport *transport, int maxprotocol)
+/*
+ Send a negprot command.
+*/
+struct smbcli_request *smb_raw_negotiate_send(struct smbcli_transport *transport,
+ int maxprotocol)
{
struct smbcli_request *req;
int i;
@@ -82,19 +85,14 @@ struct smbcli_request *smb_negprot_send(struct smbcli_transport *transport, int
return req;
}
-/****************************************************************************
+/*
Send a negprot command.
-****************************************************************************/
-NTSTATUS smb_raw_negotiate(struct smbcli_transport *transport)
+*/
+NTSTATUS smb_raw_negotiate_recv(struct smbcli_request *req)
{
- struct smbcli_request *req;
+ struct smbcli_transport *transport = req->transport;
int protocol;
- req = smb_negprot_send(transport, lp_maxprotocol());
- if (!req) {
- return NT_STATUS_UNSUCCESSFUL;
- }
-
if (!smbcli_request_receive(req) ||
smbcli_request_is_error(req)) {
return smbcli_request_destroy(req);
@@ -183,3 +181,13 @@ NTSTATUS smb_raw_negotiate(struct smbcli_transport *transport)
failed:
return smbcli_request_destroy(req);
}
+
+
+/*
+ Send a negprot command (sync interface)
+*/
+NTSTATUS smb_raw_negotiate(struct smbcli_transport *transport, int maxprotocol)
+{
+ struct smbcli_request *req = smb_raw_negotiate_send(transport, maxprotocol);
+ return smb_raw_negotiate_recv(req);
+}