1998-03-11 21:11:04 +00:00
/*
2002-01-30 06:08:46 +00:00
* Unix SMB / CIFS implementation .
1998-03-11 21:11:04 +00:00
* RPC Pipe client / server routines
* Copyright ( C ) Andrew Tridgell 1992 - 1997 ,
* Copyright ( C ) Luke Kenneth Casson Leighton 1996 - 1997 ,
2001-03-11 00:32:10 +00:00
* Copyright ( C ) Jeremy Allison 2001.
1998-03-11 21:11:04 +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-09 19:25:36 +00:00
* the Free Software Foundation ; either version 3 of the License , or
1998-03-11 21:11:04 +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 05:23:25 +00:00
* along with this program ; if not , see < http : //www.gnu.org/licenses/>.
1998-03-11 21:11:04 +00:00
*/
# include "includes.h"
2011-10-27 12:00:53 +02:00
# include "system/passwd.h" /* uid_wrapper */
2010-05-05 01:39:16 +02:00
# include "../librpc/gen_ndr/ndr_lsa.h"
2010-05-28 02:18:21 +02:00
# include "../librpc/gen_ndr/ndr_samr.h"
2011-03-24 12:08:15 +01:00
# include "auth.h"
2011-07-21 09:53:10 -04:00
# include "rpc_server/rpc_pipes.h"
2011-07-19 11:57:05 +10:00
# include "../libcli/security/security.h"
2011-07-21 11:02:59 -04:00
# include "lib/tsocket/tsocket.h"
2013-09-18 10:58:16 +02:00
# include "librpc/ndr/ndr_table.h"
1998-03-11 21:11:04 +00:00
2002-07-15 10:35:28 +00:00
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_RPC_SRV
2011-07-21 09:53:10 -04:00
static struct pipes_struct * InternalPipes ;
/* TODO
* the following prototypes are declared here to avoid
* code being moved about too much for a patch to be
* disrupted / less obvious .
*
* these functions , and associated functions that they
* call , should be moved behind a . so module - loading
* system _anyway_ . so that ' s the next step . . .
*/
2011-07-21 11:02:59 -04:00
int make_base_pipes_struct ( TALLOC_CTX * mem_ctx ,
struct messaging_context * msg_ctx ,
const char * pipe_name ,
enum dcerpc_transport_t transport ,
2014-04-17 14:22:17 +02:00
bool endian ,
2011-07-21 11:02:59 -04:00
const struct tsocket_address * remote_address ,
const struct tsocket_address * local_address ,
struct pipes_struct * * _p )
{
struct pipes_struct * p ;
p = talloc_zero ( mem_ctx , struct pipes_struct ) ;
if ( ! p ) {
return ENOMEM ;
}
p - > mem_ctx = talloc_named ( p , 0 , " pipe %s %p " , pipe_name , p ) ;
if ( ! p - > mem_ctx ) {
talloc_free ( p ) ;
return ENOMEM ;
}
p - > msg_ctx = msg_ctx ;
p - > transport = transport ;
p - > endian = endian ;
2015-07-07 09:15:39 +02:00
p - > allow_bind = true ;
2011-07-21 11:02:59 -04:00
p - > remote_address = tsocket_address_copy ( remote_address , p ) ;
if ( p - > remote_address = = NULL ) {
talloc_free ( p ) ;
return ENOMEM ;
}
if ( local_address ) {
2011-07-26 11:04:48 +02:00
p - > local_address = tsocket_address_copy ( local_address , p ) ;
2011-07-21 11:02:59 -04:00
if ( p - > local_address = = NULL ) {
talloc_free ( p ) ;
return ENOMEM ;
}
}
DLIST_ADD ( InternalPipes , p ) ;
talloc_set_destructor ( p , close_internal_rpc_pipe_hnd ) ;
* _p = p ;
return 0 ;
}
2011-07-21 09:53:10 -04:00
bool check_open_pipes ( void )
{
struct pipes_struct * p ;
for ( p = InternalPipes ; p ! = NULL ; p = p - > next ) {
if ( num_pipe_handles ( p ) ! = 0 ) {
return true ;
}
}
return false ;
}
/****************************************************************************
Close an rpc pipe .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int close_internal_rpc_pipe_hnd ( struct pipes_struct * p )
{
if ( ! p ) {
DEBUG ( 0 , ( " Invalid pipe in close_internal_rpc_pipe_hnd \n " ) ) ;
return False ;
}
/* Free the handles database. */
close_policy_by_pipe ( p ) ;
DLIST_REMOVE ( InternalPipes , p ) ;
return 0 ;
}
2009-04-18 16:10:57 +02:00
/*
* Handle database - stored per pipe .
*/
2010-06-07 17:38:01 -04:00
struct dcesrv_handle {
struct dcesrv_handle * prev , * next ;
struct policy_handle wire_handle ;
2009-04-18 16:46:53 +02:00
uint32_t access_granted ;
2010-06-07 17:38:01 -04:00
void * data ;
2009-04-18 16:10:57 +02:00
} ;
struct handle_list {
2010-06-07 17:38:01 -04:00
struct dcesrv_handle * handles ; /* List of pipe handles. */
2009-04-18 16:10:57 +02:00
size_t count ; /* Current number of handles. */
2010-06-07 17:38:01 -04:00
size_t pipe_ref_count ; /* Number of pipe handles referring
* to this tree . */
2009-04-18 16:10:57 +02:00
} ;
2001-03-13 20:18:45 +00:00
/* This is the max handles across all instances of a pipe name. */
1998-03-11 21:11:04 +00:00
# ifndef MAX_OPEN_POLS
2009-05-29 12:41:41 +02:00
# define MAX_OPEN_POLS 2048
1998-03-11 21:11:04 +00:00
# endif
2002-03-30 00:45:26 +00:00
/****************************************************************************
2016-08-24 17:42:48 +02:00
Hack as handles need to be persistent over lsa pipe closes so long as a samr
2002-03-30 00:45:26 +00:00
pipe is open . JRA .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-02-01 12:03:31 +01:00
static bool is_samr_lsa_pipe ( const struct ndr_syntax_id * syntax )
2002-03-30 00:45:26 +00:00
{
2009-02-01 12:03:31 +01:00
return ( ndr_syntax_id_equal ( syntax , & ndr_table_samr . syntax_id )
| | ndr_syntax_id_equal ( syntax , & ndr_table_lsarpc . syntax_id ) ) ;
2002-03-30 00:45:26 +00:00
}
2010-07-28 09:46:43 +02:00
size_t num_pipe_handles ( struct pipes_struct * p )
2009-04-18 16:10:57 +02:00
{
2010-06-07 16:02:14 -04:00
if ( p - > pipe_handles = = NULL ) {
2009-04-18 16:10:57 +02:00
return 0 ;
}
2010-06-07 16:02:14 -04:00
return p - > pipe_handles - > count ;
2009-04-18 16:10:57 +02:00
}
1998-03-11 21:11:04 +00:00
/****************************************************************************
2001-03-13 20:18:45 +00:00
Initialise a policy handle list on a pipe . Handle list is shared between all
pipes of the same name .
1998-03-11 21:11:04 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-03-11 00:32:10 +00:00
2010-07-28 09:46:43 +02:00
bool init_pipe_handles ( struct pipes_struct * p , const struct ndr_syntax_id * syntax )
1998-03-11 21:11:04 +00:00
{
2010-07-28 09:46:43 +02:00
struct pipes_struct * plist ;
2009-01-07 17:36:54 +01:00
struct handle_list * hl ;
2001-03-13 20:18:45 +00:00
2011-07-21 09:53:10 -04:00
for ( plist = InternalPipes ; plist ; plist = plist - > next ) {
2011-05-31 10:53:55 +02:00
struct pipe_rpc_fns * p_ctx ;
bool stop = false ;
for ( p_ctx = plist - > contexts ;
p_ctx ! = NULL ;
p_ctx = p_ctx - > next ) {
if ( ndr_syntax_id_equal ( syntax , & p_ctx - > syntax ) ) {
stop = true ;
break ;
}
if ( is_samr_lsa_pipe ( & p_ctx - > syntax )
& & is_samr_lsa_pipe ( syntax ) ) {
/*
* samr and lsa share a handle space ( same process
* under Windows ? )
*/
stop = true ;
break ;
}
2009-01-07 17:36:54 +01:00
}
2011-05-31 10:53:55 +02:00
if ( stop ) {
2001-03-13 20:18:45 +00:00
break ;
}
}
2009-01-07 17:36:54 +01:00
if ( plist ! = NULL ) {
hl = plist - > pipe_handles ;
if ( hl = = NULL ) {
return false ;
}
} else {
2001-03-13 20:18:45 +00:00
/*
2009-01-07 17:36:54 +01:00
* First open , we have to create the handle list
2001-03-13 20:18:45 +00:00
*/
2010-07-14 08:57:47 -04:00
hl = talloc_zero ( NULL , struct handle_list ) ;
2009-01-07 17:36:54 +01:00
if ( hl = = NULL ) {
return false ;
}
2001-03-13 20:18:45 +00:00
2010-01-31 15:38:16 +01:00
DEBUG ( 10 , ( " init_pipe_handle_list: created handle list for "
2009-10-31 19:28:16 +01:00
" pipe %s \n " ,
2013-09-18 10:58:16 +02:00
ndr_interface_name ( & syntax - > uuid ,
syntax - > if_version ) ) ) ;
2001-03-13 20:18:45 +00:00
}
/*
* One more pipe is using this list .
*/
hl - > pipe_ref_count + + ;
/*
* Point this pipe at this list .
*/
p - > pipe_handles = hl ;
2010-01-31 15:38:16 +01:00
DEBUG ( 10 , ( " init_pipe_handle_list: pipe_handles ref count = %lu for "
" pipe %s \n " , ( unsigned long ) p - > pipe_handles - > pipe_ref_count ,
2013-09-18 10:58:16 +02:00
ndr_interface_name ( & syntax - > uuid , syntax - > if_version ) ) ) ;
2001-03-13 20:18:45 +00:00
return True ;
1998-03-11 21:11:04 +00:00
}
/****************************************************************************
find first available policy slot . creates a policy handle for you .
2009-01-07 18:44:52 +01:00
If " data_ptr " is given , this must be a talloc ' ed object , create_policy_hnd
talloc_moves this into the handle . If the policy_hnd is closed ,
data_ptr is TALLOC_FREE ( ) ' ed
1998-03-11 21:11:04 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-03-11 00:32:10 +00:00
2010-07-28 09:46:43 +02:00
static struct dcesrv_handle * create_rpc_handle_internal ( struct pipes_struct * p ,
2010-06-07 17:38:01 -04:00
struct policy_handle * hnd , void * data_ptr )
1998-03-11 21:11:04 +00:00
{
2010-06-07 17:38:01 -04:00
struct dcesrv_handle * rpc_hnd ;
2015-05-09 10:02:05 -07:00
static uint32_t pol_hnd_low = 0 ;
static uint32_t pol_hnd_high = 0 ;
2006-09-11 22:02:34 +00:00
time_t t = time ( NULL ) ;
1998-03-11 21:11:04 +00:00
2001-03-13 20:18:45 +00:00
if ( p - > pipe_handles - > count > MAX_OPEN_POLS ) {
DEBUG ( 0 , ( " create_policy_hnd: ERROR: too many handles (%d) on this pipe. \n " ,
( int ) p - > pipe_handles - > count ) ) ;
2009-04-18 16:46:53 +02:00
return NULL ;
1998-08-17 04:54:06 +00:00
}
1998-03-11 21:11:04 +00:00
2010-06-07 17:38:01 -04:00
rpc_hnd = talloc_zero ( p - > pipe_handles , struct dcesrv_handle ) ;
if ( ! rpc_hnd ) {
2001-03-11 00:32:10 +00:00
DEBUG ( 0 , ( " create_policy_hnd: ERROR: out of memory! \n " ) ) ;
2009-04-18 16:46:53 +02:00
return NULL ;
1998-03-11 21:11:04 +00:00
}
2009-01-07 18:44:52 +01:00
if ( data_ptr ! = NULL ) {
2010-06-07 17:38:01 -04:00
rpc_hnd - > data = talloc_move ( rpc_hnd , & data_ptr ) ;
2009-01-07 18:44:52 +01:00
}
1998-03-11 21:11:04 +00:00
2002-01-22 19:45:17 +00:00
pol_hnd_low + + ;
2010-06-07 17:38:01 -04:00
if ( pol_hnd_low = = 0 ) {
pol_hnd_high + + ;
}
2002-01-22 19:45:17 +00:00
2010-06-07 17:38:01 -04:00
/* first bit must be null */
SIVAL ( & rpc_hnd - > wire_handle . handle_type , 0 , 0 ) ;
2006-09-11 22:02:34 +00:00
2010-06-07 17:38:01 -04:00
/* second bit is incrementing */
SIVAL ( & rpc_hnd - > wire_handle . uuid . time_low , 0 , pol_hnd_low ) ;
SSVAL ( & rpc_hnd - > wire_handle . uuid . time_mid , 0 , pol_hnd_high ) ;
SSVAL ( & rpc_hnd - > wire_handle . uuid . time_hi_and_version , 0 , ( pol_hnd_high > > 16 ) ) ;
2006-09-11 22:02:34 +00:00
2010-06-07 17:38:01 -04:00
/* split the current time into two 16 bit values */
2006-09-11 22:02:34 +00:00
2010-06-07 17:38:01 -04:00
/* something random */
SSVAL ( rpc_hnd - > wire_handle . uuid . clock_seq , 0 , ( t > > 16 ) ) ;
/* something random */
SSVAL ( rpc_hnd - > wire_handle . uuid . node , 0 , t ) ;
/* something more random */
2012-03-24 20:17:08 +01:00
SIVAL ( rpc_hnd - > wire_handle . uuid . node , 2 , getpid ( ) ) ;
1998-08-17 04:54:06 +00:00
2010-06-07 17:38:01 -04:00
DLIST_ADD ( p - > pipe_handles - > handles , rpc_hnd ) ;
2001-03-13 20:18:45 +00:00
p - > pipe_handles - > count + + ;
1998-08-17 04:54:06 +00:00
2010-06-07 17:38:01 -04:00
* hnd = rpc_hnd - > wire_handle ;
2012-02-13 18:58:32 +01:00
DEBUG ( 6 , ( " Opened policy hnd[%d] " , ( int ) p - > pipe_handles - > count ) ) ;
dump_data ( 6 , ( uint8_t * ) hnd , sizeof ( * hnd ) ) ;
1998-08-17 04:54:06 +00:00
2010-06-07 17:38:01 -04:00
return rpc_hnd ;
2009-04-18 16:46:53 +02:00
}
2010-07-28 09:46:43 +02:00
bool create_policy_hnd ( struct pipes_struct * p , struct policy_handle * hnd ,
2009-04-18 16:46:53 +02:00
void * data_ptr )
{
2010-06-07 17:38:01 -04:00
struct dcesrv_handle * rpc_hnd ;
rpc_hnd = create_rpc_handle_internal ( p , hnd , data_ptr ) ;
if ( rpc_hnd = = NULL ) {
return false ;
}
return true ;
1998-03-11 21:11:04 +00:00
}
/****************************************************************************
2001-03-11 00:32:10 +00:00
find policy by handle - internal version .
1998-03-11 21:11:04 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-07-28 09:46:43 +02:00
static struct dcesrv_handle * find_policy_by_hnd_internal ( struct pipes_struct * p ,
2010-06-07 17:38:01 -04:00
const struct policy_handle * hnd , void * * data_p )
2001-03-11 00:32:10 +00:00
{
2010-06-07 17:38:01 -04:00
struct dcesrv_handle * h ;
unsigned int count ;
2001-03-11 00:32:10 +00:00
2010-06-07 17:38:01 -04:00
if ( data_p ) {
2001-03-11 00:32:10 +00:00
* data_p = NULL ;
2010-06-07 17:38:01 -04:00
}
2001-03-11 00:32:10 +00:00
2010-06-07 17:38:01 -04:00
count = 0 ;
for ( h = p - > pipe_handles - > handles ; h ! = NULL ; h = h - > next ) {
if ( memcmp ( & h - > wire_handle , hnd , sizeof ( * hnd ) ) = = 0 ) {
2012-02-13 18:58:32 +01:00
DEBUG ( 6 , ( " Found policy hnd[%u] " , count ) ) ;
2015-05-09 10:02:05 -07:00
dump_data ( 6 , ( const uint8_t * ) hnd , sizeof ( * hnd ) ) ;
2010-06-07 17:38:01 -04:00
if ( data_p ) {
* data_p = h - > data ;
}
return h ;
1998-03-11 21:11:04 +00:00
}
2010-06-07 17:38:01 -04:00
count + + ;
1998-03-11 21:11:04 +00:00
}
DEBUG ( 4 , ( " Policy not found: " ) ) ;
2011-05-05 16:19:49 -07:00
dump_data ( 4 , ( const uint8_t * ) hnd , sizeof ( * hnd ) ) ;
1998-03-11 21:11:04 +00:00
2012-06-27 15:21:11 +02:00
p - > fault_state = DCERPC_FAULT_CONTEXT_MISMATCH ;
2002-01-25 05:28:37 +00:00
1998-08-17 04:54:06 +00:00
return NULL ;
}
/****************************************************************************
2001-03-11 00:32:10 +00:00
find policy by handle
1998-08-17 04:54:06 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-07-28 09:46:43 +02:00
bool find_policy_by_hnd ( struct pipes_struct * p , const struct policy_handle * hnd ,
2009-04-18 13:30:38 +02:00
void * * data_p )
1998-03-11 21:11:04 +00:00
{
2010-06-07 17:38:01 -04:00
struct dcesrv_handle * rpc_hnd ;
rpc_hnd = find_policy_by_hnd_internal ( p , hnd , data_p ) ;
if ( rpc_hnd = = NULL ) {
return false ;
}
return true ;
1998-03-11 21:11:04 +00:00
}
/****************************************************************************
2001-03-11 00:32:10 +00:00
Close a policy .
1998-03-11 21:11:04 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1998-08-17 04:54:06 +00:00
2010-07-28 09:46:43 +02:00
bool close_policy_hnd ( struct pipes_struct * p , struct policy_handle * hnd )
1998-10-21 22:36:26 +00:00
{
2010-06-07 17:38:01 -04:00
struct dcesrv_handle * rpc_hnd ;
1998-10-21 22:36:26 +00:00
2010-06-07 17:38:01 -04:00
rpc_hnd = find_policy_by_hnd_internal ( p , hnd , NULL ) ;
if ( rpc_hnd = = NULL ) {
DEBUG ( 3 , ( " Error closing policy (policy not found) \n " ) ) ;
return false ;
1998-10-21 22:36:26 +00:00
}
2012-02-13 18:58:32 +01:00
DEBUG ( 6 , ( " Closed policy \n " ) ) ;
1998-10-21 22:36:26 +00:00
2001-04-02 22:27:40 +00:00
p - > pipe_handles - > count - - ;
1998-03-11 21:11:04 +00:00
2010-06-07 17:38:01 -04:00
DLIST_REMOVE ( p - > pipe_handles - > handles , rpc_hnd ) ;
TALLOC_FREE ( rpc_hnd ) ;
1999-11-18 22:03:47 +00:00
2010-06-07 17:38:01 -04:00
return true ;
1999-11-24 18:09:33 +00:00
}
1998-03-11 21:11:04 +00:00
/****************************************************************************
2010-06-07 17:38:01 -04:00
Close a pipe - free the handle set if it was the last pipe reference .
1998-03-11 21:11:04 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-07-28 09:46:43 +02:00
void close_policy_by_pipe ( struct pipes_struct * p )
2001-03-11 00:32:10 +00:00
{
2011-05-25 17:26:28 +02:00
if ( p - > pipe_handles = = NULL ) {
return ;
}
2001-03-13 20:18:45 +00:00
p - > pipe_handles - > pipe_ref_count - - ;
if ( p - > pipe_handles - > pipe_ref_count = = 0 ) {
/*
* Last pipe open on this list - free the list .
*/
2010-06-07 17:38:01 -04:00
TALLOC_FREE ( p - > pipe_handles ) ;
2001-03-13 20:18:45 +00:00
2011-05-31 13:32:22 +02:00
DEBUG ( 10 , ( " Deleted handle list for RPC connection %s \n " ,
2013-09-18 10:58:16 +02:00
ndr_interface_name ( & p - > contexts - > syntax . uuid ,
p - > contexts - > syntax . if_version ) ) ) ;
2001-03-13 20:18:45 +00:00
}
1998-03-11 21:11:04 +00:00
}
2002-07-15 10:35:28 +00:00
/*******************************************************************
Shall we allow access to this rpc ? Currently this function
implements the ' restrict anonymous ' setting by denying access to
anonymous users if the restrict anonymous level is > 0. Further work
will be checking a security descriptor to determine whether a user
token has enough access to access the pipe .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-07-28 09:46:43 +02:00
bool pipe_access_check ( struct pipes_struct * p )
2002-07-15 10:35:28 +00:00
{
/* Don't let anonymous users access this RPC if restrict
anonymous > 0 */
if ( lp_restrict_anonymous ( ) > 0 ) {
2005-02-19 11:09:52 +00:00
/* schannel, so we must be ok */
2010-07-20 13:26:36 -04:00
if ( p - > pipe_bound & &
( p - > auth . auth_type = = DCERPC_AUTH_TYPE_SCHANNEL ) ) {
2005-02-19 11:09:52 +00:00
return True ;
2005-09-30 17:13:37 +00:00
}
2005-02-19 11:09:52 +00:00
2011-07-19 11:57:05 +10:00
if ( security_session_user_level ( p - > session_info , NULL ) < SECURITY_USER ) {
2002-07-15 10:35:28 +00:00
return False ;
2005-09-30 17:13:37 +00:00
}
2002-07-15 10:35:28 +00:00
}
return True ;
}
2009-04-18 13:31:20 +02:00
2009-04-18 16:46:53 +02:00
void * _policy_handle_create ( struct pipes_struct * p , struct policy_handle * hnd ,
uint32_t access_granted , size_t data_size ,
const char * type , NTSTATUS * pstatus )
2009-04-18 13:31:20 +02:00
{
2010-06-07 17:38:01 -04:00
struct dcesrv_handle * rpc_hnd ;
2009-04-18 13:31:20 +02:00
void * data ;
if ( p - > pipe_handles - > count > MAX_OPEN_POLS ) {
2011-05-31 13:32:22 +02:00
DEBUG ( 0 , ( " ERROR: Too many handles (%d) for RPC connection %s \n " ,
2011-06-01 14:45:59 -07:00
( int ) p - > pipe_handles - > count ,
2013-09-18 10:58:16 +02:00
ndr_interface_name ( & p - > contexts - > syntax . uuid ,
p - > contexts - > syntax . if_version ) ) ) ;
2009-04-18 16:46:53 +02:00
* pstatus = NT_STATUS_INSUFFICIENT_RESOURCES ;
return NULL ;
2009-04-18 13:31:20 +02:00
}
data = talloc_size ( talloc_tos ( ) , data_size ) ;
if ( data = = NULL ) {
2009-04-18 16:46:53 +02:00
* pstatus = NT_STATUS_NO_MEMORY ;
return NULL ;
2009-04-18 13:31:20 +02:00
}
2009-04-20 16:50:14 +02:00
talloc_set_name_const ( data , type ) ;
2009-04-18 13:31:20 +02:00
2010-06-07 17:38:01 -04:00
rpc_hnd = create_rpc_handle_internal ( p , hnd , data ) ;
if ( rpc_hnd = = NULL ) {
2009-04-18 13:31:20 +02:00
TALLOC_FREE ( data ) ;
2009-04-18 16:46:53 +02:00
* pstatus = NT_STATUS_NO_MEMORY ;
return NULL ;
2009-04-18 13:31:20 +02:00
}
2010-06-07 17:38:01 -04:00
rpc_hnd - > access_granted = access_granted ;
2009-04-18 16:46:53 +02:00
* pstatus = NT_STATUS_OK ;
return data ;
2009-04-18 13:31:20 +02:00
}
void * _policy_handle_find ( struct pipes_struct * p ,
const struct policy_handle * hnd ,
2009-04-18 16:46:53 +02:00
uint32_t access_required ,
uint32_t * paccess_granted ,
const char * name , const char * location ,
NTSTATUS * pstatus )
2009-04-18 13:31:20 +02:00
{
2010-06-07 17:38:01 -04:00
struct dcesrv_handle * rpc_hnd ;
2009-04-18 13:31:20 +02:00
void * data ;
2010-06-07 17:38:01 -04:00
rpc_hnd = find_policy_by_hnd_internal ( p , hnd , & data ) ;
if ( rpc_hnd = = NULL ) {
2009-04-18 16:46:53 +02:00
* pstatus = NT_STATUS_INVALID_HANDLE ;
2009-04-18 13:31:20 +02:00
return NULL ;
}
if ( strcmp ( name , talloc_get_name ( data ) ) ! = 0 ) {
DEBUG ( 10 , ( " expected %s, got %s \n " , name ,
talloc_get_name ( data ) ) ) ;
2009-04-18 16:46:53 +02:00
* pstatus = NT_STATUS_INVALID_HANDLE ;
2009-04-18 13:31:20 +02:00
return NULL ;
}
2010-06-07 17:38:01 -04:00
if ( ( access_required & rpc_hnd - > access_granted ) ! = access_required ) {
2013-11-06 17:43:19 +01:00
if ( root_mode ( ) ) {
2009-04-18 16:46:53 +02:00
DEBUG ( 4 , ( " %s: ACCESS should be DENIED (granted: "
" %#010x; required: %#010x) \n " , location ,
2010-06-07 17:38:01 -04:00
rpc_hnd - > access_granted , access_required ) ) ;
2009-04-18 16:46:53 +02:00
DEBUGADD ( 4 , ( " but overwritten by euid == 0 \n " ) ) ;
goto okay ;
}
DEBUG ( 2 , ( " %s: ACCESS DENIED (granted: %#010x; required: "
2010-06-07 17:38:01 -04:00
" %#010x) \n " , location , rpc_hnd - > access_granted ,
2009-04-18 16:46:53 +02:00
access_required ) ) ;
* pstatus = NT_STATUS_ACCESS_DENIED ;
return NULL ;
}
okay :
2009-04-18 13:31:20 +02:00
DEBUG ( 10 , ( " found handle of type %s \n " , talloc_get_name ( data ) ) ) ;
2009-04-18 16:46:53 +02:00
if ( paccess_granted ! = NULL ) {
2010-06-07 17:38:01 -04:00
* paccess_granted = rpc_hnd - > access_granted ;
2009-04-18 16:46:53 +02:00
}
* pstatus = NT_STATUS_OK ;
2009-04-18 13:31:20 +02:00
return data ;
}