Handle -K, -n, -N, and -u in the common dissection option code.

Also update tfshark to use that code.

Change-Id: Ic03fb8ff48c8bfc460298d180b436e53f0076cbe
Reviewed-on: https://code.wireshark.org/review/18588
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2016-10-30 18:47:59 -07:00
parent 706c106634
commit 5aacafba8e
14 changed files with 125 additions and 160 deletions

View File

@ -1817,6 +1817,7 @@ DISSECTOR_INCLUDES = \
packet-zbee-zdp.h \
packet-zep.h \
packet-ziop.h \
read_keytab_file.h \
$(GENERATED_HEADER_FILES) \
$(CUSTOM_HEADER_FILES)

View File

@ -73,6 +73,8 @@
#include "packet-cms.h"
#include "packet-windows-common.h"
#include "read_keytab_file.h"
#include "packet-dcerpc-netlogon.h"
#include "packet-dcerpc.h"

View File

@ -92,12 +92,6 @@ decrypt_krb5_data(proto_tree *tree, packet_info *pinfo,
extern gboolean krb_decrypt;
WS_DLL_PUBLIC
void read_keytab_file(const char *);
WS_DLL_PUBLIC
void read_keytab_file_from_preferences(void);
#endif /* HAVE_KERBEROS */
#include "packet-kerberos-exp.h"

View File

@ -41,6 +41,8 @@
/* for keytab format */
#include <epan/asn1.h>
#include "packet-kerberos.h"
/* for routines to read the keytab file */
#include "read_keytab_file.h"
/* for decoding */
void proto_register_dcerpc_netlogon(void);

View File

@ -81,6 +81,8 @@
#include "packet-cms.h"
#include "packet-windows-common.h"
#include "read_keytab_file.h"
#include "packet-dcerpc-netlogon.h"
#include "packet-dcerpc.h"
@ -349,7 +351,7 @@ static int hf_kerberos_KDCOptions_renew = -1;
static int hf_kerberos_KDCOptions_validate = -1;
/*--- End of included file: packet-kerberos-hf.c ---*/
#line 172 "./asn1/kerberos/packet-kerberos-template.c"
#line 174 "./asn1/kerberos/packet-kerberos-template.c"
/* Initialize the subtree pointers */
static gint ett_kerberos = -1;
@ -425,7 +427,7 @@ static gint ett_kerberos_KERB_PA_PAC_REQUEST = -1;
static gint ett_kerberos_ChangePasswdData = -1;
/*--- End of included file: packet-kerberos-ett.c ---*/
#line 186 "./asn1/kerberos/packet-kerberos-template.c"
#line 188 "./asn1/kerberos/packet-kerberos-template.c"
static expert_field ei_kerberos_decrypted_keytype = EI_INIT;
static expert_field ei_kerberos_address = EI_INIT;
@ -454,7 +456,7 @@ static gboolean gbl_do_col_info;
#define KERBEROS_ADDR_TYPE_IPV6 24
/*--- End of included file: packet-kerberos-val.h ---*/
#line 199 "./asn1/kerberos/packet-kerberos-template.c"
#line 201 "./asn1/kerberos/packet-kerberos-template.c"
static void
call_kerberos_callbacks(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int tag, kerberos_callbacks *cb)
@ -4204,7 +4206,7 @@ dissect_kerberos_ChangePasswdData(gboolean implicit_tag _U_, tvbuff_t *tvb _U_,
/*--- End of included file: packet-kerberos-fn.c ---*/
#line 1848 "./asn1/kerberos/packet-kerberos-template.c"
#line 1850 "./asn1/kerberos/packet-kerberos-template.c"
/* Make wrappers around exported functions for now */
int
@ -5258,7 +5260,7 @@ void proto_register_kerberos(void) {
NULL, HFILL }},
/*--- End of included file: packet-kerberos-hfarr.c ---*/
#line 2229 "./asn1/kerberos/packet-kerberos-template.c"
#line 2231 "./asn1/kerberos/packet-kerberos-template.c"
};
/* List of subtrees */
@ -5336,7 +5338,7 @@ void proto_register_kerberos(void) {
&ett_kerberos_ChangePasswdData,
/*--- End of included file: packet-kerberos-ettarr.c ---*/
#line 2245 "./asn1/kerberos/packet-kerberos-template.c"
#line 2247 "./asn1/kerberos/packet-kerberos-template.c"
};
static ei_register_info ei[] = {

View File

@ -100,12 +100,6 @@ decrypt_krb5_data(proto_tree *tree, packet_info *pinfo,
extern gboolean krb_decrypt;
WS_DLL_PUBLIC
void read_keytab_file(const char *);
WS_DLL_PUBLIC
void read_keytab_file_from_preferences(void);
#endif /* HAVE_KERBEROS */
@ -134,7 +128,7 @@ void read_keytab_file_from_preferences(void);
int dissect_kerberos_ChangePasswdData(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_);
/*--- End of included file: packet-kerberos-exp.h ---*/
#line 104 "./asn1/kerberos/packet-kerberos-template.h"
#line 98 "./asn1/kerberos/packet-kerberos-template.h"
#ifdef __cplusplus
}

View File

@ -52,6 +52,8 @@
#include "packet-dcerpc.h"
#include "packet-gssapi.h"
#include "read_keytab_file.h"
#include "packet-ntlmssp.h"
void proto_register_ntlmssp(void);

View File

@ -48,6 +48,8 @@
#include "packet-smb-common.h"
#include "packet-dcerpc-nt.h"
#include "read_keytab_file.h"
#include <wsutil/wsgcrypt.h>
#define NT_STATUS_PENDING 0x00000103

View File

@ -0,0 +1,43 @@
/* read_keytab_file.h
* Routines for reading Kerberos keytab files
* Copyright 2007, Anders Broman <anders.broman@ericsson.com>
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef __READ_KEYTAB_FILE_H
#define __READ_KEYTAB_FILE_H
#include "ws_symbol_export.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
WS_DLL_PUBLIC
void read_keytab_file(const char *);
WS_DLL_PUBLIC
void read_keytab_file_from_preferences(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __READ_KEYTAB_FILE_H */

View File

@ -69,17 +69,13 @@
#include <epan/addr_resolv.h>
#include "ui/util.h"
#include "ui/decode_as_utils.h"
#include "ui/dissect_opts.h"
#include "register.h"
#include <epan/epan_dissect.h>
#include <epan/tap.h>
#include <epan/stat_tap_ui.h>
#include <epan/ex-opt.h>
#if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS)
#include <epan/asn1.h>
#include <epan/dissectors/packet-kerberos.h>
#endif
#ifdef HAVE_EXTCAP
#include "extcap.h"
#endif
@ -688,15 +684,6 @@ main(int argc, char *argv[])
case 'C':
/* already processed; just ignore it now */
break;
case 'd': /* Decode as rule */
if (!decode_as_command_option(optarg))
return 1;
break;
#if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS)
case 'K': /* Kerberos keytab file */
read_keytab_file(optarg);
break;
#endif
case 'e':
/* Field entry */
output_fields_add(output_fields, optarg);
@ -767,42 +754,6 @@ main(int argc, char *argv[])
case 'S': /* Set the line Separator to be printed between packets */
separator = g_strdup(optarg);
break;
case 't': /* Time stamp type */
if (strcmp(optarg, "r") == 0)
timestamp_set_type(TS_RELATIVE);
else if (strcmp(optarg, "a") == 0)
timestamp_set_type(TS_ABSOLUTE);
else if (strcmp(optarg, "ad") == 0)
timestamp_set_type(TS_ABSOLUTE_WITH_YMD);
else if (strcmp(optarg, "adoy") == 0)
timestamp_set_type(TS_ABSOLUTE_WITH_YDOY);
else if (strcmp(optarg, "d") == 0)
timestamp_set_type(TS_DELTA);
else if (strcmp(optarg, "dd") == 0)
timestamp_set_type(TS_DELTA_DIS);
else if (strcmp(optarg, "e") == 0)
timestamp_set_type(TS_EPOCH);
else if (strcmp(optarg, "u") == 0)
timestamp_set_type(TS_UTC);
else if (strcmp(optarg, "ud") == 0)
timestamp_set_type(TS_UTC_WITH_YMD);
else if (strcmp(optarg, "udoy") == 0)
timestamp_set_type(TS_UTC_WITH_YDOY);
else {
cmdarg_err("Invalid time stamp type \"%s\"; it must be one of:", optarg);
cmdarg_err_cont("\t\"a\" for absolute\n"
"\t\"ad\" for absolute with YYYY-MM-DD date\n"
"\t\"adoy\" for absolute with YYYY/DOY date\n"
"\t\"d\" for delta\n"
"\t\"dd\" for delta displayed\n"
"\t\"e\" for epoch\n"
"\t\"r\" for relative\n"
"\t\"u\" for absolute UTC\n"
"\t\"ud\" for absolute UTC with YYYY-MM-DD date\n"
"\t\"udoy\" for absolute UTC with YYYY/DOY date");
return 1;
}
break;
case 'T': /* printing Type */
if (strcmp(optarg, "text") == 0) {
output_action = WRITE_TEXT;
@ -843,18 +794,6 @@ main(int argc, char *argv[])
return 1;
}
break;
case 'u': /* Seconds type */
if (strcmp(optarg, "s") == 0)
timestamp_set_seconds_type(TS_SECONDS_DEFAULT);
else if (strcmp(optarg, "hms") == 0)
timestamp_set_seconds_type(TS_SECONDS_HOUR_MIN_SEC);
else {
cmdarg_err("Invalid seconds type \"%s\"; it must be one of:", optarg);
cmdarg_err_cont("\t\"s\" for seconds\n"
"\t\"hms\" for hours, minutes and seconds");
return 1;
}
break;
case 'v': /* Show version and exit */
comp_info_str = get_compiled_version_info(NULL, epan_get_compiled_version_info);
runtime_info_str = get_runtime_version_info(get_tfshark_runtime_version_info);
@ -903,6 +842,13 @@ main(int argc, char *argv[])
return 1;
}
break;
case 'd': /* Decode as rule */
case 'K': /* Kerberos keytab file */
case 't': /* Time stamp type */
case 'u': /* Seconds type */
if (!dissect_opts_handle_opt(opt, optarg))
return 1;
break;
default:
case '?': /* Bad flag - print usage message */
print_usage(stderr);

