2006-05-21 16:15:04 +04:00
/*
Unix SMB / CIFS implementation .
srvsvc pipe ntvfs helper functions
Copyright ( C ) Stefan ( metze ) Metzmacher 2006
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 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2006-05-21 16:15:04 +04: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 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2006-05-21 16:15:04 +04:00
*/
# include "includes.h"
2006-07-23 22:43:07 +04:00
# include "ntvfs/ntvfs.h"
2006-05-21 16:15:04 +04:00
# include "rpc_server/dcerpc_server.h"
2007-12-10 20:41:55 +03:00
# include "param/param.h"
2011-03-19 02:43:34 +03:00
# include "rpc_server/srvsvc/proto.h"
2006-05-21 16:15:04 +04:00
struct srvsvc_ntvfs_ctx {
struct ntvfs_context * ntvfs ;
} ;
2006-05-24 11:35:06 +04:00
static int srvsvc_ntvfs_ctx_destructor ( struct srvsvc_ntvfs_ctx * c )
2006-05-21 16:15:04 +04:00
{
ntvfs_disconnect ( c - > ntvfs ) ;
return 0 ;
}
NTSTATUS srvsvc_create_ntvfs_context ( struct dcesrv_call_state * dce_call ,
TALLOC_CTX * mem_ctx ,
const char * share ,
struct ntvfs_context * * _ntvfs )
{
NTSTATUS status ;
struct srvsvc_ntvfs_ctx * c ;
struct ntvfs_request * ntvfs_req ;
enum ntvfs_type type ;
2006-07-23 22:43:07 +04:00
struct share_context * sctx ;
struct share_config * scfg ;
const char * sharetype ;
2010-03-03 20:26:15 +03:00
union smb_tcon tcon ;
2010-04-26 15:27:51 +04:00
const struct tsocket_address * local_address ;
const struct tsocket_address * remote_address ;
2006-07-23 22:43:07 +04:00
2010-07-16 08:32:42 +04:00
status = share_get_context_by_name ( mem_ctx , lpcfg_share_backend ( dce_call - > conn - > dce_ctx - > lp_ctx ) , dce_call - > event_ctx , dce_call - > conn - > dce_ctx - > lp_ctx , & sctx ) ;
2006-07-23 22:43:07 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
2006-05-21 16:15:04 +04:00
2006-07-23 22:43:07 +04:00
status = share_get_config ( mem_ctx , sctx , share , & scfg ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2006-05-21 16:15:04 +04:00
DEBUG ( 0 , ( " srvsvc_create_ntvfs_context: couldn't find service %s \n " , share ) ) ;
2006-07-23 22:43:07 +04:00
return status ;
2006-05-21 16:15:04 +04:00
}
#if 0 /* TODO: fix access cecking */
if ( ! socket_check_access ( dce_call - > connection - > socket ,
2006-07-23 22:43:07 +04:00
scfg - > name ,
share_string_list_option ( scfg , SHARE_HOSTS_ALLOW ) ,
share_string_list_option ( scfg , SHARE_HOSTS_DENY ) ) ) {
2006-05-21 16:15:04 +04:00
return NT_STATUS_ACCESS_DENIED ;
}
# endif
/* work out what sort of connection this is */
2006-07-23 22:43:07 +04:00
sharetype = share_string_option ( scfg , SHARE_TYPE , SHARE_TYPE_DEFAULT ) ;
if ( sharetype & & strcmp ( sharetype , " IPC " ) = = 0 ) {
2006-05-21 16:15:04 +04:00
type = NTVFS_IPC ;
2006-07-23 22:43:07 +04:00
} else if ( sharetype & & strcmp ( sharetype , " PRINTER " ) ) {
2006-05-21 16:15:04 +04:00
type = NTVFS_PRINT ;
} else {
type = NTVFS_DISK ;
}
c = talloc ( mem_ctx , struct srvsvc_ntvfs_ctx ) ;
NT_STATUS_HAVE_NO_MEMORY ( c ) ;
/* init ntvfs function pointers */
2006-07-23 22:43:07 +04:00
status = ntvfs_init_connection ( c , scfg , type ,
2006-05-21 16:15:04 +04:00
PROTOCOL_NT1 ,
2008-03-06 17:14:08 +03:00
0 , /* ntvfs_client_caps */
2006-05-21 16:15:04 +04:00
dce_call - > event_ctx ,
dce_call - > conn - > msg_ctx ,
2007-12-09 01:32:43 +03:00
dce_call - > conn - > dce_ctx - > lp_ctx ,
2006-05-21 16:15:04 +04:00
dce_call - > conn - > server_id ,
& c - > ntvfs ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " srvsvc_create_ntvfs_context: ntvfs_init_connection failed for service %s \n " ,
2006-07-23 22:43:07 +04:00
scfg - > name ) ) ;
2006-05-21 16:15:04 +04:00
return status ;
}
talloc_set_destructor ( c , srvsvc_ntvfs_ctx_destructor ) ;
/*
* NOTE : we only set the addr callbacks as we ' re not interesseted in oplocks or in getting file handles
*/
2010-04-26 15:27:51 +04:00
local_address = dcesrv_connection_get_local_address ( dce_call - > conn ) ;
remote_address = dcesrv_connection_get_remote_address ( dce_call - > conn ) ;
status = ntvfs_set_addresses ( c - > ntvfs , local_address , remote_address ) ;
2006-05-21 16:15:04 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " srvsvc_create_ntvfs_context: NTVFS failed to set the addr callbacks! \n " ) ) ;
return status ;
}
ntvfs_req = ntvfs_request_create ( c - > ntvfs , mem_ctx ,
dce_call - > conn - > auth_state . session_info ,
0 , /* TODO: fill in PID */
dce_call - > time ,
NULL , NULL , 0 ) ;
NT_STATUS_HAVE_NO_MEMORY ( ntvfs_req ) ;
/* Invoke NTVFS connection hook */
2010-03-03 20:26:15 +03:00
tcon . tcon . level = RAW_TCON_TCON ;
ZERO_STRUCT ( tcon . tcon . in ) ;
2010-03-03 22:12:30 +03:00
tcon . tcon . in . service = scfg - > name ;
2010-03-03 20:26:15 +03:00
status = ntvfs_connect ( ntvfs_req , & tcon ) ;
2006-05-21 16:15:04 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " srvsvc_create_ntvfs_context: NTVFS ntvfs_connect() failed! \n " ) ) ;
return status ;
}
* _ntvfs = c - > ntvfs ;
return NT_STATUS_OK ;
}