2005-01-23 23:23:26 +00:00
/*
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 0213 9 , USA .
*/
/*
a composite API for loading a whole file into memory
*/
# include "includes.h"
# include "libcli/raw/libcliraw.h"
# include "libcli/composite/composite.h"
2005-09-26 11:47:55 +00:00
# include "libcli/smb_composite/smb_composite.h"
2005-01-23 23:23:26 +00:00
enum fetchfile_stage { FETCHFILE_CONNECT ,
FETCHFILE_READ } ;
struct fetchfile_state {
enum fetchfile_stage stage ;
struct smb_composite_fetchfile * io ;
2005-09-26 11:47:55 +00:00
struct composite_context * creq ;
2005-01-23 23:23:26 +00:00
struct smb_composite_connect * connect ;
struct smb_composite_loadfile * loadfile ;
} ;
2005-01-31 08:30:44 +00:00
static void fetchfile_composite_handler ( struct composite_context * req ) ;
2005-01-23 23:23:26 +00:00
2005-01-31 08:30:44 +00:00
static NTSTATUS fetchfile_connect ( struct composite_context * c ,
2005-01-23 23:23:26 +00:00
struct smb_composite_fetchfile * io )
{
NTSTATUS status ;
struct fetchfile_state * state ;
2005-09-26 11:47:55 +00:00
state = talloc_get_type ( c - > private_data , struct fetchfile_state ) ;
2005-01-23 23:23:26 +00:00
2005-09-26 11:47:55 +00:00
status = smb_composite_connect_recv ( state - > creq , c ) ;
2005-01-23 23:23:26 +00:00
NT_STATUS_NOT_OK_RETURN ( status ) ;
state - > loadfile = talloc ( state , struct smb_composite_loadfile ) ;
2005-03-03 09:26:08 +00:00
NT_STATUS_HAVE_NO_MEMORY ( state - > loadfile ) ;
2005-01-23 23:23:26 +00:00
state - > loadfile - > in . fname = io - > in . filename ;
2005-09-26 11:47:55 +00:00
state - > creq = smb_composite_loadfile_send ( state - > connect - > out . tree ,
2005-01-23 23:23:26 +00:00
state - > loadfile ) ;
2005-09-26 11:47:55 +00:00
NT_STATUS_HAVE_NO_MEMORY ( state - > creq ) ;
2005-01-23 23:23:26 +00:00
2005-09-26 11:47:55 +00:00
state - > creq - > async . private_data = c ;
state - > creq - > async . fn = fetchfile_composite_handler ;
2005-01-23 23:23:26 +00:00
state - > stage = FETCHFILE_READ ;
2005-09-26 11:47:55 +00:00
c - > event_ctx = talloc_reference ( c , state - > creq - > event_ctx ) ;
2005-01-23 23:23:26 +00:00
return NT_STATUS_OK ;
}
2005-01-31 08:30:44 +00:00
static NTSTATUS fetchfile_read ( struct composite_context * c ,
2005-01-23 23:23:26 +00:00
struct smb_composite_fetchfile * io )
{
NTSTATUS status ;
struct fetchfile_state * state ;
2005-09-26 11:47:55 +00:00
state = talloc_get_type ( c - > private_data , struct fetchfile_state ) ;
2005-01-23 23:23:26 +00:00
2005-09-26 11:47:55 +00:00
status = smb_composite_loadfile_recv ( state - > creq , NULL ) ;
2005-01-23 23:23:26 +00:00
NT_STATUS_NOT_OK_RETURN ( status ) ;
io - > out . data = state - > loadfile - > out . data ;
io - > out . size = state - > loadfile - > out . size ;
2005-09-26 11:47:55 +00:00
c - > state = COMPOSITE_STATE_DONE ;
2005-01-23 23:23:26 +00:00
if ( c - > async . fn )
c - > async . fn ( c ) ;
return NT_STATUS_OK ;
}
2005-01-31 08:30:44 +00:00
static void fetchfile_state_handler ( struct composite_context * c )
2005-01-23 23:23:26 +00:00
{
struct fetchfile_state * state ;
NTSTATUS status ;
2005-09-26 11:47:55 +00:00
state = talloc_get_type ( c - > private_data , struct fetchfile_state ) ;
2005-01-23 23:23:26 +00:00
/* 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 ;
2005-09-26 11:47:55 +00:00
c - > state = COMPOSITE_STATE_ERROR ;
2005-01-23 23:23:26 +00:00
if ( c - > async . fn ) {
c - > async . fn ( c ) ;
}
}
}
2005-09-26 11:47:55 +00:00
static void fetchfile_composite_handler ( struct composite_context * creq )
2005-01-23 23:23:26 +00:00
{
2005-09-26 11:47:55 +00:00
struct composite_context * c = talloc_get_type ( creq - > async . private_data ,
struct composite_context ) ;
2005-06-09 09:46:46 +00:00
fetchfile_state_handler ( c ) ;
2005-01-23 23:23:26 +00:00
}
2005-01-31 08:30:44 +00:00
struct composite_context * smb_composite_fetchfile_send ( struct smb_composite_fetchfile * io ,
2005-09-26 11:47:55 +00:00
struct event_context * event_ctx )
2005-01-23 23:23:26 +00:00
{
2005-01-31 08:30:44 +00:00
struct composite_context * c ;
2005-01-23 23:23:26 +00:00
struct fetchfile_state * state ;
2005-01-31 08:30:44 +00:00
c = talloc_zero ( NULL , struct composite_context ) ;
2005-01-23 23:23:26 +00:00
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 ;
r6028: A MAJOR update to intergrate the new credentails system fully with
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
(This used to be commit 2301a4b38a21aa60917973451687063d83d18d66)
2005-03-24 04:14:06 +00:00
state - > connect - > in . credentials = io - > in . credentials ;
2005-10-10 19:57:55 +00:00
state - > connect - > in . fallback_to_anonymous = False ;
r6028: A MAJOR update to intergrate the new credentails system fully with
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
(This used to be commit 2301a4b38a21aa60917973451687063d83d18d66)
2005-03-24 04:14:06 +00:00
state - > connect - > in . workgroup = io - > in . workgroup ;
2005-01-23 23:23:26 +00:00
2005-10-02 10:02:35 +00:00
state - > creq = smb_composite_connect_send ( state - > connect , state , event_ctx ) ;
2005-09-26 11:47:55 +00:00
if ( state - > creq = = NULL ) goto failed ;
2005-01-23 23:23:26 +00:00
2005-09-26 11:47:55 +00:00
state - > creq - > async . private_data = c ;
state - > creq - > async . fn = fetchfile_composite_handler ;
2005-01-23 23:23:26 +00:00
2005-09-26 11:47:55 +00:00
c - > state = COMPOSITE_STATE_IN_PROGRESS ;
2005-01-23 23:23:26 +00:00
state - > stage = FETCHFILE_CONNECT ;
2005-09-26 11:47:55 +00:00
c - > event_ctx = talloc_reference ( c , state - > creq - > event_ctx ) ;
c - > private_data = state ;
2005-01-23 23:23:26 +00:00
return c ;
failed :
talloc_free ( c ) ;
return NULL ;
}
2005-01-31 08:30:44 +00:00
NTSTATUS smb_composite_fetchfile_recv ( struct composite_context * c ,
2005-01-23 23:23:26 +00:00
TALLOC_CTX * mem_ctx )
{
2005-01-24 03:43:48 +00:00
NTSTATUS status ;
2005-01-31 08:30:44 +00:00
status = composite_wait ( c ) ;
2005-01-24 03:43:48 +00:00
if ( NT_STATUS_IS_OK ( status ) ) {
2005-09-26 11:47:55 +00:00
struct fetchfile_state * state = talloc_get_type ( c - > private_data , struct fetchfile_state ) ;
2005-01-24 03:43:48 +00:00
talloc_steal ( mem_ctx , state - > io - > out . data ) ;
}
talloc_free ( c ) ;
return status ;
2005-01-23 23:23:26 +00:00
}
NTSTATUS smb_composite_fetchfile ( struct smb_composite_fetchfile * io ,
TALLOC_CTX * mem_ctx )
{
2005-01-31 08:30:44 +00:00
struct composite_context * c = smb_composite_fetchfile_send ( io , NULL ) ;
2005-01-23 23:23:26 +00:00
return smb_composite_fetchfile_recv ( c , mem_ctx ) ;
}