View File

@ -98,11 +98,6 @@
#include <epan/ex-opt.h>
#include <epan/exported_pdu.h>
#if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS)
#include <epan/asn1.h>
#include <epan/dissectors/packet-kerberos.h>
#endif
#include "capture_opts.h"
#include "caputils/capture-pcap-util.h"
@ -588,7 +583,6 @@ main(int argc, char *argv[])
dfilter_t *dfcode = NULL;
gchar *err_msg;
e_prefs *prefs_p;
char badopt;
int log_flags;
gchar *output_only = NULL;
gchar *volatile pdu_export_arg = NULL;
@ -613,7 +607,7 @@ main(int argc, char *argv[])
* We do *not* use a leading - because the behavior of a leading - is
* platform-dependent.
*/
#define OPTSTRING "+2" OPTSTRING_CAPTURE_COMMON OPTSTRING_DISSECT_COMMON "C:e:E:F:gG:hH:j:" "K:lnN:o:O:PqQr:R:S:T:u:U:vVw:W:xX:Y:z:"
#define OPTSTRING "+2" OPTSTRING_CAPTURE_COMMON OPTSTRING_DISSECT_COMMON "C:e:E:F:gG:hH:j:lo:O:PqQr:R:S:T:U:vVw:W:xX:Y:z:"
static const char optstring[] = OPTSTRING;
@ -1027,11 +1021,6 @@ main(int argc, char *argv[])
case 'C':
/* already processed; just ignore it now */
break;
#if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS)
case 'K': /* Kerberos keytab file */
read_keytab_file(optarg);
break;
#endif
case 'D': /* Print a list of capture devices and exit */
#ifdef HAVE_LIBPCAP
if_list = capture_interface_list(&err, &err_str,NULL);
@ -1125,23 +1114,6 @@ main(int argc, char *argv[])
arg_error = TRUE;
#endif
break;
case 'n': /* No name resolution */
disable_name_resolution();
break;
case 'N': /* Select what types of addresses/port #s to resolve */
badopt = string_to_name_resolve(optarg, &gbl_resolv_flags);
if (badopt != '\0') {
cmdarg_err("-N specifies unknown resolving option '%c'; valid options are:",
badopt);
cmdarg_err_cont("\t'd' to enable address resolution from captured DNS packets\n"
"\t'm' to enable MAC address resolution\n"
"\t'n' to enable network address resolution\n"
"\t'N' to enable using external resolvers (e.g., DNS)\n"
"\t for network address resolution\n"
"\t't' to enable transport-layer port number resolution");
return 1;
}
break;
case 'o': /* Override preference from command line */
switch (prefs_set_pref(optarg)) {
@ -1235,18 +1207,6 @@ main(int argc, char *argv[])
return 1;
}
break;
case 'u': /* Seconds type */
if (strcmp(optarg, "s") == 0)
timestamp_set_seconds_type(TS_SECONDS_DEFAULT);
else if (strcmp(optarg, "hms") == 0)
timestamp_set_seconds_type(TS_SECONDS_HOUR_MIN_SEC);
else {
cmdarg_err("Invalid seconds type \"%s\"; it must be one of:", optarg);
cmdarg_err_cont("\t\"s\" for seconds\n"
"\t\"hms\" for hours, minutes and seconds");
return 1;
}
break;
case 'U': /* Export PDUs to file */
{
GSList *export_pdu_tap_name_list = NULL;
@ -1311,14 +1271,17 @@ main(int argc, char *argv[])
}
break;
case 'd': /* Decode as rule */
case 'K': /* Kerberos keytab file */
case 'n': /* No name resolution */
case 'N': /* Select what types of addresses/port #s to resolve */
case 't': /* Time stamp type */
case 'u': /* Seconds type */
case LONGOPT_DISABLE_PROTOCOL: /* disable dissection of protocol */
case LONGOPT_ENABLE_HEURISTIC: /* enable heuristic dissection of protocol */
case LONGOPT_DISABLE_HEURISTIC: /* disable heuristic dissection of protocol */
if (!dissect_opts_handle_opt(opt, optarg))
return 1;
break;
default:
case '?': /* Bad flag - print usage message */
switch(optopt) {

View File

@ -43,7 +43,6 @@
#include <wsutil/filesystem.h>
#include <epan/ex-opt.h>
#include <epan/addr_resolv.h>
#include <epan/packet.h>
#include <epan/proto.h>
#include <epan/prefs.h>
@ -57,11 +56,6 @@
#include "recent.h"
#include "decode_as_utils.h"
#if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS)
#include <epan/asn1.h>
#include <epan/dissectors/packet-kerberos.h>
#endif
#include "../file.h"
#include "ui/dissect_opts.h"
@ -195,7 +189,7 @@ commandline_print_usage(gboolean for_help_option) {
*/
#define LONGOPT_FULL_SCREEN 65536
#define OPTSTRING OPTSTRING_CAPTURE_COMMON OPTSTRING_DISSECT_COMMON "C:g:Hh" "jJ:kK:lm:nN:o:P:r:R:Su:vw:X:Y:z:"
#define OPTSTRING OPTSTRING_CAPTURE_COMMON OPTSTRING_DISSECT_COMMON "C:g:Hh" "jJ:klm:o:P:r:R:Svw:X:Y:z:"
static const struct option long_options[] = {
{"help", no_argument, NULL, 'h'},
{"read-file", required_argument, NULL, 'r' },
@ -357,7 +351,6 @@ void commandline_other_options(int argc, char *argv[], gboolean opt_reset)
#else
gboolean capture_option_specified;
#endif
char badopt;
/*
* To reset the options parser, set optreset to 1 on platforms that
@ -445,12 +438,6 @@ void commandline_other_options(int argc, char *argv[], gboolean opt_reset)
#endif
break;
#if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS)
case 'K': /* Kerberos keytab file */
read_keytab_file(optarg);
break;
#endif
/*** all non capture option specific ***/
case 'C':
/* Configuration profile settings were already processed just ignore them this time*/
@ -480,17 +467,6 @@ void commandline_other_options(int argc, char *argv[], gboolean opt_reset)
arg_error = TRUE;
#endif
break;
case 'n': /* No name resolution */
disable_name_resolution();
break;
case 'N': /* Select what types of addresses/port #s to resolve */
badopt = string_to_name_resolve(optarg, &gbl_resolv_flags);
if (badopt != '\0') {
cmdarg_err("-N specifies unknown resolving option '%c'; valid options are 'd', m', 'n', 'N', and 't'",
badopt);
exit(1);
}
break;
case 'o': /* Override preference from command line */
switch (prefs_set_pref(optarg)) {
case PREFS_SET_OK:
@ -540,17 +516,6 @@ void commandline_other_options(int argc, char *argv[], gboolean opt_reset)
case 'R': /* Read file filter */
global_commandline_info.rfilter = optarg;
break;
case 'u': /* Seconds type */
if (strcmp(optarg, "s") == 0)
timestamp_set_seconds_type(TS_SECONDS_DEFAULT);
else if (strcmp(optarg, "hms") == 0)
timestamp_set_seconds_type(TS_SECONDS_HOUR_MIN_SEC);
else {
cmdarg_err("Invalid seconds type \"%s\"", optarg);
cmdarg_err_cont("It must be \"s\" for seconds or \"hms\" for hours, minutes and seconds.");
exit(1);
}
break;
case 'X':
/* ext ops were already processed just ignore them this time*/
break;
@ -576,7 +541,11 @@ void commandline_other_options(int argc, char *argv[], gboolean opt_reset)
}
break;
case 'd': /* Decode as rule */
case 'K': /* Kerberos keytab file */
case 'n': /* No name resolution */
case 'N': /* Select what types of addresses/port #s to resolve */
case 't': /* time stamp type */
case 'u': /* Seconds type */
case LONGOPT_DISABLE_PROTOCOL: /* disable dissection of protocol */
case LONGOPT_ENABLE_HEURISTIC: /* enable heuristic dissection of protocol */
case LONGOPT_DISABLE_HEURISTIC: /* disable heuristic dissection of protocol */

View File

@ -31,10 +31,16 @@
#include <glib.h>
#include <epan/prefs.h>
#include <epan/timestamp.h>
#include <epan/addr_resolv.h>
#include "ui/decode_as_utils.h"
#if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS)
#include <epan/dissectors/read_keytab_file.h>
#endif
#include <wsutil/clopts_common.h>
#include <wsutil/cmdarg_err.h>
#include <wsutil/file_util.h>
@ -55,11 +61,38 @@ dissect_opts_init(void)
gboolean
dissect_opts_handle_opt(int opt, char *optarg_str_p)
{
char badopt;
switch(opt) {
case 'd': /* Decode as rule */
if (!decode_as_command_option(optarg_str_p))
return FALSE;
break;
case 'K': /* Kerberos keytab file */
#if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS)
read_keytab_file(optarg_str_p);
#else
cmdarg_err("-K specified, but Kerberos keytab file support isn't present");
return FALSE;
#endif
break;
case 'n': /* No name resolution */
disable_name_resolution();
break;
case 'N': /* Select what types of addresses/port #s to resolve */
badopt = string_to_name_resolve(optarg_str_p, &gbl_resolv_flags);
if (badopt != '\0') {
cmdarg_err("-N specifies unknown resolving option '%c'; valid options are:",
badopt);
cmdarg_err_cont("\t'd' to enable address resolution from captured DNS packets\n"
"\t'm' to enable MAC address resolution\n"
"\t'n' to enable network address resolution\n"
"\t'N' to enable using external resolvers (e.g., DNS)\n"
"\t for network address resolution\n"
"\t't' to enable transport-layer port number resolution");
return FALSE;
}
break;
case 't': /* Time stamp type */
if (strcmp(optarg_str_p, "r") == 0)
global_dissect_options.time_format = TS_RELATIVE;
@ -96,6 +129,18 @@ dissect_opts_handle_opt(int opt, char *optarg_str_p)
return FALSE;
}
break;
case 'u': /* Seconds type */
if (strcmp(optarg_str_p, "s") == 0)
timestamp_set_seconds_type(TS_SECONDS_DEFAULT);
else if (strcmp(optarg_str_p, "hms") == 0)
timestamp_set_seconds_type(TS_SECONDS_HOUR_MIN_SEC);
else {
cmdarg_err("Invalid seconds type \"%s\"; it must be one of:", optarg_str_p);
cmdarg_err_cont("\t\"s\" for seconds\n"
"\t\"hms\" for hours, minutes and seconds");
return FALSE;
}
break;
case LONGOPT_DISABLE_PROTOCOL: /* disable dissection of protocol */
global_dissect_options.disable_protocol_slist = g_slist_append(global_dissect_options.disable_protocol_slist, optarg_str_p);
break;

View File

@ -66,7 +66,7 @@ extern "C" {
{"disable-heuristic", required_argument, NULL, LONGOPT_DISABLE_HEURISTIC }, \
#define OPTSTRING_DISSECT_COMMON \
"d:t:"
"d:K:nN:t:u:"
/** Capture options coming from user interface */
typedef struct dissect_options_tag {