2003-08-13 05:53:07 +04:00
/*
Unix SMB / CIFS implementation .
NTVFS utility code
2004-10-29 01:48:53 +04:00
Copyright ( C ) Stefan Metzmacher 2004
2003-08-13 05:53:07 +04: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 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2003-08-13 05:53:07 +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/>.
2003-08-13 05:53:07 +04:00
*/
/*
this implements common utility functions that many NTVFS backends may wish to use
*/
# include "includes.h"
2008-10-11 23:31:42 +04:00
# include "../lib/util/dlinklist.h"
2005-12-28 01:51:30 +03:00
# include "ntvfs/ntvfs.h"
2004-11-02 10:18:24 +03:00
2003-08-13 05:53:07 +04:00
2008-04-02 06:53:27 +04:00
struct ntvfs_request * ntvfs_request_create ( struct ntvfs_context * ctx , TALLOC_CTX * mem_ctx ,
2006-03-18 14:10:21 +03:00
struct auth_session_info * session_info ,
2006-07-11 22:15:42 +04:00
uint16_t smbpid ,
2006-03-18 14:10:21 +03:00
struct timeval request_time ,
void * private_data ,
void ( * send_fn ) ( struct ntvfs_request * ) ,
uint32_t state )
{
struct ntvfs_request * req ;
struct ntvfs_async_state * async ;
req = talloc ( mem_ctx , struct ntvfs_request ) ;
if ( ! req ) return NULL ;
req - > ctx = ctx ;
req - > async_states = NULL ;
req - > session_info = session_info ;
req - > smbpid = smbpid ;
2008-03-06 17:14:08 +03:00
req - > client_caps = ctx - > client_caps ;
2006-03-18 14:10:21 +03:00
req - > statistics . request_time = request_time ;
async = talloc ( req , struct ntvfs_async_state ) ;
if ( ! async ) goto failed ;
async - > state = state ;
async - > private_data = private_data ;
async - > send_fn = send_fn ;
async - > status = NT_STATUS_INTERNAL_ERROR ;
async - > ntvfs = NULL ;
DLIST_ADD ( req - > async_states , async ) ;
return req ;
failed :
2006-05-21 12:24:11 +04:00
talloc_free ( req ) ;
2006-03-18 14:10:21 +03:00
return NULL ;
}
2008-04-02 06:53:27 +04:00
NTSTATUS ntvfs_async_state_push ( struct ntvfs_module_context * ntvfs ,
2006-03-10 17:31:17 +03:00
struct ntvfs_request * req ,
2006-01-11 13:53:52 +03:00
void * private_data ,
2006-03-10 17:31:17 +03:00
void ( * send_fn ) ( struct ntvfs_request * ) )
2004-10-29 01:48:53 +04:00
{
struct ntvfs_async_state * async ;
2003-08-13 05:53:07 +04:00
2005-01-27 10:08:20 +03:00
async = talloc ( req , struct ntvfs_async_state ) ;
2006-03-18 14:10:21 +03:00
NT_STATUS_HAVE_NO_MEMORY ( async ) ;
2004-10-29 01:48:53 +04:00
async - > state = req - > async_states - > state ;
async - > private_data = private_data ;
async - > send_fn = send_fn ;
async - > status = NT_STATUS_INTERNAL_ERROR ;
async - > ntvfs = ntvfs ;
DLIST_ADD ( req - > async_states , async ) ;
return NT_STATUS_OK ;
}
2008-04-02 06:53:27 +04:00
void ntvfs_async_state_pop ( struct ntvfs_request * req )
2004-10-29 01:48:53 +04:00
{
struct ntvfs_async_state * async ;
async = req - > async_states ;
DLIST_REMOVE ( req - > async_states , async ) ;
req - > async_states - > state = async - > state ;
req - > async_states - > status = async - > status ;
talloc_free ( async ) ;
}
2006-05-20 12:15:22 +04:00
2008-04-02 06:53:27 +04:00
NTSTATUS ntvfs_handle_new ( struct ntvfs_module_context * ntvfs ,
2006-05-20 12:15:22 +04:00
struct ntvfs_request * req ,
struct ntvfs_handle * * h )
{
2006-05-21 12:29:56 +04:00
if ( ! ntvfs - > ctx - > handles . create_new ) {
return NT_STATUS_NOT_IMPLEMENTED ;
}
2006-05-20 12:15:22 +04:00
return ntvfs - > ctx - > handles . create_new ( ntvfs - > ctx - > handles . private_data , req , h ) ;
}
2008-04-02 06:53:27 +04:00
NTSTATUS ntvfs_handle_set_backend_data ( struct ntvfs_handle * h ,
2006-05-20 12:15:22 +04:00
struct ntvfs_module_context * ntvfs ,
TALLOC_CTX * private_data )
{
struct ntvfs_handle_data * d ;
2007-10-07 02:28:14 +04:00
bool first_time = h - > backend_data ? false : true ;
2006-05-20 12:15:22 +04:00
for ( d = h - > backend_data ; d ; d = d - > next ) {
if ( d - > owner ! = ntvfs ) continue ;
d - > private_data = talloc_steal ( d , private_data ) ;
return NT_STATUS_OK ;
}
d = talloc ( h , struct ntvfs_handle_data ) ;
NT_STATUS_HAVE_NO_MEMORY ( d ) ;
d - > owner = ntvfs ;
d - > private_data = talloc_steal ( d , private_data ) ;
DLIST_ADD ( h - > backend_data , d ) ;
if ( first_time ) {
NTSTATUS status ;
status = h - > ctx - > handles . make_valid ( h - > ctx - > handles . private_data , h ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
}
return NT_STATUS_OK ;
}
2008-04-02 06:53:27 +04:00
void * ntvfs_handle_get_backend_data ( struct ntvfs_handle * h ,
2006-05-20 12:15:22 +04:00
struct ntvfs_module_context * ntvfs )
{
struct ntvfs_handle_data * d ;
for ( d = h - > backend_data ; d ; d = d - > next ) {
if ( d - > owner ! = ntvfs ) continue ;
return d - > private_data ;
}
return NULL ;
}
2008-04-02 06:53:27 +04:00
void ntvfs_handle_remove_backend_data ( struct ntvfs_handle * h ,
2006-05-20 12:15:22 +04:00
struct ntvfs_module_context * ntvfs )
{
struct ntvfs_handle_data * d , * n ;
for ( d = h - > backend_data ; d ; d = n ) {
n = d - > next ;
if ( d - > owner ! = ntvfs ) continue ;
DLIST_REMOVE ( h - > backend_data , d ) ;
talloc_free ( d ) ;
d = NULL ;
}
if ( h - > backend_data ) return ;
/* if there's no backend_data anymore, destroy the handle */
h - > ctx - > handles . destroy ( h - > ctx - > handles . private_data , h ) ;
}
2008-04-02 06:53:27 +04:00
struct ntvfs_handle * ntvfs_handle_search_by_wire_key ( struct ntvfs_module_context * ntvfs ,
2006-05-20 12:15:22 +04:00
struct ntvfs_request * req ,
const DATA_BLOB * key )
{
2006-05-21 12:29:56 +04:00
if ( ! ntvfs - > ctx - > handles . search_by_wire_key ) {
return NULL ;
}
2006-05-20 12:15:22 +04:00
return ntvfs - > ctx - > handles . search_by_wire_key ( ntvfs - > ctx - > handles . private_data , req , key ) ;
}
2008-04-02 06:53:27 +04:00
NTSTATUS ntvfs_set_handle_callbacks ( struct ntvfs_context * ntvfs ,
2006-05-20 12:15:22 +04:00
NTSTATUS ( * create_new ) ( void * private_data , struct ntvfs_request * req , struct ntvfs_handle * * h ) ,
NTSTATUS ( * make_valid ) ( void * private_data , struct ntvfs_handle * h ) ,
void ( * destroy ) ( void * private_data , struct ntvfs_handle * h ) ,
struct ntvfs_handle * ( * search_by_wire_key ) ( void * private_data , struct ntvfs_request * req , const DATA_BLOB * key ) ,
DATA_BLOB ( * get_wire_key ) ( void * private_data , struct ntvfs_handle * handle , TALLOC_CTX * mem_ctx ) ,
void * private_data )
{
ntvfs - > handles . create_new = create_new ;
ntvfs - > handles . make_valid = make_valid ;
ntvfs - > handles . destroy = destroy ;
ntvfs - > handles . search_by_wire_key = search_by_wire_key ;
ntvfs - > handles . get_wire_key = get_wire_key ;
ntvfs - > handles . private_data = private_data ;
return NT_STATUS_OK ;
}