From: Jason Cooper <cyanogen at lakedaemon.net> Signed-off-by: Jason Cooper <cyanogen at lakedaemon.net> --- main.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 42 insertions(+), 0 deletions(-) diff --git a/main.c b/main.c index 40c7184..e2d6baa 100644 --- a/main.c +++ b/main.c @@ -35,6 +35,8 @@ #include <pwd.h> #ifndef ANDROID_CHANGES #include <sys/syslog.h> +#else +#include <android/log.h> #endif #include <sys/utsname.h> #include <sys/types.h> @@ -52,8 +54,13 @@ static int write_new_config(void *_vpninfo, char *buf, int buflen); static void write_progress(void *_vpninfo, int level, const char *fmt, ...); +#ifdef ANDROID_CHANGES +static void android_progress(void *_vpninfo, + int level, const char *fmt, ...); +#else static void syslog_progress(void *_vpninfo, int level, const char *fmt, ...); +#endif static int validate_peer_cert(void *_vpninfo, X509 *peer_cert, const char *reason); @@ -102,7 +109,9 @@ static struct option long_options[] = { {"setuid", 1, 0, 'U'}, {"script", 1, 0, 's'}, {"script-tun", 0, 0, 'S'}, +#ifndef ANDROID_CHANGES {"syslog", 0, 0, 'l'}, +#endif {"key-type", 1, 0, 'K'}, {"key-password", 1, 0, 'p'}, {"proxy", 1, 0, 'P'}, @@ -153,7 +162,9 @@ void usage(void) printf(" -g, --usergroup=GROUP Set login usergroup\n"); printf(" -h, --help Display help text\n"); printf(" -i, --interface=IFNAME Use IFNAME for tunnel interface\n"); +#ifndef ANDROID_CHANGES printf(" -l, --syslog Use syslog for progress messages\n"); +#endif printf(" -U, --setuid=USER Drop privileges after connecting\n"); printf(" --csd-user=USER Drop privileges during CSD execution\n"); printf(" --csd-wrapper=SCRIPT Run SCRIPT instead of CSD binary\n"); @@ -224,7 +235,9 @@ int main(int argc, char **argv) struct utsname utsbuf; struct sigaction sa; int cookieonly = 0; +#ifndef ANDROID_CHANGES int use_syslog = 0; +#endif char *proxy = getenv("https_proxy"); int autoproxy = 0; uid_t uid = getuid(); @@ -258,8 +271,13 @@ int main(int argc, char **argv) else vpninfo->localname = "localhost"; +#ifdef ANDROID_CHANGES + while ((opt = getopt_long(argc, argv, "bC:c:Ddg:hi:k:K:pP:Q:qSs:U:u:Vvx:", + long_options, NULL))) { +#else while ((opt = getopt_long(argc, argv, "bC:c:Ddg:hi:k:K:lpP:Q:qSs:U:u:Vvx:", long_options, NULL))) { +#endif if (opt < 0) break; @@ -345,9 +363,11 @@ int main(int argc, char **argv) case 'i': vpninfo->ifname = optarg; break; +#ifndef ANDROID_CHANGES case 'l': use_syslog = 1; break; +#endif case 'm': vpninfo->mtu = atol(optarg); if (vpninfo->mtu < 576) { @@ -477,10 +497,14 @@ int main(int argc, char **argv) if (proxy && openconnect_set_http_proxy(vpninfo, strdup(proxy))) exit(1); +#ifdef ANDROID_CHANGES + vpninfo->progress = android_progress; +#else if (use_syslog) { openlog("openconnect", LOG_PID, LOG_DAEMON); vpninfo->progress = syslog_progress; } +#endif memset(&sa, 0, sizeof(sa)); sa.sa_handler = handle_sigusr; @@ -628,6 +652,24 @@ void syslog_progress(void *_vpninfo, int level, const char *fmt, ...) } } +#ifdef ANDROID_CHANGES +void android_progress(void *_vpninfo, int level, const char *fmt, ...) +{ + va_list args; + static int l[4] = { + ANDROID_LOG_ERROR, /* PRG_ERR */ + ANDROID_LOG_INFO, /* PRG_INFO */ + ANDROID_LOG_DEBUG, /* PRG_DEBUG */ + ANDROID_LOG_DEBUG /* PRG_TRACE */ + }; + + if (verbose >= level) { + va_start(args, fmt); + __android_log_vprint(l[level], "openconnect", fmt, args); + va_end(args); + } +} +#endif struct accepted_cert { struct accepted_cert *next; -- 1.7.0.4