2005-12-27 20:15:48 +03:00
/*
Unix SMB / CIFS implementation .
dcerpc utility functions
Copyright ( C ) Andrew Tridgell 2003
Copyright ( C ) Jelmer Vernooij 2004
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
2005-12-27 20:15:48 +03: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/>.
2005-12-27 20:15:48 +03:00
*/
# include "includes.h"
2008-10-11 23:31:42 +04:00
# include "../lib/util/dlinklist.h"
2007-08-21 23:35:43 +04:00
# include "librpc/ndr/libndr.h"
# include "librpc/ndr/ndr_table.h"
2008-10-20 15:19:39 +04:00
# undef strcasecmp
2005-12-29 19:04:34 +03:00
2007-08-21 23:35:43 +04:00
static struct ndr_interface_list * ndr_interfaces ;
2005-12-29 19:04:34 +03:00
/*
2007-08-21 23:35:43 +04:00
register a ndr interface table
2005-12-29 19:04:34 +03:00
*/
2007-08-21 23:35:43 +04:00
NTSTATUS ndr_table_register ( const struct ndr_interface_table * table )
2005-12-29 19:04:34 +03:00
{
2007-08-20 00:46:45 +04:00
struct ndr_interface_list * l ;
2005-12-29 19:04:34 +03:00
2007-08-21 23:35:43 +04:00
for ( l = ndr_interfaces ; l ; l = l - > next ) {
if ( GUID_equal ( & table - > syntax_id . uuid , & l - > table - > syntax_id . uuid ) ) {
2005-12-29 19:04:34 +03:00
DEBUG ( 0 , ( " Attempt to register interface %s which has the "
2007-08-21 23:35:43 +04:00
" same UUID as already registered interface %s \n " ,
table - > name , l - > table - > name ) ) ;
2005-12-29 19:04:34 +03:00
return NT_STATUS_OBJECT_NAME_COLLISION ;
}
}
2007-08-21 23:35:43 +04:00
2007-08-20 00:46:45 +04:00
l = talloc ( talloc_autofree_context ( ) , struct ndr_interface_list ) ;
2007-08-21 23:35:43 +04:00
l - > table = table ;
DLIST_ADD ( ndr_interfaces , l ) ;
2005-12-29 19:04:34 +03:00
return NT_STATUS_OK ;
}
2005-12-27 20:15:48 +03:00
/*
find the pipe name for a local IDL interface
*/
2007-08-21 23:35:43 +04:00
const char * ndr_interface_name ( const struct GUID * uuid , uint32_t if_version )
2005-12-27 20:15:48 +03:00
{
2007-08-20 00:46:45 +04:00
const struct ndr_interface_list * l ;
2007-08-21 23:35:43 +04:00
for ( l = ndr_table_list ( ) ; l ; l = l - > next ) {
2006-03-26 04:59:17 +04:00
if ( GUID_equal ( & l - > table - > syntax_id . uuid , uuid ) & &
l - > table - > syntax_id . if_version = = if_version ) {
2005-12-27 20:15:48 +03:00
return l - > table - > name ;
}
}
return " UNKNOWN " ;
}
/*
find the number of calls defined by local IDL
*/
2007-08-21 23:35:43 +04:00
int ndr_interface_num_calls ( const struct GUID * uuid , uint32_t if_version )
2005-12-27 20:15:48 +03:00
{
2007-08-20 00:46:45 +04:00
const struct ndr_interface_list * l ;
2013-08-12 19:22:15 +04:00
for ( l = ndr_table_list ( ) ; l ; l = l - > next ) {
2006-03-26 04:59:17 +04:00
if ( GUID_equal ( & l - > table - > syntax_id . uuid , uuid ) & &
l - > table - > syntax_id . if_version = = if_version ) {
2005-12-27 20:15:48 +03:00
return l - > table - > num_calls ;
}
}
return - 1 ;
}
/*
find a dcerpc interface by name
*/
2007-08-21 23:35:43 +04:00
const struct ndr_interface_table * ndr_table_by_name ( const char * name )
2005-12-27 20:15:48 +03:00
{
2007-08-20 00:46:45 +04:00
const struct ndr_interface_list * l ;
2013-08-12 19:22:15 +04:00
for ( l = ndr_table_list ( ) ; l ; l = l - > next ) {
2005-12-27 20:15:48 +03:00
if ( strcasecmp ( l - > table - > name , name ) = = 0 ) {
return l - > table ;
}
}
return NULL ;
}
2014-01-24 13:28:05 +04:00
/*
find a dcerpc interface by syntax
*/
const struct ndr_interface_table * ndr_table_by_syntax ( const struct ndr_syntax_id * syntax )
{
const struct ndr_interface_list * l ;
for ( l = ndr_table_list ( ) ; l ; l = l - > next ) {
if ( ndr_syntax_id_equal ( & l - > table - > syntax_id , syntax ) ) {
return l - > table ;
}
}
return NULL ;
}
2005-12-27 20:15:48 +03:00
/*
find a dcerpc interface by uuid
*/
2007-08-21 23:35:43 +04:00
const struct ndr_interface_table * ndr_table_by_uuid ( const struct GUID * uuid )
2005-12-27 20:15:48 +03:00
{
2007-08-20 00:46:45 +04:00
const struct ndr_interface_list * l ;
2013-08-12 19:22:15 +04:00
for ( l = ndr_table_list ( ) ; l ; l = l - > next ) {
2006-03-26 04:59:17 +04:00
if ( GUID_equal ( & l - > table - > syntax_id . uuid , uuid ) ) {
2005-12-27 20:15:48 +03:00
return l - > table ;
}
}
return NULL ;
}
/*
return the list of registered dcerpc_pipes
*/
2007-08-21 23:35:43 +04:00
const struct ndr_interface_list * ndr_table_list ( void )
2005-12-27 20:15:48 +03:00
{
2013-08-08 19:34:56 +04:00
ndr_table_init ( ) ;
2007-08-21 23:35:43 +04:00
return ndr_interfaces ;
2005-12-27 20:15:48 +03:00
}
2007-08-20 01:23:03 +04:00
NTSTATUS ndr_table_init ( void )
2005-12-31 03:02:41 +03:00
{
2007-09-25 20:05:08 +04:00
static bool initialized = false ;
2005-12-31 03:02:41 +03:00
if ( initialized ) return NT_STATUS_OK ;
2007-09-25 20:05:08 +04:00
initialized = true ;
2005-12-31 03:02:41 +03:00
2007-08-21 23:35:43 +04:00
ndr_table_register_builtin_tables ( ) ;
2005-12-31 03:02:41 +03:00
return NT_STATUS_OK ;
}