Append vpninfo->urlpath to <group-access>

Some ASA gateways may need the relative path specified in <group-access> XML
entry so it makes sense to verify if it exists and append it.

Signed-off-by: Murilo Opsfelder Araujo <muriloo@linux.vnet.ibm.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Import translations from GNOME

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Include string.h where needed

This fixes the Solaris build; reported by "Rodney".

Also clean up #includes in compat.c; there's no need for them to be
hidden within the various ifdef blocks. Leave <sys/time.h> where it was,
just in case it's problematic on some platform. The rest are already
included unconditionally in other files, so should be fine.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Fix outdated autohate files in release tarballs

Remove --copy and add --force. We'll end up with symlinks to the original
libtool/automake files which will thus remain up to date, and shouldn't
get old files in release tarballs any more.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Clear peer_addr if aborting XML POST changes the hostname

peer_addr needs to be reset if the host changes, or else we will connect
to the wrong host, and probably trigger a certificate mismatch.

References:

Commit d9aa66ba2d (Clear cached peer_addr where necessary)
http://lists.infradead.org/pipermail/openconnect-devel/2013-August/001136.html

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
library: Remove declaration for nonexistent openconnect_get_vpn_name()

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
auth: Hack around const warnings

Seen on an NDK build:

    ../../../auth.c: In function 'prepare_stoken':
    ../../../auth.c:901:15: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]
    ../../../auth.c:909:14: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]
    ../../../auth.c:916:14: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]
    ../../../auth.c:923:14: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Introduce new helper functions for cancel_fd checking

The same code shows up in 12 places, so we'll move it into an inline
function.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
library: Add new openconnect_setup_cancel_pipe() call

Most callers will use a simple nonblocking UNIX pipe as their cancel_fd,
so provide a convenience function for creating it.  Also, libopenconnect
will take care of cleaning up pipes created in this manner when the
library instance is freed.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Move signal handling out of mainloop

In order to make the mainloop a reusable library function, it should not
take over any POSIX signals.  Handle the signals in main.c instead, and
use the cancel_fd mechanism to tell the mainloop to exit.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
mainloop: Convert vpn_mainloop() into a library function

Rename to openconnect_mainloop() and allow the caller to specify
reconnection parameters.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
main: Introduce xstrdup() function

This will abort on error, instead of causing a segfault.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
tun: Export setup_tun() functionality

Create three new setup_tun() library functions:

    openconnect_setup_tun_device - create a tun device
    openconnect_setup_tun_script - pass traffic through a script
    openconnect_setup_tun_fd - pass traffic through an existing fd

The latter is needed to support Android's VpnService API.

In all cases, the caller no longer needs to directly manipulate
vpninfo->vpnc_script or vpninfo->script_tun.  The former is treated as
a standard caller-allocated, library-freed string.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Move vpninfo default settings into library

This allows main.c to call openconnect_vpninfo_new() to create the
library instance.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
library: Check for failed allocations in openconnect_vpninfo_new()

This is probably fatal anyway, but it is better to fail in a predictable
manner.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
dtls: Export setup_dtls() function

This is an optional call; the default is "no DTLS."

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
cstp: Export make_cstp_connection()

Just rename it and add it to openconnect.h.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
library: Move the mainloop guts into libopenconnect

Now the standalone openconnect binary only consists of main.c and xml.c.

Unfortunately openconnect_CFLAGS still needs to include the whole kitchen
sink, until we can remove openconnect-internal.h as a dependency.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
library: Update openconnect.pc.in

Add openssl + gnutls to Requires.private for the ssl_library=both case.
Add liboath to Requires.private.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
tun, cstp: Don't exit() on failure

These files are part of a library now so they should report errors back
to the caller.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>