Skip to content

Latest commit

 

History

History
1161 lines (1043 loc) · 31.4 KB

main.c

File metadata and controls

1161 lines (1043 loc) · 31.4 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
*
May 13, 2012
May 13, 2012
4
* Copyright © 2008-2012 Intel Corporation.
Apr 9, 2009
Apr 9, 2009
5
* Copyright © 2008 Nick Andrew <nick@nick-andrew.net>
Sep 22, 2008
Sep 22, 2008
6
*
Nov 20, 2008
Nov 20, 2008
7
8
9
* Author: David Woodhouse <dwmw2@infradead.org>
*
* This program is free software; you can redistribute it and/or
Oct 4, 2008
Oct 4, 2008
10
* modify it under the terms of the GNU Lesser General Public License
Nov 20, 2008
Nov 20, 2008
11
* version 2.1, as published by the Free Software Foundation.
Sep 22, 2008
Sep 22, 2008
12
*
Nov 20, 2008
Nov 20, 2008
13
* This program is distributed in the hope that it will be useful, but
Oct 4, 2008
Oct 4, 2008
14
15
16
17
18
19
20
21
22
23
* 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.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to:
*
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
Sep 22, 2008
Sep 22, 2008
24
25
*/
May 13, 2012
May 13, 2012
26
27
28
29
30
#ifdef HAVE_GETLINE
/* Various BSD systems require this for getline() to be visible */
#define _WITH_GETLINE
#endif
Sep 20, 2008
Sep 20, 2008
31
#include <stdio.h>
Jul 15, 2011
Jul 15, 2011
32
33
34
#ifdef ANDROID
#include <android/log.h>
#else
Nov 3, 2009
Nov 3, 2009
35
#include <syslog.h>
Jul 15, 2011
Jul 15, 2011
36
#endif
Sep 21, 2008
Sep 21, 2008
37
#include <stdarg.h>
Sep 20, 2008
Sep 20, 2008
38
#include <stdlib.h>
Oct 19, 2009
Oct 19, 2009
39
#include <signal.h>
Sep 20, 2008
Sep 20, 2008
40
#include <string.h>
Nov 3, 2011
Nov 3, 2011
41
42
43
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
Sep 20, 2008
Sep 20, 2008
44
45
46
47
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <pwd.h>
Sep 21, 2008
Sep 21, 2008
48
49
#include <sys/utsname.h>
#include <sys/types.h>
Jun 1, 2012
Jun 1, 2012
50
#include <termios.h>
Sep 22, 2011
Sep 22, 2011
51
#ifdef LIBPROXY_HDR
May 8, 2010
May 8, 2010
52
#include LIBPROXY_HDR
Jan 2, 2010
Jan 2, 2010
53
#endif
Sep 21, 2008
Sep 21, 2008
54
#include <getopt.h>
Sep 20, 2008
Sep 20, 2008
55
Mar 9, 2011
Mar 9, 2011
56
#include "openconnect-internal.h"
Sep 20, 2008
Sep 20, 2008
57
Jun 27, 2011
Jun 27, 2011
58
59
60
61
62
63
64
static int write_new_config(void *_vpninfo,
char *buf, int buflen);
static void write_progress(void *_vpninfo,
int level, const char *fmt, ...);
static void syslog_progress(void *_vpninfo,
int level, const char *fmt, ...);
static int validate_peer_cert(void *_vpninfo,
May 29, 2012
May 29, 2012
65
66
OPENCONNECT_X509 *peer_cert,
const char *reason);
May 29, 2012
May 29, 2012
67
68
static int process_auth_form(void *_vpninfo,
struct oc_auth_form *form);
Oct 5, 2008
Oct 5, 2008
69
Nov 7, 2011
Nov 7, 2011
70
71
/* A sanity check that the openconnect executable is running against a
library of the same version */
May 12, 2012
May 12, 2012
72
#define openconnect_version_str openconnect_binary_version
Nov 7, 2011
Nov 7, 2011
73
#include "version.c"
May 12, 2012
May 12, 2012
74
#undef openconnect_version_str
Nov 7, 2011
Nov 7, 2011
75
Oct 5, 2008
Oct 5, 2008
76
int verbose = PRG_INFO;
Apr 28, 2009
Apr 28, 2009
77
int background;
Nov 30, 2010
Nov 30, 2010
78
int do_passphrase_from_fsid;
May 11, 2010
May 11, 2010
79
int nocertcheck;
Apr 28, 2011
Apr 28, 2011
80
int non_inter;
Jun 11, 2012
Jun 11, 2012
81
int cookieonly;
Sep 21, 2008
Sep 21, 2008
82
Aug 7, 2010
Aug 7, 2010
83
enum {
Jun 11, 2012
Jun 11, 2012
84
85
OPT_AUTHENTICATE = 0x100,
OPT_AUTHGROUP,
Jun 8, 2012
Jun 8, 2012
86
OPT_BASEMTU,
Aug 7, 2010
Aug 7, 2010
87
OPT_CAFILE,
May 3, 2012
May 3, 2012
88
OPT_CONFIGFILE,
Aug 7, 2010
Aug 7, 2010
89
90
91
OPT_COOKIEONLY,
OPT_COOKIE_ON_STDIN,
OPT_CSD_USER,
Nov 21, 2010
Nov 21, 2010
92
OPT_CSD_WRAPPER,
Aug 7, 2010
Aug 7, 2010
93
94
95
96
97
98
99
100
101
102
OPT_DISABLE_IPV6,
OPT_DTLS_CIPHERS,
OPT_FORCE_DPD,
OPT_KEY_PASSWORD_FROM_FSID,
OPT_LIBPROXY,
OPT_NO_CERT_CHECK,
OPT_NO_DTLS,
OPT_NO_HTTP_KEEPALIVE,
OPT_NO_PASSWD,
OPT_NO_PROXY,
Sep 9, 2011
Sep 9, 2011
103
OPT_PIDFILE,
Aug 7, 2010
Aug 7, 2010
104
105
106
107
108
OPT_PASSWORD_ON_STDIN,
OPT_PRINTCOOKIE,
OPT_RECONNECT_TIMEOUT,
OPT_SERVERCERT,
OPT_USERAGENT,
Apr 28, 2011
Apr 28, 2011
109
OPT_NON_INTER,
Aug 7, 2010
Aug 7, 2010
110
111
};
Apr 19, 2012
Apr 19, 2012
112
113
114
115
116
117
118
119
120
121
#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
Sep 21, 2008
Sep 21, 2008
122
static struct option long_options[] = {
Apr 19, 2012
Apr 19, 2012
123
124
125
126
127
128
129
130
131
132
133
134
OPTION("background", 0, 'b'),
OPTION("pid-file", 1, OPT_PIDFILE),
OPTION("certificate", 1, 'c'),
OPTION("sslkey", 1, 'k'),
OPTION("cookie", 1, 'C'),
OPTION("deflate", 0, 'd'),
OPTION("no-deflate", 0, 'D'),
OPTION("cert-expire-warning", 1, 'e'),
OPTION("usergroup", 1, 'g'),
OPTION("help", 0, 'h'),
OPTION("interface", 1, 'i'),
OPTION("mtu", 1, 'm'),
Jun 8, 2012
Jun 8, 2012
135
OPTION("base-mtu", 1, OPT_BASEMTU),
Apr 19, 2012
Apr 19, 2012
136
137
138
139
140
141
142
143
144
145
OPTION("setuid", 1, 'U'),
OPTION("script", 1, 's'),
OPTION("script-tun", 0, 'S'),
OPTION("syslog", 0, 'l'),
OPTION("key-password", 1, 'p'),
OPTION("proxy", 1, 'P'),
OPTION("user", 1, 'u'),
OPTION("verbose", 0, 'v'),
OPTION("version", 0, 'V'),
OPTION("cafile", 1, OPT_CAFILE),
May 3, 2012
May 3, 2012
146
OPTION("config", 1, OPT_CONFIGFILE),
Apr 19, 2012
Apr 19, 2012
147
OPTION("no-dtls", 0, OPT_NO_DTLS),
Jun 11, 2012
Jun 11, 2012
148
OPTION("authenticate", 0, OPT_AUTHENTICATE),
Apr 19, 2012
Apr 19, 2012
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
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),
OPTION("authgroup", 1, OPT_AUTHGROUP),
OPTION("servercert", 1, OPT_SERVERCERT),
OPTION("key-password-from-fsid", 0, OPT_KEY_PASSWORD_FROM_FSID),
OPTION("useragent", 1, OPT_USERAGENT),
OPTION("csd-user", 1, OPT_CSD_USER),
OPTION("csd-wrapper", 1, OPT_CSD_WRAPPER),
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),
OPTION(NULL, 0, 0)
Sep 21, 2008
Sep 21, 2008
173
174
};
Dec 1, 2011
Dec 1, 2011
175
176
177
178
179
180
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
181
182
183
static void print_build_opts(void)
{
#if defined (OPENCONNECT_OPENSSL) && defined (HAVE_ENGINE)
Jun 11, 2012
Jun 11, 2012
184
185
186
187
if (openconnect_has_tss_blob_support())
printf(_("Using OpenSSL with TPM ENGINE support. Loading TPM engine succeeded.\n"));
else
printf(_("Using OpenSSL with TPM ENGINE support, but loading TPM engine failed.\n"));
Jun 11, 2012
Jun 11, 2012
188
#elif defined (OPENCONNECT_OPENSSL)
Jun 11, 2012
Jun 11, 2012
189
printf(_("Using OpenSSL without TPM ENGINE support\n"));
Jun 11, 2012
Jun 11, 2012
190
#elif defined (OPENCONNECT_GNUTLS) && defined (HAVE_P11KIT)
Jun 11, 2012
Jun 11, 2012
191
printf(_("Using GnuTLS with PKCS#11 token support\n"));
Jun 11, 2012
Jun 11, 2012
192
#elif defined (OPENCONNECT_GNUTLS)
Jun 11, 2012
Jun 11, 2012
193
printf(_("Using GnuTLS without PKCS#11 token support\n"));
Jun 11, 2012
Jun 11, 2012
194
195
196
197
#else
#error wtf
#endif
#ifndef HAVE_DTLS
Jun 11, 2012
Jun 11, 2012
198
printf(_("No DTLS support in this binary\n"));
Jun 11, 2012
Jun 11, 2012
199
#elif defined (DTLS_OPENSSL)
Jun 11, 2012
Jun 11, 2012
200
printf(_("Using OpenSSL for DTLS support\n"));
Jun 11, 2012
Jun 11, 2012
201
#elif defined (DTLS_GNUTLS)
Jun 11, 2012
Jun 11, 2012
202
printf(_("Using GnuTLS for DTLS support\n"));
Jun 11, 2012
Jun 11, 2012
203
204
205
206
207
#else
#error wtf
#endif
}
Sep 15, 2011
Sep 15, 2011
208
static void usage(void)
Sep 29, 2008
Sep 29, 2008
209
{
Oct 7, 2011
Oct 7, 2011
210
printf(_("Usage: openconnect [options] <server>\n"));
May 12, 2012
May 12, 2012
211
printf(_("Open client for Cisco AnyConnect VPN, version %s\n\n"), openconnect_version_str);
Jun 11, 2012
Jun 11, 2012
212
print_build_opts();
May 3, 2012
May 3, 2012
213
printf(" --config=CONFIGFILE %s\n", _("Read options from config file"));
Oct 7, 2011
Oct 7, 2011
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
printf(" -b, --background %s\n", _("Continue in background after startup"));
printf(" --pid-file=PIDFILE %s\n", _("Write the daemons pid to this file"));
printf(" -c, --certificate=CERT %s\n", _("Use SSL client certificate CERT"));
printf(" -e, --cert-expire-warning=DAYS %s\n", _("Warn when certificate lifetime < DAYS"));
printf(" -k, --sslkey=KEY %s\n", _("Use SSL private key file KEY"));
printf(" -K, --key-type=TYPE %s\n", _("Private key type (PKCS#12 / TPM / PEM)"));
printf(" -C, --cookie=COOKIE %s\n", _("Use WebVPN cookie COOKIE"));
printf(" --cookie-on-stdin %s\n", _("Read cookie from standard input"));
printf(" -d, --deflate %s\n", _("Enable compression (default)"));
printf(" -D, --no-deflate %s\n", _("Disable compression"));
printf(" --force-dpd=INTERVAL %s\n", _("Set minimum Dead Peer Detection interval"));
printf(" -g, --usergroup=GROUP %s\n", _("Set login usergroup"));
printf(" -h, --help %s\n", _("Display help text"));
printf(" -i, --interface=IFNAME %s\n", _("Use IFNAME for tunnel interface"));
printf(" -l, --syslog %s\n", _("Use syslog for progress messages"));
printf(" -U, --setuid=USER %s\n", _("Drop privileges after connecting"));
printf(" --csd-user=USER %s\n", _("Drop privileges during CSD execution"));
printf(" --csd-wrapper=SCRIPT %s\n", _("Run SCRIPT instead of CSD binary"));
printf(" -m, --mtu=MTU %s\n", _("Request MTU from server"));
Jun 8, 2012
Jun 8, 2012
233
printf(" --base-mtu=MTU %s\n", _("Indicate path MTU to/from server"));
Oct 7, 2011
Oct 7, 2011
234
235
236
237
238
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"));
printf(" -P, --proxy=URL %s\n", _("Set proxy server"));
printf(" --no-proxy %s\n", _("Disable proxy"));
printf(" --libproxy %s\n", _("Use libproxy to automatically configure proxy"));
Sep 22, 2011
Sep 22, 2011
239
#ifndef LIBPROXY_HDR
Oct 7, 2011
Oct 7, 2011
240
printf(" %s\n", _("(NOTE: libproxy disabled in this build)"));
Jan 2, 2010
Jan 2, 2010
241
#endif
Oct 7, 2011
Oct 7, 2011
242
243
244
printf(" -q, --quiet %s\n", _("Less output"));
printf(" -Q, --queue-len=LEN %s\n", _("Set packet queue limit to LEN pkts"));
printf(" -s, --script=SCRIPT %s\n", _("Shell command line for using a vpnc-compatible config script"));
Apr 16, 2012
Apr 16, 2012
245
printf(" %s: \"%s\"\n", _("default"), DEFAULT_VPNCSCRIPT);
Oct 7, 2011
Oct 7, 2011
246
247
248
249
250
251
printf(" -S, --script-tun %s\n", _("Pass traffic to 'script' program, not tun"));
printf(" -u, --user=NAME %s\n", _("Set login username"));
printf(" -V, --version %s\n", _("Report version number"));
printf(" -v, --verbose %s\n", _("More output"));
printf(" -x, --xmlconfig=CONFIG %s\n", _("XML config file"));
printf(" --authgroup=GROUP %s\n", _("Choose authentication login selection"));
Jun 11, 2012
Jun 11, 2012
252
printf(" --authenticate %s\n", _("Authenticate only and print login info"));
Oct 7, 2011
Oct 7, 2011
253
254
255
256
257
258
259
260
261
262
263
264
265
266
printf(" --cookieonly %s\n", _("Fetch webvpn cookie only; don't connect"));
printf(" --printcookie %s\n", _("Print webvpn cookie before connecting"));
printf(" --cafile=FILE %s\n", _("Cert file for server verification"));
printf(" --disable-ipv6 %s\n", _("Do not ask for IPv6 connectivity"));
printf(" --dtls-ciphers=LIST %s\n", _("OpenSSL ciphers to support for DTLS"));
printf(" --no-dtls %s\n", _("Disable DTLS"));
printf(" --no-http-keepalive %s\n", _("Disable HTTP connection re-use"));
printf(" --no-passwd %s\n", _("Disable password/SecurID authentication"));
printf(" --no-cert-check %s\n", _("Do not require server SSL cert to be valid"));
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(" --reconnect-timeout %s\n", _("Connection retry timeout in seconds"));
printf(" --servercert=FINGERPRINT %s\n", _("Server's certificate SHA1 fingerprint"));
printf(" --useragent=STRING %s\n", _("HTTP header User-Agent: field"));
Dec 1, 2011
Dec 1, 2011
267
268
269
printf("\n");
helpmessage();
Sep 29, 2008
Sep 29, 2008
270
271
272
exit(1);
}
Oct 26, 2008
Oct 26, 2008
273
static void read_stdin(char **string)
Oct 6, 2008
Oct 6, 2008
274
275
276
{
char *c = malloc(100);
if (!c) {
Oct 7, 2011
Oct 7, 2011
277
fprintf(stderr, _("Allocation failure for string from stdin\n"));
Oct 6, 2008
Oct 6, 2008
278
279
280
exit(1);
}
if (!fgets(c, 100, stdin)) {
Oct 7, 2011
Oct 7, 2011
281
perror(_("fgets (stdin)"));
Oct 6, 2008
Oct 6, 2008
282
283
284
exit(1);
}
Oct 26, 2008
Oct 26, 2008
285
*string = c;
Oct 6, 2008
Oct 6, 2008
286
Oct 26, 2008
Oct 26, 2008
287
c = strchr(*string, '\n');
Oct 6, 2008
Oct 6, 2008
288
289
290
if (c)
*c = 0;
}
Oct 19, 2009
Oct 19, 2009
291
292
293
294
295
296
297
static void handle_sigusr(int sig)
{
if (sig == SIGUSR1)
verbose = PRG_TRACE;
else if (sig == SIGUSR2)
verbose = PRG_INFO;
}
May 3, 2012
May 3, 2012
298
299
300
301
static FILE *config_file = NULL;
static int config_line_num = 0;
Jun 5, 2012
Jun 5, 2012
302
303
304
305
306
307
308
309
310
311
312
313
/* 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);
* 2. We need to kep it, but it's a static string and will never be freed
* so when it's part of argv[] we can use it in place, but when it comes
* from a file we have to strdup() because otherwise it'll be overwritten.
* For this we use the keep_config_arg() macro below.
* 3. It may be freed during normal operation, so we have to use strdup()
* even when it's an option from argv[]. (e.g. vpninfo->cert_password).
*/
#define keep_config_arg() (config_file?strdup(config_arg):config_arg)
May 3, 2012
May 3, 2012
314
315
316
static int next_option(int argc, char **argv, char **config_arg)
{
May 3, 2012
May 3, 2012
317
318
319
320
321
322
323
324
325
326
327
328
329
/* These get re-used */
static char *line_buf = NULL;
static size_t line_size = 0;
ssize_t llen;
int opt, optlen;
struct option *this;
char *line;
int ate_equals = 0;
next:
if (!config_file) {
opt = getopt_long(argc, argv,
Jun 11, 2012
Jun 11, 2012
330
"bC:c:e:Ddg:hi:k:lpP:Q:qSs:U:u:Vvx:",
May 3, 2012
May 3, 2012
331
332
333
334
335
336
337
338
339
340
341
342
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
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);
}
line = line_buf;
/* Strip the trailing newline (coping with DOS newlines) */
if (llen && line[llen-1] == '\n')
line[--llen] = 0;
if (llen && line[llen-1] == '\r')
line[--llen] = 0;
/* Skip and leading whitespace */
while (line[0] == ' ' || line[0] == '\t' || line[0] == '\r')
line++;
/* Ignore comments and empty lines */
if (!line[0] || line[0] == '#') {
config_line_num++;
goto next;
}
/* Try to match on a known option... naïvely. This could be improved. */
for (this = long_options; this->name; this++) {
optlen = strlen(this->name);
/* If the option isn't followed by whitespace or NUL, or
perhaps an equals sign if the option takes an argument,
then it's not a match */
if (!strncmp(this->name, line, optlen) &&
(!line[optlen] || line[optlen] == ' ' || line[optlen] == '\t' ||
line[optlen] == '='))
break;
}
if (!this->name) {
char *l;
for (l = line; *l && *l != ' ' && *l != '\t'; l++)
;
*l = 0;
fprintf(stderr, _("Unrecognised option at line %d: '%s'\n"),
config_line_num, line);
return '?';
}
line += optlen;
while (*line == ' ' || *line == '\t' ||
(*line == '=' && this->has_arg && !ate_equals && ++ate_equals))
line++;
if (!this->has_arg && *line) {
fprintf(stderr, _("Option '%s' does not take an argument at line %d\n"),
this->name, config_line_num);
return '?';
} else if (this->has_arg && !*line) {
fprintf(stderr, _("Option '%s' requires an argument at line %d\n"),
this->name, config_line_num);
return '?';
}
config_line_num++;
*config_arg = line;
return this->val;
May 3, 2012
May 3, 2012
406
407
}
Jun 1, 2012
Jun 1, 2012
408
Sep 21, 2008
Sep 21, 2008
409
410
int main(int argc, char **argv)
{
Oct 5, 2008
Oct 5, 2008
411
struct openconnect_info *vpninfo;
Sep 22, 2008
Sep 22, 2008
412
struct utsname utsbuf;
Oct 19, 2009
Oct 19, 2009
413
struct sigaction sa;
Oct 20, 2008
Oct 20, 2008
414
int use_syslog = 0;
May 13, 2012
May 13, 2012
415
char *urlpath = NULL;
Jan 2, 2010
Jan 2, 2010
416
char *proxy = getenv("https_proxy");
Jan 2, 2010
Jan 2, 2010
417
int autoproxy = 0;
Aug 21, 2009
Aug 21, 2009
418
uid_t uid = getuid();
Sep 21, 2008
Sep 21, 2008
419
int opt;
Sep 9, 2011
Sep 9, 2011
420
421
char *pidfile = NULL;
FILE *fp = NULL;
May 3, 2012
May 3, 2012
422
char *config_arg;
Sep 21, 2008
Sep 21, 2008
423
Sep 22, 2011
Sep 22, 2011
424
#ifdef ENABLE_NLS
Nov 24, 2011
Nov 24, 2011
425
bindtextdomain("openconnect", LOCALEDIR);
Sep 22, 2011
Sep 22, 2011
426
427
428
setlocale(LC_ALL, "");
#endif
May 12, 2012
May 12, 2012
429
if (strcmp(openconnect_version_str, openconnect_binary_version)) {
Nov 7, 2011
Nov 7, 2011
430
431
fprintf(stderr, _("WARNING: This version of openconnect is %s but\n"
" the libopenconnect library is %s\n"),
May 12, 2012
May 12, 2012
432
openconnect_binary_version, openconnect_version_str);
Nov 7, 2011
Nov 7, 2011
433
434
}
Jun 8, 2012
Jun 8, 2012
435
openconnect_init_ssl();
Sep 22, 2008
Sep 22, 2008
436
437
438
vpninfo = malloc(sizeof(*vpninfo));
if (!vpninfo) {
Oct 7, 2011
Oct 7, 2011
439
fprintf(stderr, _("Failed to allocate vpninfo structure\n"));
Sep 22, 2008
Sep 22, 2008
440
441
442
exit(1);
}
memset(vpninfo, 0, sizeof(*vpninfo));
Sep 22, 2008
Sep 22, 2008
443
Sep 22, 2008
Sep 22, 2008
444
/* Set up some defaults */
Oct 2, 2008
Oct 2, 2008
445
vpninfo->tun_fd = vpninfo->ssl_fd = vpninfo->dtls_fd = vpninfo->new_dtls_fd = -1;
Aug 4, 2009
Aug 4, 2009
446
vpninfo->useragent = openconnect_create_useragent("Open AnyConnect VPN Agent");
Jun 8, 2012
Jun 8, 2012
447
vpninfo->mtu = 0;
Sep 30, 2008
Sep 30, 2008
448
vpninfo->deflate = 1;
Oct 2, 2008
Oct 2, 2008
449
vpninfo->dtls_attempt_period = 60;
Oct 26, 2008
Oct 26, 2008
450
vpninfo->max_qlen = 10;
Dec 12, 2008
Dec 12, 2008
451
vpninfo->reconnect_interval = RECONNECT_INTERVAL_MIN;
Dec 11, 2008
Dec 11, 2008
452
vpninfo->reconnect_timeout = 300;
Sep 21, 2009
Sep 21, 2009
453
454
vpninfo->uid_csd = 0;
vpninfo->uid_csd_given = 0;
May 11, 2010
May 11, 2010
455
vpninfo->validate_peer_cert = validate_peer_cert;
May 29, 2012
May 29, 2012
456
vpninfo->process_auth_form = process_auth_form;
Jun 27, 2011
Jun 27, 2011
457
vpninfo->cbdata = vpninfo;
Sep 29, 2011
Sep 29, 2011
458
vpninfo->cert_expire_warning = 60 * 86400;
Apr 16, 2012
Apr 16, 2012
459
vpninfo->vpnc_script = DEFAULT_VPNCSCRIPT;
May 12, 2012
May 12, 2012
460
vpninfo->cancel_fd = -1;
Sep 30, 2008
Sep 30, 2008
461
Sep 22, 2008
Sep 22, 2008
462
463
464
465
466
if (!uname(&utsbuf))
vpninfo->localname = utsbuf.nodename;
else
vpninfo->localname = "localhost";
May 3, 2012
May 3, 2012
467
468
while ((opt = next_option(argc, argv, &config_arg))) {
Sep 21, 2008
Sep 21, 2008
469
470
471
472
if (opt < 0)
break;
switch (opt) {
May 3, 2012
May 3, 2012
473
474
475
476
477
478
479
480
481
482
483
484
485
486
case OPT_CONFIGFILE:
if (config_file) {
fprintf(stderr, _("Cannot use 'config' option inside config file\n"));
exit(1);
}
config_file = fopen(config_arg, "r");
if (!config_file) {
fprintf(stderr, _("Cannot open config file '%s': %s\n"),
config_arg, strerror(errno));
exit(1);
}
config_line_num = 1;
/* The next option will come from the file... */
break;
Aug 7, 2010
Aug 7, 2010
487
case OPT_CAFILE:
May 3, 2012
May 3, 2012
488
vpninfo->cafile = keep_config_arg();
Sep 30, 2008
Sep 30, 2008
489
break;
Sep 9, 2011
Sep 9, 2011
490
case OPT_PIDFILE:
May 3, 2012
May 3, 2012
491
pidfile = keep_config_arg();
Sep 9, 2011
Sep 9, 2011
492
break;
Aug 7, 2010
Aug 7, 2010
493
case OPT_SERVERCERT:
May 3, 2012
May 3, 2012
494
vpninfo->servercert = keep_config_arg();
May 26, 2009
May 26, 2009
495
break;
Aug 7, 2010
Aug 7, 2010
496
case OPT_NO_DTLS:
Oct 7, 2008
Oct 7, 2008
497
vpninfo->dtls_attempt_period = 0;
Sep 30, 2008
Sep 30, 2008
498
break;
Aug 7, 2010
Aug 7, 2010
499
case OPT_COOKIEONLY:
Oct 1, 2008
Oct 1, 2008
500
501
cookieonly = 1;
break;
Aug 7, 2010
Aug 7, 2010
502
case OPT_PRINTCOOKIE:
Oct 2, 2008
Oct 2, 2008
503
504
cookieonly = 2;
break;
Jun 11, 2012
Jun 11, 2012
505
506
507
case OPT_AUTHENTICATE:
cookieonly = 3;
break;
Aug 7, 2010
Aug 7, 2010
508
case OPT_COOKIE_ON_STDIN:
Oct 26, 2008
Oct 26, 2008
509
read_stdin(&vpninfo->cookie);
Oct 26, 2008
Oct 26, 2008
510
511
512
513
/* If the cookie is empty, ignore it */
if (! *vpninfo->cookie) {
vpninfo->cookie = NULL;
}
Oct 26, 2008
Oct 26, 2008
514
break;
Aug 7, 2010
Aug 7, 2010
515
case OPT_PASSWORD_ON_STDIN:
Oct 26, 2008
Oct 26, 2008
516
read_stdin(&vpninfo->password);
Oct 6, 2008
Oct 6, 2008
517
break;
Aug 7, 2010
Aug 7, 2010
518
case OPT_NO_PASSWD:
Nov 4, 2008
Nov 4, 2008
519
520
vpninfo->nopasswd = 1;
break;
Apr 28, 2011
Apr 28, 2011
521
522
523
case OPT_NON_INTER:
non_inter = 1;
break;
Aug 7, 2010
Aug 7, 2010
524
case OPT_RECONNECT_TIMEOUT:
May 3, 2012
May 3, 2012
525
vpninfo->reconnect_timeout = atoi(config_arg);
Dec 12, 2008
Dec 12, 2008
526
break;
Aug 7, 2010
Aug 7, 2010
527
case OPT_DTLS_CIPHERS:
May 3, 2012
May 3, 2012
528
vpninfo->dtls_ciphers = keep_config_arg();
Apr 24, 2009
Apr 24, 2009
529
break;
Aug 7, 2010
Aug 7, 2010
530
case OPT_AUTHGROUP:
May 3, 2012
May 3, 2012
531
vpninfo->authgroup = keep_config_arg();
May 7, 2009
May 7, 2009
532
break;
Apr 28, 2009
Apr 28, 2009
533
534
535
case 'b':
background = 1;
break;
Sep 25, 2008
Sep 25, 2008
536
case 'C':
May 3, 2012
May 3, 2012
537
vpninfo->cookie = keep_config_arg();
Sep 21, 2008
Sep 21, 2008
538
break;
Sep 25, 2008
Sep 25, 2008
539
case 'c':
Jun 12, 2012
Jun 12, 2012
540
vpninfo->cert = strdup(config_arg);
Sep 25, 2008
Sep 25, 2008
541
break;
Sep 29, 2011
Sep 29, 2011
542
case 'e':
May 3, 2012
May 3, 2012
543
vpninfo->cert_expire_warning = 86400 * atoi(config_arg);
Sep 29, 2011
Sep 29, 2011
544
break;
Sep 30, 2008
Sep 30, 2008
545
case 'k':
Jun 12, 2012
Jun 12, 2012
546
vpninfo->sslkey = strdup(config_arg);
Sep 30, 2008
Sep 30, 2008
547
break;
Sep 29, 2008
Sep 29, 2008
548
549
550
551
552
553
case 'd':
vpninfo->deflate = 1;
break;
case 'D':
vpninfo->deflate = 0;
break;
Mar 31, 2009
Mar 31, 2009
554
case 'g':
May 13, 2012
May 13, 2012
555
556
free(urlpath);
urlpath = strdup(config_arg);
Mar 31, 2009
Mar 31, 2009
557
break;
Sep 21, 2008
Sep 21, 2008
558
case 'h':
Sep 29, 2008
Sep 29, 2008
559
560
usage();
case 'i':
May 3, 2012
May 3, 2012
561
vpninfo->ifname = keep_config_arg();
Sep 21, 2008
Sep 21, 2008
562
break;
Oct 20, 2008
Oct 20, 2008
563
564
565
case 'l':
use_syslog = 1;
break;
Sep 21, 2008
Sep 21, 2008
566
case 'm':
May 3, 2012
May 3, 2012
567
vpninfo->mtu = atol(config_arg);
Sep 22, 2008
Sep 22, 2008
568
if (vpninfo->mtu < 576) {
Oct 7, 2011
Oct 7, 2011
569
fprintf(stderr, _("MTU %d too small\n"), vpninfo->mtu);
Sep 22, 2008
Sep 22, 2008
570
vpninfo->mtu = 576;
Sep 21, 2008
Sep 21, 2008
571
572
}
break;
Jun 8, 2012
Jun 8, 2012
573
574
575
576
577
578
579
case OPT_BASEMTU:
vpninfo->basemtu = atol(config_arg);
if (vpninfo->basemtu < 576) {
fprintf(stderr, _("MTU %d too small\n"), vpninfo->basemtu);
vpninfo->basemtu = 576;
}
break;
Sep 29, 2008
Sep 29, 2008
580
case 'p':
Jun 5, 2012
Jun 5, 2012
581
vpninfo->cert_password = strdup(config_arg);
Sep 29, 2008
Sep 29, 2008
582
break;
Jan 2, 2010
Jan 2, 2010
583
case 'P':
May 3, 2012
May 3, 2012
584
proxy = keep_config_arg();
Jan 2, 2010
Jan 2, 2010
585
autoproxy = 0;
Jan 1, 2010
Jan 1, 2010
586
break;
Aug 7, 2010
Aug 7, 2010
587
case OPT_NO_PROXY:
Jan 2, 2010
Jan 2, 2010
588
autoproxy = 0;
Jan 2, 2010
Jan 2, 2010
589
proxy = NULL;
Aug 7, 2010
Aug 7, 2010
590
case OPT_LIBPROXY:
Jan 2, 2010
Jan 2, 2010
591
592
593
autoproxy = 1;
proxy = NULL;
break;
Aug 7, 2010
Aug 7, 2010
594
case OPT_NO_HTTP_KEEPALIVE:
Oct 7, 2011
Oct 7, 2011
595
596
597
fprintf(stderr,
_("Disabling all HTTP connection re-use due to --no-http-keepalive option.\n"
"If this helps, please report to <openconnect-devel@lists.infradead.org>.\n"));
Apr 9, 2010
Apr 9, 2010
598
599
vpninfo->no_http_keepalive = 1;
break;
Aug 7, 2010
Aug 7, 2010
600
case OPT_NO_CERT_CHECK:
May 11, 2010
May 11, 2010
601
602
nocertcheck = 1;
break;
Sep 29, 2008
Sep 29, 2008
603
case 's':
May 3, 2012
May 3, 2012
604
vpninfo->vpnc_script = keep_config_arg();
Sep 29, 2008
Sep 29, 2008
605
break;
Oct 6, 2008
Oct 6, 2008
606
607
608
case 'S':
vpninfo->script_tun = 1;
break;
Sep 22, 2008
Sep 22, 2008
609
case 'u':
May 3, 2012
May 3, 2012
610
vpninfo->username = keep_config_arg();
Sep 22, 2008
Sep 22, 2008
611
break;
Oct 20, 2008
Oct 20, 2008
612
613
case 'U': {
char *strend;
May 3, 2012
May 3, 2012
614
uid = strtol(config_arg, &strend, 0);
Oct 20, 2008
Oct 20, 2008
615
if (strend[0]) {
May 3, 2012
May 3, 2012
616
struct passwd *pw = getpwnam(config_arg);
Oct 20, 2008
Oct 20, 2008
617
if (!pw) {
Oct 7, 2011
Oct 7, 2011
618
fprintf(stderr, _("Invalid user \"%s\"\n"),
May 3, 2012
May 3, 2012
619
config_arg);
Oct 20, 2008
Oct 20, 2008
620
621
exit(1);
}
Aug 21, 2009
Aug 21, 2009
622
623
624
625
uid = pw->pw_uid;
}
break;
}
Aug 7, 2010
Aug 7, 2010
626
case OPT_CSD_USER: {
Aug 21, 2009
Aug 21, 2009
627
char *strend;
May 3, 2012
May 3, 2012
628
vpninfo->uid_csd = strtol(config_arg, &strend, 0);
Aug 21, 2009
Aug 21, 2009
629
if (strend[0]) {
May 3, 2012
May 3, 2012
630
struct passwd *pw = getpwnam(config_arg);
Aug 21, 2009
Aug 21, 2009
631
if (!pw) {
Oct 7, 2011
Oct 7, 2011
632
fprintf(stderr, _("Invalid user \"%s\"\n"),
May 3, 2012
May 3, 2012
633
config_arg);
Aug 21, 2009
Aug 21, 2009
634
635
636
exit(1);
}
vpninfo->uid_csd = pw->pw_uid;
Oct 20, 2008
Oct 20, 2008
637
}
Sep 21, 2009
Sep 21, 2009
638
vpninfo->uid_csd_given = 1;
Oct 20, 2008
Oct 20, 2008
639
640
break;
}
Nov 21, 2010
Nov 21, 2010
641
case OPT_CSD_WRAPPER:
May 3, 2012
May 3, 2012
642
vpninfo->csd_wrapper = keep_config_arg();
Nov 21, 2010
Nov 21, 2010
643
break;
Aug 7, 2010
Aug 7, 2010
644
case OPT_DISABLE_IPV6:
Nov 2, 2009
Nov 2, 2009
645
646
vpninfo->disable_ipv6 = 1;
break;
Oct 26, 2008
Oct 26, 2008
647
case 'Q':
May 3, 2012
May 3, 2012
648
vpninfo->max_qlen = atol(config_arg);
Oct 26, 2008
Oct 26, 2008
649
if (!vpninfo->max_qlen) {
Oct 7, 2011
Oct 7, 2011
650
fprintf(stderr, _("Queue length zero not permitted; using 1\n"));
Oct 26, 2008
Oct 26, 2008
651
652
653
vpninfo->max_qlen = 1;
}
break;
Oct 5, 2008
Oct 5, 2008
654
655
656
case 'q':
verbose = PRG_ERR;
break;
Sep 22, 2008
Sep 22, 2008
657
case 'v':
Oct 5, 2008
Oct 5, 2008
658
verbose = PRG_TRACE;
Sep 22, 2008
Sep 22, 2008
659
break;
Oct 2, 2008
Oct 2, 2008
660
case 'V':
May 12, 2012
May 12, 2012
661
printf(_("OpenConnect version %s\n"), openconnect_version_str);
Jun 11, 2012
Jun 11, 2012
662
print_build_opts();
Oct 2, 2008
Oct 2, 2008
663
exit(0);
Sep 30, 2008
Sep 30, 2008
664
case 'x':
May 3, 2012
May 3, 2012
665
vpninfo->xmlconfig = keep_config_arg();
Oct 5, 2008
Oct 5, 2008
666
vpninfo->write_new_config = write_new_config;
Sep 30, 2008
Sep 30, 2008
667
break;
Aug 7, 2010
Aug 7, 2010
668
case OPT_KEY_PASSWORD_FROM_FSID:
Nov 30, 2010
Nov 30, 2010
669
do_passphrase_from_fsid = 1;
May 28, 2009
May 28, 2009
670
break;
Aug 7, 2010
Aug 7, 2010
671
case OPT_USERAGENT:
Aug 4, 2009
Aug 4, 2009
672
free(vpninfo->useragent);
May 3, 2012
May 3, 2012
673
vpninfo->useragent = strdup(config_arg);
Aug 4, 2009
Aug 4, 2009
674
break;
Aug 7, 2010
Aug 7, 2010
675
case OPT_FORCE_DPD:
May 3, 2012
May 3, 2012
676
vpninfo->dtls_times.dpd = vpninfo->ssl_times.dpd = atoi(config_arg);
Aug 7, 2010
Aug 7, 2010
677
break;
Sep 29, 2008
Sep 29, 2008
678
679
default:
usage();
Sep 21, 2008
Sep 21, 2008
680
681
}
}
Jan 2, 2010
Jan 2, 2010
682
May 15, 2012
May 15, 2012
683
684
685
686
if (optind < argc - 1) {
fprintf(stderr, _("Too many arguments on command line\n"));
usage();
} else if (optind > argc - 1) {
Oct 7, 2011
Oct 7, 2011
687
fprintf(stderr, _("No server specified\n"));
Sep 29, 2008
Sep 29, 2008
688
usage();
Sep 21, 2008
Sep 21, 2008
689
690
}
Sep 30, 2008
Sep 30, 2008
691
692
693
if (!vpninfo->sslkey)
vpninfo->sslkey = vpninfo->cert;
Jan 2, 2010
Jan 2, 2010
694
695
vpninfo->progress = write_progress;
Sep 15, 2011
Sep 15, 2011
696
if (autoproxy) {
Sep 22, 2011
Sep 22, 2011
697
#ifdef LIBPROXY_HDR
Jan 2, 2010
Jan 2, 2010
698
vpninfo->proxy_factory = px_proxy_factory_new();
Sep 15, 2011
Sep 15, 2011
699
#else
Oct 7, 2011
Oct 7, 2011
700
fprintf(stderr, _("This version of openconnect was built without libproxy support\n"));
Sep 15, 2011
Sep 15, 2011
701
exit(1);
Jan 2, 2010
Jan 2, 2010
702
#endif
Sep 15, 2011
Sep 15, 2011
703
704
}
Mar 17, 2011
Mar 17, 2011
705
if (proxy && openconnect_set_http_proxy(vpninfo, strdup(proxy)))
Jan 2, 2010
Jan 2, 2010
706
707
exit(1);
Oct 20, 2008
Oct 20, 2008
708
if (use_syslog) {
Jul 15, 2011
Jul 15, 2011
709
#ifndef ANDROID
Oct 20, 2008
Oct 20, 2008
710
openlog("openconnect", LOG_PID, LOG_DAEMON);
Jul 15, 2011
Jul 15, 2011
711
#endif
Oct 20, 2008
Oct 20, 2008
712
713
vpninfo->progress = syslog_progress;
}
Jan 2, 2010
Jan 2, 2010
714
Oct 19, 2009
Oct 19, 2009
715
716
717
718
719
memset(&sa, 0, sizeof(sa));
sa.sa_handler = handle_sigusr;
sigaction(SIGUSR1, &sa, NULL);
sigaction(SIGUSR2, &sa, NULL);
Oct 20, 2008
Oct 20, 2008
720
Nov 30, 2010
Nov 30, 2010
721
if (vpninfo->sslkey && do_passphrase_from_fsid)
Nov 16, 2010
Nov 16, 2010
722
openconnect_passphrase_from_fsid(vpninfo);
May 28, 2009
May 28, 2009
723
Nov 4, 2008
Nov 4, 2008
724
725
726
if (config_lookup_host(vpninfo, argv[optind]))
exit(1);
Jan 1, 2010
Jan 1, 2010
727
728
729
if (!vpninfo->hostname) {
char *url = strdup(argv[optind]);
May 13, 2012
May 13, 2012
730
if (openconnect_parse_url(vpninfo, url))
Jan 1, 2010
Jan 1, 2010
731
exit(1);
May 13, 2012
May 13, 2012
732
Jan 3, 2010
Jan 3, 2010
733
free(url);
Jan 1, 2010
Jan 1, 2010
734
}
Nov 4, 2008
Nov 4, 2008
735
May 13, 2012
May 13, 2012
736
737
738
739
740
741
742
743
744
/* Historically, the path in the URL superseded the one in the
* --usergroup argument, just because of the order in which they
* were processed. Preserve that behaviour. */
if (urlpath && !vpninfo->urlpath) {
vpninfo->urlpath = urlpath;
urlpath = NULL;
}
free(urlpath);
Oct 15, 2008
Oct 15, 2008
745
#ifdef SSL_UI
Oct 4, 2008
Oct 4, 2008
746
set_openssl_ui();
Oct 15, 2008
Oct 15, 2008
747
#endif
Oct 4, 2008
Oct 4, 2008
748
Apr 22, 2009
Apr 22, 2009
749
if (!vpninfo->cookie && openconnect_obtain_cookie(vpninfo)) {
Oct 7, 2011
Oct 7, 2011
750
fprintf(stderr, _("Failed to obtain WebVPN cookie\n"));
Sep 25, 2008
Sep 25, 2008
751
752
753
exit(1);
}
Jun 11, 2012
Jun 11, 2012
754
755
756
757
758
759
760
761
762
if (cookieonly == 3) {
/* --authenticate */
printf("COOKIE='%s'\n", vpninfo->cookie);
printf("HOST='%s'\n", vpninfo->hostname);
if (vpninfo->peer_cert) {
char buf[41] = {0, };
openconnect_get_cert_sha1(vpninfo, vpninfo->peer_cert, buf);
printf("FINGERPRINT='%s'\n", buf);
}
Jun 12, 2012
Jun 12, 2012
763
openconnect_vpninfo_free(vpninfo);
Jun 11, 2012
Jun 11, 2012
764
765
exit(0);
} else if (cookieonly) {
Oct 1, 2008
Oct 1, 2008
766
printf("%s\n", vpninfo->cookie);
Jun 12, 2012
Jun 12, 2012
767
if (cookieonly == 1) {
Oct 2, 2008
Oct 2, 2008
768
/* We use cookieonly=2 for 'print it and continue' */
Jun 12, 2012
Jun 12, 2012
769
openconnect_vpninfo_free(vpninfo);
Oct 2, 2008
Oct 2, 2008
770
exit(0);
Jun 12, 2012
Jun 12, 2012
771
}
Oct 1, 2008
Oct 1, 2008
772
}
Oct 4, 2008
Oct 4, 2008
773
if (make_cstp_connection(vpninfo)) {
Oct 7, 2011
Oct 7, 2011
774
fprintf(stderr, _("Creating SSL connection failed\n"));
Sep 22, 2008
Sep 22, 2008
775
776
exit(1);
}
Apr 9, 2009
Apr 9, 2009
777
Sep 22, 2008
Sep 22, 2008
778
if (setup_tun(vpninfo)) {
Oct 7, 2011
Oct 7, 2011
779
fprintf(stderr, _("Set up tun device failed\n"));
Sep 21, 2008
Sep 21, 2008
780
exit(1);
Sep 22, 2008
Sep 22, 2008
781
}
Sep 22, 2008
Sep 22, 2008
782
Aug 21, 2009
Aug 21, 2009
783
784
if (uid != getuid()) {
if (setuid(uid)) {
Apr 19, 2012
Apr 19, 2012
785
786
fprintf(stderr, _("Failed to set uid %ld\n"),
(long)uid);
Oct 20, 2008
Oct 20, 2008
787
788
789
exit(1);
}
}
Apr 9, 2009
Apr 9, 2009
790
Oct 7, 2008
Oct 7, 2008
791
if (vpninfo->dtls_attempt_period && setup_dtls(vpninfo))
Oct 7, 2011
Oct 7, 2011
792
fprintf(stderr, _("Set up DTLS failed; using SSL instead\n"));
Sep 22, 2008
Sep 22, 2008
793
Jun 27, 2011
Jun 27, 2011
794
vpn_progress(vpninfo, PRG_INFO,
Sep 22, 2011
Sep 22, 2011
795
796
797
798
799
800
801
_("Connected %s as %s%s%s, using %s\n"), vpninfo->ifname,
vpninfo->vpn_addr?:"",
(vpninfo->vpn_addr6 && vpninfo->vpn_addr)?" + ":"",
vpninfo->vpn_addr6?:"",
(vpninfo->dtls_fd == -1) ?
(vpninfo->deflate ? "SSL + deflate" : "SSL")
: "DTLS");
Sep 30, 2008
Sep 30, 2008
802
Dec 1, 2011
Dec 1, 2011
803
if (!vpninfo->vpnc_script) {
Jun 27, 2011
Jun 27, 2011
804
vpn_progress(vpninfo, PRG_INFO,
Sep 22, 2011
Sep 22, 2011
805
_("No --script argument provided; DNS and routing are not configured\n"));
Dec 1, 2011
Dec 1, 2011
806
807
808
vpn_progress(vpninfo, PRG_INFO,
_("See http://www.infradead.org/openconnect/vpnc-script.html\n"));
}
Apr 5, 2010
Apr 5, 2010
809
Apr 28, 2009
Apr 28, 2009
810
811
if (background) {
int pid;
Sep 9, 2011
Sep 9, 2011
812
813
814
815
816
817
818
/* Open the pidfile before forking, so we can report errors
more sanely. It's *possible* that we'll fail to write to
it, but very unlikely. */
if (pidfile != NULL) {
fp = fopen(pidfile, "w");
if (!fp) {
Sep 22, 2011
Sep 22, 2011
819
fprintf(stderr, _("Failed to open '%s' for write: %s\n"),
Sep 9, 2011
Sep 9, 2011
820
821
822
823
pidfile, strerror(errno));
exit(1);
}
}
Feb 3, 2010
Feb 3, 2010
824
if ((pid = fork())) {
Sep 9, 2011
Sep 9, 2011
825
826
827
828
if (fp) {
fprintf(fp, "%d\n", pid);
fclose(fp);
}
Jun 27, 2011
Jun 27, 2011
829
vpn_progress(vpninfo, PRG_INFO,
Sep 22, 2011
Sep 22, 2011
830
_("Continuing in background; pid %d\n"),
Sep 9, 2011
Sep 9, 2011
831
pid);
Feb 3, 2010
Feb 3, 2010
832
exit(0);
Apr 28, 2009
Apr 28, 2009
833
}
Sep 9, 2011
Sep 9, 2011
834
835
if (fp)
fclose(fp);
Apr 28, 2009
Apr 28, 2009
836
}
Sep 22, 2008
Sep 22, 2008
837
vpn_mainloop(vpninfo);
Sep 9, 2011
Sep 9, 2011
838
839
if (fp)
unlink(pidfile);
Sep 22, 2008
Sep 22, 2008
840
exit(1);
Sep 20, 2008
Sep 20, 2008
841
}
Oct 4, 2008
Oct 4, 2008
842
Jun 27, 2011
Jun 27, 2011
843
static int write_new_config(void *_vpninfo, char *buf, int buflen)
Oct 4, 2008
Oct 4, 2008
844
{
Jun 27, 2011
Jun 27, 2011
845
struct openconnect_info *vpninfo = _vpninfo;
Oct 4, 2008
Oct 4, 2008
846
int config_fd;
Oct 5, 2009
Oct 5, 2009
847
int err;
Oct 4, 2008
Oct 4, 2008
848
849
config_fd = open(vpninfo->xmlconfig, O_WRONLY|O_TRUNC|O_CREAT, 0644);
Oct 5, 2009
Oct 5, 2009
850
if (config_fd < 0) {
Oct 5, 2009
Oct 5, 2009
851
err = errno;
Sep 22, 2011
Sep 22, 2011
852
fprintf(stderr, _("Failed to open %s for write: %s\n"),
Oct 5, 2009
Oct 5, 2009
853
854
vpninfo->xmlconfig, strerror(err));
return -err;
Oct 4, 2008
Oct 4, 2008
855
856
857
}
/* FIXME: We should actually write to a new tempfile, then rename */
Oct 5, 2009
Oct 5, 2009
858
859
if(write(config_fd, buf, buflen) != buflen) {
err = errno;
Sep 22, 2011
Sep 22, 2011
860
fprintf(stderr, _("Failed to write config to %s: %s\n"),
Oct 5, 2009
Oct 5, 2009
861
862
863
864
865
vpninfo->xmlconfig, strerror(err));
return -err;
}
Oct 4, 2008
Oct 4, 2008
866
867
return 0;
}
Oct 5, 2008
Oct 5, 2008
868
Jun 27, 2011
Jun 27, 2011
869
void write_progress(void *_vpninfo, int level, const char *fmt, ...)
Oct 5, 2008
Oct 5, 2008
870
{
Apr 9, 2009
Apr 9, 2009
871
FILE *outf = level ? stdout : stderr;
Oct 5, 2008
Oct 5, 2008
872
873
va_list args;
Jun 11, 2012
Jun 11, 2012
874
875
876
if (cookieonly)
outf = stderr;
Oct 5, 2008
Oct 5, 2008
877
878
879
880
if (verbose >= level) {
va_start(args, fmt);
vfprintf(outf, fmt, args);
va_end(args);
May 11, 2012
May 11, 2012
881
fflush(outf);
Oct 5, 2008
Oct 5, 2008
882
883
}
}
Oct 20, 2008
Oct 20, 2008
884
Jul 15, 2011
Jul 15, 2011
885
886
887
888
889
890
891
892
893
#ifdef ANDROID
void syslog_progress(void *_vpninfo, int level, const char *fmt, ...)
{
static int l[4] = {
ANDROID_LOG_ERROR, /* PRG_ERR */
ANDROID_LOG_INFO, /* PRG_INFO */
ANDROID_LOG_DEBUG, /* PRG_DEBUG */
ANDROID_LOG_DEBUG /* PRG_TRACE */
};
Jul 20, 2011
Jul 20, 2011
894
va_list args, args2;
Jul 15, 2011
Jul 15, 2011
895
896
897
if (verbose >= level) {
va_start(args, fmt);
Jul 20, 2011
Jul 20, 2011
898
va_copy(args2, args);
Jul 15, 2011
Jul 15, 2011
899
__android_log_vprint(l[level], "openconnect", fmt, args);
Jul 20, 2011
Jul 20, 2011
900
901
902
/* 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);
Jul 15, 2011
Jul 15, 2011
903
va_end(args);
Jul 20, 2011
Jul 20, 2011
904
va_end(args2);
Jul 15, 2011
Jul 15, 2011
905
906
907
}
}
#else /* !ANDROID */
Jun 27, 2011
Jun 27, 2011
908
void syslog_progress(void *_vpninfo, int level, const char *fmt, ...)
Oct 20, 2008
Oct 20, 2008
909
{
Apr 9, 2009
Apr 9, 2009
910
int priority = level ? LOG_INFO : LOG_NOTICE;
Oct 20, 2008
Oct 20, 2008
911
912
913
914
915
916
917
918
va_list args;
if (verbose >= level) {
va_start(args, fmt);
vsyslog(priority, fmt, args);
va_end(args);
}
}
Jul 15, 2011
Jul 15, 2011
919
#endif
May 11, 2010
May 11, 2010
920
921
922
struct accepted_cert {
struct accepted_cert *next;
May 29, 2012
May 29, 2012
923
char fingerprint[SHA1_SIZE * 2 + 1];
May 11, 2010
May 11, 2010
924
925
926
char host[0];
} *accepted_certs;
May 29, 2012
May 29, 2012
927
static int validate_peer_cert(void *_vpninfo, OPENCONNECT_X509 *peer_cert,
May 11, 2010
May 11, 2010
928
929
const char *reason)
{
Jun 27, 2011
Jun 27, 2011
930
struct openconnect_info *vpninfo = _vpninfo;
May 29, 2012
May 29, 2012
931
char fingerprint[SHA1_SIZE * 2 + 1];
May 11, 2010
May 11, 2010
932
933
934
struct accepted_cert *this;
int ret;
May 11, 2010
May 11, 2010
935
936
937
if (nocertcheck)
return 0;
Mar 9, 2011
Mar 9, 2011
938
ret = openconnect_get_cert_sha1(vpninfo, peer_cert, fingerprint);
May 11, 2010
May 11, 2010
939
940
941
942
943
944
945
946
947
948
if (ret)
return ret;
for (this = accepted_certs; this; this = this->next) {
if (!strcasecmp(this->host, vpninfo->hostname) &&
!strcasecmp(this->fingerprint, fingerprint))
return 0;
}
while (1) {
Jun 1, 2012
Jun 1, 2012
949
char buf[80];
May 29, 2012
May 29, 2012
950
char *details;
Jun 1, 2012
Jun 1, 2012
951
char *p;
May 11, 2010
May 11, 2010
952
Jun 11, 2012
Jun 11, 2012
953
fprintf(stderr, _("\nCertificate from VPN server \"%s\" failed verification.\n"
Jun 1, 2012
Jun 1, 2012
954
"Reason: %s\n"), vpninfo->hostname, reason);
May 16, 2012
May 16, 2012
955
Apr 28, 2011
Apr 28, 2011
956
957
958
if (non_inter)
return -EINVAL;
Jun 11, 2012
Jun 11, 2012
959
fprintf(stderr, _("Enter '%s' to accept, '%s' to abort; anything else to view: "),
Jun 1, 2012
Jun 1, 2012
960
961
_("yes"), _("no"));
if (!fgets(buf, sizeof(buf), stdin))
May 11, 2010
May 11, 2010
962
return -EINVAL;
Jun 1, 2012
Jun 1, 2012
963
964
965
p = strchr(buf, '\n');
if (p)
*p = 0;
May 11, 2010
May 11, 2010
966
Sep 22, 2011
Sep 22, 2011
967
if (!strcasecmp(buf, _("yes"))) {
May 11, 2010
May 11, 2010
968
969
970
971
972
973
974
975
976
977
struct accepted_cert *newcert = malloc(sizeof(*newcert) +
strlen(vpninfo->hostname) + 1);
if (newcert) {
newcert->next = accepted_certs;
accepted_certs = newcert;
strcpy(newcert->fingerprint, fingerprint);
strcpy(newcert->host, vpninfo->hostname);
}
return 0;
}
Sep 22, 2011
Sep 22, 2011
978
if (!strcasecmp(buf, _("no")))
May 11, 2010
May 11, 2010
979
980
return -EINVAL;
May 29, 2012
May 29, 2012
981
982
983
details = openconnect_get_cert_details(vpninfo, peer_cert);
fputs(details, stderr);
free(details);
Sep 22, 2011
Sep 22, 2011
984
fprintf(stderr, _("SHA1 fingerprint: %s\n"), fingerprint);
May 11, 2010
May 11, 2010
985
986
987
}
}
May 29, 2012
May 29, 2012
988
989
990
991
992
993
994
995
996
997
998
999
/* Return value:
* < 0, on error
* = 0, when form was parsed and POST required
* = 1, when response was cancelled by user
*/
static int process_auth_form(void *_vpninfo,
struct oc_auth_form *form)
{
struct openconnect_info *vpninfo = _vpninfo;
struct oc_form_opt *opt;
Jun 1, 2012
Jun 1, 2012
1000
char response[1024];