2003-12-13 02:20:40 +00:00
/*
Unix SMB / CIFS implementation .
server side dcerpc handle code
Copyright ( C ) Andrew Tridgell 2003
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-12-13 02:20:40 +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-12-13 02:20:40 +00:00
*/
# include "includes.h"
2006-08-30 11:29:34 +00:00
# include "lib/util/dlinklist.h"
2004-11-02 07:42:47 +00:00
# include "rpc_server/dcerpc_server.h"
2003-12-13 02:20:40 +00:00
2005-01-10 12:15:26 +00:00
/*
destroy a rpc handle
*/
2006-05-24 07:35:06 +00:00
static int dcesrv_handle_destructor ( struct dcesrv_handle * h )
2005-01-10 12:15:26 +00:00
{
DLIST_REMOVE ( h - > context - > handles , h ) ;
talloc_free ( h ) ;
return 0 ;
}
2003-12-13 02:20:40 +00:00
/*
allocate a new rpc handle
*/
2006-05-01 18:11:15 +00:00
_PUBLIC_ struct dcesrv_handle * dcesrv_handle_new ( struct dcesrv_connection_context * context ,
2004-05-25 17:50:17 +00:00
uint8_t handle_type )
2003-12-13 02:20:40 +00:00
{
struct dcesrv_handle * h ;
2005-01-27 07:08:20 +00:00
h = talloc ( context , struct dcesrv_handle ) ;
2003-12-13 02:20:40 +00:00
if ( ! h ) {
return NULL ;
}
h - > data = NULL ;
2005-01-10 12:15:26 +00:00
h - > context = context ;
2003-12-13 02:20:40 +00:00
2003-12-16 09:50:49 +00:00
h - > wire_handle . handle_type = handle_type ;
2004-11-25 20:03:46 +00:00
h - > wire_handle . uuid = GUID_random ( ) ;
2003-12-13 02:20:40 +00:00
2005-01-10 12:15:26 +00:00
DLIST_ADD ( context - > handles , h ) ;
2003-12-13 02:20:40 +00:00
2005-01-10 12:15:26 +00:00
talloc_set_destructor ( h , dcesrv_handle_destructor ) ;
2003-12-13 02:20:40 +00:00
2005-01-10 12:15:26 +00:00
return h ;
2003-12-13 02:20:40 +00:00
}
2007-08-26 15:16:40 +00:00
/**
2003-12-13 02:20:40 +00:00
find an internal handle given a wire handle . If the wire handle is NULL then
allocate a new handle
*/
2007-08-26 15:16:40 +00:00
_PUBLIC_ struct dcesrv_handle * dcesrv_handle_fetch (
struct dcesrv_connection_context * context ,
2003-12-13 02:20:40 +00:00
struct policy_handle * p ,
2004-05-25 17:50:17 +00:00
uint8_t handle_type )
2003-12-13 02:20:40 +00:00
{
struct dcesrv_handle * h ;
2003-12-19 03:59:27 +00:00
if ( policy_handle_empty ( p ) ) {
2005-01-10 12:15:26 +00:00
return dcesrv_handle_new ( context , handle_type ) ;
2003-12-13 02:20:40 +00:00
}
2005-01-10 12:15:26 +00:00
for ( h = context - > handles ; h ; h = h - > next ) {
2003-12-16 09:50:49 +00:00
if ( h - > wire_handle . handle_type = = p - > handle_type & &
2004-11-25 20:03:46 +00:00
GUID_equal ( & p - > uuid , & h - > wire_handle . uuid ) ) {
2004-04-27 07:12:10 +00:00
if ( handle_type ! = DCESRV_HANDLE_ANY & &
p - > handle_type ! = handle_type ) {
2003-12-16 09:50:49 +00:00
DEBUG ( 0 , ( " client gave us the wrong handle type (%d should be %d) \n " ,
p - > handle_type , handle_type ) ) ;
return NULL ;
}
2003-12-13 02:20:40 +00:00
return h ;
}
}
return NULL ;
}