From Rolf Fiedler:
[obnox/wireshark/wip.git] / tap-smbsids.c
1 /* tap-smbsids.c
2  * smbstat   2003 Ronnie Sahlberg
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <stdio.h>
30
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
33 #endif
34
35 #include <string.h>
36 #include "epan/packet_info.h"
37 #include <epan/dissectors/packet-smb-sidsnooping.h>
38 #include "register.h"
39 #include <epan/tap.h>
40 #include <epan/emem.h>
41 #include <epan/stat_cmd_args.h>
42 #include "epan/value_string.h"
43 #include <epan/dissectors/packet-smb.h>
44
45
46 static int
47 smbsids_packet(void *pss _U_, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *psi _U_)
48 {
49         return 1;
50 }
51
52 static void 
53 enum_sids(gpointer key _U_, gpointer value, gpointer userdata _U_)
54 {
55         sid_name *sn=(sid_name *)value;
56
57         printf("%-60s %s\n", sn->sid, sn->name);
58         return;
59 }
60
61 static void
62 smbsids_draw(void *pss _U_)
63 {
64         printf("\n");
65         printf("===================================================================\n");
66         printf("SMB SID List:\n");
67         g_hash_table_foreach(sid_name_table, enum_sids, NULL);
68         printf("===================================================================\n");
69 }
70
71
72 static void
73 smbsids_init(const char *optarg _U_, void* userdata _U_)
74 {
75         GString *error_string;
76
77         if(!sid_name_snooping){
78                 fprintf(stderr,"The -z smb,sids function needs SMB/SID-Snooping to be enabled.\n");
79                 fprintf(stderr,"Either enable Edit/Preferences/Protocols/SMB/Snoop SID name mappings  in wireshark\n");
80                 fprintf(stderr,"or override the preference file by specifying\n");
81                 fprintf(stderr,"  -o \"smb.sid_name_snooping=TRUE\"\n");
82                 fprintf(stderr,"on the tshark command line.\n");
83                 exit(1);
84         }
85
86
87         error_string=register_tap_listener("smb", NULL, NULL, NULL, smbsids_packet, smbsids_draw);
88         if(error_string){
89                 fprintf(stderr, "tshark: Couldn't register smb,sids tap:%s\n",
90                     error_string->str);
91                 g_string_free(error_string, TRUE);
92                 exit(1);
93         }
94 }
95
96
97 void
98 register_tap_listener_smbsids(void)
99 {
100         register_stat_cmd_arg("smb,sids", smbsids_init,NULL);
101 }
102