[PATCH 2/2] openconnect: modify helper script for android.

openconnect at lakedaemon.net openconnect at lakedaemon.net
Thu Jul 14 21:39:01 EDT 2011


From: Jason Cooper <cyanogen at lakedaemon.net>


Signed-off-by: Jason Cooper <cyanogen at lakedaemon.net>
---
 prebuilt/common/xbin/openconnect-up.sh |   62 ++++++++++++++++++++++++++------
 1 files changed, 51 insertions(+), 11 deletions(-)

diff --git a/prebuilt/common/xbin/openconnect-up.sh b/prebuilt/common/xbin/openconnect-up.sh
index e0140c5..035a325 100644
--- a/prebuilt/common/xbin/openconnect-up.sh
+++ b/prebuilt/common/xbin/openconnect-up.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/system/bin/sh
 #* reason                       -- why this script was called, one of: pre-init connect disconnect
 #* VPNGATEWAY                   -- vpn gateway address (always present)
 #* TUNDEV                       -- tunnel device (always present)
@@ -44,17 +44,17 @@
 
 # =========== script (variable) setup ====================================
 
-PATH=/sbin:/usr/sbin:$PATH
+PATH=/system/xbin:/system/sbin:/system/bin:$PATH
 
 OS="`uname -s`"
 
-DEFAULT_ROUTE_FILE=/var/run/vpnc/defaultroute
-RESOLV_CONF_BACKUP=/var/run/vpnc/resolv.conf-backup
+DEFAULT_ROUTE_FILE=/sdcard/openconnect/defaultroute
+RESOLV_CONF_BACKUP=/sdcard/openconnect/resolv.conf-backup
 SCRIPTNAME=`basename $0`
 
-# some systems, eg. Darwin & FreeBSD, prune /var/run on boot
-if [ ! -d "/var/run/vpnc" ]; then
-	mkdir -p /var/run/vpnc
+# Is this the first time running openconnect script?
+if [ ! -d "/sdcard/openconnect" ]; then
+	mkdir -p /sdcard/openconnect
 fi
 
 # stupid SunOS: no blubber in /usr/local/bin ... (on stdout)
@@ -85,11 +85,29 @@ if [ -x /sbin/resolvconf ]; then # Optional tool on Debian, Ubuntu, Gentoo
 elif [ -x /sbin/modify_resolvconf ]; then # Mandatory tool on Suse earlier than 11.1
 	MODIFYRESOLVCONF=modify_resolvconf_suse
 	RESTORERESOLVCONF=restore_resolvconf_suse
+elif [ -x /system/bin/setprop ]; then # Mandatory tool on Android
+	MODIFYRESOLVCONF=modify_resolvconf_android
+	RESTORERESOLVCONF=restore_resolvconf_android
 else # Generic for any OS
 	MODIFYRESOLVCONF=modify_resolvconf_generic
 	RESTORERESOLVCONF=restore_resolvconf_generic
 fi
 
+# =========== android logging ==============================================
+
+andlog() {
+	prio=$1
+	shift
+	tag="${0##*/}"
+	case $prio in
+		[vdiwe])
+			;;
+		*)
+			log -p e -t $tag "INVALID PRIO to andlog()!"
+	esac
+	log -p $prio -t $tag "$*"
+}
+
 # =========== tunnel interface handling ====================================
 
 do_ifconfig() {
@@ -286,6 +304,23 @@ fi
 
 # =========== resolv.conf handling ====================================
 
+# =========== resolv.conf handling for Android ========================
+
+modify_resolvconf_android() {
+	c=1
+	for dns in $INTERNAL_IP4_DNS; do
+		setprop vpn.dns${c} "$dns"
+		c=$((c+1))
+	done
+
+	setprop vpn.dns.search "$CISCO_DEF_DOMAIN"
+}
+
+restore_resolvconf_android() {
+	# Android auto switches between dns servers, nothing to do.
+	:
+}
+
 # =========== resolv.conf handling for any OS =========================
 
 modify_resolvconf_generic() {
@@ -472,9 +507,9 @@ kernel_is_2_6_or_above() {
 
 do_pre_init() {
 	if [ "$OS" = "Linux" ]; then
-		if (exec 6<> /dev/net/tun) > /dev/null 2>&1 ; then
+		if (exec 6<> /dev/tun) > /dev/null 2>&1 ; then
 			:
-		else # can't open /dev/net/tun
+		else # can't open /dev/tun
 			test -e /proc/sys/kernel/modprobe && `cat /proc/sys/kernel/modprobe` tun 2>/dev/null
 			# fix for broken devfs in kernel 2.6.x
 			if [ "`readlink /dev/net/tun`" = misc/net/tun \
@@ -621,7 +656,12 @@ do_disconnect() {
 #### Main
 
 if [ -z "$reason" ]; then
-	echo "this script must be called from vpnc" 1>&2
+	andlog e "this script must be called from openconnect"
+	exit 1
+fi
+
+if [ "`whoami`" != "root" ]; then
+	andlog e "this script must be run as root."
 	exit 1
 fi
 
@@ -636,7 +676,7 @@ case "$reason" in
 		do_disconnect
 		;;
 	*)
-		echo "unknown reason '$reason'. Maybe vpnc-script is out of date" 1>&2
+		andlog e "unknown reason '$reason'. Maybe vpnc-script is out of date"
 		exit 1
 		;;
 esac
-- 
1.7.0.4




More information about the openconnect-devel mailing list