2004-10-25 11:28:09 +00:00
/*
Unix SMB / CIFS implementation .
GTK + Endpoint Mapper frontend
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
the Free Software Foundation ; either version 2 of the License , or
( 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
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
2004-11-03 00:17:12 +00:00
# include "dynconfig.h"
2004-11-01 10:30:34 +00:00
# include "librpc/gen_ndr/ndr_epmapper.h"
2004-11-03 01:55:21 +00:00
# include "librpc/gen_ndr/ndr_mgmt.h"
2004-11-01 23:37:12 +00:00
# include "gtk/common/select.h"
2004-10-25 11:28:09 +00:00
# include "gtk/common/gtk-smb.h"
2004-10-27 22:41:14 +00:00
/*
* Show :
* - RPC statistics
* - Available interfaces
* - Per interface : available endpoints
* - Per interface auth details
*/
2004-10-25 11:47:29 +00:00
static GtkWidget * mainwin ;
static GtkTreeStore * store_eps ;
2004-11-03 01:55:21 +00:00
static GtkWidget * table_statistics ;
static GtkWidget * lbl_calls_in , * lbl_calls_out , * lbl_pkts_in , * lbl_pkts_out ;
static GtkWidget * lbl_iface_version , * lbl_iface_uuid , * lbl_iface_name ;
TALLOC_CTX * eps_ctx = NULL ;
2005-01-16 22:54:01 +00:00
TALLOC_CTX * conn_ctx = NULL ;
struct dcerpc_pipe * epmapper_pipe ;
struct dcerpc_pipe * mgmt_pipe ;
2004-10-25 11:28:09 +00:00
2004-10-25 11:47:29 +00:00
static void on_quit1_activate ( GtkMenuItem * menuitem , gpointer user_data )
2004-10-25 11:28:09 +00:00
{
gtk_main_quit ( ) ;
}
2004-10-25 11:47:29 +00:00
static void on_about1_activate ( GtkMenuItem * menuitem , gpointer user_data )
2004-10-25 11:28:09 +00:00
{
2004-10-25 11:47:29 +00:00
GtkDialog * aboutwin = GTK_DIALOG ( create_gtk_samba_about_dialog ( " gepdump " ) ) ;
2004-10-25 11:28:09 +00:00
gtk_dialog_run ( aboutwin ) ;
gtk_widget_destroy ( GTK_WIDGET ( aboutwin ) ) ;
}
2005-01-05 02:01:19 +00:00
static const char * get_protocol_name ( enum epm_protocol protocol )
2004-10-25 11:28:09 +00:00
{
switch ( protocol ) {
case EPM_PROTOCOL_UUID : return " UUID " ;
case EPM_PROTOCOL_NCACN : return " NCACN " ;
case EPM_PROTOCOL_NCALRPC : return " NCALRPC " ;
case EPM_PROTOCOL_NCADG : return " NCADG " ;
case EPM_PROTOCOL_IP : return " IP " ;
case EPM_PROTOCOL_TCP : return " TCP " ;
case EPM_PROTOCOL_NETBIOS : return " NetBIOS " ;
case EPM_PROTOCOL_SMB : return " SMB " ;
case EPM_PROTOCOL_PIPE : return " PIPE " ;
2004-10-25 11:47:29 +00:00
case EPM_PROTOCOL_UNIX_DS : return " Unix " ;
2004-10-25 11:28:09 +00:00
default : return " Unknown " ;
}
}
static void add_epm_entry ( TALLOC_CTX * mem_ctx , const char * annotation , struct epm_tower * t )
{
struct dcerpc_binding bd ;
int i ;
NTSTATUS status ;
GtkTreeIter toweriter ;
status = dcerpc_binding_from_tower ( mem_ctx , t , & bd ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
gtk_show_ntstatus ( mainwin , status ) ;
return ;
}
/* Don't show UUID's */
ZERO_STRUCT ( bd . object ) ;
gtk_tree_store_append ( store_eps , & toweriter , NULL ) ;
2004-11-03 01:55:21 +00:00
gtk_tree_store_set ( store_eps , & toweriter , 0 , strdup ( annotation ) , 1 , strdup ( dcerpc_binding_string ( mem_ctx , & bd ) ) , 2 , t , - 1 ) ;
2004-10-25 11:28:09 +00:00
for ( i = 0 ; i < t - > num_floors ; i + + ) {
const char * data ;
2005-02-04 01:32:19 +00:00
struct GUID if_uuid ;
uint16_t if_version ;
2004-10-25 11:28:09 +00:00
GtkTreeIter iter ;
gtk_tree_store_append ( store_eps , & iter , & toweriter ) ;
2005-02-04 01:32:19 +00:00
dcerpc_floor_get_lhs_data ( & t - > floors [ i ] , & if_uuid , & if_version ) ;
2004-10-25 11:28:09 +00:00
if ( t - > floors [ i ] . lhs . protocol = = EPM_PROTOCOL_UUID ) {
2005-02-04 01:32:19 +00:00
data = GUID_string ( mem_ctx , & if_uuid ) ;
2004-10-25 11:28:09 +00:00
} else {
data = dcerpc_floor_get_rhs_data ( mem_ctx , & t - > floors [ i ] ) ;
}
gtk_tree_store_set ( store_eps , & iter , 0 , get_protocol_name ( t - > floors [ i ] . lhs . protocol ) , 1 , data , - 1 ) ;
}
}
2005-01-16 22:54:01 +00:00
static void refresh_eps ( void )
2004-10-25 11:28:09 +00:00
{
NTSTATUS status ;
struct epm_Lookup r ;
struct GUID uuid ;
struct rpc_if_id_t iface ;
struct policy_handle handle ;
TALLOC_CTX * mem_ctx = talloc_init ( " dump " ) ;
2005-01-27 07:08:20 +00:00
talloc_free ( eps_ctx ) ;
2004-11-03 01:55:21 +00:00
2004-10-25 11:28:09 +00:00
ZERO_STRUCT ( handle ) ;
r . in . inquiry_type = 0 ;
r . in . object = & uuid ;
r . in . interface_id = & iface ;
r . in . vers_option = 0 ;
2005-01-16 22:54:01 +00:00
r . in . entry_handle = r . out . entry_handle = & handle ;
2004-10-25 11:28:09 +00:00
r . in . max_ents = 10 ;
gtk_tree_store_clear ( store_eps ) ;
2004-11-03 01:55:21 +00:00
eps_ctx = talloc_init ( " current endpoint list data " ) ;
2004-10-25 11:28:09 +00:00
do {
int i ;
2005-01-16 22:54:01 +00:00
ZERO_STRUCT ( uuid ) ;
ZERO_STRUCT ( iface ) ;
status = dcerpc_epm_Lookup ( epmapper_pipe , eps_ctx , & r ) ;
2004-10-25 11:28:09 +00:00
if ( ! NT_STATUS_IS_OK ( status ) | | r . out . result ! = 0 ) {
break ;
}
for ( i = 0 ; i < r . out . num_ents ; i + + ) {
add_epm_entry ( mem_ctx , r . out . entries [ i ] . annotation , & r . out . entries [ i ] . tower - > tower ) ;
}
2005-01-16 22:54:01 +00:00
2004-10-25 11:28:09 +00:00
} while ( NT_STATUS_IS_OK ( status ) & &
r . out . result = = 0 & &
r . out . num_ents = = r . in . max_ents ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
gtk_show_ntstatus ( mainwin , status ) ;
2005-01-27 07:08:20 +00:00
talloc_free ( mem_ctx ) ;
2004-10-25 11:28:09 +00:00
return ;
}
2005-01-27 07:08:20 +00:00
talloc_free ( mem_ctx ) ;
2004-10-25 11:28:09 +00:00
}
2005-01-16 22:54:01 +00:00
static void on_refresh_clicked ( GtkButton * btn , gpointer user_data )
{
refresh_eps ( ) ;
}
static void on_connect_clicked ( GtkButton * btn , gpointer user_data )
2004-10-25 11:28:09 +00:00
{
GtkRpcBindingDialog * d ;
2005-01-16 22:54:01 +00:00
const char * bs ;
2004-10-25 11:28:09 +00:00
TALLOC_CTX * mem_ctx ;
2005-01-16 22:54:01 +00:00
NTSTATUS status ;
2004-10-25 11:28:09 +00:00
gint result ;
2004-10-25 11:47:29 +00:00
d = GTK_RPC_BINDING_DIALOG ( gtk_rpc_binding_dialog_new ( TRUE , NULL ) ) ;
2004-10-25 11:28:09 +00:00
result = gtk_dialog_run ( GTK_DIALOG ( d ) ) ;
switch ( result ) {
case GTK_RESPONSE_ACCEPT :
break ;
default :
gtk_widget_destroy ( GTK_WIDGET ( d ) ) ;
return ;
}
2005-01-16 22:54:01 +00:00
mem_ctx = talloc_init ( " connect " ) ;
bs = gtk_rpc_binding_dialog_get_binding_string ( d , mem_ctx ) ;
status = dcerpc_pipe_connect ( & epmapper_pipe , bs , DCERPC_EPMAPPER_UUID , DCERPC_EPMAPPER_VERSION , lp_workgroup ( ) , " " , " " ) ;
if ( NT_STATUS_IS_ERR ( status ) ) {
gtk_show_ntstatus ( mainwin , status ) ;
goto fail ;
}
refresh_eps ( ) ;
status = dcerpc_secondary_context ( epmapper_pipe , & mgmt_pipe , DCERPC_MGMT_UUID , DCERPC_MGMT_VERSION ) ;
if ( NT_STATUS_IS_ERR ( status ) ) {
mgmt_pipe = NULL ;
gtk_show_ntstatus ( NULL , status ) ;
goto fail ;
}
fail :
2004-10-25 11:28:09 +00:00
gtk_widget_destroy ( GTK_WIDGET ( d ) ) ;
}
2004-11-03 01:55:21 +00:00
static gboolean on_eps_select ( GtkTreeSelection * selection ,
GtkTreeModel * model , GtkTreePath * path , gboolean path_currently_selected , gpointer data )
{
NTSTATUS status ;
2005-01-16 22:54:01 +00:00
TALLOC_CTX * mem_ctx ;
if ( mgmt_pipe = = NULL )
2004-11-03 01:55:21 +00:00
return FALSE ;
2005-01-16 22:54:01 +00:00
mem_ctx = talloc_init ( " eps " ) ;
2004-11-03 01:55:21 +00:00
{
/* Do an InqStats call */
struct mgmt_inq_stats r ;
r . in . max_count = MGMT_STATS_ARRAY_MAX_SIZE ;
r . in . unknown = 0 ;
2005-01-16 22:54:01 +00:00
status = dcerpc_mgmt_inq_stats ( mgmt_pipe , mem_ctx , & r ) ;
2004-11-03 01:55:21 +00:00
if ( NT_STATUS_IS_ERR ( status ) ) {
gtk_show_ntstatus ( NULL , status ) ;
return TRUE ;
}
if ( r . out . statistics . count ! = MGMT_STATS_ARRAY_MAX_SIZE ) {
printf ( " Unexpected array size %d \n " , r . out . statistics . count ) ;
return False ;
}
gtk_label_set_text ( GTK_LABEL ( lbl_calls_in ) , talloc_asprintf ( mem_ctx , " %6d " , r . out . statistics . statistics [ MGMT_STATS_CALLS_IN ] ) ) ;
gtk_label_set_text ( GTK_LABEL ( lbl_calls_out ) , talloc_asprintf ( mem_ctx , " %6d " , r . out . statistics . statistics [ MGMT_STATS_CALLS_OUT ] ) ) ;
gtk_label_set_text ( GTK_LABEL ( lbl_pkts_in ) , talloc_asprintf ( mem_ctx , " %6d " , r . out . statistics . statistics [ MGMT_STATS_PKTS_IN ] ) ) ;
gtk_label_set_text ( GTK_LABEL ( lbl_pkts_out ) , talloc_asprintf ( mem_ctx , " %6d " , r . out . statistics . statistics [ MGMT_STATS_PKTS_OUT ] ) ) ;
}
{
struct mgmt_inq_princ_name r ;
int i ;
for ( i = 0 ; i < 100 ; i + + ) {
r . in . authn_proto = i ; /* DCERPC_AUTH_TYPE_* */
r . in . princ_name_size = 100 ;
2005-01-16 22:54:01 +00:00
status = dcerpc_mgmt_inq_princ_name ( mgmt_pipe , mem_ctx , & r ) ;
2004-11-03 01:55:21 +00:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
continue ;
}
if ( W_ERROR_IS_OK ( r . out . result ) ) {
const char * name = gensec_get_name_by_authtype ( i ) ;
if ( name ) {
printf ( " \t principle name for proto %u (%s) is '%s' \n " ,
i , name , r . out . princ_name ) ;
} else {
printf ( " \t principle name for proto %u is '%s' \n " ,
i , r . out . princ_name ) ;
}
}
}
}
return TRUE ;
}
2004-10-25 11:28:09 +00:00
static GtkWidget * create_mainwindow ( void )
{
2004-11-03 01:55:21 +00:00
GtkWidget * mainwindow ;
GtkWidget * vbox1 , * vbox2 , * vbox3 ;
GtkWidget * menubar1 ;
GtkWidget * menuitem1 ;
GtkWidget * menuitem1_menu ;
GtkWidget * quit1 ;
GtkWidget * menuitem4 ;
GtkWidget * menuitem4_menu ;
2005-01-16 22:54:01 +00:00
GtkWidget * mnu_connect ;
GtkWidget * mnu_refresh ;
2004-11-03 01:55:21 +00:00
GtkWidget * about1 ;
GtkWidget * hbox2 ;
GtkWidget * scrolledwindow1 ;
GtkWidget * frame1 ;
GtkWidget * tree_eps ;
GtkTreeViewColumn * curcol ;
GtkCellRenderer * renderer ;
GtkWidget * statusbar ;
GtkAccelGroup * accel_group ;
2004-10-27 22:41:14 +00:00
2004-11-03 01:55:21 +00:00
accel_group = gtk_accel_group_new ( ) ;
2004-10-27 22:41:14 +00:00
2004-11-03 01:55:21 +00:00
mainwindow = gtk_window_new ( GTK_WINDOW_TOPLEVEL ) ;
gtk_window_set_title ( GTK_WINDOW ( mainwindow ) , " Gtk+ Endpoint Mapper Viewer " ) ;
2004-10-27 22:41:14 +00:00
2004-11-03 01:55:21 +00:00
vbox1 = gtk_vbox_new ( FALSE , 0 ) ;
gtk_widget_show ( vbox1 ) ;
gtk_container_add ( GTK_CONTAINER ( mainwindow ) , vbox1 ) ;
2004-10-27 22:41:14 +00:00
2004-11-03 01:55:21 +00:00
menubar1 = gtk_menu_bar_new ( ) ;
gtk_widget_show ( menubar1 ) ;
gtk_box_pack_start ( GTK_BOX ( vbox1 ) , menubar1 , FALSE , FALSE , 0 ) ;
2004-10-25 11:28:09 +00:00
2004-11-03 01:55:21 +00:00
menuitem1 = gtk_menu_item_new_with_mnemonic ( " _File " ) ;
gtk_widget_show ( menuitem1 ) ;
gtk_container_add ( GTK_CONTAINER ( menubar1 ) , menuitem1 ) ;
2004-10-25 11:28:09 +00:00
2004-11-03 01:55:21 +00:00
menuitem1_menu = gtk_menu_new ( ) ;
gtk_menu_item_set_submenu ( GTK_MENU_ITEM ( menuitem1 ) , menuitem1_menu ) ;
2004-10-25 11:28:09 +00:00
2005-01-16 22:54:01 +00:00
mnu_connect = gtk_menu_item_new_with_mnemonic ( " _Connect " ) ;
gtk_container_add ( GTK_CONTAINER ( menuitem1_menu ) , mnu_connect ) ;
mnu_refresh = gtk_menu_item_new_with_mnemonic ( " _Refresh " ) ;
gtk_container_add ( GTK_CONTAINER ( menuitem1_menu ) , mnu_refresh ) ;
2004-11-03 01:55:21 +00:00
quit1 = gtk_image_menu_item_new_from_stock ( " gtk-quit " , accel_group ) ;
gtk_container_add ( GTK_CONTAINER ( menuitem1_menu ) , quit1 ) ;
menuitem4 = gtk_menu_item_new_with_mnemonic ( " _Help " ) ;
gtk_container_add ( GTK_CONTAINER ( menubar1 ) , menuitem4 ) ;
menuitem4_menu = gtk_menu_new ( ) ;
gtk_menu_item_set_submenu ( GTK_MENU_ITEM ( menuitem4 ) , menuitem4_menu ) ;
about1 = gtk_menu_item_new_with_mnemonic ( " _About " ) ;
gtk_container_add ( GTK_CONTAINER ( menuitem4_menu ) , about1 ) ;
hbox2 = gtk_hbox_new ( FALSE , 0 ) ;
gtk_container_add ( GTK_CONTAINER ( vbox1 ) , hbox2 ) ;
scrolledwindow1 = gtk_scrolled_window_new ( NULL , NULL ) ;
gtk_box_pack_start ( GTK_BOX ( hbox2 ) , scrolledwindow1 , TRUE , TRUE , 0 ) ;
tree_eps = gtk_tree_view_new ( ) ;
curcol = gtk_tree_view_column_new ( ) ;
gtk_tree_view_column_set_title ( curcol , " Name " ) ;
renderer = gtk_cell_renderer_text_new ( ) ;
gtk_tree_view_column_pack_start ( curcol , renderer , True ) ;
gtk_tree_view_append_column ( GTK_TREE_VIEW ( tree_eps ) , curcol ) ;
gtk_tree_view_column_add_attribute ( curcol , renderer , " text " , 0 ) ;
curcol = gtk_tree_view_column_new ( ) ;
gtk_tree_view_column_set_title ( curcol , " Binding String " ) ;
renderer = gtk_cell_renderer_text_new ( ) ;
gtk_tree_view_column_pack_start ( curcol , renderer , True ) ;
gtk_tree_view_column_add_attribute ( curcol , renderer , " text " , 1 ) ;
gtk_tree_view_append_column ( GTK_TREE_VIEW ( tree_eps ) , curcol ) ;
2004-12-21 03:28:26 +00:00
store_eps = gtk_tree_store_new ( 3 , G_TYPE_STRING , G_TYPE_STRING , G_TYPE_POINTER ) ;
2004-11-03 01:55:21 +00:00
gtk_tree_view_set_model ( GTK_TREE_VIEW ( tree_eps ) , GTK_TREE_MODEL ( store_eps ) ) ;
g_object_unref ( store_eps ) ;
gtk_container_add ( GTK_CONTAINER ( scrolledwindow1 ) , tree_eps ) ;
gtk_tree_selection_set_select_function ( gtk_tree_view_get_selection ( GTK_TREE_VIEW ( tree_eps ) ) , on_eps_select , NULL , NULL ) ;
vbox2 = gtk_vbox_new ( FALSE , 0 ) ;
gtk_container_add ( GTK_CONTAINER ( hbox2 ) , vbox2 ) ;
frame1 = gtk_frame_new ( " Interface " ) ;
gtk_container_add ( GTK_CONTAINER ( vbox2 ) , frame1 ) ;
vbox3 = gtk_vbox_new ( FALSE , 0 ) ;
gtk_container_add ( GTK_CONTAINER ( frame1 ) , vbox3 ) ;
gtk_container_add ( GTK_CONTAINER ( vbox3 ) , lbl_iface_uuid = gtk_label_new ( " " ) ) ;
gtk_container_add ( GTK_CONTAINER ( vbox3 ) , lbl_iface_version = gtk_label_new ( " " ) ) ;
gtk_container_add ( GTK_CONTAINER ( vbox3 ) , lbl_iface_name = gtk_label_new ( " " ) ) ;
frame1 = gtk_frame_new ( " Statistics " ) ;
gtk_container_add ( GTK_CONTAINER ( vbox2 ) , frame1 ) ;
table_statistics = gtk_table_new ( 4 , 2 , TRUE ) ;
gtk_container_add ( GTK_CONTAINER ( frame1 ) , table_statistics ) ;
gtk_table_attach_defaults ( GTK_TABLE ( table_statistics ) , gtk_label_new ( " Calls In: " ) , 0 , 1 , 0 , 1 ) ;
gtk_table_attach_defaults ( GTK_TABLE ( table_statistics ) , lbl_calls_in = gtk_label_new ( " " ) , 1 , 2 , 0 , 1 ) ;
gtk_table_attach_defaults ( GTK_TABLE ( table_statistics ) , gtk_label_new ( " Calls Out: " ) , 0 , 1 , 1 , 2 ) ;
gtk_table_attach_defaults ( GTK_TABLE ( table_statistics ) , lbl_calls_out = gtk_label_new ( " " ) , 1 , 2 , 1 , 2 ) ;
gtk_table_attach_defaults ( GTK_TABLE ( table_statistics ) , gtk_label_new ( " Packets In: " ) , 0 , 1 , 2 , 3 ) ;
gtk_table_attach_defaults ( GTK_TABLE ( table_statistics ) , lbl_pkts_in = gtk_label_new ( " " ) , 1 , 2 , 2 , 3 ) ;
gtk_table_attach_defaults ( GTK_TABLE ( table_statistics ) , gtk_label_new ( " Packets Out: " ) , 0 , 1 , 3 , 4 ) ;
gtk_table_attach_defaults ( GTK_TABLE ( table_statistics ) , lbl_pkts_out = gtk_label_new ( " " ) , 1 , 2 , 3 , 4 ) ;
frame1 = gtk_frame_new ( " Authentication " ) ;
gtk_container_add ( GTK_CONTAINER ( vbox2 ) , frame1 ) ;
statusbar = gtk_statusbar_new ( ) ;
gtk_box_pack_start ( GTK_BOX ( vbox1 ) , statusbar , FALSE , FALSE , 0 ) ;
g_signal_connect ( ( gpointer ) quit1 , " activate " ,
G_CALLBACK ( on_quit1_activate ) ,
NULL ) ;
g_signal_connect ( ( gpointer ) about1 , " activate " ,
G_CALLBACK ( on_about1_activate ) ,
NULL ) ;
2005-01-16 22:54:01 +00:00
g_signal_connect ( ( gpointer ) mnu_connect , " activate " ,
G_CALLBACK ( on_connect_clicked ) ,
2004-11-03 01:55:21 +00:00
NULL ) ;
2005-01-16 22:54:01 +00:00
g_signal_connect ( ( gpointer ) mnu_refresh , " activate " ,
G_CALLBACK ( on_refresh_clicked ) ,
2004-11-03 01:55:21 +00:00
NULL ) ;
gtk_window_add_accel_group ( GTK_WINDOW ( mainwindow ) , accel_group ) ;
return mainwindow ;
2004-10-25 11:28:09 +00:00
}
2005-02-15 11:57:43 +00:00
int main ( int argc , char * * argv )
2004-10-25 11:28:09 +00:00
{
2004-11-06 23:23:15 +00:00
gepdump_init_subsystems ;
2004-11-03 00:17:12 +00:00
lp_load ( dyn_CONFIGFILE , True , False , False ) ;
load_interfaces ( ) ;
2005-02-15 11:57:43 +00:00
setup_logging ( argv [ 0 ] , DEBUG_STDERR ) ;
gtk_init ( & argc , & argv ) ;
2004-10-25 11:28:09 +00:00
mainwin = create_mainwindow ( ) ;
2004-10-27 22:41:14 +00:00
gtk_widget_show_all ( mainwin ) ;
2005-02-15 11:57:43 +00:00
return gtk_event_loop ( ) ;
2004-10-25 11:28:09 +00:00
}