Skip to content

Latest commit

 

History

History
2257 lines (1993 loc) · 58.5 KB

main.c

File metadata and controls

2257 lines (1993 loc) · 58.5 KB
 
Sep 22, 2008
Sep 22, 2008
1
/*
Nov 20, 2008
Nov 20, 2008
2
* OpenConnect (SSL + DTLS) VPN client
Sep 22, 2008
Sep 22, 2008
3
*
Jan 26, 2015
Jan 26, 2015
4
* Copyright © 2008-2015 Intel Corporation.
Apr 9, 2009
Apr 9, 2009
5
* Copyright © 2008 Nick Andrew <nick@nick-andrew.net>
Mar 23, 2013
Mar 23, 2013
6
* Copyright © 2013 John Morrissey <jwm@horde.net>
Sep 22, 2008
Sep 22, 2008
7
*
Nov 20, 2008
Nov 20, 2008
8
9
10
* Author: David Woodhouse <dwmw2@infradead.org>
*
* This program is free software; you can redistribute it and/or
Oct 4, 2008
Oct 4, 2008
11
* modify it under the terms of the GNU Lesser General Public License
Nov 20, 2008
Nov 20, 2008
12
* version 2.1, as published by the Free Software Foundation.
Sep 22, 2008
Sep 22, 2008
13
*
Nov 20, 2008
Nov 20, 2008
14
* This program is distributed in the hope that it will be useful, but
Oct 4, 2008
Oct 4, 2008
15
16
17
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
Sep 22, 2008
Sep 22, 2008
18
19
*/
Jul 1, 2014
Jul 1, 2014
20
21
#include <config.h>
May 13, 2012
May 13, 2012
22
23
24
25
26
#ifdef HAVE_GETLINE
/* Various BSD systems require this for getline() to be visible */
#define _WITH_GETLINE
#endif
Sep 20, 2008
Sep 20, 2008
27
#include <stdio.h>
Sep 21, 2008
Sep 21, 2008
28
#include <stdarg.h>
Sep 20, 2008
Sep 20, 2008
29
#include <stdlib.h>
Oct 19, 2009
Oct 19, 2009
30
#include <signal.h>
Sep 20, 2008
Sep 20, 2008
31
#include <string.h>
Nov 3, 2011
Nov 3, 2011
32
33
34
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
Sep 20, 2008
Sep 20, 2008
35
36
37
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
Sep 21, 2008
Sep 21, 2008
38
39
#include <sys/types.h>
#include <getopt.h>
Jan 15, 2014
Jan 15, 2014
40
#include <time.h>
Jul 29, 2014
Jul 29, 2014
41
#include <locale.h>
Jul 8, 2014
Jul 8, 2014
42
43
44
#ifdef LIBPROXY_HDR
#include LIBPROXY_HDR
Feb 6, 2014
Feb 6, 2014
45
#endif
Sep 20, 2008
Sep 20, 2008
46
Mar 9, 2011
Mar 9, 2011
47
#include "openconnect-internal.h"
Jul 8, 2014
Jul 8, 2014
48
Jul 8, 2014
Jul 8, 2014
49
#ifdef _WIN32
Jul 8, 2014
Jul 8, 2014
50
#include <shlwapi.h>
Jul 8, 2014
Jul 8, 2014
51
52
#include <wtypes.h>
#include <wincon.h>
Jul 8, 2014
Jul 8, 2014
53
54
55
56
#else
#include <sys/utsname.h>
#include <pwd.h>
#include <termios.h>
Jul 8, 2014
Jul 8, 2014
57
#endif
Sep 20, 2008
Sep 20, 2008
58
Jul 29, 2014
Jul 29, 2014
59
60
61
62
63
64
#ifdef HAVE_NL_LANGINFO
#include <langinfo.h>
static const char *legacy_charset;
#endif
Jun 27, 2011
Jun 27, 2011
65
static int write_new_config(void *_vpninfo,
Oct 9, 2014
Oct 9, 2014
66
const char *buf, int buflen);
Oct 29, 2014
Oct 29, 2014
67
68
static void __attribute__ ((format(printf, 3, 4)))
write_progress(void *_vpninfo, int level, const char *fmt, ...);
Nov 3, 2014
Nov 3, 2014
69
static int validate_peer_cert(void *_vpninfo, const char *reason);
Jan 15, 2014
Jan 15, 2014
70
71
static int process_auth_form_cb(void *_vpninfo,
struct oc_auth_form *form);
Mar 23, 2013
Mar 23, 2013
72
73
static void init_token(struct openconnect_info *vpninfo,
oc_token_mode_t token_mode, const char *token_str);
Oct 5, 2008
Oct 5, 2008
74
Nov 7, 2011
Nov 7, 2011
75
76
/* A sanity check that the openconnect executable is running against a
library of the same version */
May 12, 2012
May 12, 2012
77
#define openconnect_version_str openconnect_binary_version
Nov 8, 2012
Nov 8, 2012
78
#include <version.c>
May 12, 2012
May 12, 2012
79
#undef openconnect_version_str
Nov 7, 2011
Nov 7, 2011
80
Jul 8, 2014
Jul 8, 2014
81
82
static int verbose = PRG_INFO;
static int timestamp;
Apr 28, 2009
Apr 28, 2009
83
int background;
Jul 8, 2014
Jul 8, 2014
84
85
86
static int do_passphrase_from_fsid;
static int non_inter;
static int cookieonly;
Oct 6, 2015
Oct 6, 2015
87
static int allow_stdin_read;
Sep 21, 2008
Sep 21, 2008
88
Aug 12, 2014
Aug 12, 2014
89
static char *token_filename;
Nov 20, 2014
Nov 20, 2014
90
static char *server_cert = NULL;
Aug 12, 2014
Aug 12, 2014
91
Jul 8, 2014
Jul 8, 2014
92
93
94
95
96
97
98
static char *username;
static char *password;
static char *authgroup;
static int authgroup_set;
static int last_form_empty;
static int sig_cmd_fd;
Dec 30, 2013
Dec 30, 2013
99
Nov 6, 2018
Nov 6, 2018
100
101
static void add_form_field(char *field);
Feb 6, 2014
Feb 6, 2014
102
103
#ifdef __ANDROID__
#include <android/log.h>
Oct 29, 2014
Oct 29, 2014
104
105
static void __attribute__ ((format(printf, 3, 4)))
syslog_progress(void *_vpninfo, int level, const char *fmt, ...)
Feb 6, 2014
Feb 6, 2014
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
{
static int l[4] = {
ANDROID_LOG_ERROR, /* PRG_ERR */
ANDROID_LOG_INFO, /* PRG_INFO */
ANDROID_LOG_DEBUG, /* PRG_DEBUG */
ANDROID_LOG_DEBUG /* PRG_TRACE */
};
va_list args, args2;
if (verbose >= level) {
va_start(args, fmt);
va_copy(args2, args);
__android_log_vprint(l[level], "openconnect", fmt, args);
/* Android wants it to stderr too, so the GUI can scrape
it and display it as well as going to syslog */
vfprintf(stderr, fmt, args2);
va_end(args);
va_end(args2);
}
}
Jul 8, 2014
Jul 8, 2014
126
#define openlog(...) /* */
Mar 8, 2016
Mar 8, 2016
127
#elif defined(_WIN32) || defined(__native_client__)
Feb 6, 2014
Feb 6, 2014
128
129
130
131
/*
* FIXME: Perhaps we could implement syslog_progress() using these APIs:
* http://msdn.microsoft.com/en-us/library/windows/desktop/aa364148%28v=vs.85%29.aspx
*/
Mar 8, 2016
Mar 8, 2016
132
#else /* !__ANDROID__ && !_WIN32 && !__native_client__ */
Feb 6, 2014
Feb 6, 2014
133
#include <syslog.h>
Oct 29, 2014
Oct 29, 2014
134
135
static void __attribute__ ((format(printf, 3, 4)))
syslog_progress(void *_vpninfo, int level, const char *fmt, ...)
Feb 6, 2014
Feb 6, 2014
136
137
138
139
140
141
142
143
144
145
146
147
{
int priority = level ? LOG_INFO : LOG_NOTICE;
va_list args;
if (verbose >= level) {
va_start(args, fmt);
vsyslog(priority, fmt, args);
va_end(args);
}
}
#endif
Aug 7, 2010
Aug 7, 2010
148
enum {
Jun 11, 2012
Jun 11, 2012
149
150
OPT_AUTHENTICATE = 0x100,
OPT_AUTHGROUP,
Jun 8, 2012
Jun 8, 2012
151
OPT_BASEMTU,
Aug 7, 2010
Aug 7, 2010
152
OPT_CAFILE,
Jan 25, 2015
Jan 25, 2015
153
OPT_COMPRESSION,
May 3, 2012
May 3, 2012
154
OPT_CONFIGFILE,
Aug 7, 2010
Aug 7, 2010
155
156
157
OPT_COOKIEONLY,
OPT_COOKIE_ON_STDIN,
OPT_CSD_USER,
Nov 21, 2010
Nov 21, 2010
158
OPT_CSD_WRAPPER,
Aug 7, 2010
Aug 7, 2010
159
160
OPT_DISABLE_IPV6,
OPT_DTLS_CIPHERS,
Jan 10, 2019
Jan 10, 2019
161
OPT_DTLS12_CIPHERS,
May 30, 2013
May 30, 2013
162
OPT_DUMP_HTTP,
Aug 7, 2010
Aug 7, 2010
163
OPT_FORCE_DPD,
Dec 20, 2014
Dec 20, 2014
164
OPT_GNUTLS_DEBUG,
Jan 26, 2015
Jan 26, 2015
165
OPT_JUNIPER,
Aug 7, 2010
Aug 7, 2010
166
167
168
169
170
OPT_KEY_PASSWORD_FROM_FSID,
OPT_LIBPROXY,
OPT_NO_CERT_CHECK,
OPT_NO_DTLS,
OPT_NO_HTTP_KEEPALIVE,
Nov 3, 2014
Nov 3, 2014
171
OPT_NO_SYSTEM_TRUST,
Aug 7, 2010
Aug 7, 2010
172
173
OPT_NO_PASSWD,
OPT_NO_PROXY,
May 30, 2013
May 30, 2013
174
OPT_NO_XMLPOST,
Sep 9, 2011
Sep 9, 2011
175
OPT_PIDFILE,
Aug 7, 2010
Aug 7, 2010
176
177
178
179
OPT_PASSWORD_ON_STDIN,
OPT_PRINTCOOKIE,
OPT_RECONNECT_TIMEOUT,
OPT_SERVERCERT,
Apr 24, 2015
Apr 24, 2015
180
OPT_RESOLVE,
Aug 7, 2010
Aug 7, 2010
181
OPT_USERAGENT,
Apr 28, 2011
Apr 28, 2011
182
OPT_NON_INTER,
Jun 25, 2012
Jun 25, 2012
183
OPT_DTLS_LOCAL_PORT,
Mar 23, 2013
Mar 23, 2013
184
185
OPT_TOKEN_MODE,
OPT_TOKEN_SECRET,
Oct 28, 2012
Oct 28, 2012
186
OPT_OS,
Jan 15, 2014
Jan 15, 2014
187
OPT_TIMESTAMP,
Feb 3, 2014
Feb 3, 2014
188
OPT_PFS,
Jun 20, 2014
Jun 20, 2014
189
OPT_PROXY_AUTH,
Feb 24, 2015
Feb 24, 2015
190
OPT_HTTP_AUTH,
Mar 8, 2016
Mar 8, 2016
191
OPT_LOCAL_HOSTNAME,
May 16, 2016
May 16, 2016
192
OPT_PROTOCOL,
Aug 25, 2016
Aug 25, 2016
193
OPT_PASSTOS,
Oct 15, 2018
Oct 15, 2018
194
OPT_VERSION,
Aug 7, 2010
Aug 7, 2010
195
196
};
Apr 19, 2012
Apr 19, 2012
197
198
199
200
201
202
203
204
205
206
#ifdef __sun__
/*
* The 'name' field in Solaris 'struct option' lacks the 'const', and causes
* lots of warnings unless we cast it... https://www.illumos.org/issues/1881
*/
#define OPTION(name, arg, abbrev) {(char *)name, arg, NULL, abbrev}
#else
#define OPTION(name, arg, abbrev) {name, arg, NULL, abbrev}
#endif
Jan 7, 2015
Jan 7, 2015
207
static const struct option long_options[] = {
Feb 6, 2014
Feb 6, 2014
208
#ifndef _WIN32
Apr 19, 2012
Apr 19, 2012
209
210
OPTION("background", 0, 'b'),
OPTION("pid-file", 1, OPT_PIDFILE),
Jul 8, 2014
Jul 8, 2014
211
212
213
214
215
OPTION("setuid", 1, 'U'),
OPTION("script-tun", 0, 'S'),
OPTION("syslog", 0, 'l'),
OPTION("csd-user", 1, OPT_CSD_USER),
OPTION("csd-wrapper", 1, OPT_CSD_WRAPPER),
Feb 6, 2014
Feb 6, 2014
216
217
#endif
OPTION("pfs", 0, OPT_PFS),
Apr 19, 2012
Apr 19, 2012
218
219
220
OPTION("certificate", 1, 'c'),
OPTION("sslkey", 1, 'k'),
OPTION("cookie", 1, 'C'),
Jan 25, 2015
Jan 25, 2015
221
OPTION("compression", 1, OPT_COMPRESSION),
Apr 19, 2012
Apr 19, 2012
222
OPTION("deflate", 0, 'd'),
Jan 26, 2015
Jan 26, 2015
223
OPTION("juniper", 0, OPT_JUNIPER),
Apr 19, 2012
Apr 19, 2012
224
225
226
227
OPTION("no-deflate", 0, 'D'),
OPTION("cert-expire-warning", 1, 'e'),
OPTION("usergroup", 1, 'g'),
OPTION("help", 0, 'h'),
Feb 24, 2015
Feb 24, 2015
228
OPTION("http-auth", 1, OPT_HTTP_AUTH),
Apr 19, 2012
Apr 19, 2012
229
230
OPTION("interface", 1, 'i'),
OPTION("mtu", 1, 'm'),
Jun 8, 2012
Jun 8, 2012
231
OPTION("base-mtu", 1, OPT_BASEMTU),
Apr 19, 2012
Apr 19, 2012
232
OPTION("script", 1, 's'),
Jan 15, 2014
Jan 15, 2014
233
OPTION("timestamp", 0, OPT_TIMESTAMP),
Aug 25, 2016
Aug 25, 2016
234
OPTION("passtos", 0, OPT_PASSTOS),
Apr 19, 2012
Apr 19, 2012
235
236
OPTION("key-password", 1, 'p'),
OPTION("proxy", 1, 'P'),
Jun 20, 2014
Jun 20, 2014
237
OPTION("proxy-auth", 1, OPT_PROXY_AUTH),
Apr 19, 2012
Apr 19, 2012
238
239
240
241
OPTION("user", 1, 'u'),
OPTION("verbose", 0, 'v'),
OPTION("version", 0, 'V'),
OPTION("cafile", 1, OPT_CAFILE),
May 3, 2012
May 3, 2012
242
OPTION("config", 1, OPT_CONFIGFILE),
Apr 19, 2012
Apr 19, 2012
243
OPTION("no-dtls", 0, OPT_NO_DTLS),
Jun 11, 2012
Jun 11, 2012
244
OPTION("authenticate", 0, OPT_AUTHENTICATE),
Apr 19, 2012
Apr 19, 2012
245
246
247
248
249
250
251
252
253
254
OPTION("cookieonly", 0, OPT_COOKIEONLY),
OPTION("printcookie", 0, OPT_PRINTCOOKIE),
OPTION("quiet", 0, 'q'),
OPTION("queue-len", 1, 'Q'),
OPTION("xmlconfig", 1, 'x'),
OPTION("cookie-on-stdin", 0, OPT_COOKIE_ON_STDIN),
OPTION("passwd-on-stdin", 0, OPT_PASSWORD_ON_STDIN),
OPTION("no-passwd", 0, OPT_NO_PASSWD),
OPTION("reconnect-timeout", 1, OPT_RECONNECT_TIMEOUT),
OPTION("dtls-ciphers", 1, OPT_DTLS_CIPHERS),
Jan 10, 2019
Jan 10, 2019
255
OPTION("dtls12-ciphers", 1, OPT_DTLS12_CIPHERS),
Apr 19, 2012
Apr 19, 2012
256
257
OPTION("authgroup", 1, OPT_AUTHGROUP),
OPTION("servercert", 1, OPT_SERVERCERT),
Apr 24, 2015
Apr 24, 2015
258
OPTION("resolve", 1, OPT_RESOLVE),
Apr 19, 2012
Apr 19, 2012
259
260
OPTION("key-password-from-fsid", 0, OPT_KEY_PASSWORD_FROM_FSID),
OPTION("useragent", 1, OPT_USERAGENT),
Oct 15, 2018
Oct 15, 2018
261
OPTION("version-string", 1, OPT_VERSION),
Mar 8, 2016
Mar 8, 2016
262
OPTION("local-hostname", 1, OPT_LOCAL_HOSTNAME),
Apr 19, 2012
Apr 19, 2012
263
264
265
266
267
268
269
OPTION("disable-ipv6", 0, OPT_DISABLE_IPV6),
OPTION("no-proxy", 0, OPT_NO_PROXY),
OPTION("libproxy", 0, OPT_LIBPROXY),
OPTION("no-http-keepalive", 0, OPT_NO_HTTP_KEEPALIVE),
OPTION("no-cert-check", 0, OPT_NO_CERT_CHECK),
OPTION("force-dpd", 1, OPT_FORCE_DPD),
OPTION("non-inter", 0, OPT_NON_INTER),
Jun 25, 2012
Jun 25, 2012
270
OPTION("dtls-local-port", 1, OPT_DTLS_LOCAL_PORT),
Mar 23, 2013
Mar 23, 2013
271
OPTION("token-mode", 1, OPT_TOKEN_MODE),
Mar 25, 2013
Mar 25, 2013
272
OPTION("token-secret", 1, OPT_TOKEN_SECRET),
Oct 28, 2012
Oct 28, 2012
273
OPTION("os", 1, OPT_OS),
May 30, 2013
May 30, 2013
274
OPTION("no-xmlpost", 0, OPT_NO_XMLPOST),
May 30, 2013
May 30, 2013
275
OPTION("dump-http-traffic", 0, OPT_DUMP_HTTP),
Nov 3, 2014
Nov 3, 2014
276
OPTION("no-system-trust", 0, OPT_NO_SYSTEM_TRUST),
May 16, 2016
May 16, 2016
277
OPTION("protocol", 1, OPT_PROTOCOL),
Nov 6, 2018
Nov 6, 2018
278
OPTION("form-entry", 1, 'F'),
Dec 20, 2014
Dec 20, 2014
279
280
281
#ifdef OPENCONNECT_GNUTLS
OPTION("gnutls-debug", 1, OPT_GNUTLS_DEBUG),
#endif
Apr 19, 2012
Apr 19, 2012
282
OPTION(NULL, 0, 0)
Sep 21, 2008
Sep 21, 2008
283
284
};
Dec 20, 2014
Dec 20, 2014
285
286
287
288
289
290
291
#ifdef OPENCONNECT_GNUTLS
static void oc_gnutls_log_func(int level, const char *str)
{
fputs(str, stderr);
}
#endif
Jul 29, 2014
Jul 29, 2014
292
#ifdef _WIN32
Dec 7, 2014
Dec 7, 2014
293
294
static int __attribute__ ((format(printf, 2, 0)))
vfprintf_utf8(FILE *f, const char *fmt, va_list args)
Jul 29, 2014
Jul 29, 2014
295
296
297
298
299
300
301
302
303
304
305
306
307
308
{
HANDLE h = GetStdHandle(f == stdout ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE);
wchar_t wbuf[1024];
char buf[1024];
int chars, wchars;
buf[sizeof(buf) - 1] = 0;
chars = _vsnprintf(buf, sizeof(buf) - 1, fmt, args);
wchars = MultiByteToWideChar(CP_UTF8, 0, buf, -1, wbuf, sizeof(wbuf)/2);
WriteConsoleW(h, wbuf, wchars, NULL, NULL);
return chars;
}
Dec 7, 2014
Dec 7, 2014
309
310
static int __attribute__ ((format(printf, 2, 3)))
fprintf_utf8(FILE *f, const char *fmt, ...)
Jul 29, 2014
Jul 29, 2014
311
312
313
314
315
316
317
318
319
320
{
va_list args;
int ret;
va_start(args, fmt);
ret = vfprintf_utf8(f, fmt, args);
va_end(args);
return ret;
}
Jul 29, 2014
Jul 29, 2014
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
static wchar_t **argv_w;
/* This isn't so much "convert" the arg to UTF-8, as go grubbing
* around in the real UTF-16 command line and find the corresponding
* argument *there*, and convert *that* to UTF-8. Ick. But the
* alternative is to implement wgetopt(), and that's even more horrid. */
static char *convert_arg_to_utf8(char **argv, char *arg)
{
char *utf8;
int chars;
int offset;
if (!argv_w) {
int argc_w;
argv_w = CommandLineToArgvW(GetCommandLineW(), &argc_w);
if (!argv_w) {
Oct 28, 2014
Oct 28, 2014
339
340
341
342
char *errstr = openconnect__win32_strerror(GetLastError());
fprintf(stderr, _("CommandLineToArgvW() failed: %s\n"),
errstr);
free(errstr);
Jul 29, 2014
Jul 29, 2014
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
exit(1);
}
}
offset = arg - argv[optind - 1];
/* Sanity check */
if (offset < 0 || offset >= strlen(argv[optind - 1]) ||
(offset && (argv[optind - 1][offset-1] != '=' ||
argv_w[optind - 1][offset - 1] != '='))) {
fprintf(stderr, _("Fatal error in command line handling\n"));
exit(1);
}
chars = WideCharToMultiByte(CP_UTF8, 0, argv_w[optind-1] + offset, -1,
NULL, 0, NULL, NULL);
utf8 = malloc(chars);
if (!utf8)
return arg;
WideCharToMultiByte(CP_UTF8, 0, argv_w[optind-1] + offset, -1, utf8,
chars, NULL, NULL);
return utf8;
}
Jul 29, 2014
Jul 29, 2014
368
369
370
371
#undef fprintf
#undef vfprintf
#define fprintf fprintf_utf8
#define vfprintf vfprintf_utf8
Aug 7, 2014
Aug 7, 2014
372
#define is_arg_utf8(str) (0)
Jul 29, 2014
Jul 29, 2014
373
Oct 6, 2015
Oct 6, 2015
374
static void read_stdin(char **string, int hidden, int allow_fail)
Jul 29, 2014
Jul 29, 2014
375
376
{
CONSOLE_READCONSOLE_CONTROL rcc = { sizeof(rcc), 0, 13, 0 };
Aug 14, 2017
Aug 14, 2017
377
HANDLE stdinh = GetStdHandle(STD_INPUT_HANDLE);
Jul 29, 2014
Jul 29, 2014
378
379
380
381
DWORD cmode, nr_read;
wchar_t wbuf[1024];
char *buf;
Aug 14, 2017
Aug 14, 2017
382
383
384
385
386
if (GetConsoleMode(stdinh, &cmode)) {
if (hidden)
SetConsoleMode(stdinh, cmode & (~ENABLE_ECHO_INPUT));
if (!ReadConsoleW(stdinh, wbuf, sizeof(wbuf)/2, &nr_read, &rcc)) {
Sep 23, 2016
Sep 23, 2016
387
char *errstr = openconnect__win32_strerror(GetLastError());
Aug 14, 2017
Aug 14, 2017
388
fprintf(stderr, _("ReadConsole() failed: %s\n"), errstr);
Sep 23, 2016
Sep 23, 2016
389
390
free(errstr);
*string = NULL;
Aug 14, 2017
Aug 14, 2017
391
392
393
if (hidden)
SetConsoleMode(stdinh, cmode);
return;
Sep 23, 2016
Sep 23, 2016
394
}
Aug 14, 2017
Aug 14, 2017
395
396
397
398
399
400
401
402
403
404
405
406
if (hidden)
SetConsoleMode(stdinh, cmode);
} else {
/* Not a console; maybe reading from a piped stdin? */
if (!fgetws(wbuf, sizeof(wbuf)/2, stdin)) {
char *errstr = openconnect__win32_strerror(GetLastError());
fprintf(stderr, _("fgetws() failed: %s\n"), errstr);
free(errstr);
*string = NULL;
return;
}
nr_read = wcslen(wbuf);
Sep 23, 2016
Sep 23, 2016
407
}
Jul 29, 2014
Jul 29, 2014
408
409
410
411
412
413
414
if (nr_read >= 2 && wbuf[nr_read - 1] == 10 && wbuf[nr_read - 2] == 13) {
wbuf[nr_read - 2] = 0;
nr_read -= 2;
}
nr_read = WideCharToMultiByte(CP_UTF8, 0, wbuf, -1, NULL, 0, NULL, NULL);
if (!nr_read) {
Oct 28, 2014
Oct 28, 2014
415
char *errstr = openconnect__win32_strerror(GetLastError());
Dec 7, 2014
Dec 7, 2014
416
fprintf(stderr, _("Error converting console input: %s\n"),
Oct 28, 2014
Oct 28, 2014
417
418
errstr);
free(errstr);
Aug 14, 2017
Aug 14, 2017
419
return;
Jul 29, 2014
Jul 29, 2014
420
421
422
423
424
425
426
427
}
buf = malloc(nr_read);
if (!buf) {
fprintf(stderr, _("Allocation failure for string from stdin\n"));
exit(1);
}
if (!WideCharToMultiByte(CP_UTF8, 0, wbuf, -1, buf, nr_read, NULL, NULL)) {
Oct 28, 2014
Oct 28, 2014
428
429
430
431
char *errstr = openconnect__win32_strerror(GetLastError());
fprintf(stderr, _("Error converting console input: %s\n"),
errstr);
free(errstr);
Jul 29, 2014
Jul 29, 2014
432
free(buf);
Aug 14, 2017
Aug 14, 2017
433
return;
Jul 29, 2014
Jul 29, 2014
434
435
436
437
438
}
*string = buf;
}
Jul 29, 2014
Jul 29, 2014
439
#elif defined(HAVE_ICONV)
Jul 28, 2014
Jul 28, 2014
440
441
#include <iconv.h>
Jul 29, 2014
Jul 29, 2014
442
443
444
445
446
447
448
449
450
451
452
static int is_ascii(char *str)
{
while (str && *str) {
if ((unsigned char)*str > 0x7f)
return 0;
str++;
}
return 1;
}
Dec 7, 2014
Dec 7, 2014
453
454
static int __attribute__ ((format(printf, 2, 0)))
vfprintf_utf8(FILE *f, const char *fmt, va_list args)
Jul 28, 2014
Jul 28, 2014
455
456
457
458
459
{
char *utf8_str;
iconv_t ic;
int ret;
char outbuf[80];
Oct 30, 2014
Oct 30, 2014
460
461
ICONV_CONST char *ic_in;
char *ic_out;
Jul 28, 2014
Jul 28, 2014
462
463
464
465
466
467
468
469
470
size_t insize, outsize;
if (!legacy_charset)
return vfprintf(f, fmt, args);
ret = vasprintf(&utf8_str, fmt, args);
if (ret < 0)
return -1;
Jul 29, 2014
Jul 29, 2014
471
472
473
if (is_ascii(utf8_str))
return fwrite(utf8_str, 1, strlen(utf8_str), f);
Jul 28, 2014
Jul 28, 2014
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
ic = iconv_open(legacy_charset, "UTF-8");
if (ic == (iconv_t) -1) {
/* Better than nothing... */
ret = fprintf(f, "%s", utf8_str);
free(utf8_str);
return ret;
}
ic_in = utf8_str;
insize = strlen(utf8_str);
ret = 0;
while (insize) {
ic_out = outbuf;
outsize = sizeof(outbuf) - 1;
Oct 30, 2014
Oct 30, 2014
490
if (iconv(ic, &ic_in, &insize, &ic_out, &outsize) == (size_t)-1) {
Jul 28, 2014
Jul 28, 2014
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
if (errno == EILSEQ) {
do {
ic_in++;
insize--;
} while (insize && (ic_in[0] & 0xc0) == 0x80);
ic_out[0] = '?';
outsize--;
} else if (errno != E2BIG)
break;
}
ret += fwrite(outbuf, 1, sizeof(outbuf) - 1 - outsize, f);
}
iconv_close(ic);
return ret;
}
Dec 7, 2014
Dec 7, 2014
509
510
static int __attribute__ ((format(printf, 2, 3)))
fprintf_utf8(FILE *f, const char *fmt, ...)
Jul 28, 2014
Jul 28, 2014
511
512
513
514
515
516
517
518
519
520
521
{
va_list args;
int ret;
va_start(args, fmt);
ret = vfprintf_utf8(f, fmt, args);
va_end(args);
return ret;
}
Jul 29, 2014
Jul 29, 2014
522
static char *convert_to_utf8(char *legacy, int free_it)
Jul 28, 2014
Jul 28, 2014
523
524
525
{
char *utf8_str;
iconv_t ic;
Oct 30, 2014
Oct 30, 2014
526
527
ICONV_CONST char *ic_in;
char *ic_out;
Jul 28, 2014
Jul 28, 2014
528
529
size_t insize, outsize;
Jul 29, 2014
Jul 29, 2014
530
if (!legacy_charset || is_ascii(legacy))
Jul 28, 2014
Jul 28, 2014
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
return legacy;
ic = iconv_open("UTF-8", legacy_charset);
if (ic == (iconv_t) -1)
return legacy;
insize = strlen(legacy) + 1;
ic_in = legacy;
outsize = insize;
ic_out = utf8_str = malloc(outsize);
if (!utf8_str) {
enomem:
iconv_close(ic);
return legacy;
}
while (insize) {
Oct 30, 2014
Oct 30, 2014
549
if (iconv(ic, &ic_in, &insize, &ic_out, &outsize) == (size_t)-1) {
Jul 28, 2014
Jul 28, 2014
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
if (errno == E2BIG) {
int outlen = ic_out - utf8_str;
realloc_inplace(utf8_str, outlen + 10);
if (!utf8_str)
goto enomem;
ic_out = utf8_str + outlen;
outsize = 10;
} else {
/* Should never happen */
perror("iconv");
free(utf8_str);
goto enomem;
}
}
}
iconv_close(ic);
Jul 29, 2014
Jul 29, 2014
567
568
if (free_it)
free(legacy);
Jul 28, 2014
Jul 28, 2014
569
570
571
return utf8_str;
}
Jul 28, 2014
Jul 28, 2014
572
573
#define fprintf fprintf_utf8
#define vfprintf vfprintf_utf8
Jul 29, 2014
Jul 29, 2014
574
575
#define convert_arg_to_utf8(av, l) convert_to_utf8((l), 0)
#define is_arg_utf8(a) (!legacy_charset || is_ascii(a))
Jul 28, 2014
Jul 28, 2014
576
#else
Jul 29, 2014
Jul 29, 2014
577
578
579
#define convert_to_utf8(l,f) (l)
#define convert_arg_to_utf8(av, l) (l)
#define is_arg_utf8(a) (1)
Jul 28, 2014
Jul 28, 2014
580
581
#endif
Dec 1, 2011
Dec 1, 2011
582
583
584
585
586
587
static void helpmessage(void)
{
printf(_("For assistance with OpenConnect, please see the web page at\n"
" http://www.infradead.org/openconnect/mail.html\n"));
}
Jun 11, 2012
Jun 11, 2012
588
589
static void print_build_opts(void)
{
Jun 13, 2012
Jun 13, 2012
590
591
const char *comma = ", ", *sep = comma + 1;
Mar 10, 2013
Mar 10, 2013
592
#if defined(OPENCONNECT_OPENSSL)
Jun 13, 2012
Jun 13, 2012
593
printf(_("Using OpenSSL. Features present:"));
Mar 10, 2013
Mar 10, 2013
594
#elif defined(OPENCONNECT_GNUTLS)
Jun 13, 2012
Jun 13, 2012
595
596
597
598
599
600
601
printf(_("Using GnuTLS. Features present:"));
#endif
if (openconnect_has_tss_blob_support()) {
printf("%sTPM", sep);
sep = comma;
}
Oct 11, 2018
Oct 11, 2018
602
603
604
605
if (openconnect_has_tss2_blob_support()) {
printf("%sTPMv2", sep);
sep = comma;
}
Mar 10, 2013
Mar 10, 2013
606
#if defined(OPENCONNECT_OPENSSL) && defined(HAVE_ENGINE)
Jun 13, 2012
Jun 13, 2012
607
608
609
610
611
612
613
614
615
else {
printf("%sTPM (%s)", sep, _("OpenSSL ENGINE not present"));
sep = comma;
}
#endif
if (openconnect_has_pkcs11_support()) {
printf("%sPKCS#11", sep);
sep = comma;
}
Oct 15, 2012
Oct 15, 2012
616
if (openconnect_has_stoken_support()) {
Mar 23, 2013
Mar 23, 2013
617
618
619
printf("%sRSA software token", sep);
sep = comma;
}
Feb 18, 2014
Feb 18, 2014
620
621
622
623
switch(openconnect_has_oath_support()) {
case 2:
printf("%sHOTP software token", sep);
sep = comma;
Feb 26, 2018
Feb 26, 2018
624
/* fall through */
Feb 18, 2014
Feb 18, 2014
625
case 1:
Mar 23, 2013
Mar 23, 2013
626
printf("%sTOTP software token", sep);
Oct 15, 2012
Oct 15, 2012
627
628
sep = comma;
}
Nov 17, 2014
Nov 17, 2014
629
630
631
632
if (openconnect_has_yubioath_support()) {
printf("%sYubikey OATH", sep);
sep = comma;
}
Nov 27, 2014
Nov 27, 2014
633
634
635
636
if (openconnect_has_system_key_support()) {
printf("%sSystem keys", sep);
sep = comma;
}
Jun 13, 2012
Jun 13, 2012
637
638
#ifdef HAVE_DTLS
May 14, 2017
May 14, 2017
639
640
641
642
643
644
645
646
647
printf("%sDTLS", sep);
#endif
#ifdef HAVE_ESP
printf("%sESP", sep);
#endif
printf("\n");
#if !defined(HAVE_DTLS) || !defined(HAVE_ESP)
printf(_("WARNING: This binary lacks DTLS and/or ESP support. Performance will be impaired.\n"));
Jun 11, 2012
Jun 11, 2012
648
649
650
#endif
}
May 14, 2017
May 14, 2017
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
static void print_supported_protocols(void)
{
const char *comma = ", ", *sep = comma + 1;
struct oc_vpn_proto *protos, *p;
if (openconnect_get_supported_protocols(&protos)>=0) {
printf(_("Supported protocols:"));
for (p=protos; p->name; p++) {
printf("%s%s%s", sep, p->name, p==protos ? _(" (default)") : "");
sep = comma;
}
printf("\n");
free(protos);
}
}
static void print_supported_protocols_usage(void)
{
struct oc_vpn_proto *protos, *p;
if (openconnect_get_supported_protocols(&protos)>=0) {
May 31, 2018
May 31, 2018
672
printf("\n%s:\n", _("Set VPN protocol"));
May 14, 2017
May 14, 2017
673
674
675
676
677
678
679
for (p=protos; p->name; p++)
printf(" --protocol=%-16s %s%s\n",
p->name, p->description, p==protos ? _(" (default)") : "");
openconnect_free_supported_protocols(protos);
}
}
Feb 13, 2014
Feb 13, 2014
680
681
#ifndef _WIN32
static const char default_vpncscript[] = DEFAULT_VPNCSCRIPT;
Oct 6, 2015
Oct 6, 2015
682
static void read_stdin(char **string, int hidden, int allow_fail)
Jul 8, 2014
Jul 8, 2014
683
{
Jul 28, 2014
Jul 28, 2014
684
char *c, *buf = malloc(1025);
Jul 8, 2014
Jul 8, 2014
685
int fd = fileno(stdin);
Jul 28, 2014
Jul 28, 2014
686
struct termios t;
Jul 8, 2014
Jul 8, 2014
687
Jul 28, 2014
Jul 28, 2014
688
689
690
691
if (!buf) {
fprintf(stderr, _("Allocation failure for string from stdin\n"));
exit(1);
}
Jul 8, 2014
Jul 8, 2014
692
Jul 28, 2014
Jul 28, 2014
693
694
695
696
697
698
if (hidden) {
tcgetattr(fd, &t);
t.c_lflag &= ~ECHO;
tcsetattr(fd, TCSANOW, &t);
}
Aug 2, 2014
Aug 2, 2014
699
buf = fgets(buf, 1025, stdin);
Jul 28, 2014
Jul 28, 2014
700
701
702
703
704
705
706
if (hidden) {
t.c_lflag |= ECHO;
tcsetattr(fd, TCSANOW, &t);
fprintf(stderr, "\n");
}
Aug 2, 2014
Aug 2, 2014
707
if (!buf) {
Oct 6, 2015
Oct 6, 2015
708
709
710
711
712
713
714
715
if (allow_fail) {
*string = NULL;
free(buf);
return;
} else {
perror(_("fgets (stdin)"));
exit(1);
}
Aug 2, 2014
Aug 2, 2014
716
717
}
Jul 28, 2014
Jul 28, 2014
718
719
720
c = strchr(buf, '\n');
if (c)
*c = 0;
Jul 8, 2014
Jul 8, 2014
721
Jul 29, 2014
Jul 29, 2014
722
*string = convert_to_utf8(buf, 1);
Jul 8, 2014
Jul 8, 2014
723
724
725
726
727
728
729
}
static void handle_signal(int sig)
{
char cmd;
switch (sig) {
Nov 24, 2018
Nov 24, 2018
730
case SIGTERM:
Jul 8, 2014
Jul 8, 2014
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
case SIGINT:
cmd = OC_CMD_CANCEL;
break;
case SIGHUP:
cmd = OC_CMD_DETACH;
break;
case SIGUSR2:
default:
cmd = OC_CMD_PAUSE;
break;
}
if (write(sig_cmd_fd, &cmd, 1) < 0) {
/* suppress warn_unused_result */
}
}
#else /* _WIN32 */
Feb 13, 2014
Feb 13, 2014
748
749
750
751
752
753
754
755
756
757
static const char *default_vpncscript;
static void set_default_vpncscript(void)
{
if (PathIsRelative(DEFAULT_VPNCSCRIPT)) {
char *c = strrchr(_pgmptr, '\\');
if (!c) {
fprintf(stderr, _("Cannot process this executable path \"%s\""),
_pgmptr);
exit(1);
}
Sep 29, 2014
Sep 29, 2014
758
if (asprintf((char **)&default_vpncscript, "%.*s%s",
Feb 13, 2014
Feb 13, 2014
759
760
761
762
763
764
765
766
767
768
(c - _pgmptr + 1), _pgmptr, DEFAULT_VPNCSCRIPT) < 0) {
fprintf(stderr, _("Allocation for vpnc-script path failed\n"));
exit(1);
}
} else {
default_vpncscript = "cscript " DEFAULT_VPNCSCRIPT;
}
}
#endif
Apr 24, 2015
Apr 24, 2015
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
static struct oc_vpn_option *gai_overrides;
static int gai_override_cb(void *cbdata, const char *node,
const char *service, const struct addrinfo *hints,
struct addrinfo **res)
{
struct openconnect_info *vpninfo = cbdata;
struct oc_vpn_option *p = gai_overrides;
while (p) {
if (!strcmp(node, p->option)) {
vpn_progress(vpninfo, PRG_TRACE, _("Override hostname '%s' to '%s'\n"),
node, p->value);
node = p->value;
break;
}
p = p->next;
}
return getaddrinfo(node, service, hints, res);
}
Sep 15, 2011
Sep 15, 2011
791
static void usage(void)
Sep 29, 2008
Sep 29, 2008
792
{
Oct 7, 2011
Oct 7, 2011
793
printf(_("Usage: openconnect [options] <server>\n"));
May 14, 2017
May 14, 2017
794
printf(_("Open client for multiple VPN protocols, version %s\n\n"), openconnect_version_str);
Jun 11, 2012
Jun 11, 2012
795
print_build_opts();
May 3, 2012
May 3, 2012
796
printf(" --config=CONFIGFILE %s\n", _("Read options from config file"));
May 31, 2018
May 31, 2018
797
798
printf(" -V, --version %s\n", _("Report version number"));
printf(" -h, --help %s\n", _("Display help text"));
May 31, 2018
May 31, 2018
799
May 31, 2018
May 31, 2018
800
print_supported_protocols_usage();
May 31, 2018
May 31, 2018
801
802
printf("\n%s:\n", _("Authentication"));
May 31, 2018
May 31, 2018
803
804
805
806
807
printf(" -u, --user=NAME %s\n", _("Set login username"));
printf(" --no-passwd %s\n", _("Disable password/SecurID authentication"));
printf(" --non-inter %s\n", _("Do not expect user input; exit if it is required"));
printf(" --passwd-on-stdin %s\n", _("Read password from standard input"));
printf(" --authgroup=GROUP %s\n", _("Choose authentication login selection"));
Nov 6, 2018
Nov 6, 2018
808
printf(" -F, --form-field=FORM:OPT=VALUE %s\n", _("Provide authentication form responses"));
Oct 7, 2011
Oct 7, 2011
809
810
printf(" -c, --certificate=CERT %s\n", _("Use SSL client certificate CERT"));
printf(" -k, --sslkey=KEY %s\n", _("Use SSL private key file KEY"));
May 31, 2018
May 31, 2018
811
printf(" -e, --cert-expire-warning=DAYS %s\n", _("Warn when certificate lifetime < DAYS"));
Oct 7, 2011
Oct 7, 2011
812
813
814
printf(" -g, --usergroup=GROUP %s\n", _("Set login usergroup"));
printf(" -p, --key-password=PASS %s\n", _("Set key passphrase or TPM SRK PIN"));
printf(" --key-password-from-fsid %s\n", _("Key passphrase is fsid of file system"));
May 31, 2018
May 31, 2018
815
816
817
818
819
820
821
822
printf(" --token-mode=MODE %s\n", _("Software token type: rsa, totp or hotp"));
printf(" --token-secret=STRING %s\n", _("Software token secret"));
#ifndef HAVE_LIBSTOKEN
printf(" %s\n", _("(NOTE: libstoken (RSA SecurID) disabled in this build)"));
#endif
#ifndef HAVE_LIBPCSCLITE
printf(" %s\n", _("(NOTE: Yubikey OATH disabled in this build)"));
#endif
May 31, 2018
May 31, 2018
823
824
printf("\n%s:\n", _("Server validation"));
May 31, 2018
May 31, 2018
825
826
827
828
printf(" --servercert=FINGERPRINT %s\n", _("Server's certificate SHA1 fingerprint"));
printf(" --no-cert-check %s\n", _("Do not require server SSL cert to be valid"));
printf(" --no-system-trust %s\n", _("Disable default system certificate authorities"));
printf(" --cafile=FILE %s\n", _("Cert file for server verification"));
May 31, 2018
May 31, 2018
829
830
printf("\n%s:\n", _("Internet connectivity"));
Oct 7, 2011
Oct 7, 2011
831
printf(" -P, --proxy=URL %s\n", _("Set proxy server"));
Jun 20, 2014
Jun 20, 2014
832
printf(" --proxy-auth=METHODS %s\n", _("Set proxy authentication methods"));
Oct 7, 2011
Oct 7, 2011
833
834
printf(" --no-proxy %s\n", _("Disable proxy"));
printf(" --libproxy %s\n", _("Use libproxy to automatically configure proxy"));
Sep 22, 2011
Sep 22, 2011
835
#ifndef LIBPROXY_HDR
Oct 7, 2011
Oct 7, 2011
836
printf(" %s\n", _("(NOTE: libproxy disabled in this build)"));
Jan 2, 2010
Jan 2, 2010
837
#endif
May 31, 2018
May 31, 2018
838
839
840
printf(" --reconnect-timeout %s\n", _("Connection retry timeout in seconds"));
printf(" --resolve=HOST:IP %s\n", _("Use IP when connecting to HOST"));
printf(" --passtos %s\n", _("copy TOS / TCLASS when using DTLS"));
May 31, 2018
May 31, 2018
841
printf(" --dtls-local-port=PORT %s\n", _("Set local port for DTLS and ESP datagrams"));
May 31, 2018
May 31, 2018
842
843
printf("\n%s:\n", _("Authentication (two-phase)"));
May 31, 2018
May 31, 2018
844
printf(" -C, --cookie=COOKIE %s\n", _("Use authentication cookie COOKIE"));
May 31, 2018
May 31, 2018
845
846
printf(" --cookie-on-stdin %s\n", _("Read cookie from standard input"));
printf(" --authenticate %s\n", _("Authenticate only and print login info"));
May 31, 2018
May 31, 2018
847
848
849
printf(" --cookieonly %s\n", _("Fetch and print cookie only; don't connect"));
printf(" --printcookie %s\n", _("Print cookie before connecting"));
May 31, 2018
May 31, 2018
850
#ifndef _WIN32
May 31, 2018
May 31, 2018
851
printf("\n%s:\n", _("Process control"));
May 31, 2018
May 31, 2018
852
853
854
855
printf(" -b, --background %s\n", _("Continue in background after startup"));
printf(" --pid-file=PIDFILE %s\n", _("Write the daemon's PID to this file"));
printf(" -U, --setuid=USER %s\n", _("Drop privileges after connecting"));
#endif
May 31, 2018
May 31, 2018
856
857
printf("\n%s:\n", _("Logging (two-phase)"));
May 31, 2018
May 31, 2018
858
859
860
861
#ifndef _WIN32
printf(" -l, --syslog %s\n", _("Use syslog for progress messages"));
#endif
printf(" -v, --verbose %s\n", _("More output"));
Oct 7, 2011
Oct 7, 2011
862
printf(" -q, --quiet %s\n", _("Less output"));
May 31, 2018
May 31, 2018
863
864
printf(" --dump-http-traffic %s\n", _("Dump HTTP authentication traffic (implies --verbose"));
printf(" --timestamp %s\n", _("Prepend timestamp to progress messages"));
May 31, 2018
May 31, 2018
865
866
printf("\n%s:\n", _("VPN configuration script"));
May 31, 2018
May 31, 2018
867
printf(" -i, --interface=IFNAME %s\n", _("Use IFNAME for tunnel interface"));
Oct 7, 2011
Oct 7, 2011
868
printf(" -s, --script=SCRIPT %s\n", _("Shell command line for using a vpnc-compatible config script"));
Feb 13, 2014
Feb 13, 2014
869
printf(" %s: \"%s\"\n", _("default"), default_vpncscript);
Feb 6, 2014
Feb 6, 2014
870
#ifndef _WIN32
Oct 7, 2011
Oct 7, 2011
871
printf(" -S, --script-tun %s\n", _("Pass traffic to 'script' program, not tun"));
Feb 6, 2014
Feb 6, 2014
872
#endif
May 31, 2018
May 31, 2018
873
874
printf("\n%s:\n", _("Tunnel control"));
Oct 7, 2011
Oct 7, 2011
875
printf(" --disable-ipv6 %s\n", _("Do not ask for IPv6 connectivity"));
May 31, 2018
May 31, 2018
876
877
878
printf(" -x, --xmlconfig=CONFIG %s\n", _("XML config file"));
printf(" -m, --mtu=MTU %s\n", _("Request MTU from server (legacy servers only)"));
printf(" --base-mtu=MTU %s\n", _("Indicate path MTU to/from server"));
Aug 2, 2018
Aug 2, 2018
879
880
printf(" -d, --deflate %s\n", _("Enable stateful compression (default is stateless only)"));
printf(" -D, --no-deflate %s\n", _("Disable all compression"));
May 31, 2018
May 31, 2018
881
882
printf(" --force-dpd=INTERVAL %s\n", _("Set minimum Dead Peer Detection interval"));
printf(" --pfs %s\n", _("Require perfect forward secrecy"));
May 31, 2018
May 31, 2018
883
printf(" --no-dtls %s\n", _("Disable DTLS and ESP"));
May 31, 2018
May 31, 2018
884
885
printf(" --dtls-ciphers=LIST %s\n", _("OpenSSL ciphers to support for DTLS"));
printf(" -Q, --queue-len=LEN %s\n", _("Set packet queue limit to LEN pkts"));
May 31, 2018
May 31, 2018
886
887
printf("\n%s:\n", _("Local system information"));
Oct 7, 2011
Oct 7, 2011
888
printf(" --useragent=STRING %s\n", _("HTTP header User-Agent: field"));
Mar 8, 2016
Mar 8, 2016
889
printf(" --local-hostname=STRING %s\n", _("Local hostname to advertise to server"));
Jan 15, 2014
Jan 15, 2014
890
printf(" --os=STRING %s\n", _("OS type (linux,linux-64,win,...) to report"));
Oct 15, 2018
Oct 15, 2018
891
892
printf(" --version-string=STRING %s\n", _("reported version string during authentication"));
printf(" (%s %s)\n", _("default:"), openconnect_version_str);
May 31, 2018
May 31, 2018
893
May 31, 2018
May 31, 2018
894
#ifndef _WIN32
May 31, 2018
May 31, 2018
895
printf("\n%s:\n", _("Trojan binary (CSD) execution"));
May 31, 2018
May 31, 2018
896
897
printf(" --csd-user=USER %s\n", _("Drop privileges during trojan execution"));
printf(" --csd-wrapper=SCRIPT %s\n", _("Run SCRIPT instead of trojan binary"));
May 31, 2018
May 31, 2018
898
#endif
May 31, 2018
May 31, 2018
899
900
printf("\n%s:\n", _("Server bugs"));
May 31, 2018
May 31, 2018
901
902
printf(" --no-http-keepalive %s\n", _("Disable HTTP connection re-use"));
printf(" --no-xmlpost %s\n", _("Do not attempt XML POST authentication"));
May 14, 2017
May 14, 2017
903
Dec 1, 2011
Dec 1, 2011
904
905
906
printf("\n");
helpmessage();
Sep 29, 2008
Sep 29, 2008
907
908
909
exit(1);
}
Jul 8, 2014
Jul 8, 2014
910
May 3, 2012
May 3, 2012
911
912
913
static FILE *config_file = NULL;
static int config_line_num = 0;
Jul 29, 2014
Jul 29, 2014
914
915
static char *xstrdup(const char *arg)
{
Jul 29, 2014
Jul 29, 2014
916
917
918
919
920
921
char *ret;
if (!arg)
return NULL;
ret = strdup(arg);
Jul 29, 2014
Jul 29, 2014
922
923
924
925
926
927
928
929
if (!ret) {
fprintf(stderr, _("Failed to allocate string\n"));
exit(1);
}
return ret;
}
Jun 5, 2012
Jun 5, 2012
930
931
932
933
/* There are three ways to handle config_arg:
*
* 1. We only care about it transiently and it can be lost entirely
* (e.g. vpninfo->reconnect_timeout = atoi(config_arg);
Oct 11, 2012
Oct 11, 2012
934
* 2. We need to keep it, but it's a static string and will never be freed
Jul 29, 2014
Jul 29, 2014
935
936
937
* so when it's part of argv[] we can use it in place (unless it needs
* converting to UTF-8), but when it comes from a file we have to strdup()
* because otherwise it'll be overwritten.
Jun 5, 2012
Jun 5, 2012
938
939
* For this we use the keep_config_arg() macro below.
* 3. It may be freed during normal operation, so we have to use strdup()
Jul 29, 2014
Jul 29, 2014
940
941
942
* or convert_arg_to_utf8() even when it's an option from argv[].
* (e.g. vpninfo->cert_password).
* For this we use the dup_config_arg() macro below.
Jun 5, 2012
Jun 5, 2012
943
*/
May 3, 2012
May 3, 2012
944
Jul 29, 2014
Jul 29, 2014
945
946
947
#define keep_config_arg() \
(config_file ? xstrdup(config_arg) : convert_arg_to_utf8(argv, config_arg))
Aug 14, 2017
Aug 14, 2017
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
#define dup_config_arg() __dup_config_arg(argv, config_arg)
static inline char *__dup_config_arg(char **argv, char *config_arg)
{
char *res;
if (config_file || is_arg_utf8(config_arg))
return xstrdup(config_arg);
res = convert_arg_to_utf8(argv, config_arg);
/* Force a copy, even if conversion failed */
if (res == config_arg)
res = xstrdup(res);
return res;
}
Jan 15, 2014
Jan 15, 2014
963
May 3, 2012
May 3, 2012
964
965
static int next_option(int argc, char **argv, char **config_arg)
{
May 3, 2012
May 3, 2012
966
967
968
969
970
/* These get re-used */
static char *line_buf = NULL;
static size_t line_size = 0;
ssize_t llen;
Nov 6, 2012
Nov 6, 2012
971
int opt, optlen = 0;
Jan 7, 2015
Jan 7, 2015
972
const struct option *this;
May 3, 2012
May 3, 2012
973
974
975
976
977
978
char *line;
int ate_equals = 0;
next:
if (!config_file) {
opt = getopt_long(argc, argv,
Feb 6, 2014
Feb 6, 2014
979
#ifdef _WIN32
Nov 6, 2018
Nov 6, 2018
980
"C:c:Dde:F:g:hi:k:m:P:p:Q:qs:u:Vvx:",
Feb 6, 2014
Feb 6, 2014
981
#else
Nov 6, 2018
Nov 6, 2018
982
"bC:c:Dde:F:g:hi:k:lm:P:p:Q:qSs:U:u:Vvx:",
Feb 6, 2014
Feb 6, 2014
983
#endif
May 3, 2012
May 3, 2012
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
long_options, NULL);
*config_arg = optarg;
return opt;
}
llen = getline(&line_buf, &line_size, config_file);
if (llen < 0) {
if (feof(config_file)) {
fclose(config_file);
config_file = NULL;
goto next;
}
fprintf(stderr, _("Failed to get line from config file: %s\n"),
strerror(errno));
exit(1);
}