2005-04-15 18:45:00 +04:00
/*
2023-08-03 15:34:51 +03:00
a composite API for querying file system information
2005-04-15 18:45:00 +04:00
*/
# include "includes.h"
# include "libcli/raw/libcliraw.h"
2008-04-02 06:53:27 +04:00
# include "libcli/raw/raw_proto.h"
2005-04-15 18:45:00 +04:00
# include "libcli/composite/composite.h"
2005-09-26 15:47:55 +04:00
# include "libcli/smb_composite/smb_composite.h"
2008-01-03 03:39:01 +03:00
# include "libcli/resolve/resolve.h"
2005-04-15 18:45:00 +04:00
/* the stages of this call */
enum fsinfo_stage { FSINFO_CONNECT , FSINFO_QUERY } ;
static void fsinfo_raw_handler ( struct smbcli_request * req ) ;
static void fsinfo_composite_handler ( struct composite_context * c ) ;
static void fsinfo_state_handler ( struct composite_context * c ) ;
struct fsinfo_state {
enum fsinfo_stage stage ;
struct composite_context * creq ;
struct smb_composite_fsinfo * io ;
struct smb_composite_connect * connect ;
union smb_fsinfo * fsinfo ;
struct smbcli_tree * tree ;
struct smbcli_request * req ;
} ;
static NTSTATUS fsinfo_connect ( struct composite_context * c ,
struct smb_composite_fsinfo * io )
{
NTSTATUS status ;
struct fsinfo_state * state ;
2005-09-26 15:47:55 +04:00
state = talloc_get_type ( c - > private_data , struct fsinfo_state ) ;
2005-04-15 18:45:00 +04:00
status = smb_composite_connect_recv ( state - > creq , c ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
state - > fsinfo = talloc ( state , union smb_fsinfo ) ;
NT_STATUS_HAVE_NO_MEMORY ( state - > fsinfo ) ;
state - > fsinfo - > generic . level = io - > in . level ;
state - > req = smb_raw_fsinfo_send ( state - > connect - > out . tree ,
state ,
state - > fsinfo ) ;
NT_STATUS_HAVE_NO_MEMORY ( state - > req ) ;
2009-02-02 12:17:00 +03:00
state - > req - > async . private_data = c ;
2005-04-15 18:45:00 +04:00
state - > req - > async . fn = fsinfo_raw_handler ;
state - > stage = FSINFO_QUERY ;
return NT_STATUS_OK ;
}
static NTSTATUS fsinfo_query ( struct composite_context * c ,
struct smb_composite_fsinfo * io )
{
NTSTATUS status ;
struct fsinfo_state * state ;
2005-09-26 15:47:55 +04:00
state = talloc_get_type ( c - > private_data , struct fsinfo_state ) ;
2005-04-15 18:45:00 +04:00
status = smb_raw_fsinfo_recv ( state - > req , state , state - > fsinfo ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
state - > io - > out . fsinfo = state - > fsinfo ;
2005-09-26 15:47:55 +04:00
c - > state = COMPOSITE_STATE_DONE ;
2005-04-15 18:45:00 +04:00
if ( c - > async . fn )
c - > async . fn ( c ) ;
return NT_STATUS_OK ;
}
/*
handler for completion of a sub - request in fsinfo
*/
2005-09-26 15:47:55 +04:00
static void fsinfo_state_handler ( struct composite_context * creq )
2005-04-15 18:45:00 +04:00
{
2005-09-26 15:47:55 +04:00
struct fsinfo_state * state = talloc_get_type ( creq - > private_data , struct fsinfo_state ) ;
2005-04-15 18:45:00 +04:00
/* when this handler is called, the stage indicates what
call has just finished */
switch ( state - > stage ) {
case FSINFO_CONNECT :
2005-09-26 15:47:55 +04:00
creq - > status = fsinfo_connect ( creq , state - > io ) ;
2005-04-15 18:45:00 +04:00
break ;
case FSINFO_QUERY :
2005-09-26 15:47:55 +04:00
creq - > status = fsinfo_query ( creq , state - > io ) ;
2005-04-15 18:45:00 +04:00
break ;
}
2005-09-26 15:47:55 +04:00
if ( ! NT_STATUS_IS_OK ( creq - > status ) ) {
creq - > state = COMPOSITE_STATE_ERROR ;
2005-04-15 18:45:00 +04:00
}
2005-09-26 15:47:55 +04:00
if ( creq - > state > = COMPOSITE_STATE_DONE & & creq - > async . fn ) {
creq - > async . fn ( creq ) ;
2005-04-15 18:45:00 +04:00
}
}
/*
As raw and composite handlers take different requests , we need to handlers
to adapt both for the same state machine in fsinfo_state_handler ( )
*/
static void fsinfo_raw_handler ( struct smbcli_request * req )
{
2009-02-02 12:17:00 +03:00
struct composite_context * c = talloc_get_type ( req - > async . private_data ,
2005-04-15 18:45:00 +04:00
struct composite_context ) ;
2005-06-09 14:33:20 +04:00
fsinfo_state_handler ( c ) ;
2005-04-15 18:45:00 +04:00
}
2005-09-26 15:47:55 +04:00
static void fsinfo_composite_handler ( struct composite_context * creq )
2005-04-15 18:45:00 +04:00
{
2005-09-26 15:47:55 +04:00
struct composite_context * c = talloc_get_type ( creq - > async . private_data ,
2005-04-15 18:45:00 +04:00
struct composite_context ) ;
2005-06-09 14:33:20 +04:00
fsinfo_state_handler ( c ) ;
2005-04-15 18:45:00 +04:00
}
/*
composite fsinfo call - connects to a tree and queries a file system information
*/
struct composite_context * smb_composite_fsinfo_send ( struct smbcli_tree * tree ,
2008-09-30 04:11:55 +04:00
struct smb_composite_fsinfo * io ,
2012-04-25 10:26:50 +04:00
struct resolve_context * resolve_ctx ,
struct tevent_context * event_ctx )
2005-04-15 18:45:00 +04:00
{
struct composite_context * c ;
struct fsinfo_state * state ;
c = talloc_zero ( tree , struct composite_context ) ;
if ( c = = NULL ) goto failed ;
2012-04-25 10:26:50 +04:00
c - > event_ctx = event_ctx ;
if ( c - > event_ctx = = NULL ) goto failed ;
2005-04-15 18:45:00 +04:00
state = talloc ( c , struct fsinfo_state ) ;
if ( state = = NULL ) goto failed ;
state - > io = io ;
2012-04-25 10:26:50 +04:00
state - > connect = talloc_zero ( state , struct smb_composite_connect ) ;
2005-04-15 18:45:00 +04:00
if ( state - > connect = = NULL ) goto failed ;
state - > connect - > in . dest_host = io - > in . dest_host ;
2007-12-12 04:15:29 +03:00
state - > connect - > in . dest_ports = io - > in . dest_ports ;
2008-11-02 03:03:26 +03:00
state - > connect - > in . socket_options = io - > in . socket_options ;
2005-04-15 18:45:00 +04:00
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 ;
2007-10-07 02:28:14 +04:00
state - > connect - > in . fallback_to_anonymous = false ;
2005-04-15 18:45:00 +04:00
state - > connect - > in . workgroup = io - > in . workgroup ;
2008-11-02 18:07:28 +03:00
state - > connect - > in . gensec_settings = io - > in . gensec_settings ;
2005-04-15 18:45:00 +04:00
2008-01-06 00:36:37 +03:00
state - > connect - > in . options = tree - > session - > transport - > options ;
2008-09-30 04:47:19 +04:00
state - > connect - > in . session_options = tree - > session - > options ;
2008-01-03 03:39:15 +03:00
2005-09-26 15:47:55 +04:00
c - > state = COMPOSITE_STATE_IN_PROGRESS ;
2005-04-15 18:45:00 +04:00
state - > stage = FSINFO_CONNECT ;
2005-09-26 15:47:55 +04:00
c - > private_data = state ;
2005-04-15 18:45:00 +04:00
2005-10-02 14:02:35 +04:00
state - > creq = smb_composite_connect_send ( state - > connect , state ,
2008-09-30 04:11:55 +04:00
resolve_ctx , c - > event_ctx ) ;
2005-04-15 18:45:00 +04:00
if ( state - > creq = = NULL ) goto failed ;
2005-09-26 15:47:55 +04:00
state - > creq - > async . private_data = c ;
2005-04-15 18:45:00 +04:00
state - > creq - > async . fn = fsinfo_composite_handler ;
return c ;
failed :
talloc_free ( c ) ;
return NULL ;
}
/*
composite fsinfo call - recv side
*/
NTSTATUS smb_composite_fsinfo_recv ( struct composite_context * c , TALLOC_CTX * mem_ctx )
{
NTSTATUS status ;
status = composite_wait ( c ) ;
if ( NT_STATUS_IS_OK ( status ) ) {
2005-09-26 15:47:55 +04:00
struct fsinfo_state * state = talloc_get_type ( c - > private_data , struct fsinfo_state ) ;
2005-04-15 18:45:00 +04:00
talloc_steal ( mem_ctx , state - > io - > out . fsinfo ) ;
}
talloc_free ( c ) ;
return status ;
}
/*
composite fsinfo call - sync interface
*/
NTSTATUS smb_composite_fsinfo ( struct smbcli_tree * tree ,
TALLOC_CTX * mem_ctx ,
2008-09-30 04:11:55 +04:00
struct smb_composite_fsinfo * io ,
2012-04-25 10:26:50 +04:00
struct resolve_context * resolve_ctx ,
struct tevent_context * ev )
2005-04-15 18:45:00 +04:00
{
2012-04-25 10:26:50 +04:00
struct composite_context * c = smb_composite_fsinfo_send ( tree , io , resolve_ctx , ev ) ;
2005-04-15 18:45:00 +04:00
return smb_composite_fsinfo_recv ( c , mem_ctx ) ;
}