client connect/disconnect routines
Copyright (C) Andrew Tridgell 2003-2005
+ Copyright (C) James Peach 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 "libcli/libcli.h"
#include "libcli/raw/libcliraw.h"
-#include "libcli/composite/composite.h"
+#include "libcli/auth/proto.h"
+#include "libcli/smb_composite/smb_composite.h"
/*
wrapper around smbcli_sock_connect()
{
struct smbcli_socket *sock;
- sock = smbcli_sock_init(cli, NULL);
- if (!sock) return False;
+ sock = smbcli_sock_connect_byname(server, 0, NULL, NULL);
- if (!smbcli_sock_connect_byname(sock, server, 0)) {
- talloc_free(sock);
- return False;
- }
+ if (sock == NULL) return False;
cli->transport = smbcli_transport_init(sock, cli, True);
if (!cli->transport) {
return smb_raw_negotiate(cli->transport, lp_maxprotocol());
}
-/* wrapper around smb_raw_session_setup() */
+/* wrapper around smb_raw_sesssetup() */
NTSTATUS smbcli_session_setup(struct smbcli_state *cli,
struct cli_credentials *credentials)
{
struct smb_composite_sesssetup setup;
NTSTATUS status;
- TALLOC_CTX *mem_ctx;
cli->session = smbcli_session_init(cli->transport, cli, True);
if (!cli->session) return NT_STATUS_UNSUCCESSFUL;
- mem_ctx = talloc_init("smbcli_session_setup");
- if (!mem_ctx) return NT_STATUS_NO_MEMORY;
-
setup.in.sesskey = cli->transport->negotiate.sesskey;
setup.in.capabilities = cli->transport->negotiate.capabilities;
setup.in.credentials = credentials;
cli->session->vuid = setup.out.vuid;
- talloc_free(mem_ctx);
-
return status;
}
-/* wrapper around smb_tree_connect() */
-NTSTATUS smbcli_send_tconX(struct smbcli_state *cli, const char *sharename,
- const char *devtype, const char *password)
+/* wrapper around smb_raw_tcon() */
+NTSTATUS smbcli_tconX(struct smbcli_state *cli, const char *sharename,
+ const char *devtype, const char *password)
{
union smb_tcon tcon;
TALLOC_CTX *mem_ctx;
tcon.tconx.in.path = sharename;
tcon.tconx.in.device = devtype;
- status = smb_tree_connect(cli->tree, mem_ctx, &tcon);
+ status = smb_raw_tcon(cli->tree, mem_ctx, &tcon);
cli->tree->tid = tcon.tconx.out.tid;
const char *host,
const char *sharename,
const char *devtype,
- struct cli_credentials *credentials)
+ struct cli_credentials *credentials,
+ struct event_context *ev)
{
struct smbcli_tree *tree;
NTSTATUS status;
- TALLOC_CTX *mem_ctx;
-
- mem_ctx = talloc_init("smbcli_full_connection");
*ret_cli = NULL;
status = smbcli_tree_full_connection(parent_ctx,
&tree, host, 0, sharename, devtype,
- credentials);
+ credentials, ev);
if (!NT_STATUS_IS_OK(status)) {
goto done;
}
(*ret_cli)->tree = tree;
(*ret_cli)->session = tree->session;
(*ret_cli)->transport = tree->session->transport;
+
+ talloc_steal(*ret_cli, tree);
done:
- talloc_free(mem_ctx);
-
return status;
}
****************************************************************************/
struct smbcli_state *smbcli_state_init(TALLOC_CTX *mem_ctx)
{
- struct smbcli_state *cli;
+ return talloc_zero(mem_ctx, struct smbcli_state);
+}
+
+/* Insert a NULL at the first separator of the given path and return a pointer
+ * to the remainder of the string.
+ */
+static char *
+terminate_path_at_separator(char * path)
+{
+ char * p;
- cli = talloc_zero(mem_ctx, struct smbcli_state);
- if (cli) {
- ZERO_STRUCTP(cli);
+ if (!path) {
+ return NULL;
}
- return cli;
-}
+ if ((p = strchr_m(path, '/'))) {
+ *p = '\0';
+ return p + 1;
+ }
-/****************************************************************************
- Shutdown a client structure.
-****************************************************************************/
-void smbcli_shutdown(struct smbcli_state *cli)
-{
- talloc_free(cli);
+ if ((p = strchr_m(path, '\\'))) {
+ *p = '\0';
+ return p + 1;
+ }
+
+ /* No separator. */
+ return NULL;
}
/*
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 **hostname, char **sharename)
{
char *p;
+ *hostname = *sharename = NULL;
+
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 = terminate_path_at_separator(*hostname);
+
+ if (p && *p) {
+ *sharename = talloc_strdup(mem_ctx, p);
+ terminate_path_at_separator(*sharename);
}
- *p = 0;
- *sharename = talloc_strdup(mem_ctx, p+1);
- return True;
+ if (*hostname && *sharename) {
+ return True;
+ }
+
+ talloc_free(*hostname);
+ talloc_free(*sharename);
+ *hostname = *sharename = NULL;
+ return False;
}