Make openconnect_set_hostname() clear vpninfo->peer_addr, use it more often

Based on a patch from Kevin Cernekee.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
library: Remove declaration for nonexistent openconnect_get_vpn_name()

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Fix const warnings in stoken code with NLS disabled

The gettext() function will return a non-const 'char *' pointer, and we
should have a cast in the dummy version of the _() macro to do the same.
Otherwise, we get:

../auth.c: In function 'prepare_stoken':
../auth.c:907:15: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]
../auth.c:915:14: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]
../auth.c:922:14: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]
../auth.c:929:14: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]

Based on a patch from Kevin Cernekee.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
auth: Remove bogus comment in parse_form()

This function never actually returns 1.

[dwmw2: So remove the comment entirely. Zero for success or -ERR is normal
        and warrants no comment at all.]

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
android: Update Makefile to use NDK r9b

NDK gcc 4.7 is now deprecated, so let's recommend NDK r9b + gcc 4.8.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
android: Add .gitignore file

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
android: Honor $TMPDIR when writing CSD script

Android doesn't have /tmp, so honor $TMPDIR if the caller sets it to
an alternate location.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
android: Bump gmp up to version 5.1.2

binutils 2.23.2, which is part of the arm-linux-androideabi-4.8
toolchain in NDK r9, fails to compile gmp without the following
workaround from v5.1.2:

    * mpn/arm/udiv.asm: Change spacing to work around binutils bug.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
main: Move username/password/authgroup vars into main.c

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
auth: Add <group-access> node to XML POST initial request

This ensures that we get the form and <opaque> data corresponding to the
authgroup in use.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
android: Fix broken ARCH=mips build

The MIPS NDK doesn't seem to handle dependencies correctly.  i.e.

libopenconnect.so references symbols in libz.so (from the toolchain's
sysroot), so it has a NEEDED entry for libz.so.  It was linked with -lz.

openconnect links in libopenconnect.so, but doesn't use zlib directly so
it isn't linked with -lz.

This causes a link failure on MIPS only:

    /opt/android-ndk-r9/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/mipsel-linux-android/4.8/../../../../mipsel-linux-android/bin/ld: warning: libz.so, needed by ./.libs/libopenconnect.so, not found (try using -rpath or -rpath-link)
    ./.libs/libopenconnect.so: undefined reference to `deflateEnd'
    ./.libs/libopenconnect.so: undefined reference to `inflate'
    ./.libs/libopenconnect.so: undefined reference to `inflateInit2_'
    ./.libs/libopenconnect.so: undefined reference to `deflate'
    ./.libs/libopenconnect.so: undefined reference to `adler32'
    ./.libs/libopenconnect.so: undefined reference to `inflateEnd'
    ./.libs/libopenconnect.so: undefined reference to `deflateInit2_'
    collect2: error: ld returned 1 exit status
    make[2]: *** [openconnect] Error 1

ARM/x86 are fine.  So we'll use a temporary workaround on MIPS only,
until it's resolved.

Reference: https://code.google.com/p/android/issues/detail?id=64266

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
library: Use named constants for process_auth_form() return value

Currently we have 3 valid results, and we're about to add a fourth.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
main: Rename process_auth_form() to avoid conflict with library

Since we're still including openconnect-internal.h in main.c, it isn't
possible to use function names that overlap with internal library
symbols.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Create a common process_auth_form() wrapper function

This will be used to translate between internal library structs and
public structs.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
auth: Remove outdated comment for parse_auth_choice()

We do offer <select> choices to the user (and have for some time).

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
auth: Introduce free_opt() helper function

This frees the name/label/value (as appropriate) and fixes a potential
leak in parse_auth_choice().

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
library: Change oc_form_opt_select->choices to a pointer array

This will allow the library to store internal data at the end of each
oc_choice struct, and potentially at the end of the oc_form_opt_select
struct as well.

This change breaks the public API.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
auth: Provide information on which auth choice is currently selected

In XML POST mode, the gateway keeps track of which authgroup is selected.
Provide this information to the UI so that the interface can be rendered
correctly.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
process_auth_form: Add code to support NEWGROUP return status from UI

In order to support refreshing the <opaque> data (XML POST) or the
secondary_* fields (non XML POST) on the auth form, it is necessary for
the process_auth_form() callback to return to libopenconnect to refresh
the form fields whenever the user changes the value of a <select>
dropdown.

This change should not break existing implementations.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
auth: Parse second-auth-related properties from the auth form

Add new fields/flags to the oc_form_opt and oc_choice structs.

Note that it isn't possible to add private fields at the end of
oc_form_opt, because the layout of oc_form_opt_select depends on the
length of oc_form_opt.  So we will add a publicly visible flags
field (which also supports internal flags) and reserve space for future
expansion.

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