mirror of
https://github.com/samba-team/samba.git
synced 2025-12-04 08:23:50 +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
187 lines
5.1 KiB
C
187 lines
5.1 KiB
C
/*
|
|
Unix SMB/CIFS implementation.
|
|
|
|
Copyright (C) Volker Lendecke 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.
|
|
*/
|
|
/*
|
|
a composite API for loading a whole file into memory
|
|
*/
|
|
|
|
#include "includes.h"
|
|
#include "libcli/raw/libcliraw.h"
|
|
#include "libcli/composite/composite.h"
|
|
|
|
enum fetchfile_stage {FETCHFILE_CONNECT,
|
|
FETCHFILE_READ};
|
|
|
|
struct fetchfile_state {
|
|
enum fetchfile_stage stage;
|
|
struct smb_composite_fetchfile *io;
|
|
struct composite_context *req;
|
|
struct smb_composite_connect *connect;
|
|
struct smb_composite_loadfile *loadfile;
|
|
};
|
|
|
|
static void fetchfile_composite_handler(struct composite_context *req);
|
|
|
|
static NTSTATUS fetchfile_connect(struct composite_context *c,
|
|
struct smb_composite_fetchfile *io)
|
|
{
|
|
NTSTATUS status;
|
|
struct fetchfile_state *state;
|
|
state = talloc_get_type(c->private, struct fetchfile_state);
|
|
|
|
status = smb_composite_connect_recv(state->req, c);
|
|
NT_STATUS_NOT_OK_RETURN(status);
|
|
|
|
state->loadfile = talloc(state, struct smb_composite_loadfile);
|
|
NT_STATUS_HAVE_NO_MEMORY(state->loadfile);
|
|
|
|
state->loadfile->in.fname = io->in.filename;
|
|
|
|
state->req = smb_composite_loadfile_send(state->connect->out.tree,
|
|
state->loadfile);
|
|
NT_STATUS_HAVE_NO_MEMORY(state->req);
|
|
|
|
state->req->async.private = c;
|
|
state->req->async.fn = fetchfile_composite_handler;
|
|
|
|
state->stage = FETCHFILE_READ;
|
|
c->event_ctx = talloc_reference(c, state->req->event_ctx);
|
|
|
|
return NT_STATUS_OK;
|
|
}
|
|
|
|
static NTSTATUS fetchfile_read(struct composite_context *c,
|
|
struct smb_composite_fetchfile *io)
|
|
{
|
|
NTSTATUS status;
|
|
struct fetchfile_state *state;
|
|
state = talloc_get_type(c->private, struct fetchfile_state);
|
|
|
|
status = smb_composite_loadfile_recv(state->req, NULL);
|
|
NT_STATUS_NOT_OK_RETURN(status);
|
|
|
|
io->out.data = state->loadfile->out.data;
|
|
io->out.size = state->loadfile->out.size;
|
|
|
|
c->state = SMBCLI_REQUEST_DONE;
|
|
if (c->async.fn)
|
|
c->async.fn(c);
|
|
|
|
return NT_STATUS_OK;
|
|
}
|
|
|
|
static void fetchfile_state_handler(struct composite_context *c)
|
|
{
|
|
struct fetchfile_state *state;
|
|
NTSTATUS status;
|
|
|
|
state = talloc_get_type(c->private, struct fetchfile_state);
|
|
|
|
/* when this handler is called, the stage indicates what
|
|
call has just finished */
|
|
switch (state->stage) {
|
|
case FETCHFILE_CONNECT:
|
|
status = fetchfile_connect(c, state->io);
|
|
break;
|
|
case FETCHFILE_READ:
|
|
status = fetchfile_read(c, state->io);
|
|
break;
|
|
}
|
|
|
|
if (!NT_STATUS_IS_OK(status)) {
|
|
c->status = status;
|
|
c->state = SMBCLI_REQUEST_ERROR;
|
|
if (c->async.fn) {
|
|
c->async.fn(c);
|
|
}
|
|
}
|
|
}
|
|
|
|
static void fetchfile_composite_handler(struct composite_context *req)
|
|
{
|
|
struct composite_context *c = talloc_get_type(req->async.private,
|
|
struct composite_context);
|
|
return fetchfile_state_handler(c);
|
|
}
|
|
|
|
struct composite_context *smb_composite_fetchfile_send(struct smb_composite_fetchfile *io,
|
|
struct event_context *event_ctx)
|
|
{
|
|
struct composite_context *c;
|
|
struct fetchfile_state *state;
|
|
|
|
c = talloc_zero(NULL, struct composite_context);
|
|
if (c == NULL) goto failed;
|
|
|
|
state = talloc(c, struct fetchfile_state);
|
|
if (state == NULL) goto failed;
|
|
|
|
state->connect = talloc(state, struct smb_composite_connect);
|
|
if (state->connect == NULL) goto failed;
|
|
|
|
state->io = io;
|
|
|
|
state->connect->in.dest_host = io->in.dest_host;
|
|
state->connect->in.port = io->in.port;
|
|
state->connect->in.called_name = io->in.called_name;
|
|
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.workgroup = io->in.workgroup;
|
|
|
|
state->req = smb_composite_connect_send(state->connect, event_ctx);
|
|
if (state->req == NULL) goto failed;
|
|
|
|
state->req->async.private = c;
|
|
state->req->async.fn = fetchfile_composite_handler;
|
|
|
|
c->state = SMBCLI_REQUEST_SEND;
|
|
state->stage = FETCHFILE_CONNECT;
|
|
c->event_ctx = talloc_reference(c, state->req->event_ctx);
|
|
c->private = state;
|
|
|
|
return c;
|
|
failed:
|
|
talloc_free(c);
|
|
return NULL;
|
|
}
|
|
|
|
NTSTATUS smb_composite_fetchfile_recv(struct composite_context *c,
|
|
TALLOC_CTX *mem_ctx)
|
|
{
|
|
NTSTATUS status;
|
|
|
|
status = composite_wait(c);
|
|
|
|
if (NT_STATUS_IS_OK(status)) {
|
|
struct fetchfile_state *state = talloc_get_type(c->private, struct fetchfile_state);
|
|
talloc_steal(mem_ctx, state->io->out.data);
|
|
}
|
|
|
|
talloc_free(c);
|
|
return status;
|
|
}
|
|
|
|
NTSTATUS smb_composite_fetchfile(struct smb_composite_fetchfile *io,
|
|
TALLOC_CTX *mem_ctx)
|
|
{
|
|
struct composite_context *c = smb_composite_fetchfile_send(io, NULL);
|
|
return smb_composite_fetchfile_recv(c, mem_ctx);
|
|
}
|