mirror of
https://github.com/samba-team/samba.git
synced 2025-11-09 20:23:51 +03:00
GENSEC, and to pull SCHANNEL into GENSEC, by making it less 'special'. GENSEC now no longer has it's own handling of 'set username' etc, instead it uses cli_credentials calls. In order to link the credentails code right though Samba, a lot of interfaces have changed to remove 'username, domain, password' arguments, and these have been replaced with a single 'struct cli_credentials'. In the session setup code, a new parameter 'workgroup' contains the client/server current workgroup, which seems unrelated to the authentication exchange (it was being filled in from the auth info). This allows in particular kerberos to only call back for passwords when it actually needs to perform the kinit. The kerberos code has been modified not to use the SPNEGO provided 'principal name' (in the mechListMIC), but to instead use the name the host was connected to as. This better matches Microsoft behaviour, is more secure and allows better use of standard kerberos functions. To achieve this, I made changes to our socket code so that the hostname (before name resolution) is now recorded on the socket. In schannel, most of the code from librpc/rpc/dcerpc_schannel.c is now in libcli/auth/schannel.c, and it looks much more like a standard GENSEC module. The actual sign/seal code moved to libcli/auth/schannel_sign.c in a previous commit. The schannel credentails structure is now merged with the rest of the credentails, as many of the values (username, workstation, domain) where already present there. This makes handling this in a generic manner much easier, as there is no longer a custom entry-point. The auth_domain module continues to be developed, but is now just as functional as auth_winbind. The changes here are consequential to the schannel changes. The only removed function at this point is the RPC-LOGIN test (simulating the load of a WinXP login), which needs much more work to clean it up (it contains copies of too much code from all over the torture suite, and I havn't been able to penetrate its 'structure'). Andrew Bartlett
231 lines
5.7 KiB
C
231 lines
5.7 KiB
C
/*
|
|
Unix SMB/CIFS implementation.
|
|
|
|
client connect/disconnect routines
|
|
|
|
Copyright (C) Andrew Tridgell 2003-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
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
*/
|
|
|
|
#include "includes.h"
|
|
#include "libcli/raw/libcliraw.h"
|
|
#include "libcli/composite/composite.h"
|
|
|
|
/*
|
|
wrapper around smbcli_sock_connect()
|
|
*/
|
|
BOOL smbcli_socket_connect(struct smbcli_state *cli, const char *server)
|
|
{
|
|
struct smbcli_socket *sock;
|
|
|
|
sock = smbcli_sock_init(cli, NULL);
|
|
if (!sock) return False;
|
|
|
|
if (!smbcli_sock_connect_byname(sock, server, 0)) {
|
|
talloc_free(sock);
|
|
return False;
|
|
}
|
|
|
|
cli->transport = smbcli_transport_init(sock, cli, True);
|
|
if (!cli->transport) {
|
|
return False;
|
|
}
|
|
|
|
return True;
|
|
}
|
|
|
|
/* wrapper around smbcli_transport_connect() */
|
|
BOOL smbcli_transport_establish(struct smbcli_state *cli,
|
|
struct nbt_name *calling,
|
|
struct nbt_name *called)
|
|
{
|
|
return smbcli_transport_connect(cli->transport, calling, called);
|
|
}
|
|
|
|
/* wrapper around smb_raw_negotiate() */
|
|
NTSTATUS smbcli_negprot(struct smbcli_state *cli)
|
|
{
|
|
return smb_raw_negotiate(cli->transport, lp_maxprotocol());
|
|
}
|
|
|
|
/* wrapper around smb_raw_session_setup() */
|
|
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;
|
|
setup.in.workgroup = lp_workgroup();
|
|
|
|
status = smb_composite_sesssetup(cli->session, &setup);
|
|
|
|
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)
|
|
{
|
|
union smb_tcon tcon;
|
|
TALLOC_CTX *mem_ctx;
|
|
NTSTATUS status;
|
|
|
|
cli->tree = smbcli_tree_init(cli->session, cli, True);
|
|
if (!cli->tree) return NT_STATUS_UNSUCCESSFUL;
|
|
|
|
mem_ctx = talloc_init("tcon");
|
|
if (!mem_ctx) {
|
|
return NT_STATUS_NO_MEMORY;
|
|
}
|
|
|
|
/* setup a tree connect */
|
|
tcon.generic.level = RAW_TCON_TCONX;
|
|
tcon.tconx.in.flags = 0;
|
|
if (cli->transport->negotiate.sec_mode & NEGOTIATE_SECURITY_USER_LEVEL) {
|
|
tcon.tconx.in.password = data_blob(NULL, 0);
|
|
} else if (cli->transport->negotiate.sec_mode & NEGOTIATE_SECURITY_CHALLENGE_RESPONSE) {
|
|
tcon.tconx.in.password = data_blob_talloc(mem_ctx, NULL, 24);
|
|
if (cli->transport->negotiate.secblob.length < 8) {
|
|
return NT_STATUS_INVALID_PARAMETER;
|
|
}
|
|
SMBencrypt(password, cli->transport->negotiate.secblob.data, tcon.tconx.in.password.data);
|
|
} else {
|
|
tcon.tconx.in.password = data_blob_talloc(mem_ctx, password, strlen(password)+1);
|
|
}
|
|
tcon.tconx.in.path = sharename;
|
|
tcon.tconx.in.device = devtype;
|
|
|
|
status = smb_tree_connect(cli->tree, mem_ctx, &tcon);
|
|
|
|
cli->tree->tid = tcon.tconx.out.tid;
|
|
|
|
talloc_free(mem_ctx);
|
|
|
|
return status;
|
|
}
|
|
|
|
|
|
/*
|
|
easy way to get to a fully connected smbcli_state in one call
|
|
*/
|
|
NTSTATUS smbcli_full_connection(TALLOC_CTX *parent_ctx,
|
|
struct smbcli_state **ret_cli,
|
|
const char *host,
|
|
const char *sharename,
|
|
const char *devtype,
|
|
struct cli_credentials *credentials)
|
|
{
|
|
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);
|
|
if (!NT_STATUS_IS_OK(status)) {
|
|
goto done;
|
|
}
|
|
|
|
(*ret_cli) = smbcli_state_init(parent_ctx);
|
|
|
|
(*ret_cli)->tree = tree;
|
|
(*ret_cli)->session = tree->session;
|
|
(*ret_cli)->transport = tree->session->transport;
|
|
|
|
done:
|
|
talloc_free(mem_ctx);
|
|
|
|
return status;
|
|
}
|
|
|
|
|
|
/*
|
|
disconnect the tree
|
|
*/
|
|
NTSTATUS smbcli_tdis(struct smbcli_state *cli)
|
|
{
|
|
return smb_tree_disconnect(cli->tree);
|
|
}
|
|
|
|
/****************************************************************************
|
|
Initialise a client state structure.
|
|
****************************************************************************/
|
|
struct smbcli_state *smbcli_state_init(TALLOC_CTX *mem_ctx)
|
|
{
|
|
struct smbcli_state *cli;
|
|
|
|
cli = talloc_zero(mem_ctx, struct smbcli_state);
|
|
if (cli) {
|
|
ZERO_STRUCTP(cli);
|
|
}
|
|
|
|
return cli;
|
|
}
|
|
|
|
/****************************************************************************
|
|
Shutdown a client structure.
|
|
****************************************************************************/
|
|
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;
|
|
}
|
|
|
|
|
|
|