2003-08-13 01:53:07 +00:00
/*
Unix SMB / CIFS implementation .
default IPC $ NTVFS backend
This patch adds a better dcerpc server infastructure.
1.) We now register endpoint servers add startup via register_backend()
and later use the smb.conf 'dcerpc endpoint servers' parameter to setup the dcesrv_context
2.) each endpoint server can register at context creation time as much interfaces as it wants
(multiple interfaces on one endpoint are supported!)
(NOTE: there's a difference between 'endpoint server' and 'endpoint'!
for details look at rpc_server/dcesrv_server.h)
3.) one endpoint can have a security descriptor registered to it self
this will be checked in the future when a client wants to connect
to an smb pipe endpoint.
4.) we now have a 'remote' endpoint server, which works like the ntvfs_cifs module
it takes this options in the [globals] section:
dcerpc remote:interfaces = srvsvc, winreg, w32time, epmapper
dcerpc remote:binding = ...
dcerpc remote:user = ...
dcerpc remote:password = ...
5.) we currently have tree endpoint servers: epmapper, rpcecho and remote
the default for the 'dcerpc endpiont servers = epmapper, rpcecho'
for testing you can also do
dcerpc endpoint servers = rpcecho, remote, epmapper
dcerpc remote:interfaces = srvsvc, samr, netlogon
6,) please notice the the epmapper now only returns NO_ENTRIES
(but I think we'll find a solution for this too:-)
7.) also there're some other stuff left, but step by step :-)
This patch also includes updates for the
register_subsystem() , ntvfs_init(), and some other funtions
to check for duplicate subsystem registration
metze
(hmmm, my first large commit...I hope it works as supposed :-)
(This used to be commit 917e45dafd5be4c2cd90ff425b8d6f8403122349)
2004-01-08 22:55:27 +00:00
2003-08-13 01:53:07 +00:00
Copyright ( C ) Andrew Tridgell 2003
2005-01-11 16:53:02 +00:00
Copyright ( C ) Stefan ( metze ) Metzmacher 2004 - 2005
2003-08-13 01:53:07 +00:00
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
2007-07-10 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2003-08-13 01:53:07 +00:00
( 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
2007-07-10 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2003-08-13 01:53:07 +00:00
*/
/*
this implements the IPC $ backend , called by the NTVFS subsystem to
handle requests on IPC $ shares
*/
# include "includes.h"
2008-10-11 21:31:42 +02:00
# include "../lib/util/dlinklist.h"
2005-12-27 22:51:30 +00:00
# include "ntvfs/ntvfs.h"
2010-04-26 15:41:17 +02:00
# include "../librpc/gen_ndr/rap.h"
2006-03-06 23:28:18 +00:00
# include "ntvfs/ipc/proto.h"
2011-10-18 11:47:05 +02:00
# include "../libcli/smb/smb_constants.h"
2007-12-04 20:05:00 +01:00
# include "param/param.h"
2009-08-11 14:50:36 +02:00
# include "../lib/tsocket/tsocket.h"
# include "../libcli/named_pipe_auth/npa_tstream.h"
# include "auth/auth.h"
# include "auth/auth_sam_reply.h"
# include "lib/socket/socket.h"
# include "auth/credentials/credentials.h"
# include "auth/credentials/credentials_krb5.h"
2012-05-02 20:59:00 +03:00
# include "system/kerberos.h"
2012-04-24 19:37:13 +03:00
# include "system/gssapi.h"
2009-09-18 22:58:03 -07:00
# include "system/locale.h"
2012-05-02 20:59:00 +03:00
# include "system/filesys.h"
2003-08-13 01:53:07 +00:00
2020-08-07 13:27:39 -07:00
# undef strncasecmp
2003-12-10 22:24:33 +00:00
/* this is the private structure used to keep the state of an open
ipc $ connection . It needs to keep information about all open
pipes */
struct ipc_private {
2006-03-16 18:54:19 +00:00
struct ntvfs_module_context * ntvfs ;
2003-12-10 22:24:33 +00:00
/* a list of open pipes */
struct pipe_state {
struct pipe_state * next , * prev ;
2009-02-02 08:33:21 +01:00
struct ipc_private * ipriv ;
2003-12-10 22:24:33 +00:00
const char * pipe_name ;
2006-05-20 08:15:22 +00:00
struct ntvfs_handle * handle ;
2009-08-11 14:50:36 +02:00
struct tstream_context * npipe ;
uint16_t file_type ;
uint16_t device_state ;
uint64_t allocation_size ;
struct tevent_queue * write_queue ;
struct tevent_queue * read_queue ;
2003-12-10 22:24:33 +00:00
} * pipe_list ;
} ;
/*
2006-05-20 08:15:22 +00:00
find a open pipe give a file handle
2003-12-10 22:24:33 +00:00
*/
2009-02-02 08:33:21 +01:00
static struct pipe_state * pipe_state_find ( struct ipc_private * ipriv , struct ntvfs_handle * handle )
2003-12-10 22:24:33 +00:00
{
2006-03-16 18:54:19 +00:00
struct pipe_state * s ;
void * p ;
2009-02-02 08:33:21 +01:00
p = ntvfs_handle_get_backend_data ( handle , ipriv - > ntvfs ) ;
2006-03-16 18:54:19 +00:00
if ( ! p ) return NULL ;
s = talloc_get_type ( p , struct pipe_state ) ;
2006-05-20 08:15:22 +00:00
if ( ! s ) return NULL ;
2006-03-16 18:54:19 +00:00
return s ;
2003-12-10 22:24:33 +00:00
}
2006-05-20 08:15:22 +00:00
/*
find a open pipe give a wire fnum
*/
2009-02-02 08:33:21 +01:00
static struct pipe_state * pipe_state_find_key ( struct ipc_private * ipriv , struct ntvfs_request * req , const DATA_BLOB * key )
2006-05-20 08:15:22 +00:00
{
struct ntvfs_handle * h ;
2009-02-02 08:33:21 +01:00
h = ntvfs_handle_search_by_wire_key ( ipriv - > ntvfs , req , key ) ;
2006-05-20 08:15:22 +00:00
if ( ! h ) return NULL ;
2009-02-02 08:33:21 +01:00
return pipe_state_find ( ipriv , h ) ;
2006-05-20 08:15:22 +00:00
}
2003-12-10 22:24:33 +00:00
2003-08-13 01:53:07 +00:00
/*
connect to a share - always works
*/
2004-09-29 13:17:09 +00:00
static NTSTATUS ipc_connect ( struct ntvfs_module_context * ntvfs ,
2009-05-14 08:58:50 +01:00
struct ntvfs_request * req ,
union smb_tcon * tcon )
2003-08-13 01:53:07 +00:00
{
2009-02-02 08:33:21 +01:00
struct ipc_private * ipriv ;
2009-05-14 08:58:50 +01:00
const char * sharename ;
switch ( tcon - > generic . level ) {
case RAW_TCON_TCON :
sharename = tcon - > tcon . in . service ;
break ;
case RAW_TCON_TCONX :
sharename = tcon - > tconx . in . path ;
break ;
case RAW_TCON_SMB2 :
sharename = tcon - > smb2 . in . path ;
break ;
default :
return NT_STATUS_INVALID_LEVEL ;
}
if ( strncmp ( sharename , " \\ \\ " , 2 ) = = 0 ) {
char * p = strchr ( sharename + 2 , ' \\ ' ) ;
if ( p ) {
sharename = p + 1 ;
}
}
2003-08-13 01:53:07 +00:00
2006-03-15 17:28:46 +00:00
ntvfs - > ctx - > fs_type = talloc_strdup ( ntvfs - > ctx , " IPC " ) ;
NT_STATUS_HAVE_NO_MEMORY ( ntvfs - > ctx - > fs_type ) ;
2005-02-22 11:35:38 +00:00
2006-03-15 17:28:46 +00:00
ntvfs - > ctx - > dev_type = talloc_strdup ( ntvfs - > ctx , " IPC " ) ;
NT_STATUS_HAVE_NO_MEMORY ( ntvfs - > ctx - > dev_type ) ;
2003-08-13 01:53:07 +00:00
2009-05-14 08:58:50 +01:00
if ( tcon - > generic . level = = RAW_TCON_TCONX ) {
tcon - > tconx . out . fs_type = ntvfs - > ctx - > fs_type ;
tcon - > tconx . out . dev_type = ntvfs - > ctx - > dev_type ;
}
2003-12-10 22:24:33 +00:00
/* prepare the private state for this connection */
2009-02-02 08:33:21 +01:00
ipriv = talloc ( ntvfs , struct ipc_private ) ;
NT_STATUS_HAVE_NO_MEMORY ( ipriv ) ;
2005-01-11 14:32:15 +00:00
2009-02-02 08:33:21 +01:00
ntvfs - > private_data = ipriv ;
2003-12-10 22:24:33 +00:00
2009-02-02 08:33:21 +01:00
ipriv - > ntvfs = ntvfs ;
ipriv - > pipe_list = NULL ;
r3081: several updates to ntvfs and server side async request handling in
preparation for the full share modes and ntcreatex code that I am
working on.
highlights include:
- changed the way a backend determines if it is allowed to process a
request asynchronously. The previous method of looking at the
send_fn caused problems when an intermediate ntvfs module disabled
it, and the caller then wanted to finished processing using this
function. The new method is a REQ_CONTROL_MAY_ASYNC flag in
req->control_flags, which is also a bit easier to read
- fixed 2 bugs in the readbraw server code. One related to trying to
answer a readbraw with smb signing (which can't work, and crashed
our signing code), the second related to error handling, which
attempted to send a normal SMB error packet, when readbraw must
send a 0 read reply (as it has no header)
- added several more ntvfs_generic.c generic mapping functions. This
means that backends no longer need to implement such esoteric
functions as SMBwriteunlock() if they don't want to. The backend
can just request the mapping layer turn it into a write followed by
an unlock. This makes the backends considerably simpler as they
only need to implement one style of each function for lock, read,
write, open etc, rather than the full host of functions that SMB
provides. A backend can still choose to implement them
individually, of course, and the CIFS backend does that.
- simplified the generic structures to make them identical to the
principal call for several common SMB calls (such as
RAW_WRITE_GENERIC now being an alias for RAW_WRITE_WRITEX).
- started rewriting the pvfs_open() code in preparation for the full
ntcreatex semantics.
- in pvfs_open and ipc_open, initially allocate the open file
structure as a child of the request, so on error we don't need to
clean up. Then when we are going to succeed the open steal the
pointer into the long term backend context. This makes for much
simpler error handling (and fixes some bugs)
- use a destructor in the ipc backend to make sure that everthing is
cleaned up on receive error conditions.
- switched the ipc backend to using idtree for fnum allocation
- in the ntvfs_generic mapping routines, use a allocated secondary
structure not a stack structure to ensure the request pointer
remains valid even if the backend replies async.
(This used to be commit 3457c1836c09c82956697eb21627dfa2ed37682e)
2004-10-20 08:28:31 +00:00
2003-08-13 01:53:07 +00:00
return NT_STATUS_OK ;
}
/*
disconnect from a share
*/
2006-03-10 14:31:17 +00:00
static NTSTATUS ipc_disconnect ( struct ntvfs_module_context * ntvfs )
2003-08-13 01:53:07 +00:00
{
return NT_STATUS_OK ;
}
/*
delete a file
*/
2004-09-29 13:17:09 +00:00
static NTSTATUS ipc_unlink ( struct ntvfs_module_context * ntvfs ,
2006-03-10 20:49:20 +00:00
struct ntvfs_request * req ,
union smb_unlink * unl )
2003-08-13 01:53:07 +00:00
{
return NT_STATUS_ACCESS_DENIED ;
}
/*
check if a directory exists
*/
2004-09-29 13:17:09 +00:00
static NTSTATUS ipc_chkpath ( struct ntvfs_module_context * ntvfs ,
2006-03-10 20:49:20 +00:00
struct ntvfs_request * req ,
union smb_chkpath * cp )
2003-08-13 01:53:07 +00:00
{
return NT_STATUS_ACCESS_DENIED ;
}
/*
return info on a pathname
*/
2004-09-29 13:17:09 +00:00
static NTSTATUS ipc_qpathinfo ( struct ntvfs_module_context * ntvfs ,
2006-03-10 14:31:17 +00:00
struct ntvfs_request * req , union smb_fileinfo * info )
2003-08-13 01:53:07 +00:00
{
2007-05-15 01:21:20 +00:00
switch ( info - > generic . level ) {
case RAW_FILEINFO_GENERIC :
return NT_STATUS_INVALID_DEVICE_REQUEST ;
case RAW_FILEINFO_GETATTR :
return NT_STATUS_ACCESS_DENIED ;
default :
return ntvfs_map_qpathinfo ( ntvfs , req , info ) ;
}
2003-08-13 01:53:07 +00:00
}
/*
set info on a pathname
*/
2004-09-29 13:17:09 +00:00
static NTSTATUS ipc_setpathinfo ( struct ntvfs_module_context * ntvfs ,
2006-03-10 14:31:17 +00:00
struct ntvfs_request * req , union smb_setfileinfo * st )
2003-08-13 01:53:07 +00:00
{
return NT_STATUS_ACCESS_DENIED ;
}
2003-12-16 09:02:58 +00:00
r3081: several updates to ntvfs and server side async request handling in
preparation for the full share modes and ntcreatex code that I am
working on.
highlights include:
- changed the way a backend determines if it is allowed to process a
request asynchronously. The previous method of looking at the
send_fn caused problems when an intermediate ntvfs module disabled
it, and the caller then wanted to finished processing using this
function. The new method is a REQ_CONTROL_MAY_ASYNC flag in
req->control_flags, which is also a bit easier to read
- fixed 2 bugs in the readbraw server code. One related to trying to
answer a readbraw with smb signing (which can't work, and crashed
our signing code), the second related to error handling, which
attempted to send a normal SMB error packet, when readbraw must
send a 0 read reply (as it has no header)
- added several more ntvfs_generic.c generic mapping functions. This
means that backends no longer need to implement such esoteric
functions as SMBwriteunlock() if they don't want to. The backend
can just request the mapping layer turn it into a write followed by
an unlock. This makes the backends considerably simpler as they
only need to implement one style of each function for lock, read,
write, open etc, rather than the full host of functions that SMB
provides. A backend can still choose to implement them
individually, of course, and the CIFS backend does that.
- simplified the generic structures to make them identical to the
principal call for several common SMB calls (such as
RAW_WRITE_GENERIC now being an alias for RAW_WRITE_WRITEX).
- started rewriting the pvfs_open() code in preparation for the full
ntcreatex semantics.
- in pvfs_open and ipc_open, initially allocate the open file
structure as a child of the request, so on error we don't need to
clean up. Then when we are going to succeed the open steal the
pointer into the long term backend context. This makes for much
simpler error handling (and fixes some bugs)
- use a destructor in the ipc backend to make sure that everthing is
cleaned up on receive error conditions.
- switched the ipc backend to using idtree for fnum allocation
- in the ntvfs_generic mapping routines, use a allocated secondary
structure not a stack structure to ensure the request pointer
remains valid even if the backend replies async.
(This used to be commit 3457c1836c09c82956697eb21627dfa2ed37682e)
2004-10-20 08:28:31 +00:00
/*
destroy a open pipe structure
*/
2006-05-24 07:34:11 +00:00
static int ipc_fd_destructor ( struct pipe_state * p )
r3081: several updates to ntvfs and server side async request handling in
preparation for the full share modes and ntcreatex code that I am
working on.
highlights include:
- changed the way a backend determines if it is allowed to process a
request asynchronously. The previous method of looking at the
send_fn caused problems when an intermediate ntvfs module disabled
it, and the caller then wanted to finished processing using this
function. The new method is a REQ_CONTROL_MAY_ASYNC flag in
req->control_flags, which is also a bit easier to read
- fixed 2 bugs in the readbraw server code. One related to trying to
answer a readbraw with smb signing (which can't work, and crashed
our signing code), the second related to error handling, which
attempted to send a normal SMB error packet, when readbraw must
send a 0 read reply (as it has no header)
- added several more ntvfs_generic.c generic mapping functions. This
means that backends no longer need to implement such esoteric
functions as SMBwriteunlock() if they don't want to. The backend
can just request the mapping layer turn it into a write followed by
an unlock. This makes the backends considerably simpler as they
only need to implement one style of each function for lock, read,
write, open etc, rather than the full host of functions that SMB
provides. A backend can still choose to implement them
individually, of course, and the CIFS backend does that.
- simplified the generic structures to make them identical to the
principal call for several common SMB calls (such as
RAW_WRITE_GENERIC now being an alias for RAW_WRITE_WRITEX).
- started rewriting the pvfs_open() code in preparation for the full
ntcreatex semantics.
- in pvfs_open and ipc_open, initially allocate the open file
structure as a child of the request, so on error we don't need to
clean up. Then when we are going to succeed the open steal the
pointer into the long term backend context. This makes for much
simpler error handling (and fixes some bugs)
- use a destructor in the ipc backend to make sure that everthing is
cleaned up on receive error conditions.
- switched the ipc backend to using idtree for fnum allocation
- in the ntvfs_generic mapping routines, use a allocated secondary
structure not a stack structure to ensure the request pointer
remains valid even if the backend replies async.
(This used to be commit 3457c1836c09c82956697eb21627dfa2ed37682e)
2004-10-20 08:28:31 +00:00
{
2009-02-02 08:33:21 +01:00
DLIST_REMOVE ( p - > ipriv - > pipe_list , p ) ;
ntvfs_handle_remove_backend_data ( p - > handle , p - > ipriv - > ntvfs ) ;
r3081: several updates to ntvfs and server side async request handling in
preparation for the full share modes and ntcreatex code that I am
working on.
highlights include:
- changed the way a backend determines if it is allowed to process a
request asynchronously. The previous method of looking at the
send_fn caused problems when an intermediate ntvfs module disabled
it, and the caller then wanted to finished processing using this
function. The new method is a REQ_CONTROL_MAY_ASYNC flag in
req->control_flags, which is also a bit easier to read
- fixed 2 bugs in the readbraw server code. One related to trying to
answer a readbraw with smb signing (which can't work, and crashed
our signing code), the second related to error handling, which
attempted to send a normal SMB error packet, when readbraw must
send a 0 read reply (as it has no header)
- added several more ntvfs_generic.c generic mapping functions. This
means that backends no longer need to implement such esoteric
functions as SMBwriteunlock() if they don't want to. The backend
can just request the mapping layer turn it into a write followed by
an unlock. This makes the backends considerably simpler as they
only need to implement one style of each function for lock, read,
write, open etc, rather than the full host of functions that SMB
provides. A backend can still choose to implement them
individually, of course, and the CIFS backend does that.
- simplified the generic structures to make them identical to the
principal call for several common SMB calls (such as
RAW_WRITE_GENERIC now being an alias for RAW_WRITE_WRITEX).
- started rewriting the pvfs_open() code in preparation for the full
ntcreatex semantics.
- in pvfs_open and ipc_open, initially allocate the open file
structure as a child of the request, so on error we don't need to
clean up. Then when we are going to succeed the open steal the
pointer into the long term backend context. This makes for much
simpler error handling (and fixes some bugs)
- use a destructor in the ipc backend to make sure that everthing is
cleaned up on receive error conditions.
- switched the ipc backend to using idtree for fnum allocation
- in the ntvfs_generic mapping routines, use a allocated secondary
structure not a stack structure to ensure the request pointer
remains valid even if the backend replies async.
(This used to be commit 3457c1836c09c82956697eb21627dfa2ed37682e)
2004-10-20 08:28:31 +00:00
return 0 ;
}
2009-08-11 14:50:36 +02:00
struct ipc_open_state {
struct ipc_private * ipriv ;
struct pipe_state * p ;
struct ntvfs_request * req ;
union smb_open * oi ;
2011-02-09 14:22:16 +11:00
struct auth_session_info_transport * session_info_transport ;
2009-08-11 14:50:36 +02:00
} ;
2006-03-16 18:46:49 +00:00
2009-08-11 14:50:36 +02:00
static void ipc_open_done ( struct tevent_req * subreq ) ;
2003-12-16 09:02:58 +00:00
2009-09-18 22:58:03 -07:00
/*
check the pipename is valid
*/
static NTSTATUS validate_pipename ( const char * name )
{
while ( * name ) {
2010-09-28 04:40:38 +04:00
if ( ! isalnum ( * name ) & & * name ! = ' _ ' ) {
return NT_STATUS_INVALID_PARAMETER ;
}
2009-09-18 22:58:03 -07:00
name + + ;
}
return NT_STATUS_OK ;
}
2003-08-13 01:53:07 +00:00
/*
2009-08-11 14:50:36 +02:00
open a file - used for MSRPC pipes
2003-08-13 01:53:07 +00:00
*/
2009-08-11 14:50:36 +02:00
static NTSTATUS ipc_open ( struct ntvfs_module_context * ntvfs ,
struct ntvfs_request * req , union smb_open * oi )
2003-08-13 01:53:07 +00:00
{
2003-12-10 22:24:33 +00:00
NTSTATUS status ;
2009-08-11 14:50:36 +02:00
struct pipe_state * p ;
struct ipc_private * ipriv = talloc_get_type_abort ( ntvfs - > private_data ,
struct ipc_private ) ;
2006-05-20 08:15:22 +00:00
struct ntvfs_handle * h ;
2009-08-11 14:50:36 +02:00
struct ipc_open_state * state ;
struct tevent_req * subreq ;
const char * fname ;
const char * directory ;
2017-03-10 12:43:42 +13:00
const struct tsocket_address * remote_client_addr ;
const struct tsocket_address * local_server_addr ;
2009-08-11 14:50:36 +02:00
switch ( oi - > generic . level ) {
case RAW_OPEN_NTCREATEX :
2009-11-07 20:53:28 +01:00
case RAW_OPEN_NTTRANS_CREATE :
2009-08-11 14:50:36 +02:00
fname = oi - > ntcreatex . in . fname ;
2012-05-28 19:44:04 +02:00
while ( fname [ 0 ] = = ' \\ ' ) fname + + ;
2009-08-11 14:50:36 +02:00
break ;
case RAW_OPEN_OPENX :
fname = oi - > openx . in . fname ;
2012-05-28 19:44:04 +02:00
while ( fname [ 0 ] = = ' \\ ' ) fname + + ;
if ( strncasecmp ( fname , " PIPE \\ " , 5 ) ! = 0 ) {
return NT_STATUS_OBJECT_PATH_SYNTAX_BAD ;
}
while ( fname [ 0 ] = = ' \\ ' ) fname + + ;
2009-08-11 14:50:36 +02:00
break ;
case RAW_OPEN_SMB2 :
fname = oi - > smb2 . in . fname ;
break ;
default :
2009-11-07 20:53:28 +01:00
return NT_STATUS_NOT_SUPPORTED ;
2009-08-11 14:50:36 +02:00
}
directory = talloc_asprintf ( req , " %s/np " ,
2010-07-16 14:32:42 +10:00
lpcfg_ncalrpc_dir ( ipriv - > ntvfs - > ctx - > lp_ctx ) ) ;
2009-08-11 14:50:36 +02:00
NT_STATUS_HAVE_NO_MEMORY ( directory ) ;
state = talloc ( req , struct ipc_open_state ) ;
NT_STATUS_HAVE_NO_MEMORY ( state ) ;
2006-05-20 08:15:22 +00:00
status = ntvfs_handle_new ( ntvfs , req , & h ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
2003-12-10 22:24:33 +00:00
2006-05-20 08:15:22 +00:00
p = talloc ( h , struct pipe_state ) ;
2005-01-11 16:53:02 +00:00
NT_STATUS_HAVE_NO_MEMORY ( p ) ;
2009-09-18 22:58:03 -07:00
/* check for valid characters in name */
fname = strlower_talloc ( p , fname ) ;
status = validate_pipename ( fname ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
2004-10-18 16:07:08 +00:00
p - > pipe_name = talloc_asprintf ( p , " \\ pipe \\ %s " , fname ) ;
2005-01-11 16:53:02 +00:00
NT_STATUS_HAVE_NO_MEMORY ( p - > pipe_name ) ;
2003-12-10 22:24:33 +00:00
2006-05-20 08:15:22 +00:00
p - > handle = h ;
2009-08-11 14:50:36 +02:00
p - > ipriv = ipriv ;
2006-01-28 20:08:03 +00:00
2009-08-11 14:50:36 +02:00
p - > write_queue = tevent_queue_create ( p , " ipc_write_queue " ) ;
NT_STATUS_HAVE_NO_MEMORY ( p - > write_queue ) ;
2003-12-10 22:24:33 +00:00
2009-08-11 14:50:36 +02:00
p - > read_queue = tevent_queue_create ( p , " ipc_read_queue " ) ;
NT_STATUS_HAVE_NO_MEMORY ( p - > read_queue ) ;
2004-09-26 11:30:20 +00:00
2009-08-11 14:50:36 +02:00
state - > ipriv = ipriv ;
state - > p = p ;
state - > req = req ;
state - > oi = oi ;
r3081: several updates to ntvfs and server side async request handling in
preparation for the full share modes and ntcreatex code that I am
working on.
highlights include:
- changed the way a backend determines if it is allowed to process a
request asynchronously. The previous method of looking at the
send_fn caused problems when an intermediate ntvfs module disabled
it, and the caller then wanted to finished processing using this
function. The new method is a REQ_CONTROL_MAY_ASYNC flag in
req->control_flags, which is also a bit easier to read
- fixed 2 bugs in the readbraw server code. One related to trying to
answer a readbraw with smb signing (which can't work, and crashed
our signing code), the second related to error handling, which
attempted to send a normal SMB error packet, when readbraw must
send a 0 read reply (as it has no header)
- added several more ntvfs_generic.c generic mapping functions. This
means that backends no longer need to implement such esoteric
functions as SMBwriteunlock() if they don't want to. The backend
can just request the mapping layer turn it into a write followed by
an unlock. This makes the backends considerably simpler as they
only need to implement one style of each function for lock, read,
write, open etc, rather than the full host of functions that SMB
provides. A backend can still choose to implement them
individually, of course, and the CIFS backend does that.
- simplified the generic structures to make them identical to the
principal call for several common SMB calls (such as
RAW_WRITE_GENERIC now being an alias for RAW_WRITE_WRITEX).
- started rewriting the pvfs_open() code in preparation for the full
ntcreatex semantics.
- in pvfs_open and ipc_open, initially allocate the open file
structure as a child of the request, so on error we don't need to
clean up. Then when we are going to succeed the open steal the
pointer into the long term backend context. This makes for much
simpler error handling (and fixes some bugs)
- use a destructor in the ipc backend to make sure that everthing is
cleaned up on receive error conditions.
- switched the ipc backend to using idtree for fnum allocation
- in the ntvfs_generic mapping routines, use a allocated secondary
structure not a stack structure to ensure the request pointer
remains valid even if the backend replies async.
(This used to be commit 3457c1836c09c82956697eb21627dfa2ed37682e)
2004-10-20 08:28:31 +00:00
2011-02-09 14:22:16 +11:00
status = auth_session_info_transport_from_session ( state ,
req - > session_info ,
ipriv - > ntvfs - > ctx - > event_ctx ,
ipriv - > ntvfs - > ctx - > lp_ctx ,
& state - > session_info_transport ) ;
2011-02-08 16:53:13 +11:00
2006-05-20 08:15:22 +00:00
NT_STATUS_NOT_OK_RETURN ( status ) ;
2017-03-10 12:43:42 +13:00
local_server_addr = ntvfs_get_local_address ( ipriv - > ntvfs ) ;
remote_client_addr = ntvfs_get_remote_address ( ipriv - > ntvfs ) ;
2003-12-10 22:24:33 +00:00
2009-08-11 14:50:36 +02:00
subreq = tstream_npa_connect_send ( p ,
ipriv - > ntvfs - > ctx - > event_ctx ,
directory ,
fname ,
2021-11-27 16:38:38 +01:00
NCACN_NP ,
2017-03-10 12:43:42 +13:00
remote_client_addr ,
2009-08-11 14:50:36 +02:00
NULL ,
2017-03-10 12:43:42 +13:00
local_server_addr ,
2009-08-11 14:50:36 +02:00
NULL ,
2011-02-09 14:22:16 +11:00
state - > session_info_transport ) ;
2009-08-11 14:50:36 +02:00
NT_STATUS_HAVE_NO_MEMORY ( subreq ) ;
tevent_req_set_callback ( subreq , ipc_open_done , state ) ;
req - > async_states - > state | = NTVFS_ASYNC_STATE_ASYNC ;
return NT_STATUS_OK ;
2003-12-16 09:02:58 +00:00
}
2009-08-11 14:50:36 +02:00
static void ipc_open_done ( struct tevent_req * subreq )
2006-07-09 09:56:13 +00:00
{
2009-08-11 14:50:36 +02:00
struct ipc_open_state * state = tevent_req_callback_data ( subreq ,
struct ipc_open_state ) ;
struct ipc_private * ipriv = state - > ipriv ;
struct pipe_state * p = state - > p ;
struct ntvfs_request * req = state - > req ;
union smb_open * oi = state - > oi ;
int ret ;
int sys_errno ;
2006-07-09 09:56:13 +00:00
NTSTATUS status ;
2009-08-11 14:50:36 +02:00
ret = tstream_npa_connect_recv ( subreq , & sys_errno ,
p , & p - > npipe ,
& p - > file_type ,
& p - > device_state ,
& p - > allocation_size ) ;
TALLOC_FREE ( subreq ) ;
if ( ret = = - 1 ) {
2011-06-20 14:55:32 +10:00
status = map_nt_error_from_unix_common ( sys_errno ) ;
2009-08-11 14:50:36 +02:00
goto reply ;
}
2006-07-09 09:56:13 +00:00
2009-08-11 14:50:36 +02:00
DLIST_ADD ( ipriv - > pipe_list , p ) ;
talloc_set_destructor ( p , ipc_fd_destructor ) ;
2006-07-09 09:56:13 +00:00
2009-08-11 14:50:36 +02:00
status = ntvfs_handle_set_backend_data ( p - > handle , ipriv - > ntvfs , p ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto reply ;
}
2003-12-16 09:02:58 +00:00
switch ( oi - > generic . level ) {
case RAW_OPEN_NTCREATEX :
2009-08-11 14:50:36 +02:00
ZERO_STRUCT ( oi - > ntcreatex . out ) ;
oi - > ntcreatex . out . file . ntvfs = p - > handle ;
oi - > ntcreatex . out . oplock_level = 0 ;
oi - > ntcreatex . out . create_action = NTCREATEX_ACTION_EXISTED ;
oi - > ntcreatex . out . create_time = 0 ;
oi - > ntcreatex . out . access_time = 0 ;
oi - > ntcreatex . out . write_time = 0 ;
oi - > ntcreatex . out . change_time = 0 ;
oi - > ntcreatex . out . attrib = FILE_ATTRIBUTE_NORMAL ;
oi - > ntcreatex . out . alloc_size = p - > allocation_size ;
oi - > ntcreatex . out . size = 0 ;
oi - > ntcreatex . out . file_type = p - > file_type ;
oi - > ntcreatex . out . ipc_state = p - > device_state ;
oi - > ntcreatex . out . is_directory = 0 ;
2003-12-16 09:02:58 +00:00
break ;
case RAW_OPEN_OPENX :
2009-08-11 14:50:36 +02:00
ZERO_STRUCT ( oi - > openx . out ) ;
oi - > openx . out . file . ntvfs = p - > handle ;
oi - > openx . out . attrib = FILE_ATTRIBUTE_NORMAL ;
oi - > openx . out . write_time = 0 ;
oi - > openx . out . size = 0 ;
oi - > openx . out . access = 0 ;
oi - > openx . out . ftype = p - > file_type ;
oi - > openx . out . devstate = p - > device_state ;
oi - > openx . out . action = 0 ;
oi - > openx . out . unique_fid = 0 ;
oi - > openx . out . access_mask = 0 ;
oi - > openx . out . unknown = 0 ;
2003-12-16 09:02:58 +00:00
break ;
2006-07-09 09:56:13 +00:00
case RAW_OPEN_SMB2 :
2009-08-11 14:50:36 +02:00
ZERO_STRUCT ( oi - > smb2 . out ) ;
oi - > smb2 . out . file . ntvfs = p - > handle ;
oi - > smb2 . out . oplock_level = oi - > smb2 . in . oplock_level ;
oi - > smb2 . out . create_action = NTCREATEX_ACTION_EXISTED ;
oi - > smb2 . out . create_time = 0 ;
oi - > smb2 . out . access_time = 0 ;
oi - > smb2 . out . write_time = 0 ;
oi - > smb2 . out . change_time = 0 ;
oi - > smb2 . out . alloc_size = p - > allocation_size ;
oi - > smb2 . out . size = 0 ;
oi - > smb2 . out . file_attr = FILE_ATTRIBUTE_NORMAL ;
oi - > smb2 . out . reserved2 = 0 ;
2006-07-09 09:56:13 +00:00
break ;
2003-12-16 09:02:58 +00:00
default :
break ;
}
2009-08-11 14:50:36 +02:00
reply :
req - > async_states - > status = status ;
req - > async_states - > send_fn ( req ) ;
2003-08-13 01:53:07 +00:00
}
/*
create a directory
*/
2004-09-29 13:17:09 +00:00
static NTSTATUS ipc_mkdir ( struct ntvfs_module_context * ntvfs ,
2006-03-10 14:31:17 +00:00
struct ntvfs_request * req , union smb_mkdir * md )
2003-08-13 01:53:07 +00:00
{
return NT_STATUS_ACCESS_DENIED ;
}
/*
remove a directory
*/
2004-09-29 13:17:09 +00:00
static NTSTATUS ipc_rmdir ( struct ntvfs_module_context * ntvfs ,
2006-03-10 14:31:17 +00:00
struct ntvfs_request * req , struct smb_rmdir * rd )
2003-08-13 01:53:07 +00:00
{
return NT_STATUS_ACCESS_DENIED ;
}
/*
rename a set of files
*/
2004-09-29 13:17:09 +00:00
static NTSTATUS ipc_rename ( struct ntvfs_module_context * ntvfs ,
2006-03-10 14:31:17 +00:00
struct ntvfs_request * req , union smb_rename * ren )
2003-08-13 01:53:07 +00:00
{
return NT_STATUS_ACCESS_DENIED ;
}
/*
copy a set of files
*/
2004-09-29 13:17:09 +00:00
static NTSTATUS ipc_copy ( struct ntvfs_module_context * ntvfs ,
2006-03-10 14:31:17 +00:00
struct ntvfs_request * req , struct smb_copy * cp )
2003-08-13 01:53:07 +00:00
{
return NT_STATUS_ACCESS_DENIED ;
}
2009-08-11 14:50:36 +02:00
struct ipc_readv_next_vector_state {
uint8_t * buf ;
size_t len ;
off_t ofs ;
size_t remaining ;
} ;
static void ipc_readv_next_vector_init ( struct ipc_readv_next_vector_state * s ,
uint8_t * buf , size_t len )
{
ZERO_STRUCTP ( s ) ;
s - > buf = buf ;
s - > len = MIN ( len , UINT16_MAX ) ;
}
static int ipc_readv_next_vector ( struct tstream_context * stream ,
void * private_data ,
TALLOC_CTX * mem_ctx ,
struct iovec * * _vector ,
size_t * count )
2006-01-28 20:08:03 +00:00
{
2009-08-11 14:50:36 +02:00
struct ipc_readv_next_vector_state * state =
( struct ipc_readv_next_vector_state * ) private_data ;
struct iovec * vector ;
ssize_t pending ;
size_t wanted ;
if ( state - > ofs = = state - > len ) {
* _vector = NULL ;
* count = 0 ;
return 0 ;
}
2006-01-28 20:08:03 +00:00
2009-08-11 14:50:36 +02:00
pending = tstream_pending_bytes ( stream ) ;
if ( pending = = - 1 ) {
return - 1 ;
2006-01-28 20:08:03 +00:00
}
2009-08-11 14:50:36 +02:00
if ( pending = = 0 & & state - > ofs ! = 0 ) {
/* return a short read */
* _vector = NULL ;
* count = 0 ;
return 0 ;
}
if ( pending = = 0 ) {
/* we want at least one byte and recheck again */
wanted = 1 ;
} else {
size_t missing = state - > len - state - > ofs ;
if ( pending > missing ) {
/* there's more available */
state - > remaining = pending - missing ;
wanted = missing ;
} else {
/* read what we can get and recheck in the next cycle */
wanted = pending ;
}
}
vector = talloc_array ( mem_ctx , struct iovec , 1 ) ;
if ( ! vector ) {
return - 1 ;
}
2010-06-29 22:33:32 +02:00
vector [ 0 ] . iov_base = ( char * ) ( state - > buf + state - > ofs ) ;
2009-08-11 14:50:36 +02:00
vector [ 0 ] . iov_len = wanted ;
state - > ofs + = wanted ;
* _vector = vector ;
* count = 1 ;
return 0 ;
2006-01-28 20:08:03 +00:00
}
2009-08-11 14:50:36 +02:00
struct ipc_read_state {
struct ipc_private * ipriv ;
struct pipe_state * p ;
struct ntvfs_request * req ;
union smb_read * rd ;
struct ipc_readv_next_vector_state next_vector ;
} ;
static void ipc_read_done ( struct tevent_req * subreq ) ;
2003-08-13 01:53:07 +00:00
/*
read from a file
*/
2004-09-29 13:17:09 +00:00
static NTSTATUS ipc_read ( struct ntvfs_module_context * ntvfs ,
2006-03-10 14:31:17 +00:00
struct ntvfs_request * req , union smb_read * rd )
2003-08-13 01:53:07 +00:00
{
2009-08-11 14:50:36 +02:00
struct ipc_private * ipriv = talloc_get_type_abort ( ntvfs - > private_data ,
struct ipc_private ) ;
2003-12-11 09:07:45 +00:00
struct pipe_state * p ;
2009-08-11 14:50:36 +02:00
struct ipc_read_state * state ;
struct tevent_req * subreq ;
2003-12-11 09:07:45 +00:00
r3081: several updates to ntvfs and server side async request handling in
preparation for the full share modes and ntcreatex code that I am
working on.
highlights include:
- changed the way a backend determines if it is allowed to process a
request asynchronously. The previous method of looking at the
send_fn caused problems when an intermediate ntvfs module disabled
it, and the caller then wanted to finished processing using this
function. The new method is a REQ_CONTROL_MAY_ASYNC flag in
req->control_flags, which is also a bit easier to read
- fixed 2 bugs in the readbraw server code. One related to trying to
answer a readbraw with smb signing (which can't work, and crashed
our signing code), the second related to error handling, which
attempted to send a normal SMB error packet, when readbraw must
send a 0 read reply (as it has no header)
- added several more ntvfs_generic.c generic mapping functions. This
means that backends no longer need to implement such esoteric
functions as SMBwriteunlock() if they don't want to. The backend
can just request the mapping layer turn it into a write followed by
an unlock. This makes the backends considerably simpler as they
only need to implement one style of each function for lock, read,
write, open etc, rather than the full host of functions that SMB
provides. A backend can still choose to implement them
individually, of course, and the CIFS backend does that.
- simplified the generic structures to make them identical to the
principal call for several common SMB calls (such as
RAW_WRITE_GENERIC now being an alias for RAW_WRITE_WRITEX).
- started rewriting the pvfs_open() code in preparation for the full
ntcreatex semantics.
- in pvfs_open and ipc_open, initially allocate the open file
structure as a child of the request, so on error we don't need to
clean up. Then when we are going to succeed the open steal the
pointer into the long term backend context. This makes for much
simpler error handling (and fixes some bugs)
- use a destructor in the ipc backend to make sure that everthing is
cleaned up on receive error conditions.
- switched the ipc backend to using idtree for fnum allocation
- in the ntvfs_generic mapping routines, use a allocated secondary
structure not a stack structure to ensure the request pointer
remains valid even if the backend replies async.
(This used to be commit 3457c1836c09c82956697eb21627dfa2ed37682e)
2004-10-20 08:28:31 +00:00
if ( rd - > generic . level ! = RAW_READ_GENERIC ) {
2006-03-10 14:31:17 +00:00
return ntvfs_map_read ( ntvfs , req , rd ) ;
2003-12-11 09:07:45 +00:00
}
2009-02-02 08:33:21 +01:00
p = pipe_state_find ( ipriv , rd - > readx . in . file . ntvfs ) ;
2003-12-11 09:07:45 +00:00
if ( ! p ) {
return NT_STATUS_INVALID_HANDLE ;
}
2009-08-11 14:50:36 +02:00
state = talloc ( req , struct ipc_read_state ) ;
NT_STATUS_HAVE_NO_MEMORY ( state ) ;
state - > ipriv = ipriv ;
state - > p = p ;
state - > req = req ;
state - > rd = rd ;
/* rd->readx.out.data is already allocated */
ipc_readv_next_vector_init ( & state - > next_vector ,
rd - > readx . out . data ,
rd - > readx . in . maxcnt ) ;
subreq = tstream_readv_pdu_queue_send ( req ,
ipriv - > ntvfs - > ctx - > event_ctx ,
p - > npipe ,
p - > read_queue ,
ipc_readv_next_vector ,
& state - > next_vector ) ;
NT_STATUS_HAVE_NO_MEMORY ( subreq ) ;
tevent_req_set_callback ( subreq , ipc_read_done , state ) ;
req - > async_states - > state | = NTVFS_ASYNC_STATE_ASYNC ;
return NT_STATUS_OK ;
}
static void ipc_read_done ( struct tevent_req * subreq )
{
struct ipc_read_state * state =
tevent_req_callback_data ( subreq ,
struct ipc_read_state ) ;
struct ntvfs_request * req = state - > req ;
union smb_read * rd = state - > rd ;
int ret ;
int sys_errno ;
NTSTATUS status ;
ret = tstream_readv_pdu_queue_recv ( subreq , & sys_errno ) ;
TALLOC_FREE ( subreq ) ;
if ( ret = = - 1 ) {
2011-06-20 14:55:32 +10:00
status = map_nt_error_from_unix_common ( sys_errno ) ;
2009-08-11 14:50:36 +02:00
goto reply ;
2004-10-26 05:36:14 +00:00
}
2009-08-11 14:50:36 +02:00
status = NT_STATUS_OK ;
if ( state - > next_vector . remaining > 0 ) {
status = STATUS_BUFFER_OVERFLOW ;
2003-12-11 09:07:45 +00:00
}
2009-08-11 14:50:36 +02:00
rd - > readx . out . remaining = state - > next_vector . remaining ;
r3081: several updates to ntvfs and server side async request handling in
preparation for the full share modes and ntcreatex code that I am
working on.
highlights include:
- changed the way a backend determines if it is allowed to process a
request asynchronously. The previous method of looking at the
send_fn caused problems when an intermediate ntvfs module disabled
it, and the caller then wanted to finished processing using this
function. The new method is a REQ_CONTROL_MAY_ASYNC flag in
req->control_flags, which is also a bit easier to read
- fixed 2 bugs in the readbraw server code. One related to trying to
answer a readbraw with smb signing (which can't work, and crashed
our signing code), the second related to error handling, which
attempted to send a normal SMB error packet, when readbraw must
send a 0 read reply (as it has no header)
- added several more ntvfs_generic.c generic mapping functions. This
means that backends no longer need to implement such esoteric
functions as SMBwriteunlock() if they don't want to. The backend
can just request the mapping layer turn it into a write followed by
an unlock. This makes the backends considerably simpler as they
only need to implement one style of each function for lock, read,
write, open etc, rather than the full host of functions that SMB
provides. A backend can still choose to implement them
individually, of course, and the CIFS backend does that.
- simplified the generic structures to make them identical to the
principal call for several common SMB calls (such as
RAW_WRITE_GENERIC now being an alias for RAW_WRITE_WRITEX).
- started rewriting the pvfs_open() code in preparation for the full
ntcreatex semantics.
- in pvfs_open and ipc_open, initially allocate the open file
structure as a child of the request, so on error we don't need to
clean up. Then when we are going to succeed the open steal the
pointer into the long term backend context. This makes for much
simpler error handling (and fixes some bugs)
- use a destructor in the ipc backend to make sure that everthing is
cleaned up on receive error conditions.
- switched the ipc backend to using idtree for fnum allocation
- in the ntvfs_generic mapping routines, use a allocated secondary
structure not a stack structure to ensure the request pointer
remains valid even if the backend replies async.
(This used to be commit 3457c1836c09c82956697eb21627dfa2ed37682e)
2004-10-20 08:28:31 +00:00
rd - > readx . out . compaction_mode = 0 ;
2009-08-11 14:50:36 +02:00
rd - > readx . out . nread = ret ;
2003-12-11 09:07:45 +00:00
2009-08-11 14:50:36 +02:00
reply :
req - > async_states - > status = status ;
req - > async_states - > send_fn ( req ) ;
2003-08-13 01:53:07 +00:00
}
2009-08-11 14:50:36 +02:00
struct ipc_write_state {
struct ipc_private * ipriv ;
struct pipe_state * p ;
struct ntvfs_request * req ;
union smb_write * wr ;
struct iovec iov ;
} ;
static void ipc_write_done ( struct tevent_req * subreq ) ;
2003-08-13 01:53:07 +00:00
/*
write to a file
*/
2004-09-29 13:17:09 +00:00
static NTSTATUS ipc_write ( struct ntvfs_module_context * ntvfs ,
2006-03-10 14:31:17 +00:00
struct ntvfs_request * req , union smb_write * wr )
2003-08-13 01:53:07 +00:00
{
2009-08-11 14:50:36 +02:00
struct ipc_private * ipriv = talloc_get_type_abort ( ntvfs - > private_data ,
struct ipc_private ) ;
2003-12-11 09:07:45 +00:00
struct pipe_state * p ;
2009-08-11 14:50:36 +02:00
struct tevent_req * subreq ;
struct ipc_write_state * state ;
2003-12-11 09:07:45 +00:00
r3081: several updates to ntvfs and server side async request handling in
preparation for the full share modes and ntcreatex code that I am
working on.
highlights include:
- changed the way a backend determines if it is allowed to process a
request asynchronously. The previous method of looking at the
send_fn caused problems when an intermediate ntvfs module disabled
it, and the caller then wanted to finished processing using this
function. The new method is a REQ_CONTROL_MAY_ASYNC flag in
req->control_flags, which is also a bit easier to read
- fixed 2 bugs in the readbraw server code. One related to trying to
answer a readbraw with smb signing (which can't work, and crashed
our signing code), the second related to error handling, which
attempted to send a normal SMB error packet, when readbraw must
send a 0 read reply (as it has no header)
- added several more ntvfs_generic.c generic mapping functions. This
means that backends no longer need to implement such esoteric
functions as SMBwriteunlock() if they don't want to. The backend
can just request the mapping layer turn it into a write followed by
an unlock. This makes the backends considerably simpler as they
only need to implement one style of each function for lock, read,
write, open etc, rather than the full host of functions that SMB
provides. A backend can still choose to implement them
individually, of course, and the CIFS backend does that.
- simplified the generic structures to make them identical to the
principal call for several common SMB calls (such as
RAW_WRITE_GENERIC now being an alias for RAW_WRITE_WRITEX).
- started rewriting the pvfs_open() code in preparation for the full
ntcreatex semantics.
- in pvfs_open and ipc_open, initially allocate the open file
structure as a child of the request, so on error we don't need to
clean up. Then when we are going to succeed the open steal the
pointer into the long term backend context. This makes for much
simpler error handling (and fixes some bugs)
- use a destructor in the ipc backend to make sure that everthing is
cleaned up on receive error conditions.
- switched the ipc backend to using idtree for fnum allocation
- in the ntvfs_generic mapping routines, use a allocated secondary
structure not a stack structure to ensure the request pointer
remains valid even if the backend replies async.
(This used to be commit 3457c1836c09c82956697eb21627dfa2ed37682e)
2004-10-20 08:28:31 +00:00
if ( wr - > generic . level ! = RAW_WRITE_GENERIC ) {
2006-03-10 14:31:17 +00:00
return ntvfs_map_write ( ntvfs , req , wr ) ;
2003-12-11 09:07:45 +00:00
}
2009-02-02 08:33:21 +01:00
p = pipe_state_find ( ipriv , wr - > writex . in . file . ntvfs ) ;
2003-12-11 09:07:45 +00:00
if ( ! p ) {
return NT_STATUS_INVALID_HANDLE ;
}
2009-08-11 14:50:36 +02:00
state = talloc ( req , struct ipc_write_state ) ;
NT_STATUS_HAVE_NO_MEMORY ( state ) ;
state - > ipriv = ipriv ;
state - > p = p ;
state - > req = req ;
state - > wr = wr ;
state - > iov . iov_base = discard_const_p ( void , wr - > writex . in . data ) ;
state - > iov . iov_len = wr - > writex . in . count ;
subreq = tstream_writev_queue_send ( state ,
ipriv - > ntvfs - > ctx - > event_ctx ,
p - > npipe ,
p - > write_queue ,
& state - > iov , 1 ) ;
NT_STATUS_HAVE_NO_MEMORY ( subreq ) ;
tevent_req_set_callback ( subreq , ipc_write_done , state ) ;
req - > async_states - > state | = NTVFS_ASYNC_STATE_ASYNC ;
return NT_STATUS_OK ;
}
static void ipc_write_done ( struct tevent_req * subreq )
{
struct ipc_write_state * state =
tevent_req_callback_data ( subreq ,
struct ipc_write_state ) ;
struct ntvfs_request * req = state - > req ;
union smb_write * wr = state - > wr ;
int ret ;
int sys_errno ;
NTSTATUS status ;
ret = tstream_writev_queue_recv ( subreq , & sys_errno ) ;
TALLOC_FREE ( subreq ) ;
if ( ret = = - 1 ) {
2011-06-20 14:55:32 +10:00
status = map_nt_error_from_unix_common ( sys_errno ) ;
2009-08-11 14:50:36 +02:00
goto reply ;
2003-12-11 09:07:45 +00:00
}
2009-08-11 14:50:36 +02:00
status = NT_STATUS_OK ;
wr - > writex . out . nwritten = ret ;
r3081: several updates to ntvfs and server side async request handling in
preparation for the full share modes and ntcreatex code that I am
working on.
highlights include:
- changed the way a backend determines if it is allowed to process a
request asynchronously. The previous method of looking at the
send_fn caused problems when an intermediate ntvfs module disabled
it, and the caller then wanted to finished processing using this
function. The new method is a REQ_CONTROL_MAY_ASYNC flag in
req->control_flags, which is also a bit easier to read
- fixed 2 bugs in the readbraw server code. One related to trying to
answer a readbraw with smb signing (which can't work, and crashed
our signing code), the second related to error handling, which
attempted to send a normal SMB error packet, when readbraw must
send a 0 read reply (as it has no header)
- added several more ntvfs_generic.c generic mapping functions. This
means that backends no longer need to implement such esoteric
functions as SMBwriteunlock() if they don't want to. The backend
can just request the mapping layer turn it into a write followed by
an unlock. This makes the backends considerably simpler as they
only need to implement one style of each function for lock, read,
write, open etc, rather than the full host of functions that SMB
provides. A backend can still choose to implement them
individually, of course, and the CIFS backend does that.
- simplified the generic structures to make them identical to the
principal call for several common SMB calls (such as
RAW_WRITE_GENERIC now being an alias for RAW_WRITE_WRITEX).
- started rewriting the pvfs_open() code in preparation for the full
ntcreatex semantics.
- in pvfs_open and ipc_open, initially allocate the open file
structure as a child of the request, so on error we don't need to
clean up. Then when we are going to succeed the open steal the
pointer into the long term backend context. This makes for much
simpler error handling (and fixes some bugs)
- use a destructor in the ipc backend to make sure that everthing is
cleaned up on receive error conditions.
- switched the ipc backend to using idtree for fnum allocation
- in the ntvfs_generic mapping routines, use a allocated secondary
structure not a stack structure to ensure the request pointer
remains valid even if the backend replies async.
(This used to be commit 3457c1836c09c82956697eb21627dfa2ed37682e)
2004-10-20 08:28:31 +00:00
wr - > writex . out . remaining = 0 ;
2003-12-11 09:07:45 +00:00
2009-08-11 14:50:36 +02:00
reply :
req - > async_states - > status = status ;
req - > async_states - > send_fn ( req ) ;
2003-08-13 01:53:07 +00:00
}
/*
seek in a file
*/
2004-09-29 13:17:09 +00:00
static NTSTATUS ipc_seek ( struct ntvfs_module_context * ntvfs ,
2006-03-10 20:49:20 +00:00
struct ntvfs_request * req ,
union smb_seek * io )
2003-08-13 01:53:07 +00:00
{
return NT_STATUS_ACCESS_DENIED ;
}
/*
flush a file
*/
2004-09-29 13:17:09 +00:00
static NTSTATUS ipc_flush ( struct ntvfs_module_context * ntvfs ,
2006-03-10 20:49:20 +00:00
struct ntvfs_request * req ,
union smb_flush * io )
2003-08-13 01:53:07 +00:00
{
return NT_STATUS_ACCESS_DENIED ;
}
/*
close a file
*/
2004-09-29 13:17:09 +00:00
static NTSTATUS ipc_close ( struct ntvfs_module_context * ntvfs ,
2006-03-10 14:31:17 +00:00
struct ntvfs_request * req , union smb_close * io )
2003-08-13 01:53:07 +00:00
{
2009-08-11 14:50:36 +02:00
struct ipc_private * ipriv = talloc_get_type_abort ( ntvfs - > private_data ,
struct ipc_private ) ;
2003-12-10 22:24:33 +00:00
struct pipe_state * p ;
2014-10-18 10:42:00 +02:00
if ( io - > generic . level ! = RAW_CLOSE_GENERIC ) {
2006-03-10 14:31:17 +00:00
return ntvfs_map_close ( ntvfs , req , io ) ;
2003-12-10 22:24:33 +00:00
}
2014-10-18 10:42:00 +02:00
ZERO_STRUCT ( io - > generic . out ) ;
p = pipe_state_find ( ipriv , io - > generic . in . file . ntvfs ) ;
2003-12-10 22:24:33 +00:00
if ( ! p ) {
return NT_STATUS_INVALID_HANDLE ;
}
r3081: several updates to ntvfs and server side async request handling in
preparation for the full share modes and ntcreatex code that I am
working on.
highlights include:
- changed the way a backend determines if it is allowed to process a
request asynchronously. The previous method of looking at the
send_fn caused problems when an intermediate ntvfs module disabled
it, and the caller then wanted to finished processing using this
function. The new method is a REQ_CONTROL_MAY_ASYNC flag in
req->control_flags, which is also a bit easier to read
- fixed 2 bugs in the readbraw server code. One related to trying to
answer a readbraw with smb signing (which can't work, and crashed
our signing code), the second related to error handling, which
attempted to send a normal SMB error packet, when readbraw must
send a 0 read reply (as it has no header)
- added several more ntvfs_generic.c generic mapping functions. This
means that backends no longer need to implement such esoteric
functions as SMBwriteunlock() if they don't want to. The backend
can just request the mapping layer turn it into a write followed by
an unlock. This makes the backends considerably simpler as they
only need to implement one style of each function for lock, read,
write, open etc, rather than the full host of functions that SMB
provides. A backend can still choose to implement them
individually, of course, and the CIFS backend does that.
- simplified the generic structures to make them identical to the
principal call for several common SMB calls (such as
RAW_WRITE_GENERIC now being an alias for RAW_WRITE_WRITEX).
- started rewriting the pvfs_open() code in preparation for the full
ntcreatex semantics.
- in pvfs_open and ipc_open, initially allocate the open file
structure as a child of the request, so on error we don't need to
clean up. Then when we are going to succeed the open steal the
pointer into the long term backend context. This makes for much
simpler error handling (and fixes some bugs)
- use a destructor in the ipc backend to make sure that everthing is
cleaned up on receive error conditions.
- switched the ipc backend to using idtree for fnum allocation
- in the ntvfs_generic mapping routines, use a allocated secondary
structure not a stack structure to ensure the request pointer
remains valid even if the backend replies async.
(This used to be commit 3457c1836c09c82956697eb21627dfa2ed37682e)
2004-10-20 08:28:31 +00:00
talloc_free ( p ) ;
2003-12-10 22:24:33 +00:00
return NT_STATUS_OK ;
2003-08-13 01:53:07 +00:00
}
/*
2004-09-26 11:30:20 +00:00
exit - closing files
2003-08-13 01:53:07 +00:00
*/
2004-09-29 13:17:09 +00:00
static NTSTATUS ipc_exit ( struct ntvfs_module_context * ntvfs ,
2006-03-10 14:31:17 +00:00
struct ntvfs_request * req )
2003-08-13 01:53:07 +00:00
{
2009-08-11 14:50:36 +02:00
struct ipc_private * ipriv = talloc_get_type_abort ( ntvfs - > private_data ,
struct ipc_private ) ;
2004-09-26 11:30:20 +00:00
struct pipe_state * p , * next ;
2009-02-02 08:33:21 +01:00
for ( p = ipriv - > pipe_list ; p ; p = next ) {
2004-09-26 11:30:20 +00:00
next = p - > next ;
2006-05-20 08:15:22 +00:00
if ( p - > handle - > session_info = = req - > session_info & &
p - > handle - > smbpid = = req - > smbpid ) {
r3081: several updates to ntvfs and server side async request handling in
preparation for the full share modes and ntcreatex code that I am
working on.
highlights include:
- changed the way a backend determines if it is allowed to process a
request asynchronously. The previous method of looking at the
send_fn caused problems when an intermediate ntvfs module disabled
it, and the caller then wanted to finished processing using this
function. The new method is a REQ_CONTROL_MAY_ASYNC flag in
req->control_flags, which is also a bit easier to read
- fixed 2 bugs in the readbraw server code. One related to trying to
answer a readbraw with smb signing (which can't work, and crashed
our signing code), the second related to error handling, which
attempted to send a normal SMB error packet, when readbraw must
send a 0 read reply (as it has no header)
- added several more ntvfs_generic.c generic mapping functions. This
means that backends no longer need to implement such esoteric
functions as SMBwriteunlock() if they don't want to. The backend
can just request the mapping layer turn it into a write followed by
an unlock. This makes the backends considerably simpler as they
only need to implement one style of each function for lock, read,
write, open etc, rather than the full host of functions that SMB
provides. A backend can still choose to implement them
individually, of course, and the CIFS backend does that.
- simplified the generic structures to make them identical to the
principal call for several common SMB calls (such as
RAW_WRITE_GENERIC now being an alias for RAW_WRITE_WRITEX).
- started rewriting the pvfs_open() code in preparation for the full
ntcreatex semantics.
- in pvfs_open and ipc_open, initially allocate the open file
structure as a child of the request, so on error we don't need to
clean up. Then when we are going to succeed the open steal the
pointer into the long term backend context. This makes for much
simpler error handling (and fixes some bugs)
- use a destructor in the ipc backend to make sure that everthing is
cleaned up on receive error conditions.
- switched the ipc backend to using idtree for fnum allocation
- in the ntvfs_generic mapping routines, use a allocated secondary
structure not a stack structure to ensure the request pointer
remains valid even if the backend replies async.
(This used to be commit 3457c1836c09c82956697eb21627dfa2ed37682e)
2004-10-20 08:28:31 +00:00
talloc_free ( p ) ;
2004-09-26 11:30:20 +00:00
}
}
return NT_STATUS_OK ;
}
/*
logoff - closing files open by the user
*/
2004-09-29 13:17:09 +00:00
static NTSTATUS ipc_logoff ( struct ntvfs_module_context * ntvfs ,
2006-03-10 14:31:17 +00:00
struct ntvfs_request * req )
2004-09-26 11:30:20 +00:00
{
2009-08-11 14:50:36 +02:00
struct ipc_private * ipriv = talloc_get_type_abort ( ntvfs - > private_data ,
struct ipc_private ) ;
2004-09-26 11:30:20 +00:00
struct pipe_state * p , * next ;
2009-02-02 08:33:21 +01:00
for ( p = ipriv - > pipe_list ; p ; p = next ) {
2004-09-26 11:30:20 +00:00
next = p - > next ;
2006-05-20 08:15:22 +00:00
if ( p - > handle - > session_info = = req - > session_info ) {
r3081: several updates to ntvfs and server side async request handling in
preparation for the full share modes and ntcreatex code that I am
working on.
highlights include:
- changed the way a backend determines if it is allowed to process a
request asynchronously. The previous method of looking at the
send_fn caused problems when an intermediate ntvfs module disabled
it, and the caller then wanted to finished processing using this
function. The new method is a REQ_CONTROL_MAY_ASYNC flag in
req->control_flags, which is also a bit easier to read
- fixed 2 bugs in the readbraw server code. One related to trying to
answer a readbraw with smb signing (which can't work, and crashed
our signing code), the second related to error handling, which
attempted to send a normal SMB error packet, when readbraw must
send a 0 read reply (as it has no header)
- added several more ntvfs_generic.c generic mapping functions. This
means that backends no longer need to implement such esoteric
functions as SMBwriteunlock() if they don't want to. The backend
can just request the mapping layer turn it into a write followed by
an unlock. This makes the backends considerably simpler as they
only need to implement one style of each function for lock, read,
write, open etc, rather than the full host of functions that SMB
provides. A backend can still choose to implement them
individually, of course, and the CIFS backend does that.
- simplified the generic structures to make them identical to the
principal call for several common SMB calls (such as
RAW_WRITE_GENERIC now being an alias for RAW_WRITE_WRITEX).
- started rewriting the pvfs_open() code in preparation for the full
ntcreatex semantics.
- in pvfs_open and ipc_open, initially allocate the open file
structure as a child of the request, so on error we don't need to
clean up. Then when we are going to succeed the open steal the
pointer into the long term backend context. This makes for much
simpler error handling (and fixes some bugs)
- use a destructor in the ipc backend to make sure that everthing is
cleaned up on receive error conditions.
- switched the ipc backend to using idtree for fnum allocation
- in the ntvfs_generic mapping routines, use a allocated secondary
structure not a stack structure to ensure the request pointer
remains valid even if the backend replies async.
(This used to be commit 3457c1836c09c82956697eb21627dfa2ed37682e)
2004-10-20 08:28:31 +00:00
talloc_free ( p ) ;
2004-09-26 11:30:20 +00:00
}
}
return NT_STATUS_OK ;
2003-08-13 01:53:07 +00:00
}
2004-10-18 13:27:22 +00:00
/*
setup for an async call
*/
static NTSTATUS ipc_async_setup ( struct ntvfs_module_context * ntvfs ,
2006-03-10 14:31:17 +00:00
struct ntvfs_request * req ,
2009-02-02 08:33:21 +01:00
void * private_data )
2004-10-18 13:27:22 +00:00
{
return NT_STATUS_OK ;
}
2004-11-04 11:28:38 +00:00
/*
cancel an async call
*/
static NTSTATUS ipc_cancel ( struct ntvfs_module_context * ntvfs ,
2006-03-10 14:31:17 +00:00
struct ntvfs_request * req )
2004-11-04 11:28:38 +00:00
{
return NT_STATUS_UNSUCCESSFUL ;
}
2003-08-13 01:53:07 +00:00
/*
lock a byte range
*/
2004-09-29 13:17:09 +00:00
static NTSTATUS ipc_lock ( struct ntvfs_module_context * ntvfs ,
2006-03-10 14:31:17 +00:00
struct ntvfs_request * req , union smb_lock * lck )
2003-08-13 01:53:07 +00:00
{
return NT_STATUS_ACCESS_DENIED ;
}
/*
set info on a open file
*/
2004-09-29 13:17:09 +00:00
static NTSTATUS ipc_setfileinfo ( struct ntvfs_module_context * ntvfs ,
2006-03-10 14:31:17 +00:00
struct ntvfs_request * req , union smb_setfileinfo * info )
2003-08-13 01:53:07 +00:00
{
return NT_STATUS_ACCESS_DENIED ;
}
/*
query info on a open file
*/
2004-09-29 13:17:09 +00:00
static NTSTATUS ipc_qfileinfo ( struct ntvfs_module_context * ntvfs ,
2006-03-10 14:31:17 +00:00
struct ntvfs_request * req , union smb_fileinfo * info )
2003-08-13 01:53:07 +00:00
{
2009-08-11 14:50:36 +02:00
struct ipc_private * ipriv = talloc_get_type_abort ( ntvfs - > private_data ,
struct ipc_private ) ;
2009-02-02 08:33:21 +01:00
struct pipe_state * p = pipe_state_find ( ipriv , info - > generic . in . file . ntvfs ) ;
2007-05-15 06:51:18 +00:00
if ( ! p ) {
return NT_STATUS_INVALID_HANDLE ;
}
2007-05-15 01:21:20 +00:00
switch ( info - > generic . level ) {
case RAW_FILEINFO_GENERIC :
{
ZERO_STRUCT ( info - > generic . out ) ;
info - > generic . out . attrib = FILE_ATTRIBUTE_NORMAL ;
info - > generic . out . fname . s = strrchr ( p - > pipe_name , ' \\ ' ) ;
info - > generic . out . alloc_size = 4096 ;
info - > generic . out . nlink = 1 ;
/* What the heck? Match Win2k3: IPC$ pipes are delete pending */
info - > generic . out . delete_pending = 1 ;
return NT_STATUS_OK ;
}
case RAW_FILEINFO_ALT_NAME_INFO :
case RAW_FILEINFO_ALT_NAME_INFORMATION :
case RAW_FILEINFO_STREAM_INFO :
case RAW_FILEINFO_STREAM_INFORMATION :
case RAW_FILEINFO_COMPRESSION_INFO :
case RAW_FILEINFO_COMPRESSION_INFORMATION :
case RAW_FILEINFO_NETWORK_OPEN_INFORMATION :
case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION :
return NT_STATUS_INVALID_PARAMETER ;
case RAW_FILEINFO_ALL_EAS :
return NT_STATUS_ACCESS_DENIED ;
default :
return ntvfs_map_qfileinfo ( ntvfs , req , info ) ;
}
2003-08-13 01:53:07 +00:00
}
/*
return filesystem info
*/
2004-09-29 13:17:09 +00:00
static NTSTATUS ipc_fsinfo ( struct ntvfs_module_context * ntvfs ,
2006-03-10 14:31:17 +00:00
struct ntvfs_request * req , union smb_fsinfo * fs )
2003-08-13 01:53:07 +00:00
{
return NT_STATUS_ACCESS_DENIED ;
}
/*
return print queue info
*/
2004-09-29 13:17:09 +00:00
static NTSTATUS ipc_lpq ( struct ntvfs_module_context * ntvfs ,
2006-03-10 14:31:17 +00:00
struct ntvfs_request * req , union smb_lpq * lpq )
2003-08-13 01:53:07 +00:00
{
return NT_STATUS_ACCESS_DENIED ;
}
/*
list files in a directory matching a wildcard pattern
*/
2004-09-29 13:17:09 +00:00
static NTSTATUS ipc_search_first ( struct ntvfs_module_context * ntvfs ,
2006-03-10 14:31:17 +00:00
struct ntvfs_request * req , union smb_search_first * io ,
2003-08-13 01:53:07 +00:00
void * search_private ,
2007-10-06 22:28:14 +00:00
bool ( * callback ) ( void * , const union smb_search_data * ) )
2003-08-13 01:53:07 +00:00
{
return NT_STATUS_ACCESS_DENIED ;
}
/*
continue listing files in a directory
*/
2004-09-29 13:17:09 +00:00
static NTSTATUS ipc_search_next ( struct ntvfs_module_context * ntvfs ,
2006-03-10 14:31:17 +00:00
struct ntvfs_request * req , union smb_search_next * io ,
2003-08-13 01:53:07 +00:00
void * search_private ,
2007-10-06 22:28:14 +00:00
bool ( * callback ) ( void * , const union smb_search_data * ) )
2003-08-13 01:53:07 +00:00
{
return NT_STATUS_ACCESS_DENIED ;
}
/*
end listing files in a directory
*/
2004-09-29 13:17:09 +00:00
static NTSTATUS ipc_search_close ( struct ntvfs_module_context * ntvfs ,
2006-03-10 14:31:17 +00:00
struct ntvfs_request * req , union smb_search_close * io )
2003-08-13 01:53:07 +00:00
{
return NT_STATUS_ACCESS_DENIED ;
}
2009-08-11 14:50:36 +02:00
struct ipc_trans_state {
struct ipc_private * ipriv ;
struct pipe_state * p ;
struct ntvfs_request * req ;
struct smb_trans2 * trans ;
struct iovec writev_iov ;
struct ipc_readv_next_vector_state next_vector ;
} ;
2006-01-28 20:08:03 +00:00
2009-08-11 14:50:36 +02:00
static void ipc_trans_writev_done ( struct tevent_req * subreq ) ;
static void ipc_trans_readv_done ( struct tevent_req * subreq ) ;
2006-01-28 20:08:03 +00:00
/* SMBtrans - handle a DCERPC command */
static NTSTATUS ipc_dcerpc_cmd ( struct ntvfs_module_context * ntvfs ,
2006-03-10 14:31:17 +00:00
struct ntvfs_request * req , struct smb_trans2 * trans )
2003-12-11 09:07:45 +00:00
{
2009-08-11 14:50:36 +02:00
struct ipc_private * ipriv = talloc_get_type_abort ( ntvfs - > private_data ,
struct ipc_private ) ;
2006-01-28 12:58:38 +00:00
struct pipe_state * p ;
2006-05-20 08:15:22 +00:00
DATA_BLOB fnum_key ;
2006-05-25 04:46:38 +00:00
uint16_t fnum ;
2009-08-11 14:50:36 +02:00
struct ipc_trans_state * state ;
struct tevent_req * subreq ;
2003-12-11 09:07:45 +00:00
2006-05-30 20:23:55 +00:00
/*
* the fnum is in setup [ 1 ] , a 16 bit value
* the setup [ * ] values are already in host byteorder
* but ntvfs_handle_search_by_wire_key ( ) expects
* network byteorder
*/
2006-05-25 04:46:38 +00:00
SSVAL ( & fnum , 0 , trans - > in . setup [ 1 ] ) ;
fnum_key = data_blob_const ( & fnum , 2 ) ;
2006-05-20 08:15:22 +00:00
2009-02-02 08:33:21 +01:00
p = pipe_state_find_key ( ipriv , req , & fnum_key ) ;
2005-07-01 06:05:49 +00:00
if ( ! p ) {
return NT_STATUS_INVALID_HANDLE ;
}
2003-12-11 09:07:45 +00:00
2006-01-28 20:08:03 +00:00
/*
2009-08-11 14:50:36 +02:00
* Trans requests are only allowed
* if no other Trans or Read is active
*/
if ( tevent_queue_length ( p - > read_queue ) > 0 ) {
return NT_STATUS_PIPE_BUSY ;
2005-07-01 06:05:49 +00:00
}
2003-12-11 09:07:45 +00:00
2009-08-11 14:50:36 +02:00
state = talloc ( req , struct ipc_trans_state ) ;
NT_STATUS_HAVE_NO_MEMORY ( state ) ;
2003-12-11 09:07:45 +00:00
trans - > out . setup_count = 0 ;
trans - > out . setup = NULL ;
trans - > out . params = data_blob ( NULL , 0 ) ;
2009-08-11 14:50:36 +02:00
trans - > out . data = data_blob_talloc ( req , NULL , trans - > in . max_data ) ;
NT_STATUS_HAVE_NO_MEMORY ( trans - > out . data . data ) ;
state - > ipriv = ipriv ;
state - > p = p ;
state - > req = req ;
state - > trans = trans ;
2010-06-29 22:33:32 +02:00
state - > writev_iov . iov_base = ( char * ) trans - > in . data . data ;
2009-08-11 14:50:36 +02:00
state - > writev_iov . iov_len = trans - > in . data . length ;
ipc_readv_next_vector_init ( & state - > next_vector ,
trans - > out . data . data ,
trans - > out . data . length ) ;
subreq = tstream_writev_queue_send ( state ,
ipriv - > ntvfs - > ctx - > event_ctx ,
p - > npipe ,
p - > write_queue ,
& state - > writev_iov , 1 ) ;
NT_STATUS_HAVE_NO_MEMORY ( subreq ) ;
tevent_req_set_callback ( subreq , ipc_trans_writev_done , state ) ;
req - > async_states - > state | = NTVFS_ASYNC_STATE_ASYNC ;
return NT_STATUS_OK ;
}
2003-12-11 09:07:45 +00:00
2009-08-11 14:50:36 +02:00
static void ipc_trans_writev_done ( struct tevent_req * subreq )
{
struct ipc_trans_state * state =
tevent_req_callback_data ( subreq ,
struct ipc_trans_state ) ;
struct ipc_private * ipriv = state - > ipriv ;
struct pipe_state * p = state - > p ;
struct ntvfs_request * req = state - > req ;
int ret ;
int sys_errno ;
NTSTATUS status ;
ret = tstream_writev_queue_recv ( subreq , & sys_errno ) ;
TALLOC_FREE ( subreq ) ;
if ( ret = = 0 ) {
status = NT_STATUS_PIPE_DISCONNECTED ;
goto reply ;
} else if ( ret = = - 1 ) {
2011-06-20 14:55:32 +10:00
status = map_nt_error_from_unix_common ( sys_errno ) ;
2009-08-11 14:50:36 +02:00
goto reply ;
}
subreq = tstream_readv_pdu_queue_send ( state ,
ipriv - > ntvfs - > ctx - > event_ctx ,
p - > npipe ,
p - > read_queue ,
ipc_readv_next_vector ,
& state - > next_vector ) ;
if ( ! subreq ) {
status = NT_STATUS_NO_MEMORY ;
goto reply ;
}
tevent_req_set_callback ( subreq , ipc_trans_readv_done , state ) ;
return ;
reply :
req - > async_states - > status = status ;
req - > async_states - > send_fn ( req ) ;
2003-12-11 09:07:45 +00:00
}
2009-08-11 14:50:36 +02:00
static void ipc_trans_readv_done ( struct tevent_req * subreq )
{
struct ipc_trans_state * state =
tevent_req_callback_data ( subreq ,
struct ipc_trans_state ) ;
struct ntvfs_request * req = state - > req ;
struct smb_trans2 * trans = state - > trans ;
int ret ;
int sys_errno ;
NTSTATUS status ;
ret = tstream_readv_pdu_queue_recv ( subreq , & sys_errno ) ;
TALLOC_FREE ( subreq ) ;
if ( ret = = - 1 ) {
2011-06-20 14:55:32 +10:00
status = map_nt_error_from_unix_common ( sys_errno ) ;
2009-08-11 14:50:36 +02:00
goto reply ;
}
status = NT_STATUS_OK ;
if ( state - > next_vector . remaining > 0 ) {
status = STATUS_BUFFER_OVERFLOW ;
}
trans - > out . data . length = ret ;
reply :
req - > async_states - > status = status ;
req - > async_states - > send_fn ( req ) ;
}
2006-01-28 20:08:03 +00:00
/* SMBtrans - set named pipe state */
static NTSTATUS ipc_set_nm_pipe_state ( struct ntvfs_module_context * ntvfs ,
2006-05-20 08:15:22 +00:00
struct ntvfs_request * req , struct smb_trans2 * trans )
2003-12-13 04:46:50 +00:00
{
2009-08-11 14:50:36 +02:00
struct ipc_private * ipriv = talloc_get_type_abort ( ntvfs - > private_data ,
struct ipc_private ) ;
2003-12-13 04:46:50 +00:00
struct pipe_state * p ;
2006-05-20 08:15:22 +00:00
DATA_BLOB fnum_key ;
2003-12-13 04:46:50 +00:00
/* the fnum is in setup[1] */
2006-05-20 08:15:22 +00:00
fnum_key = data_blob_const ( & trans - > in . setup [ 1 ] , sizeof ( trans - > in . setup [ 1 ] ) ) ;
2009-02-02 08:33:21 +01:00
p = pipe_state_find_key ( ipriv , req , & fnum_key ) ;
2003-12-13 04:46:50 +00:00
if ( ! p ) {
return NT_STATUS_INVALID_HANDLE ;
}
2006-01-28 20:08:03 +00:00
if ( trans - > in . params . length ! = 2 ) {
2003-12-13 04:46:50 +00:00
return NT_STATUS_INVALID_PARAMETER ;
}
2009-08-11 14:50:36 +02:00
/*
* TODO : pass this to the tstream_npa logic
*/
p - > device_state = SVAL ( trans - > in . params . data , 0 ) ;
2003-12-13 04:46:50 +00:00
trans - > out . setup_count = 0 ;
trans - > out . setup = NULL ;
trans - > out . params = data_blob ( NULL , 0 ) ;
2006-01-28 20:08:03 +00:00
trans - > out . data = data_blob ( NULL , 0 ) ;
2003-12-13 04:46:50 +00:00
return NT_STATUS_OK ;
}
2006-01-28 20:08:03 +00:00
2003-12-13 04:46:50 +00:00
/* SMBtrans - used to provide access to SMB pipes */
2004-09-29 13:17:09 +00:00
static NTSTATUS ipc_trans ( struct ntvfs_module_context * ntvfs ,
2006-03-10 14:31:17 +00:00
struct ntvfs_request * req , struct smb_trans2 * trans )
2003-12-13 04:46:50 +00:00
{
NTSTATUS status ;
2006-01-28 20:08:03 +00:00
if ( strequal ( trans - > in . trans_name , " \\ PIPE \\ LANMAN " ) )
2008-04-17 12:23:44 +02:00
return ipc_rap_call ( req , ntvfs - > ctx - > event_ctx , ntvfs - > ctx - > lp_ctx , trans ) ;
2006-01-28 20:08:03 +00:00
if ( trans - > in . setup_count ! = 2 ) {
return NT_STATUS_INVALID_PARAMETER ;
}
switch ( trans - > in . setup [ 0 ] ) {
case TRANSACT_SETNAMEDPIPEHANDLESTATE :
status = ipc_set_nm_pipe_state ( ntvfs , req , trans ) ;
break ;
case TRANSACT_DCERPCCMD :
status = ipc_dcerpc_cmd ( ntvfs , req , trans ) ;
break ;
default :
status = NT_STATUS_INVALID_PARAMETER ;
break ;
2003-12-13 04:46:50 +00:00
}
return status ;
}
2009-08-11 14:50:36 +02:00
struct ipc_ioctl_state {
struct ipc_private * ipriv ;
struct pipe_state * p ;
struct ntvfs_request * req ;
union smb_ioctl * io ;
struct iovec writev_iov ;
struct ipc_readv_next_vector_state next_vector ;
} ;
static void ipc_ioctl_writev_done ( struct tevent_req * subreq ) ;
static void ipc_ioctl_readv_done ( struct tevent_req * subreq ) ;
2006-07-09 09:56:13 +00:00
static NTSTATUS ipc_ioctl_smb2 ( struct ntvfs_module_context * ntvfs ,
struct ntvfs_request * req , union smb_ioctl * io )
{
2009-08-11 14:50:36 +02:00
struct ipc_private * ipriv = talloc_get_type_abort ( ntvfs - > private_data ,
struct ipc_private ) ;
2006-07-09 09:56:13 +00:00
struct pipe_state * p ;
2009-08-11 14:50:36 +02:00
struct ipc_ioctl_state * state ;
struct tevent_req * subreq ;
2006-07-09 09:56:13 +00:00
switch ( io - > smb2 . in . function ) {
case FSCTL_NAMED_PIPE_READ_WRITE :
break ;
default :
return NT_STATUS_FS_DRIVER_REQUIRED ;
}
2009-02-02 08:33:21 +01:00
p = pipe_state_find ( ipriv , io - > smb2 . in . file . ntvfs ) ;
2006-07-09 09:56:13 +00:00
if ( ! p ) {
return NT_STATUS_INVALID_HANDLE ;
}
/*
2009-08-11 14:50:36 +02:00
* Trans requests are only allowed
* if no other Trans or Read is active
*/
if ( tevent_queue_length ( p - > read_queue ) > 0 ) {
return NT_STATUS_PIPE_BUSY ;
}
state = talloc ( req , struct ipc_ioctl_state ) ;
NT_STATUS_HAVE_NO_MEMORY ( state ) ;
2006-07-09 09:56:13 +00:00
2019-01-08 15:52:35 +01:00
io - > smb2 . out . reserved = 0 ;
2006-07-09 09:56:13 +00:00
io - > smb2 . out . function = io - > smb2 . in . function ;
2019-01-08 15:52:35 +01:00
io - > smb2 . out . flags = 0 ;
io - > smb2 . out . reserved2 = 0 ;
2012-04-26 12:05:24 +02:00
io - > smb2 . out . in = data_blob_null ;
2019-01-08 15:52:35 +01:00
io - > smb2 . out . out = data_blob_talloc ( req , NULL , io - > smb2 . in . max_output_response ) ;
2009-08-11 14:50:36 +02:00
NT_STATUS_HAVE_NO_MEMORY ( io - > smb2 . out . out . data ) ;
2006-07-09 09:56:13 +00:00
2009-08-11 14:50:36 +02:00
state - > ipriv = ipriv ;
state - > p = p ;
state - > req = req ;
state - > io = io ;
2010-06-29 22:33:32 +02:00
state - > writev_iov . iov_base = ( char * ) io - > smb2 . in . out . data ;
2009-08-11 14:50:36 +02:00
state - > writev_iov . iov_len = io - > smb2 . in . out . length ;
ipc_readv_next_vector_init ( & state - > next_vector ,
io - > smb2 . out . out . data ,
io - > smb2 . out . out . length ) ;
subreq = tstream_writev_queue_send ( state ,
ipriv - > ntvfs - > ctx - > event_ctx ,
p - > npipe ,
p - > write_queue ,
& state - > writev_iov , 1 ) ;
NT_STATUS_HAVE_NO_MEMORY ( subreq ) ;
tevent_req_set_callback ( subreq , ipc_ioctl_writev_done , state ) ;
req - > async_states - > state | = NTVFS_ASYNC_STATE_ASYNC ;
return NT_STATUS_OK ;
}
static void ipc_ioctl_writev_done ( struct tevent_req * subreq )
{
struct ipc_ioctl_state * state =
tevent_req_callback_data ( subreq ,
struct ipc_ioctl_state ) ;
struct ipc_private * ipriv = state - > ipriv ;
struct pipe_state * p = state - > p ;
struct ntvfs_request * req = state - > req ;
int ret ;
int sys_errno ;
NTSTATUS status ;
ret = tstream_writev_queue_recv ( subreq , & sys_errno ) ;
TALLOC_FREE ( subreq ) ;
if ( ret = = - 1 ) {
2011-06-20 14:55:32 +10:00
status = map_nt_error_from_unix_common ( sys_errno ) ;
2009-08-11 14:50:36 +02:00
goto reply ;
}
subreq = tstream_readv_pdu_queue_send ( state ,
ipriv - > ntvfs - > ctx - > event_ctx ,
p - > npipe ,
p - > read_queue ,
ipc_readv_next_vector ,
& state - > next_vector ) ;
if ( ! subreq ) {
status = NT_STATUS_NO_MEMORY ;
goto reply ;
}
tevent_req_set_callback ( subreq , ipc_ioctl_readv_done , state ) ;
return ;
reply :
req - > async_states - > status = status ;
req - > async_states - > send_fn ( req ) ;
}
static void ipc_ioctl_readv_done ( struct tevent_req * subreq )
{
struct ipc_ioctl_state * state =
tevent_req_callback_data ( subreq ,
struct ipc_ioctl_state ) ;
struct ntvfs_request * req = state - > req ;
union smb_ioctl * io = state - > io ;
int ret ;
int sys_errno ;
NTSTATUS status ;
ret = tstream_readv_pdu_queue_recv ( subreq , & sys_errno ) ;
TALLOC_FREE ( subreq ) ;
if ( ret = = - 1 ) {
2011-06-20 14:55:32 +10:00
status = map_nt_error_from_unix_common ( sys_errno ) ;
2009-08-11 14:50:36 +02:00
goto reply ;
}
status = NT_STATUS_OK ;
if ( state - > next_vector . remaining > 0 ) {
status = STATUS_BUFFER_OVERFLOW ;
}
io - > smb2 . out . out . length = ret ;
reply :
req - > async_states - > status = status ;
req - > async_states - > send_fn ( req ) ;
2006-07-09 09:56:13 +00:00
}
/*
ioctl interface
*/
static NTSTATUS ipc_ioctl ( struct ntvfs_module_context * ntvfs ,
struct ntvfs_request * req , union smb_ioctl * io )
{
switch ( io - > generic . level ) {
case RAW_IOCTL_SMB2 :
return ipc_ioctl_smb2 ( ntvfs , req , io ) ;
2006-07-10 14:01:53 +00:00
case RAW_IOCTL_SMB2_NO_HANDLE :
return NT_STATUS_FS_DRIVER_REQUIRED ;
2006-07-09 09:56:13 +00:00
default :
return NT_STATUS_ACCESS_DENIED ;
}
}
2006-01-28 20:08:03 +00:00
2003-08-13 01:53:07 +00:00
/*
2023-08-03 14:40:03 +02:00
initialise the IPC backend , registering ourselves with the ntvfs subsystem
2003-08-13 01:53:07 +00:00
*/
2017-04-20 12:24:43 -07:00
NTSTATUS ntvfs_ipc_init ( TALLOC_CTX * ctx )
2003-08-13 01:53:07 +00:00
{
2003-11-25 03:15:26 +00:00
NTSTATUS ret ;
2003-08-13 01:53:07 +00:00
struct ntvfs_ops ops ;
2006-04-24 01:26:31 +00:00
NTVFS_CURRENT_CRITICAL_SIZES ( vers ) ;
2006-01-28 20:08:03 +00:00
2003-08-13 01:53:07 +00:00
ZERO_STRUCT ( ops ) ;
2004-02-02 13:28:29 +00:00
/* fill in the name and type */
ops . name = " default " ;
2003-11-25 03:15:26 +00:00
ops . type = NTVFS_IPC ;
2004-02-02 13:28:29 +00:00
/* fill in all the operations */
2012-06-13 09:11:42 +02:00
ops . connect_fn = ipc_connect ;
ops . disconnect_fn = ipc_disconnect ;
ops . unlink_fn = ipc_unlink ;
ops . chkpath_fn = ipc_chkpath ;
ops . qpathinfo_fn = ipc_qpathinfo ;
ops . setpathinfo_fn = ipc_setpathinfo ;
ops . open_fn = ipc_open ;
ops . mkdir_fn = ipc_mkdir ;
ops . rmdir_fn = ipc_rmdir ;
ops . rename_fn = ipc_rename ;
ops . copy_fn = ipc_copy ;
ops . ioctl_fn = ipc_ioctl ;
ops . read_fn = ipc_read ;
ops . write_fn = ipc_write ;
ops . seek_fn = ipc_seek ;
ops . flush_fn = ipc_flush ;
ops . close_fn = ipc_close ;
ops . exit_fn = ipc_exit ;
ops . lock_fn = ipc_lock ;
ops . setfileinfo_fn = ipc_setfileinfo ;
ops . qfileinfo_fn = ipc_qfileinfo ;
ops . fsinfo_fn = ipc_fsinfo ;
ops . lpq_fn = ipc_lpq ;
ops . search_first_fn = ipc_search_first ;
ops . search_next_fn = ipc_search_next ;
ops . search_close_fn = ipc_search_close ;
ops . trans_fn = ipc_trans ;
ops . logoff_fn = ipc_logoff ;
ops . async_setup_fn = ipc_async_setup ;
ops . cancel_fn = ipc_cancel ;
2003-08-13 01:53:07 +00:00
/* register ourselves with the NTVFS subsystem. */
2006-04-24 01:26:31 +00:00
ret = ntvfs_register ( & ops , & vers ) ;
2003-08-13 01:53:07 +00:00
2003-11-25 03:15:26 +00:00
if ( ! NT_STATUS_IS_OK ( ret ) ) {
2003-08-13 01:53:07 +00:00
DEBUG ( 0 , ( " Failed to register IPC backend! \n " ) ) ;
2003-11-25 03:15:26 +00:00
return ret ;
2003-08-13 01:53:07 +00:00
}
2003-11-25 03:15:26 +00:00
return ret ;
2003-08-13 01:53:07 +00:00
}