Bug Summary

File:extcap/sshdump.c
Warning:line 279, column 9
Opened stream never closed. Potential resource leak

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name sshdump.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -ffloat16-excess-precision=fast -fbfloat16-excess-precision=fast -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/builds/wireshark/wireshark/build -fcoverage-compilation-dir=/builds/wireshark/wireshark/build -resource-dir /usr/lib/llvm-19/lib/clang/19 -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D WS_DEBUG -D WS_DEBUG_UTF_8 -I /builds/wireshark/wireshark/build -I /builds/wireshark/wireshark -I /builds/wireshark/wireshark/include -D _GLIBCXX_ASSERTIONS -internal-isystem /usr/lib/llvm-19/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/builds/wireshark/wireshark/= -fmacro-prefix-map=/builds/wireshark/wireshark/build/= -fmacro-prefix-map=../= -Wno-format-truncation -Wno-format-nonliteral -Wno-pointer-sign -std=gnu11 -ferror-limit 19 -fvisibility=hidden -fwrapv -fstrict-flex-arrays=3 -stack-protector 2 -fstack-clash-protection -fcf-protection=full -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fexceptions -fcolor-diagnostics -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /builds/wireshark/wireshark/sbout/2025-07-07-100249-3847-1 -x c /builds/wireshark/wireshark/extcap/sshdump.c
1/* sshdump.c
2 * sshdump is extcap tool used to capture data using a remote ssh host
3 *
4 * Copyright 2015, Dario Lombardo
5 *
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
9 *
10 * SPDX-License-Identifier: GPL-2.0-or-later
11 */
12
13#include "config.h"
14#define WS_LOG_DOMAIN"sshdump" "sshdump"
15
16#include <extcap/extcap-base.h>
17#include <extcap/ssh-base.h>
18#include <wsutil/interface.h>
19#include <wsutil/file_util.h>
20#include <wsutil/strtoi.h>
21#include <wsutil/filesystem.h>
22#include <wsutil/privileges.h>
23#include <wsutil/please_report_bug.h>
24#include <wsutil/wslog.h>
25
26#include <errno(*__errno_location ()).h>
27#include <string.h>
28#include <fcntl.h>
29
30#include <cli_main.h>
31
32static char* sshdump_extcap_interface;
33#define DEFAULT_SSHDUMP_EXTCAP_INTERFACE"sshdump" "sshdump"
34
35#define SSHDUMP_VERSION_MAJOR"1" "1"
36#define SSHDUMP_VERSION_MINOR"2" "2"
37#define SSHDUMP_VERSION_RELEASE"0" "0"
38
39#define SSH_READ_BLOCK_SIZE256 256
40
41enum {
42 EXTCAP_BASE_OPTIONS_ENUMEXTCAP_OPT_LIST_INTERFACES, EXTCAP_OPT_VERSION, EXTCAP_OPT_LIST_DLTS
, EXTCAP_OPT_INTERFACE, EXTCAP_OPT_CONFIG, EXTCAP_OPT_CAPTURE
, EXTCAP_OPT_CAPTURE_FILTER, EXTCAP_OPT_FIFO, EXTCAP_OPT_LOG_LEVEL
, EXTCAP_OPT_LOG_FILE
,
43 OPT_HELP,
44 OPT_VERSION,
45 OPT_REMOTE_HOST,
46 OPT_REMOTE_PORT,
47 OPT_REMOTE_USERNAME,
48 OPT_REMOTE_PASSWORD,
49 OPT_REMOTE_INTERFACE,
50 OPT_REMOTE_CAPTURE_COMMAND_SELECT,
51 OPT_REMOTE_CAPTURE_COMMAND,
52 OPT_REMOTE_FILTER,
53 OPT_SSHKEY,
54 OPT_SSHKEY_PASSPHRASE,
55 OPT_PROXYCOMMAND,
56 OPT_SSH_SHA1,
57 OPT_REMOTE_COUNT,
58 OPT_REMOTE_SUDO, // Deprecated
59 OPT_REMOTE_PRIV,
60 OPT_REMOTE_PRIV_USER,
61 OPT_REMOTE_NOPROM
62};
63
64static const struct ws_option longopts[] = {
65 EXTCAP_BASE_OPTIONS{ "extcap-interfaces", 0, ((void*)0), EXTCAP_OPT_LIST_INTERFACES
}, { "extcap-version", 2, ((void*)0), EXTCAP_OPT_VERSION}, { "extcap-dlts"
, 0, ((void*)0), EXTCAP_OPT_LIST_DLTS}, { "extcap-interface",
1, ((void*)0), EXTCAP_OPT_INTERFACE}, { "extcap-config", 0, (
(void*)0), EXTCAP_OPT_CONFIG}, { "capture", 0, ((void*)0), EXTCAP_OPT_CAPTURE
}, { "extcap-capture-filter", 1, ((void*)0), EXTCAP_OPT_CAPTURE_FILTER
}, { "fifo", 1, ((void*)0), EXTCAP_OPT_FIFO}, { "log-level", 1
, ((void*)0), EXTCAP_OPT_LOG_LEVEL}, { "log-file", 1, ((void*
)0), EXTCAP_OPT_LOG_FILE}
,
66 { "help", ws_no_argument0, NULL((void*)0), OPT_HELP},
67 { "version", ws_no_argument0, NULL((void*)0), OPT_VERSION},
68 SSH_BASE_PACKET_OPTIONS{ "remote-host", 1, ((void*)0), OPT_REMOTE_HOST}, { "remote-port"
, 1, ((void*)0), OPT_REMOTE_PORT}, { "remote-username", 1, ((
void*)0), OPT_REMOTE_USERNAME}, { "remote-password", 1, ((void
*)0), OPT_REMOTE_PASSWORD}, { "remote-count", 1, ((void*)0), OPT_REMOTE_COUNT
}, { "sshkey", 1, ((void*)0), OPT_SSHKEY}, { "sshkey-passphrase"
, 1, ((void*)0), OPT_SSHKEY_PASSPHRASE}, { "proxycommand", 1,
((void*)0), OPT_PROXYCOMMAND}, { "ssh-sha1", 0, ((void*)0), OPT_SSH_SHA1
}, { "remote-interface", 1, ((void*)0), OPT_REMOTE_INTERFACE}
, { "remote-filter", 1, ((void*)0), OPT_REMOTE_FILTER}
,
69 { "remote-capture-command-select", ws_required_argument1, NULL((void*)0), OPT_REMOTE_CAPTURE_COMMAND_SELECT},
70 { "remote-capture-command", ws_required_argument1, NULL((void*)0), OPT_REMOTE_CAPTURE_COMMAND},
71 { "remote-sudo", ws_no_argument0, NULL((void*)0), OPT_REMOTE_SUDO }, // Deprecated
72 { "remote-priv", ws_required_argument1, NULL((void*)0), OPT_REMOTE_PRIV },
73 { "remote-priv-user", ws_required_argument1, NULL((void*)0), OPT_REMOTE_PRIV_USER },
74 { "remote-noprom", ws_no_argument0, NULL((void*)0), OPT_REMOTE_NOPROM },
75 { 0, 0, 0, 0}
76};
77
78static char* interfaces_list_to_filter(GSList* if_list, unsigned int remote_port);
79
80static int ssh_loop_read(ssh_channel channel, FILE* fp)
81{
82 int nbytes;
83 int ret = EXIT_SUCCESS0;
84 char buffer[SSH_READ_BLOCK_SIZE256];
85
86 /* read from stdin until data are available */
87 while (ssh_channel_is_open(channel) && !ssh_channel_is_eof(channel)) {
88 nbytes = ssh_channel_read(channel, buffer, SSH_READ_BLOCK_SIZE256, 0);
89 if (nbytes < 0) {
90 ws_warning("Error reading from channel")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c"
, 90, __func__, "Error reading from channel"); } } while (0)
;
91 goto end;
92 }
93 if (nbytes == 0) {
94 break;
95 }
96 if (fwrite(buffer, 1, nbytes, fp) != (unsigned)nbytes) {
97 ws_warning("Error writing to fifo")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c"
, 97, __func__, "Error writing to fifo"); } } while (0)
;
98 ret = EXIT_FAILURE1;
99 goto end;
100 }
101 fflush(fp);
102 }
103
104 /* read loop finished... maybe something wrong happened. Read from stderr */
105 while (ssh_channel_is_open(channel) && !ssh_channel_is_eof(channel)) {
106 nbytes = ssh_channel_read(channel, buffer, SSH_READ_BLOCK_SIZE256, 1);
107 if (nbytes < 0) {
108 ws_warning("Error reading from channel")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c"
, 108, __func__, "Error reading from channel"); } } while (0)
;
109 goto end;
110 }
111 if (fwrite(buffer, 1, nbytes, stderrstderr) != (unsigned)nbytes) {
112 ws_warning("Error writing to stderr")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c"
, 112, __func__, "Error writing to stderr"); } } while (0)
;
113 break;
114 }
115 }
116
117end:
118 if (ssh_channel_send_eof(channel) != SSH_OK0) {
119 ws_warning("Error sending EOF in ssh channel")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c"
, 119, __func__, "Error sending EOF in ssh channel"); } } while
(0)
;
120 ret = EXIT_FAILURE1;
121 }
122 return ret;
123}
124
125static char* local_interfaces_to_filter(const uint16_t remote_port)
126{
127 GSList* interfaces = local_interfaces_to_list();
128 char* filter = interfaces_list_to_filter(interfaces, remote_port);
129 g_slist_free_full(interfaces, g_free);
130 return filter;
131}
132
133static ssh_channel run_ssh_command(ssh_session sshs, const char* capture_command_select,
134 const char* capture_command, const char* privilege, bool_Bool noprom,
135 const char* iface, const char* cfilter, const uint32_t count)
136{
137 char* cmdline = NULL((void*)0);
138 ssh_channel channel;
139 char** ifaces_array = NULL((void*)0);
140 int ifaces_array_num = 0;
141 GString *ifaces_string;
142 char *ifaces = NULL((void*)0);
143 char* quoted_iface = NULL((void*)0);
144 char* quoted_filter = NULL((void*)0);
145 char* count_str = NULL((void*)0);
146 unsigned int remote_port = 22;
147
148 channel = ssh_channel_new(sshs);
149 if (!channel) {
150 ws_warning("Can't create channel")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c"
, 150, __func__, "Can't create channel"); } } while (0)
;
151 return NULL((void*)0);
152 }
153
154 if (ssh_channel_open_session(channel) != SSH_OK0) {
155 ws_warning("Can't open session")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c"
, 155, __func__, "Can't open session"); } } while (0)
;
156 ssh_channel_free(channel);
157 return NULL((void*)0);
158 }
159
160 ssh_options_get_port(sshs, &remote_port);
161
162 if (capture_command_select == NULL((void*)0) || !g_strcmp0(capture_command_select, "other")) {
163 if (capture_command && *capture_command) {
164 cmdline = g_strdup(capture_command)g_strdup_inline (capture_command);
165 ws_debug("Remote capture command has disabled other options")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_DEBUG, "extcap/sshdump.c"
, 165, __func__, "Remote capture command has disabled other options"
); } } while (0)
;
166 } else {
167 capture_command_select = "tcpdump";
168 }
169 }
170
171 /* escape parameters to go save with the shell */
172 if (!g_strcmp0(capture_command_select, "tcpdump")) {
173 quoted_iface = iface ? g_shell_quote(iface) : NULL((void*)0);
174 quoted_filter = g_shell_quote(cfilter ? cfilter : "");
175 if (count > 0)
176 count_str = ws_strdup_printf("-c %u", count)wmem_strdup_printf(((void*)0), "-c %u", count);
177
178 cmdline = ws_strdup_printf("%s tcpdump -U %s%s %s -w - %s %s",wmem_strdup_printf(((void*)0), "%s tcpdump -U %s%s %s -w - %s %s"
, privilege, quoted_iface ? "-i " : "", quoted_iface ? quoted_iface
: "", noprom ? "-p" : "", count_str ? count_str : "", quoted_filter
)
179 privilege,wmem_strdup_printf(((void*)0), "%s tcpdump -U %s%s %s -w - %s %s"
, privilege, quoted_iface ? "-i " : "", quoted_iface ? quoted_iface
: "", noprom ? "-p" : "", count_str ? count_str : "", quoted_filter
)
180 quoted_iface ? "-i " : "",wmem_strdup_printf(((void*)0), "%s tcpdump -U %s%s %s -w - %s %s"
, privilege, quoted_iface ? "-i " : "", quoted_iface ? quoted_iface
: "", noprom ? "-p" : "", count_str ? count_str : "", quoted_filter
)
181 quoted_iface ? quoted_iface : "",wmem_strdup_printf(((void*)0), "%s tcpdump -U %s%s %s -w - %s %s"
, privilege, quoted_iface ? "-i " : "", quoted_iface ? quoted_iface
: "", noprom ? "-p" : "", count_str ? count_str : "", quoted_filter
)
182 noprom ? "-p" : "",wmem_strdup_printf(((void*)0), "%s tcpdump -U %s%s %s -w - %s %s"
, privilege, quoted_iface ? "-i " : "", quoted_iface ? quoted_iface
: "", noprom ? "-p" : "", count_str ? count_str : "", quoted_filter
)
183 count_str ? count_str : "",wmem_strdup_printf(((void*)0), "%s tcpdump -U %s%s %s -w - %s %s"
, privilege, quoted_iface ? "-i " : "", quoted_iface ? quoted_iface
: "", noprom ? "-p" : "", count_str ? count_str : "", quoted_filter
)
184 quoted_filter)wmem_strdup_printf(((void*)0), "%s tcpdump -U %s%s %s -w - %s %s"
, privilege, quoted_iface ? "-i " : "", quoted_iface ? quoted_iface
: "", noprom ? "-p" : "", count_str ? count_str : "", quoted_filter
)
;
185 } else if (!g_strcmp0(capture_command_select, "dumpcap")) {
186 if (iface) {
187 ifaces_array = g_strsplit(iface, " ", -1);
188 ifaces_string = g_string_new(NULL((void*)0));
189 while (ifaces_array[ifaces_array_num])
190 {
191 quoted_iface = g_shell_quote(ifaces_array[ifaces_array_num]);
192 g_string_append_printf(ifaces_string, "-i %s ", quoted_iface);
193 ifaces_array_num++;
194 }
195 ifaces = g_string_free(ifaces_string, FALSE)(__builtin_constant_p ((0)) ? (((0)) ? (g_string_free) ((ifaces_string
), ((0))) : g_string_free_and_steal (ifaces_string)) : (g_string_free
) ((ifaces_string), ((0))))
;
196 }
197 quoted_filter = g_shell_quote(cfilter ? cfilter : "");
198 if (count > 0)
199 count_str = ws_strdup_printf("-c %u", count)wmem_strdup_printf(((void*)0), "-c %u", count);
200
201 cmdline = ws_strdup_printf("%s dumpcap %s %s -w - %s -f %s",wmem_strdup_printf(((void*)0), "%s dumpcap %s %s -w - %s -f %s"
, privilege, noprom ? "-p" : "", ifaces ? ifaces : "", count_str
? count_str : "", quoted_filter)
202 privilege,wmem_strdup_printf(((void*)0), "%s dumpcap %s %s -w - %s -f %s"
, privilege, noprom ? "-p" : "", ifaces ? ifaces : "", count_str
? count_str : "", quoted_filter)
203 noprom ? "-p" : "",wmem_strdup_printf(((void*)0), "%s dumpcap %s %s -w - %s -f %s"
, privilege, noprom ? "-p" : "", ifaces ? ifaces : "", count_str
? count_str : "", quoted_filter)
204 ifaces ? ifaces : "",wmem_strdup_printf(((void*)0), "%s dumpcap %s %s -w - %s -f %s"
, privilege, noprom ? "-p" : "", ifaces ? ifaces : "", count_str
? count_str : "", quoted_filter)
205 count_str ? count_str : "",wmem_strdup_printf(((void*)0), "%s dumpcap %s %s -w - %s -f %s"
, privilege, noprom ? "-p" : "", ifaces ? ifaces : "", count_str
? count_str : "", quoted_filter)
206 quoted_filter)wmem_strdup_printf(((void*)0), "%s dumpcap %s %s -w - %s -f %s"
, privilege, noprom ? "-p" : "", ifaces ? ifaces : "", count_str
? count_str : "", quoted_filter)
;
207
208 g_free(ifaces);
209 g_strfreev(ifaces_array);
210 }
211
212 ws_debug("Running: %s", cmdline)do { if (1) { ws_log_full("sshdump", LOG_LEVEL_DEBUG, "extcap/sshdump.c"
, 212, __func__, "Running: %s", cmdline); } } while (0)
;
213 if (ssh_channel_request_exec(channel, cmdline) != SSH_OK0) {
214 ws_warning("Can't request exec")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c"
, 214, __func__, "Can't request exec"); } } while (0)
;
215 ssh_channel_close(channel);
216 ssh_channel_free(channel);
217 channel = NULL((void*)0);
218 }
219
220 g_free(quoted_iface);
221 g_free(quoted_filter);
222 g_free(cmdline);
223 g_free(count_str);
224
225 return channel;
226}
227
228static int ssh_open_remote_connection(const ssh_params_t* params, const char* iface, const char* cfilter,
229 const char* capture_command_select, const char* capture_command, const char* privilege,
230 bool_Bool noprom, const uint32_t count, const char* fifo)
231{
232 ssh_session sshs = NULL((void*)0);
233 ssh_channel channel = NULL((void*)0);
234 FILE* fp = stdoutstdout;
235 int ret = EXIT_FAILURE1;
236 char* err_info = NULL((void*)0);
237
238 if (g_strcmp0(fifo, "-")) {
26
Assuming the condition is true
27
Taking true branch
239 /* Open or create the output file */
240 fp = fopen(fifo, "wb");
28
Stream opened here
29
Assuming that 'fopen' is successful
241 if (fp
29.1
'fp' is not equal to NULL
== NULL((void*)0)) {
30
Taking false branch
242 ws_warning("Error creating output file: %s (%s)", fifo, g_strerror(errno))do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c"
, 242, __func__, "Error creating output file: %s (%s)", fifo,
g_strerror((*__errno_location ()))); } } while (0)
;
243 return EXIT_FAILURE1;
244 }
245 }
246
247 sshs = create_ssh_connection(params, &err_info);
248
249 if (!sshs) {
31
Assuming 'sshs' is null
32
Taking true branch
250 ws_warning("Error creating connection.")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c"
, 250, __func__, "Error creating connection."); } } while (0)
;
33
Taking true branch
34
Loop condition is false. Exiting loop
251 goto cleanup;
35
Control jumps to line 270
252 }
253
254 channel = run_ssh_command(sshs, capture_command_select, capture_command, privilege, noprom, iface, cfilter, count);
255
256 if (!channel) {
257 ws_warning("Can't run ssh command.")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c"
, 257, __func__, "Can't run ssh command."); } } while (0)
;
258 goto cleanup;
259 }
260
261 /* read from channel and write into fp */
262 if (ssh_loop_read(channel, fp) != EXIT_SUCCESS0) {
263 ws_warning("Error in read loop.")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c"
, 263, __func__, "Error in read loop."); } } while (0)
;
264 ret = EXIT_FAILURE1;
265 goto cleanup;
266 }
267
268 ret = EXIT_SUCCESS0;
269cleanup:
270 if (err_info)
36
Assuming 'err_info' is null
37
Taking false branch
271 ws_warning("%s", err_info)do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c"
, 271, __func__, "%s", err_info); } } while (0)
;
272 g_free(err_info);
273
274 /* clean up and exit */
275 ssh_cleanup(&sshs, &channel);
276
277 if (g_strcmp0(fifo, "-"))
38
Assuming the condition is false
39
Taking false branch
278 fclose(fp);
279 return ret;
40
Opened stream never closed. Potential resource leak
280}
281
282static char* interfaces_list_to_filter(GSList* interfaces, unsigned int remote_port)
283{
284 GString* filter = g_string_new(NULL((void*)0));
285 GSList* cur;
286
287 // If no port is given, assume the default one. This might not be
288 // correct if the port is looked up from the ssh config file, but it is
289 // better than nothing.
290 if (remote_port == 0) {
291 remote_port = 22;
292 }
293
294 if (!interfaces) {
295 g_string_append_printf(filter, "not port %u", remote_port);
296 } else {
297 g_string_append_printf(filter, "not ((host %s", (char*)interfaces->data);
298 cur = g_slist_next(interfaces)((interfaces) ? (((GSList *)(interfaces))->next) : ((void*
)0))
;
299 while (cur) {
300 g_string_append_printf(filter, " or host %s", (char*)cur->data);
301 cur = g_slist_next(cur)((cur) ? (((GSList *)(cur))->next) : ((void*)0));
302 }
303 g_string_append_printf(filter, ") and port %u)", remote_port);
304 }
305 return g_string_free(filter, FALSE)(__builtin_constant_p ((0)) ? (((0)) ? (g_string_free) ((filter
), ((0))) : g_string_free_and_steal (filter)) : (g_string_free
) ((filter), ((0))))
;
306}
307
308static int list_config(char *interface, unsigned int remote_port)
309{
310 unsigned inc = 0;
311 char* ipfilter;
312
313 if (!interface) {
314 ws_warning("ERROR: No interface specified.")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c"
, 314, __func__, "ERROR: No interface specified."); } } while
(0)
;
315 return EXIT_FAILURE1;
316 }
317
318 if (g_strcmp0(interface, sshdump_extcap_interface)) {
319 ws_warning("ERROR: interface must be %s", sshdump_extcap_interface)do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c"
, 319, __func__, "ERROR: interface must be %s", sshdump_extcap_interface
); } } while (0)
;
320 return EXIT_FAILURE1;
321 }
322
323 ipfilter = local_interfaces_to_filter(remote_port);
324
325 printf("arg {number=%u}{call=--remote-host}{display=Remote SSH server address}"
326 "{type=string}{tooltip=The remote SSH host. It can be both "
327 "an IP address or a hostname}{required=true}{group=Server}\n", inc++);
328 printf("arg {number=%u}{call=--remote-port}{display=Remote SSH server port}"
329 "{type=unsigned}{default=22}{tooltip=The remote SSH host port (1-65535)}"
330 "{range=1,65535}{group=Server}\n", inc++);
331 printf("arg {number=%u}{call=--remote-username}{display=Remote SSH server username}"
332 "{type=string}{tooltip=The remote SSH username. If not provided, "
333 "the current user will be used}{group=Authentication}\n", inc++);
334 printf("arg {number=%u}{call=--remote-password}{display=Remote SSH server password}"
335 "{type=password}{tooltip=The SSH password, used when other methods (SSH agent "
336 "or key files) are unavailable.}{group=Authentication}\n", inc++);
337 printf("arg {number=%u}{call=--sshkey}{display=Path to SSH private key}"
338 "{type=fileselect}{tooltip=The path on the local filesystem of the private SSH key (OpenSSH format)}"
339 "{mustexist=true}{group=Authentication}\n", inc++);
340 printf("arg {number=%u}{call=--sshkey-passphrase}{display=SSH key passphrase}"
341 "{type=password}{tooltip=Passphrase to unlock the SSH private key}{group=Authentication}\n",
342 inc++);
343 printf("arg {number=%u}{call=--proxycommand}{display=ProxyCommand}"
344 "{type=string}{tooltip=The command to use as proxy for the SSH connection}"
345 "{group=Authentication}\n", inc++);
346 printf("arg {number=%u}{call=--ssh-sha1}{display=Support SHA-1 keys (deprecated)}"
347 "{type=boolflag}{tooltip=Support keys and key exchange algorithms using SHA-1 (deprecated)}{group=Authentication}"
348 "\n", inc++);
349 printf("arg {number=%u}{call=--remote-interface}{display=Remote interface}"
350 "{type=string}{tooltip=The remote network interface used for capture"
351 "}{group=Capture}\n", inc++);
352 printf("arg {number=%u}{call=--remote-capture-command-select}{display=Remote capture command selection}"
353 "{type=radio}{tooltip=The remote capture command to build a command line for}{group=Capture}\n", inc);
354 printf("value {arg=%u}{value=dumpcap}{display=dumpcap}\n", inc);
355 printf("value {arg=%u}{value=tcpdump}{display=tcpdump}{default=true}\n", inc);
356 printf("value {arg=%u}{value=other}{display=Other:}\n", inc++);
357 printf("arg {number=%u}{call=--remote-capture-command}{display=Remote capture command}"
358 "{type=string}{tooltip=The remote command used to capture}{group=Capture}\n", inc++);
359 // Deprecated
360 //printf("arg {number=%u}{call=--remote-sudo}{display=Use sudo on the remote machine}"
361 // "{type=boolflag}{tooltip=Prepend the capture command with sudo on the remote machine}"
362 // "{group=Capture}\n", inc++);
363 printf("arg {number=%u}{call=--remote-priv}{display=Gain capture privilege on the remote machine}"
364 "{type=radio}{tooltip=Optionally prepend the capture command with sudo or doas on the remote machine}"
365 "{group=Capture}\n", inc);
366 printf("value {arg=%u}{value=none}{display=none}{default=true}\n", inc);
367 printf("value {arg=%u}{value=sudo}{display=sudo}\n", inc);
368 printf("value {arg=%u}{value=doas -n}{display=doas}\n", inc++);
369 printf("arg {number=%u}{call=--remote-priv-user}{display=Privileged user name for sudo or doas}"
370 "{type=string}{tooltip=User name of privileged user to execute the capture command on the remote machine}"
371 "{group=Capture}\n", inc++);
372 printf("arg {number=%u}{call=--remote-noprom}{display=No promiscuous mode}"
373 "{type=boolflag}{tooltip=Don't use promiscuous mode on the remote machine}{group=Capture}"
374 "\n", inc++);
375 printf("arg {number=%u}{call=--remote-filter}{display=Remote capture filter}{type=string}"
376 "{tooltip=The remote capture filter}", inc++);
377 if (ipfilter)
378 printf("{default=%s}", ipfilter);
379 printf("{group=Capture}\n");
380 printf("arg {number=%u}{call=--remote-count}{display=Packets to capture}"
381 "{type=unsigned}{default=0}{tooltip=The number of remote packets to capture. (Default: inf)}"
382 "{group=Capture}\n", inc++);
383
384 extcap_config_debug(&inc);
385
386 g_free(ipfilter);
387
388 return EXIT_SUCCESS0;
389}
390
391static char* concat_filters(const char* extcap_filter, const char* remote_filter)
392{
393 if (!extcap_filter && remote_filter)
394 return g_strdup(remote_filter)g_strdup_inline (remote_filter);
395
396 if (!remote_filter && extcap_filter)
397 return g_strdup(extcap_filter)g_strdup_inline (extcap_filter);
398
399 if (!remote_filter && !extcap_filter)
400 return NULL((void*)0);
401
402 return ws_strdup_printf("(%s) and (%s)", extcap_filter, remote_filter)wmem_strdup_printf(((void*)0), "(%s) and (%s)", extcap_filter
, remote_filter)
;
403}
404
405int main(int argc, char *argv[])
406{
407 char* err_msg;
408 int result;
409 int option_idx = 0;
410 ssh_params_t* ssh_params = ssh_params_new();
411 char* remote_interface = NULL((void*)0);
412 char* remote_capture_command_select = NULL((void*)0);
413 char* remote_capture_command = NULL((void*)0);
414 char* remote_filter = NULL((void*)0);
415 uint32_t count = 0;
416 int ret = EXIT_FAILURE1;
417 extcap_parameters* extcap_conf = g_new0(extcap_parameters, 1)((extcap_parameters *) g_malloc0_n ((1), sizeof (extcap_parameters
)))
;
418 char* help_url;
419 char* help_header = NULL((void*)0);
420 char* priv = NULL((void*)0);
421 char* priv_user = NULL((void*)0);
422 bool_Bool noprom = false0;
423 char* interface_description = g_strdup("SSH remote capture")g_strdup_inline ("SSH remote capture");
424
425 /* Set the program name. */
426 g_set_prgname("sshdump");
427
428 /* Initialize log handler early so we can have proper logging during startup. */
429 extcap_log_init();
430
431 sshdump_extcap_interface = g_path_get_basename(argv[0]);
432 if (g_str_has_suffix(sshdump_extcap_interface, ".exe")(__builtin_constant_p (".exe")? __extension__ ({ const char *
const __str = (sshdump_extcap_interface); const char * const
__suffix = (".exe"); gboolean __result = (0); if (__str == (
(void*)0) || __suffix == ((void*)0)) __result = (g_str_has_suffix
) (__str, __suffix); else { const size_t __str_len = strlen (
((__str) + !(__str))); const size_t __suffix_len = strlen (((
__suffix) + !(__suffix))); if (__str_len >= __suffix_len) __result
= memcmp (__str + __str_len - __suffix_len, ((__suffix) + !(
__suffix)), __suffix_len) == 0; } __result; }) : (g_str_has_suffix
) (sshdump_extcap_interface, ".exe") )
) {
1
'?' condition is true
2
Assuming '__str' is not equal to null
3
Taking false branch
4
Assuming '__str_len' is < '__suffix_len'
5
Taking false branch
6
Taking false branch
433 sshdump_extcap_interface[strlen(sshdump_extcap_interface) - 4] = '\0';
434 }
435
436 /*
437 * Get credential information for later use.
438 */
439 init_process_policies();
440
441 /*
442 * Attempt to get the pathname of the directory containing the
443 * executable file.
444 */
445 err_msg = configuration_init(argv[0]);
446 if (err_msg != NULL((void*)0)) {
7
Assuming 'err_msg' is equal to NULL
8
Taking false branch
447 ws_warning("Can't get pathname of directory containing the extcap program: %s.",do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c"
, 448, __func__, "Can't get pathname of directory containing the extcap program: %s."
, err_msg); } } while (0)
448 err_msg)do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c"
, 448, __func__, "Can't get pathname of directory containing the extcap program: %s."
, err_msg); } } while (0)
;
449 g_free(err_msg);
450 }
451
452 help_url = data_file_url("sshdump.html");
453 extcap_base_set_util_info(extcap_conf, argv[0], SSHDUMP_VERSION_MAJOR"1", SSHDUMP_VERSION_MINOR"2",
454 SSHDUMP_VERSION_RELEASE"0", help_url);
455 g_free(help_url);
456 add_libssh_info(extcap_conf);
457 if (g_strcmp0(sshdump_extcap_interface, DEFAULT_SSHDUMP_EXTCAP_INTERFACE"sshdump")) {
9
Assuming the condition is false
10
Taking false branch
458 char* temp = interface_description;
459 interface_description = ws_strdup_printf("%s, custom version", interface_description)wmem_strdup_printf(((void*)0), "%s, custom version", interface_description
)
;
460 g_free(temp);
461 }
462 extcap_base_register_interface(extcap_conf, sshdump_extcap_interface, interface_description, 147, "Remote capture dependent DLT");
463 g_free(interface_description);
464
465 help_header = ws_strdup_printf(wmem_strdup_printf(((void*)0), " %s --extcap-interfaces\n" " %s --extcap-interface=%s --extcap-dlts\n"
" %s --extcap-interface=%s --extcap-config\n" " %s --extcap-interface=%s --remote-host myhost --remote-port 22222 "
"--remote-username myuser --remote-interface eth2 --remote-capture-command 'tcpdump -U -i eth0 -w -' "
"--fifo=FILENAME --capture\n", argv[0], argv[0], sshdump_extcap_interface
, argv[0], sshdump_extcap_interface, argv[0], sshdump_extcap_interface
)
466 " %s --extcap-interfaces\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces\n" " %s --extcap-interface=%s --extcap-dlts\n"
" %s --extcap-interface=%s --extcap-config\n" " %s --extcap-interface=%s --remote-host myhost --remote-port 22222 "
"--remote-username myuser --remote-interface eth2 --remote-capture-command 'tcpdump -U -i eth0 -w -' "
"--fifo=FILENAME --capture\n", argv[0], argv[0], sshdump_extcap_interface
, argv[0], sshdump_extcap_interface, argv[0], sshdump_extcap_interface
)
467 " %s --extcap-interface=%s --extcap-dlts\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces\n" " %s --extcap-interface=%s --extcap-dlts\n"
" %s --extcap-interface=%s --extcap-config\n" " %s --extcap-interface=%s --remote-host myhost --remote-port 22222 "
"--remote-username myuser --remote-interface eth2 --remote-capture-command 'tcpdump -U -i eth0 -w -' "
"--fifo=FILENAME --capture\n", argv[0], argv[0], sshdump_extcap_interface
, argv[0], sshdump_extcap_interface, argv[0], sshdump_extcap_interface
)
468 " %s --extcap-interface=%s --extcap-config\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces\n" " %s --extcap-interface=%s --extcap-dlts\n"
" %s --extcap-interface=%s --extcap-config\n" " %s --extcap-interface=%s --remote-host myhost --remote-port 22222 "
"--remote-username myuser --remote-interface eth2 --remote-capture-command 'tcpdump -U -i eth0 -w -' "
"--fifo=FILENAME --capture\n", argv[0], argv[0], sshdump_extcap_interface
, argv[0], sshdump_extcap_interface, argv[0], sshdump_extcap_interface
)
469 " %s --extcap-interface=%s --remote-host myhost --remote-port 22222 "wmem_strdup_printf(((void*)0), " %s --extcap-interfaces\n" " %s --extcap-interface=%s --extcap-dlts\n"
" %s --extcap-interface=%s --extcap-config\n" " %s --extcap-interface=%s --remote-host myhost --remote-port 22222 "
"--remote-username myuser --remote-interface eth2 --remote-capture-command 'tcpdump -U -i eth0 -w -' "
"--fifo=FILENAME --capture\n", argv[0], argv[0], sshdump_extcap_interface
, argv[0], sshdump_extcap_interface, argv[0], sshdump_extcap_interface
)
470 "--remote-username myuser --remote-interface eth2 --remote-capture-command 'tcpdump -U -i eth0 -w -' "wmem_strdup_printf(((void*)0), " %s --extcap-interfaces\n" " %s --extcap-interface=%s --extcap-dlts\n"
" %s --extcap-interface=%s --extcap-config\n" " %s --extcap-interface=%s --remote-host myhost --remote-port 22222 "
"--remote-username myuser --remote-interface eth2 --remote-capture-command 'tcpdump -U -i eth0 -w -' "
"--fifo=FILENAME --capture\n", argv[0], argv[0], sshdump_extcap_interface
, argv[0], sshdump_extcap_interface, argv[0], sshdump_extcap_interface
)
471 "--fifo=FILENAME --capture\n", argv[0], argv[0], sshdump_extcap_interface, argv[0],wmem_strdup_printf(((void*)0), " %s --extcap-interfaces\n" " %s --extcap-interface=%s --extcap-dlts\n"
" %s --extcap-interface=%s --extcap-config\n" " %s --extcap-interface=%s --remote-host myhost --remote-port 22222 "
"--remote-username myuser --remote-interface eth2 --remote-capture-command 'tcpdump -U -i eth0 -w -' "
"--fifo=FILENAME --capture\n", argv[0], argv[0], sshdump_extcap_interface
, argv[0], sshdump_extcap_interface, argv[0], sshdump_extcap_interface
)
472 sshdump_extcap_interface, argv[0], sshdump_extcap_interface)wmem_strdup_printf(((void*)0), " %s --extcap-interfaces\n" " %s --extcap-interface=%s --extcap-dlts\n"
" %s --extcap-interface=%s --extcap-config\n" " %s --extcap-interface=%s --remote-host myhost --remote-port 22222 "
"--remote-username myuser --remote-interface eth2 --remote-capture-command 'tcpdump -U -i eth0 -w -' "
"--fifo=FILENAME --capture\n", argv[0], argv[0], sshdump_extcap_interface
, argv[0], sshdump_extcap_interface, argv[0], sshdump_extcap_interface
)
;
473 extcap_help_add_header(extcap_conf, help_header);
474 g_free(help_header);
475 extcap_help_add_option(extcap_conf, "--help", "print this help");
476 extcap_help_add_option(extcap_conf, "--version", "print the version");
477 extcap_help_add_option(extcap_conf, "--remote-host <host>", "the remote SSH host");
478 extcap_help_add_option(extcap_conf, "--remote-port <port>", "the remote SSH port");
479 extcap_help_add_option(extcap_conf, "--remote-username <username>", "the remote SSH username");
480 extcap_help_add_option(extcap_conf, "--remote-password <password>", "the remote SSH password. If not specified, ssh-agent and ssh-key are used");
481 extcap_help_add_option(extcap_conf, "--sshkey <private key path>", "the path of the SSH key (OpenSSH format)");
482 extcap_help_add_option(extcap_conf, "--sshkey-passphrase <private key passphrase>", "the passphrase to unlock private SSH key");
483 extcap_help_add_option(extcap_conf, "--proxycommand <proxy command>", "the command to use as proxy for the SSH connection");
484 extcap_help_add_option(extcap_conf, "--ssh-sha1", "support keys and key exchange using SHA-1 (deprecated)");
485 extcap_help_add_option(extcap_conf, "--remote-interface <iface>", "the remote capture interface");
486 extcap_help_add_option(extcap_conf, "--remote-capture-command-select <selection>", "dumpcap, tcpdump or other remote capture command");
487 extcap_help_add_option(extcap_conf, "--remote-capture-command <capture command>", "the remote capture command");
488 //extcap_help_add_option(extcap_conf, "--remote-sudo", "use sudo on the remote machine to capture"); // Deprecated
489 extcap_help_add_option(extcap_conf, "--remote-priv <selection>", "none, sudo or doas");
490 extcap_help_add_option(extcap_conf, "--remote-priv-user <username>", "privileged user name");
491 extcap_help_add_option(extcap_conf, "--remote-noprom", "don't use promiscuous mode on the remote machine");
492 extcap_help_add_option(extcap_conf, "--remote-filter <filter>", "a filter for remote capture (default: don't listen on local interfaces IPs)");
493 extcap_help_add_option(extcap_conf, "--remote-count <count>", "the number of packets to capture");
494
495 ws_opterr = 0;
496 ws_optind = 0;
497
498 if (argc == 1) {
11
Assuming 'argc' is not equal to 1
12
Taking false branch
499 extcap_help_print(extcap_conf);
500 goto end;
501 }
502
503 while ((result = ws_getopt_long(argc, argv, ":", longopts, &option_idx)) != -1) {
13
Assuming the condition is false
14
Loop condition is false. Execution continues on line 620
504
505 switch (result) {
506
507 case OPT_HELP:
508 extcap_help_print(extcap_conf);
509 ret = EXIT_SUCCESS0;
510 goto end;
511
512 case OPT_VERSION:
513 extcap_version_print(extcap_conf);
514 ret = EXIT_SUCCESS0;
515 goto end;
516
517 case OPT_REMOTE_HOST:
518 g_free(ssh_params->host);
519 ssh_params->host = g_strdup(ws_optarg)g_strdup_inline (ws_optarg);
520 break;
521
522 case OPT_REMOTE_PORT:
523 if (!ws_strtou16(ws_optarg, NULL((void*)0), &ssh_params->port) || ssh_params->port == 0) {
524 ws_warning("Invalid port: %s", ws_optarg)do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c"
, 524, __func__, "Invalid port: %s", ws_optarg); } } while (0
)
;
525 goto end;
526 }
527 break;
528
529 case OPT_REMOTE_USERNAME:
530 g_free(ssh_params->username);
531 ssh_params->username = g_strdup(ws_optarg)g_strdup_inline (ws_optarg);
532 break;
533
534 case OPT_REMOTE_PASSWORD:
535 g_free(ssh_params->password);
536 ssh_params->password = g_strdup(ws_optarg)g_strdup_inline (ws_optarg);
537 memset(ws_optarg, 'X', strlen(ws_optarg));
538 break;
539
540 case OPT_SSHKEY:
541 g_free(ssh_params->sshkey_path);
542 ssh_params->sshkey_path = g_strdup(ws_optarg)g_strdup_inline (ws_optarg);
543 break;
544
545 case OPT_SSHKEY_PASSPHRASE:
546 g_free(ssh_params->sshkey_passphrase);
547 ssh_params->sshkey_passphrase = g_strdup(ws_optarg)g_strdup_inline (ws_optarg);
548 memset(ws_optarg, 'X', strlen(ws_optarg));
549 break;
550
551 case OPT_PROXYCOMMAND:
552 g_free(ssh_params->proxycommand);
553 ssh_params->proxycommand = g_strdup(ws_optarg)g_strdup_inline (ws_optarg);
554 break;
555
556 case OPT_SSH_SHA1:
557 ssh_params->ssh_sha1 = true1;
558 break;
559
560 case OPT_REMOTE_INTERFACE:
561 g_free(remote_interface);
562 remote_interface = g_strdup(ws_optarg)g_strdup_inline (ws_optarg);
563 break;
564
565 case OPT_REMOTE_CAPTURE_COMMAND_SELECT:
566 g_free(remote_capture_command_select);
567 remote_capture_command_select = g_strdup(ws_optarg)g_strdup_inline (ws_optarg);
568 break;
569
570 case OPT_REMOTE_CAPTURE_COMMAND:
571 g_free(remote_capture_command);
572 remote_capture_command = g_strdup(ws_optarg)g_strdup_inline (ws_optarg);
573 break;
574
575 case OPT_REMOTE_SUDO:
576 // Deprecated
577 g_free(priv);
578 priv = g_strdup("sudo")g_strdup_inline ("sudo");
579 break;
580
581 case OPT_REMOTE_PRIV:
582 g_free(priv);
583 priv = g_strdup(ws_optarg)g_strdup_inline (ws_optarg);
584 break;
585
586 case OPT_REMOTE_PRIV_USER:
587 g_free(priv_user);
588 priv_user = g_strdup(ws_optarg)g_strdup_inline (ws_optarg);
589 break;
590
591 case OPT_REMOTE_FILTER:
592 g_free(remote_filter);
593 remote_filter = g_strdup(ws_optarg)g_strdup_inline (ws_optarg);
594 break;
595
596 case OPT_REMOTE_COUNT:
597 if (!ws_strtou32(ws_optarg, NULL((void*)0), &count)) {
598 ws_warning("Invalid value for count: %s", ws_optarg)do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c"
, 598, __func__, "Invalid value for count: %s", ws_optarg); }
} while (0)
;
599 goto end;
600 }
601 break;
602
603 case OPT_REMOTE_NOPROM:
604 noprom = true1;
605 break;
606
607 case ':':
608 /* missing option argument */
609 ws_warning("Option '%s' requires an argument", argv[ws_optind - 1])do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c"
, 609, __func__, "Option '%s' requires an argument", argv[ws_optind
- 1]); } } while (0)
;
610 break;
611
612 default:
613 if (!extcap_base_parse_options(extcap_conf, result - EXTCAP_OPT_LIST_INTERFACES, ws_optarg)) {
614 ws_warning("Invalid option: %s", argv[ws_optind - 1])do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c"
, 614, __func__, "Invalid option: %s", argv[ws_optind - 1]); }
} while (0)
;
615 goto end;
616 }
617 }
618 }
619
620 extcap_cmdline_debug(argv, argc);
621
622 if (extcap_base_handle_interface(extcap_conf)) {
15
Assuming the condition is false
16
Taking false branch
623 ret = EXIT_SUCCESS0;
624 goto end;
625 }
626
627 if (extcap_conf->show_config) {
17
Assuming field 'show_config' is 0
18
Taking false branch
628 ret = list_config(extcap_conf->interface, ssh_params->port);
629 goto end;
630 }
631
632 err_msg = ws_init_sockets();
633 if (err_msg != NULL((void*)0)) {
19
Assuming 'err_msg' is equal to NULL
20
Taking false branch
634 ws_warning("ERROR: %s", err_msg)do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c"
, 634, __func__, "ERROR: %s", err_msg); } } while (0)
;
635 g_free(err_msg);
636 ws_warning("%s", please_report_bug())do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c"
, 636, __func__, "%s", please_report_bug()); } } while (0)
;
637 goto end;
638 }
639
640 if (extcap_conf->capture) {
21
Assuming field 'capture' is not equal to 0
22
Taking true branch
641 char* filter;
642 char* privilege;
643
644 if (!ssh_params->host) {
23
Assuming field 'host' is non-null
645 ws_warning("Missing parameter: --remote-host")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c"
, 645, __func__, "Missing parameter: --remote-host"); } } while
(0)
;
646 goto end;
647 }
648
649 if ((priv
23.1
'priv' is null
) && g_strcmp0(priv, "none") && strlen(g_strstrip(priv)g_strchomp (g_strchug (priv)))) {
650 if ((priv_user) && strlen(g_strstrip(priv_user)g_strchomp (g_strchug (priv_user))))
651 /* Both sudo and doas use the same command line option */
652 privilege = g_strconcat(priv, " -u ", priv_user, NULL((void*)0));
653 else
654 privilege = g_strdup(priv)g_strdup_inline (priv);
655 } else {
656 privilege = g_strdup("")g_strdup_inline ("");
657 }
658
659 // This may result in the use of a different port number than was given in
660 // the default filter string, as presented in the config dialog. The default
661 // given is always using the default SSH port since there's no remote SSH port
662 // given on the command line to get the extcap arguments.
663 // However the remote SSH port used here is the one given on the command line
664 // when the capture us started, which is the intended one.
665 // And this is only happening when no remote filter is specified on the command
666 // line to start the capture.
667 if (remote_filter
23.2
'remote_filter' is equal to NULL
== NULL((void*)0))
24
Taking true branch
668 remote_filter = local_interfaces_to_filter(ssh_params->port);
669 filter = concat_filters(extcap_conf->capture_filter, remote_filter);
670 ssh_params_set_log_level(ssh_params, extcap_conf->debug);
671 ret = ssh_open_remote_connection(ssh_params, remote_interface,
25
Calling 'ssh_open_remote_connection'
672 filter, remote_capture_command_select, remote_capture_command,
673 privilege, noprom, count, extcap_conf->fifo);
674 g_free(filter);
675 g_free(privilege);
676 } else {
677 ws_debug("You should not come here... maybe some parameter missing?")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_DEBUG, "extcap/sshdump.c"
, 677, __func__, "You should not come here... maybe some parameter missing?"
); } } while (0)
;
678 ret = EXIT_FAILURE1;
679 }
680
681end:
682 /* clean up stuff */
683 ssh_params_free(ssh_params);
684 g_free(remote_capture_command_select);
685 g_free(remote_capture_command);
686 g_free(remote_interface);
687 g_free(remote_filter);
688 g_free(priv);
689 g_free(priv_user);
690 extcap_base_cleanup(&extcap_conf);
691 return ret;
692}
693
694/*
695 * Editor modelines - https://www.wireshark.org/tools/modelines.html
696 *
697 * Local variables:
698 * c-basic-offset: 8
699 * tab-width: 8
700 * indent-tabs-mode: t
701 * End:
702 *
703 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
704 * :indentSize=8:tabSize=8:noTabs=false:
705 */